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 static 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 #ifdef HAVE_WINDOW_SYSTEM
765 /* Non-zero means an hourglass cursor is currently shown. */
766 int hourglass_shown_p
;
768 /* If non-null, an asynchronous timer that, when it expires, displays
769 an hourglass cursor on all frames. */
770 struct atimer
*hourglass_atimer
;
772 #endif /* HAVE_WINDOW_SYSTEM */
774 /* Name of the face used to display glyphless characters. */
775 Lisp_Object Qglyphless_char
;
777 /* Symbol for the purpose of Vglyphless_char_display. */
778 static Lisp_Object Qglyphless_char_display
;
780 /* Method symbols for Vglyphless_char_display. */
781 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
783 /* Default number of seconds to wait before displaying an hourglass
785 #define DEFAULT_HOURGLASS_DELAY 1
787 #ifdef HAVE_WINDOW_SYSTEM
789 /* Default pixel width of `thin-space' display method. */
790 #define THIN_SPACE_WIDTH 1
792 #endif /* HAVE_WINDOW_SYSTEM */
794 /* Function prototypes. */
796 static void setup_for_ellipsis (struct it
*, int);
797 static void set_iterator_to_next (struct it
*, int);
798 static void mark_window_display_accurate_1 (struct window
*, int);
799 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
800 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
801 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
802 static int cursor_row_p (struct glyph_row
*);
803 static int redisplay_mode_lines (Lisp_Object
, int);
804 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
806 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
808 static void handle_line_prefix (struct it
*);
810 static void pint2str (char *, int, ptrdiff_t);
811 static void pint2hrstr (char *, int, ptrdiff_t);
812 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
814 static int text_outside_line_unchanged_p (struct window
*,
815 ptrdiff_t, ptrdiff_t);
816 static void store_mode_line_noprop_char (char);
817 static int store_mode_line_noprop (const char *, int, int);
818 static void handle_stop (struct it
*);
819 static void handle_stop_backwards (struct it
*, ptrdiff_t);
820 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
821 static void ensure_echo_area_buffers (void);
822 static void unwind_with_echo_area_buffer (Lisp_Object
);
823 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
824 static int with_echo_area_buffer (struct window
*, int,
825 int (*) (ptrdiff_t, Lisp_Object
),
826 ptrdiff_t, Lisp_Object
);
827 static void clear_garbaged_frames (void);
828 static int current_message_1 (ptrdiff_t, Lisp_Object
);
829 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
830 static void set_message (Lisp_Object
);
831 static int set_message_1 (ptrdiff_t, Lisp_Object
);
832 static int display_echo_area (struct window
*);
833 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
834 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
835 static void unwind_redisplay (void);
836 static int string_char_and_length (const unsigned char *, int *);
837 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
839 static int compute_window_start_on_continuation_line (struct window
*);
840 static void insert_left_trunc_glyphs (struct it
*);
841 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
843 static void extend_face_to_end_of_line (struct it
*);
844 static int append_space_for_newline (struct it
*, int);
845 static int cursor_row_fully_visible_p (struct window
*, int, int);
846 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
847 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
848 static int trailing_whitespace_p (ptrdiff_t);
849 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
850 static void push_it (struct it
*, struct text_pos
*);
851 static void iterate_out_of_display_property (struct it
*);
852 static void pop_it (struct it
*);
853 static void sync_frame_with_window_matrix_rows (struct window
*);
854 static void redisplay_internal (void);
855 static int echo_area_display (int);
856 static void redisplay_windows (Lisp_Object
);
857 static void redisplay_window (Lisp_Object
, int);
858 static Lisp_Object
redisplay_window_error (Lisp_Object
);
859 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
860 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
861 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
862 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
864 static int update_menu_bar (struct frame
*, int, int);
865 static int try_window_reusing_current_matrix (struct window
*);
866 static int try_window_id (struct window
*);
867 static int display_line (struct it
*);
868 static int display_mode_lines (struct window
*);
869 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
870 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
871 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
872 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
873 static void display_menu_bar (struct window
*);
874 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
876 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
877 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
878 static void compute_line_metrics (struct it
*);
879 static void run_redisplay_end_trigger_hook (struct it
*);
880 static int get_overlay_strings (struct it
*, ptrdiff_t);
881 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
882 static void next_overlay_string (struct it
*);
883 static void reseat (struct it
*, struct text_pos
, int);
884 static void reseat_1 (struct it
*, struct text_pos
, int);
885 static void back_to_previous_visible_line_start (struct it
*);
886 static void reseat_at_next_visible_line_start (struct it
*, int);
887 static int next_element_from_ellipsis (struct it
*);
888 static int next_element_from_display_vector (struct it
*);
889 static int next_element_from_string (struct it
*);
890 static int next_element_from_c_string (struct it
*);
891 static int next_element_from_buffer (struct it
*);
892 static int next_element_from_composition (struct it
*);
893 static int next_element_from_image (struct it
*);
894 static int next_element_from_stretch (struct it
*);
895 static void load_overlay_strings (struct it
*, ptrdiff_t);
896 static int init_from_display_pos (struct it
*, struct window
*,
897 struct display_pos
*);
898 static void reseat_to_string (struct it
*, const char *,
899 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
900 static int get_next_display_element (struct it
*);
901 static enum move_it_result
902 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
903 enum move_operation_enum
);
904 static void get_visually_first_element (struct it
*);
905 static void init_to_row_start (struct it
*, struct window
*,
907 static int init_to_row_end (struct it
*, struct window
*,
909 static void back_to_previous_line_start (struct it
*);
910 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
911 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
912 Lisp_Object
, ptrdiff_t);
913 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
914 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
915 static ptrdiff_t number_of_chars (const char *, bool);
916 static void compute_stop_pos (struct it
*);
917 static void compute_string_pos (struct text_pos
*, struct text_pos
,
919 static int face_before_or_after_it_pos (struct it
*, int);
920 static ptrdiff_t next_overlay_change (ptrdiff_t);
921 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
922 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
923 static int handle_single_display_spec (struct it
*, Lisp_Object
,
924 Lisp_Object
, Lisp_Object
,
925 struct text_pos
*, ptrdiff_t, int, int);
926 static int underlying_face_id (struct it
*);
927 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
930 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
931 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
933 #ifdef HAVE_WINDOW_SYSTEM
935 static void x_consider_frame_title (Lisp_Object
);
936 static int tool_bar_lines_needed (struct frame
*, int *);
937 static void update_tool_bar (struct frame
*, int);
938 static void build_desired_tool_bar_string (struct frame
*f
);
939 static int redisplay_tool_bar (struct frame
*);
940 static void display_tool_bar_line (struct it
*, int);
941 static void notice_overwritten_cursor (struct window
*,
944 static void append_stretch_glyph (struct it
*, Lisp_Object
,
948 #endif /* HAVE_WINDOW_SYSTEM */
950 static void produce_special_glyphs (struct it
*, enum display_element_type
);
951 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
952 static int coords_in_mouse_face_p (struct window
*, int, int);
956 /***********************************************************************
957 Window display dimensions
958 ***********************************************************************/
960 /* Return the bottom boundary y-position for text lines in window W.
961 This is the first y position at which a line cannot start.
962 It is relative to the top of the window.
964 This is the height of W minus the height of a mode line, if any. */
967 window_text_bottom_y (struct window
*w
)
969 int height
= WINDOW_TOTAL_HEIGHT (w
);
971 if (WINDOW_WANTS_MODELINE_P (w
))
972 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
976 /* Return the pixel width of display area AREA of window W.
977 ANY_AREA means return the total width of W, not including
978 fringes to the left and right of the window. */
981 window_box_width (struct window
*w
, enum glyph_row_area area
)
983 int cols
= w
->total_cols
;
986 if (!w
->pseudo_window_p
)
988 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
990 if (area
== TEXT_AREA
)
992 cols
-= max (0, w
->left_margin_cols
);
993 cols
-= max (0, w
->right_margin_cols
);
994 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
996 else if (area
== LEFT_MARGIN_AREA
)
998 cols
= max (0, w
->left_margin_cols
);
1001 else if (area
== RIGHT_MARGIN_AREA
)
1003 cols
= max (0, w
->right_margin_cols
);
1008 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1012 /* Return the pixel height of the display area of window W, not
1013 including mode lines of W, if any. */
1016 window_box_height (struct window
*w
)
1018 struct frame
*f
= XFRAME (w
->frame
);
1019 int height
= WINDOW_TOTAL_HEIGHT (w
);
1021 eassert (height
>= 0);
1023 /* Note: the code below that determines the mode-line/header-line
1024 height is essentially the same as that contained in the macro
1025 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1026 the appropriate glyph row has its `mode_line_p' flag set,
1027 and if it doesn't, uses estimate_mode_line_height instead. */
1029 if (WINDOW_WANTS_MODELINE_P (w
))
1031 struct glyph_row
*ml_row
1032 = (w
->current_matrix
&& w
->current_matrix
->rows
1033 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1035 if (ml_row
&& ml_row
->mode_line_p
)
1036 height
-= ml_row
->height
;
1038 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1041 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1043 struct glyph_row
*hl_row
1044 = (w
->current_matrix
&& w
->current_matrix
->rows
1045 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1047 if (hl_row
&& hl_row
->mode_line_p
)
1048 height
-= hl_row
->height
;
1050 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1053 /* With a very small font and a mode-line that's taller than
1054 default, we might end up with a negative height. */
1055 return max (0, height
);
1058 /* Return the window-relative coordinate of the left edge of display
1059 area AREA of window W. ANY_AREA means return the left edge of the
1060 whole window, to the right of the left fringe of W. */
1063 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1067 if (w
->pseudo_window_p
)
1070 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1072 if (area
== TEXT_AREA
)
1073 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1074 + window_box_width (w
, LEFT_MARGIN_AREA
));
1075 else if (area
== RIGHT_MARGIN_AREA
)
1076 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1077 + window_box_width (w
, LEFT_MARGIN_AREA
)
1078 + window_box_width (w
, TEXT_AREA
)
1079 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1081 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1082 else if (area
== LEFT_MARGIN_AREA
1083 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1084 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1090 /* Return the window-relative coordinate of the right edge of display
1091 area AREA of window W. ANY_AREA means return the right edge of the
1092 whole window, to the left of the right fringe of W. */
1095 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1097 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1100 /* Return the frame-relative coordinate of the left edge of display
1101 area AREA of window W. ANY_AREA means return the left edge of the
1102 whole window, to the right of the left fringe of W. */
1105 window_box_left (struct window
*w
, enum glyph_row_area area
)
1107 struct frame
*f
= XFRAME (w
->frame
);
1110 if (w
->pseudo_window_p
)
1111 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1113 x
= (WINDOW_LEFT_EDGE_X (w
)
1114 + window_box_left_offset (w
, area
));
1120 /* Return the frame-relative coordinate of the right edge of display
1121 area AREA of window W. ANY_AREA means return the right edge of the
1122 whole window, to the left of the right fringe of W. */
1125 window_box_right (struct window
*w
, enum glyph_row_area area
)
1127 return window_box_left (w
, area
) + window_box_width (w
, area
);
1130 /* Get the bounding box of the display area AREA of window W, without
1131 mode lines, in frame-relative coordinates. ANY_AREA means the
1132 whole window, not including the left and right fringes of
1133 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1134 coordinates of the upper-left corner of the box. Return in
1135 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1138 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1139 int *box_y
, int *box_width
, int *box_height
)
1142 *box_width
= window_box_width (w
, area
);
1144 *box_height
= window_box_height (w
);
1146 *box_x
= window_box_left (w
, area
);
1149 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1150 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1151 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1155 #ifdef HAVE_WINDOW_SYSTEM
1157 /* Get the bounding box of the display area AREA of window W, without
1158 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1159 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1160 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1161 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1165 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1166 int *bottom_right_x
, int *bottom_right_y
)
1168 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1169 bottom_right_x
, bottom_right_y
);
1170 *bottom_right_x
+= *top_left_x
;
1171 *bottom_right_y
+= *top_left_y
;
1174 #endif /* HAVE_WINDOW_SYSTEM */
1176 /***********************************************************************
1178 ***********************************************************************/
1180 /* Return the bottom y-position of the line the iterator IT is in.
1181 This can modify IT's settings. */
1184 line_bottom_y (struct it
*it
)
1186 int line_height
= it
->max_ascent
+ it
->max_descent
;
1187 int line_top_y
= it
->current_y
;
1189 if (line_height
== 0)
1192 line_height
= last_height
;
1193 else if (IT_CHARPOS (*it
) < ZV
)
1195 move_it_by_lines (it
, 1);
1196 line_height
= (it
->max_ascent
|| it
->max_descent
1197 ? it
->max_ascent
+ it
->max_descent
1202 struct glyph_row
*row
= it
->glyph_row
;
1204 /* Use the default character height. */
1205 it
->glyph_row
= NULL
;
1206 it
->what
= IT_CHARACTER
;
1209 PRODUCE_GLYPHS (it
);
1210 line_height
= it
->ascent
+ it
->descent
;
1211 it
->glyph_row
= row
;
1215 return line_top_y
+ line_height
;
1218 DEFUN ("line-pixel-height", Fline_pixel_height
,
1219 Sline_pixel_height
, 0, 0, 0,
1220 doc
: /* Return height in pixels of text line in the selected window.
1222 Value is the height in pixels of the line at point. */)
1227 struct window
*w
= XWINDOW (selected_window
);
1229 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1230 start_display (&it
, w
, pt
);
1231 it
.vpos
= it
.current_y
= 0;
1233 return make_number (line_bottom_y (&it
));
1236 /* Return the default pixel height of text lines in window W. The
1237 value is the canonical height of the W frame's default font, plus
1238 any extra space required by the line-spacing variable or frame
1241 Implementation note: this ignores any line-spacing text properties
1242 put on the newline characters. This is because those properties
1243 only affect the _screen_ line ending in the newline (i.e., in a
1244 continued line, only the last screen line will be affected), which
1245 means only a small number of lines in a buffer can ever use this
1246 feature. Since this function is used to compute the default pixel
1247 equivalent of text lines in a window, we can safely ignore those
1248 few lines. For the same reasons, we ignore the line-height
1251 default_line_pixel_height (struct window
*w
)
1253 struct frame
*f
= WINDOW_XFRAME (w
);
1254 int height
= FRAME_LINE_HEIGHT (f
);
1256 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1258 struct buffer
*b
= XBUFFER (w
->contents
);
1259 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1262 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1265 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1266 height
+= XFASTINT (val
);
1267 else if (FLOATP (val
))
1269 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1276 height
+= f
->extra_line_spacing
;
1282 /* Subroutine of pos_visible_p below. Extracts a display string, if
1283 any, from the display spec given as its argument. */
1285 string_from_display_spec (Lisp_Object spec
)
1289 while (CONSP (spec
))
1291 if (STRINGP (XCAR (spec
)))
1296 else if (VECTORP (spec
))
1300 for (i
= 0; i
< ASIZE (spec
); i
++)
1302 if (STRINGP (AREF (spec
, i
)))
1303 return AREF (spec
, i
);
1312 /* Limit insanely large values of W->hscroll on frame F to the largest
1313 value that will still prevent first_visible_x and last_visible_x of
1314 'struct it' from overflowing an int. */
1316 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1318 ptrdiff_t window_hscroll
= w
->hscroll
;
1319 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1320 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1322 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1323 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1325 return window_hscroll
;
1328 /* Return 1 if position CHARPOS is visible in window W.
1329 CHARPOS < 0 means return info about WINDOW_END position.
1330 If visible, set *X and *Y to pixel coordinates of top left corner.
1331 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1332 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1335 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1336 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1339 void *itdata
= bidi_shelve_cache ();
1340 struct text_pos top
;
1342 struct buffer
*old_buffer
= NULL
;
1344 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1347 if (XBUFFER (w
->contents
) != current_buffer
)
1349 old_buffer
= current_buffer
;
1350 set_buffer_internal_1 (XBUFFER (w
->contents
));
1353 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1354 /* Scrolling a minibuffer window via scroll bar when the echo area
1355 shows long text sometimes resets the minibuffer contents behind
1357 if (CHARPOS (top
) > ZV
)
1358 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1360 /* Compute exact mode line heights. */
1361 if (WINDOW_WANTS_MODELINE_P (w
))
1362 current_mode_line_height
1363 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1364 BVAR (current_buffer
, mode_line_format
));
1366 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1367 current_header_line_height
1368 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1369 BVAR (current_buffer
, header_line_format
));
1371 start_display (&it
, w
, top
);
1372 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1373 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1376 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1377 && IT_CHARPOS (it
) >= charpos
)
1378 /* When scanning backwards under bidi iteration, move_it_to
1379 stops at or _before_ CHARPOS, because it stops at or to
1380 the _right_ of the character at CHARPOS. */
1381 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1382 && IT_CHARPOS (it
) <= charpos
)))
1384 /* We have reached CHARPOS, or passed it. How the call to
1385 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1386 or covered by a display property, move_it_to stops at the end
1387 of the invisible text, to the right of CHARPOS. (ii) If
1388 CHARPOS is in a display vector, move_it_to stops on its last
1390 int top_x
= it
.current_x
;
1391 int top_y
= it
.current_y
;
1392 /* Calling line_bottom_y may change it.method, it.position, etc. */
1393 enum it_method it_method
= it
.method
;
1394 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1395 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1397 if (top_y
< window_top_y
)
1398 visible_p
= bottom_y
> window_top_y
;
1399 else if (top_y
< it
.last_visible_y
)
1401 if (bottom_y
>= it
.last_visible_y
1402 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1403 && IT_CHARPOS (it
) < charpos
)
1405 /* When the last line of the window is scanned backwards
1406 under bidi iteration, we could be duped into thinking
1407 that we have passed CHARPOS, when in fact move_it_to
1408 simply stopped short of CHARPOS because it reached
1409 last_visible_y. To see if that's what happened, we call
1410 move_it_to again with a slightly larger vertical limit,
1411 and see if it actually moved vertically; if it did, we
1412 didn't really reach CHARPOS, which is beyond window end. */
1413 struct it save_it
= it
;
1414 /* Why 10? because we don't know how many canonical lines
1415 will the height of the next line(s) be. So we guess. */
1416 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1418 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1419 MOVE_TO_POS
| MOVE_TO_Y
);
1420 if (it
.current_y
> top_y
)
1427 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1429 /* We stopped on the last glyph of a display vector.
1430 Try and recompute. Hack alert! */
1431 if (charpos
< 2 || top
.charpos
>= charpos
)
1432 top_x
= it
.glyph_row
->x
;
1435 struct it it2
, it2_prev
;
1436 /* The idea is to get to the previous buffer
1437 position, consume the character there, and use
1438 the pixel coordinates we get after that. But if
1439 the previous buffer position is also displayed
1440 from a display vector, we need to consume all of
1441 the glyphs from that display vector. */
1442 start_display (&it2
, w
, top
);
1443 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1444 /* If we didn't get to CHARPOS - 1, there's some
1445 replacing display property at that position, and
1446 we stopped after it. That is exactly the place
1447 whose coordinates we want. */
1448 if (IT_CHARPOS (it2
) != charpos
- 1)
1452 /* Iterate until we get out of the display
1453 vector that displays the character at
1456 get_next_display_element (&it2
);
1457 PRODUCE_GLYPHS (&it2
);
1459 set_iterator_to_next (&it2
, 1);
1460 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1461 && IT_CHARPOS (it2
) < charpos
);
1463 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1464 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1465 top_x
= it
.glyph_row
->x
;
1468 top_x
= it2_prev
.current_x
;
1469 top_y
= it2_prev
.current_y
;
1473 else if (IT_CHARPOS (it
) != charpos
)
1475 Lisp_Object cpos
= make_number (charpos
);
1476 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1477 Lisp_Object string
= string_from_display_spec (spec
);
1478 struct text_pos tpos
;
1479 int replacing_spec_p
;
1480 bool newline_in_string
1482 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1484 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1487 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1488 charpos
, FRAME_WINDOW_P (it
.f
)));
1489 /* The tricky code below is needed because there's a
1490 discrepancy between move_it_to and how we set cursor
1491 when PT is at the beginning of a portion of text
1492 covered by a display property or an overlay with a
1493 display property, or the display line ends in a
1494 newline from a display string. move_it_to will stop
1495 _after_ such display strings, whereas
1496 set_cursor_from_row conspires with cursor_row_p to
1497 place the cursor on the first glyph produced from the
1500 /* We have overshoot PT because it is covered by a
1501 display property that replaces the text it covers.
1502 If the string includes embedded newlines, we are also
1503 in the wrong display line. Backtrack to the correct
1504 line, where the display property begins. */
1505 if (replacing_spec_p
)
1507 Lisp_Object startpos
, endpos
;
1508 EMACS_INT start
, end
;
1512 /* Find the first and the last buffer positions
1513 covered by the display string. */
1515 Fnext_single_char_property_change (cpos
, Qdisplay
,
1518 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1520 start
= XFASTINT (startpos
);
1521 end
= XFASTINT (endpos
);
1522 /* Move to the last buffer position before the
1523 display property. */
1524 start_display (&it3
, w
, top
);
1525 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1526 /* Move forward one more line if the position before
1527 the display string is a newline or if it is the
1528 rightmost character on a line that is
1529 continued or word-wrapped. */
1530 if (it3
.method
== GET_FROM_BUFFER
1532 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1533 move_it_by_lines (&it3
, 1);
1534 else if (move_it_in_display_line_to (&it3
, -1,
1538 == MOVE_LINE_CONTINUED
)
1540 move_it_by_lines (&it3
, 1);
1541 /* When we are under word-wrap, the #$@%!
1542 move_it_by_lines moves 2 lines, so we need to
1544 if (it3
.line_wrap
== WORD_WRAP
)
1545 move_it_by_lines (&it3
, -1);
1548 /* Record the vertical coordinate of the display
1549 line where we wound up. */
1550 top_y
= it3
.current_y
;
1553 /* When characters are reordered for display,
1554 the character displayed to the left of the
1555 display string could be _after_ the display
1556 property in the logical order. Use the
1557 smallest vertical position of these two. */
1558 start_display (&it3
, w
, top
);
1559 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1560 if (it3
.current_y
< top_y
)
1561 top_y
= it3
.current_y
;
1563 /* Move from the top of the window to the beginning
1564 of the display line where the display string
1566 start_display (&it3
, w
, top
);
1567 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1568 /* If it3_moved stays zero after the 'while' loop
1569 below, that means we already were at a newline
1570 before the loop (e.g., the display string begins
1571 with a newline), so we don't need to (and cannot)
1572 inspect the glyphs of it3.glyph_row, because
1573 PRODUCE_GLYPHS will not produce anything for a
1574 newline, and thus it3.glyph_row stays at its
1575 stale content it got at top of the window. */
1577 /* Finally, advance the iterator until we hit the
1578 first display element whose character position is
1579 CHARPOS, or until the first newline from the
1580 display string, which signals the end of the
1582 while (get_next_display_element (&it3
))
1584 PRODUCE_GLYPHS (&it3
);
1585 if (IT_CHARPOS (it3
) == charpos
1586 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1589 set_iterator_to_next (&it3
, 0);
1591 top_x
= it3
.current_x
- it3
.pixel_width
;
1592 /* Normally, we would exit the above loop because we
1593 found the display element whose character
1594 position is CHARPOS. For the contingency that we
1595 didn't, and stopped at the first newline from the
1596 display string, move back over the glyphs
1597 produced from the string, until we find the
1598 rightmost glyph not from the string. */
1600 && newline_in_string
1601 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1603 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1604 + it3
.glyph_row
->used
[TEXT_AREA
];
1606 while (EQ ((g
- 1)->object
, string
))
1609 top_x
-= g
->pixel_width
;
1611 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1612 + it3
.glyph_row
->used
[TEXT_AREA
]);
1618 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1619 *rtop
= max (0, window_top_y
- top_y
);
1620 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1621 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1622 - max (top_y
, window_top_y
)));
1628 /* We were asked to provide info about WINDOW_END. */
1630 void *it2data
= NULL
;
1632 SAVE_IT (it2
, it
, it2data
);
1633 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1634 move_it_by_lines (&it
, 1);
1635 if (charpos
< IT_CHARPOS (it
)
1636 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1639 RESTORE_IT (&it2
, &it2
, it2data
);
1640 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1642 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1643 *rtop
= max (0, -it2
.current_y
);
1644 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1645 - it
.last_visible_y
));
1646 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1648 - max (it2
.current_y
,
1649 WINDOW_HEADER_LINE_HEIGHT (w
))));
1653 bidi_unshelve_cache (it2data
, 1);
1655 bidi_unshelve_cache (itdata
, 0);
1658 set_buffer_internal_1 (old_buffer
);
1660 current_header_line_height
= current_mode_line_height
= -1;
1662 if (visible_p
&& w
->hscroll
> 0)
1664 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1665 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1668 /* Debugging code. */
1670 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1671 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1673 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1680 /* Return the next character from STR. Return in *LEN the length of
1681 the character. This is like STRING_CHAR_AND_LENGTH but never
1682 returns an invalid character. If we find one, we return a `?', but
1683 with the length of the invalid character. */
1686 string_char_and_length (const unsigned char *str
, int *len
)
1690 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1691 if (!CHAR_VALID_P (c
))
1692 /* We may not change the length here because other places in Emacs
1693 don't use this function, i.e. they silently accept invalid
1702 /* Given a position POS containing a valid character and byte position
1703 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1705 static struct text_pos
1706 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1708 eassert (STRINGP (string
) && nchars
>= 0);
1710 if (STRING_MULTIBYTE (string
))
1712 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1717 string_char_and_length (p
, &len
);
1720 BYTEPOS (pos
) += len
;
1724 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1730 /* Value is the text position, i.e. character and byte position,
1731 for character position CHARPOS in STRING. */
1733 static struct text_pos
1734 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1736 struct text_pos pos
;
1737 eassert (STRINGP (string
));
1738 eassert (charpos
>= 0);
1739 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1744 /* Value is a text position, i.e. character and byte position, for
1745 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1746 means recognize multibyte characters. */
1748 static struct text_pos
1749 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1751 struct text_pos pos
;
1753 eassert (s
!= NULL
);
1754 eassert (charpos
>= 0);
1760 SET_TEXT_POS (pos
, 0, 0);
1763 string_char_and_length ((const unsigned char *) s
, &len
);
1766 BYTEPOS (pos
) += len
;
1770 SET_TEXT_POS (pos
, charpos
, charpos
);
1776 /* Value is the number of characters in C string S. MULTIBYTE_P
1777 non-zero means recognize multibyte characters. */
1780 number_of_chars (const char *s
, bool multibyte_p
)
1786 ptrdiff_t rest
= strlen (s
);
1788 const unsigned char *p
= (const unsigned char *) s
;
1790 for (nchars
= 0; rest
> 0; ++nchars
)
1792 string_char_and_length (p
, &len
);
1793 rest
-= len
, p
+= len
;
1797 nchars
= strlen (s
);
1803 /* Compute byte position NEWPOS->bytepos corresponding to
1804 NEWPOS->charpos. POS is a known position in string STRING.
1805 NEWPOS->charpos must be >= POS.charpos. */
1808 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1810 eassert (STRINGP (string
));
1811 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1813 if (STRING_MULTIBYTE (string
))
1814 *newpos
= string_pos_nchars_ahead (pos
, string
,
1815 CHARPOS (*newpos
) - CHARPOS (pos
));
1817 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1821 Return an estimation of the pixel height of mode or header lines on
1822 frame F. FACE_ID specifies what line's height to estimate. */
1825 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1827 #ifdef HAVE_WINDOW_SYSTEM
1828 if (FRAME_WINDOW_P (f
))
1830 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1832 /* This function is called so early when Emacs starts that the face
1833 cache and mode line face are not yet initialized. */
1834 if (FRAME_FACE_CACHE (f
))
1836 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1840 height
= FONT_HEIGHT (face
->font
);
1841 if (face
->box_line_width
> 0)
1842 height
+= 2 * face
->box_line_width
;
1853 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1854 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1855 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1856 not force the value into range. */
1859 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1860 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1863 #ifdef HAVE_WINDOW_SYSTEM
1864 if (FRAME_WINDOW_P (f
))
1866 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1867 even for negative values. */
1869 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1871 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1873 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1874 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1877 STORE_NATIVE_RECT (*bounds
,
1878 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1879 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1880 FRAME_COLUMN_WIDTH (f
) - 1,
1881 FRAME_LINE_HEIGHT (f
) - 1);
1887 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1888 pix_x
= FRAME_TOTAL_COLS (f
);
1892 else if (pix_y
> FRAME_LINES (f
))
1893 pix_y
= FRAME_LINES (f
);
1903 /* Find the glyph under window-relative coordinates X/Y in window W.
1904 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1905 strings. Return in *HPOS and *VPOS the row and column number of
1906 the glyph found. Return in *AREA the glyph area containing X.
1907 Value is a pointer to the glyph found or null if X/Y is not on
1908 text, or we can't tell because W's current matrix is not up to
1913 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1914 int *dx
, int *dy
, int *area
)
1916 struct glyph
*glyph
, *end
;
1917 struct glyph_row
*row
= NULL
;
1920 /* Find row containing Y. Give up if some row is not enabled. */
1921 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1923 row
= MATRIX_ROW (w
->current_matrix
, i
);
1924 if (!row
->enabled_p
)
1926 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1933 /* Give up if Y is not in the window. */
1934 if (i
== w
->current_matrix
->nrows
)
1937 /* Get the glyph area containing X. */
1938 if (w
->pseudo_window_p
)
1945 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1947 *area
= LEFT_MARGIN_AREA
;
1948 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1950 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1953 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1957 *area
= RIGHT_MARGIN_AREA
;
1958 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1962 /* Find glyph containing X. */
1963 glyph
= row
->glyphs
[*area
];
1964 end
= glyph
+ row
->used
[*area
];
1966 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1968 x
-= glyph
->pixel_width
;
1978 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1981 *hpos
= glyph
- row
->glyphs
[*area
];
1985 /* Convert frame-relative x/y to coordinates relative to window W.
1986 Takes pseudo-windows into account. */
1989 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1991 if (w
->pseudo_window_p
)
1993 /* A pseudo-window is always full-width, and starts at the
1994 left edge of the frame, plus a frame border. */
1995 struct frame
*f
= XFRAME (w
->frame
);
1996 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1997 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2001 *x
-= WINDOW_LEFT_EDGE_X (w
);
2002 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2006 #ifdef HAVE_WINDOW_SYSTEM
2009 Return in RECTS[] at most N clipping rectangles for glyph string S.
2010 Return the number of stored rectangles. */
2013 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2020 if (s
->row
->full_width_p
)
2022 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2023 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2024 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
2026 /* Unless displaying a mode or menu bar line, which are always
2027 fully visible, clip to the visible part of the row. */
2028 if (s
->w
->pseudo_window_p
)
2029 r
.height
= s
->row
->visible_height
;
2031 r
.height
= s
->height
;
2035 /* This is a text line that may be partially visible. */
2036 r
.x
= window_box_left (s
->w
, s
->area
);
2037 r
.width
= window_box_width (s
->w
, s
->area
);
2038 r
.height
= s
->row
->visible_height
;
2042 if (r
.x
< s
->clip_head
->x
)
2044 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2045 r
.width
-= s
->clip_head
->x
- r
.x
;
2048 r
.x
= s
->clip_head
->x
;
2051 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2053 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2054 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2059 /* If S draws overlapping rows, it's sufficient to use the top and
2060 bottom of the window for clipping because this glyph string
2061 intentionally draws over other lines. */
2062 if (s
->for_overlaps
)
2064 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2065 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2067 /* Alas, the above simple strategy does not work for the
2068 environments with anti-aliased text: if the same text is
2069 drawn onto the same place multiple times, it gets thicker.
2070 If the overlap we are processing is for the erased cursor, we
2071 take the intersection with the rectangle of the cursor. */
2072 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2074 XRectangle rc
, r_save
= r
;
2076 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2077 rc
.y
= s
->w
->phys_cursor
.y
;
2078 rc
.width
= s
->w
->phys_cursor_width
;
2079 rc
.height
= s
->w
->phys_cursor_height
;
2081 x_intersect_rectangles (&r_save
, &rc
, &r
);
2086 /* Don't use S->y for clipping because it doesn't take partially
2087 visible lines into account. For example, it can be negative for
2088 partially visible lines at the top of a window. */
2089 if (!s
->row
->full_width_p
2090 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2091 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2093 r
.y
= max (0, s
->row
->y
);
2096 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2098 /* If drawing the cursor, don't let glyph draw outside its
2099 advertised boundaries. Cleartype does this under some circumstances. */
2100 if (s
->hl
== DRAW_CURSOR
)
2102 struct glyph
*glyph
= s
->first_glyph
;
2107 r
.width
-= s
->x
- r
.x
;
2110 r
.width
= min (r
.width
, glyph
->pixel_width
);
2112 /* If r.y is below window bottom, ensure that we still see a cursor. */
2113 height
= min (glyph
->ascent
+ glyph
->descent
,
2114 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2115 max_y
= window_text_bottom_y (s
->w
) - height
;
2116 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2117 if (s
->ybase
- glyph
->ascent
> max_y
)
2124 /* Don't draw cursor glyph taller than our actual glyph. */
2125 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2126 if (height
< r
.height
)
2128 max_y
= r
.y
+ r
.height
;
2129 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2130 r
.height
= min (max_y
- r
.y
, height
);
2137 XRectangle r_save
= r
;
2139 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2143 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2144 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2146 #ifdef CONVERT_FROM_XRECT
2147 CONVERT_FROM_XRECT (r
, *rects
);
2155 /* If we are processing overlapping and allowed to return
2156 multiple clipping rectangles, we exclude the row of the glyph
2157 string from the clipping rectangle. This is to avoid drawing
2158 the same text on the environment with anti-aliasing. */
2159 #ifdef CONVERT_FROM_XRECT
2162 XRectangle
*rs
= rects
;
2164 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2166 if (s
->for_overlaps
& OVERLAPS_PRED
)
2169 if (r
.y
+ r
.height
> row_y
)
2172 rs
[i
].height
= row_y
- r
.y
;
2178 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2181 if (r
.y
< row_y
+ s
->row
->visible_height
)
2183 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2185 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2186 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2195 #ifdef CONVERT_FROM_XRECT
2196 for (i
= 0; i
< n
; i
++)
2197 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2204 Return in *NR the clipping rectangle for glyph string S. */
2207 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2209 get_glyph_string_clip_rects (s
, nr
, 1);
2214 Return the position and height of the phys cursor in window W.
2215 Set w->phys_cursor_width to width of phys cursor.
2219 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2220 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2222 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2223 int x
, y
, wd
, h
, h0
, y0
;
2225 /* Compute the width of the rectangle to draw. If on a stretch
2226 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2227 rectangle as wide as the glyph, but use a canonical character
2229 wd
= glyph
->pixel_width
- 1;
2230 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2234 x
= w
->phys_cursor
.x
;
2241 if (glyph
->type
== STRETCH_GLYPH
2242 && !x_stretch_cursor_p
)
2243 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2244 w
->phys_cursor_width
= wd
;
2246 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2248 /* If y is below window bottom, ensure that we still see a cursor. */
2249 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2251 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2252 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2254 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2257 h
= max (h
- (y0
- y
) + 1, h0
);
2262 y0
= window_text_bottom_y (w
) - h0
;
2270 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2271 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2276 * Remember which glyph the mouse is over.
2280 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2284 struct glyph_row
*r
, *gr
, *end_row
;
2285 enum window_part part
;
2286 enum glyph_row_area area
;
2287 int x
, y
, width
, height
;
2289 /* Try to determine frame pixel position and size of the glyph under
2290 frame pixel coordinates X/Y on frame F. */
2292 if (!f
->glyphs_initialized_p
2293 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2296 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2297 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2301 w
= XWINDOW (window
);
2302 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2303 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2305 x
= window_relative_x_coord (w
, part
, gx
);
2306 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2308 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2309 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2311 if (w
->pseudo_window_p
)
2314 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2320 case ON_LEFT_MARGIN
:
2321 area
= LEFT_MARGIN_AREA
;
2324 case ON_RIGHT_MARGIN
:
2325 area
= RIGHT_MARGIN_AREA
;
2328 case ON_HEADER_LINE
:
2330 gr
= (part
== ON_HEADER_LINE
2331 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2332 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2335 goto text_glyph_row_found
;
2342 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2343 if (r
->y
+ r
->height
> y
)
2349 text_glyph_row_found
:
2352 struct glyph
*g
= gr
->glyphs
[area
];
2353 struct glyph
*end
= g
+ gr
->used
[area
];
2355 height
= gr
->height
;
2356 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2357 if (gx
+ g
->pixel_width
> x
)
2362 if (g
->type
== IMAGE_GLYPH
)
2364 /* Don't remember when mouse is over image, as
2365 image may have hot-spots. */
2366 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2369 width
= g
->pixel_width
;
2373 /* Use nominal char spacing at end of line. */
2375 gx
+= (x
/ width
) * width
;
2378 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2379 gx
+= window_box_left_offset (w
, area
);
2383 /* Use nominal line height at end of window. */
2384 gx
= (x
/ width
) * width
;
2386 gy
+= (y
/ height
) * height
;
2390 case ON_LEFT_FRINGE
:
2391 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2392 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2393 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2394 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2397 case ON_RIGHT_FRINGE
:
2398 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2399 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2400 : window_box_right_offset (w
, TEXT_AREA
));
2401 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2405 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2407 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2408 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2409 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2411 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2415 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2416 if (r
->y
+ r
->height
> y
)
2423 height
= gr
->height
;
2426 /* Use nominal line height at end of window. */
2428 gy
+= (y
/ height
) * height
;
2435 /* If there is no glyph under the mouse, then we divide the screen
2436 into a grid of the smallest glyph in the frame, and use that
2439 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2440 round down even for negative values. */
2446 gx
= (gx
/ width
) * width
;
2447 gy
= (gy
/ height
) * height
;
2452 gx
+= WINDOW_LEFT_EDGE_X (w
);
2453 gy
+= WINDOW_TOP_EDGE_Y (w
);
2456 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2458 /* Visible feedback for debugging. */
2461 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2462 f
->output_data
.x
->normal_gc
,
2463 gx
, gy
, width
, height
);
2469 #endif /* HAVE_WINDOW_SYSTEM */
2472 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2475 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2476 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2478 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2481 /***********************************************************************
2482 Lisp form evaluation
2483 ***********************************************************************/
2485 /* Error handler for safe_eval and safe_call. */
2488 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2490 add_to_log ("Error during redisplay: %S signaled %S",
2491 Flist (nargs
, args
), arg
);
2495 /* Call function FUNC with the rest of NARGS - 1 arguments
2496 following. Return the result, or nil if something went
2497 wrong. Prevent redisplay during the evaluation. */
2500 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2504 if (inhibit_eval_during_redisplay
)
2510 ptrdiff_t count
= SPECPDL_INDEX ();
2511 struct gcpro gcpro1
;
2512 Lisp_Object
*args
= alloca (nargs
* word_size
);
2515 va_start (ap
, func
);
2516 for (i
= 1; i
< nargs
; i
++)
2517 args
[i
] = va_arg (ap
, Lisp_Object
);
2521 gcpro1
.nvars
= nargs
;
2522 specbind (Qinhibit_redisplay
, Qt
);
2523 /* Use Qt to ensure debugger does not run,
2524 so there is no possibility of wanting to redisplay. */
2525 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2528 val
= unbind_to (count
, val
);
2535 /* Call function FN with one argument ARG.
2536 Return the result, or nil if something went wrong. */
2539 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2541 return safe_call (2, fn
, arg
);
2544 static Lisp_Object Qeval
;
2547 safe_eval (Lisp_Object sexpr
)
2549 return safe_call1 (Qeval
, sexpr
);
2552 /* Call function FN with two arguments ARG1 and ARG2.
2553 Return the result, or nil if something went wrong. */
2556 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2558 return safe_call (3, fn
, arg1
, arg2
);
2563 /***********************************************************************
2565 ***********************************************************************/
2569 /* Define CHECK_IT to perform sanity checks on iterators.
2570 This is for debugging. It is too slow to do unconditionally. */
2573 check_it (struct it
*it
)
2575 if (it
->method
== GET_FROM_STRING
)
2577 eassert (STRINGP (it
->string
));
2578 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2582 eassert (IT_STRING_CHARPOS (*it
) < 0);
2583 if (it
->method
== GET_FROM_BUFFER
)
2585 /* Check that character and byte positions agree. */
2586 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2591 eassert (it
->current
.dpvec_index
>= 0);
2593 eassert (it
->current
.dpvec_index
< 0);
2596 #define CHECK_IT(IT) check_it ((IT))
2600 #define CHECK_IT(IT) (void) 0
2605 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2607 /* Check that the window end of window W is what we expect it
2608 to be---the last row in the current matrix displaying text. */
2611 check_window_end (struct window
*w
)
2613 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2615 struct glyph_row
*row
;
2616 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2618 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2619 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2623 #define CHECK_WINDOW_END(W) check_window_end ((W))
2627 #define CHECK_WINDOW_END(W) (void) 0
2629 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2631 /* Return mark position if current buffer has the region of non-zero length,
2635 markpos_of_region (void)
2637 if (!NILP (Vtransient_mark_mode
)
2638 && !NILP (BVAR (current_buffer
, mark_active
))
2639 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2641 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2649 /***********************************************************************
2650 Iterator initialization
2651 ***********************************************************************/
2653 /* Initialize IT for displaying current_buffer in window W, starting
2654 at character position CHARPOS. CHARPOS < 0 means that no buffer
2655 position is specified which is useful when the iterator is assigned
2656 a position later. BYTEPOS is the byte position corresponding to
2659 If ROW is not null, calls to produce_glyphs with IT as parameter
2660 will produce glyphs in that row.
2662 BASE_FACE_ID is the id of a base face to use. It must be one of
2663 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2664 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2665 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2667 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2668 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2669 will be initialized to use the corresponding mode line glyph row of
2670 the desired matrix of W. */
2673 init_iterator (struct it
*it
, struct window
*w
,
2674 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2675 struct glyph_row
*row
, enum face_id base_face_id
)
2678 enum face_id remapped_base_face_id
= base_face_id
;
2680 /* Some precondition checks. */
2681 eassert (w
!= NULL
&& it
!= NULL
);
2682 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2685 /* If face attributes have been changed since the last redisplay,
2686 free realized faces now because they depend on face definitions
2687 that might have changed. Don't free faces while there might be
2688 desired matrices pending which reference these faces. */
2689 if (face_change_count
&& !inhibit_free_realized_faces
)
2691 face_change_count
= 0;
2692 free_all_realized_faces (Qnil
);
2695 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2696 if (! NILP (Vface_remapping_alist
))
2697 remapped_base_face_id
2698 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2700 /* Use one of the mode line rows of W's desired matrix if
2704 if (base_face_id
== MODE_LINE_FACE_ID
2705 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2706 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2707 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2708 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2712 memset (it
, 0, sizeof *it
);
2713 it
->current
.overlay_string_index
= -1;
2714 it
->current
.dpvec_index
= -1;
2715 it
->base_face_id
= remapped_base_face_id
;
2717 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2718 it
->paragraph_embedding
= L2R
;
2719 it
->bidi_it
.string
.lstring
= Qnil
;
2720 it
->bidi_it
.string
.s
= NULL
;
2721 it
->bidi_it
.string
.bufpos
= 0;
2724 /* The window in which we iterate over current_buffer: */
2725 XSETWINDOW (it
->window
, w
);
2727 it
->f
= XFRAME (w
->frame
);
2731 /* Extra space between lines (on window systems only). */
2732 if (base_face_id
== DEFAULT_FACE_ID
2733 && FRAME_WINDOW_P (it
->f
))
2735 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2736 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2737 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2738 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2739 * FRAME_LINE_HEIGHT (it
->f
));
2740 else if (it
->f
->extra_line_spacing
> 0)
2741 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2742 it
->max_extra_line_spacing
= 0;
2745 /* If realized faces have been removed, e.g. because of face
2746 attribute changes of named faces, recompute them. When running
2747 in batch mode, the face cache of the initial frame is null. If
2748 we happen to get called, make a dummy face cache. */
2749 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2750 init_frame_faces (it
->f
);
2751 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2752 recompute_basic_faces (it
->f
);
2754 /* Current value of the `slice', `space-width', and 'height' properties. */
2755 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2756 it
->space_width
= Qnil
;
2757 it
->font_height
= Qnil
;
2758 it
->override_ascent
= -1;
2760 /* Are control characters displayed as `^C'? */
2761 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2763 /* -1 means everything between a CR and the following line end
2764 is invisible. >0 means lines indented more than this value are
2766 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2768 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2770 : (!NILP (BVAR (current_buffer
, selective_display
))
2772 it
->selective_display_ellipsis_p
2773 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2775 /* Display table to use. */
2776 it
->dp
= window_display_table (w
);
2778 /* Are multibyte characters enabled in current_buffer? */
2779 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2781 /* If visible region is of non-zero length, set IT->region_beg_charpos
2782 and IT->region_end_charpos to the start and end of a visible region
2783 in window IT->w. Set both to -1 to indicate no region. */
2784 markpos
= markpos_of_region ();
2786 /* Maybe highlight only in selected window. */
2787 && (/* Either show region everywhere. */
2788 highlight_nonselected_windows
2789 /* Or show region in the selected window. */
2790 || w
== XWINDOW (selected_window
)
2791 /* Or show the region if we are in the mini-buffer and W is
2792 the window the mini-buffer refers to. */
2793 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2794 && WINDOWP (minibuf_selected_window
)
2795 && w
== XWINDOW (minibuf_selected_window
))))
2797 it
->region_beg_charpos
= min (PT
, markpos
);
2798 it
->region_end_charpos
= max (PT
, markpos
);
2801 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2803 /* Get the position at which the redisplay_end_trigger hook should
2804 be run, if it is to be run at all. */
2805 if (MARKERP (w
->redisplay_end_trigger
)
2806 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2807 it
->redisplay_end_trigger_charpos
2808 = marker_position (w
->redisplay_end_trigger
);
2809 else if (INTEGERP (w
->redisplay_end_trigger
))
2810 it
->redisplay_end_trigger_charpos
=
2811 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2813 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2815 /* Are lines in the display truncated? */
2816 if (base_face_id
!= DEFAULT_FACE_ID
2818 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2819 && ((!NILP (Vtruncate_partial_width_windows
)
2820 && !INTEGERP (Vtruncate_partial_width_windows
))
2821 || (INTEGERP (Vtruncate_partial_width_windows
)
2822 && (WINDOW_TOTAL_COLS (it
->w
)
2823 < XINT (Vtruncate_partial_width_windows
))))))
2824 it
->line_wrap
= TRUNCATE
;
2825 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2826 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2827 ? WINDOW_WRAP
: WORD_WRAP
;
2829 it
->line_wrap
= TRUNCATE
;
2831 /* Get dimensions of truncation and continuation glyphs. These are
2832 displayed as fringe bitmaps under X, but we need them for such
2833 frames when the fringes are turned off. But leave the dimensions
2834 zero for tooltip frames, as these glyphs look ugly there and also
2835 sabotage calculations of tooltip dimensions in x-show-tip. */
2836 #ifdef HAVE_WINDOW_SYSTEM
2837 if (!(FRAME_WINDOW_P (it
->f
)
2838 && FRAMEP (tip_frame
)
2839 && it
->f
== XFRAME (tip_frame
)))
2842 if (it
->line_wrap
== TRUNCATE
)
2844 /* We will need the truncation glyph. */
2845 eassert (it
->glyph_row
== NULL
);
2846 produce_special_glyphs (it
, IT_TRUNCATION
);
2847 it
->truncation_pixel_width
= it
->pixel_width
;
2851 /* We will need the continuation glyph. */
2852 eassert (it
->glyph_row
== NULL
);
2853 produce_special_glyphs (it
, IT_CONTINUATION
);
2854 it
->continuation_pixel_width
= it
->pixel_width
;
2858 /* Reset these values to zero because the produce_special_glyphs
2859 above has changed them. */
2860 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2861 it
->phys_ascent
= it
->phys_descent
= 0;
2863 /* Set this after getting the dimensions of truncation and
2864 continuation glyphs, so that we don't produce glyphs when calling
2865 produce_special_glyphs, above. */
2866 it
->glyph_row
= row
;
2867 it
->area
= TEXT_AREA
;
2869 /* Forget any previous info about this row being reversed. */
2871 it
->glyph_row
->reversed_p
= 0;
2873 /* Get the dimensions of the display area. The display area
2874 consists of the visible window area plus a horizontally scrolled
2875 part to the left of the window. All x-values are relative to the
2876 start of this total display area. */
2877 if (base_face_id
!= DEFAULT_FACE_ID
)
2879 /* Mode lines, menu bar in terminal frames. */
2880 it
->first_visible_x
= 0;
2881 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2885 it
->first_visible_x
=
2886 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2887 it
->last_visible_x
= (it
->first_visible_x
2888 + window_box_width (w
, TEXT_AREA
));
2890 /* If we truncate lines, leave room for the truncation glyph(s) at
2891 the right margin. Otherwise, leave room for the continuation
2892 glyph(s). Done only if the window has no fringes. Since we
2893 don't know at this point whether there will be any R2L lines in
2894 the window, we reserve space for truncation/continuation glyphs
2895 even if only one of the fringes is absent. */
2896 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2897 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2899 if (it
->line_wrap
== TRUNCATE
)
2900 it
->last_visible_x
-= it
->truncation_pixel_width
;
2902 it
->last_visible_x
-= it
->continuation_pixel_width
;
2905 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2906 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2909 /* Leave room for a border glyph. */
2910 if (!FRAME_WINDOW_P (it
->f
)
2911 && !WINDOW_RIGHTMOST_P (it
->w
))
2912 it
->last_visible_x
-= 1;
2914 it
->last_visible_y
= window_text_bottom_y (w
);
2916 /* For mode lines and alike, arrange for the first glyph having a
2917 left box line if the face specifies a box. */
2918 if (base_face_id
!= DEFAULT_FACE_ID
)
2922 it
->face_id
= remapped_base_face_id
;
2924 /* If we have a boxed mode line, make the first character appear
2925 with a left box line. */
2926 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2927 if (face
->box
!= FACE_NO_BOX
)
2928 it
->start_of_box_run_p
= 1;
2931 /* If a buffer position was specified, set the iterator there,
2932 getting overlays and face properties from that position. */
2933 if (charpos
>= BUF_BEG (current_buffer
))
2935 it
->end_charpos
= ZV
;
2936 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2937 IT_CHARPOS (*it
) = charpos
;
2938 IT_BYTEPOS (*it
) = bytepos
;
2940 /* We will rely on `reseat' to set this up properly, via
2941 handle_face_prop. */
2942 it
->face_id
= it
->base_face_id
;
2944 it
->start
= it
->current
;
2945 /* Do we need to reorder bidirectional text? Not if this is a
2946 unibyte buffer: by definition, none of the single-byte
2947 characters are strong R2L, so no reordering is needed. And
2948 bidi.c doesn't support unibyte buffers anyway. Also, don't
2949 reorder while we are loading loadup.el, since the tables of
2950 character properties needed for reordering are not yet
2954 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2957 /* If we are to reorder bidirectional text, init the bidi
2961 /* Note the paragraph direction that this buffer wants to
2963 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2965 it
->paragraph_embedding
= L2R
;
2966 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2968 it
->paragraph_embedding
= R2L
;
2970 it
->paragraph_embedding
= NEUTRAL_DIR
;
2971 bidi_unshelve_cache (NULL
, 0);
2972 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2976 /* Compute faces etc. */
2977 reseat (it
, it
->current
.pos
, 1);
2984 /* Initialize IT for the display of window W with window start POS. */
2987 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2989 struct glyph_row
*row
;
2990 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2992 row
= w
->desired_matrix
->rows
+ first_vpos
;
2993 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2994 it
->first_vpos
= first_vpos
;
2996 /* Don't reseat to previous visible line start if current start
2997 position is in a string or image. */
2998 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3000 int start_at_line_beg_p
;
3001 int first_y
= it
->current_y
;
3003 /* If window start is not at a line start, skip forward to POS to
3004 get the correct continuation lines width. */
3005 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3006 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3007 if (!start_at_line_beg_p
)
3011 reseat_at_previous_visible_line_start (it
);
3012 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3014 new_x
= it
->current_x
+ it
->pixel_width
;
3016 /* If lines are continued, this line may end in the middle
3017 of a multi-glyph character (e.g. a control character
3018 displayed as \003, or in the middle of an overlay
3019 string). In this case move_it_to above will not have
3020 taken us to the start of the continuation line but to the
3021 end of the continued line. */
3022 if (it
->current_x
> 0
3023 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3024 && (/* And glyph doesn't fit on the line. */
3025 new_x
> it
->last_visible_x
3026 /* Or it fits exactly and we're on a window
3028 || (new_x
== it
->last_visible_x
3029 && FRAME_WINDOW_P (it
->f
)
3030 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3031 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3032 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3034 if ((it
->current
.dpvec_index
>= 0
3035 || it
->current
.overlay_string_index
>= 0)
3036 /* If we are on a newline from a display vector or
3037 overlay string, then we are already at the end of
3038 a screen line; no need to go to the next line in
3039 that case, as this line is not really continued.
3040 (If we do go to the next line, C-e will not DTRT.) */
3043 set_iterator_to_next (it
, 1);
3044 move_it_in_display_line_to (it
, -1, -1, 0);
3047 it
->continuation_lines_width
+= it
->current_x
;
3049 /* If the character at POS is displayed via a display
3050 vector, move_it_to above stops at the final glyph of
3051 IT->dpvec. To make the caller redisplay that character
3052 again (a.k.a. start at POS), we need to reset the
3053 dpvec_index to the beginning of IT->dpvec. */
3054 else if (it
->current
.dpvec_index
>= 0)
3055 it
->current
.dpvec_index
= 0;
3057 /* We're starting a new display line, not affected by the
3058 height of the continued line, so clear the appropriate
3059 fields in the iterator structure. */
3060 it
->max_ascent
= it
->max_descent
= 0;
3061 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3063 it
->current_y
= first_y
;
3065 it
->current_x
= it
->hpos
= 0;
3071 /* Return 1 if POS is a position in ellipses displayed for invisible
3072 text. W is the window we display, for text property lookup. */
3075 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3077 Lisp_Object prop
, window
;
3079 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3081 /* If POS specifies a position in a display vector, this might
3082 be for an ellipsis displayed for invisible text. We won't
3083 get the iterator set up for delivering that ellipsis unless
3084 we make sure that it gets aware of the invisible text. */
3085 if (pos
->dpvec_index
>= 0
3086 && pos
->overlay_string_index
< 0
3087 && CHARPOS (pos
->string_pos
) < 0
3089 && (XSETWINDOW (window
, w
),
3090 prop
= Fget_char_property (make_number (charpos
),
3091 Qinvisible
, window
),
3092 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3094 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3096 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3103 /* Initialize IT for stepping through current_buffer in window W,
3104 starting at position POS that includes overlay string and display
3105 vector/ control character translation position information. Value
3106 is zero if there are overlay strings with newlines at POS. */
3109 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3111 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3112 int i
, overlay_strings_with_newlines
= 0;
3114 /* If POS specifies a position in a display vector, this might
3115 be for an ellipsis displayed for invisible text. We won't
3116 get the iterator set up for delivering that ellipsis unless
3117 we make sure that it gets aware of the invisible text. */
3118 if (in_ellipses_for_invisible_text_p (pos
, w
))
3124 /* Keep in mind: the call to reseat in init_iterator skips invisible
3125 text, so we might end up at a position different from POS. This
3126 is only a problem when POS is a row start after a newline and an
3127 overlay starts there with an after-string, and the overlay has an
3128 invisible property. Since we don't skip invisible text in
3129 display_line and elsewhere immediately after consuming the
3130 newline before the row start, such a POS will not be in a string,
3131 but the call to init_iterator below will move us to the
3133 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3135 /* This only scans the current chunk -- it should scan all chunks.
3136 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3137 to 16 in 22.1 to make this a lesser problem. */
3138 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3140 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3141 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3143 while (s
< e
&& *s
!= '\n')
3148 overlay_strings_with_newlines
= 1;
3153 /* If position is within an overlay string, set up IT to the right
3155 if (pos
->overlay_string_index
>= 0)
3159 /* If the first overlay string happens to have a `display'
3160 property for an image, the iterator will be set up for that
3161 image, and we have to undo that setup first before we can
3162 correct the overlay string index. */
3163 if (it
->method
== GET_FROM_IMAGE
)
3166 /* We already have the first chunk of overlay strings in
3167 IT->overlay_strings. Load more until the one for
3168 pos->overlay_string_index is in IT->overlay_strings. */
3169 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3171 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3172 it
->current
.overlay_string_index
= 0;
3175 load_overlay_strings (it
, 0);
3176 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3180 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3181 relative_index
= (it
->current
.overlay_string_index
3182 % OVERLAY_STRING_CHUNK_SIZE
);
3183 it
->string
= it
->overlay_strings
[relative_index
];
3184 eassert (STRINGP (it
->string
));
3185 it
->current
.string_pos
= pos
->string_pos
;
3186 it
->method
= GET_FROM_STRING
;
3187 it
->end_charpos
= SCHARS (it
->string
);
3188 /* Set up the bidi iterator for this overlay string. */
3191 it
->bidi_it
.string
.lstring
= it
->string
;
3192 it
->bidi_it
.string
.s
= NULL
;
3193 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3194 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3195 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3196 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3197 it
->bidi_it
.w
= it
->w
;
3198 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3199 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3201 /* Synchronize the state of the bidi iterator with
3202 pos->string_pos. For any string position other than
3203 zero, this will be done automagically when we resume
3204 iteration over the string and get_visually_first_element
3205 is called. But if string_pos is zero, and the string is
3206 to be reordered for display, we need to resync manually,
3207 since it could be that the iteration state recorded in
3208 pos ended at string_pos of 0 moving backwards in string. */
3209 if (CHARPOS (pos
->string_pos
) == 0)
3211 get_visually_first_element (it
);
3212 if (IT_STRING_CHARPOS (*it
) != 0)
3215 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3216 bidi_move_to_visually_next (&it
->bidi_it
);
3217 } while (it
->bidi_it
.charpos
!= 0);
3219 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3220 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3224 if (CHARPOS (pos
->string_pos
) >= 0)
3226 /* Recorded position is not in an overlay string, but in another
3227 string. This can only be a string from a `display' property.
3228 IT should already be filled with that string. */
3229 it
->current
.string_pos
= pos
->string_pos
;
3230 eassert (STRINGP (it
->string
));
3232 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3233 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3236 /* Restore position in display vector translations, control
3237 character translations or ellipses. */
3238 if (pos
->dpvec_index
>= 0)
3240 if (it
->dpvec
== NULL
)
3241 get_next_display_element (it
);
3242 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3243 it
->current
.dpvec_index
= pos
->dpvec_index
;
3247 return !overlay_strings_with_newlines
;
3251 /* Initialize IT for stepping through current_buffer in window W
3252 starting at ROW->start. */
3255 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3257 init_from_display_pos (it
, w
, &row
->start
);
3258 it
->start
= row
->start
;
3259 it
->continuation_lines_width
= row
->continuation_lines_width
;
3264 /* Initialize IT for stepping through current_buffer in window W
3265 starting in the line following ROW, i.e. starting at ROW->end.
3266 Value is zero if there are overlay strings with newlines at ROW's
3270 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3274 if (init_from_display_pos (it
, w
, &row
->end
))
3276 if (row
->continued_p
)
3277 it
->continuation_lines_width
3278 = row
->continuation_lines_width
+ row
->pixel_width
;
3289 /***********************************************************************
3291 ***********************************************************************/
3293 /* Called when IT reaches IT->stop_charpos. Handle text property and
3294 overlay changes. Set IT->stop_charpos to the next position where
3298 handle_stop (struct it
*it
)
3300 enum prop_handled handled
;
3301 int handle_overlay_change_p
;
3305 it
->current
.dpvec_index
= -1;
3306 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3307 it
->ignore_overlay_strings_at_pos_p
= 0;
3310 /* Use face of preceding text for ellipsis (if invisible) */
3311 if (it
->selective_display_ellipsis_p
)
3312 it
->saved_face_id
= it
->face_id
;
3316 handled
= HANDLED_NORMALLY
;
3318 /* Call text property handlers. */
3319 for (p
= it_props
; p
->handler
; ++p
)
3321 handled
= p
->handler (it
);
3323 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3325 else if (handled
== HANDLED_RETURN
)
3327 /* We still want to show before and after strings from
3328 overlays even if the actual buffer text is replaced. */
3329 if (!handle_overlay_change_p
3331 /* Don't call get_overlay_strings_1 if we already
3332 have overlay strings loaded, because doing so
3333 will load them again and push the iterator state
3334 onto the stack one more time, which is not
3335 expected by the rest of the code that processes
3337 || (it
->current
.overlay_string_index
< 0
3338 ? !get_overlay_strings_1 (it
, 0, 0)
3342 setup_for_ellipsis (it
, 0);
3343 /* When handling a display spec, we might load an
3344 empty string. In that case, discard it here. We
3345 used to discard it in handle_single_display_spec,
3346 but that causes get_overlay_strings_1, above, to
3347 ignore overlay strings that we must check. */
3348 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3352 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3356 it
->ignore_overlay_strings_at_pos_p
= 1;
3357 it
->string_from_display_prop_p
= 0;
3358 it
->from_disp_prop_p
= 0;
3359 handle_overlay_change_p
= 0;
3361 handled
= HANDLED_RECOMPUTE_PROPS
;
3364 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3365 handle_overlay_change_p
= 0;
3368 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3370 /* Don't check for overlay strings below when set to deliver
3371 characters from a display vector. */
3372 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3373 handle_overlay_change_p
= 0;
3375 /* Handle overlay changes.
3376 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3377 if it finds overlays. */
3378 if (handle_overlay_change_p
)
3379 handled
= handle_overlay_change (it
);
3384 setup_for_ellipsis (it
, 0);
3388 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3390 /* Determine where to stop next. */
3391 if (handled
== HANDLED_NORMALLY
)
3392 compute_stop_pos (it
);
3396 /* Compute IT->stop_charpos from text property and overlay change
3397 information for IT's current position. */
3400 compute_stop_pos (struct it
*it
)
3402 register INTERVAL iv
, next_iv
;
3403 Lisp_Object object
, limit
, position
;
3404 ptrdiff_t charpos
, bytepos
;
3406 if (STRINGP (it
->string
))
3408 /* Strings are usually short, so don't limit the search for
3410 it
->stop_charpos
= it
->end_charpos
;
3411 object
= it
->string
;
3413 charpos
= IT_STRING_CHARPOS (*it
);
3414 bytepos
= IT_STRING_BYTEPOS (*it
);
3420 /* If end_charpos is out of range for some reason, such as a
3421 misbehaving display function, rationalize it (Bug#5984). */
3422 if (it
->end_charpos
> ZV
)
3423 it
->end_charpos
= ZV
;
3424 it
->stop_charpos
= it
->end_charpos
;
3426 /* If next overlay change is in front of the current stop pos
3427 (which is IT->end_charpos), stop there. Note: value of
3428 next_overlay_change is point-max if no overlay change
3430 charpos
= IT_CHARPOS (*it
);
3431 bytepos
= IT_BYTEPOS (*it
);
3432 pos
= next_overlay_change (charpos
);
3433 if (pos
< it
->stop_charpos
)
3434 it
->stop_charpos
= pos
;
3436 /* If showing the region, we have to stop at the region
3437 start or end because the face might change there. */
3438 if (it
->region_beg_charpos
> 0)
3440 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3441 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3442 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3443 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3446 /* Set up variables for computing the stop position from text
3447 property changes. */
3448 XSETBUFFER (object
, current_buffer
);
3449 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3452 /* Get the interval containing IT's position. Value is a null
3453 interval if there isn't such an interval. */
3454 position
= make_number (charpos
);
3455 iv
= validate_interval_range (object
, &position
, &position
, 0);
3458 Lisp_Object values_here
[LAST_PROP_IDX
];
3461 /* Get properties here. */
3462 for (p
= it_props
; p
->handler
; ++p
)
3463 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3465 /* Look for an interval following iv that has different
3467 for (next_iv
= next_interval (iv
);
3470 || XFASTINT (limit
) > next_iv
->position
));
3471 next_iv
= next_interval (next_iv
))
3473 for (p
= it_props
; p
->handler
; ++p
)
3475 Lisp_Object new_value
;
3477 new_value
= textget (next_iv
->plist
, *p
->name
);
3478 if (!EQ (values_here
[p
->idx
], new_value
))
3488 if (INTEGERP (limit
)
3489 && next_iv
->position
>= XFASTINT (limit
))
3490 /* No text property change up to limit. */
3491 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3493 /* Text properties change in next_iv. */
3494 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3498 if (it
->cmp_it
.id
< 0)
3500 ptrdiff_t stoppos
= it
->end_charpos
;
3502 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3504 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3505 stoppos
, it
->string
);
3508 eassert (STRINGP (it
->string
)
3509 || (it
->stop_charpos
>= BEGV
3510 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3514 /* Return the position of the next overlay change after POS in
3515 current_buffer. Value is point-max if no overlay change
3516 follows. This is like `next-overlay-change' but doesn't use
3520 next_overlay_change (ptrdiff_t pos
)
3522 ptrdiff_t i
, noverlays
;
3524 Lisp_Object
*overlays
;
3526 /* Get all overlays at the given position. */
3527 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3529 /* If any of these overlays ends before endpos,
3530 use its ending point instead. */
3531 for (i
= 0; i
< noverlays
; ++i
)
3536 oend
= OVERLAY_END (overlays
[i
]);
3537 oendpos
= OVERLAY_POSITION (oend
);
3538 endpos
= min (endpos
, oendpos
);
3544 /* How many characters forward to search for a display property or
3545 display string. Searching too far forward makes the bidi display
3546 sluggish, especially in small windows. */
3547 #define MAX_DISP_SCAN 250
3549 /* Return the character position of a display string at or after
3550 position specified by POSITION. If no display string exists at or
3551 after POSITION, return ZV. A display string is either an overlay
3552 with `display' property whose value is a string, or a `display'
3553 text property whose value is a string. STRING is data about the
3554 string to iterate; if STRING->lstring is nil, we are iterating a
3555 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3556 on a GUI frame. DISP_PROP is set to zero if we searched
3557 MAX_DISP_SCAN characters forward without finding any display
3558 strings, non-zero otherwise. It is set to 2 if the display string
3559 uses any kind of `(space ...)' spec that will produce a stretch of
3560 white space in the text area. */
3562 compute_display_string_pos (struct text_pos
*position
,
3563 struct bidi_string_data
*string
,
3565 int frame_window_p
, int *disp_prop
)
3567 /* OBJECT = nil means current buffer. */
3568 Lisp_Object object
, object1
;
3569 Lisp_Object pos
, spec
, limpos
;
3570 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3571 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3572 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3573 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3575 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3576 struct text_pos tpos
;
3579 if (string
&& STRINGP (string
->lstring
))
3580 object1
= object
= string
->lstring
;
3581 else if (w
&& !string_p
)
3583 XSETWINDOW (object
, w
);
3587 object1
= object
= Qnil
;
3592 /* We don't support display properties whose values are strings
3593 that have display string properties. */
3594 || string
->from_disp_str
3595 /* C strings cannot have display properties. */
3596 || (string
->s
&& !STRINGP (object
)))
3602 /* If the character at CHARPOS is where the display string begins,
3604 pos
= make_number (charpos
);
3605 if (STRINGP (object
))
3606 bufpos
= string
->bufpos
;
3610 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3612 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3615 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3623 /* Look forward for the first character with a `display' property
3624 that will replace the underlying text when displayed. */
3625 limpos
= make_number (lim
);
3627 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3628 CHARPOS (tpos
) = XFASTINT (pos
);
3629 if (CHARPOS (tpos
) >= lim
)
3634 if (STRINGP (object
))
3635 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3637 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3638 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3639 if (!STRINGP (object
))
3640 bufpos
= CHARPOS (tpos
);
3641 } while (NILP (spec
)
3642 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3643 bufpos
, frame_window_p
)));
3647 return CHARPOS (tpos
);
3650 /* Return the character position of the end of the display string that
3651 started at CHARPOS. If there's no display string at CHARPOS,
3652 return -1. A display string is either an overlay with `display'
3653 property whose value is a string or a `display' text property whose
3654 value is a string. */
3656 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3658 /* OBJECT = nil means current buffer. */
3659 Lisp_Object object
=
3660 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3661 Lisp_Object pos
= make_number (charpos
);
3663 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3665 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3668 /* It could happen that the display property or overlay was removed
3669 since we found it in compute_display_string_pos above. One way
3670 this can happen is if JIT font-lock was called (through
3671 handle_fontified_prop), and jit-lock-functions remove text
3672 properties or overlays from the portion of buffer that includes
3673 CHARPOS. Muse mode is known to do that, for example. In this
3674 case, we return -1 to the caller, to signal that no display
3675 string is actually present at CHARPOS. See bidi_fetch_char for
3676 how this is handled.
3678 An alternative would be to never look for display properties past
3679 it->stop_charpos. But neither compute_display_string_pos nor
3680 bidi_fetch_char that calls it know or care where the next
3682 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3685 /* Look forward for the first character where the `display' property
3687 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3689 return XFASTINT (pos
);
3694 /***********************************************************************
3696 ***********************************************************************/
3698 /* Handle changes in the `fontified' property of the current buffer by
3699 calling hook functions from Qfontification_functions to fontify
3702 static enum prop_handled
3703 handle_fontified_prop (struct it
*it
)
3705 Lisp_Object prop
, pos
;
3706 enum prop_handled handled
= HANDLED_NORMALLY
;
3708 if (!NILP (Vmemory_full
))
3711 /* Get the value of the `fontified' property at IT's current buffer
3712 position. (The `fontified' property doesn't have a special
3713 meaning in strings.) If the value is nil, call functions from
3714 Qfontification_functions. */
3715 if (!STRINGP (it
->string
)
3717 && !NILP (Vfontification_functions
)
3718 && !NILP (Vrun_hooks
)
3719 && (pos
= make_number (IT_CHARPOS (*it
)),
3720 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3721 /* Ignore the special cased nil value always present at EOB since
3722 no amount of fontifying will be able to change it. */
3723 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3725 ptrdiff_t count
= SPECPDL_INDEX ();
3727 struct buffer
*obuf
= current_buffer
;
3728 int begv
= BEGV
, zv
= ZV
;
3729 int old_clip_changed
= current_buffer
->clip_changed
;
3731 val
= Vfontification_functions
;
3732 specbind (Qfontification_functions
, Qnil
);
3734 eassert (it
->end_charpos
== ZV
);
3736 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3737 safe_call1 (val
, pos
);
3740 Lisp_Object fns
, fn
;
3741 struct gcpro gcpro1
, gcpro2
;
3746 for (; CONSP (val
); val
= XCDR (val
))
3752 /* A value of t indicates this hook has a local
3753 binding; it means to run the global binding too.
3754 In a global value, t should not occur. If it
3755 does, we must ignore it to avoid an endless
3757 for (fns
= Fdefault_value (Qfontification_functions
);
3763 safe_call1 (fn
, pos
);
3767 safe_call1 (fn
, pos
);
3773 unbind_to (count
, Qnil
);
3775 /* Fontification functions routinely call `save-restriction'.
3776 Normally, this tags clip_changed, which can confuse redisplay
3777 (see discussion in Bug#6671). Since we don't perform any
3778 special handling of fontification changes in the case where
3779 `save-restriction' isn't called, there's no point doing so in
3780 this case either. So, if the buffer's restrictions are
3781 actually left unchanged, reset clip_changed. */
3782 if (obuf
== current_buffer
)
3784 if (begv
== BEGV
&& zv
== ZV
)
3785 current_buffer
->clip_changed
= old_clip_changed
;
3787 /* There isn't much we can reasonably do to protect against
3788 misbehaving fontification, but here's a fig leaf. */
3789 else if (BUFFER_LIVE_P (obuf
))
3790 set_buffer_internal_1 (obuf
);
3792 /* The fontification code may have added/removed text.
3793 It could do even a lot worse, but let's at least protect against
3794 the most obvious case where only the text past `pos' gets changed',
3795 as is/was done in grep.el where some escapes sequences are turned
3796 into face properties (bug#7876). */
3797 it
->end_charpos
= ZV
;
3799 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3800 something. This avoids an endless loop if they failed to
3801 fontify the text for which reason ever. */
3802 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3803 handled
= HANDLED_RECOMPUTE_PROPS
;
3811 /***********************************************************************
3813 ***********************************************************************/
3815 /* Set up iterator IT from face properties at its current position.
3816 Called from handle_stop. */
3818 static enum prop_handled
3819 handle_face_prop (struct it
*it
)
3822 ptrdiff_t next_stop
;
3824 if (!STRINGP (it
->string
))
3827 = face_at_buffer_position (it
->w
,
3829 it
->region_beg_charpos
,
3830 it
->region_end_charpos
,
3833 + TEXT_PROP_DISTANCE_LIMIT
),
3834 0, it
->base_face_id
);
3836 /* Is this a start of a run of characters with box face?
3837 Caveat: this can be called for a freshly initialized
3838 iterator; face_id is -1 in this case. We know that the new
3839 face will not change until limit, i.e. if the new face has a
3840 box, all characters up to limit will have one. But, as
3841 usual, we don't know whether limit is really the end. */
3842 if (new_face_id
!= it
->face_id
)
3844 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3845 /* If it->face_id is -1, old_face below will be NULL, see
3846 the definition of FACE_FROM_ID. This will happen if this
3847 is the initial call that gets the face. */
3848 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3850 /* If the value of face_id of the iterator is -1, we have to
3851 look in front of IT's position and see whether there is a
3852 face there that's different from new_face_id. */
3853 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3855 int prev_face_id
= face_before_it_pos (it
);
3857 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3860 /* If the new face has a box, but the old face does not,
3861 this is the start of a run of characters with box face,
3862 i.e. this character has a shadow on the left side. */
3863 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3864 && (old_face
== NULL
|| !old_face
->box
));
3865 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3873 Lisp_Object from_overlay
3874 = (it
->current
.overlay_string_index
>= 0
3875 ? it
->string_overlays
[it
->current
.overlay_string_index
3876 % OVERLAY_STRING_CHUNK_SIZE
]
3879 /* See if we got to this string directly or indirectly from
3880 an overlay property. That includes the before-string or
3881 after-string of an overlay, strings in display properties
3882 provided by an overlay, their text properties, etc.
3884 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3885 if (! NILP (from_overlay
))
3886 for (i
= it
->sp
- 1; i
>= 0; i
--)
3888 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3890 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3891 % OVERLAY_STRING_CHUNK_SIZE
];
3892 else if (! NILP (it
->stack
[i
].from_overlay
))
3893 from_overlay
= it
->stack
[i
].from_overlay
;
3895 if (!NILP (from_overlay
))
3899 if (! NILP (from_overlay
))
3901 bufpos
= IT_CHARPOS (*it
);
3902 /* For a string from an overlay, the base face depends
3903 only on text properties and ignores overlays. */
3905 = face_for_overlay_string (it
->w
,
3907 it
->region_beg_charpos
,
3908 it
->region_end_charpos
,
3911 + TEXT_PROP_DISTANCE_LIMIT
),
3919 /* For strings from a `display' property, use the face at
3920 IT's current buffer position as the base face to merge
3921 with, so that overlay strings appear in the same face as
3922 surrounding text, unless they specify their own faces.
3923 For strings from wrap-prefix and line-prefix properties,
3924 use the default face, possibly remapped via
3925 Vface_remapping_alist. */
3926 base_face_id
= it
->string_from_prefix_prop_p
3927 ? (!NILP (Vface_remapping_alist
)
3928 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3930 : underlying_face_id (it
);
3933 new_face_id
= face_at_string_position (it
->w
,
3935 IT_STRING_CHARPOS (*it
),
3937 it
->region_beg_charpos
,
3938 it
->region_end_charpos
,
3942 /* Is this a start of a run of characters with box? Caveat:
3943 this can be called for a freshly allocated iterator; face_id
3944 is -1 is this case. We know that the new face will not
3945 change until the next check pos, i.e. if the new face has a
3946 box, all characters up to that position will have a
3947 box. But, as usual, we don't know whether that position
3948 is really the end. */
3949 if (new_face_id
!= it
->face_id
)
3951 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3952 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3954 /* If new face has a box but old face hasn't, this is the
3955 start of a run of characters with box, i.e. it has a
3956 shadow on the left side. */
3957 it
->start_of_box_run_p
3958 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3959 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3963 it
->face_id
= new_face_id
;
3964 return HANDLED_NORMALLY
;
3968 /* Return the ID of the face ``underlying'' IT's current position,
3969 which is in a string. If the iterator is associated with a
3970 buffer, return the face at IT's current buffer position.
3971 Otherwise, use the iterator's base_face_id. */
3974 underlying_face_id (struct it
*it
)
3976 int face_id
= it
->base_face_id
, i
;
3978 eassert (STRINGP (it
->string
));
3980 for (i
= it
->sp
- 1; i
>= 0; --i
)
3981 if (NILP (it
->stack
[i
].string
))
3982 face_id
= it
->stack
[i
].face_id
;
3988 /* Compute the face one character before or after the current position
3989 of IT, in the visual order. BEFORE_P non-zero means get the face
3990 in front (to the left in L2R paragraphs, to the right in R2L
3991 paragraphs) of IT's screen position. Value is the ID of the face. */
3994 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3997 ptrdiff_t next_check_charpos
;
3999 void *it_copy_data
= NULL
;
4001 eassert (it
->s
== NULL
);
4003 if (STRINGP (it
->string
))
4005 ptrdiff_t bufpos
, charpos
;
4008 /* No face change past the end of the string (for the case
4009 we are padding with spaces). No face change before the
4011 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4012 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4017 /* Set charpos to the position before or after IT's current
4018 position, in the logical order, which in the non-bidi
4019 case is the same as the visual order. */
4021 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4022 else if (it
->what
== IT_COMPOSITION
)
4023 /* For composition, we must check the character after the
4025 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4027 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4033 /* With bidi iteration, the character before the current
4034 in the visual order cannot be found by simple
4035 iteration, because "reverse" reordering is not
4036 supported. Instead, we need to use the move_it_*
4037 family of functions. */
4038 /* Ignore face changes before the first visible
4039 character on this display line. */
4040 if (it
->current_x
<= it
->first_visible_x
)
4042 SAVE_IT (it_copy
, *it
, it_copy_data
);
4043 /* Implementation note: Since move_it_in_display_line
4044 works in the iterator geometry, and thinks the first
4045 character is always the leftmost, even in R2L lines,
4046 we don't need to distinguish between the R2L and L2R
4048 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4049 it_copy
.current_x
- 1, MOVE_TO_X
);
4050 charpos
= IT_STRING_CHARPOS (it_copy
);
4051 RESTORE_IT (it
, it
, it_copy_data
);
4055 /* Set charpos to the string position of the character
4056 that comes after IT's current position in the visual
4058 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4062 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4064 charpos
= it_copy
.bidi_it
.charpos
;
4067 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4069 if (it
->current
.overlay_string_index
>= 0)
4070 bufpos
= IT_CHARPOS (*it
);
4074 base_face_id
= underlying_face_id (it
);
4076 /* Get the face for ASCII, or unibyte. */
4077 face_id
= face_at_string_position (it
->w
,
4081 it
->region_beg_charpos
,
4082 it
->region_end_charpos
,
4083 &next_check_charpos
,
4086 /* Correct the face for charsets different from ASCII. Do it
4087 for the multibyte case only. The face returned above is
4088 suitable for unibyte text if IT->string is unibyte. */
4089 if (STRING_MULTIBYTE (it
->string
))
4091 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4092 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4094 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4096 c
= string_char_and_length (p
, &len
);
4097 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4102 struct text_pos pos
;
4104 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4105 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4108 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4109 pos
= it
->current
.pos
;
4114 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4117 if (it
->what
== IT_COMPOSITION
)
4119 /* For composition, we must check the position after
4121 pos
.charpos
+= it
->cmp_it
.nchars
;
4122 pos
.bytepos
+= it
->len
;
4125 INC_TEXT_POS (pos
, it
->multibyte_p
);
4132 /* With bidi iteration, the character before the current
4133 in the visual order cannot be found by simple
4134 iteration, because "reverse" reordering is not
4135 supported. Instead, we need to use the move_it_*
4136 family of functions. */
4137 /* Ignore face changes before the first visible
4138 character on this display line. */
4139 if (it
->current_x
<= it
->first_visible_x
)
4141 SAVE_IT (it_copy
, *it
, it_copy_data
);
4142 /* Implementation note: Since move_it_in_display_line
4143 works in the iterator geometry, and thinks the first
4144 character is always the leftmost, even in R2L lines,
4145 we don't need to distinguish between the R2L and L2R
4147 move_it_in_display_line (&it_copy
, ZV
,
4148 it_copy
.current_x
- 1, MOVE_TO_X
);
4149 pos
= it_copy
.current
.pos
;
4150 RESTORE_IT (it
, it
, it_copy_data
);
4154 /* Set charpos to the buffer position of the character
4155 that comes after IT's current position in the visual
4157 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4161 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4164 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4167 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4169 /* Determine face for CHARSET_ASCII, or unibyte. */
4170 face_id
= face_at_buffer_position (it
->w
,
4172 it
->region_beg_charpos
,
4173 it
->region_end_charpos
,
4174 &next_check_charpos
,
4177 /* Correct the face for charsets different from ASCII. Do it
4178 for the multibyte case only. The face returned above is
4179 suitable for unibyte text if current_buffer is unibyte. */
4180 if (it
->multibyte_p
)
4182 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4183 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4184 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4193 /***********************************************************************
4195 ***********************************************************************/
4197 /* Set up iterator IT from invisible properties at its current
4198 position. Called from handle_stop. */
4200 static enum prop_handled
4201 handle_invisible_prop (struct it
*it
)
4203 enum prop_handled handled
= HANDLED_NORMALLY
;
4207 if (STRINGP (it
->string
))
4209 Lisp_Object end_charpos
, limit
, charpos
;
4211 /* Get the value of the invisible text property at the
4212 current position. Value will be nil if there is no such
4214 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4215 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4216 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4218 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4220 /* Record whether we have to display an ellipsis for the
4222 int display_ellipsis_p
= (invis_p
== 2);
4223 ptrdiff_t len
, endpos
;
4225 handled
= HANDLED_RECOMPUTE_PROPS
;
4227 /* Get the position at which the next visible text can be
4228 found in IT->string, if any. */
4229 endpos
= len
= SCHARS (it
->string
);
4230 XSETINT (limit
, len
);
4233 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4235 if (INTEGERP (end_charpos
))
4237 endpos
= XFASTINT (end_charpos
);
4238 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4239 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4241 display_ellipsis_p
= 1;
4244 while (invis_p
&& endpos
< len
);
4246 if (display_ellipsis_p
)
4251 /* Text at END_CHARPOS is visible. Move IT there. */
4252 struct text_pos old
;
4255 old
= it
->current
.string_pos
;
4256 oldpos
= CHARPOS (old
);
4259 if (it
->bidi_it
.first_elt
4260 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4261 bidi_paragraph_init (it
->paragraph_embedding
,
4263 /* Bidi-iterate out of the invisible text. */
4266 bidi_move_to_visually_next (&it
->bidi_it
);
4268 while (oldpos
<= it
->bidi_it
.charpos
4269 && it
->bidi_it
.charpos
< endpos
);
4271 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4272 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4273 if (IT_CHARPOS (*it
) >= endpos
)
4274 it
->prev_stop
= endpos
;
4278 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4279 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4284 /* The rest of the string is invisible. If this is an
4285 overlay string, proceed with the next overlay string
4286 or whatever comes and return a character from there. */
4287 if (it
->current
.overlay_string_index
>= 0
4288 && !display_ellipsis_p
)
4290 next_overlay_string (it
);
4291 /* Don't check for overlay strings when we just
4292 finished processing them. */
4293 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4297 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4298 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4305 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4306 Lisp_Object pos
, overlay
;
4308 /* First of all, is there invisible text at this position? */
4309 tem
= start_charpos
= IT_CHARPOS (*it
);
4310 pos
= make_number (tem
);
4311 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4313 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4315 /* If we are on invisible text, skip over it. */
4316 if (invis_p
&& start_charpos
< it
->end_charpos
)
4318 /* Record whether we have to display an ellipsis for the
4320 int display_ellipsis_p
= invis_p
== 2;
4322 handled
= HANDLED_RECOMPUTE_PROPS
;
4324 /* Loop skipping over invisible text. The loop is left at
4325 ZV or with IT on the first char being visible again. */
4328 /* Try to skip some invisible text. Return value is the
4329 position reached which can be equal to where we start
4330 if there is nothing invisible there. This skips both
4331 over invisible text properties and overlays with
4332 invisible property. */
4333 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4335 /* If we skipped nothing at all we weren't at invisible
4336 text in the first place. If everything to the end of
4337 the buffer was skipped, end the loop. */
4338 if (newpos
== tem
|| newpos
>= ZV
)
4342 /* We skipped some characters but not necessarily
4343 all there are. Check if we ended up on visible
4344 text. Fget_char_property returns the property of
4345 the char before the given position, i.e. if we
4346 get invis_p = 0, this means that the char at
4347 newpos is visible. */
4348 pos
= make_number (newpos
);
4349 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4350 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4353 /* If we ended up on invisible text, proceed to
4354 skip starting with next_stop. */
4358 /* If there are adjacent invisible texts, don't lose the
4359 second one's ellipsis. */
4361 display_ellipsis_p
= 1;
4365 /* The position newpos is now either ZV or on visible text. */
4368 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4370 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4372 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4374 /* If the invisible text ends on a newline or on a
4375 character after a newline, we can avoid the costly,
4376 character by character, bidi iteration to NEWPOS, and
4377 instead simply reseat the iterator there. That's
4378 because all bidi reordering information is tossed at
4379 the newline. This is a big win for modes that hide
4380 complete lines, like Outline, Org, etc. */
4381 if (on_newline
|| after_newline
)
4383 struct text_pos tpos
;
4384 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4386 SET_TEXT_POS (tpos
, newpos
, bpos
);
4387 reseat_1 (it
, tpos
, 0);
4388 /* If we reseat on a newline/ZV, we need to prep the
4389 bidi iterator for advancing to the next character
4390 after the newline/EOB, keeping the current paragraph
4391 direction (so that PRODUCE_GLYPHS does TRT wrt
4392 prepending/appending glyphs to a glyph row). */
4395 it
->bidi_it
.first_elt
= 0;
4396 it
->bidi_it
.paragraph_dir
= pdir
;
4397 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4398 it
->bidi_it
.nchars
= 1;
4399 it
->bidi_it
.ch_len
= 1;
4402 else /* Must use the slow method. */
4404 /* With bidi iteration, the region of invisible text
4405 could start and/or end in the middle of a
4406 non-base embedding level. Therefore, we need to
4407 skip invisible text using the bidi iterator,
4408 starting at IT's current position, until we find
4409 ourselves outside of the invisible text.
4410 Skipping invisible text _after_ bidi iteration
4411 avoids affecting the visual order of the
4412 displayed text when invisible properties are
4413 added or removed. */
4414 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4416 /* If we were `reseat'ed to a new paragraph,
4417 determine the paragraph base direction. We
4418 need to do it now because
4419 next_element_from_buffer may not have a
4420 chance to do it, if we are going to skip any
4421 text at the beginning, which resets the
4423 bidi_paragraph_init (it
->paragraph_embedding
,
4428 bidi_move_to_visually_next (&it
->bidi_it
);
4430 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4431 && it
->bidi_it
.charpos
< newpos
);
4432 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4433 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4434 /* If we overstepped NEWPOS, record its position in
4435 the iterator, so that we skip invisible text if
4436 later the bidi iteration lands us in the
4437 invisible region again. */
4438 if (IT_CHARPOS (*it
) >= newpos
)
4439 it
->prev_stop
= newpos
;
4444 IT_CHARPOS (*it
) = newpos
;
4445 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4448 /* If there are before-strings at the start of invisible
4449 text, and the text is invisible because of a text
4450 property, arrange to show before-strings because 20.x did
4451 it that way. (If the text is invisible because of an
4452 overlay property instead of a text property, this is
4453 already handled in the overlay code.) */
4455 && get_overlay_strings (it
, it
->stop_charpos
))
4457 handled
= HANDLED_RECOMPUTE_PROPS
;
4458 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4460 else if (display_ellipsis_p
)
4462 /* Make sure that the glyphs of the ellipsis will get
4463 correct `charpos' values. If we would not update
4464 it->position here, the glyphs would belong to the
4465 last visible character _before_ the invisible
4466 text, which confuses `set_cursor_from_row'.
4468 We use the last invisible position instead of the
4469 first because this way the cursor is always drawn on
4470 the first "." of the ellipsis, whenever PT is inside
4471 the invisible text. Otherwise the cursor would be
4472 placed _after_ the ellipsis when the point is after the
4473 first invisible character. */
4474 if (!STRINGP (it
->object
))
4476 it
->position
.charpos
= newpos
- 1;
4477 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4480 /* Let the ellipsis display before
4481 considering any properties of the following char.
4482 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4483 handled
= HANDLED_RETURN
;
4492 /* Make iterator IT return `...' next.
4493 Replaces LEN characters from buffer. */
4496 setup_for_ellipsis (struct it
*it
, int len
)
4498 /* Use the display table definition for `...'. Invalid glyphs
4499 will be handled by the method returning elements from dpvec. */
4500 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4502 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4503 it
->dpvec
= v
->contents
;
4504 it
->dpend
= v
->contents
+ v
->header
.size
;
4508 /* Default `...'. */
4509 it
->dpvec
= default_invis_vector
;
4510 it
->dpend
= default_invis_vector
+ 3;
4513 it
->dpvec_char_len
= len
;
4514 it
->current
.dpvec_index
= 0;
4515 it
->dpvec_face_id
= -1;
4517 /* Remember the current face id in case glyphs specify faces.
4518 IT's face is restored in set_iterator_to_next.
4519 saved_face_id was set to preceding char's face in handle_stop. */
4520 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4521 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4523 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4529 /***********************************************************************
4531 ***********************************************************************/
4533 /* Set up iterator IT from `display' property at its current position.
4534 Called from handle_stop.
4535 We return HANDLED_RETURN if some part of the display property
4536 overrides the display of the buffer text itself.
4537 Otherwise we return HANDLED_NORMALLY. */
4539 static enum prop_handled
4540 handle_display_prop (struct it
*it
)
4542 Lisp_Object propval
, object
, overlay
;
4543 struct text_pos
*position
;
4545 /* Nonzero if some property replaces the display of the text itself. */
4546 int display_replaced_p
= 0;
4548 if (STRINGP (it
->string
))
4550 object
= it
->string
;
4551 position
= &it
->current
.string_pos
;
4552 bufpos
= CHARPOS (it
->current
.pos
);
4556 XSETWINDOW (object
, it
->w
);
4557 position
= &it
->current
.pos
;
4558 bufpos
= CHARPOS (*position
);
4561 /* Reset those iterator values set from display property values. */
4562 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4563 it
->space_width
= Qnil
;
4564 it
->font_height
= Qnil
;
4567 /* We don't support recursive `display' properties, i.e. string
4568 values that have a string `display' property, that have a string
4569 `display' property etc. */
4570 if (!it
->string_from_display_prop_p
)
4571 it
->area
= TEXT_AREA
;
4573 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4574 Qdisplay
, object
, &overlay
);
4576 return HANDLED_NORMALLY
;
4577 /* Now OVERLAY is the overlay that gave us this property, or nil
4578 if it was a text property. */
4580 if (!STRINGP (it
->string
))
4581 object
= it
->w
->contents
;
4583 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4585 FRAME_WINDOW_P (it
->f
));
4587 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4590 /* Subroutine of handle_display_prop. Returns non-zero if the display
4591 specification in SPEC is a replacing specification, i.e. it would
4592 replace the text covered by `display' property with something else,
4593 such as an image or a display string. If SPEC includes any kind or
4594 `(space ...) specification, the value is 2; this is used by
4595 compute_display_string_pos, which see.
4597 See handle_single_display_spec for documentation of arguments.
4598 frame_window_p is non-zero if the window being redisplayed is on a
4599 GUI frame; this argument is used only if IT is NULL, see below.
4601 IT can be NULL, if this is called by the bidi reordering code
4602 through compute_display_string_pos, which see. In that case, this
4603 function only examines SPEC, but does not otherwise "handle" it, in
4604 the sense that it doesn't set up members of IT from the display
4607 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4608 Lisp_Object overlay
, struct text_pos
*position
,
4609 ptrdiff_t bufpos
, int frame_window_p
)
4611 int replacing_p
= 0;
4615 /* Simple specifications. */
4616 && !EQ (XCAR (spec
), Qimage
)
4617 && !EQ (XCAR (spec
), Qspace
)
4618 && !EQ (XCAR (spec
), Qwhen
)
4619 && !EQ (XCAR (spec
), Qslice
)
4620 && !EQ (XCAR (spec
), Qspace_width
)
4621 && !EQ (XCAR (spec
), Qheight
)
4622 && !EQ (XCAR (spec
), Qraise
)
4623 /* Marginal area specifications. */
4624 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4625 && !EQ (XCAR (spec
), Qleft_fringe
)
4626 && !EQ (XCAR (spec
), Qright_fringe
)
4627 && !NILP (XCAR (spec
)))
4629 for (; CONSP (spec
); spec
= XCDR (spec
))
4631 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4632 overlay
, position
, bufpos
,
4633 replacing_p
, frame_window_p
)))
4636 /* If some text in a string is replaced, `position' no
4637 longer points to the position of `object'. */
4638 if (!it
|| STRINGP (object
))
4643 else if (VECTORP (spec
))
4646 for (i
= 0; i
< ASIZE (spec
); ++i
)
4647 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4648 overlay
, position
, bufpos
,
4649 replacing_p
, frame_window_p
)))
4652 /* If some text in a string is replaced, `position' no
4653 longer points to the position of `object'. */
4654 if (!it
|| STRINGP (object
))
4660 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4661 position
, bufpos
, 0,
4669 /* Value is the position of the end of the `display' property starting
4670 at START_POS in OBJECT. */
4672 static struct text_pos
4673 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4676 struct text_pos end_pos
;
4678 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4679 Qdisplay
, object
, Qnil
);
4680 CHARPOS (end_pos
) = XFASTINT (end
);
4681 if (STRINGP (object
))
4682 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4684 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4690 /* Set up IT from a single `display' property specification SPEC. OBJECT
4691 is the object in which the `display' property was found. *POSITION
4692 is the position in OBJECT at which the `display' property was found.
4693 BUFPOS is the buffer position of OBJECT (different from POSITION if
4694 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4695 previously saw a display specification which already replaced text
4696 display with something else, for example an image; we ignore such
4697 properties after the first one has been processed.
4699 OVERLAY is the overlay this `display' property came from,
4700 or nil if it was a text property.
4702 If SPEC is a `space' or `image' specification, and in some other
4703 cases too, set *POSITION to the position where the `display'
4706 If IT is NULL, only examine the property specification in SPEC, but
4707 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4708 is intended to be displayed in a window on a GUI frame.
4710 Value is non-zero if something was found which replaces the display
4711 of buffer or string text. */
4714 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4715 Lisp_Object overlay
, struct text_pos
*position
,
4716 ptrdiff_t bufpos
, int display_replaced_p
,
4720 Lisp_Object location
, value
;
4721 struct text_pos start_pos
= *position
;
4724 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4725 If the result is non-nil, use VALUE instead of SPEC. */
4727 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4736 if (!NILP (form
) && !EQ (form
, Qt
))
4738 ptrdiff_t count
= SPECPDL_INDEX ();
4739 struct gcpro gcpro1
;
4741 /* Bind `object' to the object having the `display' property, a
4742 buffer or string. Bind `position' to the position in the
4743 object where the property was found, and `buffer-position'
4744 to the current position in the buffer. */
4747 XSETBUFFER (object
, current_buffer
);
4748 specbind (Qobject
, object
);
4749 specbind (Qposition
, make_number (CHARPOS (*position
)));
4750 specbind (Qbuffer_position
, make_number (bufpos
));
4752 form
= safe_eval (form
);
4754 unbind_to (count
, Qnil
);
4760 /* Handle `(height HEIGHT)' specifications. */
4762 && EQ (XCAR (spec
), Qheight
)
4763 && CONSP (XCDR (spec
)))
4767 if (!FRAME_WINDOW_P (it
->f
))
4770 it
->font_height
= XCAR (XCDR (spec
));
4771 if (!NILP (it
->font_height
))
4773 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4774 int new_height
= -1;
4776 if (CONSP (it
->font_height
)
4777 && (EQ (XCAR (it
->font_height
), Qplus
)
4778 || EQ (XCAR (it
->font_height
), Qminus
))
4779 && CONSP (XCDR (it
->font_height
))
4780 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4782 /* `(+ N)' or `(- N)' where N is an integer. */
4783 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4784 if (EQ (XCAR (it
->font_height
), Qplus
))
4786 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4788 else if (FUNCTIONP (it
->font_height
))
4790 /* Call function with current height as argument.
4791 Value is the new height. */
4793 height
= safe_call1 (it
->font_height
,
4794 face
->lface
[LFACE_HEIGHT_INDEX
]);
4795 if (NUMBERP (height
))
4796 new_height
= XFLOATINT (height
);
4798 else if (NUMBERP (it
->font_height
))
4800 /* Value is a multiple of the canonical char height. */
4803 f
= FACE_FROM_ID (it
->f
,
4804 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4805 new_height
= (XFLOATINT (it
->font_height
)
4806 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4810 /* Evaluate IT->font_height with `height' bound to the
4811 current specified height to get the new height. */
4812 ptrdiff_t count
= SPECPDL_INDEX ();
4814 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4815 value
= safe_eval (it
->font_height
);
4816 unbind_to (count
, Qnil
);
4818 if (NUMBERP (value
))
4819 new_height
= XFLOATINT (value
);
4823 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4830 /* Handle `(space-width WIDTH)'. */
4832 && EQ (XCAR (spec
), Qspace_width
)
4833 && CONSP (XCDR (spec
)))
4837 if (!FRAME_WINDOW_P (it
->f
))
4840 value
= XCAR (XCDR (spec
));
4841 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4842 it
->space_width
= value
;
4848 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4850 && EQ (XCAR (spec
), Qslice
))
4856 if (!FRAME_WINDOW_P (it
->f
))
4859 if (tem
= XCDR (spec
), CONSP (tem
))
4861 it
->slice
.x
= XCAR (tem
);
4862 if (tem
= XCDR (tem
), CONSP (tem
))
4864 it
->slice
.y
= XCAR (tem
);
4865 if (tem
= XCDR (tem
), CONSP (tem
))
4867 it
->slice
.width
= XCAR (tem
);
4868 if (tem
= XCDR (tem
), CONSP (tem
))
4869 it
->slice
.height
= XCAR (tem
);
4878 /* Handle `(raise FACTOR)'. */
4880 && EQ (XCAR (spec
), Qraise
)
4881 && CONSP (XCDR (spec
)))
4885 if (!FRAME_WINDOW_P (it
->f
))
4888 #ifdef HAVE_WINDOW_SYSTEM
4889 value
= XCAR (XCDR (spec
));
4890 if (NUMBERP (value
))
4892 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4893 it
->voffset
= - (XFLOATINT (value
)
4894 * (FONT_HEIGHT (face
->font
)));
4896 #endif /* HAVE_WINDOW_SYSTEM */
4902 /* Don't handle the other kinds of display specifications
4903 inside a string that we got from a `display' property. */
4904 if (it
&& it
->string_from_display_prop_p
)
4907 /* Characters having this form of property are not displayed, so
4908 we have to find the end of the property. */
4911 start_pos
= *position
;
4912 *position
= display_prop_end (it
, object
, start_pos
);
4916 /* Stop the scan at that end position--we assume that all
4917 text properties change there. */
4919 it
->stop_charpos
= position
->charpos
;
4921 /* Handle `(left-fringe BITMAP [FACE])'
4922 and `(right-fringe BITMAP [FACE])'. */
4924 && (EQ (XCAR (spec
), Qleft_fringe
)
4925 || EQ (XCAR (spec
), Qright_fringe
))
4926 && CONSP (XCDR (spec
)))
4932 if (!FRAME_WINDOW_P (it
->f
))
4933 /* If we return here, POSITION has been advanced
4934 across the text with this property. */
4936 /* Synchronize the bidi iterator with POSITION. This is
4937 needed because we are not going to push the iterator
4938 on behalf of this display property, so there will be
4939 no pop_it call to do this synchronization for us. */
4942 it
->position
= *position
;
4943 iterate_out_of_display_property (it
);
4944 *position
= it
->position
;
4949 else if (!frame_window_p
)
4952 #ifdef HAVE_WINDOW_SYSTEM
4953 value
= XCAR (XCDR (spec
));
4954 if (!SYMBOLP (value
)
4955 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4956 /* If we return here, POSITION has been advanced
4957 across the text with this property. */
4959 if (it
&& it
->bidi_p
)
4961 it
->position
= *position
;
4962 iterate_out_of_display_property (it
);
4963 *position
= it
->position
;
4970 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4972 if (CONSP (XCDR (XCDR (spec
))))
4974 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4975 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4981 /* Save current settings of IT so that we can restore them
4982 when we are finished with the glyph property value. */
4983 push_it (it
, position
);
4985 it
->area
= TEXT_AREA
;
4986 it
->what
= IT_IMAGE
;
4987 it
->image_id
= -1; /* no image */
4988 it
->position
= start_pos
;
4989 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4990 it
->method
= GET_FROM_IMAGE
;
4991 it
->from_overlay
= Qnil
;
4992 it
->face_id
= face_id
;
4993 it
->from_disp_prop_p
= 1;
4995 /* Say that we haven't consumed the characters with
4996 `display' property yet. The call to pop_it in
4997 set_iterator_to_next will clean this up. */
4998 *position
= start_pos
;
5000 if (EQ (XCAR (spec
), Qleft_fringe
))
5002 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5003 it
->left_user_fringe_face_id
= face_id
;
5007 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5008 it
->right_user_fringe_face_id
= face_id
;
5011 #endif /* HAVE_WINDOW_SYSTEM */
5015 /* Prepare to handle `((margin left-margin) ...)',
5016 `((margin right-margin) ...)' and `((margin nil) ...)'
5017 prefixes for display specifications. */
5018 location
= Qunbound
;
5019 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5023 value
= XCDR (spec
);
5025 value
= XCAR (value
);
5028 if (EQ (XCAR (tem
), Qmargin
)
5029 && (tem
= XCDR (tem
),
5030 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5032 || EQ (tem
, Qleft_margin
)
5033 || EQ (tem
, Qright_margin
))))
5037 if (EQ (location
, Qunbound
))
5043 /* After this point, VALUE is the property after any
5044 margin prefix has been stripped. It must be a string,
5045 an image specification, or `(space ...)'.
5047 LOCATION specifies where to display: `left-margin',
5048 `right-margin' or nil. */
5050 valid_p
= (STRINGP (value
)
5051 #ifdef HAVE_WINDOW_SYSTEM
5052 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5053 && valid_image_p (value
))
5054 #endif /* not HAVE_WINDOW_SYSTEM */
5055 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5057 if (valid_p
&& !display_replaced_p
)
5063 /* Callers need to know whether the display spec is any kind
5064 of `(space ...)' spec that is about to affect text-area
5066 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5071 /* Save current settings of IT so that we can restore them
5072 when we are finished with the glyph property value. */
5073 push_it (it
, position
);
5074 it
->from_overlay
= overlay
;
5075 it
->from_disp_prop_p
= 1;
5077 if (NILP (location
))
5078 it
->area
= TEXT_AREA
;
5079 else if (EQ (location
, Qleft_margin
))
5080 it
->area
= LEFT_MARGIN_AREA
;
5082 it
->area
= RIGHT_MARGIN_AREA
;
5084 if (STRINGP (value
))
5087 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5088 it
->current
.overlay_string_index
= -1;
5089 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5090 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5091 it
->method
= GET_FROM_STRING
;
5092 it
->stop_charpos
= 0;
5094 it
->base_level_stop
= 0;
5095 it
->string_from_display_prop_p
= 1;
5096 /* Say that we haven't consumed the characters with
5097 `display' property yet. The call to pop_it in
5098 set_iterator_to_next will clean this up. */
5099 if (BUFFERP (object
))
5100 *position
= start_pos
;
5102 /* Force paragraph direction to be that of the parent
5103 object. If the parent object's paragraph direction is
5104 not yet determined, default to L2R. */
5105 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5106 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5108 it
->paragraph_embedding
= L2R
;
5110 /* Set up the bidi iterator for this display string. */
5113 it
->bidi_it
.string
.lstring
= it
->string
;
5114 it
->bidi_it
.string
.s
= NULL
;
5115 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5116 it
->bidi_it
.string
.bufpos
= bufpos
;
5117 it
->bidi_it
.string
.from_disp_str
= 1;
5118 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5119 it
->bidi_it
.w
= it
->w
;
5120 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5123 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5125 it
->method
= GET_FROM_STRETCH
;
5127 *position
= it
->position
= start_pos
;
5128 retval
= 1 + (it
->area
== TEXT_AREA
);
5130 #ifdef HAVE_WINDOW_SYSTEM
5133 it
->what
= IT_IMAGE
;
5134 it
->image_id
= lookup_image (it
->f
, value
);
5135 it
->position
= start_pos
;
5136 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5137 it
->method
= GET_FROM_IMAGE
;
5139 /* Say that we haven't consumed the characters with
5140 `display' property yet. The call to pop_it in
5141 set_iterator_to_next will clean this up. */
5142 *position
= start_pos
;
5144 #endif /* HAVE_WINDOW_SYSTEM */
5149 /* Invalid property or property not supported. Restore
5150 POSITION to what it was before. */
5151 *position
= start_pos
;
5155 /* Check if PROP is a display property value whose text should be
5156 treated as intangible. OVERLAY is the overlay from which PROP
5157 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5158 specify the buffer position covered by PROP. */
5161 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5162 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5164 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5165 struct text_pos position
;
5167 SET_TEXT_POS (position
, charpos
, bytepos
);
5168 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5169 &position
, charpos
, frame_window_p
);
5173 /* Return 1 if PROP is a display sub-property value containing STRING.
5175 Implementation note: this and the following function are really
5176 special cases of handle_display_spec and
5177 handle_single_display_spec, and should ideally use the same code.
5178 Until they do, these two pairs must be consistent and must be
5179 modified in sync. */
5182 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5184 if (EQ (string
, prop
))
5187 /* Skip over `when FORM'. */
5188 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5193 /* Actually, the condition following `when' should be eval'ed,
5194 like handle_single_display_spec does, and we should return
5195 zero if it evaluates to nil. However, this function is
5196 called only when the buffer was already displayed and some
5197 glyph in the glyph matrix was found to come from a display
5198 string. Therefore, the condition was already evaluated, and
5199 the result was non-nil, otherwise the display string wouldn't
5200 have been displayed and we would have never been called for
5201 this property. Thus, we can skip the evaluation and assume
5202 its result is non-nil. */
5207 /* Skip over `margin LOCATION'. */
5208 if (EQ (XCAR (prop
), Qmargin
))
5219 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5223 /* Return 1 if STRING appears in the `display' property PROP. */
5226 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5229 && !EQ (XCAR (prop
), Qwhen
)
5230 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5232 /* A list of sub-properties. */
5233 while (CONSP (prop
))
5235 if (single_display_spec_string_p (XCAR (prop
), string
))
5240 else if (VECTORP (prop
))
5242 /* A vector of sub-properties. */
5244 for (i
= 0; i
< ASIZE (prop
); ++i
)
5245 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5249 return single_display_spec_string_p (prop
, string
);
5254 /* Look for STRING in overlays and text properties in the current
5255 buffer, between character positions FROM and TO (excluding TO).
5256 BACK_P non-zero means look back (in this case, TO is supposed to be
5258 Value is the first character position where STRING was found, or
5259 zero if it wasn't found before hitting TO.
5261 This function may only use code that doesn't eval because it is
5262 called asynchronously from note_mouse_highlight. */
5265 string_buffer_position_lim (Lisp_Object string
,
5266 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5268 Lisp_Object limit
, prop
, pos
;
5271 pos
= make_number (max (from
, BEGV
));
5273 if (!back_p
) /* looking forward */
5275 limit
= make_number (min (to
, ZV
));
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
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5286 else /* looking back */
5288 limit
= make_number (max (to
, BEGV
));
5289 while (!found
&& !EQ (pos
, limit
))
5291 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5292 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5295 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5300 return found
? XINT (pos
) : 0;
5303 /* Determine which buffer position in current buffer STRING comes from.
5304 AROUND_CHARPOS is an approximate position where it could come from.
5305 Value is the buffer position or 0 if it couldn't be determined.
5307 This function is necessary because we don't record buffer positions
5308 in glyphs generated from strings (to keep struct glyph small).
5309 This function may only use code that doesn't eval because it is
5310 called asynchronously from note_mouse_highlight. */
5313 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5315 const int MAX_DISTANCE
= 1000;
5316 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5317 around_charpos
+ MAX_DISTANCE
,
5321 found
= string_buffer_position_lim (string
, around_charpos
,
5322 around_charpos
- MAX_DISTANCE
, 1);
5328 /***********************************************************************
5329 `composition' property
5330 ***********************************************************************/
5332 /* Set up iterator IT from `composition' property at its current
5333 position. Called from handle_stop. */
5335 static enum prop_handled
5336 handle_composition_prop (struct it
*it
)
5338 Lisp_Object prop
, string
;
5339 ptrdiff_t pos
, pos_byte
, start
, end
;
5341 if (STRINGP (it
->string
))
5345 pos
= IT_STRING_CHARPOS (*it
);
5346 pos_byte
= IT_STRING_BYTEPOS (*it
);
5347 string
= it
->string
;
5348 s
= SDATA (string
) + pos_byte
;
5349 it
->c
= STRING_CHAR (s
);
5353 pos
= IT_CHARPOS (*it
);
5354 pos_byte
= IT_BYTEPOS (*it
);
5356 it
->c
= FETCH_CHAR (pos_byte
);
5359 /* If there's a valid composition and point is not inside of the
5360 composition (in the case that the composition is from the current
5361 buffer), draw a glyph composed from the composition components. */
5362 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5363 && composition_valid_p (start
, end
, prop
)
5364 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5367 /* As we can't handle this situation (perhaps font-lock added
5368 a new composition), we just return here hoping that next
5369 redisplay will detect this composition much earlier. */
5370 return HANDLED_NORMALLY
;
5373 if (STRINGP (it
->string
))
5374 pos_byte
= string_char_to_byte (it
->string
, start
);
5376 pos_byte
= CHAR_TO_BYTE (start
);
5378 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5381 if (it
->cmp_it
.id
>= 0)
5384 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5385 it
->cmp_it
.nglyphs
= -1;
5389 return HANDLED_NORMALLY
;
5394 /***********************************************************************
5396 ***********************************************************************/
5398 /* The following structure is used to record overlay strings for
5399 later sorting in load_overlay_strings. */
5401 struct overlay_entry
5403 Lisp_Object overlay
;
5410 /* Set up iterator IT from overlay strings at its current position.
5411 Called from handle_stop. */
5413 static enum prop_handled
5414 handle_overlay_change (struct it
*it
)
5416 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5417 return HANDLED_RECOMPUTE_PROPS
;
5419 return HANDLED_NORMALLY
;
5423 /* Set up the next overlay string for delivery by IT, if there is an
5424 overlay string to deliver. Called by set_iterator_to_next when the
5425 end of the current overlay string is reached. If there are more
5426 overlay strings to display, IT->string and
5427 IT->current.overlay_string_index are set appropriately here.
5428 Otherwise IT->string is set to nil. */
5431 next_overlay_string (struct it
*it
)
5433 ++it
->current
.overlay_string_index
;
5434 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5436 /* No more overlay strings. Restore IT's settings to what
5437 they were before overlay strings were processed, and
5438 continue to deliver from current_buffer. */
5440 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5443 || (NILP (it
->string
)
5444 && it
->method
== GET_FROM_BUFFER
5445 && it
->stop_charpos
>= BEGV
5446 && it
->stop_charpos
<= it
->end_charpos
));
5447 it
->current
.overlay_string_index
= -1;
5448 it
->n_overlay_strings
= 0;
5449 it
->overlay_strings_charpos
= -1;
5450 /* If there's an empty display string on the stack, pop the
5451 stack, to resync the bidi iterator with IT's position. Such
5452 empty strings are pushed onto the stack in
5453 get_overlay_strings_1. */
5454 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5457 /* If we're at the end of the buffer, record that we have
5458 processed the overlay strings there already, so that
5459 next_element_from_buffer doesn't try it again. */
5460 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5461 it
->overlay_strings_at_end_processed_p
= 1;
5465 /* There are more overlay strings to process. If
5466 IT->current.overlay_string_index has advanced to a position
5467 where we must load IT->overlay_strings with more strings, do
5468 it. We must load at the IT->overlay_strings_charpos where
5469 IT->n_overlay_strings was originally computed; when invisible
5470 text is present, this might not be IT_CHARPOS (Bug#7016). */
5471 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5473 if (it
->current
.overlay_string_index
&& i
== 0)
5474 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5476 /* Initialize IT to deliver display elements from the overlay
5478 it
->string
= it
->overlay_strings
[i
];
5479 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5480 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5481 it
->method
= GET_FROM_STRING
;
5482 it
->stop_charpos
= 0;
5483 it
->end_charpos
= SCHARS (it
->string
);
5484 if (it
->cmp_it
.stop_pos
>= 0)
5485 it
->cmp_it
.stop_pos
= 0;
5487 it
->base_level_stop
= 0;
5489 /* Set up the bidi iterator for this overlay string. */
5492 it
->bidi_it
.string
.lstring
= it
->string
;
5493 it
->bidi_it
.string
.s
= NULL
;
5494 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5495 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5496 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5497 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5498 it
->bidi_it
.w
= it
->w
;
5499 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5507 /* Compare two overlay_entry structures E1 and E2. Used as a
5508 comparison function for qsort in load_overlay_strings. Overlay
5509 strings for the same position are sorted so that
5511 1. All after-strings come in front of before-strings, except
5512 when they come from the same overlay.
5514 2. Within after-strings, strings are sorted so that overlay strings
5515 from overlays with higher priorities come first.
5517 2. Within before-strings, strings are sorted so that overlay
5518 strings from overlays with higher priorities come last.
5520 Value is analogous to strcmp. */
5524 compare_overlay_entries (const void *e1
, const void *e2
)
5526 struct overlay_entry
const *entry1
= e1
;
5527 struct overlay_entry
const *entry2
= e2
;
5530 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5532 /* Let after-strings appear in front of before-strings if
5533 they come from different overlays. */
5534 if (EQ (entry1
->overlay
, entry2
->overlay
))
5535 result
= entry1
->after_string_p
? 1 : -1;
5537 result
= entry1
->after_string_p
? -1 : 1;
5539 else if (entry1
->priority
!= entry2
->priority
)
5541 if (entry1
->after_string_p
)
5542 /* After-strings sorted in order of decreasing priority. */
5543 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5545 /* Before-strings sorted in order of increasing priority. */
5546 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5555 /* Load the vector IT->overlay_strings with overlay strings from IT's
5556 current buffer position, or from CHARPOS if that is > 0. Set
5557 IT->n_overlays to the total number of overlay strings found.
5559 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5560 a time. On entry into load_overlay_strings,
5561 IT->current.overlay_string_index gives the number of overlay
5562 strings that have already been loaded by previous calls to this
5565 IT->add_overlay_start contains an additional overlay start
5566 position to consider for taking overlay strings from, if non-zero.
5567 This position comes into play when the overlay has an `invisible'
5568 property, and both before and after-strings. When we've skipped to
5569 the end of the overlay, because of its `invisible' property, we
5570 nevertheless want its before-string to appear.
5571 IT->add_overlay_start will contain the overlay start position
5574 Overlay strings are sorted so that after-string strings come in
5575 front of before-string strings. Within before and after-strings,
5576 strings are sorted by overlay priority. See also function
5577 compare_overlay_entries. */
5580 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5582 Lisp_Object overlay
, window
, str
, invisible
;
5583 struct Lisp_Overlay
*ov
;
5584 ptrdiff_t start
, end
;
5585 ptrdiff_t size
= 20;
5586 ptrdiff_t n
= 0, i
, j
;
5588 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5592 charpos
= IT_CHARPOS (*it
);
5594 /* Append the overlay string STRING of overlay OVERLAY to vector
5595 `entries' which has size `size' and currently contains `n'
5596 elements. AFTER_P non-zero means STRING is an after-string of
5598 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5601 Lisp_Object priority; \
5605 struct overlay_entry *old = entries; \
5606 SAFE_NALLOCA (entries, 2, size); \
5607 memcpy (entries, old, size * sizeof *entries); \
5611 entries[n].string = (STRING); \
5612 entries[n].overlay = (OVERLAY); \
5613 priority = Foverlay_get ((OVERLAY), Qpriority); \
5614 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5615 entries[n].after_string_p = (AFTER_P); \
5620 /* Process overlay before the overlay center. */
5621 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5623 XSETMISC (overlay
, ov
);
5624 eassert (OVERLAYP (overlay
));
5625 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5626 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5631 /* Skip this overlay if it doesn't start or end at IT's current
5633 if (end
!= charpos
&& start
!= charpos
)
5636 /* Skip this overlay if it doesn't apply to IT->w. */
5637 window
= Foverlay_get (overlay
, Qwindow
);
5638 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5641 /* If the text ``under'' the overlay is invisible, both before-
5642 and after-strings from this overlay are visible; start and
5643 end position are indistinguishable. */
5644 invisible
= Foverlay_get (overlay
, Qinvisible
);
5645 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5647 /* If overlay has a non-empty before-string, record it. */
5648 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5649 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5651 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5653 /* If overlay has a non-empty after-string, record it. */
5654 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5655 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5657 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5660 /* Process overlays after the overlay center. */
5661 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5663 XSETMISC (overlay
, ov
);
5664 eassert (OVERLAYP (overlay
));
5665 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5666 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5668 if (start
> charpos
)
5671 /* Skip this overlay if it doesn't start or end at IT's current
5673 if (end
!= charpos
&& start
!= charpos
)
5676 /* Skip this overlay if it doesn't apply to IT->w. */
5677 window
= Foverlay_get (overlay
, Qwindow
);
5678 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5681 /* If the text ``under'' the overlay is invisible, it has a zero
5682 dimension, and both before- and after-strings apply. */
5683 invisible
= Foverlay_get (overlay
, Qinvisible
);
5684 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5686 /* If overlay has a non-empty before-string, record it. */
5687 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5688 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5690 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5692 /* If overlay has a non-empty after-string, record it. */
5693 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5694 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5696 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5699 #undef RECORD_OVERLAY_STRING
5703 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5705 /* Record number of overlay strings, and where we computed it. */
5706 it
->n_overlay_strings
= n
;
5707 it
->overlay_strings_charpos
= charpos
;
5709 /* IT->current.overlay_string_index is the number of overlay strings
5710 that have already been consumed by IT. Copy some of the
5711 remaining overlay strings to IT->overlay_strings. */
5713 j
= it
->current
.overlay_string_index
;
5714 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5716 it
->overlay_strings
[i
] = entries
[j
].string
;
5717 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5725 /* Get the first chunk of overlay strings at IT's current buffer
5726 position, or at CHARPOS if that is > 0. Value is non-zero if at
5727 least one overlay string was found. */
5730 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5732 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5733 process. This fills IT->overlay_strings with strings, and sets
5734 IT->n_overlay_strings to the total number of strings to process.
5735 IT->pos.overlay_string_index has to be set temporarily to zero
5736 because load_overlay_strings needs this; it must be set to -1
5737 when no overlay strings are found because a zero value would
5738 indicate a position in the first overlay string. */
5739 it
->current
.overlay_string_index
= 0;
5740 load_overlay_strings (it
, charpos
);
5742 /* If we found overlay strings, set up IT to deliver display
5743 elements from the first one. Otherwise set up IT to deliver
5744 from current_buffer. */
5745 if (it
->n_overlay_strings
)
5747 /* Make sure we know settings in current_buffer, so that we can
5748 restore meaningful values when we're done with the overlay
5751 compute_stop_pos (it
);
5752 eassert (it
->face_id
>= 0);
5754 /* Save IT's settings. They are restored after all overlay
5755 strings have been processed. */
5756 eassert (!compute_stop_p
|| it
->sp
== 0);
5758 /* When called from handle_stop, there might be an empty display
5759 string loaded. In that case, don't bother saving it. But
5760 don't use this optimization with the bidi iterator, since we
5761 need the corresponding pop_it call to resync the bidi
5762 iterator's position with IT's position, after we are done
5763 with the overlay strings. (The corresponding call to pop_it
5764 in case of an empty display string is in
5765 next_overlay_string.) */
5767 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5770 /* Set up IT to deliver display elements from the first overlay
5772 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5773 it
->string
= it
->overlay_strings
[0];
5774 it
->from_overlay
= Qnil
;
5775 it
->stop_charpos
= 0;
5776 eassert (STRINGP (it
->string
));
5777 it
->end_charpos
= SCHARS (it
->string
);
5779 it
->base_level_stop
= 0;
5780 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5781 it
->method
= GET_FROM_STRING
;
5782 it
->from_disp_prop_p
= 0;
5784 /* Force paragraph direction to be that of the parent
5786 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5787 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5789 it
->paragraph_embedding
= L2R
;
5791 /* Set up the bidi iterator for this overlay string. */
5794 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5796 it
->bidi_it
.string
.lstring
= it
->string
;
5797 it
->bidi_it
.string
.s
= NULL
;
5798 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5799 it
->bidi_it
.string
.bufpos
= pos
;
5800 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5801 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5802 it
->bidi_it
.w
= it
->w
;
5803 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5808 it
->current
.overlay_string_index
= -1;
5813 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5816 it
->method
= GET_FROM_BUFFER
;
5818 (void) get_overlay_strings_1 (it
, charpos
, 1);
5822 /* Value is non-zero if we found at least one overlay string. */
5823 return STRINGP (it
->string
);
5828 /***********************************************************************
5829 Saving and restoring state
5830 ***********************************************************************/
5832 /* Save current settings of IT on IT->stack. Called, for example,
5833 before setting up IT for an overlay string, to be able to restore
5834 IT's settings to what they were after the overlay string has been
5835 processed. If POSITION is non-NULL, it is the position to save on
5836 the stack instead of IT->position. */
5839 push_it (struct it
*it
, struct text_pos
*position
)
5841 struct iterator_stack_entry
*p
;
5843 eassert (it
->sp
< IT_STACK_SIZE
);
5844 p
= it
->stack
+ it
->sp
;
5846 p
->stop_charpos
= it
->stop_charpos
;
5847 p
->prev_stop
= it
->prev_stop
;
5848 p
->base_level_stop
= it
->base_level_stop
;
5849 p
->cmp_it
= it
->cmp_it
;
5850 eassert (it
->face_id
>= 0);
5851 p
->face_id
= it
->face_id
;
5852 p
->string
= it
->string
;
5853 p
->method
= it
->method
;
5854 p
->from_overlay
= it
->from_overlay
;
5857 case GET_FROM_IMAGE
:
5858 p
->u
.image
.object
= it
->object
;
5859 p
->u
.image
.image_id
= it
->image_id
;
5860 p
->u
.image
.slice
= it
->slice
;
5862 case GET_FROM_STRETCH
:
5863 p
->u
.stretch
.object
= it
->object
;
5866 p
->position
= position
? *position
: it
->position
;
5867 p
->current
= it
->current
;
5868 p
->end_charpos
= it
->end_charpos
;
5869 p
->string_nchars
= it
->string_nchars
;
5871 p
->multibyte_p
= it
->multibyte_p
;
5872 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5873 p
->space_width
= it
->space_width
;
5874 p
->font_height
= it
->font_height
;
5875 p
->voffset
= it
->voffset
;
5876 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5877 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5878 p
->display_ellipsis_p
= 0;
5879 p
->line_wrap
= it
->line_wrap
;
5880 p
->bidi_p
= it
->bidi_p
;
5881 p
->paragraph_embedding
= it
->paragraph_embedding
;
5882 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5885 /* Save the state of the bidi iterator as well. */
5887 bidi_push_it (&it
->bidi_it
);
5891 iterate_out_of_display_property (struct it
*it
)
5893 int buffer_p
= !STRINGP (it
->string
);
5894 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5895 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5897 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5899 /* Maybe initialize paragraph direction. If we are at the beginning
5900 of a new paragraph, next_element_from_buffer may not have a
5901 chance to do that. */
5902 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5903 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5904 /* prev_stop can be zero, so check against BEGV as well. */
5905 while (it
->bidi_it
.charpos
>= bob
5906 && it
->prev_stop
<= it
->bidi_it
.charpos
5907 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5908 && it
->bidi_it
.charpos
< eob
)
5909 bidi_move_to_visually_next (&it
->bidi_it
);
5910 /* Record the stop_pos we just crossed, for when we cross it
5912 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5913 it
->prev_stop
= CHARPOS (it
->position
);
5914 /* If we ended up not where pop_it put us, resync IT's
5915 positional members with the bidi iterator. */
5916 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5917 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5919 it
->current
.pos
= it
->position
;
5921 it
->current
.string_pos
= it
->position
;
5924 /* Restore IT's settings from IT->stack. Called, for example, when no
5925 more overlay strings must be processed, and we return to delivering
5926 display elements from a buffer, or when the end of a string from a
5927 `display' property is reached and we return to delivering display
5928 elements from an overlay string, or from a buffer. */
5931 pop_it (struct it
*it
)
5933 struct iterator_stack_entry
*p
;
5934 int from_display_prop
= it
->from_disp_prop_p
;
5936 eassert (it
->sp
> 0);
5938 p
= it
->stack
+ it
->sp
;
5939 it
->stop_charpos
= p
->stop_charpos
;
5940 it
->prev_stop
= p
->prev_stop
;
5941 it
->base_level_stop
= p
->base_level_stop
;
5942 it
->cmp_it
= p
->cmp_it
;
5943 it
->face_id
= p
->face_id
;
5944 it
->current
= p
->current
;
5945 it
->position
= p
->position
;
5946 it
->string
= p
->string
;
5947 it
->from_overlay
= p
->from_overlay
;
5948 if (NILP (it
->string
))
5949 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5950 it
->method
= p
->method
;
5953 case GET_FROM_IMAGE
:
5954 it
->image_id
= p
->u
.image
.image_id
;
5955 it
->object
= p
->u
.image
.object
;
5956 it
->slice
= p
->u
.image
.slice
;
5958 case GET_FROM_STRETCH
:
5959 it
->object
= p
->u
.stretch
.object
;
5961 case GET_FROM_BUFFER
:
5962 it
->object
= it
->w
->contents
;
5964 case GET_FROM_STRING
:
5965 it
->object
= it
->string
;
5967 case GET_FROM_DISPLAY_VECTOR
:
5969 it
->method
= GET_FROM_C_STRING
;
5970 else if (STRINGP (it
->string
))
5971 it
->method
= GET_FROM_STRING
;
5974 it
->method
= GET_FROM_BUFFER
;
5975 it
->object
= it
->w
->contents
;
5978 it
->end_charpos
= p
->end_charpos
;
5979 it
->string_nchars
= p
->string_nchars
;
5981 it
->multibyte_p
= p
->multibyte_p
;
5982 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5983 it
->space_width
= p
->space_width
;
5984 it
->font_height
= p
->font_height
;
5985 it
->voffset
= p
->voffset
;
5986 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5987 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5988 it
->line_wrap
= p
->line_wrap
;
5989 it
->bidi_p
= p
->bidi_p
;
5990 it
->paragraph_embedding
= p
->paragraph_embedding
;
5991 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5994 bidi_pop_it (&it
->bidi_it
);
5995 /* Bidi-iterate until we get out of the portion of text, if any,
5996 covered by a `display' text property or by an overlay with
5997 `display' property. (We cannot just jump there, because the
5998 internal coherency of the bidi iterator state can not be
5999 preserved across such jumps.) We also must determine the
6000 paragraph base direction if the overlay we just processed is
6001 at the beginning of a new paragraph. */
6002 if (from_display_prop
6003 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6004 iterate_out_of_display_property (it
);
6006 eassert ((BUFFERP (it
->object
)
6007 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6008 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6009 || (STRINGP (it
->object
)
6010 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6011 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6012 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6018 /***********************************************************************
6020 ***********************************************************************/
6022 /* Set IT's current position to the previous line start. */
6025 back_to_previous_line_start (struct it
*it
)
6027 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6030 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6034 /* Move IT to the next line start.
6036 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6037 we skipped over part of the text (as opposed to moving the iterator
6038 continuously over the text). Otherwise, don't change the value
6041 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6042 iterator on the newline, if it was found.
6044 Newlines may come from buffer text, overlay strings, or strings
6045 displayed via the `display' property. That's the reason we can't
6046 simply use find_newline_no_quit.
6048 Note that this function may not skip over invisible text that is so
6049 because of text properties and immediately follows a newline. If
6050 it would, function reseat_at_next_visible_line_start, when called
6051 from set_iterator_to_next, would effectively make invisible
6052 characters following a newline part of the wrong glyph row, which
6053 leads to wrong cursor motion. */
6056 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6057 struct bidi_it
*bidi_it_prev
)
6059 ptrdiff_t old_selective
;
6060 int newline_found_p
, n
;
6061 const int MAX_NEWLINE_DISTANCE
= 500;
6063 /* If already on a newline, just consume it to avoid unintended
6064 skipping over invisible text below. */
6065 if (it
->what
== IT_CHARACTER
6067 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6069 if (it
->bidi_p
&& bidi_it_prev
)
6070 *bidi_it_prev
= it
->bidi_it
;
6071 set_iterator_to_next (it
, 0);
6076 /* Don't handle selective display in the following. It's (a)
6077 unnecessary because it's done by the caller, and (b) leads to an
6078 infinite recursion because next_element_from_ellipsis indirectly
6079 calls this function. */
6080 old_selective
= it
->selective
;
6083 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6084 from buffer text. */
6085 for (n
= newline_found_p
= 0;
6086 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6087 n
+= STRINGP (it
->string
) ? 0 : 1)
6089 if (!get_next_display_element (it
))
6091 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6092 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6093 *bidi_it_prev
= it
->bidi_it
;
6094 set_iterator_to_next (it
, 0);
6097 /* If we didn't find a newline near enough, see if we can use a
6099 if (!newline_found_p
)
6101 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6102 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6106 eassert (!STRINGP (it
->string
));
6108 /* If there isn't any `display' property in sight, and no
6109 overlays, we can just use the position of the newline in
6111 if (it
->stop_charpos
>= limit
6112 || ((pos
= Fnext_single_property_change (make_number (start
),
6114 make_number (limit
)),
6116 && next_overlay_change (start
) == ZV
))
6120 IT_CHARPOS (*it
) = limit
;
6121 IT_BYTEPOS (*it
) = bytepos
;
6125 struct bidi_it bprev
;
6127 /* Help bidi.c avoid expensive searches for display
6128 properties and overlays, by telling it that there are
6129 none up to `limit'. */
6130 if (it
->bidi_it
.disp_pos
< limit
)
6132 it
->bidi_it
.disp_pos
= limit
;
6133 it
->bidi_it
.disp_prop
= 0;
6136 bprev
= it
->bidi_it
;
6137 bidi_move_to_visually_next (&it
->bidi_it
);
6138 } while (it
->bidi_it
.charpos
!= limit
);
6139 IT_CHARPOS (*it
) = limit
;
6140 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6142 *bidi_it_prev
= bprev
;
6144 *skipped_p
= newline_found_p
= 1;
6148 while (get_next_display_element (it
)
6149 && !newline_found_p
)
6151 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6152 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6153 *bidi_it_prev
= it
->bidi_it
;
6154 set_iterator_to_next (it
, 0);
6159 it
->selective
= old_selective
;
6160 return newline_found_p
;
6164 /* Set IT's current position to the previous visible line start. Skip
6165 invisible text that is so either due to text properties or due to
6166 selective display. Caution: this does not change IT->current_x and
6170 back_to_previous_visible_line_start (struct it
*it
)
6172 while (IT_CHARPOS (*it
) > BEGV
)
6174 back_to_previous_line_start (it
);
6176 if (IT_CHARPOS (*it
) <= BEGV
)
6179 /* If selective > 0, then lines indented more than its value are
6181 if (it
->selective
> 0
6182 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6186 /* Check the newline before point for invisibility. */
6189 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6190 Qinvisible
, it
->window
);
6191 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6195 if (IT_CHARPOS (*it
) <= BEGV
)
6200 void *it2data
= NULL
;
6203 Lisp_Object val
, overlay
;
6205 SAVE_IT (it2
, *it
, it2data
);
6207 /* If newline is part of a composition, continue from start of composition */
6208 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6209 && beg
< IT_CHARPOS (*it
))
6212 /* If newline is replaced by a display property, find start of overlay
6213 or interval and continue search from that point. */
6214 pos
= --IT_CHARPOS (it2
);
6217 bidi_unshelve_cache (NULL
, 0);
6218 it2
.string_from_display_prop_p
= 0;
6219 it2
.from_disp_prop_p
= 0;
6220 if (handle_display_prop (&it2
) == HANDLED_RETURN
6221 && !NILP (val
= get_char_property_and_overlay
6222 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6223 && (OVERLAYP (overlay
)
6224 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6225 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6227 RESTORE_IT (it
, it
, it2data
);
6231 /* Newline is not replaced by anything -- so we are done. */
6232 RESTORE_IT (it
, it
, it2data
);
6238 IT_CHARPOS (*it
) = beg
;
6239 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6243 it
->continuation_lines_width
= 0;
6245 eassert (IT_CHARPOS (*it
) >= BEGV
);
6246 eassert (IT_CHARPOS (*it
) == BEGV
6247 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6252 /* Reseat iterator IT at the previous visible line start. Skip
6253 invisible text that is so either due to text properties or due to
6254 selective display. At the end, update IT's overlay information,
6255 face information etc. */
6258 reseat_at_previous_visible_line_start (struct it
*it
)
6260 back_to_previous_visible_line_start (it
);
6261 reseat (it
, it
->current
.pos
, 1);
6266 /* Reseat iterator IT on the next visible line start in the current
6267 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6268 preceding the line start. Skip over invisible text that is so
6269 because of selective display. Compute faces, overlays etc at the
6270 new position. Note that this function does not skip over text that
6271 is invisible because of text properties. */
6274 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6276 int newline_found_p
, skipped_p
= 0;
6277 struct bidi_it bidi_it_prev
;
6279 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6281 /* Skip over lines that are invisible because they are indented
6282 more than the value of IT->selective. */
6283 if (it
->selective
> 0)
6284 while (IT_CHARPOS (*it
) < ZV
6285 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6288 eassert (IT_BYTEPOS (*it
) == BEGV
6289 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6291 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6294 /* Position on the newline if that's what's requested. */
6295 if (on_newline_p
&& newline_found_p
)
6297 if (STRINGP (it
->string
))
6299 if (IT_STRING_CHARPOS (*it
) > 0)
6303 --IT_STRING_CHARPOS (*it
);
6304 --IT_STRING_BYTEPOS (*it
);
6308 /* We need to restore the bidi iterator to the state
6309 it had on the newline, and resync the IT's
6310 position with that. */
6311 it
->bidi_it
= bidi_it_prev
;
6312 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6313 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6317 else if (IT_CHARPOS (*it
) > BEGV
)
6326 /* We need to restore the bidi iterator to the state it
6327 had on the newline and resync IT with that. */
6328 it
->bidi_it
= bidi_it_prev
;
6329 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6330 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6332 reseat (it
, it
->current
.pos
, 0);
6336 reseat (it
, it
->current
.pos
, 0);
6343 /***********************************************************************
6344 Changing an iterator's position
6345 ***********************************************************************/
6347 /* Change IT's current position to POS in current_buffer. If FORCE_P
6348 is non-zero, always check for text properties at the new position.
6349 Otherwise, text properties are only looked up if POS >=
6350 IT->check_charpos of a property. */
6353 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6355 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6357 reseat_1 (it
, pos
, 0);
6359 /* Determine where to check text properties. Avoid doing it
6360 where possible because text property lookup is very expensive. */
6362 || CHARPOS (pos
) > it
->stop_charpos
6363 || CHARPOS (pos
) < original_pos
)
6367 /* For bidi iteration, we need to prime prev_stop and
6368 base_level_stop with our best estimations. */
6369 /* Implementation note: Of course, POS is not necessarily a
6370 stop position, so assigning prev_pos to it is a lie; we
6371 should have called compute_stop_backwards. However, if
6372 the current buffer does not include any R2L characters,
6373 that call would be a waste of cycles, because the
6374 iterator will never move back, and thus never cross this
6375 "fake" stop position. So we delay that backward search
6376 until the time we really need it, in next_element_from_buffer. */
6377 if (CHARPOS (pos
) != it
->prev_stop
)
6378 it
->prev_stop
= CHARPOS (pos
);
6379 if (CHARPOS (pos
) < it
->base_level_stop
)
6380 it
->base_level_stop
= 0; /* meaning it's unknown */
6386 it
->prev_stop
= it
->base_level_stop
= 0;
6395 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6396 IT->stop_pos to POS, also. */
6399 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6401 /* Don't call this function when scanning a C string. */
6402 eassert (it
->s
== NULL
);
6404 /* POS must be a reasonable value. */
6405 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6407 it
->current
.pos
= it
->position
= pos
;
6408 it
->end_charpos
= ZV
;
6410 it
->current
.dpvec_index
= -1;
6411 it
->current
.overlay_string_index
= -1;
6412 IT_STRING_CHARPOS (*it
) = -1;
6413 IT_STRING_BYTEPOS (*it
) = -1;
6415 it
->method
= GET_FROM_BUFFER
;
6416 it
->object
= it
->w
->contents
;
6417 it
->area
= TEXT_AREA
;
6418 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6420 it
->string_from_display_prop_p
= 0;
6421 it
->string_from_prefix_prop_p
= 0;
6423 it
->from_disp_prop_p
= 0;
6424 it
->face_before_selective_p
= 0;
6427 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6429 bidi_unshelve_cache (NULL
, 0);
6430 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6431 it
->bidi_it
.string
.s
= NULL
;
6432 it
->bidi_it
.string
.lstring
= Qnil
;
6433 it
->bidi_it
.string
.bufpos
= 0;
6434 it
->bidi_it
.string
.unibyte
= 0;
6435 it
->bidi_it
.w
= it
->w
;
6440 it
->stop_charpos
= CHARPOS (pos
);
6441 it
->base_level_stop
= CHARPOS (pos
);
6443 /* This make the information stored in it->cmp_it invalidate. */
6448 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6449 If S is non-null, it is a C string to iterate over. Otherwise,
6450 STRING gives a Lisp string to iterate over.
6452 If PRECISION > 0, don't return more then PRECISION number of
6453 characters from the string.
6455 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6456 characters have been returned. FIELD_WIDTH < 0 means an infinite
6459 MULTIBYTE = 0 means disable processing of multibyte characters,
6460 MULTIBYTE > 0 means enable it,
6461 MULTIBYTE < 0 means use IT->multibyte_p.
6463 IT must be initialized via a prior call to init_iterator before
6464 calling this function. */
6467 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6468 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6471 /* No region in strings. */
6472 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6474 /* No text property checks performed by default, but see below. */
6475 it
->stop_charpos
= -1;
6477 /* Set iterator position and end position. */
6478 memset (&it
->current
, 0, sizeof it
->current
);
6479 it
->current
.overlay_string_index
= -1;
6480 it
->current
.dpvec_index
= -1;
6481 eassert (charpos
>= 0);
6483 /* If STRING is specified, use its multibyteness, otherwise use the
6484 setting of MULTIBYTE, if specified. */
6486 it
->multibyte_p
= multibyte
> 0;
6488 /* Bidirectional reordering of strings is controlled by the default
6489 value of bidi-display-reordering. Don't try to reorder while
6490 loading loadup.el, as the necessary character property tables are
6491 not yet available. */
6494 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6498 eassert (STRINGP (string
));
6499 it
->string
= string
;
6501 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6502 it
->method
= GET_FROM_STRING
;
6503 it
->current
.string_pos
= string_pos (charpos
, string
);
6507 it
->bidi_it
.string
.lstring
= string
;
6508 it
->bidi_it
.string
.s
= NULL
;
6509 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6510 it
->bidi_it
.string
.bufpos
= 0;
6511 it
->bidi_it
.string
.from_disp_str
= 0;
6512 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6513 it
->bidi_it
.w
= it
->w
;
6514 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6515 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6520 it
->s
= (const unsigned char *) s
;
6523 /* Note that we use IT->current.pos, not it->current.string_pos,
6524 for displaying C strings. */
6525 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6526 if (it
->multibyte_p
)
6528 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6529 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6533 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6534 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6539 it
->bidi_it
.string
.lstring
= Qnil
;
6540 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6541 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6542 it
->bidi_it
.string
.bufpos
= 0;
6543 it
->bidi_it
.string
.from_disp_str
= 0;
6544 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6545 it
->bidi_it
.w
= it
->w
;
6546 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6549 it
->method
= GET_FROM_C_STRING
;
6552 /* PRECISION > 0 means don't return more than PRECISION characters
6554 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6556 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6558 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6561 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6562 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6563 FIELD_WIDTH < 0 means infinite field width. This is useful for
6564 padding with `-' at the end of a mode line. */
6565 if (field_width
< 0)
6566 field_width
= INFINITY
;
6567 /* Implementation note: We deliberately don't enlarge
6568 it->bidi_it.string.schars here to fit it->end_charpos, because
6569 the bidi iterator cannot produce characters out of thin air. */
6570 if (field_width
> it
->end_charpos
- charpos
)
6571 it
->end_charpos
= charpos
+ field_width
;
6573 /* Use the standard display table for displaying strings. */
6574 if (DISP_TABLE_P (Vstandard_display_table
))
6575 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6577 it
->stop_charpos
= charpos
;
6578 it
->prev_stop
= charpos
;
6579 it
->base_level_stop
= 0;
6582 it
->bidi_it
.first_elt
= 1;
6583 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6584 it
->bidi_it
.disp_pos
= -1;
6586 if (s
== NULL
&& it
->multibyte_p
)
6588 ptrdiff_t endpos
= SCHARS (it
->string
);
6589 if (endpos
> it
->end_charpos
)
6590 endpos
= it
->end_charpos
;
6591 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6599 /***********************************************************************
6601 ***********************************************************************/
6603 /* Map enum it_method value to corresponding next_element_from_* function. */
6605 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6607 next_element_from_buffer
,
6608 next_element_from_display_vector
,
6609 next_element_from_string
,
6610 next_element_from_c_string
,
6611 next_element_from_image
,
6612 next_element_from_stretch
6615 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6618 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6619 (possibly with the following characters). */
6621 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6622 ((IT)->cmp_it.id >= 0 \
6623 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6624 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6625 END_CHARPOS, (IT)->w, \
6626 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6630 /* Lookup the char-table Vglyphless_char_display for character C (-1
6631 if we want information for no-font case), and return the display
6632 method symbol. By side-effect, update it->what and
6633 it->glyphless_method. This function is called from
6634 get_next_display_element for each character element, and from
6635 x_produce_glyphs when no suitable font was found. */
6638 lookup_glyphless_char_display (int c
, struct it
*it
)
6640 Lisp_Object glyphless_method
= Qnil
;
6642 if (CHAR_TABLE_P (Vglyphless_char_display
)
6643 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6647 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6648 if (CONSP (glyphless_method
))
6649 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6650 ? XCAR (glyphless_method
)
6651 : XCDR (glyphless_method
);
6654 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6658 if (NILP (glyphless_method
))
6661 /* The default is to display the character by a proper font. */
6663 /* The default for the no-font case is to display an empty box. */
6664 glyphless_method
= Qempty_box
;
6666 if (EQ (glyphless_method
, Qzero_width
))
6669 return glyphless_method
;
6670 /* This method can't be used for the no-font case. */
6671 glyphless_method
= Qempty_box
;
6673 if (EQ (glyphless_method
, Qthin_space
))
6674 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6675 else if (EQ (glyphless_method
, Qempty_box
))
6676 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6677 else if (EQ (glyphless_method
, Qhex_code
))
6678 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6679 else if (STRINGP (glyphless_method
))
6680 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6683 /* Invalid value. We use the default method. */
6684 glyphless_method
= Qnil
;
6687 it
->what
= IT_GLYPHLESS
;
6688 return glyphless_method
;
6691 /* Load IT's display element fields with information about the next
6692 display element from the current position of IT. Value is zero if
6693 end of buffer (or C string) is reached. */
6695 static struct frame
*last_escape_glyph_frame
= NULL
;
6696 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6697 static int last_escape_glyph_merged_face_id
= 0;
6699 struct frame
*last_glyphless_glyph_frame
= NULL
;
6700 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6701 int last_glyphless_glyph_merged_face_id
= 0;
6704 get_next_display_element (struct it
*it
)
6706 /* Non-zero means that we found a display element. Zero means that
6707 we hit the end of what we iterate over. Performance note: the
6708 function pointer `method' used here turns out to be faster than
6709 using a sequence of if-statements. */
6713 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6715 if (it
->what
== IT_CHARACTER
)
6717 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6718 and only if (a) the resolved directionality of that character
6720 /* FIXME: Do we need an exception for characters from display
6722 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6723 it
->c
= bidi_mirror_char (it
->c
);
6724 /* Map via display table or translate control characters.
6725 IT->c, IT->len etc. have been set to the next character by
6726 the function call above. If we have a display table, and it
6727 contains an entry for IT->c, translate it. Don't do this if
6728 IT->c itself comes from a display table, otherwise we could
6729 end up in an infinite recursion. (An alternative could be to
6730 count the recursion depth of this function and signal an
6731 error when a certain maximum depth is reached.) Is it worth
6733 if (success_p
&& it
->dpvec
== NULL
)
6736 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6737 int nonascii_space_p
= 0;
6738 int nonascii_hyphen_p
= 0;
6739 int c
= it
->c
; /* This is the character to display. */
6741 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6743 eassert (SINGLE_BYTE_CHAR_P (c
));
6744 if (unibyte_display_via_language_environment
)
6746 c
= DECODE_CHAR (unibyte
, c
);
6748 c
= BYTE8_TO_CHAR (it
->c
);
6751 c
= BYTE8_TO_CHAR (it
->c
);
6755 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6758 struct Lisp_Vector
*v
= XVECTOR (dv
);
6760 /* Return the first character from the display table
6761 entry, if not empty. If empty, don't display the
6762 current character. */
6765 it
->dpvec_char_len
= it
->len
;
6766 it
->dpvec
= v
->contents
;
6767 it
->dpend
= v
->contents
+ v
->header
.size
;
6768 it
->current
.dpvec_index
= 0;
6769 it
->dpvec_face_id
= -1;
6770 it
->saved_face_id
= it
->face_id
;
6771 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6776 set_iterator_to_next (it
, 0);
6781 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6783 if (it
->what
== IT_GLYPHLESS
)
6785 /* Don't display this character. */
6786 set_iterator_to_next (it
, 0);
6790 /* If `nobreak-char-display' is non-nil, we display
6791 non-ASCII spaces and hyphens specially. */
6792 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6795 nonascii_space_p
= 1;
6796 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6797 nonascii_hyphen_p
= 1;
6800 /* Translate control characters into `\003' or `^C' form.
6801 Control characters coming from a display table entry are
6802 currently not translated because we use IT->dpvec to hold
6803 the translation. This could easily be changed but I
6804 don't believe that it is worth doing.
6806 The characters handled by `nobreak-char-display' must be
6809 Non-printable characters and raw-byte characters are also
6810 translated to octal form. */
6811 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6812 ? (it
->area
!= TEXT_AREA
6813 /* In mode line, treat \n, \t like other crl chars. */
6816 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6817 || (c
!= '\n' && c
!= '\t'))
6819 || nonascii_hyphen_p
6821 || ! CHAR_PRINTABLE_P (c
))))
6823 /* C is a control character, non-ASCII space/hyphen,
6824 raw-byte, or a non-printable character which must be
6825 displayed either as '\003' or as `^C' where the '\\'
6826 and '^' can be defined in the display table. Fill
6827 IT->ctl_chars with glyphs for what we have to
6828 display. Then, set IT->dpvec to these glyphs. */
6835 /* Handle control characters with ^. */
6837 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6841 g
= '^'; /* default glyph for Control */
6842 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6844 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6846 g
= GLYPH_CODE_CHAR (gc
);
6847 lface_id
= GLYPH_CODE_FACE (gc
);
6851 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6853 else if (it
->f
== last_escape_glyph_frame
6854 && it
->face_id
== last_escape_glyph_face_id
)
6856 face_id
= last_escape_glyph_merged_face_id
;
6860 /* Merge the escape-glyph face into the current face. */
6861 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6863 last_escape_glyph_frame
= it
->f
;
6864 last_escape_glyph_face_id
= it
->face_id
;
6865 last_escape_glyph_merged_face_id
= face_id
;
6868 XSETINT (it
->ctl_chars
[0], g
);
6869 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6871 goto display_control
;
6874 /* Handle non-ascii space in the mode where it only gets
6877 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6879 /* Merge `nobreak-space' into the current face. */
6880 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6882 XSETINT (it
->ctl_chars
[0], ' ');
6884 goto display_control
;
6887 /* Handle sequences that start with the "escape glyph". */
6889 /* the default escape glyph is \. */
6890 escape_glyph
= '\\';
6893 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6895 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6896 lface_id
= GLYPH_CODE_FACE (gc
);
6900 /* The display table specified a face.
6901 Merge it into face_id and also into escape_glyph. */
6902 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6905 else if (it
->f
== last_escape_glyph_frame
6906 && it
->face_id
== last_escape_glyph_face_id
)
6908 face_id
= last_escape_glyph_merged_face_id
;
6912 /* Merge the escape-glyph face into the current face. */
6913 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6915 last_escape_glyph_frame
= it
->f
;
6916 last_escape_glyph_face_id
= it
->face_id
;
6917 last_escape_glyph_merged_face_id
= face_id
;
6920 /* Draw non-ASCII hyphen with just highlighting: */
6922 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6924 XSETINT (it
->ctl_chars
[0], '-');
6926 goto display_control
;
6929 /* Draw non-ASCII space/hyphen with escape glyph: */
6931 if (nonascii_space_p
|| nonascii_hyphen_p
)
6933 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6934 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6936 goto display_control
;
6943 if (CHAR_BYTE8_P (c
))
6944 /* Display \200 instead of \17777600. */
6945 c
= CHAR_TO_BYTE8 (c
);
6946 len
= sprintf (str
, "%03o", c
);
6948 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6949 for (i
= 0; i
< len
; i
++)
6950 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6955 /* Set up IT->dpvec and return first character from it. */
6956 it
->dpvec_char_len
= it
->len
;
6957 it
->dpvec
= it
->ctl_chars
;
6958 it
->dpend
= it
->dpvec
+ ctl_len
;
6959 it
->current
.dpvec_index
= 0;
6960 it
->dpvec_face_id
= face_id
;
6961 it
->saved_face_id
= it
->face_id
;
6962 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6966 it
->char_to_display
= c
;
6970 it
->char_to_display
= it
->c
;
6974 /* Adjust face id for a multibyte character. There are no multibyte
6975 character in unibyte text. */
6976 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6979 && FRAME_WINDOW_P (it
->f
))
6981 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6983 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6985 /* Automatic composition with glyph-string. */
6986 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6988 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6992 ptrdiff_t pos
= (it
->s
? -1
6993 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6994 : IT_CHARPOS (*it
));
6997 if (it
->what
== IT_CHARACTER
)
6998 c
= it
->char_to_display
;
7001 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7005 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7006 /* TAB in a composition means display glyphs with
7007 padding space on the left or right. */
7008 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7011 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7016 /* Is this character the last one of a run of characters with
7017 box? If yes, set IT->end_of_box_run_p to 1. */
7021 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7023 int face_id
= underlying_face_id (it
);
7024 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7028 if (face
->box
== FACE_NO_BOX
)
7030 /* If the box comes from face properties in a
7031 display string, check faces in that string. */
7032 int string_face_id
= face_after_it_pos (it
);
7033 it
->end_of_box_run_p
7034 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7037 /* Otherwise, the box comes from the underlying face.
7038 If this is the last string character displayed, check
7039 the next buffer location. */
7040 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7041 && (it
->current
.overlay_string_index
7042 == it
->n_overlay_strings
- 1))
7046 struct text_pos pos
= it
->current
.pos
;
7047 INC_TEXT_POS (pos
, it
->multibyte_p
);
7049 next_face_id
= face_at_buffer_position
7050 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7051 it
->region_end_charpos
, &ignore
,
7052 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7054 it
->end_of_box_run_p
7055 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7060 /* next_element_from_display_vector sets this flag according to
7061 faces of the display vector glyphs, see there. */
7062 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7064 int face_id
= face_after_it_pos (it
);
7065 it
->end_of_box_run_p
7066 = (face_id
!= it
->face_id
7067 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7070 /* If we reached the end of the object we've been iterating (e.g., a
7071 display string or an overlay string), and there's something on
7072 IT->stack, proceed with what's on the stack. It doesn't make
7073 sense to return zero if there's unprocessed stuff on the stack,
7074 because otherwise that stuff will never be displayed. */
7075 if (!success_p
&& it
->sp
> 0)
7077 set_iterator_to_next (it
, 0);
7078 success_p
= get_next_display_element (it
);
7081 /* Value is 0 if end of buffer or string reached. */
7086 /* Move IT to the next display element.
7088 RESEAT_P non-zero means if called on a newline in buffer text,
7089 skip to the next visible line start.
7091 Functions get_next_display_element and set_iterator_to_next are
7092 separate because I find this arrangement easier to handle than a
7093 get_next_display_element function that also increments IT's
7094 position. The way it is we can first look at an iterator's current
7095 display element, decide whether it fits on a line, and if it does,
7096 increment the iterator position. The other way around we probably
7097 would either need a flag indicating whether the iterator has to be
7098 incremented the next time, or we would have to implement a
7099 decrement position function which would not be easy to write. */
7102 set_iterator_to_next (struct it
*it
, int reseat_p
)
7104 /* Reset flags indicating start and end of a sequence of characters
7105 with box. Reset them at the start of this function because
7106 moving the iterator to a new position might set them. */
7107 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7111 case GET_FROM_BUFFER
:
7112 /* The current display element of IT is a character from
7113 current_buffer. Advance in the buffer, and maybe skip over
7114 invisible lines that are so because of selective display. */
7115 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7116 reseat_at_next_visible_line_start (it
, 0);
7117 else if (it
->cmp_it
.id
>= 0)
7119 /* We are currently getting glyphs from a composition. */
7124 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7125 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7126 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7128 it
->cmp_it
.from
= it
->cmp_it
.to
;
7133 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7135 it
->end_charpos
, Qnil
);
7138 else if (! it
->cmp_it
.reversed_p
)
7140 /* Composition created while scanning forward. */
7141 /* Update IT's char/byte positions to point to the first
7142 character of the next grapheme cluster, or to the
7143 character visually after the current composition. */
7144 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7145 bidi_move_to_visually_next (&it
->bidi_it
);
7146 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7147 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7149 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7151 /* Proceed to the next grapheme cluster. */
7152 it
->cmp_it
.from
= it
->cmp_it
.to
;
7156 /* No more grapheme clusters in this composition.
7157 Find the next stop position. */
7158 ptrdiff_t stop
= it
->end_charpos
;
7159 if (it
->bidi_it
.scan_dir
< 0)
7160 /* Now we are scanning backward and don't know
7163 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7164 IT_BYTEPOS (*it
), stop
, Qnil
);
7169 /* Composition created while scanning backward. */
7170 /* Update IT's char/byte positions to point to the last
7171 character of the previous grapheme cluster, or the
7172 character visually after the current composition. */
7173 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7174 bidi_move_to_visually_next (&it
->bidi_it
);
7175 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7176 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7177 if (it
->cmp_it
.from
> 0)
7179 /* Proceed to the previous grapheme cluster. */
7180 it
->cmp_it
.to
= it
->cmp_it
.from
;
7184 /* No more grapheme clusters in this composition.
7185 Find the next stop position. */
7186 ptrdiff_t stop
= it
->end_charpos
;
7187 if (it
->bidi_it
.scan_dir
< 0)
7188 /* Now we are scanning backward and don't know
7191 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7192 IT_BYTEPOS (*it
), stop
, Qnil
);
7198 eassert (it
->len
!= 0);
7202 IT_BYTEPOS (*it
) += it
->len
;
7203 IT_CHARPOS (*it
) += 1;
7207 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7208 /* If this is a new paragraph, determine its base
7209 direction (a.k.a. its base embedding level). */
7210 if (it
->bidi_it
.new_paragraph
)
7211 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7212 bidi_move_to_visually_next (&it
->bidi_it
);
7213 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7214 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7215 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7217 /* As the scan direction was changed, we must
7218 re-compute the stop position for composition. */
7219 ptrdiff_t stop
= it
->end_charpos
;
7220 if (it
->bidi_it
.scan_dir
< 0)
7222 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7223 IT_BYTEPOS (*it
), stop
, Qnil
);
7226 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7230 case GET_FROM_C_STRING
:
7231 /* Current display element of IT is from a C string. */
7233 /* If the string position is beyond string's end, it means
7234 next_element_from_c_string is padding the string with
7235 blanks, in which case we bypass the bidi iterator,
7236 because it cannot deal with such virtual characters. */
7237 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7239 IT_BYTEPOS (*it
) += it
->len
;
7240 IT_CHARPOS (*it
) += 1;
7244 bidi_move_to_visually_next (&it
->bidi_it
);
7245 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7246 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7250 case GET_FROM_DISPLAY_VECTOR
:
7251 /* Current display element of IT is from a display table entry.
7252 Advance in the display table definition. Reset it to null if
7253 end reached, and continue with characters from buffers/
7255 ++it
->current
.dpvec_index
;
7257 /* Restore face of the iterator to what they were before the
7258 display vector entry (these entries may contain faces). */
7259 it
->face_id
= it
->saved_face_id
;
7261 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7263 int recheck_faces
= it
->ellipsis_p
;
7266 it
->method
= GET_FROM_C_STRING
;
7267 else if (STRINGP (it
->string
))
7268 it
->method
= GET_FROM_STRING
;
7271 it
->method
= GET_FROM_BUFFER
;
7272 it
->object
= it
->w
->contents
;
7276 it
->current
.dpvec_index
= -1;
7278 /* Skip over characters which were displayed via IT->dpvec. */
7279 if (it
->dpvec_char_len
< 0)
7280 reseat_at_next_visible_line_start (it
, 1);
7281 else if (it
->dpvec_char_len
> 0)
7283 if (it
->method
== GET_FROM_STRING
7284 && it
->current
.overlay_string_index
>= 0
7285 && it
->n_overlay_strings
> 0)
7286 it
->ignore_overlay_strings_at_pos_p
= 1;
7287 it
->len
= it
->dpvec_char_len
;
7288 set_iterator_to_next (it
, reseat_p
);
7291 /* Maybe recheck faces after display vector */
7293 it
->stop_charpos
= IT_CHARPOS (*it
);
7297 case GET_FROM_STRING
:
7298 /* Current display element is a character from a Lisp string. */
7299 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7300 /* Don't advance past string end. These conditions are true
7301 when set_iterator_to_next is called at the end of
7302 get_next_display_element, in which case the Lisp string is
7303 already exhausted, and all we want is pop the iterator
7305 if (it
->current
.overlay_string_index
>= 0)
7307 /* This is an overlay string, so there's no padding with
7308 spaces, and the number of characters in the string is
7309 where the string ends. */
7310 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7311 goto consider_string_end
;
7315 /* Not an overlay string. There could be padding, so test
7316 against it->end_charpos . */
7317 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7318 goto consider_string_end
;
7320 if (it
->cmp_it
.id
>= 0)
7326 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7327 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7328 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7329 it
->cmp_it
.from
= it
->cmp_it
.to
;
7333 composition_compute_stop_pos (&it
->cmp_it
,
7334 IT_STRING_CHARPOS (*it
),
7335 IT_STRING_BYTEPOS (*it
),
7336 it
->end_charpos
, it
->string
);
7339 else if (! it
->cmp_it
.reversed_p
)
7341 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7342 bidi_move_to_visually_next (&it
->bidi_it
);
7343 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7344 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7346 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7347 it
->cmp_it
.from
= it
->cmp_it
.to
;
7350 ptrdiff_t stop
= it
->end_charpos
;
7351 if (it
->bidi_it
.scan_dir
< 0)
7353 composition_compute_stop_pos (&it
->cmp_it
,
7354 IT_STRING_CHARPOS (*it
),
7355 IT_STRING_BYTEPOS (*it
), stop
,
7361 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7362 bidi_move_to_visually_next (&it
->bidi_it
);
7363 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7364 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7365 if (it
->cmp_it
.from
> 0)
7366 it
->cmp_it
.to
= it
->cmp_it
.from
;
7369 ptrdiff_t stop
= it
->end_charpos
;
7370 if (it
->bidi_it
.scan_dir
< 0)
7372 composition_compute_stop_pos (&it
->cmp_it
,
7373 IT_STRING_CHARPOS (*it
),
7374 IT_STRING_BYTEPOS (*it
), stop
,
7382 /* If the string position is beyond string's end, it
7383 means next_element_from_string is padding the string
7384 with blanks, in which case we bypass the bidi
7385 iterator, because it cannot deal with such virtual
7387 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7389 IT_STRING_BYTEPOS (*it
) += it
->len
;
7390 IT_STRING_CHARPOS (*it
) += 1;
7394 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7396 bidi_move_to_visually_next (&it
->bidi_it
);
7397 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7398 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7399 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7401 ptrdiff_t stop
= it
->end_charpos
;
7403 if (it
->bidi_it
.scan_dir
< 0)
7405 composition_compute_stop_pos (&it
->cmp_it
,
7406 IT_STRING_CHARPOS (*it
),
7407 IT_STRING_BYTEPOS (*it
), stop
,
7413 consider_string_end
:
7415 if (it
->current
.overlay_string_index
>= 0)
7417 /* IT->string is an overlay string. Advance to the
7418 next, if there is one. */
7419 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7422 next_overlay_string (it
);
7424 setup_for_ellipsis (it
, 0);
7429 /* IT->string is not an overlay string. If we reached
7430 its end, and there is something on IT->stack, proceed
7431 with what is on the stack. This can be either another
7432 string, this time an overlay string, or a buffer. */
7433 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7437 if (it
->method
== GET_FROM_STRING
)
7438 goto consider_string_end
;
7443 case GET_FROM_IMAGE
:
7444 case GET_FROM_STRETCH
:
7445 /* The position etc with which we have to proceed are on
7446 the stack. The position may be at the end of a string,
7447 if the `display' property takes up the whole string. */
7448 eassert (it
->sp
> 0);
7450 if (it
->method
== GET_FROM_STRING
)
7451 goto consider_string_end
;
7455 /* There are no other methods defined, so this should be a bug. */
7459 eassert (it
->method
!= GET_FROM_STRING
7460 || (STRINGP (it
->string
)
7461 && IT_STRING_CHARPOS (*it
) >= 0));
7464 /* Load IT's display element fields with information about the next
7465 display element which comes from a display table entry or from the
7466 result of translating a control character to one of the forms `^C'
7469 IT->dpvec holds the glyphs to return as characters.
7470 IT->saved_face_id holds the face id before the display vector--it
7471 is restored into IT->face_id in set_iterator_to_next. */
7474 next_element_from_display_vector (struct it
*it
)
7477 int prev_face_id
= it
->face_id
;
7481 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7483 it
->face_id
= it
->saved_face_id
;
7485 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7486 That seemed totally bogus - so I changed it... */
7487 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7489 if (GLYPH_CODE_P (gc
))
7491 struct face
*this_face
, *prev_face
, *next_face
;
7493 it
->c
= GLYPH_CODE_CHAR (gc
);
7494 it
->len
= CHAR_BYTES (it
->c
);
7496 /* The entry may contain a face id to use. Such a face id is
7497 the id of a Lisp face, not a realized face. A face id of
7498 zero means no face is specified. */
7499 if (it
->dpvec_face_id
>= 0)
7500 it
->face_id
= it
->dpvec_face_id
;
7503 int lface_id
= GLYPH_CODE_FACE (gc
);
7505 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7509 /* Glyphs in the display vector could have the box face, so we
7510 need to set the related flags in the iterator, as
7512 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7513 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7515 /* Is this character the first character of a box-face run? */
7516 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7518 || prev_face
->box
== FACE_NO_BOX
));
7520 /* For the last character of the box-face run, we need to look
7521 either at the next glyph from the display vector, or at the
7522 face we saw before the display vector. */
7523 next_face_id
= it
->saved_face_id
;
7524 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7526 if (it
->dpvec_face_id
>= 0)
7527 next_face_id
= it
->dpvec_face_id
;
7531 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7534 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7538 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7539 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7541 || next_face
->box
== FACE_NO_BOX
));
7542 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7545 /* Display table entry is invalid. Return a space. */
7546 it
->c
= ' ', it
->len
= 1;
7548 /* Don't change position and object of the iterator here. They are
7549 still the values of the character that had this display table
7550 entry or was translated, and that's what we want. */
7551 it
->what
= IT_CHARACTER
;
7555 /* Get the first element of string/buffer in the visual order, after
7556 being reseated to a new position in a string or a buffer. */
7558 get_visually_first_element (struct it
*it
)
7560 int string_p
= STRINGP (it
->string
) || it
->s
;
7561 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7562 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7564 if (STRINGP (it
->string
))
7566 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7567 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7571 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7572 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7575 if (it
->bidi_it
.charpos
== eob
)
7577 /* Nothing to do, but reset the FIRST_ELT flag, like
7578 bidi_paragraph_init does, because we are not going to
7580 it
->bidi_it
.first_elt
= 0;
7582 else if (it
->bidi_it
.charpos
== bob
7584 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7585 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7587 /* If we are at the beginning of a line/string, we can produce
7588 the next element right away. */
7589 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7590 bidi_move_to_visually_next (&it
->bidi_it
);
7594 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7596 /* We need to prime the bidi iterator starting at the line's or
7597 string's beginning, before we will be able to produce the
7600 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7602 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7603 IT_BYTEPOS (*it
), -1,
7604 &it
->bidi_it
.bytepos
);
7605 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7608 /* Now return to buffer/string position where we were asked
7609 to get the next display element, and produce that. */
7610 bidi_move_to_visually_next (&it
->bidi_it
);
7612 while (it
->bidi_it
.bytepos
!= orig_bytepos
7613 && it
->bidi_it
.charpos
< eob
);
7616 /* Adjust IT's position information to where we ended up. */
7617 if (STRINGP (it
->string
))
7619 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7620 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7624 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7625 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7628 if (STRINGP (it
->string
) || !it
->s
)
7630 ptrdiff_t stop
, charpos
, bytepos
;
7632 if (STRINGP (it
->string
))
7635 stop
= SCHARS (it
->string
);
7636 if (stop
> it
->end_charpos
)
7637 stop
= it
->end_charpos
;
7638 charpos
= IT_STRING_CHARPOS (*it
);
7639 bytepos
= IT_STRING_BYTEPOS (*it
);
7643 stop
= it
->end_charpos
;
7644 charpos
= IT_CHARPOS (*it
);
7645 bytepos
= IT_BYTEPOS (*it
);
7647 if (it
->bidi_it
.scan_dir
< 0)
7649 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7654 /* Load IT with the next display element from Lisp string IT->string.
7655 IT->current.string_pos is the current position within the string.
7656 If IT->current.overlay_string_index >= 0, the Lisp string is an
7660 next_element_from_string (struct it
*it
)
7662 struct text_pos position
;
7664 eassert (STRINGP (it
->string
));
7665 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7666 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7667 position
= it
->current
.string_pos
;
7669 /* With bidi reordering, the character to display might not be the
7670 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7671 that we were reseat()ed to a new string, whose paragraph
7672 direction is not known. */
7673 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7675 get_visually_first_element (it
);
7676 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7679 /* Time to check for invisible text? */
7680 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7682 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7685 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7686 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7688 /* With bidi non-linear iteration, we could find
7689 ourselves far beyond the last computed stop_charpos,
7690 with several other stop positions in between that we
7691 missed. Scan them all now, in buffer's logical
7692 order, until we find and handle the last stop_charpos
7693 that precedes our current position. */
7694 handle_stop_backwards (it
, it
->stop_charpos
);
7695 return GET_NEXT_DISPLAY_ELEMENT (it
);
7701 /* Take note of the stop position we just moved
7702 across, for when we will move back across it. */
7703 it
->prev_stop
= it
->stop_charpos
;
7704 /* If we are at base paragraph embedding level, take
7705 note of the last stop position seen at this
7707 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7708 it
->base_level_stop
= it
->stop_charpos
;
7712 /* Since a handler may have changed IT->method, we must
7714 return GET_NEXT_DISPLAY_ELEMENT (it
);
7718 /* If we are before prev_stop, we may have overstepped
7719 on our way backwards a stop_pos, and if so, we need
7720 to handle that stop_pos. */
7721 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7722 /* We can sometimes back up for reasons that have nothing
7723 to do with bidi reordering. E.g., compositions. The
7724 code below is only needed when we are above the base
7725 embedding level, so test for that explicitly. */
7726 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7728 /* If we lost track of base_level_stop, we have no better
7729 place for handle_stop_backwards to start from than string
7730 beginning. This happens, e.g., when we were reseated to
7731 the previous screenful of text by vertical-motion. */
7732 if (it
->base_level_stop
<= 0
7733 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7734 it
->base_level_stop
= 0;
7735 handle_stop_backwards (it
, it
->base_level_stop
);
7736 return GET_NEXT_DISPLAY_ELEMENT (it
);
7740 if (it
->current
.overlay_string_index
>= 0)
7742 /* Get the next character from an overlay string. In overlay
7743 strings, there is no field width or padding with spaces to
7745 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7750 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7751 IT_STRING_BYTEPOS (*it
),
7752 it
->bidi_it
.scan_dir
< 0
7754 : SCHARS (it
->string
))
7755 && next_element_from_composition (it
))
7759 else if (STRING_MULTIBYTE (it
->string
))
7761 const unsigned char *s
= (SDATA (it
->string
)
7762 + IT_STRING_BYTEPOS (*it
));
7763 it
->c
= string_char_and_length (s
, &it
->len
);
7767 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7773 /* Get the next character from a Lisp string that is not an
7774 overlay string. Such strings come from the mode line, for
7775 example. We may have to pad with spaces, or truncate the
7776 string. See also next_element_from_c_string. */
7777 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7782 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7784 /* Pad with spaces. */
7785 it
->c
= ' ', it
->len
= 1;
7786 CHARPOS (position
) = BYTEPOS (position
) = -1;
7788 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7789 IT_STRING_BYTEPOS (*it
),
7790 it
->bidi_it
.scan_dir
< 0
7792 : it
->string_nchars
)
7793 && next_element_from_composition (it
))
7797 else if (STRING_MULTIBYTE (it
->string
))
7799 const unsigned char *s
= (SDATA (it
->string
)
7800 + IT_STRING_BYTEPOS (*it
));
7801 it
->c
= string_char_and_length (s
, &it
->len
);
7805 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7810 /* Record what we have and where it came from. */
7811 it
->what
= IT_CHARACTER
;
7812 it
->object
= it
->string
;
7813 it
->position
= position
;
7818 /* Load IT with next display element from C string IT->s.
7819 IT->string_nchars is the maximum number of characters to return
7820 from the string. IT->end_charpos may be greater than
7821 IT->string_nchars when this function is called, in which case we
7822 may have to return padding spaces. Value is zero if end of string
7823 reached, including padding spaces. */
7826 next_element_from_c_string (struct it
*it
)
7831 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7832 it
->what
= IT_CHARACTER
;
7833 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7836 /* With bidi reordering, the character to display might not be the
7837 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7838 we were reseated to a new string, whose paragraph direction is
7840 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7841 get_visually_first_element (it
);
7843 /* IT's position can be greater than IT->string_nchars in case a
7844 field width or precision has been specified when the iterator was
7846 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7848 /* End of the game. */
7852 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7854 /* Pad with spaces. */
7855 it
->c
= ' ', it
->len
= 1;
7856 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7858 else if (it
->multibyte_p
)
7859 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7861 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7867 /* Set up IT to return characters from an ellipsis, if appropriate.
7868 The definition of the ellipsis glyphs may come from a display table
7869 entry. This function fills IT with the first glyph from the
7870 ellipsis if an ellipsis is to be displayed. */
7873 next_element_from_ellipsis (struct it
*it
)
7875 if (it
->selective_display_ellipsis_p
)
7876 setup_for_ellipsis (it
, it
->len
);
7879 /* The face at the current position may be different from the
7880 face we find after the invisible text. Remember what it
7881 was in IT->saved_face_id, and signal that it's there by
7882 setting face_before_selective_p. */
7883 it
->saved_face_id
= it
->face_id
;
7884 it
->method
= GET_FROM_BUFFER
;
7885 it
->object
= it
->w
->contents
;
7886 reseat_at_next_visible_line_start (it
, 1);
7887 it
->face_before_selective_p
= 1;
7890 return GET_NEXT_DISPLAY_ELEMENT (it
);
7894 /* Deliver an image display element. The iterator IT is already
7895 filled with image information (done in handle_display_prop). Value
7900 next_element_from_image (struct it
*it
)
7902 it
->what
= IT_IMAGE
;
7903 it
->ignore_overlay_strings_at_pos_p
= 0;
7908 /* Fill iterator IT with next display element from a stretch glyph
7909 property. IT->object is the value of the text property. Value is
7913 next_element_from_stretch (struct it
*it
)
7915 it
->what
= IT_STRETCH
;
7919 /* Scan backwards from IT's current position until we find a stop
7920 position, or until BEGV. This is called when we find ourself
7921 before both the last known prev_stop and base_level_stop while
7922 reordering bidirectional text. */
7925 compute_stop_pos_backwards (struct it
*it
)
7927 const int SCAN_BACK_LIMIT
= 1000;
7928 struct text_pos pos
;
7929 struct display_pos save_current
= it
->current
;
7930 struct text_pos save_position
= it
->position
;
7931 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7932 ptrdiff_t where_we_are
= charpos
;
7933 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7934 ptrdiff_t save_end_pos
= it
->end_charpos
;
7936 eassert (NILP (it
->string
) && !it
->s
);
7937 eassert (it
->bidi_p
);
7941 it
->end_charpos
= min (charpos
+ 1, ZV
);
7942 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7943 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7944 reseat_1 (it
, pos
, 0);
7945 compute_stop_pos (it
);
7946 /* We must advance forward, right? */
7947 if (it
->stop_charpos
<= charpos
)
7950 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7952 if (it
->stop_charpos
<= where_we_are
)
7953 it
->prev_stop
= it
->stop_charpos
;
7955 it
->prev_stop
= BEGV
;
7957 it
->current
= save_current
;
7958 it
->position
= save_position
;
7959 it
->stop_charpos
= save_stop_pos
;
7960 it
->end_charpos
= save_end_pos
;
7963 /* Scan forward from CHARPOS in the current buffer/string, until we
7964 find a stop position > current IT's position. Then handle the stop
7965 position before that. This is called when we bump into a stop
7966 position while reordering bidirectional text. CHARPOS should be
7967 the last previously processed stop_pos (or BEGV/0, if none were
7968 processed yet) whose position is less that IT's current
7972 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7974 int bufp
= !STRINGP (it
->string
);
7975 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7976 struct display_pos save_current
= it
->current
;
7977 struct text_pos save_position
= it
->position
;
7978 struct text_pos pos1
;
7979 ptrdiff_t next_stop
;
7981 /* Scan in strict logical order. */
7982 eassert (it
->bidi_p
);
7986 it
->prev_stop
= charpos
;
7989 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7990 reseat_1 (it
, pos1
, 0);
7993 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7994 compute_stop_pos (it
);
7995 /* We must advance forward, right? */
7996 if (it
->stop_charpos
<= it
->prev_stop
)
7998 charpos
= it
->stop_charpos
;
8000 while (charpos
<= where_we_are
);
8003 it
->current
= save_current
;
8004 it
->position
= save_position
;
8005 next_stop
= it
->stop_charpos
;
8006 it
->stop_charpos
= it
->prev_stop
;
8008 it
->stop_charpos
= next_stop
;
8011 /* Load IT with the next display element from current_buffer. Value
8012 is zero if end of buffer reached. IT->stop_charpos is the next
8013 position at which to stop and check for text properties or buffer
8017 next_element_from_buffer (struct it
*it
)
8021 eassert (IT_CHARPOS (*it
) >= BEGV
);
8022 eassert (NILP (it
->string
) && !it
->s
);
8023 eassert (!it
->bidi_p
8024 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8025 && it
->bidi_it
.string
.s
== NULL
));
8027 /* With bidi reordering, the character to display might not be the
8028 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8029 we were reseat()ed to a new buffer position, which is potentially
8030 a different paragraph. */
8031 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8033 get_visually_first_element (it
);
8034 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8037 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8039 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8041 int overlay_strings_follow_p
;
8043 /* End of the game, except when overlay strings follow that
8044 haven't been returned yet. */
8045 if (it
->overlay_strings_at_end_processed_p
)
8046 overlay_strings_follow_p
= 0;
8049 it
->overlay_strings_at_end_processed_p
= 1;
8050 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8053 if (overlay_strings_follow_p
)
8054 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8058 it
->position
= it
->current
.pos
;
8062 else if (!(!it
->bidi_p
8063 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8064 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8066 /* With bidi non-linear iteration, we could find ourselves
8067 far beyond the last computed stop_charpos, with several
8068 other stop positions in between that we missed. Scan
8069 them all now, in buffer's logical order, until we find
8070 and handle the last stop_charpos that precedes our
8071 current position. */
8072 handle_stop_backwards (it
, it
->stop_charpos
);
8073 return GET_NEXT_DISPLAY_ELEMENT (it
);
8079 /* Take note of the stop position we just moved across,
8080 for when we will move back across it. */
8081 it
->prev_stop
= it
->stop_charpos
;
8082 /* If we are at base paragraph embedding level, take
8083 note of the last stop position seen at this
8085 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8086 it
->base_level_stop
= it
->stop_charpos
;
8089 return GET_NEXT_DISPLAY_ELEMENT (it
);
8093 /* If we are before prev_stop, we may have overstepped on
8094 our way backwards a stop_pos, and if so, we need to
8095 handle that stop_pos. */
8096 && IT_CHARPOS (*it
) < it
->prev_stop
8097 /* We can sometimes back up for reasons that have nothing
8098 to do with bidi reordering. E.g., compositions. The
8099 code below is only needed when we are above the base
8100 embedding level, so test for that explicitly. */
8101 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8103 if (it
->base_level_stop
<= 0
8104 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8106 /* If we lost track of base_level_stop, we need to find
8107 prev_stop by looking backwards. This happens, e.g., when
8108 we were reseated to the previous screenful of text by
8110 it
->base_level_stop
= BEGV
;
8111 compute_stop_pos_backwards (it
);
8112 handle_stop_backwards (it
, it
->prev_stop
);
8115 handle_stop_backwards (it
, it
->base_level_stop
);
8116 return GET_NEXT_DISPLAY_ELEMENT (it
);
8120 /* No face changes, overlays etc. in sight, so just return a
8121 character from current_buffer. */
8125 /* Maybe run the redisplay end trigger hook. Performance note:
8126 This doesn't seem to cost measurable time. */
8127 if (it
->redisplay_end_trigger_charpos
8129 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8130 run_redisplay_end_trigger_hook (it
);
8132 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8133 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8135 && next_element_from_composition (it
))
8140 /* Get the next character, maybe multibyte. */
8141 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8142 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8143 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8145 it
->c
= *p
, it
->len
= 1;
8147 /* Record what we have and where it came from. */
8148 it
->what
= IT_CHARACTER
;
8149 it
->object
= it
->w
->contents
;
8150 it
->position
= it
->current
.pos
;
8152 /* Normally we return the character found above, except when we
8153 really want to return an ellipsis for selective display. */
8158 /* A value of selective > 0 means hide lines indented more
8159 than that number of columns. */
8160 if (it
->selective
> 0
8161 && IT_CHARPOS (*it
) + 1 < ZV
8162 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8163 IT_BYTEPOS (*it
) + 1,
8166 success_p
= next_element_from_ellipsis (it
);
8167 it
->dpvec_char_len
= -1;
8170 else if (it
->c
== '\r' && it
->selective
== -1)
8172 /* A value of selective == -1 means that everything from the
8173 CR to the end of the line is invisible, with maybe an
8174 ellipsis displayed for it. */
8175 success_p
= next_element_from_ellipsis (it
);
8176 it
->dpvec_char_len
= -1;
8181 /* Value is zero if end of buffer reached. */
8182 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8187 /* Run the redisplay end trigger hook for IT. */
8190 run_redisplay_end_trigger_hook (struct it
*it
)
8192 Lisp_Object args
[3];
8194 /* IT->glyph_row should be non-null, i.e. we should be actually
8195 displaying something, or otherwise we should not run the hook. */
8196 eassert (it
->glyph_row
);
8198 /* Set up hook arguments. */
8199 args
[0] = Qredisplay_end_trigger_functions
;
8200 args
[1] = it
->window
;
8201 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8202 it
->redisplay_end_trigger_charpos
= 0;
8204 /* Since we are *trying* to run these functions, don't try to run
8205 them again, even if they get an error. */
8206 wset_redisplay_end_trigger (it
->w
, Qnil
);
8207 Frun_hook_with_args (3, args
);
8209 /* Notice if it changed the face of the character we are on. */
8210 handle_face_prop (it
);
8214 /* Deliver a composition display element. Unlike the other
8215 next_element_from_XXX, this function is not registered in the array
8216 get_next_element[]. It is called from next_element_from_buffer and
8217 next_element_from_string when necessary. */
8220 next_element_from_composition (struct it
*it
)
8222 it
->what
= IT_COMPOSITION
;
8223 it
->len
= it
->cmp_it
.nbytes
;
8224 if (STRINGP (it
->string
))
8228 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8229 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8232 it
->position
= it
->current
.string_pos
;
8233 it
->object
= it
->string
;
8234 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8235 IT_STRING_BYTEPOS (*it
), it
->string
);
8241 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8242 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8245 if (it
->bidi_it
.new_paragraph
)
8246 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8247 /* Resync the bidi iterator with IT's new position.
8248 FIXME: this doesn't support bidirectional text. */
8249 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8250 bidi_move_to_visually_next (&it
->bidi_it
);
8254 it
->position
= it
->current
.pos
;
8255 it
->object
= it
->w
->contents
;
8256 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8257 IT_BYTEPOS (*it
), Qnil
);
8264 /***********************************************************************
8265 Moving an iterator without producing glyphs
8266 ***********************************************************************/
8268 /* Check if iterator is at a position corresponding to a valid buffer
8269 position after some move_it_ call. */
8271 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8272 ((it)->method == GET_FROM_STRING \
8273 ? IT_STRING_CHARPOS (*it) == 0 \
8277 /* Move iterator IT to a specified buffer or X position within one
8278 line on the display without producing glyphs.
8280 OP should be a bit mask including some or all of these bits:
8281 MOVE_TO_X: Stop upon reaching x-position TO_X.
8282 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8283 Regardless of OP's value, stop upon reaching the end of the display line.
8285 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8286 This means, in particular, that TO_X includes window's horizontal
8289 The return value has several possible values that
8290 say what condition caused the scan to stop:
8292 MOVE_POS_MATCH_OR_ZV
8293 - when TO_POS or ZV was reached.
8296 -when TO_X was reached before TO_POS or ZV were reached.
8299 - when we reached the end of the display area and the line must
8303 - when we reached the end of the display area and the line is
8307 - when we stopped at a line end, i.e. a newline or a CR and selective
8310 static enum move_it_result
8311 move_it_in_display_line_to (struct it
*it
,
8312 ptrdiff_t to_charpos
, int to_x
,
8313 enum move_operation_enum op
)
8315 enum move_it_result result
= MOVE_UNDEFINED
;
8316 struct glyph_row
*saved_glyph_row
;
8317 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8318 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8319 void *ppos_data
= NULL
;
8321 enum it_method prev_method
= it
->method
;
8322 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8323 int saw_smaller_pos
= prev_pos
< to_charpos
;
8325 /* Don't produce glyphs in produce_glyphs. */
8326 saved_glyph_row
= it
->glyph_row
;
8327 it
->glyph_row
= NULL
;
8329 /* Use wrap_it to save a copy of IT wherever a word wrap could
8330 occur. Use atpos_it to save a copy of IT at the desired buffer
8331 position, if found, so that we can scan ahead and check if the
8332 word later overshoots the window edge. Use atx_it similarly, for
8338 /* Use ppos_it under bidi reordering to save a copy of IT for the
8339 position > CHARPOS that is the closest to CHARPOS. We restore
8340 that position in IT when we have scanned the entire display line
8341 without finding a match for CHARPOS and all the character
8342 positions are greater than CHARPOS. */
8345 SAVE_IT (ppos_it
, *it
, ppos_data
);
8346 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8347 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8348 SAVE_IT (ppos_it
, *it
, ppos_data
);
8351 #define BUFFER_POS_REACHED_P() \
8352 ((op & MOVE_TO_POS) != 0 \
8353 && BUFFERP (it->object) \
8354 && (IT_CHARPOS (*it) == to_charpos \
8356 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8357 && IT_CHARPOS (*it) > to_charpos) \
8358 || (it->what == IT_COMPOSITION \
8359 && ((IT_CHARPOS (*it) > to_charpos \
8360 && to_charpos >= it->cmp_it.charpos) \
8361 || (IT_CHARPOS (*it) < to_charpos \
8362 && to_charpos <= it->cmp_it.charpos)))) \
8363 && (it->method == GET_FROM_BUFFER \
8364 || (it->method == GET_FROM_DISPLAY_VECTOR \
8365 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8367 /* If there's a line-/wrap-prefix, handle it. */
8368 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8369 && it
->current_y
< it
->last_visible_y
)
8370 handle_line_prefix (it
);
8372 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8373 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8377 int x
, i
, ascent
= 0, descent
= 0;
8379 /* Utility macro to reset an iterator with x, ascent, and descent. */
8380 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8381 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8382 (IT)->max_descent = descent)
8384 /* Stop if we move beyond TO_CHARPOS (after an image or a
8385 display string or stretch glyph). */
8386 if ((op
& MOVE_TO_POS
) != 0
8387 && BUFFERP (it
->object
)
8388 && it
->method
== GET_FROM_BUFFER
8390 /* When the iterator is at base embedding level, we
8391 are guaranteed that characters are delivered for
8392 display in strictly increasing order of their
8393 buffer positions. */
8394 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8395 && IT_CHARPOS (*it
) > to_charpos
)
8397 && (prev_method
== GET_FROM_IMAGE
8398 || prev_method
== GET_FROM_STRETCH
8399 || prev_method
== GET_FROM_STRING
)
8400 /* Passed TO_CHARPOS from left to right. */
8401 && ((prev_pos
< to_charpos
8402 && IT_CHARPOS (*it
) > to_charpos
)
8403 /* Passed TO_CHARPOS from right to left. */
8404 || (prev_pos
> to_charpos
8405 && IT_CHARPOS (*it
) < to_charpos
)))))
8407 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8409 result
= MOVE_POS_MATCH_OR_ZV
;
8412 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8413 /* If wrap_it is valid, the current position might be in a
8414 word that is wrapped. So, save the iterator in
8415 atpos_it and continue to see if wrapping happens. */
8416 SAVE_IT (atpos_it
, *it
, atpos_data
);
8419 /* Stop when ZV reached.
8420 We used to stop here when TO_CHARPOS reached as well, but that is
8421 too soon if this glyph does not fit on this line. So we handle it
8422 explicitly below. */
8423 if (!get_next_display_element (it
))
8425 result
= MOVE_POS_MATCH_OR_ZV
;
8429 if (it
->line_wrap
== TRUNCATE
)
8431 if (BUFFER_POS_REACHED_P ())
8433 result
= MOVE_POS_MATCH_OR_ZV
;
8439 if (it
->line_wrap
== WORD_WRAP
)
8441 if (IT_DISPLAYING_WHITESPACE (it
))
8445 /* We have reached a glyph that follows one or more
8446 whitespace characters. If the position is
8447 already found, we are done. */
8448 if (atpos_it
.sp
>= 0)
8450 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8451 result
= MOVE_POS_MATCH_OR_ZV
;
8456 RESTORE_IT (it
, &atx_it
, atx_data
);
8457 result
= MOVE_X_REACHED
;
8460 /* Otherwise, we can wrap here. */
8461 SAVE_IT (wrap_it
, *it
, wrap_data
);
8467 /* Remember the line height for the current line, in case
8468 the next element doesn't fit on the line. */
8469 ascent
= it
->max_ascent
;
8470 descent
= it
->max_descent
;
8472 /* The call to produce_glyphs will get the metrics of the
8473 display element IT is loaded with. Record the x-position
8474 before this display element, in case it doesn't fit on the
8478 PRODUCE_GLYPHS (it
);
8480 if (it
->area
!= TEXT_AREA
)
8482 prev_method
= it
->method
;
8483 if (it
->method
== GET_FROM_BUFFER
)
8484 prev_pos
= IT_CHARPOS (*it
);
8485 set_iterator_to_next (it
, 1);
8486 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8487 SET_TEXT_POS (this_line_min_pos
,
8488 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8490 && (op
& MOVE_TO_POS
)
8491 && IT_CHARPOS (*it
) > to_charpos
8492 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8493 SAVE_IT (ppos_it
, *it
, ppos_data
);
8497 /* The number of glyphs we get back in IT->nglyphs will normally
8498 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8499 character on a terminal frame, or (iii) a line end. For the
8500 second case, IT->nglyphs - 1 padding glyphs will be present.
8501 (On X frames, there is only one glyph produced for a
8502 composite character.)
8504 The behavior implemented below means, for continuation lines,
8505 that as many spaces of a TAB as fit on the current line are
8506 displayed there. For terminal frames, as many glyphs of a
8507 multi-glyph character are displayed in the current line, too.
8508 This is what the old redisplay code did, and we keep it that
8509 way. Under X, the whole shape of a complex character must
8510 fit on the line or it will be completely displayed in the
8513 Note that both for tabs and padding glyphs, all glyphs have
8517 /* More than one glyph or glyph doesn't fit on line. All
8518 glyphs have the same width. */
8519 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8521 int x_before_this_char
= x
;
8522 int hpos_before_this_char
= it
->hpos
;
8524 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8526 new_x
= x
+ single_glyph_width
;
8528 /* We want to leave anything reaching TO_X to the caller. */
8529 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8531 if (BUFFER_POS_REACHED_P ())
8533 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8534 goto buffer_pos_reached
;
8535 if (atpos_it
.sp
< 0)
8537 SAVE_IT (atpos_it
, *it
, atpos_data
);
8538 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8543 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8546 result
= MOVE_X_REACHED
;
8551 SAVE_IT (atx_it
, *it
, atx_data
);
8552 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8557 if (/* Lines are continued. */
8558 it
->line_wrap
!= TRUNCATE
8559 && (/* And glyph doesn't fit on the line. */
8560 new_x
> it
->last_visible_x
8561 /* Or it fits exactly and we're on a window
8563 || (new_x
== it
->last_visible_x
8564 && FRAME_WINDOW_P (it
->f
)
8565 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8566 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8567 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8569 if (/* IT->hpos == 0 means the very first glyph
8570 doesn't fit on the line, e.g. a wide image. */
8572 || (new_x
== it
->last_visible_x
8573 && FRAME_WINDOW_P (it
->f
)))
8576 it
->current_x
= new_x
;
8578 /* The character's last glyph just barely fits
8580 if (i
== it
->nglyphs
- 1)
8582 /* If this is the destination position,
8583 return a position *before* it in this row,
8584 now that we know it fits in this row. */
8585 if (BUFFER_POS_REACHED_P ())
8587 if (it
->line_wrap
!= WORD_WRAP
8590 it
->hpos
= hpos_before_this_char
;
8591 it
->current_x
= x_before_this_char
;
8592 result
= MOVE_POS_MATCH_OR_ZV
;
8595 if (it
->line_wrap
== WORD_WRAP
8598 SAVE_IT (atpos_it
, *it
, atpos_data
);
8599 atpos_it
.current_x
= x_before_this_char
;
8600 atpos_it
.hpos
= hpos_before_this_char
;
8604 prev_method
= it
->method
;
8605 if (it
->method
== GET_FROM_BUFFER
)
8606 prev_pos
= IT_CHARPOS (*it
);
8607 set_iterator_to_next (it
, 1);
8608 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8609 SET_TEXT_POS (this_line_min_pos
,
8610 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8611 /* On graphical terminals, newlines may
8612 "overflow" into the fringe if
8613 overflow-newline-into-fringe is non-nil.
8614 On text terminals, and on graphical
8615 terminals with no right margin, newlines
8616 may overflow into the last glyph on the
8618 if (!FRAME_WINDOW_P (it
->f
)
8620 && it
->bidi_it
.paragraph_dir
== R2L
)
8621 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8622 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8623 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8625 if (!get_next_display_element (it
))
8627 result
= MOVE_POS_MATCH_OR_ZV
;
8630 if (BUFFER_POS_REACHED_P ())
8632 if (ITERATOR_AT_END_OF_LINE_P (it
))
8633 result
= MOVE_POS_MATCH_OR_ZV
;
8635 result
= MOVE_LINE_CONTINUED
;
8638 if (ITERATOR_AT_END_OF_LINE_P (it
)
8639 && (it
->line_wrap
!= WORD_WRAP
8642 result
= MOVE_NEWLINE_OR_CR
;
8649 IT_RESET_X_ASCENT_DESCENT (it
);
8651 if (wrap_it
.sp
>= 0)
8653 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8658 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8660 result
= MOVE_LINE_CONTINUED
;
8664 if (BUFFER_POS_REACHED_P ())
8666 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8667 goto buffer_pos_reached
;
8668 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8670 SAVE_IT (atpos_it
, *it
, atpos_data
);
8671 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8675 if (new_x
> it
->first_visible_x
)
8677 /* Glyph is visible. Increment number of glyphs that
8678 would be displayed. */
8683 if (result
!= MOVE_UNDEFINED
)
8686 else if (BUFFER_POS_REACHED_P ())
8689 IT_RESET_X_ASCENT_DESCENT (it
);
8690 result
= MOVE_POS_MATCH_OR_ZV
;
8693 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8695 /* Stop when TO_X specified and reached. This check is
8696 necessary here because of lines consisting of a line end,
8697 only. The line end will not produce any glyphs and we
8698 would never get MOVE_X_REACHED. */
8699 eassert (it
->nglyphs
== 0);
8700 result
= MOVE_X_REACHED
;
8704 /* Is this a line end? If yes, we're done. */
8705 if (ITERATOR_AT_END_OF_LINE_P (it
))
8707 /* If we are past TO_CHARPOS, but never saw any character
8708 positions smaller than TO_CHARPOS, return
8709 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8711 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8713 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8715 if (IT_CHARPOS (ppos_it
) < ZV
)
8717 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8718 result
= MOVE_POS_MATCH_OR_ZV
;
8721 goto buffer_pos_reached
;
8723 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8724 && IT_CHARPOS (*it
) > to_charpos
)
8725 goto buffer_pos_reached
;
8727 result
= MOVE_NEWLINE_OR_CR
;
8730 result
= MOVE_NEWLINE_OR_CR
;
8734 prev_method
= it
->method
;
8735 if (it
->method
== GET_FROM_BUFFER
)
8736 prev_pos
= IT_CHARPOS (*it
);
8737 /* The current display element has been consumed. Advance
8739 set_iterator_to_next (it
, 1);
8740 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8741 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8742 if (IT_CHARPOS (*it
) < to_charpos
)
8743 saw_smaller_pos
= 1;
8745 && (op
& MOVE_TO_POS
)
8746 && IT_CHARPOS (*it
) >= to_charpos
8747 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8748 SAVE_IT (ppos_it
, *it
, ppos_data
);
8750 /* Stop if lines are truncated and IT's current x-position is
8751 past the right edge of the window now. */
8752 if (it
->line_wrap
== TRUNCATE
8753 && it
->current_x
>= it
->last_visible_x
)
8755 if (!FRAME_WINDOW_P (it
->f
)
8756 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8757 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8758 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8759 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8763 if ((at_eob_p
= !get_next_display_element (it
))
8764 || BUFFER_POS_REACHED_P ()
8765 /* If we are past TO_CHARPOS, but never saw any
8766 character positions smaller than TO_CHARPOS,
8767 return MOVE_POS_MATCH_OR_ZV, like the
8768 unidirectional display did. */
8769 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8771 && IT_CHARPOS (*it
) > to_charpos
))
8774 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8775 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8776 result
= MOVE_POS_MATCH_OR_ZV
;
8779 if (ITERATOR_AT_END_OF_LINE_P (it
))
8781 result
= MOVE_NEWLINE_OR_CR
;
8785 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8787 && IT_CHARPOS (*it
) > to_charpos
)
8789 if (IT_CHARPOS (ppos_it
) < ZV
)
8790 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8791 result
= MOVE_POS_MATCH_OR_ZV
;
8794 result
= MOVE_LINE_TRUNCATED
;
8797 #undef IT_RESET_X_ASCENT_DESCENT
8800 #undef BUFFER_POS_REACHED_P
8802 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8803 restore the saved iterator. */
8804 if (atpos_it
.sp
>= 0)
8805 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8806 else if (atx_it
.sp
>= 0)
8807 RESTORE_IT (it
, &atx_it
, atx_data
);
8812 bidi_unshelve_cache (atpos_data
, 1);
8814 bidi_unshelve_cache (atx_data
, 1);
8816 bidi_unshelve_cache (wrap_data
, 1);
8818 bidi_unshelve_cache (ppos_data
, 1);
8820 /* Restore the iterator settings altered at the beginning of this
8822 it
->glyph_row
= saved_glyph_row
;
8826 /* For external use. */
8828 move_it_in_display_line (struct it
*it
,
8829 ptrdiff_t to_charpos
, int to_x
,
8830 enum move_operation_enum op
)
8832 if (it
->line_wrap
== WORD_WRAP
8833 && (op
& MOVE_TO_X
))
8836 void *save_data
= NULL
;
8839 SAVE_IT (save_it
, *it
, save_data
);
8840 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8841 /* When word-wrap is on, TO_X may lie past the end
8842 of a wrapped line. Then it->current is the
8843 character on the next line, so backtrack to the
8844 space before the wrap point. */
8845 if (skip
== MOVE_LINE_CONTINUED
)
8847 int prev_x
= max (it
->current_x
- 1, 0);
8848 RESTORE_IT (it
, &save_it
, save_data
);
8849 move_it_in_display_line_to
8850 (it
, -1, prev_x
, MOVE_TO_X
);
8853 bidi_unshelve_cache (save_data
, 1);
8856 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8860 /* Move IT forward until it satisfies one or more of the criteria in
8861 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8863 OP is a bit-mask that specifies where to stop, and in particular,
8864 which of those four position arguments makes a difference. See the
8865 description of enum move_operation_enum.
8867 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8868 screen line, this function will set IT to the next position that is
8869 displayed to the right of TO_CHARPOS on the screen. */
8872 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8874 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8875 int line_height
, line_start_x
= 0, reached
= 0;
8876 void *backup_data
= NULL
;
8880 if (op
& MOVE_TO_VPOS
)
8882 /* If no TO_CHARPOS and no TO_X specified, stop at the
8883 start of the line TO_VPOS. */
8884 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8886 if (it
->vpos
== to_vpos
)
8892 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8896 /* TO_VPOS >= 0 means stop at TO_X in the line at
8897 TO_VPOS, or at TO_POS, whichever comes first. */
8898 if (it
->vpos
== to_vpos
)
8904 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8906 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8911 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8913 /* We have reached TO_X but not in the line we want. */
8914 skip
= move_it_in_display_line_to (it
, to_charpos
,
8916 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8924 else if (op
& MOVE_TO_Y
)
8926 struct it it_backup
;
8928 if (it
->line_wrap
== WORD_WRAP
)
8929 SAVE_IT (it_backup
, *it
, backup_data
);
8931 /* TO_Y specified means stop at TO_X in the line containing
8932 TO_Y---or at TO_CHARPOS if this is reached first. The
8933 problem is that we can't really tell whether the line
8934 contains TO_Y before we have completely scanned it, and
8935 this may skip past TO_X. What we do is to first scan to
8938 If TO_X is not specified, use a TO_X of zero. The reason
8939 is to make the outcome of this function more predictable.
8940 If we didn't use TO_X == 0, we would stop at the end of
8941 the line which is probably not what a caller would expect
8943 skip
= move_it_in_display_line_to
8944 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8945 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8947 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8948 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8950 else if (skip
== MOVE_X_REACHED
)
8952 /* If TO_X was reached, we want to know whether TO_Y is
8953 in the line. We know this is the case if the already
8954 scanned glyphs make the line tall enough. Otherwise,
8955 we must check by scanning the rest of the line. */
8956 line_height
= it
->max_ascent
+ it
->max_descent
;
8957 if (to_y
>= it
->current_y
8958 && to_y
< it
->current_y
+ line_height
)
8963 SAVE_IT (it_backup
, *it
, backup_data
);
8964 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8965 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8967 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8968 line_height
= it
->max_ascent
+ it
->max_descent
;
8969 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8971 if (to_y
>= it
->current_y
8972 && to_y
< it
->current_y
+ line_height
)
8974 /* If TO_Y is in this line and TO_X was reached
8975 above, we scanned too far. We have to restore
8976 IT's settings to the ones before skipping. But
8977 keep the more accurate values of max_ascent and
8978 max_descent we've found while skipping the rest
8979 of the line, for the sake of callers, such as
8980 pos_visible_p, that need to know the line
8982 int max_ascent
= it
->max_ascent
;
8983 int max_descent
= it
->max_descent
;
8985 RESTORE_IT (it
, &it_backup
, backup_data
);
8986 it
->max_ascent
= max_ascent
;
8987 it
->max_descent
= max_descent
;
8993 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8999 /* Check whether TO_Y is in this line. */
9000 line_height
= it
->max_ascent
+ it
->max_descent
;
9001 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9003 if (to_y
>= it
->current_y
9004 && to_y
< it
->current_y
+ line_height
)
9006 /* When word-wrap is on, TO_X may lie past the end
9007 of a wrapped line. Then it->current is the
9008 character on the next line, so backtrack to the
9009 space before the wrap point. */
9010 if (skip
== MOVE_LINE_CONTINUED
9011 && it
->line_wrap
== WORD_WRAP
)
9013 int prev_x
= max (it
->current_x
- 1, 0);
9014 RESTORE_IT (it
, &it_backup
, backup_data
);
9015 skip
= move_it_in_display_line_to
9016 (it
, -1, prev_x
, MOVE_TO_X
);
9025 else if (BUFFERP (it
->object
)
9026 && (it
->method
== GET_FROM_BUFFER
9027 || it
->method
== GET_FROM_STRETCH
)
9028 && IT_CHARPOS (*it
) >= to_charpos
9029 /* Under bidi iteration, a call to set_iterator_to_next
9030 can scan far beyond to_charpos if the initial
9031 portion of the next line needs to be reordered. In
9032 that case, give move_it_in_display_line_to another
9035 && it
->bidi_it
.scan_dir
== -1))
9036 skip
= MOVE_POS_MATCH_OR_ZV
;
9038 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9042 case MOVE_POS_MATCH_OR_ZV
:
9046 case MOVE_NEWLINE_OR_CR
:
9047 set_iterator_to_next (it
, 1);
9048 it
->continuation_lines_width
= 0;
9051 case MOVE_LINE_TRUNCATED
:
9052 it
->continuation_lines_width
= 0;
9053 reseat_at_next_visible_line_start (it
, 0);
9054 if ((op
& MOVE_TO_POS
) != 0
9055 && IT_CHARPOS (*it
) > to_charpos
)
9062 case MOVE_LINE_CONTINUED
:
9063 /* For continued lines ending in a tab, some of the glyphs
9064 associated with the tab are displayed on the current
9065 line. Since it->current_x does not include these glyphs,
9066 we use it->last_visible_x instead. */
9069 it
->continuation_lines_width
+= it
->last_visible_x
;
9070 /* When moving by vpos, ensure that the iterator really
9071 advances to the next line (bug#847, bug#969). Fixme:
9072 do we need to do this in other circumstances? */
9073 if (it
->current_x
!= it
->last_visible_x
9074 && (op
& MOVE_TO_VPOS
)
9075 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9077 line_start_x
= it
->current_x
+ it
->pixel_width
9078 - it
->last_visible_x
;
9079 set_iterator_to_next (it
, 0);
9083 it
->continuation_lines_width
+= it
->current_x
;
9090 /* Reset/increment for the next run. */
9091 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9092 it
->current_x
= line_start_x
;
9095 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9097 last_height
= it
->max_ascent
+ it
->max_descent
;
9098 it
->max_ascent
= it
->max_descent
= 0;
9103 /* On text terminals, we may stop at the end of a line in the middle
9104 of a multi-character glyph. If the glyph itself is continued,
9105 i.e. it is actually displayed on the next line, don't treat this
9106 stopping point as valid; move to the next line instead (unless
9107 that brings us offscreen). */
9108 if (!FRAME_WINDOW_P (it
->f
)
9110 && IT_CHARPOS (*it
) == to_charpos
9111 && it
->what
== IT_CHARACTER
9113 && it
->line_wrap
== WINDOW_WRAP
9114 && it
->current_x
== it
->last_visible_x
- 1
9117 && it
->vpos
< it
->w
->window_end_vpos
)
9119 it
->continuation_lines_width
+= it
->current_x
;
9120 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9121 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9123 last_height
= it
->max_ascent
+ it
->max_descent
;
9127 bidi_unshelve_cache (backup_data
, 1);
9129 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9133 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9135 If DY > 0, move IT backward at least that many pixels. DY = 0
9136 means move IT backward to the preceding line start or BEGV. This
9137 function may move over more than DY pixels if IT->current_y - DY
9138 ends up in the middle of a line; in this case IT->current_y will be
9139 set to the top of the line moved to. */
9142 move_it_vertically_backward (struct it
*it
, int dy
)
9146 void *it2data
= NULL
, *it3data
= NULL
;
9147 ptrdiff_t start_pos
;
9149 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9150 ptrdiff_t pos_limit
;
9155 start_pos
= IT_CHARPOS (*it
);
9157 /* Estimate how many newlines we must move back. */
9158 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9159 if (it
->line_wrap
== TRUNCATE
)
9162 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9164 /* Set the iterator's position that many lines back. But don't go
9165 back more than NLINES full screen lines -- this wins a day with
9166 buffers which have very long lines. */
9167 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9168 back_to_previous_visible_line_start (it
);
9170 /* Reseat the iterator here. When moving backward, we don't want
9171 reseat to skip forward over invisible text, set up the iterator
9172 to deliver from overlay strings at the new position etc. So,
9173 use reseat_1 here. */
9174 reseat_1 (it
, it
->current
.pos
, 1);
9176 /* We are now surely at a line start. */
9177 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9178 reordering is in effect. */
9179 it
->continuation_lines_width
= 0;
9181 /* Move forward and see what y-distance we moved. First move to the
9182 start of the next line so that we get its height. We need this
9183 height to be able to tell whether we reached the specified
9185 SAVE_IT (it2
, *it
, it2data
);
9186 it2
.max_ascent
= it2
.max_descent
= 0;
9189 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9190 MOVE_TO_POS
| MOVE_TO_VPOS
);
9192 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9193 /* If we are in a display string which starts at START_POS,
9194 and that display string includes a newline, and we are
9195 right after that newline (i.e. at the beginning of a
9196 display line), exit the loop, because otherwise we will
9197 infloop, since move_it_to will see that it is already at
9198 START_POS and will not move. */
9199 || (it2
.method
== GET_FROM_STRING
9200 && IT_CHARPOS (it2
) == start_pos
9201 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9202 eassert (IT_CHARPOS (*it
) >= BEGV
);
9203 SAVE_IT (it3
, it2
, it3data
);
9205 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9206 eassert (IT_CHARPOS (*it
) >= BEGV
);
9207 /* H is the actual vertical distance from the position in *IT
9208 and the starting position. */
9209 h
= it2
.current_y
- it
->current_y
;
9210 /* NLINES is the distance in number of lines. */
9211 nlines
= it2
.vpos
- it
->vpos
;
9213 /* Correct IT's y and vpos position
9214 so that they are relative to the starting point. */
9220 /* DY == 0 means move to the start of the screen line. The
9221 value of nlines is > 0 if continuation lines were involved,
9222 or if the original IT position was at start of a line. */
9223 RESTORE_IT (it
, it
, it2data
);
9225 move_it_by_lines (it
, nlines
);
9226 /* The above code moves us to some position NLINES down,
9227 usually to its first glyph (leftmost in an L2R line), but
9228 that's not necessarily the start of the line, under bidi
9229 reordering. We want to get to the character position
9230 that is immediately after the newline of the previous
9233 && !it
->continuation_lines_width
9234 && !STRINGP (it
->string
)
9235 && IT_CHARPOS (*it
) > BEGV
9236 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9238 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9241 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9242 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9244 bidi_unshelve_cache (it3data
, 1);
9248 /* The y-position we try to reach, relative to *IT.
9249 Note that H has been subtracted in front of the if-statement. */
9250 int target_y
= it
->current_y
+ h
- dy
;
9251 int y0
= it3
.current_y
;
9255 RESTORE_IT (&it3
, &it3
, it3data
);
9256 y1
= line_bottom_y (&it3
);
9257 line_height
= y1
- y0
;
9258 RESTORE_IT (it
, it
, it2data
);
9259 /* If we did not reach target_y, try to move further backward if
9260 we can. If we moved too far backward, try to move forward. */
9261 if (target_y
< it
->current_y
9262 /* This is heuristic. In a window that's 3 lines high, with
9263 a line height of 13 pixels each, recentering with point
9264 on the bottom line will try to move -39/2 = 19 pixels
9265 backward. Try to avoid moving into the first line. */
9266 && (it
->current_y
- target_y
9267 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9268 && IT_CHARPOS (*it
) > BEGV
)
9270 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9271 target_y
- it
->current_y
));
9272 dy
= it
->current_y
- target_y
;
9273 goto move_further_back
;
9275 else if (target_y
>= it
->current_y
+ line_height
9276 && IT_CHARPOS (*it
) < ZV
)
9278 /* Should move forward by at least one line, maybe more.
9280 Note: Calling move_it_by_lines can be expensive on
9281 terminal frames, where compute_motion is used (via
9282 vmotion) to do the job, when there are very long lines
9283 and truncate-lines is nil. That's the reason for
9284 treating terminal frames specially here. */
9286 if (!FRAME_WINDOW_P (it
->f
))
9287 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9292 move_it_by_lines (it
, 1);
9294 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9301 /* Move IT by a specified amount of pixel lines DY. DY negative means
9302 move backwards. DY = 0 means move to start of screen line. At the
9303 end, IT will be on the start of a screen line. */
9306 move_it_vertically (struct it
*it
, int dy
)
9309 move_it_vertically_backward (it
, -dy
);
9312 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9313 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9314 MOVE_TO_POS
| MOVE_TO_Y
);
9315 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9317 /* If buffer ends in ZV without a newline, move to the start of
9318 the line to satisfy the post-condition. */
9319 if (IT_CHARPOS (*it
) == ZV
9321 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9322 move_it_by_lines (it
, 0);
9327 /* Move iterator IT past the end of the text line it is in. */
9330 move_it_past_eol (struct it
*it
)
9332 enum move_it_result rc
;
9334 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9335 if (rc
== MOVE_NEWLINE_OR_CR
)
9336 set_iterator_to_next (it
, 0);
9340 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9341 negative means move up. DVPOS == 0 means move to the start of the
9344 Optimization idea: If we would know that IT->f doesn't use
9345 a face with proportional font, we could be faster for
9346 truncate-lines nil. */
9349 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9352 /* The commented-out optimization uses vmotion on terminals. This
9353 gives bad results, because elements like it->what, on which
9354 callers such as pos_visible_p rely, aren't updated. */
9355 /* struct position pos;
9356 if (!FRAME_WINDOW_P (it->f))
9358 struct text_pos textpos;
9360 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9361 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9362 reseat (it, textpos, 1);
9363 it->vpos += pos.vpos;
9364 it->current_y += pos.vpos;
9370 /* DVPOS == 0 means move to the start of the screen line. */
9371 move_it_vertically_backward (it
, 0);
9372 /* Let next call to line_bottom_y calculate real line height */
9377 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9378 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9380 /* Only move to the next buffer position if we ended up in a
9381 string from display property, not in an overlay string
9382 (before-string or after-string). That is because the
9383 latter don't conceal the underlying buffer position, so
9384 we can ask to move the iterator to the exact position we
9385 are interested in. Note that, even if we are already at
9386 IT_CHARPOS (*it), the call below is not a no-op, as it
9387 will detect that we are at the end of the string, pop the
9388 iterator, and compute it->current_x and it->hpos
9390 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9391 -1, -1, -1, MOVE_TO_POS
);
9397 void *it2data
= NULL
;
9398 ptrdiff_t start_charpos
, i
;
9400 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9401 ptrdiff_t pos_limit
;
9403 /* Start at the beginning of the screen line containing IT's
9404 position. This may actually move vertically backwards,
9405 in case of overlays, so adjust dvpos accordingly. */
9407 move_it_vertically_backward (it
, 0);
9410 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9411 screen lines, and reseat the iterator there. */
9412 start_charpos
= IT_CHARPOS (*it
);
9413 if (it
->line_wrap
== TRUNCATE
)
9416 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9417 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9418 back_to_previous_visible_line_start (it
);
9419 reseat (it
, it
->current
.pos
, 1);
9421 /* Move further back if we end up in a string or an image. */
9422 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9424 /* First try to move to start of display line. */
9426 move_it_vertically_backward (it
, 0);
9428 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9430 /* If start of line is still in string or image,
9431 move further back. */
9432 back_to_previous_visible_line_start (it
);
9433 reseat (it
, it
->current
.pos
, 1);
9437 it
->current_x
= it
->hpos
= 0;
9439 /* Above call may have moved too far if continuation lines
9440 are involved. Scan forward and see if it did. */
9441 SAVE_IT (it2
, *it
, it2data
);
9442 it2
.vpos
= it2
.current_y
= 0;
9443 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9444 it
->vpos
-= it2
.vpos
;
9445 it
->current_y
-= it2
.current_y
;
9446 it
->current_x
= it
->hpos
= 0;
9448 /* If we moved too far back, move IT some lines forward. */
9449 if (it2
.vpos
> -dvpos
)
9451 int delta
= it2
.vpos
+ dvpos
;
9453 RESTORE_IT (&it2
, &it2
, it2data
);
9454 SAVE_IT (it2
, *it
, it2data
);
9455 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9456 /* Move back again if we got too far ahead. */
9457 if (IT_CHARPOS (*it
) >= start_charpos
)
9458 RESTORE_IT (it
, &it2
, it2data
);
9460 bidi_unshelve_cache (it2data
, 1);
9463 RESTORE_IT (it
, it
, it2data
);
9467 /* Return 1 if IT points into the middle of a display vector. */
9470 in_display_vector_p (struct it
*it
)
9472 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9473 && it
->current
.dpvec_index
> 0
9474 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9478 /***********************************************************************
9480 ***********************************************************************/
9483 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9487 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9489 Lisp_Object args
[3];
9490 Lisp_Object msg
, fmt
;
9493 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9497 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9499 args
[0] = fmt
= build_string (format
);
9502 msg
= Fformat (3, args
);
9504 len
= SBYTES (msg
) + 1;
9505 buffer
= SAFE_ALLOCA (len
);
9506 memcpy (buffer
, SDATA (msg
), len
);
9508 message_dolog (buffer
, len
- 1, 1, 0);
9515 /* Output a newline in the *Messages* buffer if "needs" one. */
9518 message_log_maybe_newline (void)
9520 if (message_log_need_newline
)
9521 message_dolog ("", 0, 1, 0);
9525 /* Add a string M of length NBYTES to the message log, optionally
9526 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9527 true, means interpret the contents of M as multibyte. This
9528 function calls low-level routines in order to bypass text property
9529 hooks, etc. which might not be safe to run.
9531 This may GC (insert may run before/after change hooks),
9532 so the buffer M must NOT point to a Lisp string. */
9535 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9537 const unsigned char *msg
= (const unsigned char *) m
;
9539 if (!NILP (Vmemory_full
))
9542 if (!NILP (Vmessage_log_max
))
9544 struct buffer
*oldbuf
;
9545 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9546 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9547 ptrdiff_t point_at_end
= 0;
9548 ptrdiff_t zv_at_end
= 0;
9549 Lisp_Object old_deactivate_mark
;
9551 struct gcpro gcpro1
;
9553 old_deactivate_mark
= Vdeactivate_mark
;
9554 oldbuf
= current_buffer
;
9555 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9556 bset_undo_list (current_buffer
, Qt
);
9558 oldpoint
= message_dolog_marker1
;
9559 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9560 oldbegv
= message_dolog_marker2
;
9561 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9562 oldzv
= message_dolog_marker3
;
9563 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9564 GCPRO1 (old_deactivate_mark
);
9572 BEGV_BYTE
= BEG_BYTE
;
9575 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9577 /* Insert the string--maybe converting multibyte to single byte
9578 or vice versa, so that all the text fits the buffer. */
9580 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9586 /* Convert a multibyte string to single-byte
9587 for the *Message* buffer. */
9588 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9590 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9591 work
[0] = (ASCII_CHAR_P (c
)
9593 : multibyte_char_to_unibyte (c
));
9594 insert_1_both (work
, 1, 1, 1, 0, 0);
9597 else if (! multibyte
9598 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9602 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9603 /* Convert a single-byte string to multibyte
9604 for the *Message* buffer. */
9605 for (i
= 0; i
< nbytes
; i
++)
9608 MAKE_CHAR_MULTIBYTE (c
);
9609 char_bytes
= CHAR_STRING (c
, str
);
9610 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9614 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9618 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9621 insert_1_both ("\n", 1, 1, 1, 0, 0);
9623 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9625 this_bol_byte
= PT_BYTE
;
9627 /* See if this line duplicates the previous one.
9628 If so, combine duplicates. */
9631 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9633 prev_bol_byte
= PT_BYTE
;
9635 dups
= message_log_check_duplicate (prev_bol_byte
,
9639 del_range_both (prev_bol
, prev_bol_byte
,
9640 this_bol
, this_bol_byte
, 0);
9643 char dupstr
[sizeof " [ times]"
9644 + INT_STRLEN_BOUND (printmax_t
)];
9646 /* If you change this format, don't forget to also
9647 change message_log_check_duplicate. */
9648 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9649 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9650 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9655 /* If we have more than the desired maximum number of lines
9656 in the *Messages* buffer now, delete the oldest ones.
9657 This is safe because we don't have undo in this buffer. */
9659 if (NATNUMP (Vmessage_log_max
))
9661 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9662 -XFASTINT (Vmessage_log_max
) - 1, 0);
9663 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9666 BEGV
= marker_position (oldbegv
);
9667 BEGV_BYTE
= marker_byte_position (oldbegv
);
9676 ZV
= marker_position (oldzv
);
9677 ZV_BYTE
= marker_byte_position (oldzv
);
9681 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9683 /* We can't do Fgoto_char (oldpoint) because it will run some
9685 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9686 marker_byte_position (oldpoint
));
9689 unchain_marker (XMARKER (oldpoint
));
9690 unchain_marker (XMARKER (oldbegv
));
9691 unchain_marker (XMARKER (oldzv
));
9693 shown
= buffer_window_count (current_buffer
) > 0;
9694 set_buffer_internal (oldbuf
);
9695 /* We called insert_1_both above with its 5th argument (PREPARE)
9696 zero, which prevents insert_1_both from calling
9697 prepare_to_modify_buffer, which in turns prevents us from
9698 incrementing windows_or_buffers_changed even if *Messages* is
9699 shown in some window. So we must manually incrementing
9700 windows_or_buffers_changed here to make up for that. */
9702 windows_or_buffers_changed
++;
9704 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9705 message_log_need_newline
= !nlflag
;
9706 Vdeactivate_mark
= old_deactivate_mark
;
9711 /* We are at the end of the buffer after just having inserted a newline.
9712 (Note: We depend on the fact we won't be crossing the gap.)
9713 Check to see if the most recent message looks a lot like the previous one.
9714 Return 0 if different, 1 if the new one should just replace it, or a
9715 value N > 1 if we should also append " [N times]". */
9718 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9721 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9723 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9724 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9726 for (i
= 0; i
< len
; i
++)
9728 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9736 if (*p1
++ == ' ' && *p1
++ == '[')
9739 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9740 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9747 /* Display an echo area message M with a specified length of NBYTES
9748 bytes. The string may include null characters. If M is not a
9749 string, clear out any existing message, and let the mini-buffer
9752 This function cancels echoing. */
9755 message3 (Lisp_Object m
)
9757 struct gcpro gcpro1
;
9760 clear_message (1,1);
9763 /* First flush out any partial line written with print. */
9764 message_log_maybe_newline ();
9767 ptrdiff_t nbytes
= SBYTES (m
);
9768 bool multibyte
= STRING_MULTIBYTE (m
);
9770 char *buffer
= SAFE_ALLOCA (nbytes
);
9771 memcpy (buffer
, SDATA (m
), nbytes
);
9772 message_dolog (buffer
, nbytes
, 1, multibyte
);
9781 /* The non-logging version of message3.
9782 This does not cancel echoing, because it is used for echoing.
9783 Perhaps we need to make a separate function for echoing
9784 and make this cancel echoing. */
9787 message3_nolog (Lisp_Object m
)
9789 struct frame
*sf
= SELECTED_FRAME ();
9791 if (FRAME_INITIAL_P (sf
))
9793 if (noninteractive_need_newline
)
9794 putc ('\n', stderr
);
9795 noninteractive_need_newline
= 0;
9797 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9798 if (cursor_in_echo_area
== 0)
9799 fprintf (stderr
, "\n");
9802 /* Error messages get reported properly by cmd_error, so this must be just an
9803 informative message; if the frame hasn't really been initialized yet, just
9805 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9807 /* Get the frame containing the mini-buffer
9808 that the selected frame is using. */
9809 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9810 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9811 struct frame
*f
= XFRAME (frame
);
9813 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9814 Fmake_frame_visible (frame
);
9816 if (STRINGP (m
) && SCHARS (m
) > 0)
9819 if (minibuffer_auto_raise
)
9820 Fraise_frame (frame
);
9821 /* Assume we are not echoing.
9822 (If we are, echo_now will override this.) */
9823 echo_message_buffer
= Qnil
;
9826 clear_message (1, 1);
9828 do_pending_window_change (0);
9829 echo_area_display (1);
9830 do_pending_window_change (0);
9831 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9832 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9837 /* Display a null-terminated echo area message M. If M is 0, clear
9838 out any existing message, and let the mini-buffer text show through.
9840 The buffer M must continue to exist until after the echo area gets
9841 cleared or some other message gets displayed there. Do not pass
9842 text that is stored in a Lisp string. Do not pass text in a buffer
9843 that was alloca'd. */
9846 message1 (const char *m
)
9848 message3 (m
? build_unibyte_string (m
) : Qnil
);
9852 /* The non-logging counterpart of message1. */
9855 message1_nolog (const char *m
)
9857 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9860 /* Display a message M which contains a single %s
9861 which gets replaced with STRING. */
9864 message_with_string (const char *m
, Lisp_Object string
, int log
)
9866 CHECK_STRING (string
);
9872 if (noninteractive_need_newline
)
9873 putc ('\n', stderr
);
9874 noninteractive_need_newline
= 0;
9875 fprintf (stderr
, m
, SDATA (string
));
9876 if (!cursor_in_echo_area
)
9877 fprintf (stderr
, "\n");
9881 else if (INTERACTIVE
)
9883 /* The frame whose minibuffer we're going to display the message on.
9884 It may be larger than the selected frame, so we need
9885 to use its buffer, not the selected frame's buffer. */
9886 Lisp_Object mini_window
;
9887 struct frame
*f
, *sf
= SELECTED_FRAME ();
9889 /* Get the frame containing the minibuffer
9890 that the selected frame is using. */
9891 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9892 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9894 /* Error messages get reported properly by cmd_error, so this must be
9895 just an informative message; if the frame hasn't really been
9896 initialized yet, just toss it. */
9897 if (f
->glyphs_initialized_p
)
9899 Lisp_Object args
[2], msg
;
9900 struct gcpro gcpro1
, gcpro2
;
9902 args
[0] = build_string (m
);
9903 args
[1] = msg
= string
;
9904 GCPRO2 (args
[0], msg
);
9907 msg
= Fformat (2, args
);
9912 message3_nolog (msg
);
9916 /* Print should start at the beginning of the message
9917 buffer next time. */
9918 message_buf_print
= 0;
9924 /* Dump an informative message to the minibuf. If M is 0, clear out
9925 any existing message, and let the mini-buffer text show through. */
9928 vmessage (const char *m
, va_list ap
)
9934 if (noninteractive_need_newline
)
9935 putc ('\n', stderr
);
9936 noninteractive_need_newline
= 0;
9937 vfprintf (stderr
, m
, ap
);
9938 if (cursor_in_echo_area
== 0)
9939 fprintf (stderr
, "\n");
9943 else if (INTERACTIVE
)
9945 /* The frame whose mini-buffer we're going to display the message
9946 on. It may be larger than the selected frame, so we need to
9947 use its buffer, not the selected frame's buffer. */
9948 Lisp_Object mini_window
;
9949 struct frame
*f
, *sf
= SELECTED_FRAME ();
9951 /* Get the frame containing the mini-buffer
9952 that the selected frame is using. */
9953 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9954 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9956 /* Error messages get reported properly by cmd_error, so this must be
9957 just an informative message; if the frame hasn't really been
9958 initialized yet, just toss it. */
9959 if (f
->glyphs_initialized_p
)
9964 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9965 char *message_buf
= alloca (maxsize
+ 1);
9967 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9969 message3 (make_string (message_buf
, len
));
9974 /* Print should start at the beginning of the message
9975 buffer next time. */
9976 message_buf_print
= 0;
9982 message (const char *m
, ...)
9992 /* The non-logging version of message. */
9995 message_nolog (const char *m
, ...)
9997 Lisp_Object old_log_max
;
10000 old_log_max
= Vmessage_log_max
;
10001 Vmessage_log_max
= Qnil
;
10003 Vmessage_log_max
= old_log_max
;
10009 /* Display the current message in the current mini-buffer. This is
10010 only called from error handlers in process.c, and is not time
10014 update_echo_area (void)
10016 if (!NILP (echo_area_buffer
[0]))
10018 Lisp_Object string
;
10019 string
= Fcurrent_message ();
10025 /* Make sure echo area buffers in `echo_buffers' are live.
10026 If they aren't, make new ones. */
10029 ensure_echo_area_buffers (void)
10033 for (i
= 0; i
< 2; ++i
)
10034 if (!BUFFERP (echo_buffer
[i
])
10035 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10038 Lisp_Object old_buffer
;
10041 old_buffer
= echo_buffer
[i
];
10042 echo_buffer
[i
] = Fget_buffer_create
10043 (make_formatted_string (name
, " *Echo Area %d*", i
));
10044 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10045 /* to force word wrap in echo area -
10046 it was decided to postpone this*/
10047 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10049 for (j
= 0; j
< 2; ++j
)
10050 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10051 echo_area_buffer
[j
] = echo_buffer
[i
];
10056 /* Call FN with args A1..A2 with either the current or last displayed
10057 echo_area_buffer as current buffer.
10059 WHICH zero means use the current message buffer
10060 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10061 from echo_buffer[] and clear it.
10063 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10064 suitable buffer from echo_buffer[] and clear it.
10066 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10067 that the current message becomes the last displayed one, make
10068 choose a suitable buffer for echo_area_buffer[0], and clear it.
10070 Value is what FN returns. */
10073 with_echo_area_buffer (struct window
*w
, int which
,
10074 int (*fn
) (ptrdiff_t, Lisp_Object
),
10075 ptrdiff_t a1
, Lisp_Object a2
)
10077 Lisp_Object buffer
;
10078 int this_one
, the_other
, clear_buffer_p
, rc
;
10079 ptrdiff_t count
= SPECPDL_INDEX ();
10081 /* If buffers aren't live, make new ones. */
10082 ensure_echo_area_buffers ();
10084 clear_buffer_p
= 0;
10087 this_one
= 0, the_other
= 1;
10088 else if (which
> 0)
10089 this_one
= 1, the_other
= 0;
10092 this_one
= 0, the_other
= 1;
10093 clear_buffer_p
= 1;
10095 /* We need a fresh one in case the current echo buffer equals
10096 the one containing the last displayed echo area message. */
10097 if (!NILP (echo_area_buffer
[this_one
])
10098 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10099 echo_area_buffer
[this_one
] = Qnil
;
10102 /* Choose a suitable buffer from echo_buffer[] is we don't
10104 if (NILP (echo_area_buffer
[this_one
]))
10106 echo_area_buffer
[this_one
]
10107 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10108 ? echo_buffer
[the_other
]
10109 : echo_buffer
[this_one
]);
10110 clear_buffer_p
= 1;
10113 buffer
= echo_area_buffer
[this_one
];
10115 /* Don't get confused by reusing the buffer used for echoing
10116 for a different purpose. */
10117 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10120 record_unwind_protect (unwind_with_echo_area_buffer
,
10121 with_echo_area_buffer_unwind_data (w
));
10123 /* Make the echo area buffer current. Note that for display
10124 purposes, it is not necessary that the displayed window's buffer
10125 == current_buffer, except for text property lookup. So, let's
10126 only set that buffer temporarily here without doing a full
10127 Fset_window_buffer. We must also change w->pointm, though,
10128 because otherwise an assertions in unshow_buffer fails, and Emacs
10130 set_buffer_internal_1 (XBUFFER (buffer
));
10133 wset_buffer (w
, buffer
);
10134 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10137 bset_undo_list (current_buffer
, Qt
);
10138 bset_read_only (current_buffer
, Qnil
);
10139 specbind (Qinhibit_read_only
, Qt
);
10140 specbind (Qinhibit_modification_hooks
, Qt
);
10142 if (clear_buffer_p
&& Z
> BEG
)
10143 del_range (BEG
, Z
);
10145 eassert (BEGV
>= BEG
);
10146 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10150 eassert (BEGV
>= BEG
);
10151 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10153 unbind_to (count
, Qnil
);
10158 /* Save state that should be preserved around the call to the function
10159 FN called in with_echo_area_buffer. */
10162 with_echo_area_buffer_unwind_data (struct window
*w
)
10165 Lisp_Object vector
, tmp
;
10167 /* Reduce consing by keeping one vector in
10168 Vwith_echo_area_save_vector. */
10169 vector
= Vwith_echo_area_save_vector
;
10170 Vwith_echo_area_save_vector
= Qnil
;
10173 vector
= Fmake_vector (make_number (9), Qnil
);
10175 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10176 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10177 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10181 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10182 ASET (vector
, i
, w
->contents
); ++i
;
10183 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10184 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10185 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10186 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10191 for (; i
< end
; ++i
)
10192 ASET (vector
, i
, Qnil
);
10195 eassert (i
== ASIZE (vector
));
10200 /* Restore global state from VECTOR which was created by
10201 with_echo_area_buffer_unwind_data. */
10204 unwind_with_echo_area_buffer (Lisp_Object vector
)
10206 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10207 Vdeactivate_mark
= AREF (vector
, 1);
10208 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10210 if (WINDOWP (AREF (vector
, 3)))
10213 Lisp_Object buffer
;
10215 w
= XWINDOW (AREF (vector
, 3));
10216 buffer
= AREF (vector
, 4);
10218 wset_buffer (w
, buffer
);
10219 set_marker_both (w
->pointm
, buffer
,
10220 XFASTINT (AREF (vector
, 5)),
10221 XFASTINT (AREF (vector
, 6)));
10222 set_marker_both (w
->start
, buffer
,
10223 XFASTINT (AREF (vector
, 7)),
10224 XFASTINT (AREF (vector
, 8)));
10227 Vwith_echo_area_save_vector
= vector
;
10231 /* Set up the echo area for use by print functions. MULTIBYTE_P
10232 non-zero means we will print multibyte. */
10235 setup_echo_area_for_printing (int multibyte_p
)
10237 /* If we can't find an echo area any more, exit. */
10238 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10239 Fkill_emacs (Qnil
);
10241 ensure_echo_area_buffers ();
10243 if (!message_buf_print
)
10245 /* A message has been output since the last time we printed.
10246 Choose a fresh echo area buffer. */
10247 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10248 echo_area_buffer
[0] = echo_buffer
[1];
10250 echo_area_buffer
[0] = echo_buffer
[0];
10252 /* Switch to that buffer and clear it. */
10253 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10254 bset_truncate_lines (current_buffer
, Qnil
);
10258 ptrdiff_t count
= SPECPDL_INDEX ();
10259 specbind (Qinhibit_read_only
, Qt
);
10260 /* Note that undo recording is always disabled. */
10261 del_range (BEG
, Z
);
10262 unbind_to (count
, Qnil
);
10264 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10266 /* Set up the buffer for the multibyteness we need. */
10268 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10269 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10271 /* Raise the frame containing the echo area. */
10272 if (minibuffer_auto_raise
)
10274 struct frame
*sf
= SELECTED_FRAME ();
10275 Lisp_Object mini_window
;
10276 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10277 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10280 message_log_maybe_newline ();
10281 message_buf_print
= 1;
10285 if (NILP (echo_area_buffer
[0]))
10287 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10288 echo_area_buffer
[0] = echo_buffer
[1];
10290 echo_area_buffer
[0] = echo_buffer
[0];
10293 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10295 /* Someone switched buffers between print requests. */
10296 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10297 bset_truncate_lines (current_buffer
, Qnil
);
10303 /* Display an echo area message in window W. Value is non-zero if W's
10304 height is changed. If display_last_displayed_message_p is
10305 non-zero, display the message that was last displayed, otherwise
10306 display the current message. */
10309 display_echo_area (struct window
*w
)
10311 int i
, no_message_p
, window_height_changed_p
;
10313 /* Temporarily disable garbage collections while displaying the echo
10314 area. This is done because a GC can print a message itself.
10315 That message would modify the echo area buffer's contents while a
10316 redisplay of the buffer is going on, and seriously confuse
10318 ptrdiff_t count
= inhibit_garbage_collection ();
10320 /* If there is no message, we must call display_echo_area_1
10321 nevertheless because it resizes the window. But we will have to
10322 reset the echo_area_buffer in question to nil at the end because
10323 with_echo_area_buffer will sets it to an empty buffer. */
10324 i
= display_last_displayed_message_p
? 1 : 0;
10325 no_message_p
= NILP (echo_area_buffer
[i
]);
10327 window_height_changed_p
10328 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10329 display_echo_area_1
,
10330 (intptr_t) w
, Qnil
);
10333 echo_area_buffer
[i
] = Qnil
;
10335 unbind_to (count
, Qnil
);
10336 return window_height_changed_p
;
10340 /* Helper for display_echo_area. Display the current buffer which
10341 contains the current echo area message in window W, a mini-window,
10342 a pointer to which is passed in A1. A2..A4 are currently not used.
10343 Change the height of W so that all of the message is displayed.
10344 Value is non-zero if height of W was changed. */
10347 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10350 struct window
*w
= (struct window
*) i1
;
10351 Lisp_Object window
;
10352 struct text_pos start
;
10353 int window_height_changed_p
= 0;
10355 /* Do this before displaying, so that we have a large enough glyph
10356 matrix for the display. If we can't get enough space for the
10357 whole text, display the last N lines. That works by setting w->start. */
10358 window_height_changed_p
= resize_mini_window (w
, 0);
10360 /* Use the starting position chosen by resize_mini_window. */
10361 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10364 clear_glyph_matrix (w
->desired_matrix
);
10365 XSETWINDOW (window
, w
);
10366 try_window (window
, start
, 0);
10368 return window_height_changed_p
;
10372 /* Resize the echo area window to exactly the size needed for the
10373 currently displayed message, if there is one. If a mini-buffer
10374 is active, don't shrink it. */
10377 resize_echo_area_exactly (void)
10379 if (BUFFERP (echo_area_buffer
[0])
10380 && WINDOWP (echo_area_window
))
10382 struct window
*w
= XWINDOW (echo_area_window
);
10384 Lisp_Object resize_exactly
;
10386 if (minibuf_level
== 0)
10387 resize_exactly
= Qt
;
10389 resize_exactly
= Qnil
;
10391 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10392 (intptr_t) w
, resize_exactly
);
10395 ++windows_or_buffers_changed
;
10396 ++update_mode_lines
;
10397 redisplay_internal ();
10403 /* Callback function for with_echo_area_buffer, when used from
10404 resize_echo_area_exactly. A1 contains a pointer to the window to
10405 resize, EXACTLY non-nil means resize the mini-window exactly to the
10406 size of the text displayed. A3 and A4 are not used. Value is what
10407 resize_mini_window returns. */
10410 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10413 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10417 /* Resize mini-window W to fit the size of its contents. EXACT_P
10418 means size the window exactly to the size needed. Otherwise, it's
10419 only enlarged until W's buffer is empty.
10421 Set W->start to the right place to begin display. If the whole
10422 contents fit, start at the beginning. Otherwise, start so as
10423 to make the end of the contents appear. This is particularly
10424 important for y-or-n-p, but seems desirable generally.
10426 Value is non-zero if the window height has been changed. */
10429 resize_mini_window (struct window
*w
, int exact_p
)
10431 struct frame
*f
= XFRAME (w
->frame
);
10432 int window_height_changed_p
= 0;
10434 eassert (MINI_WINDOW_P (w
));
10436 /* By default, start display at the beginning. */
10437 set_marker_both (w
->start
, w
->contents
,
10438 BUF_BEGV (XBUFFER (w
->contents
)),
10439 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10441 /* Don't resize windows while redisplaying a window; it would
10442 confuse redisplay functions when the size of the window they are
10443 displaying changes from under them. Such a resizing can happen,
10444 for instance, when which-func prints a long message while
10445 we are running fontification-functions. We're running these
10446 functions with safe_call which binds inhibit-redisplay to t. */
10447 if (!NILP (Vinhibit_redisplay
))
10450 /* Nil means don't try to resize. */
10451 if (NILP (Vresize_mini_windows
)
10452 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10455 if (!FRAME_MINIBUF_ONLY_P (f
))
10458 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10459 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10461 EMACS_INT max_height
;
10462 int unit
= FRAME_LINE_HEIGHT (f
);
10463 struct text_pos start
;
10464 struct buffer
*old_current_buffer
= NULL
;
10466 if (current_buffer
!= XBUFFER (w
->contents
))
10468 old_current_buffer
= current_buffer
;
10469 set_buffer_internal (XBUFFER (w
->contents
));
10472 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10474 /* Compute the max. number of lines specified by the user. */
10475 if (FLOATP (Vmax_mini_window_height
))
10476 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10477 else if (INTEGERP (Vmax_mini_window_height
))
10478 max_height
= XINT (Vmax_mini_window_height
);
10480 max_height
= total_height
/ 4;
10482 /* Correct that max. height if it's bogus. */
10483 max_height
= clip_to_bounds (1, max_height
, total_height
);
10485 /* Find out the height of the text in the window. */
10486 if (it
.line_wrap
== TRUNCATE
)
10491 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10492 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10493 height
= it
.current_y
+ last_height
;
10495 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10496 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10497 height
= (height
+ unit
- 1) / unit
;
10500 /* Compute a suitable window start. */
10501 if (height
> max_height
)
10503 height
= max_height
;
10504 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10505 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10506 start
= it
.current
.pos
;
10509 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10510 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10512 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10514 /* Let it grow only, until we display an empty message, in which
10515 case the window shrinks again. */
10516 if (height
> WINDOW_TOTAL_LINES (w
))
10518 int old_height
= WINDOW_TOTAL_LINES (w
);
10520 FRAME_WINDOWS_FROZEN (f
) = 1;
10521 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10522 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10524 else if (height
< WINDOW_TOTAL_LINES (w
)
10525 && (exact_p
|| BEGV
== ZV
))
10527 int old_height
= WINDOW_TOTAL_LINES (w
);
10529 FRAME_WINDOWS_FROZEN (f
) = 0;
10530 shrink_mini_window (w
);
10531 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10536 /* Always resize to exact size needed. */
10537 if (height
> WINDOW_TOTAL_LINES (w
))
10539 int old_height
= WINDOW_TOTAL_LINES (w
);
10541 FRAME_WINDOWS_FROZEN (f
) = 1;
10542 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10543 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10545 else if (height
< WINDOW_TOTAL_LINES (w
))
10547 int old_height
= WINDOW_TOTAL_LINES (w
);
10549 FRAME_WINDOWS_FROZEN (f
) = 0;
10550 shrink_mini_window (w
);
10554 FRAME_WINDOWS_FROZEN (f
) = 1;
10555 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10558 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10562 if (old_current_buffer
)
10563 set_buffer_internal (old_current_buffer
);
10566 return window_height_changed_p
;
10570 /* Value is the current message, a string, or nil if there is no
10571 current message. */
10574 current_message (void)
10578 if (!BUFFERP (echo_area_buffer
[0]))
10582 with_echo_area_buffer (0, 0, current_message_1
,
10583 (intptr_t) &msg
, Qnil
);
10585 echo_area_buffer
[0] = Qnil
;
10593 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10596 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10599 *msg
= make_buffer_string (BEG
, Z
, 1);
10606 /* Push the current message on Vmessage_stack for later restoration
10607 by restore_message. Value is non-zero if the current message isn't
10608 empty. This is a relatively infrequent operation, so it's not
10609 worth optimizing. */
10612 push_message (void)
10614 Lisp_Object msg
= current_message ();
10615 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10616 return STRINGP (msg
);
10620 /* Restore message display from the top of Vmessage_stack. */
10623 restore_message (void)
10625 eassert (CONSP (Vmessage_stack
));
10626 message3_nolog (XCAR (Vmessage_stack
));
10630 /* Handler for unwind-protect calling pop_message. */
10633 pop_message_unwind (void)
10635 /* Pop the top-most entry off Vmessage_stack. */
10636 eassert (CONSP (Vmessage_stack
));
10637 Vmessage_stack
= XCDR (Vmessage_stack
);
10641 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10642 exits. If the stack is not empty, we have a missing pop_message
10646 check_message_stack (void)
10648 if (!NILP (Vmessage_stack
))
10653 /* Truncate to NCHARS what will be displayed in the echo area the next
10654 time we display it---but don't redisplay it now. */
10657 truncate_echo_area (ptrdiff_t nchars
)
10660 echo_area_buffer
[0] = Qnil
;
10661 else if (!noninteractive
10663 && !NILP (echo_area_buffer
[0]))
10665 struct frame
*sf
= SELECTED_FRAME ();
10666 /* Error messages get reported properly by cmd_error, so this must be
10667 just an informative message; if the frame hasn't really been
10668 initialized yet, just toss it. */
10669 if (sf
->glyphs_initialized_p
)
10670 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10675 /* Helper function for truncate_echo_area. Truncate the current
10676 message to at most NCHARS characters. */
10679 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10681 if (BEG
+ nchars
< Z
)
10682 del_range (BEG
+ nchars
, Z
);
10684 echo_area_buffer
[0] = Qnil
;
10688 /* Set the current message to STRING. */
10691 set_message (Lisp_Object string
)
10693 eassert (STRINGP (string
));
10695 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10697 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10698 message_buf_print
= 0;
10699 help_echo_showing_p
= 0;
10701 if (STRINGP (Vdebug_on_message
)
10702 && STRINGP (string
)
10703 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10704 call_debugger (list2 (Qerror
, string
));
10708 /* Helper function for set_message. First argument is ignored and second
10709 argument has the same meaning as for set_message.
10710 This function is called with the echo area buffer being current. */
10713 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10715 eassert (STRINGP (string
));
10717 /* Change multibyteness of the echo buffer appropriately. */
10718 if (message_enable_multibyte
10719 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10720 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10722 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10723 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10724 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10726 /* Insert new message at BEG. */
10727 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10729 /* This function takes care of single/multibyte conversion.
10730 We just have to ensure that the echo area buffer has the right
10731 setting of enable_multibyte_characters. */
10732 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10738 /* Clear messages. CURRENT_P non-zero means clear the current
10739 message. LAST_DISPLAYED_P non-zero means clear the message
10743 clear_message (int current_p
, int last_displayed_p
)
10747 echo_area_buffer
[0] = Qnil
;
10748 message_cleared_p
= 1;
10751 if (last_displayed_p
)
10752 echo_area_buffer
[1] = Qnil
;
10754 message_buf_print
= 0;
10757 /* Clear garbaged frames.
10759 This function is used where the old redisplay called
10760 redraw_garbaged_frames which in turn called redraw_frame which in
10761 turn called clear_frame. The call to clear_frame was a source of
10762 flickering. I believe a clear_frame is not necessary. It should
10763 suffice in the new redisplay to invalidate all current matrices,
10764 and ensure a complete redisplay of all windows. */
10767 clear_garbaged_frames (void)
10769 if (frame_garbaged
)
10771 Lisp_Object tail
, frame
;
10772 int changed_count
= 0;
10774 FOR_EACH_FRAME (tail
, frame
)
10776 struct frame
*f
= XFRAME (frame
);
10778 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10783 f
->force_flush_display_p
= 1;
10785 clear_current_matrices (f
);
10792 frame_garbaged
= 0;
10794 ++windows_or_buffers_changed
;
10799 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10800 is non-zero update selected_frame. Value is non-zero if the
10801 mini-windows height has been changed. */
10804 echo_area_display (int update_frame_p
)
10806 Lisp_Object mini_window
;
10809 int window_height_changed_p
= 0;
10810 struct frame
*sf
= SELECTED_FRAME ();
10812 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10813 w
= XWINDOW (mini_window
);
10814 f
= XFRAME (WINDOW_FRAME (w
));
10816 /* Don't display if frame is invisible or not yet initialized. */
10817 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10820 #ifdef HAVE_WINDOW_SYSTEM
10821 /* When Emacs starts, selected_frame may be the initial terminal
10822 frame. If we let this through, a message would be displayed on
10824 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10826 #endif /* HAVE_WINDOW_SYSTEM */
10828 /* Redraw garbaged frames. */
10829 clear_garbaged_frames ();
10831 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10833 echo_area_window
= mini_window
;
10834 window_height_changed_p
= display_echo_area (w
);
10835 w
->must_be_updated_p
= 1;
10837 /* Update the display, unless called from redisplay_internal.
10838 Also don't update the screen during redisplay itself. The
10839 update will happen at the end of redisplay, and an update
10840 here could cause confusion. */
10841 if (update_frame_p
&& !redisplaying_p
)
10845 /* If the display update has been interrupted by pending
10846 input, update mode lines in the frame. Due to the
10847 pending input, it might have been that redisplay hasn't
10848 been called, so that mode lines above the echo area are
10849 garbaged. This looks odd, so we prevent it here. */
10850 if (!display_completed
)
10851 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10853 if (window_height_changed_p
10854 /* Don't do this if Emacs is shutting down. Redisplay
10855 needs to run hooks. */
10856 && !NILP (Vrun_hooks
))
10858 /* Must update other windows. Likewise as in other
10859 cases, don't let this update be interrupted by
10861 ptrdiff_t count
= SPECPDL_INDEX ();
10862 specbind (Qredisplay_dont_pause
, Qt
);
10863 windows_or_buffers_changed
= 1;
10864 redisplay_internal ();
10865 unbind_to (count
, Qnil
);
10867 else if (FRAME_WINDOW_P (f
) && n
== 0)
10869 /* Window configuration is the same as before.
10870 Can do with a display update of the echo area,
10871 unless we displayed some mode lines. */
10872 update_single_window (w
, 1);
10873 FRAME_RIF (f
)->flush_display (f
);
10876 update_frame (f
, 1, 1);
10878 /* If cursor is in the echo area, make sure that the next
10879 redisplay displays the minibuffer, so that the cursor will
10880 be replaced with what the minibuffer wants. */
10881 if (cursor_in_echo_area
)
10882 ++windows_or_buffers_changed
;
10885 else if (!EQ (mini_window
, selected_window
))
10886 windows_or_buffers_changed
++;
10888 /* Last displayed message is now the current message. */
10889 echo_area_buffer
[1] = echo_area_buffer
[0];
10890 /* Inform read_char that we're not echoing. */
10891 echo_message_buffer
= Qnil
;
10893 /* Prevent redisplay optimization in redisplay_internal by resetting
10894 this_line_start_pos. This is done because the mini-buffer now
10895 displays the message instead of its buffer text. */
10896 if (EQ (mini_window
, selected_window
))
10897 CHARPOS (this_line_start_pos
) = 0;
10899 return window_height_changed_p
;
10902 /* Nonzero if the current window's buffer is shown in more than one
10903 window and was modified since last redisplay. */
10906 buffer_shared_and_changed (void)
10908 return (buffer_window_count (current_buffer
) > 1
10909 && UNCHANGED_MODIFIED
< MODIFF
);
10912 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10913 is enabled and mark of W's buffer was changed since last W's update. */
10916 window_buffer_changed (struct window
*w
)
10918 struct buffer
*b
= XBUFFER (w
->contents
);
10920 eassert (BUFFER_LIVE_P (b
));
10922 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10923 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10924 != (w
->region_showing
!= 0)));
10927 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10930 mode_line_update_needed (struct window
*w
)
10932 return (w
->column_number_displayed
!= -1
10933 && !(PT
== w
->last_point
&& !window_outdated (w
))
10934 && (w
->column_number_displayed
!= current_column ()));
10937 /* Nonzero if window start of W is frozen and may not be changed during
10941 window_frozen_p (struct window
*w
)
10943 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10945 Lisp_Object window
;
10947 XSETWINDOW (window
, w
);
10948 if (MINI_WINDOW_P (w
))
10950 else if (EQ (window
, selected_window
))
10952 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10953 && EQ (window
, Vminibuf_scroll_window
))
10954 /* This special window can't be frozen too. */
10962 /***********************************************************************
10963 Mode Lines and Frame Titles
10964 ***********************************************************************/
10966 /* A buffer for constructing non-propertized mode-line strings and
10967 frame titles in it; allocated from the heap in init_xdisp and
10968 resized as needed in store_mode_line_noprop_char. */
10970 static char *mode_line_noprop_buf
;
10972 /* The buffer's end, and a current output position in it. */
10974 static char *mode_line_noprop_buf_end
;
10975 static char *mode_line_noprop_ptr
;
10977 #define MODE_LINE_NOPROP_LEN(start) \
10978 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10981 MODE_LINE_DISPLAY
= 0,
10985 } mode_line_target
;
10987 /* Alist that caches the results of :propertize.
10988 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10989 static Lisp_Object mode_line_proptrans_alist
;
10991 /* List of strings making up the mode-line. */
10992 static Lisp_Object mode_line_string_list
;
10994 /* Base face property when building propertized mode line string. */
10995 static Lisp_Object mode_line_string_face
;
10996 static Lisp_Object mode_line_string_face_prop
;
10999 /* Unwind data for mode line strings */
11001 static Lisp_Object Vmode_line_unwind_vector
;
11004 format_mode_line_unwind_data (struct frame
*target_frame
,
11005 struct buffer
*obuf
,
11007 int save_proptrans
)
11009 Lisp_Object vector
, tmp
;
11011 /* Reduce consing by keeping one vector in
11012 Vwith_echo_area_save_vector. */
11013 vector
= Vmode_line_unwind_vector
;
11014 Vmode_line_unwind_vector
= Qnil
;
11017 vector
= Fmake_vector (make_number (10), Qnil
);
11019 ASET (vector
, 0, make_number (mode_line_target
));
11020 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11021 ASET (vector
, 2, mode_line_string_list
);
11022 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11023 ASET (vector
, 4, mode_line_string_face
);
11024 ASET (vector
, 5, mode_line_string_face_prop
);
11027 XSETBUFFER (tmp
, obuf
);
11030 ASET (vector
, 6, tmp
);
11031 ASET (vector
, 7, owin
);
11034 /* Similarly to `with-selected-window', if the operation selects
11035 a window on another frame, we must restore that frame's
11036 selected window, and (for a tty) the top-frame. */
11037 ASET (vector
, 8, target_frame
->selected_window
);
11038 if (FRAME_TERMCAP_P (target_frame
))
11039 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11046 unwind_format_mode_line (Lisp_Object vector
)
11048 Lisp_Object old_window
= AREF (vector
, 7);
11049 Lisp_Object target_frame_window
= AREF (vector
, 8);
11050 Lisp_Object old_top_frame
= AREF (vector
, 9);
11052 mode_line_target
= XINT (AREF (vector
, 0));
11053 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11054 mode_line_string_list
= AREF (vector
, 2);
11055 if (! EQ (AREF (vector
, 3), Qt
))
11056 mode_line_proptrans_alist
= AREF (vector
, 3);
11057 mode_line_string_face
= AREF (vector
, 4);
11058 mode_line_string_face_prop
= AREF (vector
, 5);
11060 /* Select window before buffer, since it may change the buffer. */
11061 if (!NILP (old_window
))
11063 /* If the operation that we are unwinding had selected a window
11064 on a different frame, reset its frame-selected-window. For a
11065 text terminal, reset its top-frame if necessary. */
11066 if (!NILP (target_frame_window
))
11069 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11071 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11072 Fselect_window (target_frame_window
, Qt
);
11074 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11075 Fselect_frame (old_top_frame
, Qt
);
11078 Fselect_window (old_window
, Qt
);
11081 if (!NILP (AREF (vector
, 6)))
11083 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11084 ASET (vector
, 6, Qnil
);
11087 Vmode_line_unwind_vector
= vector
;
11091 /* Store a single character C for the frame title in mode_line_noprop_buf.
11092 Re-allocate mode_line_noprop_buf if necessary. */
11095 store_mode_line_noprop_char (char c
)
11097 /* If output position has reached the end of the allocated buffer,
11098 increase the buffer's size. */
11099 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11101 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11102 ptrdiff_t size
= len
;
11103 mode_line_noprop_buf
=
11104 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11105 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11106 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11109 *mode_line_noprop_ptr
++ = c
;
11113 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11114 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11115 characters that yield more columns than PRECISION; PRECISION <= 0
11116 means copy the whole string. Pad with spaces until FIELD_WIDTH
11117 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11118 pad. Called from display_mode_element when it is used to build a
11122 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11124 const unsigned char *str
= (const unsigned char *) string
;
11126 ptrdiff_t dummy
, nbytes
;
11128 /* Copy at most PRECISION chars from STR. */
11129 nbytes
= strlen (string
);
11130 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11132 store_mode_line_noprop_char (*str
++);
11134 /* Fill up with spaces until FIELD_WIDTH reached. */
11135 while (field_width
> 0
11136 && n
< field_width
)
11138 store_mode_line_noprop_char (' ');
11145 /***********************************************************************
11147 ***********************************************************************/
11149 #ifdef HAVE_WINDOW_SYSTEM
11151 /* Set the title of FRAME, if it has changed. The title format is
11152 Vicon_title_format if FRAME is iconified, otherwise it is
11153 frame_title_format. */
11156 x_consider_frame_title (Lisp_Object frame
)
11158 struct frame
*f
= XFRAME (frame
);
11160 if (FRAME_WINDOW_P (f
)
11161 || FRAME_MINIBUF_ONLY_P (f
)
11162 || f
->explicit_name
)
11164 /* Do we have more than one visible frame on this X display? */
11165 Lisp_Object tail
, other_frame
, fmt
;
11166 ptrdiff_t title_start
;
11170 ptrdiff_t count
= SPECPDL_INDEX ();
11172 FOR_EACH_FRAME (tail
, other_frame
)
11174 struct frame
*tf
= XFRAME (other_frame
);
11177 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11178 && !FRAME_MINIBUF_ONLY_P (tf
)
11179 && !EQ (other_frame
, tip_frame
)
11180 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11184 /* Set global variable indicating that multiple frames exist. */
11185 multiple_frames
= CONSP (tail
);
11187 /* Switch to the buffer of selected window of the frame. Set up
11188 mode_line_target so that display_mode_element will output into
11189 mode_line_noprop_buf; then display the title. */
11190 record_unwind_protect (unwind_format_mode_line
,
11191 format_mode_line_unwind_data
11192 (f
, current_buffer
, selected_window
, 0));
11194 Fselect_window (f
->selected_window
, Qt
);
11195 set_buffer_internal_1
11196 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11197 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11199 mode_line_target
= MODE_LINE_TITLE
;
11200 title_start
= MODE_LINE_NOPROP_LEN (0);
11201 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11202 NULL
, DEFAULT_FACE_ID
);
11203 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11204 len
= MODE_LINE_NOPROP_LEN (title_start
);
11205 title
= mode_line_noprop_buf
+ title_start
;
11206 unbind_to (count
, Qnil
);
11208 /* Set the title only if it's changed. This avoids consing in
11209 the common case where it hasn't. (If it turns out that we've
11210 already wasted too much time by walking through the list with
11211 display_mode_element, then we might need to optimize at a
11212 higher level than this.) */
11213 if (! STRINGP (f
->name
)
11214 || SBYTES (f
->name
) != len
11215 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11216 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11220 #endif /* not HAVE_WINDOW_SYSTEM */
11223 /***********************************************************************
11225 ***********************************************************************/
11228 /* Prepare for redisplay by updating menu-bar item lists when
11229 appropriate. This can call eval. */
11232 prepare_menu_bars (void)
11235 struct gcpro gcpro1
, gcpro2
;
11237 Lisp_Object tooltip_frame
;
11239 #ifdef HAVE_WINDOW_SYSTEM
11240 tooltip_frame
= tip_frame
;
11242 tooltip_frame
= Qnil
;
11245 /* Update all frame titles based on their buffer names, etc. We do
11246 this before the menu bars so that the buffer-menu will show the
11247 up-to-date frame titles. */
11248 #ifdef HAVE_WINDOW_SYSTEM
11249 if (windows_or_buffers_changed
|| update_mode_lines
)
11251 Lisp_Object tail
, frame
;
11253 FOR_EACH_FRAME (tail
, frame
)
11255 f
= XFRAME (frame
);
11256 if (!EQ (frame
, tooltip_frame
)
11257 && (FRAME_ICONIFIED_P (f
)
11258 || FRAME_VISIBLE_P (f
) == 1
11259 /* Exclude TTY frames that are obscured because they
11260 are not the top frame on their console. This is
11261 because x_consider_frame_title actually switches
11262 to the frame, which for TTY frames means it is
11263 marked as garbaged, and will be completely
11264 redrawn on the next redisplay cycle. This causes
11265 TTY frames to be completely redrawn, when there
11266 are more than one of them, even though nothing
11267 should be changed on display. */
11268 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11269 x_consider_frame_title (frame
);
11272 #endif /* HAVE_WINDOW_SYSTEM */
11274 /* Update the menu bar item lists, if appropriate. This has to be
11275 done before any actual redisplay or generation of display lines. */
11276 all_windows
= (update_mode_lines
11277 || buffer_shared_and_changed ()
11278 || windows_or_buffers_changed
);
11281 Lisp_Object tail
, frame
;
11282 ptrdiff_t count
= SPECPDL_INDEX ();
11283 /* 1 means that update_menu_bar has run its hooks
11284 so any further calls to update_menu_bar shouldn't do so again. */
11285 int menu_bar_hooks_run
= 0;
11287 record_unwind_save_match_data ();
11289 FOR_EACH_FRAME (tail
, frame
)
11291 f
= XFRAME (frame
);
11293 /* Ignore tooltip frame. */
11294 if (EQ (frame
, tooltip_frame
))
11297 /* If a window on this frame changed size, report that to
11298 the user and clear the size-change flag. */
11299 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11301 Lisp_Object functions
;
11303 /* Clear flag first in case we get an error below. */
11304 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11305 functions
= Vwindow_size_change_functions
;
11306 GCPRO2 (tail
, functions
);
11308 while (CONSP (functions
))
11310 if (!EQ (XCAR (functions
), Qt
))
11311 call1 (XCAR (functions
), frame
);
11312 functions
= XCDR (functions
);
11318 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11319 #ifdef HAVE_WINDOW_SYSTEM
11320 update_tool_bar (f
, 0);
11323 if (windows_or_buffers_changed
11326 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11331 unbind_to (count
, Qnil
);
11335 struct frame
*sf
= SELECTED_FRAME ();
11336 update_menu_bar (sf
, 1, 0);
11337 #ifdef HAVE_WINDOW_SYSTEM
11338 update_tool_bar (sf
, 1);
11344 /* Update the menu bar item list for frame F. This has to be done
11345 before we start to fill in any display lines, because it can call
11348 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11350 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11351 already ran the menu bar hooks for this redisplay, so there
11352 is no need to run them again. The return value is the
11353 updated value of this flag, to pass to the next call. */
11356 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11358 Lisp_Object window
;
11359 register struct window
*w
;
11361 /* If called recursively during a menu update, do nothing. This can
11362 happen when, for instance, an activate-menubar-hook causes a
11364 if (inhibit_menubar_update
)
11367 window
= FRAME_SELECTED_WINDOW (f
);
11368 w
= XWINDOW (window
);
11370 if (FRAME_WINDOW_P (f
)
11372 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11373 || defined (HAVE_NS) || defined (USE_GTK)
11374 FRAME_EXTERNAL_MENU_BAR (f
)
11376 FRAME_MENU_BAR_LINES (f
) > 0
11378 : FRAME_MENU_BAR_LINES (f
) > 0)
11380 /* If the user has switched buffers or windows, we need to
11381 recompute to reflect the new bindings. But we'll
11382 recompute when update_mode_lines is set too; that means
11383 that people can use force-mode-line-update to request
11384 that the menu bar be recomputed. The adverse effect on
11385 the rest of the redisplay algorithm is about the same as
11386 windows_or_buffers_changed anyway. */
11387 if (windows_or_buffers_changed
11388 /* This used to test w->update_mode_line, but we believe
11389 there is no need to recompute the menu in that case. */
11390 || update_mode_lines
11391 || window_buffer_changed (w
))
11393 struct buffer
*prev
= current_buffer
;
11394 ptrdiff_t count
= SPECPDL_INDEX ();
11396 specbind (Qinhibit_menubar_update
, Qt
);
11398 set_buffer_internal_1 (XBUFFER (w
->contents
));
11399 if (save_match_data
)
11400 record_unwind_save_match_data ();
11401 if (NILP (Voverriding_local_map_menu_flag
))
11403 specbind (Qoverriding_terminal_local_map
, Qnil
);
11404 specbind (Qoverriding_local_map
, Qnil
);
11409 /* Run the Lucid hook. */
11410 safe_run_hooks (Qactivate_menubar_hook
);
11412 /* If it has changed current-menubar from previous value,
11413 really recompute the menu-bar from the value. */
11414 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11415 call0 (Qrecompute_lucid_menubar
);
11417 safe_run_hooks (Qmenu_bar_update_hook
);
11422 XSETFRAME (Vmenu_updating_frame
, f
);
11423 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11425 /* Redisplay the menu bar in case we changed it. */
11426 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11427 || defined (HAVE_NS) || defined (USE_GTK)
11428 if (FRAME_WINDOW_P (f
))
11430 #if defined (HAVE_NS)
11431 /* All frames on Mac OS share the same menubar. So only
11432 the selected frame should be allowed to set it. */
11433 if (f
== SELECTED_FRAME ())
11435 set_frame_menubar (f
, 0, 0);
11438 /* On a terminal screen, the menu bar is an ordinary screen
11439 line, and this makes it get updated. */
11440 w
->update_mode_line
= 1;
11441 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11442 /* In the non-toolkit version, the menu bar is an ordinary screen
11443 line, and this makes it get updated. */
11444 w
->update_mode_line
= 1;
11445 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11447 unbind_to (count
, Qnil
);
11448 set_buffer_internal_1 (prev
);
11455 /***********************************************************************
11457 ***********************************************************************/
11459 #ifdef HAVE_WINDOW_SYSTEM
11461 /* Where the mouse was last time we reported a mouse event. */
11463 struct frame
*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
;
11484 /* Update the tool-bar item list for frame F. This has to be done
11485 before we start to fill in any display lines. Called from
11486 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11487 and restore it here. */
11490 update_tool_bar (struct frame
*f
, int save_match_data
)
11492 #if defined (USE_GTK) || defined (HAVE_NS)
11493 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11495 int do_update
= WINDOWP (f
->tool_bar_window
)
11496 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11501 Lisp_Object window
;
11504 window
= FRAME_SELECTED_WINDOW (f
);
11505 w
= XWINDOW (window
);
11507 /* If the user has switched buffers or windows, we need to
11508 recompute to reflect the new bindings. But we'll
11509 recompute when update_mode_lines is set too; that means
11510 that people can use force-mode-line-update to request
11511 that the menu bar be recomputed. The adverse effect on
11512 the rest of the redisplay algorithm is about the same as
11513 windows_or_buffers_changed anyway. */
11514 if (windows_or_buffers_changed
11515 || w
->update_mode_line
11516 || update_mode_lines
11517 || window_buffer_changed (w
))
11519 struct buffer
*prev
= current_buffer
;
11520 ptrdiff_t count
= SPECPDL_INDEX ();
11521 Lisp_Object frame
, new_tool_bar
;
11522 int new_n_tool_bar
;
11523 struct gcpro gcpro1
;
11525 /* Set current_buffer to the buffer of the selected
11526 window of the frame, so that we get the right local
11528 set_buffer_internal_1 (XBUFFER (w
->contents
));
11530 /* Save match data, if we must. */
11531 if (save_match_data
)
11532 record_unwind_save_match_data ();
11534 /* Make sure that we don't accidentally use bogus keymaps. */
11535 if (NILP (Voverriding_local_map_menu_flag
))
11537 specbind (Qoverriding_terminal_local_map
, Qnil
);
11538 specbind (Qoverriding_local_map
, Qnil
);
11541 GCPRO1 (new_tool_bar
);
11543 /* We must temporarily set the selected frame to this frame
11544 before calling tool_bar_items, because the calculation of
11545 the tool-bar keymap uses the selected frame (see
11546 `tool-bar-make-keymap' in tool-bar.el). */
11547 eassert (EQ (selected_window
,
11548 /* Since we only explicitly preserve selected_frame,
11549 check that selected_window would be redundant. */
11550 XFRAME (selected_frame
)->selected_window
));
11551 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11552 XSETFRAME (frame
, f
);
11553 fast_set_selected_frame (frame
);
11555 /* Build desired tool-bar items from keymaps. */
11557 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11560 /* Redisplay the tool-bar if we changed it. */
11561 if (new_n_tool_bar
!= f
->n_tool_bar_items
11562 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11564 /* Redisplay that happens asynchronously due to an expose event
11565 may access f->tool_bar_items. Make sure we update both
11566 variables within BLOCK_INPUT so no such event interrupts. */
11568 fset_tool_bar_items (f
, new_tool_bar
);
11569 f
->n_tool_bar_items
= new_n_tool_bar
;
11570 w
->update_mode_line
= 1;
11576 unbind_to (count
, Qnil
);
11577 set_buffer_internal_1 (prev
);
11583 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11584 F's desired tool-bar contents. F->tool_bar_items must have
11585 been set up previously by calling prepare_menu_bars. */
11588 build_desired_tool_bar_string (struct frame
*f
)
11590 int i
, size
, size_needed
;
11591 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11592 Lisp_Object image
, plist
, props
;
11594 image
= plist
= props
= Qnil
;
11595 GCPRO3 (image
, plist
, props
);
11597 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11598 Otherwise, make a new string. */
11600 /* The size of the string we might be able to reuse. */
11601 size
= (STRINGP (f
->desired_tool_bar_string
)
11602 ? SCHARS (f
->desired_tool_bar_string
)
11605 /* We need one space in the string for each image. */
11606 size_needed
= f
->n_tool_bar_items
;
11608 /* Reuse f->desired_tool_bar_string, if possible. */
11609 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11610 fset_desired_tool_bar_string
11611 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11614 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11615 Fremove_text_properties (make_number (0), make_number (size
),
11616 props
, f
->desired_tool_bar_string
);
11619 /* Put a `display' property on the string for the images to display,
11620 put a `menu_item' property on tool-bar items with a value that
11621 is the index of the item in F's tool-bar item vector. */
11622 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11624 #define PROP(IDX) \
11625 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11627 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11628 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11629 int hmargin
, vmargin
, relief
, idx
, end
;
11631 /* If image is a vector, choose the image according to the
11633 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11634 if (VECTORP (image
))
11638 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11639 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11642 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11643 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11645 eassert (ASIZE (image
) >= idx
);
11646 image
= AREF (image
, idx
);
11651 /* Ignore invalid image specifications. */
11652 if (!valid_image_p (image
))
11655 /* Display the tool-bar button pressed, or depressed. */
11656 plist
= Fcopy_sequence (XCDR (image
));
11658 /* Compute margin and relief to draw. */
11659 relief
= (tool_bar_button_relief
>= 0
11660 ? tool_bar_button_relief
11661 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11662 hmargin
= vmargin
= relief
;
11664 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11665 INT_MAX
- max (hmargin
, vmargin
)))
11667 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11668 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11670 else if (CONSP (Vtool_bar_button_margin
))
11672 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11673 INT_MAX
- hmargin
))
11674 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11676 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11677 INT_MAX
- vmargin
))
11678 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11681 if (auto_raise_tool_bar_buttons_p
)
11683 /* Add a `:relief' property to the image spec if the item is
11687 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11694 /* If image is selected, display it pressed, i.e. with a
11695 negative relief. If it's not selected, display it with a
11697 plist
= Fplist_put (plist
, QCrelief
,
11699 ? make_number (-relief
)
11700 : make_number (relief
)));
11705 /* Put a margin around the image. */
11706 if (hmargin
|| vmargin
)
11708 if (hmargin
== vmargin
)
11709 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11711 plist
= Fplist_put (plist
, QCmargin
,
11712 Fcons (make_number (hmargin
),
11713 make_number (vmargin
)));
11716 /* If button is not enabled, and we don't have special images
11717 for the disabled state, make the image appear disabled by
11718 applying an appropriate algorithm to it. */
11719 if (!enabled_p
&& idx
< 0)
11720 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11722 /* Put a `display' text property on the string for the image to
11723 display. Put a `menu-item' property on the string that gives
11724 the start of this item's properties in the tool-bar items
11726 image
= Fcons (Qimage
, plist
);
11727 props
= list4 (Qdisplay
, image
,
11728 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11730 /* Let the last image hide all remaining spaces in the tool bar
11731 string. The string can be longer than needed when we reuse a
11732 previous string. */
11733 if (i
+ 1 == f
->n_tool_bar_items
)
11734 end
= SCHARS (f
->desired_tool_bar_string
);
11737 Fadd_text_properties (make_number (i
), make_number (end
),
11738 props
, f
->desired_tool_bar_string
);
11746 /* Display one line of the tool-bar of frame IT->f.
11748 HEIGHT specifies the desired height of the tool-bar line.
11749 If the actual height of the glyph row is less than HEIGHT, the
11750 row's height is increased to HEIGHT, and the icons are centered
11751 vertically in the new height.
11753 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11754 count a final empty row in case the tool-bar width exactly matches
11759 display_tool_bar_line (struct it
*it
, int height
)
11761 struct glyph_row
*row
= it
->glyph_row
;
11762 int max_x
= it
->last_visible_x
;
11763 struct glyph
*last
;
11765 prepare_desired_row (row
);
11766 row
->y
= it
->current_y
;
11768 /* Note that this isn't made use of if the face hasn't a box,
11769 so there's no need to check the face here. */
11770 it
->start_of_box_run_p
= 1;
11772 while (it
->current_x
< max_x
)
11774 int x
, n_glyphs_before
, i
, nglyphs
;
11775 struct it it_before
;
11777 /* Get the next display element. */
11778 if (!get_next_display_element (it
))
11780 /* Don't count empty row if we are counting needed tool-bar lines. */
11781 if (height
< 0 && !it
->hpos
)
11786 /* Produce glyphs. */
11787 n_glyphs_before
= row
->used
[TEXT_AREA
];
11790 PRODUCE_GLYPHS (it
);
11792 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11794 x
= it_before
.current_x
;
11795 while (i
< nglyphs
)
11797 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11799 if (x
+ glyph
->pixel_width
> max_x
)
11801 /* Glyph doesn't fit on line. Backtrack. */
11802 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11804 /* If this is the only glyph on this line, it will never fit on the
11805 tool-bar, so skip it. But ensure there is at least one glyph,
11806 so we don't accidentally disable the tool-bar. */
11807 if (n_glyphs_before
== 0
11808 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11814 x
+= glyph
->pixel_width
;
11818 /* Stop at line end. */
11819 if (ITERATOR_AT_END_OF_LINE_P (it
))
11822 set_iterator_to_next (it
, 1);
11827 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11829 /* Use default face for the border below the tool bar.
11831 FIXME: When auto-resize-tool-bars is grow-only, there is
11832 no additional border below the possibly empty tool-bar lines.
11833 So to make the extra empty lines look "normal", we have to
11834 use the tool-bar face for the border too. */
11835 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11836 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11837 it
->face_id
= DEFAULT_FACE_ID
;
11839 extend_face_to_end_of_line (it
);
11840 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11841 last
->right_box_line_p
= 1;
11842 if (last
== row
->glyphs
[TEXT_AREA
])
11843 last
->left_box_line_p
= 1;
11845 /* Make line the desired height and center it vertically. */
11846 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11848 /* Don't add more than one line height. */
11849 height
%= FRAME_LINE_HEIGHT (it
->f
);
11850 it
->max_ascent
+= height
/ 2;
11851 it
->max_descent
+= (height
+ 1) / 2;
11854 compute_line_metrics (it
);
11856 /* If line is empty, make it occupy the rest of the tool-bar. */
11857 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11859 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11860 row
->visible_height
= row
->height
;
11861 row
->ascent
= row
->phys_ascent
= 0;
11862 row
->extra_line_spacing
= 0;
11865 row
->full_width_p
= 1;
11866 row
->continued_p
= 0;
11867 row
->truncated_on_left_p
= 0;
11868 row
->truncated_on_right_p
= 0;
11870 it
->current_x
= it
->hpos
= 0;
11871 it
->current_y
+= row
->height
;
11877 /* Max tool-bar height. */
11879 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11880 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11882 /* Value is the number of screen lines needed to make all tool-bar
11883 items of frame F visible. The number of actual rows needed is
11884 returned in *N_ROWS if non-NULL. */
11887 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11889 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11891 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11892 the desired matrix, so use (unused) mode-line row as temporary row to
11893 avoid destroying the first tool-bar row. */
11894 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11896 /* Initialize an iterator for iteration over
11897 F->desired_tool_bar_string in the tool-bar window of frame F. */
11898 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11899 it
.first_visible_x
= 0;
11900 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11901 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11902 it
.paragraph_embedding
= L2R
;
11904 while (!ITERATOR_AT_END_P (&it
))
11906 clear_glyph_row (temp_row
);
11907 it
.glyph_row
= temp_row
;
11908 display_tool_bar_line (&it
, -1);
11910 clear_glyph_row (temp_row
);
11912 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11914 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11916 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11920 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11922 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11923 If FRAME is nil or omitted, use the selected frame. */)
11924 (Lisp_Object frame
)
11926 struct frame
*f
= decode_any_frame (frame
);
11930 if (WINDOWP (f
->tool_bar_window
)
11931 && (w
= XWINDOW (f
->tool_bar_window
),
11932 WINDOW_TOTAL_LINES (w
) > 0))
11934 update_tool_bar (f
, 1);
11935 if (f
->n_tool_bar_items
)
11937 build_desired_tool_bar_string (f
);
11938 nlines
= tool_bar_lines_needed (f
, NULL
);
11942 return make_number (nlines
);
11946 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11947 height should be changed. */
11950 redisplay_tool_bar (struct frame
*f
)
11954 struct glyph_row
*row
;
11956 #if defined (USE_GTK) || defined (HAVE_NS)
11957 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11958 update_frame_tool_bar (f
);
11962 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11963 do anything. This means you must start with tool-bar-lines
11964 non-zero to get the auto-sizing effect. Or in other words, you
11965 can turn off tool-bars by specifying tool-bar-lines zero. */
11966 if (!WINDOWP (f
->tool_bar_window
)
11967 || (w
= XWINDOW (f
->tool_bar_window
),
11968 WINDOW_TOTAL_LINES (w
) == 0))
11971 /* Set up an iterator for the tool-bar window. */
11972 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11973 it
.first_visible_x
= 0;
11974 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11975 row
= it
.glyph_row
;
11977 /* Build a string that represents the contents of the tool-bar. */
11978 build_desired_tool_bar_string (f
);
11979 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11980 /* FIXME: This should be controlled by a user option. But it
11981 doesn't make sense to have an R2L tool bar if the menu bar cannot
11982 be drawn also R2L, and making the menu bar R2L is tricky due
11983 toolkit-specific code that implements it. If an R2L tool bar is
11984 ever supported, display_tool_bar_line should also be augmented to
11985 call unproduce_glyphs like display_line and display_string
11987 it
.paragraph_embedding
= L2R
;
11989 if (f
->n_tool_bar_rows
== 0)
11993 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11994 nlines
!= WINDOW_TOTAL_LINES (w
)))
11997 int old_height
= WINDOW_TOTAL_LINES (w
);
11999 XSETFRAME (frame
, f
);
12000 Fmodify_frame_parameters (frame
,
12001 list1 (Fcons (Qtool_bar_lines
,
12002 make_number (nlines
))));
12003 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12005 clear_glyph_matrix (w
->desired_matrix
);
12006 fonts_changed_p
= 1;
12012 /* Display as many lines as needed to display all tool-bar items. */
12014 if (f
->n_tool_bar_rows
> 0)
12016 int border
, rows
, height
, extra
;
12018 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12019 border
= XINT (Vtool_bar_border
);
12020 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12021 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12022 else if (EQ (Vtool_bar_border
, Qborder_width
))
12023 border
= f
->border_width
;
12029 rows
= f
->n_tool_bar_rows
;
12030 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12031 extra
= it
.last_visible_y
- border
- height
* rows
;
12033 while (it
.current_y
< it
.last_visible_y
)
12036 if (extra
> 0 && rows
-- > 0)
12038 h
= (extra
+ rows
- 1) / rows
;
12041 display_tool_bar_line (&it
, height
+ h
);
12046 while (it
.current_y
< it
.last_visible_y
)
12047 display_tool_bar_line (&it
, 0);
12050 /* It doesn't make much sense to try scrolling in the tool-bar
12051 window, so don't do it. */
12052 w
->desired_matrix
->no_scrolling_p
= 1;
12053 w
->must_be_updated_p
= 1;
12055 if (!NILP (Vauto_resize_tool_bars
))
12057 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12058 int change_height_p
= 0;
12060 /* If we couldn't display everything, change the tool-bar's
12061 height if there is room for more. */
12062 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12063 && it
.current_y
< max_tool_bar_height
)
12064 change_height_p
= 1;
12066 row
= it
.glyph_row
- 1;
12068 /* If there are blank lines at the end, except for a partially
12069 visible blank line at the end that is smaller than
12070 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12071 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12072 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12073 change_height_p
= 1;
12075 /* If row displays tool-bar items, but is partially visible,
12076 change the tool-bar's height. */
12077 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12078 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12079 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12080 change_height_p
= 1;
12082 /* Resize windows as needed by changing the `tool-bar-lines'
12083 frame parameter. */
12084 if (change_height_p
)
12087 int old_height
= WINDOW_TOTAL_LINES (w
);
12089 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12091 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12092 && !f
->minimize_tool_bar_window_p
)
12093 ? (nlines
> old_height
)
12094 : (nlines
!= old_height
));
12095 f
->minimize_tool_bar_window_p
= 0;
12097 if (change_height_p
)
12099 XSETFRAME (frame
, f
);
12100 Fmodify_frame_parameters (frame
,
12101 list1 (Fcons (Qtool_bar_lines
,
12102 make_number (nlines
))));
12103 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12105 clear_glyph_matrix (w
->desired_matrix
);
12106 f
->n_tool_bar_rows
= nrows
;
12107 fonts_changed_p
= 1;
12114 f
->minimize_tool_bar_window_p
= 0;
12119 /* Get information about the tool-bar item which is displayed in GLYPH
12120 on frame F. Return in *PROP_IDX the index where tool-bar item
12121 properties start in F->tool_bar_items. Value is zero if
12122 GLYPH doesn't display a tool-bar item. */
12125 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12131 /* This function can be called asynchronously, which means we must
12132 exclude any possibility that Fget_text_property signals an
12134 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12135 charpos
= max (0, charpos
);
12137 /* Get the text property `menu-item' at pos. The value of that
12138 property is the start index of this item's properties in
12139 F->tool_bar_items. */
12140 prop
= Fget_text_property (make_number (charpos
),
12141 Qmenu_item
, f
->current_tool_bar_string
);
12142 if (INTEGERP (prop
))
12144 *prop_idx
= XINT (prop
);
12154 /* Get information about the tool-bar item at position X/Y on frame F.
12155 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12156 the current matrix of the tool-bar window of F, or NULL if not
12157 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12158 item in F->tool_bar_items. Value is
12160 -1 if X/Y is not on a tool-bar item
12161 0 if X/Y is on the same item that was highlighted before.
12165 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12166 int *hpos
, int *vpos
, int *prop_idx
)
12168 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12169 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12172 /* Find the glyph under X/Y. */
12173 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12174 if (*glyph
== NULL
)
12177 /* Get the start of this tool-bar item's properties in
12178 f->tool_bar_items. */
12179 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12182 /* Is mouse on the highlighted item? */
12183 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12184 && *vpos
>= hlinfo
->mouse_face_beg_row
12185 && *vpos
<= hlinfo
->mouse_face_end_row
12186 && (*vpos
> hlinfo
->mouse_face_beg_row
12187 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12188 && (*vpos
< hlinfo
->mouse_face_end_row
12189 || *hpos
< hlinfo
->mouse_face_end_col
12190 || hlinfo
->mouse_face_past_end
))
12198 Handle mouse button event on the tool-bar of frame F, at
12199 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12200 0 for button release. MODIFIERS is event modifiers for button
12204 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12207 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12208 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12209 int hpos
, vpos
, prop_idx
;
12210 struct glyph
*glyph
;
12211 Lisp_Object enabled_p
;
12214 /* If not on the highlighted tool-bar item, and mouse-highlight is
12215 non-nil, return. This is so we generate the tool-bar button
12216 click only when the mouse button is released on the same item as
12217 where it was pressed. However, when mouse-highlight is disabled,
12218 generate the click when the button is released regardless of the
12219 highlight, since tool-bar items are not highlighted in that
12221 frame_to_window_pixel_xy (w
, &x
, &y
);
12222 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12224 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12227 /* When mouse-highlight is off, generate the click for the item
12228 where the button was pressed, disregarding where it was
12230 if (NILP (Vmouse_highlight
) && !down_p
)
12231 prop_idx
= last_tool_bar_item
;
12233 /* If item is disabled, do nothing. */
12234 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12235 if (NILP (enabled_p
))
12240 /* Show item in pressed state. */
12241 if (!NILP (Vmouse_highlight
))
12242 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12243 last_tool_bar_item
= prop_idx
;
12247 Lisp_Object key
, frame
;
12248 struct input_event event
;
12249 EVENT_INIT (event
);
12251 /* Show item in released state. */
12252 if (!NILP (Vmouse_highlight
))
12253 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12255 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12257 XSETFRAME (frame
, f
);
12258 event
.kind
= TOOL_BAR_EVENT
;
12259 event
.frame_or_window
= frame
;
12261 kbd_buffer_store_event (&event
);
12263 event
.kind
= TOOL_BAR_EVENT
;
12264 event
.frame_or_window
= frame
;
12266 event
.modifiers
= modifiers
;
12267 kbd_buffer_store_event (&event
);
12268 last_tool_bar_item
= -1;
12273 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12274 tool-bar window-relative coordinates X/Y. Called from
12275 note_mouse_highlight. */
12278 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12280 Lisp_Object window
= f
->tool_bar_window
;
12281 struct window
*w
= XWINDOW (window
);
12282 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12283 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12285 struct glyph
*glyph
;
12286 struct glyph_row
*row
;
12288 Lisp_Object enabled_p
;
12290 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12291 int mouse_down_p
, rc
;
12293 /* Function note_mouse_highlight is called with negative X/Y
12294 values when mouse moves outside of the frame. */
12295 if (x
<= 0 || y
<= 0)
12297 clear_mouse_face (hlinfo
);
12301 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12304 /* Not on tool-bar item. */
12305 clear_mouse_face (hlinfo
);
12309 /* On same tool-bar item as before. */
12310 goto set_help_echo
;
12312 clear_mouse_face (hlinfo
);
12314 /* Mouse is down, but on different tool-bar item? */
12315 mouse_down_p
= (dpyinfo
->grabbed
12316 && f
== last_mouse_frame
12317 && FRAME_LIVE_P (f
));
12319 && last_tool_bar_item
!= prop_idx
)
12322 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12324 /* If tool-bar item is not enabled, don't highlight it. */
12325 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12326 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12328 /* Compute the x-position of the glyph. In front and past the
12329 image is a space. We include this in the highlighted area. */
12330 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12331 for (i
= x
= 0; i
< hpos
; ++i
)
12332 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12334 /* Record this as the current active region. */
12335 hlinfo
->mouse_face_beg_col
= hpos
;
12336 hlinfo
->mouse_face_beg_row
= vpos
;
12337 hlinfo
->mouse_face_beg_x
= x
;
12338 hlinfo
->mouse_face_past_end
= 0;
12340 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12341 hlinfo
->mouse_face_end_row
= vpos
;
12342 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12343 hlinfo
->mouse_face_window
= window
;
12344 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12346 /* Display it as active. */
12347 show_mouse_face (hlinfo
, draw
);
12352 /* Set help_echo_string to a help string to display for this tool-bar item.
12353 XTread_socket does the rest. */
12354 help_echo_object
= help_echo_window
= Qnil
;
12355 help_echo_pos
= -1;
12356 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12357 if (NILP (help_echo_string
))
12358 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12361 #endif /* HAVE_WINDOW_SYSTEM */
12365 /************************************************************************
12366 Horizontal scrolling
12367 ************************************************************************/
12369 static int hscroll_window_tree (Lisp_Object
);
12370 static int hscroll_windows (Lisp_Object
);
12372 /* For all leaf windows in the window tree rooted at WINDOW, set their
12373 hscroll value so that PT is (i) visible in the window, and (ii) so
12374 that it is not within a certain margin at the window's left and
12375 right border. Value is non-zero if any window's hscroll has been
12379 hscroll_window_tree (Lisp_Object window
)
12381 int hscrolled_p
= 0;
12382 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12383 int hscroll_step_abs
= 0;
12384 double hscroll_step_rel
= 0;
12386 if (hscroll_relative_p
)
12388 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12389 if (hscroll_step_rel
< 0)
12391 hscroll_relative_p
= 0;
12392 hscroll_step_abs
= 0;
12395 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12397 hscroll_step_abs
= XINT (Vhscroll_step
);
12398 if (hscroll_step_abs
< 0)
12399 hscroll_step_abs
= 0;
12402 hscroll_step_abs
= 0;
12404 while (WINDOWP (window
))
12406 struct window
*w
= XWINDOW (window
);
12408 if (WINDOWP (w
->contents
))
12409 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12410 else if (w
->cursor
.vpos
>= 0)
12413 int text_area_width
;
12414 struct glyph_row
*current_cursor_row
12415 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12416 struct glyph_row
*desired_cursor_row
12417 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12418 struct glyph_row
*cursor_row
12419 = (desired_cursor_row
->enabled_p
12420 ? desired_cursor_row
12421 : current_cursor_row
);
12422 int row_r2l_p
= cursor_row
->reversed_p
;
12424 text_area_width
= window_box_width (w
, TEXT_AREA
);
12426 /* Scroll when cursor is inside this scroll margin. */
12427 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12429 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12430 /* For left-to-right rows, hscroll when cursor is either
12431 (i) inside the right hscroll margin, or (ii) if it is
12432 inside the left margin and the window is already
12436 && w
->cursor
.x
<= h_margin
)
12437 || (cursor_row
->enabled_p
12438 && cursor_row
->truncated_on_right_p
12439 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12440 /* For right-to-left rows, the logic is similar,
12441 except that rules for scrolling to left and right
12442 are reversed. E.g., if cursor.x <= h_margin, we
12443 need to hscroll "to the right" unconditionally,
12444 and that will scroll the screen to the left so as
12445 to reveal the next portion of the row. */
12447 && ((cursor_row
->enabled_p
12448 /* FIXME: It is confusing to set the
12449 truncated_on_right_p flag when R2L rows
12450 are actually truncated on the left. */
12451 && cursor_row
->truncated_on_right_p
12452 && w
->cursor
.x
<= h_margin
)
12454 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12458 struct buffer
*saved_current_buffer
;
12462 /* Find point in a display of infinite width. */
12463 saved_current_buffer
= current_buffer
;
12464 current_buffer
= XBUFFER (w
->contents
);
12466 if (w
== XWINDOW (selected_window
))
12469 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12471 /* Move iterator to pt starting at cursor_row->start in
12472 a line with infinite width. */
12473 init_to_row_start (&it
, w
, cursor_row
);
12474 it
.last_visible_x
= INFINITY
;
12475 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12476 current_buffer
= saved_current_buffer
;
12478 /* Position cursor in window. */
12479 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12480 hscroll
= max (0, (it
.current_x
12481 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12482 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12483 : (text_area_width
/ 2))))
12484 / FRAME_COLUMN_WIDTH (it
.f
);
12485 else if ((!row_r2l_p
12486 && w
->cursor
.x
>= text_area_width
- h_margin
)
12487 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12489 if (hscroll_relative_p
)
12490 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12493 wanted_x
= text_area_width
12494 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12497 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12501 if (hscroll_relative_p
)
12502 wanted_x
= text_area_width
* hscroll_step_rel
12505 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12508 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12510 hscroll
= max (hscroll
, w
->min_hscroll
);
12512 /* Don't prevent redisplay optimizations if hscroll
12513 hasn't changed, as it will unnecessarily slow down
12515 if (w
->hscroll
!= hscroll
)
12517 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12518 w
->hscroll
= hscroll
;
12527 /* Value is non-zero if hscroll of any leaf window has been changed. */
12528 return hscrolled_p
;
12532 /* Set hscroll so that cursor is visible and not inside horizontal
12533 scroll margins for all windows in the tree rooted at WINDOW. See
12534 also hscroll_window_tree above. Value is non-zero if any window's
12535 hscroll has been changed. If it has, desired matrices on the frame
12536 of WINDOW are cleared. */
12539 hscroll_windows (Lisp_Object window
)
12541 int hscrolled_p
= hscroll_window_tree (window
);
12543 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12544 return hscrolled_p
;
12549 /************************************************************************
12551 ************************************************************************/
12553 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12554 to a non-zero value. This is sometimes handy to have in a debugger
12559 /* First and last unchanged row for try_window_id. */
12561 static int debug_first_unchanged_at_end_vpos
;
12562 static int debug_last_unchanged_at_beg_vpos
;
12564 /* Delta vpos and y. */
12566 static int debug_dvpos
, debug_dy
;
12568 /* Delta in characters and bytes for try_window_id. */
12570 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12572 /* Values of window_end_pos and window_end_vpos at the end of
12575 static ptrdiff_t debug_end_vpos
;
12577 /* Append a string to W->desired_matrix->method. FMT is a printf
12578 format string. If trace_redisplay_p is non-zero also printf the
12579 resulting string to stderr. */
12581 static void debug_method_add (struct window
*, char const *, ...)
12582 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12585 debug_method_add (struct window
*w
, char const *fmt
, ...)
12588 char *method
= w
->desired_matrix
->method
;
12589 int len
= strlen (method
);
12590 int size
= sizeof w
->desired_matrix
->method
;
12591 int remaining
= size
- len
- 1;
12594 if (len
&& remaining
)
12597 --remaining
, ++len
;
12600 va_start (ap
, fmt
);
12601 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12604 if (trace_redisplay_p
)
12605 fprintf (stderr
, "%p (%s): %s\n",
12607 ((BUFFERP (w
->contents
)
12608 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12609 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12614 #endif /* GLYPH_DEBUG */
12617 /* Value is non-zero if all changes in window W, which displays
12618 current_buffer, are in the text between START and END. START is a
12619 buffer position, END is given as a distance from Z. Used in
12620 redisplay_internal for display optimization. */
12623 text_outside_line_unchanged_p (struct window
*w
,
12624 ptrdiff_t start
, ptrdiff_t end
)
12626 int unchanged_p
= 1;
12628 /* If text or overlays have changed, see where. */
12629 if (window_outdated (w
))
12631 /* Gap in the line? */
12632 if (GPT
< start
|| Z
- GPT
< end
)
12635 /* Changes start in front of the line, or end after it? */
12637 && (BEG_UNCHANGED
< start
- 1
12638 || END_UNCHANGED
< end
))
12641 /* If selective display, can't optimize if changes start at the
12642 beginning of the line. */
12644 && INTEGERP (BVAR (current_buffer
, selective_display
))
12645 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12646 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12649 /* If there are overlays at the start or end of the line, these
12650 may have overlay strings with newlines in them. A change at
12651 START, for instance, may actually concern the display of such
12652 overlay strings as well, and they are displayed on different
12653 lines. So, quickly rule out this case. (For the future, it
12654 might be desirable to implement something more telling than
12655 just BEG/END_UNCHANGED.) */
12658 if (BEG
+ BEG_UNCHANGED
== start
12659 && overlay_touches_p (start
))
12661 if (END_UNCHANGED
== end
12662 && overlay_touches_p (Z
- end
))
12666 /* Under bidi reordering, adding or deleting a character in the
12667 beginning of a paragraph, before the first strong directional
12668 character, can change the base direction of the paragraph (unless
12669 the buffer specifies a fixed paragraph direction), which will
12670 require to redisplay the whole paragraph. It might be worthwhile
12671 to find the paragraph limits and widen the range of redisplayed
12672 lines to that, but for now just give up this optimization. */
12673 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12674 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12678 return unchanged_p
;
12682 /* Do a frame update, taking possible shortcuts into account. This is
12683 the main external entry point for redisplay.
12685 If the last redisplay displayed an echo area message and that message
12686 is no longer requested, we clear the echo area or bring back the
12687 mini-buffer if that is in use. */
12692 redisplay_internal ();
12697 overlay_arrow_string_or_property (Lisp_Object var
)
12701 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12704 return Voverlay_arrow_string
;
12707 /* Return 1 if there are any overlay-arrows in current_buffer. */
12709 overlay_arrow_in_current_buffer_p (void)
12713 for (vlist
= Voverlay_arrow_variable_list
;
12715 vlist
= XCDR (vlist
))
12717 Lisp_Object var
= XCAR (vlist
);
12720 if (!SYMBOLP (var
))
12722 val
= find_symbol_value (var
);
12724 && current_buffer
== XMARKER (val
)->buffer
)
12731 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12735 overlay_arrows_changed_p (void)
12739 for (vlist
= Voverlay_arrow_variable_list
;
12741 vlist
= XCDR (vlist
))
12743 Lisp_Object var
= XCAR (vlist
);
12744 Lisp_Object val
, pstr
;
12746 if (!SYMBOLP (var
))
12748 val
= find_symbol_value (var
);
12749 if (!MARKERP (val
))
12751 if (! EQ (COERCE_MARKER (val
),
12752 Fget (var
, Qlast_arrow_position
))
12753 || ! (pstr
= overlay_arrow_string_or_property (var
),
12754 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12760 /* Mark overlay arrows to be updated on next redisplay. */
12763 update_overlay_arrows (int up_to_date
)
12767 for (vlist
= Voverlay_arrow_variable_list
;
12769 vlist
= XCDR (vlist
))
12771 Lisp_Object var
= XCAR (vlist
);
12773 if (!SYMBOLP (var
))
12776 if (up_to_date
> 0)
12778 Lisp_Object val
= find_symbol_value (var
);
12779 Fput (var
, Qlast_arrow_position
,
12780 COERCE_MARKER (val
));
12781 Fput (var
, Qlast_arrow_string
,
12782 overlay_arrow_string_or_property (var
));
12784 else if (up_to_date
< 0
12785 || !NILP (Fget (var
, Qlast_arrow_position
)))
12787 Fput (var
, Qlast_arrow_position
, Qt
);
12788 Fput (var
, Qlast_arrow_string
, Qt
);
12794 /* Return overlay arrow string to display at row.
12795 Return integer (bitmap number) for arrow bitmap in left fringe.
12796 Return nil if no overlay arrow. */
12799 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12803 for (vlist
= Voverlay_arrow_variable_list
;
12805 vlist
= XCDR (vlist
))
12807 Lisp_Object var
= XCAR (vlist
);
12810 if (!SYMBOLP (var
))
12813 val
= find_symbol_value (var
);
12816 && current_buffer
== XMARKER (val
)->buffer
12817 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12819 if (FRAME_WINDOW_P (it
->f
)
12820 /* FIXME: if ROW->reversed_p is set, this should test
12821 the right fringe, not the left one. */
12822 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12824 #ifdef HAVE_WINDOW_SYSTEM
12825 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12828 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12829 return make_number (fringe_bitmap
);
12832 return make_number (-1); /* Use default arrow bitmap. */
12834 return overlay_arrow_string_or_property (var
);
12841 /* Return 1 if point moved out of or into a composition. Otherwise
12842 return 0. PREV_BUF and PREV_PT are the last point buffer and
12843 position. BUF and PT are the current point buffer and position. */
12846 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12847 struct buffer
*buf
, ptrdiff_t pt
)
12849 ptrdiff_t start
, end
;
12851 Lisp_Object buffer
;
12853 XSETBUFFER (buffer
, buf
);
12854 /* Check a composition at the last point if point moved within the
12856 if (prev_buf
== buf
)
12859 /* Point didn't move. */
12862 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12863 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12864 && composition_valid_p (start
, end
, prop
)
12865 && start
< prev_pt
&& end
> prev_pt
)
12866 /* The last point was within the composition. Return 1 iff
12867 point moved out of the composition. */
12868 return (pt
<= start
|| pt
>= end
);
12871 /* Check a composition at the current point. */
12872 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12873 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12874 && composition_valid_p (start
, end
, prop
)
12875 && start
< pt
&& end
> pt
);
12878 /* Reconsider the clip changes of buffer which is displayed in W. */
12881 reconsider_clip_changes (struct window
*w
)
12883 struct buffer
*b
= XBUFFER (w
->contents
);
12885 if (b
->clip_changed
12886 && w
->window_end_valid
12887 && w
->current_matrix
->buffer
== b
12888 && w
->current_matrix
->zv
== BUF_ZV (b
)
12889 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12890 b
->clip_changed
= 0;
12892 /* If display wasn't paused, and W is not a tool bar window, see if
12893 point has been moved into or out of a composition. In that case,
12894 we set b->clip_changed to 1 to force updating the screen. If
12895 b->clip_changed has already been set to 1, we can skip this
12897 if (!b
->clip_changed
&& w
->window_end_valid
)
12899 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12900 ? PT
: marker_position (w
->pointm
));
12902 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12903 && check_point_in_composition (w
->current_matrix
->buffer
,
12904 w
->last_point
, b
, pt
))
12905 b
->clip_changed
= 1;
12909 #define STOP_POLLING \
12910 do { if (! polling_stopped_here) stop_polling (); \
12911 polling_stopped_here = 1; } while (0)
12913 #define RESUME_POLLING \
12914 do { if (polling_stopped_here) start_polling (); \
12915 polling_stopped_here = 0; } while (0)
12918 /* Perhaps in the future avoid recentering windows if it
12919 is not necessary; currently that causes some problems. */
12922 redisplay_internal (void)
12924 struct window
*w
= XWINDOW (selected_window
);
12928 bool must_finish
= 0, match_p
;
12929 struct text_pos tlbufpos
, tlendpos
;
12930 int number_of_visible_frames
;
12933 int polling_stopped_here
= 0;
12934 Lisp_Object tail
, frame
;
12936 /* Non-zero means redisplay has to consider all windows on all
12937 frames. Zero means, only selected_window is considered. */
12938 int consider_all_windows_p
;
12940 /* Non-zero means redisplay has to redisplay the miniwindow. */
12941 int update_miniwindow_p
= 0;
12943 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12945 /* No redisplay if running in batch mode or frame is not yet fully
12946 initialized, or redisplay is explicitly turned off by setting
12947 Vinhibit_redisplay. */
12948 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12949 || !NILP (Vinhibit_redisplay
))
12952 /* Don't examine these until after testing Vinhibit_redisplay.
12953 When Emacs is shutting down, perhaps because its connection to
12954 X has dropped, we should not look at them at all. */
12955 fr
= XFRAME (w
->frame
);
12956 sf
= SELECTED_FRAME ();
12958 if (!fr
->glyphs_initialized_p
)
12961 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12962 if (popup_activated ())
12966 /* I don't think this happens but let's be paranoid. */
12967 if (redisplaying_p
)
12970 /* Record a function that clears redisplaying_p
12971 when we leave this function. */
12972 count
= SPECPDL_INDEX ();
12973 record_unwind_protect_void (unwind_redisplay
);
12974 redisplaying_p
= 1;
12975 specbind (Qinhibit_free_realized_faces
, Qnil
);
12977 /* Record this function, so it appears on the profiler's backtraces. */
12978 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
12980 FOR_EACH_FRAME (tail
, frame
)
12981 XFRAME (frame
)->already_hscrolled_p
= 0;
12984 /* Remember the currently selected window. */
12988 last_escape_glyph_frame
= NULL
;
12989 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12990 last_glyphless_glyph_frame
= NULL
;
12991 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12993 /* If new fonts have been loaded that make a glyph matrix adjustment
12994 necessary, do it. */
12995 if (fonts_changed_p
)
12997 adjust_glyphs (NULL
);
12998 ++windows_or_buffers_changed
;
12999 fonts_changed_p
= 0;
13002 /* If face_change_count is non-zero, init_iterator will free all
13003 realized faces, which includes the faces referenced from current
13004 matrices. So, we can't reuse current matrices in this case. */
13005 if (face_change_count
)
13006 ++windows_or_buffers_changed
;
13008 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13009 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13011 /* Since frames on a single ASCII terminal share the same
13012 display area, displaying a different frame means redisplay
13013 the whole thing. */
13014 windows_or_buffers_changed
++;
13015 SET_FRAME_GARBAGED (sf
);
13017 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13019 FRAME_TTY (sf
)->previous_frame
= sf
;
13022 /* Set the visible flags for all frames. Do this before checking for
13023 resized or garbaged frames; they want to know if their frames are
13024 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13025 number_of_visible_frames
= 0;
13027 FOR_EACH_FRAME (tail
, frame
)
13029 struct frame
*f
= XFRAME (frame
);
13031 if (FRAME_VISIBLE_P (f
))
13032 ++number_of_visible_frames
;
13033 clear_desired_matrices (f
);
13036 /* Notice any pending interrupt request to change frame size. */
13037 do_pending_window_change (1);
13039 /* do_pending_window_change could change the selected_window due to
13040 frame resizing which makes the selected window too small. */
13041 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13044 /* Clear frames marked as garbaged. */
13045 clear_garbaged_frames ();
13047 /* Build menubar and tool-bar items. */
13048 if (NILP (Vmemory_full
))
13049 prepare_menu_bars ();
13051 if (windows_or_buffers_changed
)
13052 update_mode_lines
++;
13054 reconsider_clip_changes (w
);
13056 /* In most cases selected window displays current buffer. */
13057 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13062 /* Detect case that we need to write or remove a star in the mode line. */
13063 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13065 w
->update_mode_line
= 1;
13066 if (buffer_shared_and_changed ())
13067 update_mode_lines
++;
13070 /* Avoid invocation of point motion hooks by `current_column' below. */
13071 count1
= SPECPDL_INDEX ();
13072 specbind (Qinhibit_point_motion_hooks
, Qt
);
13074 if (mode_line_update_needed (w
))
13075 w
->update_mode_line
= 1;
13077 unbind_to (count1
, Qnil
);
13080 consider_all_windows_p
= (update_mode_lines
13081 || buffer_shared_and_changed ()
13082 || cursor_type_changed
);
13084 /* If specs for an arrow have changed, do thorough redisplay
13085 to ensure we remove any arrow that should no longer exist. */
13086 if (overlay_arrows_changed_p ())
13087 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13089 /* Normally the message* functions will have already displayed and
13090 updated the echo area, but the frame may have been trashed, or
13091 the update may have been preempted, so display the echo area
13092 again here. Checking message_cleared_p captures the case that
13093 the echo area should be cleared. */
13094 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13095 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13096 || (message_cleared_p
13097 && minibuf_level
== 0
13098 /* If the mini-window is currently selected, this means the
13099 echo-area doesn't show through. */
13100 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13102 int window_height_changed_p
= echo_area_display (0);
13104 if (message_cleared_p
)
13105 update_miniwindow_p
= 1;
13109 /* If we don't display the current message, don't clear the
13110 message_cleared_p flag, because, if we did, we wouldn't clear
13111 the echo area in the next redisplay which doesn't preserve
13113 if (!display_last_displayed_message_p
)
13114 message_cleared_p
= 0;
13116 if (fonts_changed_p
)
13118 else if (window_height_changed_p
)
13120 consider_all_windows_p
= 1;
13121 ++update_mode_lines
;
13122 ++windows_or_buffers_changed
;
13124 /* If window configuration was changed, frames may have been
13125 marked garbaged. Clear them or we will experience
13126 surprises wrt scrolling. */
13127 clear_garbaged_frames ();
13130 else if (EQ (selected_window
, minibuf_window
)
13131 && (current_buffer
->clip_changed
|| window_outdated (w
))
13132 && resize_mini_window (w
, 0))
13134 /* Resized active mini-window to fit the size of what it is
13135 showing if its contents might have changed. */
13137 /* FIXME: this causes all frames to be updated, which seems unnecessary
13138 since only the current frame needs to be considered. This function
13139 needs to be rewritten with two variables, consider_all_windows and
13140 consider_all_frames. */
13141 consider_all_windows_p
= 1;
13142 ++windows_or_buffers_changed
;
13143 ++update_mode_lines
;
13145 /* If window configuration was changed, frames may have been
13146 marked garbaged. Clear them or we will experience
13147 surprises wrt scrolling. */
13148 clear_garbaged_frames ();
13151 /* If showing the region, and mark has changed, we must redisplay
13152 the whole window. The assignment to this_line_start_pos prevents
13153 the optimization directly below this if-statement. */
13154 if (((!NILP (Vtransient_mark_mode
)
13155 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13156 != (w
->region_showing
> 0))
13157 || (w
->region_showing
13158 && w
->region_showing
13159 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13160 CHARPOS (this_line_start_pos
) = 0;
13162 /* Optimize the case that only the line containing the cursor in the
13163 selected window has changed. Variables starting with this_ are
13164 set in display_line and record information about the line
13165 containing the cursor. */
13166 tlbufpos
= this_line_start_pos
;
13167 tlendpos
= this_line_end_pos
;
13168 if (!consider_all_windows_p
13169 && CHARPOS (tlbufpos
) > 0
13170 && !w
->update_mode_line
13171 && !current_buffer
->clip_changed
13172 && !current_buffer
->prevent_redisplay_optimizations_p
13173 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13174 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13175 /* Make sure recorded data applies to current buffer, etc. */
13176 && this_line_buffer
== current_buffer
13179 && !w
->optional_new_start
13180 /* Point must be on the line that we have info recorded about. */
13181 && PT
>= CHARPOS (tlbufpos
)
13182 && PT
<= Z
- CHARPOS (tlendpos
)
13183 /* All text outside that line, including its final newline,
13184 must be unchanged. */
13185 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13186 CHARPOS (tlendpos
)))
13188 if (CHARPOS (tlbufpos
) > BEGV
13189 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13190 && (CHARPOS (tlbufpos
) == ZV
13191 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13192 /* Former continuation line has disappeared by becoming empty. */
13194 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13196 /* We have to handle the case of continuation around a
13197 wide-column character (see the comment in indent.c around
13200 For instance, in the following case:
13202 -------- Insert --------
13203 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13204 J_I_ ==> J_I_ `^^' are cursors.
13208 As we have to redraw the line above, we cannot use this
13212 int line_height_before
= this_line_pixel_height
;
13214 /* Note that start_display will handle the case that the
13215 line starting at tlbufpos is a continuation line. */
13216 start_display (&it
, w
, tlbufpos
);
13218 /* Implementation note: It this still necessary? */
13219 if (it
.current_x
!= this_line_start_x
)
13222 TRACE ((stderr
, "trying display optimization 1\n"));
13223 w
->cursor
.vpos
= -1;
13224 overlay_arrow_seen
= 0;
13225 it
.vpos
= this_line_vpos
;
13226 it
.current_y
= this_line_y
;
13227 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13228 display_line (&it
);
13230 /* If line contains point, is not continued,
13231 and ends at same distance from eob as before, we win. */
13232 if (w
->cursor
.vpos
>= 0
13233 /* Line is not continued, otherwise this_line_start_pos
13234 would have been set to 0 in display_line. */
13235 && CHARPOS (this_line_start_pos
)
13236 /* Line ends as before. */
13237 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13238 /* Line has same height as before. Otherwise other lines
13239 would have to be shifted up or down. */
13240 && this_line_pixel_height
== line_height_before
)
13242 /* If this is not the window's last line, we must adjust
13243 the charstarts of the lines below. */
13244 if (it
.current_y
< it
.last_visible_y
)
13246 struct glyph_row
*row
13247 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13248 ptrdiff_t delta
, delta_bytes
;
13250 /* We used to distinguish between two cases here,
13251 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13252 when the line ends in a newline or the end of the
13253 buffer's accessible portion. But both cases did
13254 the same, so they were collapsed. */
13256 - CHARPOS (tlendpos
)
13257 - MATRIX_ROW_START_CHARPOS (row
));
13258 delta_bytes
= (Z_BYTE
13259 - BYTEPOS (tlendpos
)
13260 - MATRIX_ROW_START_BYTEPOS (row
));
13262 increment_matrix_positions (w
->current_matrix
,
13263 this_line_vpos
+ 1,
13264 w
->current_matrix
->nrows
,
13265 delta
, delta_bytes
);
13268 /* If this row displays text now but previously didn't,
13269 or vice versa, w->window_end_vpos may have to be
13271 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13273 if (w
->window_end_vpos
< this_line_vpos
)
13274 w
->window_end_vpos
= this_line_vpos
;
13276 else if (w
->window_end_vpos
== this_line_vpos
13277 && this_line_vpos
> 0)
13278 w
->window_end_vpos
= this_line_vpos
- 1;
13279 w
->window_end_valid
= 0;
13281 /* Update hint: No need to try to scroll in update_window. */
13282 w
->desired_matrix
->no_scrolling_p
= 1;
13285 *w
->desired_matrix
->method
= 0;
13286 debug_method_add (w
, "optimization 1");
13288 #ifdef HAVE_WINDOW_SYSTEM
13289 update_window_fringes (w
, 0);
13296 else if (/* Cursor position hasn't changed. */
13297 PT
== w
->last_point
13298 /* Make sure the cursor was last displayed
13299 in this window. Otherwise we have to reposition it. */
13300 && 0 <= w
->cursor
.vpos
13301 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13305 do_pending_window_change (1);
13306 /* If selected_window changed, redisplay again. */
13307 if (WINDOWP (selected_window
)
13308 && (w
= XWINDOW (selected_window
)) != sw
)
13311 /* We used to always goto end_of_redisplay here, but this
13312 isn't enough if we have a blinking cursor. */
13313 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13314 goto end_of_redisplay
;
13318 /* If highlighting the region, or if the cursor is in the echo area,
13319 then we can't just move the cursor. */
13320 else if (! (!NILP (Vtransient_mark_mode
)
13321 && !NILP (BVAR (current_buffer
, mark_active
)))
13322 && (EQ (selected_window
,
13323 BVAR (current_buffer
, last_selected_window
))
13324 || highlight_nonselected_windows
)
13325 && !w
->region_showing
13326 && NILP (Vshow_trailing_whitespace
)
13327 && !cursor_in_echo_area
)
13330 struct glyph_row
*row
;
13332 /* Skip from tlbufpos to PT and see where it is. Note that
13333 PT may be in invisible text. If so, we will end at the
13334 next visible position. */
13335 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13336 NULL
, DEFAULT_FACE_ID
);
13337 it
.current_x
= this_line_start_x
;
13338 it
.current_y
= this_line_y
;
13339 it
.vpos
= this_line_vpos
;
13341 /* The call to move_it_to stops in front of PT, but
13342 moves over before-strings. */
13343 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13345 if (it
.vpos
== this_line_vpos
13346 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13349 eassert (this_line_vpos
== it
.vpos
);
13350 eassert (this_line_y
== it
.current_y
);
13351 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13353 *w
->desired_matrix
->method
= 0;
13354 debug_method_add (w
, "optimization 3");
13363 /* Text changed drastically or point moved off of line. */
13364 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13367 CHARPOS (this_line_start_pos
) = 0;
13368 consider_all_windows_p
|= buffer_shared_and_changed ();
13369 ++clear_face_cache_count
;
13370 #ifdef HAVE_WINDOW_SYSTEM
13371 ++clear_image_cache_count
;
13374 /* Build desired matrices, and update the display. If
13375 consider_all_windows_p is non-zero, do it for all windows on all
13376 frames. Otherwise do it for selected_window, only. */
13378 if (consider_all_windows_p
)
13380 FOR_EACH_FRAME (tail
, frame
)
13381 XFRAME (frame
)->updated_p
= 0;
13383 FOR_EACH_FRAME (tail
, frame
)
13385 struct frame
*f
= XFRAME (frame
);
13387 /* We don't have to do anything for unselected terminal
13389 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13390 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13393 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13395 /* Mark all the scroll bars to be removed; we'll redeem
13396 the ones we want when we redisplay their windows. */
13397 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13398 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13400 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13401 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13403 /* The X error handler may have deleted that frame. */
13404 if (!FRAME_LIVE_P (f
))
13407 /* Any scroll bars which redisplay_windows should have
13408 nuked should now go away. */
13409 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13410 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13412 /* If fonts changed, display again. */
13413 /* ??? rms: I suspect it is a mistake to jump all the way
13414 back to retry here. It should just retry this frame. */
13415 if (fonts_changed_p
)
13418 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13420 /* See if we have to hscroll. */
13421 if (!f
->already_hscrolled_p
)
13423 f
->already_hscrolled_p
= 1;
13424 if (hscroll_windows (f
->root_window
))
13428 /* Prevent various kinds of signals during display
13429 update. stdio is not robust about handling
13430 signals, which can cause an apparent I/O
13432 if (interrupt_input
)
13433 unrequest_sigio ();
13436 /* Update the display. */
13437 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13438 pending
|= update_frame (f
, 0, 0);
13444 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13448 /* Do the mark_window_display_accurate after all windows have
13449 been redisplayed because this call resets flags in buffers
13450 which are needed for proper redisplay. */
13451 FOR_EACH_FRAME (tail
, frame
)
13453 struct frame
*f
= XFRAME (frame
);
13456 mark_window_display_accurate (f
->root_window
, 1);
13457 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13458 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13463 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13465 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13466 struct frame
*mini_frame
;
13468 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13469 /* Use list_of_error, not Qerror, so that
13470 we catch only errors and don't run the debugger. */
13471 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13473 redisplay_window_error
);
13474 if (update_miniwindow_p
)
13475 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13477 redisplay_window_error
);
13479 /* Compare desired and current matrices, perform output. */
13482 /* If fonts changed, display again. */
13483 if (fonts_changed_p
)
13486 /* Prevent various kinds of signals during display update.
13487 stdio is not robust about handling signals,
13488 which can cause an apparent I/O error. */
13489 if (interrupt_input
)
13490 unrequest_sigio ();
13493 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13495 if (hscroll_windows (selected_window
))
13498 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13499 pending
= update_frame (sf
, 0, 0);
13502 /* We may have called echo_area_display at the top of this
13503 function. If the echo area is on another frame, that may
13504 have put text on a frame other than the selected one, so the
13505 above call to update_frame would not have caught it. Catch
13507 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13508 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13510 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13512 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13513 pending
|= update_frame (mini_frame
, 0, 0);
13514 if (!pending
&& hscroll_windows (mini_window
))
13519 /* If display was paused because of pending input, make sure we do a
13520 thorough update the next time. */
13523 /* Prevent the optimization at the beginning of
13524 redisplay_internal that tries a single-line update of the
13525 line containing the cursor in the selected window. */
13526 CHARPOS (this_line_start_pos
) = 0;
13528 /* Let the overlay arrow be updated the next time. */
13529 update_overlay_arrows (0);
13531 /* If we pause after scrolling, some rows in the current
13532 matrices of some windows are not valid. */
13533 if (!WINDOW_FULL_WIDTH_P (w
)
13534 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13535 update_mode_lines
= 1;
13539 if (!consider_all_windows_p
)
13541 /* This has already been done above if
13542 consider_all_windows_p is set. */
13543 mark_window_display_accurate_1 (w
, 1);
13545 /* Say overlay arrows are up to date. */
13546 update_overlay_arrows (1);
13548 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13549 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13552 update_mode_lines
= 0;
13553 windows_or_buffers_changed
= 0;
13554 cursor_type_changed
= 0;
13557 /* Start SIGIO interrupts coming again. Having them off during the
13558 code above makes it less likely one will discard output, but not
13559 impossible, since there might be stuff in the system buffer here.
13560 But it is much hairier to try to do anything about that. */
13561 if (interrupt_input
)
13565 /* If a frame has become visible which was not before, redisplay
13566 again, so that we display it. Expose events for such a frame
13567 (which it gets when becoming visible) don't call the parts of
13568 redisplay constructing glyphs, so simply exposing a frame won't
13569 display anything in this case. So, we have to display these
13570 frames here explicitly. */
13575 FOR_EACH_FRAME (tail
, frame
)
13577 int this_is_visible
= 0;
13579 if (XFRAME (frame
)->visible
)
13580 this_is_visible
= 1;
13582 if (this_is_visible
)
13586 if (new_count
!= number_of_visible_frames
)
13587 windows_or_buffers_changed
++;
13590 /* Change frame size now if a change is pending. */
13591 do_pending_window_change (1);
13593 /* If we just did a pending size change, or have additional
13594 visible frames, or selected_window changed, redisplay again. */
13595 if ((windows_or_buffers_changed
&& !pending
)
13596 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13599 /* Clear the face and image caches.
13601 We used to do this only if consider_all_windows_p. But the cache
13602 needs to be cleared if a timer creates images in the current
13603 buffer (e.g. the test case in Bug#6230). */
13605 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13607 clear_face_cache (0);
13608 clear_face_cache_count
= 0;
13611 #ifdef HAVE_WINDOW_SYSTEM
13612 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13614 clear_image_caches (Qnil
);
13615 clear_image_cache_count
= 0;
13617 #endif /* HAVE_WINDOW_SYSTEM */
13620 unbind_to (count
, Qnil
);
13625 /* Redisplay, but leave alone any recent echo area message unless
13626 another message has been requested in its place.
13628 This is useful in situations where you need to redisplay but no
13629 user action has occurred, making it inappropriate for the message
13630 area to be cleared. See tracking_off and
13631 wait_reading_process_output for examples of these situations.
13633 FROM_WHERE is an integer saying from where this function was
13634 called. This is useful for debugging. */
13637 redisplay_preserve_echo_area (int from_where
)
13639 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13641 if (!NILP (echo_area_buffer
[1]))
13643 /* We have a previously displayed message, but no current
13644 message. Redisplay the previous message. */
13645 display_last_displayed_message_p
= 1;
13646 redisplay_internal ();
13647 display_last_displayed_message_p
= 0;
13650 redisplay_internal ();
13652 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13653 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13654 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13658 /* Function registered with record_unwind_protect in redisplay_internal. */
13661 unwind_redisplay (void)
13663 redisplaying_p
= 0;
13667 /* Mark the display of leaf window W as accurate or inaccurate.
13668 If ACCURATE_P is non-zero mark display of W as accurate. If
13669 ACCURATE_P is zero, arrange for W to be redisplayed the next
13670 time redisplay_internal is called. */
13673 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13675 struct buffer
*b
= XBUFFER (w
->contents
);
13677 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13678 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13679 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13683 b
->clip_changed
= 0;
13684 b
->prevent_redisplay_optimizations_p
= 0;
13686 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13687 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13688 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13689 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13691 w
->current_matrix
->buffer
= b
;
13692 w
->current_matrix
->begv
= BUF_BEGV (b
);
13693 w
->current_matrix
->zv
= BUF_ZV (b
);
13695 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13696 w
->last_cursor_off_p
= w
->cursor_off_p
;
13698 if (w
== XWINDOW (selected_window
))
13699 w
->last_point
= BUF_PT (b
);
13701 w
->last_point
= marker_position (w
->pointm
);
13703 w
->window_end_valid
= 1;
13704 w
->update_mode_line
= 0;
13709 /* Mark the display of windows in the window tree rooted at WINDOW as
13710 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13711 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13712 be redisplayed the next time redisplay_internal is called. */
13715 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13719 for (; !NILP (window
); window
= w
->next
)
13721 w
= XWINDOW (window
);
13722 if (WINDOWP (w
->contents
))
13723 mark_window_display_accurate (w
->contents
, accurate_p
);
13725 mark_window_display_accurate_1 (w
, accurate_p
);
13729 update_overlay_arrows (1);
13731 /* Force a thorough redisplay the next time by setting
13732 last_arrow_position and last_arrow_string to t, which is
13733 unequal to any useful value of Voverlay_arrow_... */
13734 update_overlay_arrows (-1);
13738 /* Return value in display table DP (Lisp_Char_Table *) for character
13739 C. Since a display table doesn't have any parent, we don't have to
13740 follow parent. Do not call this function directly but use the
13741 macro DISP_CHAR_VECTOR. */
13744 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13748 if (ASCII_CHAR_P (c
))
13751 if (SUB_CHAR_TABLE_P (val
))
13752 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13758 XSETCHAR_TABLE (table
, dp
);
13759 val
= char_table_ref (table
, c
);
13768 /***********************************************************************
13770 ***********************************************************************/
13772 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13775 redisplay_windows (Lisp_Object window
)
13777 while (!NILP (window
))
13779 struct window
*w
= XWINDOW (window
);
13781 if (WINDOWP (w
->contents
))
13782 redisplay_windows (w
->contents
);
13783 else if (BUFFERP (w
->contents
))
13785 displayed_buffer
= XBUFFER (w
->contents
);
13786 /* Use list_of_error, not Qerror, so that
13787 we catch only errors and don't run the debugger. */
13788 internal_condition_case_1 (redisplay_window_0
, window
,
13790 redisplay_window_error
);
13798 redisplay_window_error (Lisp_Object ignore
)
13800 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13805 redisplay_window_0 (Lisp_Object window
)
13807 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13808 redisplay_window (window
, 0);
13813 redisplay_window_1 (Lisp_Object window
)
13815 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13816 redisplay_window (window
, 1);
13821 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13822 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13823 which positions recorded in ROW differ from current buffer
13826 Return 0 if cursor is not on this row, 1 otherwise. */
13829 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13830 struct glyph_matrix
*matrix
,
13831 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13834 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13835 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13836 struct glyph
*cursor
= NULL
;
13837 /* The last known character position in row. */
13838 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13840 ptrdiff_t pt_old
= PT
- delta
;
13841 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13842 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13843 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13844 /* A glyph beyond the edge of TEXT_AREA which we should never
13846 struct glyph
*glyphs_end
= end
;
13847 /* Non-zero means we've found a match for cursor position, but that
13848 glyph has the avoid_cursor_p flag set. */
13849 int match_with_avoid_cursor
= 0;
13850 /* Non-zero means we've seen at least one glyph that came from a
13852 int string_seen
= 0;
13853 /* Largest and smallest buffer positions seen so far during scan of
13855 ptrdiff_t bpos_max
= pos_before
;
13856 ptrdiff_t bpos_min
= pos_after
;
13857 /* Last buffer position covered by an overlay string with an integer
13858 `cursor' property. */
13859 ptrdiff_t bpos_covered
= 0;
13860 /* Non-zero means the display string on which to display the cursor
13861 comes from a text property, not from an overlay. */
13862 int string_from_text_prop
= 0;
13864 /* Don't even try doing anything if called for a mode-line or
13865 header-line row, since the rest of the code isn't prepared to
13866 deal with such calamities. */
13867 eassert (!row
->mode_line_p
);
13868 if (row
->mode_line_p
)
13871 /* Skip over glyphs not having an object at the start and the end of
13872 the row. These are special glyphs like truncation marks on
13873 terminal frames. */
13874 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13876 if (!row
->reversed_p
)
13879 && INTEGERP (glyph
->object
)
13880 && glyph
->charpos
< 0)
13882 x
+= glyph
->pixel_width
;
13886 && INTEGERP ((end
- 1)->object
)
13887 /* CHARPOS is zero for blanks and stretch glyphs
13888 inserted by extend_face_to_end_of_line. */
13889 && (end
- 1)->charpos
<= 0)
13891 glyph_before
= glyph
- 1;
13898 /* If the glyph row is reversed, we need to process it from back
13899 to front, so swap the edge pointers. */
13900 glyphs_end
= end
= glyph
- 1;
13901 glyph
+= row
->used
[TEXT_AREA
] - 1;
13903 while (glyph
> end
+ 1
13904 && INTEGERP (glyph
->object
)
13905 && glyph
->charpos
< 0)
13908 x
-= glyph
->pixel_width
;
13910 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13912 /* By default, in reversed rows we put the cursor on the
13913 rightmost (first in the reading order) glyph. */
13914 for (g
= end
+ 1; g
< glyph
; g
++)
13915 x
+= g
->pixel_width
;
13917 && INTEGERP ((end
+ 1)->object
)
13918 && (end
+ 1)->charpos
<= 0)
13920 glyph_before
= glyph
+ 1;
13924 else if (row
->reversed_p
)
13926 /* In R2L rows that don't display text, put the cursor on the
13927 rightmost glyph. Case in point: an empty last line that is
13928 part of an R2L paragraph. */
13930 /* Avoid placing the cursor on the last glyph of the row, where
13931 on terminal frames we hold the vertical border between
13932 adjacent windows. */
13933 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13934 && !WINDOW_RIGHTMOST_P (w
)
13935 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13937 x
= -1; /* will be computed below, at label compute_x */
13940 /* Step 1: Try to find the glyph whose character position
13941 corresponds to point. If that's not possible, find 2 glyphs
13942 whose character positions are the closest to point, one before
13943 point, the other after it. */
13944 if (!row
->reversed_p
)
13945 while (/* not marched to end of glyph row */
13947 /* glyph was not inserted by redisplay for internal purposes */
13948 && !INTEGERP (glyph
->object
))
13950 if (BUFFERP (glyph
->object
))
13952 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13954 if (glyph
->charpos
> bpos_max
)
13955 bpos_max
= glyph
->charpos
;
13956 if (glyph
->charpos
< bpos_min
)
13957 bpos_min
= glyph
->charpos
;
13958 if (!glyph
->avoid_cursor_p
)
13960 /* If we hit point, we've found the glyph on which to
13961 display the cursor. */
13964 match_with_avoid_cursor
= 0;
13967 /* See if we've found a better approximation to
13968 POS_BEFORE or to POS_AFTER. */
13969 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13971 pos_before
= glyph
->charpos
;
13972 glyph_before
= glyph
;
13974 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13976 pos_after
= glyph
->charpos
;
13977 glyph_after
= glyph
;
13980 else if (dpos
== 0)
13981 match_with_avoid_cursor
= 1;
13983 else if (STRINGP (glyph
->object
))
13985 Lisp_Object chprop
;
13986 ptrdiff_t glyph_pos
= glyph
->charpos
;
13988 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13990 if (!NILP (chprop
))
13992 /* If the string came from a `display' text property,
13993 look up the buffer position of that property and
13994 use that position to update bpos_max, as if we
13995 actually saw such a position in one of the row's
13996 glyphs. This helps with supporting integer values
13997 of `cursor' property on the display string in
13998 situations where most or all of the row's buffer
13999 text is completely covered by display properties,
14000 so that no glyph with valid buffer positions is
14001 ever seen in the row. */
14002 ptrdiff_t prop_pos
=
14003 string_buffer_position_lim (glyph
->object
, pos_before
,
14006 if (prop_pos
>= pos_before
)
14007 bpos_max
= prop_pos
- 1;
14009 if (INTEGERP (chprop
))
14011 bpos_covered
= bpos_max
+ XINT (chprop
);
14012 /* If the `cursor' property covers buffer positions up
14013 to and including point, we should display cursor on
14014 this glyph. Note that, if a `cursor' property on one
14015 of the string's characters has an integer value, we
14016 will break out of the loop below _before_ we get to
14017 the position match above. IOW, integer values of
14018 the `cursor' property override the "exact match for
14019 point" strategy of positioning the cursor. */
14020 /* Implementation note: bpos_max == pt_old when, e.g.,
14021 we are in an empty line, where bpos_max is set to
14022 MATRIX_ROW_START_CHARPOS, see above. */
14023 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14032 x
+= glyph
->pixel_width
;
14035 else if (glyph
> end
) /* row is reversed */
14036 while (!INTEGERP (glyph
->object
))
14038 if (BUFFERP (glyph
->object
))
14040 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14042 if (glyph
->charpos
> bpos_max
)
14043 bpos_max
= glyph
->charpos
;
14044 if (glyph
->charpos
< bpos_min
)
14045 bpos_min
= glyph
->charpos
;
14046 if (!glyph
->avoid_cursor_p
)
14050 match_with_avoid_cursor
= 0;
14053 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14055 pos_before
= glyph
->charpos
;
14056 glyph_before
= glyph
;
14058 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14060 pos_after
= glyph
->charpos
;
14061 glyph_after
= glyph
;
14064 else if (dpos
== 0)
14065 match_with_avoid_cursor
= 1;
14067 else if (STRINGP (glyph
->object
))
14069 Lisp_Object chprop
;
14070 ptrdiff_t glyph_pos
= glyph
->charpos
;
14072 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14074 if (!NILP (chprop
))
14076 ptrdiff_t prop_pos
=
14077 string_buffer_position_lim (glyph
->object
, pos_before
,
14080 if (prop_pos
>= pos_before
)
14081 bpos_max
= prop_pos
- 1;
14083 if (INTEGERP (chprop
))
14085 bpos_covered
= bpos_max
+ XINT (chprop
);
14086 /* If the `cursor' property covers buffer positions up
14087 to and including point, we should display cursor on
14089 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14098 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14100 x
--; /* can't use any pixel_width */
14103 x
-= glyph
->pixel_width
;
14106 /* Step 2: If we didn't find an exact match for point, we need to
14107 look for a proper place to put the cursor among glyphs between
14108 GLYPH_BEFORE and GLYPH_AFTER. */
14109 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14110 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14111 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14113 /* An empty line has a single glyph whose OBJECT is zero and
14114 whose CHARPOS is the position of a newline on that line.
14115 Note that on a TTY, there are more glyphs after that, which
14116 were produced by extend_face_to_end_of_line, but their
14117 CHARPOS is zero or negative. */
14119 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14120 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14121 /* On a TTY, continued and truncated rows also have a glyph at
14122 their end whose OBJECT is zero and whose CHARPOS is
14123 positive (the continuation and truncation glyphs), but such
14124 rows are obviously not "empty". */
14125 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14127 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14129 ptrdiff_t ellipsis_pos
;
14131 /* Scan back over the ellipsis glyphs. */
14132 if (!row
->reversed_p
)
14134 ellipsis_pos
= (glyph
- 1)->charpos
;
14135 while (glyph
> row
->glyphs
[TEXT_AREA
]
14136 && (glyph
- 1)->charpos
== ellipsis_pos
)
14137 glyph
--, x
-= glyph
->pixel_width
;
14138 /* That loop always goes one position too far, including
14139 the glyph before the ellipsis. So scan forward over
14141 x
+= glyph
->pixel_width
;
14144 else /* row is reversed */
14146 ellipsis_pos
= (glyph
+ 1)->charpos
;
14147 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14148 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14149 glyph
++, x
+= glyph
->pixel_width
;
14150 x
-= glyph
->pixel_width
;
14154 else if (match_with_avoid_cursor
)
14156 cursor
= glyph_after
;
14159 else if (string_seen
)
14161 int incr
= row
->reversed_p
? -1 : +1;
14163 /* Need to find the glyph that came out of a string which is
14164 present at point. That glyph is somewhere between
14165 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14166 positioned between POS_BEFORE and POS_AFTER in the
14168 struct glyph
*start
, *stop
;
14169 ptrdiff_t pos
= pos_before
;
14173 /* If the row ends in a newline from a display string,
14174 reordering could have moved the glyphs belonging to the
14175 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14176 in this case we extend the search to the last glyph in
14177 the row that was not inserted by redisplay. */
14178 if (row
->ends_in_newline_from_string_p
)
14181 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14184 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14185 correspond to POS_BEFORE and POS_AFTER, respectively. We
14186 need START and STOP in the order that corresponds to the
14187 row's direction as given by its reversed_p flag. If the
14188 directionality of characters between POS_BEFORE and
14189 POS_AFTER is the opposite of the row's base direction,
14190 these characters will have been reordered for display,
14191 and we need to reverse START and STOP. */
14192 if (!row
->reversed_p
)
14194 start
= min (glyph_before
, glyph_after
);
14195 stop
= max (glyph_before
, glyph_after
);
14199 start
= max (glyph_before
, glyph_after
);
14200 stop
= min (glyph_before
, glyph_after
);
14202 for (glyph
= start
+ incr
;
14203 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14206 /* Any glyphs that come from the buffer are here because
14207 of bidi reordering. Skip them, and only pay
14208 attention to glyphs that came from some string. */
14209 if (STRINGP (glyph
->object
))
14213 /* If the display property covers the newline, we
14214 need to search for it one position farther. */
14215 ptrdiff_t lim
= pos_after
14216 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14218 string_from_text_prop
= 0;
14219 str
= glyph
->object
;
14220 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14221 if (tem
== 0 /* from overlay */
14224 /* If the string from which this glyph came is
14225 found in the buffer at point, or at position
14226 that is closer to point than pos_after, then
14227 we've found the glyph we've been looking for.
14228 If it comes from an overlay (tem == 0), and
14229 it has the `cursor' property on one of its
14230 glyphs, record that glyph as a candidate for
14231 displaying the cursor. (As in the
14232 unidirectional version, we will display the
14233 cursor on the last candidate we find.) */
14236 || (tem
- pt_old
> 0 && tem
< pos_after
))
14238 /* The glyphs from this string could have
14239 been reordered. Find the one with the
14240 smallest string position. Or there could
14241 be a character in the string with the
14242 `cursor' property, which means display
14243 cursor on that character's glyph. */
14244 ptrdiff_t strpos
= glyph
->charpos
;
14249 string_from_text_prop
= 1;
14252 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14253 && EQ (glyph
->object
, str
);
14257 ptrdiff_t gpos
= glyph
->charpos
;
14259 cprop
= Fget_char_property (make_number (gpos
),
14267 if (tem
&& glyph
->charpos
< strpos
)
14269 strpos
= glyph
->charpos
;
14275 || (tem
- pt_old
> 0 && tem
< pos_after
))
14279 pos
= tem
+ 1; /* don't find previous instances */
14281 /* This string is not what we want; skip all of the
14282 glyphs that came from it. */
14283 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14284 && EQ (glyph
->object
, str
))
14291 /* If we reached the end of the line, and END was from a string,
14292 the cursor is not on this line. */
14294 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14295 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14296 && STRINGP (end
->object
)
14297 && row
->continued_p
)
14300 /* A truncated row may not include PT among its character positions.
14301 Setting the cursor inside the scroll margin will trigger
14302 recalculation of hscroll in hscroll_window_tree. But if a
14303 display string covers point, defer to the string-handling
14304 code below to figure this out. */
14305 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14307 cursor
= glyph_before
;
14310 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14311 /* Zero-width characters produce no glyphs. */
14313 && (row
->reversed_p
14314 ? glyph_after
> glyphs_end
14315 : glyph_after
< glyphs_end
)))
14317 cursor
= glyph_after
;
14323 if (cursor
!= NULL
)
14325 else if (glyph
== glyphs_end
14326 && pos_before
== pos_after
14327 && STRINGP ((row
->reversed_p
14328 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14329 : row
->glyphs
[TEXT_AREA
])->object
))
14331 /* If all the glyphs of this row came from strings, put the
14332 cursor on the first glyph of the row. This avoids having the
14333 cursor outside of the text area in this very rare and hard
14337 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14338 : row
->glyphs
[TEXT_AREA
];
14344 /* Need to compute x that corresponds to GLYPH. */
14345 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14347 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14349 x
+= g
->pixel_width
;
14353 /* ROW could be part of a continued line, which, under bidi
14354 reordering, might have other rows whose start and end charpos
14355 occlude point. Only set w->cursor if we found a better
14356 approximation to the cursor position than we have from previously
14357 examined candidate rows belonging to the same continued line. */
14358 if (/* we already have a candidate row */
14359 w
->cursor
.vpos
>= 0
14360 /* that candidate is not the row we are processing */
14361 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14362 /* Make sure cursor.vpos specifies a row whose start and end
14363 charpos occlude point, and it is valid candidate for being a
14364 cursor-row. This is because some callers of this function
14365 leave cursor.vpos at the row where the cursor was displayed
14366 during the last redisplay cycle. */
14367 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14368 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14369 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14372 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14374 /* Don't consider glyphs that are outside TEXT_AREA. */
14375 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14377 /* Keep the candidate whose buffer position is the closest to
14378 point or has the `cursor' property. */
14379 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14380 w
->cursor
.hpos
>= 0
14381 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14382 && ((BUFFERP (g1
->object
)
14383 && (g1
->charpos
== pt_old
/* an exact match always wins */
14384 || (BUFFERP (glyph
->object
)
14385 && eabs (g1
->charpos
- pt_old
)
14386 < eabs (glyph
->charpos
- pt_old
))))
14387 /* previous candidate is a glyph from a string that has
14388 a non-nil `cursor' property */
14389 || (STRINGP (g1
->object
)
14390 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14391 Qcursor
, g1
->object
))
14392 /* previous candidate is from the same display
14393 string as this one, and the display string
14394 came from a text property */
14395 || (EQ (g1
->object
, glyph
->object
)
14396 && string_from_text_prop
)
14397 /* this candidate is from newline and its
14398 position is not an exact match */
14399 || (INTEGERP (glyph
->object
)
14400 && glyph
->charpos
!= pt_old
)))))
14402 /* If this candidate gives an exact match, use that. */
14403 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14404 /* If this candidate is a glyph created for the
14405 terminating newline of a line, and point is on that
14406 newline, it wins because it's an exact match. */
14407 || (!row
->continued_p
14408 && INTEGERP (glyph
->object
)
14409 && glyph
->charpos
== 0
14410 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14411 /* Otherwise, keep the candidate that comes from a row
14412 spanning less buffer positions. This may win when one or
14413 both candidate positions are on glyphs that came from
14414 display strings, for which we cannot compare buffer
14416 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14417 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14418 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14421 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14423 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14424 w
->cursor
.y
= row
->y
+ dy
;
14426 if (w
== XWINDOW (selected_window
))
14428 if (!row
->continued_p
14429 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14432 this_line_buffer
= XBUFFER (w
->contents
);
14434 CHARPOS (this_line_start_pos
)
14435 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14436 BYTEPOS (this_line_start_pos
)
14437 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14439 CHARPOS (this_line_end_pos
)
14440 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14441 BYTEPOS (this_line_end_pos
)
14442 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14444 this_line_y
= w
->cursor
.y
;
14445 this_line_pixel_height
= row
->height
;
14446 this_line_vpos
= w
->cursor
.vpos
;
14447 this_line_start_x
= row
->x
;
14450 CHARPOS (this_line_start_pos
) = 0;
14457 /* Run window scroll functions, if any, for WINDOW with new window
14458 start STARTP. Sets the window start of WINDOW to that position.
14460 We assume that the window's buffer is really current. */
14462 static struct text_pos
14463 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14465 struct window
*w
= XWINDOW (window
);
14466 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14468 eassert (current_buffer
== XBUFFER (w
->contents
));
14470 if (!NILP (Vwindow_scroll_functions
))
14472 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14473 make_number (CHARPOS (startp
)));
14474 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14475 /* In case the hook functions switch buffers. */
14476 set_buffer_internal (XBUFFER (w
->contents
));
14483 /* Make sure the line containing the cursor is fully visible.
14484 A value of 1 means there is nothing to be done.
14485 (Either the line is fully visible, or it cannot be made so,
14486 or we cannot tell.)
14488 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14489 is higher than window.
14491 A value of 0 means the caller should do scrolling
14492 as if point had gone off the screen. */
14495 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14497 struct glyph_matrix
*matrix
;
14498 struct glyph_row
*row
;
14501 if (!make_cursor_line_fully_visible_p
)
14504 /* It's not always possible to find the cursor, e.g, when a window
14505 is full of overlay strings. Don't do anything in that case. */
14506 if (w
->cursor
.vpos
< 0)
14509 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14510 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14512 /* If the cursor row is not partially visible, there's nothing to do. */
14513 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14516 /* If the row the cursor is in is taller than the window's height,
14517 it's not clear what to do, so do nothing. */
14518 window_height
= window_box_height (w
);
14519 if (row
->height
>= window_height
)
14521 if (!force_p
|| MINI_WINDOW_P (w
)
14522 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14529 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14530 non-zero means only WINDOW is redisplayed in redisplay_internal.
14531 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14532 in redisplay_window to bring a partially visible line into view in
14533 the case that only the cursor has moved.
14535 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14536 last screen line's vertical height extends past the end of the screen.
14540 1 if scrolling succeeded
14542 0 if scrolling didn't find point.
14544 -1 if new fonts have been loaded so that we must interrupt
14545 redisplay, adjust glyph matrices, and try again. */
14551 SCROLLING_NEED_LARGER_MATRICES
14554 /* If scroll-conservatively is more than this, never recenter.
14556 If you change this, don't forget to update the doc string of
14557 `scroll-conservatively' and the Emacs manual. */
14558 #define SCROLL_LIMIT 100
14561 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14562 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14563 int temp_scroll_step
, int last_line_misfit
)
14565 struct window
*w
= XWINDOW (window
);
14566 struct frame
*f
= XFRAME (w
->frame
);
14567 struct text_pos pos
, startp
;
14569 int this_scroll_margin
, scroll_max
, rc
, height
;
14570 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14571 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14572 Lisp_Object aggressive
;
14573 /* We will never try scrolling more than this number of lines. */
14574 int scroll_limit
= SCROLL_LIMIT
;
14575 int frame_line_height
= default_line_pixel_height (w
);
14576 int window_total_lines
14577 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14580 debug_method_add (w
, "try_scrolling");
14583 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14585 /* Compute scroll margin height in pixels. We scroll when point is
14586 within this distance from the top or bottom of the window. */
14587 if (scroll_margin
> 0)
14588 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14589 * frame_line_height
;
14591 this_scroll_margin
= 0;
14593 /* Force arg_scroll_conservatively to have a reasonable value, to
14594 avoid scrolling too far away with slow move_it_* functions. Note
14595 that the user can supply scroll-conservatively equal to
14596 `most-positive-fixnum', which can be larger than INT_MAX. */
14597 if (arg_scroll_conservatively
> scroll_limit
)
14599 arg_scroll_conservatively
= scroll_limit
+ 1;
14600 scroll_max
= scroll_limit
* frame_line_height
;
14602 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14603 /* Compute how much we should try to scroll maximally to bring
14604 point into view. */
14605 scroll_max
= (max (scroll_step
,
14606 max (arg_scroll_conservatively
, temp_scroll_step
))
14607 * frame_line_height
);
14608 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14609 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14610 /* We're trying to scroll because of aggressive scrolling but no
14611 scroll_step is set. Choose an arbitrary one. */
14612 scroll_max
= 10 * frame_line_height
;
14618 /* Decide whether to scroll down. */
14619 if (PT
> CHARPOS (startp
))
14621 int scroll_margin_y
;
14623 /* Compute the pixel ypos of the scroll margin, then move IT to
14624 either that ypos or PT, whichever comes first. */
14625 start_display (&it
, w
, startp
);
14626 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14627 - frame_line_height
* extra_scroll_margin_lines
;
14628 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14629 (MOVE_TO_POS
| MOVE_TO_Y
));
14631 if (PT
> CHARPOS (it
.current
.pos
))
14633 int y0
= line_bottom_y (&it
);
14634 /* Compute how many pixels below window bottom to stop searching
14635 for PT. This avoids costly search for PT that is far away if
14636 the user limited scrolling by a small number of lines, but
14637 always finds PT if scroll_conservatively is set to a large
14638 number, such as most-positive-fixnum. */
14639 int slack
= max (scroll_max
, 10 * frame_line_height
);
14640 int y_to_move
= it
.last_visible_y
+ slack
;
14642 /* Compute the distance from the scroll margin to PT or to
14643 the scroll limit, whichever comes first. This should
14644 include the height of the cursor line, to make that line
14646 move_it_to (&it
, PT
, -1, y_to_move
,
14647 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14648 dy
= line_bottom_y (&it
) - y0
;
14650 if (dy
> scroll_max
)
14651 return SCROLLING_FAILED
;
14660 /* Point is in or below the bottom scroll margin, so move the
14661 window start down. If scrolling conservatively, move it just
14662 enough down to make point visible. If scroll_step is set,
14663 move it down by scroll_step. */
14664 if (arg_scroll_conservatively
)
14666 = min (max (dy
, frame_line_height
),
14667 frame_line_height
* arg_scroll_conservatively
);
14668 else if (scroll_step
|| temp_scroll_step
)
14669 amount_to_scroll
= scroll_max
;
14672 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14673 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14674 if (NUMBERP (aggressive
))
14676 double float_amount
= XFLOATINT (aggressive
) * height
;
14677 int aggressive_scroll
= float_amount
;
14678 if (aggressive_scroll
== 0 && float_amount
> 0)
14679 aggressive_scroll
= 1;
14680 /* Don't let point enter the scroll margin near top of
14681 the window. This could happen if the value of
14682 scroll_up_aggressively is too large and there are
14683 non-zero margins, because scroll_up_aggressively
14684 means put point that fraction of window height
14685 _from_the_bottom_margin_. */
14686 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14687 aggressive_scroll
= height
- 2*this_scroll_margin
;
14688 amount_to_scroll
= dy
+ aggressive_scroll
;
14692 if (amount_to_scroll
<= 0)
14693 return SCROLLING_FAILED
;
14695 start_display (&it
, w
, startp
);
14696 if (arg_scroll_conservatively
<= scroll_limit
)
14697 move_it_vertically (&it
, amount_to_scroll
);
14700 /* Extra precision for users who set scroll-conservatively
14701 to a large number: make sure the amount we scroll
14702 the window start is never less than amount_to_scroll,
14703 which was computed as distance from window bottom to
14704 point. This matters when lines at window top and lines
14705 below window bottom have different height. */
14707 void *it1data
= NULL
;
14708 /* We use a temporary it1 because line_bottom_y can modify
14709 its argument, if it moves one line down; see there. */
14712 SAVE_IT (it1
, it
, it1data
);
14713 start_y
= line_bottom_y (&it1
);
14715 RESTORE_IT (&it
, &it
, it1data
);
14716 move_it_by_lines (&it
, 1);
14717 SAVE_IT (it1
, it
, it1data
);
14718 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14721 /* If STARTP is unchanged, move it down another screen line. */
14722 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14723 move_it_by_lines (&it
, 1);
14724 startp
= it
.current
.pos
;
14728 struct text_pos scroll_margin_pos
= startp
;
14731 /* See if point is inside the scroll margin at the top of the
14733 if (this_scroll_margin
)
14737 start_display (&it
, w
, startp
);
14738 y_start
= it
.current_y
;
14739 move_it_vertically (&it
, this_scroll_margin
);
14740 scroll_margin_pos
= it
.current
.pos
;
14741 /* If we didn't move enough before hitting ZV, request
14742 additional amount of scroll, to move point out of the
14744 if (IT_CHARPOS (it
) == ZV
14745 && it
.current_y
- y_start
< this_scroll_margin
)
14746 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14749 if (PT
< CHARPOS (scroll_margin_pos
))
14751 /* Point is in the scroll margin at the top of the window or
14752 above what is displayed in the window. */
14755 /* Compute the vertical distance from PT to the scroll
14756 margin position. Move as far as scroll_max allows, or
14757 one screenful, or 10 screen lines, whichever is largest.
14758 Give up if distance is greater than scroll_max or if we
14759 didn't reach the scroll margin position. */
14760 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14761 start_display (&it
, w
, pos
);
14763 y_to_move
= max (it
.last_visible_y
,
14764 max (scroll_max
, 10 * frame_line_height
));
14765 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14767 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14768 dy
= it
.current_y
- y0
;
14769 if (dy
> scroll_max
14770 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14771 return SCROLLING_FAILED
;
14773 /* Additional scroll for when ZV was too close to point. */
14776 /* Compute new window start. */
14777 start_display (&it
, w
, startp
);
14779 if (arg_scroll_conservatively
)
14780 amount_to_scroll
= max (dy
, frame_line_height
*
14781 max (scroll_step
, temp_scroll_step
));
14782 else if (scroll_step
|| temp_scroll_step
)
14783 amount_to_scroll
= scroll_max
;
14786 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14787 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14788 if (NUMBERP (aggressive
))
14790 double float_amount
= XFLOATINT (aggressive
) * height
;
14791 int aggressive_scroll
= float_amount
;
14792 if (aggressive_scroll
== 0 && float_amount
> 0)
14793 aggressive_scroll
= 1;
14794 /* Don't let point enter the scroll margin near
14795 bottom of the window, if the value of
14796 scroll_down_aggressively happens to be too
14798 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14799 aggressive_scroll
= height
- 2*this_scroll_margin
;
14800 amount_to_scroll
= dy
+ aggressive_scroll
;
14804 if (amount_to_scroll
<= 0)
14805 return SCROLLING_FAILED
;
14807 move_it_vertically_backward (&it
, amount_to_scroll
);
14808 startp
= it
.current
.pos
;
14812 /* Run window scroll functions. */
14813 startp
= run_window_scroll_functions (window
, startp
);
14815 /* Display the window. Give up if new fonts are loaded, or if point
14817 if (!try_window (window
, startp
, 0))
14818 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14819 else if (w
->cursor
.vpos
< 0)
14821 clear_glyph_matrix (w
->desired_matrix
);
14822 rc
= SCROLLING_FAILED
;
14826 /* Maybe forget recorded base line for line number display. */
14827 if (!just_this_one_p
14828 || current_buffer
->clip_changed
14829 || BEG_UNCHANGED
< CHARPOS (startp
))
14830 w
->base_line_number
= 0;
14832 /* If cursor ends up on a partially visible line,
14833 treat that as being off the bottom of the screen. */
14834 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14835 /* It's possible that the cursor is on the first line of the
14836 buffer, which is partially obscured due to a vscroll
14837 (Bug#7537). In that case, avoid looping forever . */
14838 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14840 clear_glyph_matrix (w
->desired_matrix
);
14841 ++extra_scroll_margin_lines
;
14844 rc
= SCROLLING_SUCCESS
;
14851 /* Compute a suitable window start for window W if display of W starts
14852 on a continuation line. Value is non-zero if a new window start
14855 The new window start will be computed, based on W's width, starting
14856 from the start of the continued line. It is the start of the
14857 screen line with the minimum distance from the old start W->start. */
14860 compute_window_start_on_continuation_line (struct window
*w
)
14862 struct text_pos pos
, start_pos
;
14863 int window_start_changed_p
= 0;
14865 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14867 /* If window start is on a continuation line... Window start may be
14868 < BEGV in case there's invisible text at the start of the
14869 buffer (M-x rmail, for example). */
14870 if (CHARPOS (start_pos
) > BEGV
14871 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14874 struct glyph_row
*row
;
14876 /* Handle the case that the window start is out of range. */
14877 if (CHARPOS (start_pos
) < BEGV
)
14878 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14879 else if (CHARPOS (start_pos
) > ZV
)
14880 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14882 /* Find the start of the continued line. This should be fast
14883 because find_newline is fast (newline cache). */
14884 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14885 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14886 row
, DEFAULT_FACE_ID
);
14887 reseat_at_previous_visible_line_start (&it
);
14889 /* If the line start is "too far" away from the window start,
14890 say it takes too much time to compute a new window start. */
14891 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14892 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14894 int min_distance
, distance
;
14896 /* Move forward by display lines to find the new window
14897 start. If window width was enlarged, the new start can
14898 be expected to be > the old start. If window width was
14899 decreased, the new window start will be < the old start.
14900 So, we're looking for the display line start with the
14901 minimum distance from the old window start. */
14902 pos
= it
.current
.pos
;
14903 min_distance
= INFINITY
;
14904 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14905 distance
< min_distance
)
14907 min_distance
= distance
;
14908 pos
= it
.current
.pos
;
14909 if (it
.line_wrap
== WORD_WRAP
)
14911 /* Under WORD_WRAP, move_it_by_lines is likely to
14912 overshoot and stop not at the first, but the
14913 second character from the left margin. So in
14914 that case, we need a more tight control on the X
14915 coordinate of the iterator than move_it_by_lines
14916 promises in its contract. The method is to first
14917 go to the last (rightmost) visible character of a
14918 line, then move to the leftmost character on the
14919 next line in a separate call. */
14920 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14921 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14922 move_it_to (&it
, ZV
, 0,
14923 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14924 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14927 move_it_by_lines (&it
, 1);
14930 /* Set the window start there. */
14931 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14932 window_start_changed_p
= 1;
14936 return window_start_changed_p
;
14940 /* Try cursor movement in case text has not changed in window WINDOW,
14941 with window start STARTP. Value is
14943 CURSOR_MOVEMENT_SUCCESS if successful
14945 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14947 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14948 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14949 we want to scroll as if scroll-step were set to 1. See the code.
14951 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14952 which case we have to abort this redisplay, and adjust matrices
14957 CURSOR_MOVEMENT_SUCCESS
,
14958 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14959 CURSOR_MOVEMENT_MUST_SCROLL
,
14960 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14964 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14966 struct window
*w
= XWINDOW (window
);
14967 struct frame
*f
= XFRAME (w
->frame
);
14968 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14971 if (inhibit_try_cursor_movement
)
14975 /* Previously, there was a check for Lisp integer in the
14976 if-statement below. Now, this field is converted to
14977 ptrdiff_t, thus zero means invalid position in a buffer. */
14978 eassert (w
->last_point
> 0);
14979 /* Likewise there was a check whether window_end_vpos is nil or larger
14980 than the window. Now window_end_vpos is int and so never nil, but
14981 let's leave eassert to check whether it fits in the window. */
14982 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
14984 /* Handle case where text has not changed, only point, and it has
14985 not moved off the frame. */
14986 if (/* Point may be in this window. */
14987 PT
>= CHARPOS (startp
)
14988 /* Selective display hasn't changed. */
14989 && !current_buffer
->clip_changed
14990 /* Function force-mode-line-update is used to force a thorough
14991 redisplay. It sets either windows_or_buffers_changed or
14992 update_mode_lines. So don't take a shortcut here for these
14994 && !update_mode_lines
14995 && !windows_or_buffers_changed
14996 && !cursor_type_changed
14997 /* Can't use this case if highlighting a region. When a
14998 region exists, cursor movement has to do more than just
15000 && markpos_of_region () < 0
15001 && !w
->region_showing
15002 && NILP (Vshow_trailing_whitespace
)
15003 /* This code is not used for mini-buffer for the sake of the case
15004 of redisplaying to replace an echo area message; since in
15005 that case the mini-buffer contents per se are usually
15006 unchanged. This code is of no real use in the mini-buffer
15007 since the handling of this_line_start_pos, etc., in redisplay
15008 handles the same cases. */
15009 && !EQ (window
, minibuf_window
)
15010 && (FRAME_WINDOW_P (f
)
15011 || !overlay_arrow_in_current_buffer_p ()))
15013 int this_scroll_margin
, top_scroll_margin
;
15014 struct glyph_row
*row
= NULL
;
15015 int frame_line_height
= default_line_pixel_height (w
);
15016 int window_total_lines
15017 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15020 debug_method_add (w
, "cursor movement");
15023 /* Scroll if point within this distance from the top or bottom
15024 of the window. This is a pixel value. */
15025 if (scroll_margin
> 0)
15027 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15028 this_scroll_margin
*= frame_line_height
;
15031 this_scroll_margin
= 0;
15033 top_scroll_margin
= this_scroll_margin
;
15034 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15035 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15037 /* Start with the row the cursor was displayed during the last
15038 not paused redisplay. Give up if that row is not valid. */
15039 if (w
->last_cursor_vpos
< 0
15040 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15041 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15044 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15045 if (row
->mode_line_p
)
15047 if (!row
->enabled_p
)
15048 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15051 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15053 int scroll_p
= 0, must_scroll
= 0;
15054 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15056 if (PT
> w
->last_point
)
15058 /* Point has moved forward. */
15059 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15060 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15062 eassert (row
->enabled_p
);
15066 /* If the end position of a row equals the start
15067 position of the next row, and PT is at that position,
15068 we would rather display cursor in the next line. */
15069 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15070 && MATRIX_ROW_END_CHARPOS (row
) == PT
15071 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15072 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15073 && !cursor_row_p (row
))
15076 /* If within the scroll margin, scroll. Note that
15077 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15078 the next line would be drawn, and that
15079 this_scroll_margin can be zero. */
15080 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15081 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15082 /* Line is completely visible last line in window
15083 and PT is to be set in the next line. */
15084 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15085 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15086 && !row
->ends_at_zv_p
15087 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15090 else if (PT
< w
->last_point
)
15092 /* Cursor has to be moved backward. Note that PT >=
15093 CHARPOS (startp) because of the outer if-statement. */
15094 while (!row
->mode_line_p
15095 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15096 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15097 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15098 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15099 row
> w
->current_matrix
->rows
15100 && (row
-1)->ends_in_newline_from_string_p
))))
15101 && (row
->y
> top_scroll_margin
15102 || CHARPOS (startp
) == BEGV
))
15104 eassert (row
->enabled_p
);
15108 /* Consider the following case: Window starts at BEGV,
15109 there is invisible, intangible text at BEGV, so that
15110 display starts at some point START > BEGV. It can
15111 happen that we are called with PT somewhere between
15112 BEGV and START. Try to handle that case. */
15113 if (row
< w
->current_matrix
->rows
15114 || row
->mode_line_p
)
15116 row
= w
->current_matrix
->rows
;
15117 if (row
->mode_line_p
)
15121 /* Due to newlines in overlay strings, we may have to
15122 skip forward over overlay strings. */
15123 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15124 && MATRIX_ROW_END_CHARPOS (row
) == PT
15125 && !cursor_row_p (row
))
15128 /* If within the scroll margin, scroll. */
15129 if (row
->y
< top_scroll_margin
15130 && CHARPOS (startp
) != BEGV
)
15135 /* Cursor did not move. So don't scroll even if cursor line
15136 is partially visible, as it was so before. */
15137 rc
= CURSOR_MOVEMENT_SUCCESS
;
15140 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15141 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15143 /* if PT is not in the glyph row, give up. */
15144 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15147 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15148 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15150 struct glyph_row
*row1
;
15152 /* If rows are bidi-reordered and point moved, back up
15153 until we find a row that does not belong to a
15154 continuation line. This is because we must consider
15155 all rows of a continued line as candidates for the
15156 new cursor positioning, since row start and end
15157 positions change non-linearly with vertical position
15159 /* FIXME: Revisit this when glyph ``spilling'' in
15160 continuation lines' rows is implemented for
15161 bidi-reordered rows. */
15162 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15163 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15166 /* If we hit the beginning of the displayed portion
15167 without finding the first row of a continued
15171 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15174 eassert (row
->enabled_p
);
15179 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15180 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15181 /* Make sure this isn't a header line by any chance, since
15182 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15183 && !row
->mode_line_p
15184 && make_cursor_line_fully_visible_p
)
15186 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15187 && !row
->ends_at_zv_p
15188 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15189 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15190 else if (row
->height
> window_box_height (w
))
15192 /* If we end up in a partially visible line, let's
15193 make it fully visible, except when it's taller
15194 than the window, in which case we can't do much
15197 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15201 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15202 if (!cursor_row_fully_visible_p (w
, 0, 1))
15203 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15205 rc
= CURSOR_MOVEMENT_SUCCESS
;
15209 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15210 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15211 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15213 /* With bidi-reordered rows, there could be more than
15214 one candidate row whose start and end positions
15215 occlude point. We need to let set_cursor_from_row
15216 find the best candidate. */
15217 /* FIXME: Revisit this when glyph ``spilling'' in
15218 continuation lines' rows is implemented for
15219 bidi-reordered rows. */
15224 int at_zv_p
= 0, exact_match_p
= 0;
15226 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15227 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15228 && cursor_row_p (row
))
15229 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15231 /* As soon as we've found the exact match for point,
15232 or the first suitable row whose ends_at_zv_p flag
15233 is set, we are done. */
15235 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15237 && w
->cursor
.hpos
>= 0
15238 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15241 struct glyph_row
*candidate
=
15242 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15244 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15245 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15248 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15249 || (INTEGERP (g
->object
)
15250 && (g
->charpos
== PT
15251 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15253 if (rv
&& (at_zv_p
|| exact_match_p
))
15255 rc
= CURSOR_MOVEMENT_SUCCESS
;
15258 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15262 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15263 || row
->continued_p
)
15264 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15265 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15266 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15267 /* If we didn't find any candidate rows, or exited the
15268 loop before all the candidates were examined, signal
15269 to the caller that this method failed. */
15270 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15272 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15273 && !row
->continued_p
))
15274 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15276 rc
= CURSOR_MOVEMENT_SUCCESS
;
15282 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15284 rc
= CURSOR_MOVEMENT_SUCCESS
;
15289 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15290 && MATRIX_ROW_START_CHARPOS (row
) == PT
15291 && cursor_row_p (row
));
15299 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15303 set_vertical_scroll_bar (struct window
*w
)
15305 ptrdiff_t start
, end
, whole
;
15307 /* Calculate the start and end positions for the current window.
15308 At some point, it would be nice to choose between scrollbars
15309 which reflect the whole buffer size, with special markers
15310 indicating narrowing, and scrollbars which reflect only the
15313 Note that mini-buffers sometimes aren't displaying any text. */
15314 if (!MINI_WINDOW_P (w
)
15315 || (w
== XWINDOW (minibuf_window
)
15316 && NILP (echo_area_buffer
[0])))
15318 struct buffer
*buf
= XBUFFER (w
->contents
);
15319 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15320 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15321 /* I don't think this is guaranteed to be right. For the
15322 moment, we'll pretend it is. */
15323 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15327 if (whole
< (end
- start
))
15328 whole
= end
- start
;
15331 start
= end
= whole
= 0;
15333 /* Indicate what this scroll bar ought to be displaying now. */
15334 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15335 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15336 (w
, end
- start
, whole
, start
);
15340 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15341 selected_window is redisplayed.
15343 We can return without actually redisplaying the window if
15344 fonts_changed_p. In that case, redisplay_internal will
15348 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15350 struct window
*w
= XWINDOW (window
);
15351 struct frame
*f
= XFRAME (w
->frame
);
15352 struct buffer
*buffer
= XBUFFER (w
->contents
);
15353 struct buffer
*old
= current_buffer
;
15354 struct text_pos lpoint
, opoint
, startp
;
15355 int update_mode_line
;
15358 /* Record it now because it's overwritten. */
15359 int current_matrix_up_to_date_p
= 0;
15360 int used_current_matrix_p
= 0;
15361 /* This is less strict than current_matrix_up_to_date_p.
15362 It indicates that the buffer contents and narrowing are unchanged. */
15363 int buffer_unchanged_p
= 0;
15364 int temp_scroll_step
= 0;
15365 ptrdiff_t count
= SPECPDL_INDEX ();
15367 int centering_position
= -1;
15368 int last_line_misfit
= 0;
15369 ptrdiff_t beg_unchanged
, end_unchanged
;
15370 int frame_line_height
;
15372 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15376 *w
->desired_matrix
->method
= 0;
15379 /* Make sure that both W's markers are valid. */
15380 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15381 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15384 reconsider_clip_changes (w
);
15385 frame_line_height
= default_line_pixel_height (w
);
15387 /* Has the mode line to be updated? */
15388 update_mode_line
= (w
->update_mode_line
15389 || update_mode_lines
15390 || buffer
->clip_changed
15391 || buffer
->prevent_redisplay_optimizations_p
);
15393 if (MINI_WINDOW_P (w
))
15395 if (w
== XWINDOW (echo_area_window
)
15396 && !NILP (echo_area_buffer
[0]))
15398 if (update_mode_line
)
15399 /* We may have to update a tty frame's menu bar or a
15400 tool-bar. Example `M-x C-h C-h C-g'. */
15401 goto finish_menu_bars
;
15403 /* We've already displayed the echo area glyphs in this window. */
15404 goto finish_scroll_bars
;
15406 else if ((w
!= XWINDOW (minibuf_window
)
15407 || minibuf_level
== 0)
15408 /* When buffer is nonempty, redisplay window normally. */
15409 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15410 /* Quail displays non-mini buffers in minibuffer window.
15411 In that case, redisplay the window normally. */
15412 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15414 /* W is a mini-buffer window, but it's not active, so clear
15416 int yb
= window_text_bottom_y (w
);
15417 struct glyph_row
*row
;
15420 for (y
= 0, row
= w
->desired_matrix
->rows
;
15422 y
+= row
->height
, ++row
)
15423 blank_row (w
, row
, y
);
15424 goto finish_scroll_bars
;
15427 clear_glyph_matrix (w
->desired_matrix
);
15430 /* Otherwise set up data on this window; select its buffer and point
15432 /* Really select the buffer, for the sake of buffer-local
15434 set_buffer_internal_1 (XBUFFER (w
->contents
));
15436 current_matrix_up_to_date_p
15437 = (w
->window_end_valid
15438 && !current_buffer
->clip_changed
15439 && !current_buffer
->prevent_redisplay_optimizations_p
15440 && !window_outdated (w
));
15442 /* Run the window-bottom-change-functions
15443 if it is possible that the text on the screen has changed
15444 (either due to modification of the text, or any other reason). */
15445 if (!current_matrix_up_to_date_p
15446 && !NILP (Vwindow_text_change_functions
))
15448 safe_run_hooks (Qwindow_text_change_functions
);
15452 beg_unchanged
= BEG_UNCHANGED
;
15453 end_unchanged
= END_UNCHANGED
;
15455 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15457 specbind (Qinhibit_point_motion_hooks
, Qt
);
15460 = (w
->window_end_valid
15461 && !current_buffer
->clip_changed
15462 && !window_outdated (w
));
15464 /* When windows_or_buffers_changed is non-zero, we can't rely
15465 on the window end being valid, so set it to zero there. */
15466 if (windows_or_buffers_changed
)
15468 /* If window starts on a continuation line, maybe adjust the
15469 window start in case the window's width changed. */
15470 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15471 compute_window_start_on_continuation_line (w
);
15473 w
->window_end_valid
= 0;
15474 /* If so, we also can't rely on current matrix
15475 and should not fool try_cursor_movement below. */
15476 current_matrix_up_to_date_p
= 0;
15479 /* Some sanity checks. */
15480 CHECK_WINDOW_END (w
);
15481 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15483 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15486 if (mode_line_update_needed (w
))
15487 update_mode_line
= 1;
15489 /* Point refers normally to the selected window. For any other
15490 window, set up appropriate value. */
15491 if (!EQ (window
, selected_window
))
15493 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15494 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15498 new_pt_byte
= BEGV_BYTE
;
15499 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15501 else if (new_pt
> (ZV
- 1))
15504 new_pt_byte
= ZV_BYTE
;
15505 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15508 /* We don't use SET_PT so that the point-motion hooks don't run. */
15509 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15512 /* If any of the character widths specified in the display table
15513 have changed, invalidate the width run cache. It's true that
15514 this may be a bit late to catch such changes, but the rest of
15515 redisplay goes (non-fatally) haywire when the display table is
15516 changed, so why should we worry about doing any better? */
15517 if (current_buffer
->width_run_cache
)
15519 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15521 if (! disptab_matches_widthtab
15522 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15524 invalidate_region_cache (current_buffer
,
15525 current_buffer
->width_run_cache
,
15527 recompute_width_table (current_buffer
, disptab
);
15531 /* If window-start is screwed up, choose a new one. */
15532 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15535 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15537 /* If someone specified a new starting point but did not insist,
15538 check whether it can be used. */
15539 if (w
->optional_new_start
15540 && CHARPOS (startp
) >= BEGV
15541 && CHARPOS (startp
) <= ZV
)
15543 w
->optional_new_start
= 0;
15544 start_display (&it
, w
, startp
);
15545 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15546 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15547 if (IT_CHARPOS (it
) == PT
)
15548 w
->force_start
= 1;
15549 /* IT may overshoot PT if text at PT is invisible. */
15550 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15551 w
->force_start
= 1;
15556 /* Handle case where place to start displaying has been specified,
15557 unless the specified location is outside the accessible range. */
15558 if (w
->force_start
|| window_frozen_p (w
))
15560 /* We set this later on if we have to adjust point. */
15563 w
->force_start
= 0;
15565 w
->window_end_valid
= 0;
15567 /* Forget any recorded base line for line number display. */
15568 if (!buffer_unchanged_p
)
15569 w
->base_line_number
= 0;
15571 /* Redisplay the mode line. Select the buffer properly for that.
15572 Also, run the hook window-scroll-functions
15573 because we have scrolled. */
15574 /* Note, we do this after clearing force_start because
15575 if there's an error, it is better to forget about force_start
15576 than to get into an infinite loop calling the hook functions
15577 and having them get more errors. */
15578 if (!update_mode_line
15579 || ! NILP (Vwindow_scroll_functions
))
15581 update_mode_line
= 1;
15582 w
->update_mode_line
= 1;
15583 startp
= run_window_scroll_functions (window
, startp
);
15586 if (CHARPOS (startp
) < BEGV
)
15587 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15588 else if (CHARPOS (startp
) > ZV
)
15589 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15591 /* Redisplay, then check if cursor has been set during the
15592 redisplay. Give up if new fonts were loaded. */
15593 /* We used to issue a CHECK_MARGINS argument to try_window here,
15594 but this causes scrolling to fail when point begins inside
15595 the scroll margin (bug#148) -- cyd */
15596 if (!try_window (window
, startp
, 0))
15598 w
->force_start
= 1;
15599 clear_glyph_matrix (w
->desired_matrix
);
15600 goto need_larger_matrices
;
15603 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15605 /* If point does not appear, try to move point so it does
15606 appear. The desired matrix has been built above, so we
15607 can use it here. */
15608 new_vpos
= window_box_height (w
) / 2;
15611 if (!cursor_row_fully_visible_p (w
, 0, 0))
15613 /* Point does appear, but on a line partly visible at end of window.
15614 Move it back to a fully-visible line. */
15615 new_vpos
= window_box_height (w
);
15617 else if (w
->cursor
.vpos
>=0)
15619 /* Some people insist on not letting point enter the scroll
15620 margin, even though this part handles windows that didn't
15622 int window_total_lines
15623 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15624 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15625 int pixel_margin
= margin
* frame_line_height
;
15626 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15628 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15629 below, which finds the row to move point to, advances by
15630 the Y coordinate of the _next_ row, see the definition of
15631 MATRIX_ROW_BOTTOM_Y. */
15632 if (w
->cursor
.vpos
< margin
+ header_line
)
15634 w
->cursor
.vpos
= -1;
15635 clear_glyph_matrix (w
->desired_matrix
);
15636 goto try_to_scroll
;
15640 int window_height
= window_box_height (w
);
15643 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15644 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15646 w
->cursor
.vpos
= -1;
15647 clear_glyph_matrix (w
->desired_matrix
);
15648 goto try_to_scroll
;
15653 /* If we need to move point for either of the above reasons,
15654 now actually do it. */
15657 struct glyph_row
*row
;
15659 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15660 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15663 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15664 MATRIX_ROW_START_BYTEPOS (row
));
15666 if (w
!= XWINDOW (selected_window
))
15667 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15668 else if (current_buffer
== old
)
15669 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15671 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15673 /* If we are highlighting the region, then we just changed
15674 the region, so redisplay to show it. */
15675 if (markpos_of_region () >= 0)
15677 clear_glyph_matrix (w
->desired_matrix
);
15678 if (!try_window (window
, startp
, 0))
15679 goto need_larger_matrices
;
15684 debug_method_add (w
, "forced window start");
15689 /* Handle case where text has not changed, only point, and it has
15690 not moved off the frame, and we are not retrying after hscroll.
15691 (current_matrix_up_to_date_p is nonzero when retrying.) */
15692 if (current_matrix_up_to_date_p
15693 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15694 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15698 case CURSOR_MOVEMENT_SUCCESS
:
15699 used_current_matrix_p
= 1;
15702 case CURSOR_MOVEMENT_MUST_SCROLL
:
15703 goto try_to_scroll
;
15709 /* If current starting point was originally the beginning of a line
15710 but no longer is, find a new starting point. */
15711 else if (w
->start_at_line_beg
15712 && !(CHARPOS (startp
) <= BEGV
15713 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15716 debug_method_add (w
, "recenter 1");
15721 /* Try scrolling with try_window_id. Value is > 0 if update has
15722 been done, it is -1 if we know that the same window start will
15723 not work. It is 0 if unsuccessful for some other reason. */
15724 else if ((tem
= try_window_id (w
)) != 0)
15727 debug_method_add (w
, "try_window_id %d", tem
);
15730 if (fonts_changed_p
)
15731 goto need_larger_matrices
;
15735 /* Otherwise try_window_id has returned -1 which means that we
15736 don't want the alternative below this comment to execute. */
15738 else if (CHARPOS (startp
) >= BEGV
15739 && CHARPOS (startp
) <= ZV
15740 && PT
>= CHARPOS (startp
)
15741 && (CHARPOS (startp
) < ZV
15742 /* Avoid starting at end of buffer. */
15743 || CHARPOS (startp
) == BEGV
15744 || !window_outdated (w
)))
15746 int d1
, d2
, d3
, d4
, d5
, d6
;
15748 /* If first window line is a continuation line, and window start
15749 is inside the modified region, but the first change is before
15750 current window start, we must select a new window start.
15752 However, if this is the result of a down-mouse event (e.g. by
15753 extending the mouse-drag-overlay), we don't want to select a
15754 new window start, since that would change the position under
15755 the mouse, resulting in an unwanted mouse-movement rather
15756 than a simple mouse-click. */
15757 if (!w
->start_at_line_beg
15758 && NILP (do_mouse_tracking
)
15759 && CHARPOS (startp
) > BEGV
15760 && CHARPOS (startp
) > BEG
+ beg_unchanged
15761 && CHARPOS (startp
) <= Z
- end_unchanged
15762 /* Even if w->start_at_line_beg is nil, a new window may
15763 start at a line_beg, since that's how set_buffer_window
15764 sets it. So, we need to check the return value of
15765 compute_window_start_on_continuation_line. (See also
15767 && XMARKER (w
->start
)->buffer
== current_buffer
15768 && compute_window_start_on_continuation_line (w
)
15769 /* It doesn't make sense to force the window start like we
15770 do at label force_start if it is already known that point
15771 will not be visible in the resulting window, because
15772 doing so will move point from its correct position
15773 instead of scrolling the window to bring point into view.
15775 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15777 w
->force_start
= 1;
15778 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15783 debug_method_add (w
, "same window start");
15786 /* Try to redisplay starting at same place as before.
15787 If point has not moved off frame, accept the results. */
15788 if (!current_matrix_up_to_date_p
15789 /* Don't use try_window_reusing_current_matrix in this case
15790 because a window scroll function can have changed the
15792 || !NILP (Vwindow_scroll_functions
)
15793 || MINI_WINDOW_P (w
)
15794 || !(used_current_matrix_p
15795 = try_window_reusing_current_matrix (w
)))
15797 IF_DEBUG (debug_method_add (w
, "1"));
15798 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15799 /* -1 means we need to scroll.
15800 0 means we need new matrices, but fonts_changed_p
15801 is set in that case, so we will detect it below. */
15802 goto try_to_scroll
;
15805 if (fonts_changed_p
)
15806 goto need_larger_matrices
;
15808 if (w
->cursor
.vpos
>= 0)
15810 if (!just_this_one_p
15811 || current_buffer
->clip_changed
15812 || BEG_UNCHANGED
< CHARPOS (startp
))
15813 /* Forget any recorded base line for line number display. */
15814 w
->base_line_number
= 0;
15816 if (!cursor_row_fully_visible_p (w
, 1, 0))
15818 clear_glyph_matrix (w
->desired_matrix
);
15819 last_line_misfit
= 1;
15821 /* Drop through and scroll. */
15826 clear_glyph_matrix (w
->desired_matrix
);
15831 /* Redisplay the mode line. Select the buffer properly for that. */
15832 if (!update_mode_line
)
15834 update_mode_line
= 1;
15835 w
->update_mode_line
= 1;
15838 /* Try to scroll by specified few lines. */
15839 if ((scroll_conservatively
15840 || emacs_scroll_step
15841 || temp_scroll_step
15842 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15843 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15844 && CHARPOS (startp
) >= BEGV
15845 && CHARPOS (startp
) <= ZV
)
15847 /* The function returns -1 if new fonts were loaded, 1 if
15848 successful, 0 if not successful. */
15849 int ss
= try_scrolling (window
, just_this_one_p
,
15850 scroll_conservatively
,
15852 temp_scroll_step
, last_line_misfit
);
15855 case SCROLLING_SUCCESS
:
15858 case SCROLLING_NEED_LARGER_MATRICES
:
15859 goto need_larger_matrices
;
15861 case SCROLLING_FAILED
:
15869 /* Finally, just choose a place to start which positions point
15870 according to user preferences. */
15875 debug_method_add (w
, "recenter");
15878 /* Forget any previously recorded base line for line number display. */
15879 if (!buffer_unchanged_p
)
15880 w
->base_line_number
= 0;
15882 /* Determine the window start relative to point. */
15883 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15884 it
.current_y
= it
.last_visible_y
;
15885 if (centering_position
< 0)
15887 int window_total_lines
15888 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15891 ? min (scroll_margin
, window_total_lines
/ 4)
15893 ptrdiff_t margin_pos
= CHARPOS (startp
);
15894 Lisp_Object aggressive
;
15897 /* If there is a scroll margin at the top of the window, find
15898 its character position. */
15900 /* Cannot call start_display if startp is not in the
15901 accessible region of the buffer. This can happen when we
15902 have just switched to a different buffer and/or changed
15903 its restriction. In that case, startp is initialized to
15904 the character position 1 (BEGV) because we did not yet
15905 have chance to display the buffer even once. */
15906 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15909 void *it1data
= NULL
;
15911 SAVE_IT (it1
, it
, it1data
);
15912 start_display (&it1
, w
, startp
);
15913 move_it_vertically (&it1
, margin
* frame_line_height
);
15914 margin_pos
= IT_CHARPOS (it1
);
15915 RESTORE_IT (&it
, &it
, it1data
);
15917 scrolling_up
= PT
> margin_pos
;
15920 ? BVAR (current_buffer
, scroll_up_aggressively
)
15921 : BVAR (current_buffer
, scroll_down_aggressively
);
15923 if (!MINI_WINDOW_P (w
)
15924 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15928 /* Setting scroll-conservatively overrides
15929 scroll-*-aggressively. */
15930 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15932 double float_amount
= XFLOATINT (aggressive
);
15934 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15935 if (pt_offset
== 0 && float_amount
> 0)
15937 if (pt_offset
&& margin
> 0)
15940 /* Compute how much to move the window start backward from
15941 point so that point will be displayed where the user
15945 centering_position
= it
.last_visible_y
;
15947 centering_position
-= pt_offset
;
15948 centering_position
-=
15949 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15950 + WINDOW_HEADER_LINE_HEIGHT (w
);
15951 /* Don't let point enter the scroll margin near top of
15953 if (centering_position
< margin
* frame_line_height
)
15954 centering_position
= margin
* frame_line_height
;
15957 centering_position
= margin
* frame_line_height
+ pt_offset
;
15960 /* Set the window start half the height of the window backward
15962 centering_position
= window_box_height (w
) / 2;
15964 move_it_vertically_backward (&it
, centering_position
);
15966 eassert (IT_CHARPOS (it
) >= BEGV
);
15968 /* The function move_it_vertically_backward may move over more
15969 than the specified y-distance. If it->w is small, e.g. a
15970 mini-buffer window, we may end up in front of the window's
15971 display area. Start displaying at the start of the line
15972 containing PT in this case. */
15973 if (it
.current_y
<= 0)
15975 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15976 move_it_vertically_backward (&it
, 0);
15980 it
.current_x
= it
.hpos
= 0;
15982 /* Set the window start position here explicitly, to avoid an
15983 infinite loop in case the functions in window-scroll-functions
15985 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15987 /* Run scroll hooks. */
15988 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15990 /* Redisplay the window. */
15991 if (!current_matrix_up_to_date_p
15992 || windows_or_buffers_changed
15993 || cursor_type_changed
15994 /* Don't use try_window_reusing_current_matrix in this case
15995 because it can have changed the buffer. */
15996 || !NILP (Vwindow_scroll_functions
)
15997 || !just_this_one_p
15998 || MINI_WINDOW_P (w
)
15999 || !(used_current_matrix_p
16000 = try_window_reusing_current_matrix (w
)))
16001 try_window (window
, startp
, 0);
16003 /* If new fonts have been loaded (due to fontsets), give up. We
16004 have to start a new redisplay since we need to re-adjust glyph
16006 if (fonts_changed_p
)
16007 goto need_larger_matrices
;
16009 /* If cursor did not appear assume that the middle of the window is
16010 in the first line of the window. Do it again with the next line.
16011 (Imagine a window of height 100, displaying two lines of height
16012 60. Moving back 50 from it->last_visible_y will end in the first
16014 if (w
->cursor
.vpos
< 0)
16016 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16018 clear_glyph_matrix (w
->desired_matrix
);
16019 move_it_by_lines (&it
, 1);
16020 try_window (window
, it
.current
.pos
, 0);
16022 else if (PT
< IT_CHARPOS (it
))
16024 clear_glyph_matrix (w
->desired_matrix
);
16025 move_it_by_lines (&it
, -1);
16026 try_window (window
, it
.current
.pos
, 0);
16030 /* Not much we can do about it. */
16034 /* Consider the following case: Window starts at BEGV, there is
16035 invisible, intangible text at BEGV, so that display starts at
16036 some point START > BEGV. It can happen that we are called with
16037 PT somewhere between BEGV and START. Try to handle that case. */
16038 if (w
->cursor
.vpos
< 0)
16040 struct glyph_row
*row
= w
->current_matrix
->rows
;
16041 if (row
->mode_line_p
)
16043 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16046 if (!cursor_row_fully_visible_p (w
, 0, 0))
16048 /* If vscroll is enabled, disable it and try again. */
16052 clear_glyph_matrix (w
->desired_matrix
);
16056 /* Users who set scroll-conservatively to a large number want
16057 point just above/below the scroll margin. If we ended up
16058 with point's row partially visible, move the window start to
16059 make that row fully visible and out of the margin. */
16060 if (scroll_conservatively
> SCROLL_LIMIT
)
16062 int window_total_lines
16063 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16066 ? min (scroll_margin
, window_total_lines
/ 4)
16068 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16070 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16071 clear_glyph_matrix (w
->desired_matrix
);
16072 if (1 == try_window (window
, it
.current
.pos
,
16073 TRY_WINDOW_CHECK_MARGINS
))
16077 /* If centering point failed to make the whole line visible,
16078 put point at the top instead. That has to make the whole line
16079 visible, if it can be done. */
16080 if (centering_position
== 0)
16083 clear_glyph_matrix (w
->desired_matrix
);
16084 centering_position
= 0;
16090 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16091 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16092 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16094 /* Display the mode line, if we must. */
16095 if ((update_mode_line
16096 /* If window not full width, must redo its mode line
16097 if (a) the window to its side is being redone and
16098 (b) we do a frame-based redisplay. This is a consequence
16099 of how inverted lines are drawn in frame-based redisplay. */
16100 || (!just_this_one_p
16101 && !FRAME_WINDOW_P (f
)
16102 && !WINDOW_FULL_WIDTH_P (w
))
16103 /* Line number to display. */
16104 || w
->base_line_pos
> 0
16105 /* Column number is displayed and different from the one displayed. */
16106 || (w
->column_number_displayed
!= -1
16107 && (w
->column_number_displayed
!= current_column ())))
16108 /* This means that the window has a mode line. */
16109 && (WINDOW_WANTS_MODELINE_P (w
)
16110 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16112 display_mode_lines (w
);
16114 /* If mode line height has changed, arrange for a thorough
16115 immediate redisplay using the correct mode line height. */
16116 if (WINDOW_WANTS_MODELINE_P (w
)
16117 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16119 fonts_changed_p
= 1;
16120 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16121 = DESIRED_MODE_LINE_HEIGHT (w
);
16124 /* If header line height has changed, arrange for a thorough
16125 immediate redisplay using the correct header line height. */
16126 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16127 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16129 fonts_changed_p
= 1;
16130 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16131 = DESIRED_HEADER_LINE_HEIGHT (w
);
16134 if (fonts_changed_p
)
16135 goto need_larger_matrices
;
16138 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16140 w
->base_line_pos
= 0;
16141 w
->base_line_number
= 0;
16146 /* When we reach a frame's selected window, redo the frame's menu bar. */
16147 if (update_mode_line
16148 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16150 int redisplay_menu_p
= 0;
16152 if (FRAME_WINDOW_P (f
))
16154 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16155 || defined (HAVE_NS) || defined (USE_GTK)
16156 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16158 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16162 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16164 if (redisplay_menu_p
)
16165 display_menu_bar (w
);
16167 #ifdef HAVE_WINDOW_SYSTEM
16168 if (FRAME_WINDOW_P (f
))
16170 #if defined (USE_GTK) || defined (HAVE_NS)
16171 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16172 redisplay_tool_bar (f
);
16174 if (WINDOWP (f
->tool_bar_window
)
16175 && (FRAME_TOOL_BAR_LINES (f
) > 0
16176 || !NILP (Vauto_resize_tool_bars
))
16177 && redisplay_tool_bar (f
))
16178 ignore_mouse_drag_p
= 1;
16184 #ifdef HAVE_WINDOW_SYSTEM
16185 if (FRAME_WINDOW_P (f
)
16186 && update_window_fringes (w
, (just_this_one_p
16187 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16188 || w
->pseudo_window_p
)))
16192 if (draw_window_fringes (w
, 1))
16193 x_draw_vertical_border (w
);
16197 #endif /* HAVE_WINDOW_SYSTEM */
16199 /* We go to this label, with fonts_changed_p set,
16200 if it is necessary to try again using larger glyph matrices.
16201 We have to redeem the scroll bar even in this case,
16202 because the loop in redisplay_internal expects that. */
16203 need_larger_matrices
:
16205 finish_scroll_bars
:
16207 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16209 /* Set the thumb's position and size. */
16210 set_vertical_scroll_bar (w
);
16212 /* Note that we actually used the scroll bar attached to this
16213 window, so it shouldn't be deleted at the end of redisplay. */
16214 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16215 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16218 /* Restore current_buffer and value of point in it. The window
16219 update may have changed the buffer, so first make sure `opoint'
16220 is still valid (Bug#6177). */
16221 if (CHARPOS (opoint
) < BEGV
)
16222 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16223 else if (CHARPOS (opoint
) > ZV
)
16224 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16226 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16228 set_buffer_internal_1 (old
);
16229 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16230 shorter. This can be caused by log truncation in *Messages*. */
16231 if (CHARPOS (lpoint
) <= ZV
)
16232 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16234 unbind_to (count
, Qnil
);
16238 /* Build the complete desired matrix of WINDOW with a window start
16239 buffer position POS.
16241 Value is 1 if successful. It is zero if fonts were loaded during
16242 redisplay which makes re-adjusting glyph matrices necessary, and -1
16243 if point would appear in the scroll margins.
16244 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16245 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16249 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16251 struct window
*w
= XWINDOW (window
);
16253 struct glyph_row
*last_text_row
= NULL
;
16254 struct frame
*f
= XFRAME (w
->frame
);
16255 int frame_line_height
= default_line_pixel_height (w
);
16257 /* Make POS the new window start. */
16258 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16260 /* Mark cursor position as unknown. No overlay arrow seen. */
16261 w
->cursor
.vpos
= -1;
16262 overlay_arrow_seen
= 0;
16264 /* Initialize iterator and info to start at POS. */
16265 start_display (&it
, w
, pos
);
16267 /* Display all lines of W. */
16268 while (it
.current_y
< it
.last_visible_y
)
16270 if (display_line (&it
))
16271 last_text_row
= it
.glyph_row
- 1;
16272 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16276 /* Don't let the cursor end in the scroll margins. */
16277 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16278 && !MINI_WINDOW_P (w
))
16280 int this_scroll_margin
;
16281 int window_total_lines
16282 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16284 if (scroll_margin
> 0)
16286 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16287 this_scroll_margin
*= frame_line_height
;
16290 this_scroll_margin
= 0;
16292 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16293 && w
->cursor
.y
< this_scroll_margin
16294 && CHARPOS (pos
) > BEGV
16295 && IT_CHARPOS (it
) < ZV
)
16296 /* rms: considering make_cursor_line_fully_visible_p here
16297 seems to give wrong results. We don't want to recenter
16298 when the last line is partly visible, we want to allow
16299 that case to be handled in the usual way. */
16300 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16302 w
->cursor
.vpos
= -1;
16303 clear_glyph_matrix (w
->desired_matrix
);
16308 /* If bottom moved off end of frame, change mode line percentage. */
16309 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16310 w
->update_mode_line
= 1;
16312 /* Set window_end_pos to the offset of the last character displayed
16313 on the window from the end of current_buffer. Set
16314 window_end_vpos to its row number. */
16317 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16318 adjust_window_ends (w
, last_text_row
, 0);
16320 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16321 w
->window_end_vpos
)));
16325 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16326 w
->window_end_pos
= Z
- ZV
;
16327 w
->window_end_vpos
= 0;
16330 /* But that is not valid info until redisplay finishes. */
16331 w
->window_end_valid
= 0;
16337 /************************************************************************
16338 Window redisplay reusing current matrix when buffer has not changed
16339 ************************************************************************/
16341 /* Try redisplay of window W showing an unchanged buffer with a
16342 different window start than the last time it was displayed by
16343 reusing its current matrix. Value is non-zero if successful.
16344 W->start is the new window start. */
16347 try_window_reusing_current_matrix (struct window
*w
)
16349 struct frame
*f
= XFRAME (w
->frame
);
16350 struct glyph_row
*bottom_row
;
16353 struct text_pos start
, new_start
;
16354 int nrows_scrolled
, i
;
16355 struct glyph_row
*last_text_row
;
16356 struct glyph_row
*last_reused_text_row
;
16357 struct glyph_row
*start_row
;
16358 int start_vpos
, min_y
, max_y
;
16361 if (inhibit_try_window_reusing
)
16365 if (/* This function doesn't handle terminal frames. */
16366 !FRAME_WINDOW_P (f
)
16367 /* Don't try to reuse the display if windows have been split
16369 || windows_or_buffers_changed
16370 || cursor_type_changed
)
16373 /* Can't do this if region may have changed. */
16374 if (markpos_of_region () >= 0
16375 || w
->region_showing
16376 || !NILP (Vshow_trailing_whitespace
))
16379 /* If top-line visibility has changed, give up. */
16380 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16381 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16384 /* Give up if old or new display is scrolled vertically. We could
16385 make this function handle this, but right now it doesn't. */
16386 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16387 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16390 /* The variable new_start now holds the new window start. The old
16391 start `start' can be determined from the current matrix. */
16392 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16393 start
= start_row
->minpos
;
16394 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16396 /* Clear the desired matrix for the display below. */
16397 clear_glyph_matrix (w
->desired_matrix
);
16399 if (CHARPOS (new_start
) <= CHARPOS (start
))
16401 /* Don't use this method if the display starts with an ellipsis
16402 displayed for invisible text. It's not easy to handle that case
16403 below, and it's certainly not worth the effort since this is
16404 not a frequent case. */
16405 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16408 IF_DEBUG (debug_method_add (w
, "twu1"));
16410 /* Display up to a row that can be reused. The variable
16411 last_text_row is set to the last row displayed that displays
16412 text. Note that it.vpos == 0 if or if not there is a
16413 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16414 start_display (&it
, w
, new_start
);
16415 w
->cursor
.vpos
= -1;
16416 last_text_row
= last_reused_text_row
= NULL
;
16418 while (it
.current_y
< it
.last_visible_y
16419 && !fonts_changed_p
)
16421 /* If we have reached into the characters in the START row,
16422 that means the line boundaries have changed. So we
16423 can't start copying with the row START. Maybe it will
16424 work to start copying with the following row. */
16425 while (IT_CHARPOS (it
) > CHARPOS (start
))
16427 /* Advance to the next row as the "start". */
16429 start
= start_row
->minpos
;
16430 /* If there are no more rows to try, or just one, give up. */
16431 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16432 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16433 || CHARPOS (start
) == ZV
)
16435 clear_glyph_matrix (w
->desired_matrix
);
16439 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16441 /* If we have reached alignment, we can copy the rest of the
16443 if (IT_CHARPOS (it
) == CHARPOS (start
)
16444 /* Don't accept "alignment" inside a display vector,
16445 since start_row could have started in the middle of
16446 that same display vector (thus their character
16447 positions match), and we have no way of telling if
16448 that is the case. */
16449 && it
.current
.dpvec_index
< 0)
16452 if (display_line (&it
))
16453 last_text_row
= it
.glyph_row
- 1;
16457 /* A value of current_y < last_visible_y means that we stopped
16458 at the previous window start, which in turn means that we
16459 have at least one reusable row. */
16460 if (it
.current_y
< it
.last_visible_y
)
16462 struct glyph_row
*row
;
16464 /* IT.vpos always starts from 0; it counts text lines. */
16465 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16467 /* Find PT if not already found in the lines displayed. */
16468 if (w
->cursor
.vpos
< 0)
16470 int dy
= it
.current_y
- start_row
->y
;
16472 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16473 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16475 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16476 dy
, nrows_scrolled
);
16479 clear_glyph_matrix (w
->desired_matrix
);
16484 /* Scroll the display. Do it before the current matrix is
16485 changed. The problem here is that update has not yet
16486 run, i.e. part of the current matrix is not up to date.
16487 scroll_run_hook will clear the cursor, and use the
16488 current matrix to get the height of the row the cursor is
16490 run
.current_y
= start_row
->y
;
16491 run
.desired_y
= it
.current_y
;
16492 run
.height
= it
.last_visible_y
- it
.current_y
;
16494 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16497 FRAME_RIF (f
)->update_window_begin_hook (w
);
16498 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16499 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16500 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16504 /* Shift current matrix down by nrows_scrolled lines. */
16505 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16506 rotate_matrix (w
->current_matrix
,
16508 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16511 /* Disable lines that must be updated. */
16512 for (i
= 0; i
< nrows_scrolled
; ++i
)
16513 (start_row
+ i
)->enabled_p
= 0;
16515 /* Re-compute Y positions. */
16516 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16517 max_y
= it
.last_visible_y
;
16518 for (row
= start_row
+ nrows_scrolled
;
16522 row
->y
= it
.current_y
;
16523 row
->visible_height
= row
->height
;
16525 if (row
->y
< min_y
)
16526 row
->visible_height
-= min_y
- row
->y
;
16527 if (row
->y
+ row
->height
> max_y
)
16528 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16529 if (row
->fringe_bitmap_periodic_p
)
16530 row
->redraw_fringe_bitmaps_p
= 1;
16532 it
.current_y
+= row
->height
;
16534 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16535 last_reused_text_row
= row
;
16536 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16540 /* Disable lines in the current matrix which are now
16541 below the window. */
16542 for (++row
; row
< bottom_row
; ++row
)
16543 row
->enabled_p
= row
->mode_line_p
= 0;
16546 /* Update window_end_pos etc.; last_reused_text_row is the last
16547 reused row from the current matrix containing text, if any.
16548 The value of last_text_row is the last displayed line
16549 containing text. */
16550 if (last_reused_text_row
)
16551 adjust_window_ends (w
, last_reused_text_row
, 1);
16552 else if (last_text_row
)
16553 adjust_window_ends (w
, last_text_row
, 0);
16556 /* This window must be completely empty. */
16557 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16558 w
->window_end_pos
= Z
- ZV
;
16559 w
->window_end_vpos
= 0;
16561 w
->window_end_valid
= 0;
16563 /* Update hint: don't try scrolling again in update_window. */
16564 w
->desired_matrix
->no_scrolling_p
= 1;
16567 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16571 else if (CHARPOS (new_start
) > CHARPOS (start
))
16573 struct glyph_row
*pt_row
, *row
;
16574 struct glyph_row
*first_reusable_row
;
16575 struct glyph_row
*first_row_to_display
;
16577 int yb
= window_text_bottom_y (w
);
16579 /* Find the row starting at new_start, if there is one. Don't
16580 reuse a partially visible line at the end. */
16581 first_reusable_row
= start_row
;
16582 while (first_reusable_row
->enabled_p
16583 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16584 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16585 < CHARPOS (new_start
)))
16586 ++first_reusable_row
;
16588 /* Give up if there is no row to reuse. */
16589 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16590 || !first_reusable_row
->enabled_p
16591 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16592 != CHARPOS (new_start
)))
16595 /* We can reuse fully visible rows beginning with
16596 first_reusable_row to the end of the window. Set
16597 first_row_to_display to the first row that cannot be reused.
16598 Set pt_row to the row containing point, if there is any. */
16600 for (first_row_to_display
= first_reusable_row
;
16601 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16602 ++first_row_to_display
)
16604 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16605 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16606 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16607 && first_row_to_display
->ends_at_zv_p
16608 && pt_row
== NULL
)))
16609 pt_row
= first_row_to_display
;
16612 /* Start displaying at the start of first_row_to_display. */
16613 eassert (first_row_to_display
->y
< yb
);
16614 init_to_row_start (&it
, w
, first_row_to_display
);
16616 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16618 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16620 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16621 + WINDOW_HEADER_LINE_HEIGHT (w
));
16623 /* Display lines beginning with first_row_to_display in the
16624 desired matrix. Set last_text_row to the last row displayed
16625 that displays text. */
16626 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16627 if (pt_row
== NULL
)
16628 w
->cursor
.vpos
= -1;
16629 last_text_row
= NULL
;
16630 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16631 if (display_line (&it
))
16632 last_text_row
= it
.glyph_row
- 1;
16634 /* If point is in a reused row, adjust y and vpos of the cursor
16638 w
->cursor
.vpos
-= nrows_scrolled
;
16639 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16642 /* Give up if point isn't in a row displayed or reused. (This
16643 also handles the case where w->cursor.vpos < nrows_scrolled
16644 after the calls to display_line, which can happen with scroll
16645 margins. See bug#1295.) */
16646 if (w
->cursor
.vpos
< 0)
16648 clear_glyph_matrix (w
->desired_matrix
);
16652 /* Scroll the display. */
16653 run
.current_y
= first_reusable_row
->y
;
16654 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16655 run
.height
= it
.last_visible_y
- run
.current_y
;
16656 dy
= run
.current_y
- run
.desired_y
;
16661 FRAME_RIF (f
)->update_window_begin_hook (w
);
16662 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16663 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16664 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16668 /* Adjust Y positions of reused rows. */
16669 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16670 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16671 max_y
= it
.last_visible_y
;
16672 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16675 row
->visible_height
= row
->height
;
16676 if (row
->y
< min_y
)
16677 row
->visible_height
-= min_y
- row
->y
;
16678 if (row
->y
+ row
->height
> max_y
)
16679 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16680 if (row
->fringe_bitmap_periodic_p
)
16681 row
->redraw_fringe_bitmaps_p
= 1;
16684 /* Scroll the current matrix. */
16685 eassert (nrows_scrolled
> 0);
16686 rotate_matrix (w
->current_matrix
,
16688 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16691 /* Disable rows not reused. */
16692 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16693 row
->enabled_p
= 0;
16695 /* Point may have moved to a different line, so we cannot assume that
16696 the previous cursor position is valid; locate the correct row. */
16699 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16701 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16702 && !row
->ends_at_zv_p
;
16706 w
->cursor
.y
= row
->y
;
16708 if (row
< bottom_row
)
16710 /* Can't simply scan the row for point with
16711 bidi-reordered glyph rows. Let set_cursor_from_row
16712 figure out where to put the cursor, and if it fails,
16714 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16716 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16719 clear_glyph_matrix (w
->desired_matrix
);
16725 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16726 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16729 && (!BUFFERP (glyph
->object
)
16730 || glyph
->charpos
< PT
);
16734 w
->cursor
.x
+= glyph
->pixel_width
;
16740 /* Adjust window end. A null value of last_text_row means that
16741 the window end is in reused rows which in turn means that
16742 only its vpos can have changed. */
16744 adjust_window_ends (w
, last_text_row
, 0);
16746 w
->window_end_vpos
-= nrows_scrolled
;
16748 w
->window_end_valid
= 0;
16749 w
->desired_matrix
->no_scrolling_p
= 1;
16752 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16762 /************************************************************************
16763 Window redisplay reusing current matrix when buffer has changed
16764 ************************************************************************/
16766 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16767 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16768 ptrdiff_t *, ptrdiff_t *);
16769 static struct glyph_row
*
16770 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16771 struct glyph_row
*);
16774 /* Return the last row in MATRIX displaying text. If row START is
16775 non-null, start searching with that row. IT gives the dimensions
16776 of the display. Value is null if matrix is empty; otherwise it is
16777 a pointer to the row found. */
16779 static struct glyph_row
*
16780 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16781 struct glyph_row
*start
)
16783 struct glyph_row
*row
, *row_found
;
16785 /* Set row_found to the last row in IT->w's current matrix
16786 displaying text. The loop looks funny but think of partially
16789 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16790 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16792 eassert (row
->enabled_p
);
16794 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16803 /* Return the last row in the current matrix of W that is not affected
16804 by changes at the start of current_buffer that occurred since W's
16805 current matrix was built. Value is null if no such row exists.
16807 BEG_UNCHANGED us the number of characters unchanged at the start of
16808 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16809 first changed character in current_buffer. Characters at positions <
16810 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16811 when the current matrix was built. */
16813 static struct glyph_row
*
16814 find_last_unchanged_at_beg_row (struct window
*w
)
16816 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16817 struct glyph_row
*row
;
16818 struct glyph_row
*row_found
= NULL
;
16819 int yb
= window_text_bottom_y (w
);
16821 /* Find the last row displaying unchanged text. */
16822 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16823 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16824 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16827 if (/* If row ends before first_changed_pos, it is unchanged,
16828 except in some case. */
16829 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16830 /* When row ends in ZV and we write at ZV it is not
16832 && !row
->ends_at_zv_p
16833 /* When first_changed_pos is the end of a continued line,
16834 row is not unchanged because it may be no longer
16836 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16837 && (row
->continued_p
16838 || row
->exact_window_width_line_p
))
16839 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16840 needs to be recomputed, so don't consider this row as
16841 unchanged. This happens when the last line was
16842 bidi-reordered and was killed immediately before this
16843 redisplay cycle. In that case, ROW->end stores the
16844 buffer position of the first visual-order character of
16845 the killed text, which is now beyond ZV. */
16846 && CHARPOS (row
->end
.pos
) <= ZV
)
16849 /* Stop if last visible row. */
16850 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16858 /* Find the first glyph row in the current matrix of W that is not
16859 affected by changes at the end of current_buffer since the
16860 time W's current matrix was built.
16862 Return in *DELTA the number of chars by which buffer positions in
16863 unchanged text at the end of current_buffer must be adjusted.
16865 Return in *DELTA_BYTES the corresponding number of bytes.
16867 Value is null if no such row exists, i.e. all rows are affected by
16870 static struct glyph_row
*
16871 find_first_unchanged_at_end_row (struct window
*w
,
16872 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16874 struct glyph_row
*row
;
16875 struct glyph_row
*row_found
= NULL
;
16877 *delta
= *delta_bytes
= 0;
16879 /* Display must not have been paused, otherwise the current matrix
16880 is not up to date. */
16881 eassert (w
->window_end_valid
);
16883 /* A value of window_end_pos >= END_UNCHANGED means that the window
16884 end is in the range of changed text. If so, there is no
16885 unchanged row at the end of W's current matrix. */
16886 if (w
->window_end_pos
>= END_UNCHANGED
)
16889 /* Set row to the last row in W's current matrix displaying text. */
16890 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16892 /* If matrix is entirely empty, no unchanged row exists. */
16893 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16895 /* The value of row is the last glyph row in the matrix having a
16896 meaningful buffer position in it. The end position of row
16897 corresponds to window_end_pos. This allows us to translate
16898 buffer positions in the current matrix to current buffer
16899 positions for characters not in changed text. */
16901 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16902 ptrdiff_t Z_BYTE_old
=
16903 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16904 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16905 struct glyph_row
*first_text_row
16906 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16908 *delta
= Z
- Z_old
;
16909 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16911 /* Set last_unchanged_pos to the buffer position of the last
16912 character in the buffer that has not been changed. Z is the
16913 index + 1 of the last character in current_buffer, i.e. by
16914 subtracting END_UNCHANGED we get the index of the last
16915 unchanged character, and we have to add BEG to get its buffer
16917 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16918 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16920 /* Search backward from ROW for a row displaying a line that
16921 starts at a minimum position >= last_unchanged_pos_old. */
16922 for (; row
> first_text_row
; --row
)
16924 /* This used to abort, but it can happen.
16925 It is ok to just stop the search instead here. KFS. */
16926 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16929 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16934 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16940 /* Make sure that glyph rows in the current matrix of window W
16941 reference the same glyph memory as corresponding rows in the
16942 frame's frame matrix. This function is called after scrolling W's
16943 current matrix on a terminal frame in try_window_id and
16944 try_window_reusing_current_matrix. */
16947 sync_frame_with_window_matrix_rows (struct window
*w
)
16949 struct frame
*f
= XFRAME (w
->frame
);
16950 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16952 /* Preconditions: W must be a leaf window and full-width. Its frame
16953 must have a frame matrix. */
16954 eassert (BUFFERP (w
->contents
));
16955 eassert (WINDOW_FULL_WIDTH_P (w
));
16956 eassert (!FRAME_WINDOW_P (f
));
16958 /* If W is a full-width window, glyph pointers in W's current matrix
16959 have, by definition, to be the same as glyph pointers in the
16960 corresponding frame matrix. Note that frame matrices have no
16961 marginal areas (see build_frame_matrix). */
16962 window_row
= w
->current_matrix
->rows
;
16963 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16964 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16965 while (window_row
< window_row_end
)
16967 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16968 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16970 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16971 frame_row
->glyphs
[TEXT_AREA
] = start
;
16972 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16973 frame_row
->glyphs
[LAST_AREA
] = end
;
16975 /* Disable frame rows whose corresponding window rows have
16976 been disabled in try_window_id. */
16977 if (!window_row
->enabled_p
)
16978 frame_row
->enabled_p
= 0;
16980 ++window_row
, ++frame_row
;
16985 /* Find the glyph row in window W containing CHARPOS. Consider all
16986 rows between START and END (not inclusive). END null means search
16987 all rows to the end of the display area of W. Value is the row
16988 containing CHARPOS or null. */
16991 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16992 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16994 struct glyph_row
*row
= start
;
16995 struct glyph_row
*best_row
= NULL
;
16996 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
16999 /* If we happen to start on a header-line, skip that. */
17000 if (row
->mode_line_p
)
17003 if ((end
&& row
>= end
) || !row
->enabled_p
)
17006 last_y
= window_text_bottom_y (w
) - dy
;
17010 /* Give up if we have gone too far. */
17011 if (end
&& row
>= end
)
17013 /* This formerly returned if they were equal.
17014 I think that both quantities are of a "last plus one" type;
17015 if so, when they are equal, the row is within the screen. -- rms. */
17016 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17019 /* If it is in this row, return this row. */
17020 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17021 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17022 /* The end position of a row equals the start
17023 position of the next row. If CHARPOS is there, we
17024 would rather consider it displayed in the next
17025 line, except when this line ends in ZV. */
17026 && !row_for_charpos_p (row
, charpos
)))
17027 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17031 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17032 || (!best_row
&& !row
->continued_p
))
17034 /* In bidi-reordered rows, there could be several rows whose
17035 edges surround CHARPOS, all of these rows belonging to
17036 the same continued line. We need to find the row which
17037 fits CHARPOS the best. */
17038 for (g
= row
->glyphs
[TEXT_AREA
];
17039 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17042 if (!STRINGP (g
->object
))
17044 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17046 mindif
= eabs (g
->charpos
- charpos
);
17048 /* Exact match always wins. */
17055 else if (best_row
&& !row
->continued_p
)
17062 /* Try to redisplay window W by reusing its existing display. W's
17063 current matrix must be up to date when this function is called,
17064 i.e. window_end_valid must be nonzero.
17068 1 if display has been updated
17069 0 if otherwise unsuccessful
17070 -1 if redisplay with same window start is known not to succeed
17072 The following steps are performed:
17074 1. Find the last row in the current matrix of W that is not
17075 affected by changes at the start of current_buffer. If no such row
17078 2. Find the first row in W's current matrix that is not affected by
17079 changes at the end of current_buffer. Maybe there is no such row.
17081 3. Display lines beginning with the row + 1 found in step 1 to the
17082 row found in step 2 or, if step 2 didn't find a row, to the end of
17085 4. If cursor is not known to appear on the window, give up.
17087 5. If display stopped at the row found in step 2, scroll the
17088 display and current matrix as needed.
17090 6. Maybe display some lines at the end of W, if we must. This can
17091 happen under various circumstances, like a partially visible line
17092 becoming fully visible, or because newly displayed lines are displayed
17093 in smaller font sizes.
17095 7. Update W's window end information. */
17098 try_window_id (struct window
*w
)
17100 struct frame
*f
= XFRAME (w
->frame
);
17101 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17102 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17103 struct glyph_row
*last_unchanged_at_beg_row
;
17104 struct glyph_row
*first_unchanged_at_end_row
;
17105 struct glyph_row
*row
;
17106 struct glyph_row
*bottom_row
;
17109 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17111 struct text_pos start_pos
;
17113 int first_unchanged_at_end_vpos
= 0;
17114 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17115 struct text_pos start
;
17116 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17119 if (inhibit_try_window_id
)
17123 /* This is handy for debugging. */
17125 #define GIVE_UP(X) \
17127 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17131 #define GIVE_UP(X) return 0
17134 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17136 /* Don't use this for mini-windows because these can show
17137 messages and mini-buffers, and we don't handle that here. */
17138 if (MINI_WINDOW_P (w
))
17141 /* This flag is used to prevent redisplay optimizations. */
17142 if (windows_or_buffers_changed
|| cursor_type_changed
)
17145 /* Verify that narrowing has not changed.
17146 Also verify that we were not told to prevent redisplay optimizations.
17147 It would be nice to further
17148 reduce the number of cases where this prevents try_window_id. */
17149 if (current_buffer
->clip_changed
17150 || current_buffer
->prevent_redisplay_optimizations_p
)
17153 /* Window must either use window-based redisplay or be full width. */
17154 if (!FRAME_WINDOW_P (f
)
17155 && (!FRAME_LINE_INS_DEL_OK (f
)
17156 || !WINDOW_FULL_WIDTH_P (w
)))
17159 /* Give up if point is known NOT to appear in W. */
17160 if (PT
< CHARPOS (start
))
17163 /* Another way to prevent redisplay optimizations. */
17164 if (w
->last_modified
== 0)
17167 /* Verify that window is not hscrolled. */
17168 if (w
->hscroll
!= 0)
17171 /* Verify that display wasn't paused. */
17172 if (!w
->window_end_valid
)
17175 /* Can't use this if highlighting a region because a cursor movement
17176 will do more than just set the cursor. */
17177 if (markpos_of_region () >= 0)
17180 /* Likewise if highlighting trailing whitespace. */
17181 if (!NILP (Vshow_trailing_whitespace
))
17184 /* Likewise if showing a region. */
17185 if (w
->region_showing
)
17188 /* Can't use this if overlay arrow position and/or string have
17190 if (overlay_arrows_changed_p ())
17193 /* When word-wrap is on, adding a space to the first word of a
17194 wrapped line can change the wrap position, altering the line
17195 above it. It might be worthwhile to handle this more
17196 intelligently, but for now just redisplay from scratch. */
17197 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17200 /* Under bidi reordering, adding or deleting a character in the
17201 beginning of a paragraph, before the first strong directional
17202 character, can change the base direction of the paragraph (unless
17203 the buffer specifies a fixed paragraph direction), which will
17204 require to redisplay the whole paragraph. It might be worthwhile
17205 to find the paragraph limits and widen the range of redisplayed
17206 lines to that, but for now just give up this optimization and
17207 redisplay from scratch. */
17208 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17209 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17212 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17213 only if buffer has really changed. The reason is that the gap is
17214 initially at Z for freshly visited files. The code below would
17215 set end_unchanged to 0 in that case. */
17216 if (MODIFF
> SAVE_MODIFF
17217 /* This seems to happen sometimes after saving a buffer. */
17218 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17220 if (GPT
- BEG
< BEG_UNCHANGED
)
17221 BEG_UNCHANGED
= GPT
- BEG
;
17222 if (Z
- GPT
< END_UNCHANGED
)
17223 END_UNCHANGED
= Z
- GPT
;
17226 /* The position of the first and last character that has been changed. */
17227 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17228 last_changed_charpos
= Z
- END_UNCHANGED
;
17230 /* If window starts after a line end, and the last change is in
17231 front of that newline, then changes don't affect the display.
17232 This case happens with stealth-fontification. Note that although
17233 the display is unchanged, glyph positions in the matrix have to
17234 be adjusted, of course. */
17235 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17236 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17237 && ((last_changed_charpos
< CHARPOS (start
)
17238 && CHARPOS (start
) == BEGV
)
17239 || (last_changed_charpos
< CHARPOS (start
) - 1
17240 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17242 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17243 struct glyph_row
*r0
;
17245 /* Compute how many chars/bytes have been added to or removed
17246 from the buffer. */
17247 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17248 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17249 Z_delta
= Z
- Z_old
;
17250 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17252 /* Give up if PT is not in the window. Note that it already has
17253 been checked at the start of try_window_id that PT is not in
17254 front of the window start. */
17255 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17258 /* If window start is unchanged, we can reuse the whole matrix
17259 as is, after adjusting glyph positions. No need to compute
17260 the window end again, since its offset from Z hasn't changed. */
17261 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17262 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17263 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17264 /* PT must not be in a partially visible line. */
17265 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17266 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17268 /* Adjust positions in the glyph matrix. */
17269 if (Z_delta
|| Z_delta_bytes
)
17271 struct glyph_row
*r1
17272 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17273 increment_matrix_positions (w
->current_matrix
,
17274 MATRIX_ROW_VPOS (r0
, current_matrix
),
17275 MATRIX_ROW_VPOS (r1
, current_matrix
),
17276 Z_delta
, Z_delta_bytes
);
17279 /* Set the cursor. */
17280 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17282 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17289 /* Handle the case that changes are all below what is displayed in
17290 the window, and that PT is in the window. This shortcut cannot
17291 be taken if ZV is visible in the window, and text has been added
17292 there that is visible in the window. */
17293 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17294 /* ZV is not visible in the window, or there are no
17295 changes at ZV, actually. */
17296 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17297 || first_changed_charpos
== last_changed_charpos
))
17299 struct glyph_row
*r0
;
17301 /* Give up if PT is not in the window. Note that it already has
17302 been checked at the start of try_window_id that PT is not in
17303 front of the window start. */
17304 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17307 /* If window start is unchanged, we can reuse the whole matrix
17308 as is, without changing glyph positions since no text has
17309 been added/removed in front of the window end. */
17310 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17311 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17312 /* PT must not be in a partially visible line. */
17313 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17314 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17316 /* We have to compute the window end anew since text
17317 could have been added/removed after it. */
17318 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17319 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17321 /* Set the cursor. */
17322 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17324 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17331 /* Give up if window start is in the changed area.
17333 The condition used to read
17335 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17337 but why that was tested escapes me at the moment. */
17338 if (CHARPOS (start
) >= first_changed_charpos
17339 && CHARPOS (start
) <= last_changed_charpos
)
17342 /* Check that window start agrees with the start of the first glyph
17343 row in its current matrix. Check this after we know the window
17344 start is not in changed text, otherwise positions would not be
17346 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17347 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17350 /* Give up if the window ends in strings. Overlay strings
17351 at the end are difficult to handle, so don't try. */
17352 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17353 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17356 /* Compute the position at which we have to start displaying new
17357 lines. Some of the lines at the top of the window might be
17358 reusable because they are not displaying changed text. Find the
17359 last row in W's current matrix not affected by changes at the
17360 start of current_buffer. Value is null if changes start in the
17361 first line of window. */
17362 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17363 if (last_unchanged_at_beg_row
)
17365 /* Avoid starting to display in the middle of a character, a TAB
17366 for instance. This is easier than to set up the iterator
17367 exactly, and it's not a frequent case, so the additional
17368 effort wouldn't really pay off. */
17369 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17370 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17371 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17372 --last_unchanged_at_beg_row
;
17374 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17377 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17379 start_pos
= it
.current
.pos
;
17381 /* Start displaying new lines in the desired matrix at the same
17382 vpos we would use in the current matrix, i.e. below
17383 last_unchanged_at_beg_row. */
17384 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17386 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17387 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17389 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17393 /* There are no reusable lines at the start of the window.
17394 Start displaying in the first text line. */
17395 start_display (&it
, w
, start
);
17396 it
.vpos
= it
.first_vpos
;
17397 start_pos
= it
.current
.pos
;
17400 /* Find the first row that is not affected by changes at the end of
17401 the buffer. Value will be null if there is no unchanged row, in
17402 which case we must redisplay to the end of the window. delta
17403 will be set to the value by which buffer positions beginning with
17404 first_unchanged_at_end_row have to be adjusted due to text
17406 first_unchanged_at_end_row
17407 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17408 IF_DEBUG (debug_delta
= delta
);
17409 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17411 /* Set stop_pos to the buffer position up to which we will have to
17412 display new lines. If first_unchanged_at_end_row != NULL, this
17413 is the buffer position of the start of the line displayed in that
17414 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17415 that we don't stop at a buffer position. */
17417 if (first_unchanged_at_end_row
)
17419 eassert (last_unchanged_at_beg_row
== NULL
17420 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17422 /* If this is a continuation line, move forward to the next one
17423 that isn't. Changes in lines above affect this line.
17424 Caution: this may move first_unchanged_at_end_row to a row
17425 not displaying text. */
17426 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17427 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17428 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17429 < it
.last_visible_y
))
17430 ++first_unchanged_at_end_row
;
17432 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17433 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17434 >= it
.last_visible_y
))
17435 first_unchanged_at_end_row
= NULL
;
17438 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17440 first_unchanged_at_end_vpos
17441 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17442 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17445 else if (last_unchanged_at_beg_row
== NULL
)
17451 /* Either there is no unchanged row at the end, or the one we have
17452 now displays text. This is a necessary condition for the window
17453 end pos calculation at the end of this function. */
17454 eassert (first_unchanged_at_end_row
== NULL
17455 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17457 debug_last_unchanged_at_beg_vpos
17458 = (last_unchanged_at_beg_row
17459 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17461 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17463 #endif /* GLYPH_DEBUG */
17466 /* Display new lines. Set last_text_row to the last new line
17467 displayed which has text on it, i.e. might end up as being the
17468 line where the window_end_vpos is. */
17469 w
->cursor
.vpos
= -1;
17470 last_text_row
= NULL
;
17471 overlay_arrow_seen
= 0;
17472 while (it
.current_y
< it
.last_visible_y
17473 && !fonts_changed_p
17474 && (first_unchanged_at_end_row
== NULL
17475 || IT_CHARPOS (it
) < stop_pos
))
17477 if (display_line (&it
))
17478 last_text_row
= it
.glyph_row
- 1;
17481 if (fonts_changed_p
)
17485 /* Compute differences in buffer positions, y-positions etc. for
17486 lines reused at the bottom of the window. Compute what we can
17488 if (first_unchanged_at_end_row
17489 /* No lines reused because we displayed everything up to the
17490 bottom of the window. */
17491 && it
.current_y
< it
.last_visible_y
)
17494 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17496 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17497 run
.current_y
= first_unchanged_at_end_row
->y
;
17498 run
.desired_y
= run
.current_y
+ dy
;
17499 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17503 delta
= delta_bytes
= dvpos
= dy
17504 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17505 first_unchanged_at_end_row
= NULL
;
17507 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17510 /* Find the cursor if not already found. We have to decide whether
17511 PT will appear on this window (it sometimes doesn't, but this is
17512 not a very frequent case.) This decision has to be made before
17513 the current matrix is altered. A value of cursor.vpos < 0 means
17514 that PT is either in one of the lines beginning at
17515 first_unchanged_at_end_row or below the window. Don't care for
17516 lines that might be displayed later at the window end; as
17517 mentioned, this is not a frequent case. */
17518 if (w
->cursor
.vpos
< 0)
17520 /* Cursor in unchanged rows at the top? */
17521 if (PT
< CHARPOS (start_pos
)
17522 && last_unchanged_at_beg_row
)
17524 row
= row_containing_pos (w
, PT
,
17525 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17526 last_unchanged_at_beg_row
+ 1, 0);
17528 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17531 /* Start from first_unchanged_at_end_row looking for PT. */
17532 else if (first_unchanged_at_end_row
)
17534 row
= row_containing_pos (w
, PT
- delta
,
17535 first_unchanged_at_end_row
, NULL
, 0);
17537 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17538 delta_bytes
, dy
, dvpos
);
17541 /* Give up if cursor was not found. */
17542 if (w
->cursor
.vpos
< 0)
17544 clear_glyph_matrix (w
->desired_matrix
);
17549 /* Don't let the cursor end in the scroll margins. */
17551 int this_scroll_margin
, cursor_height
;
17552 int frame_line_height
= default_line_pixel_height (w
);
17553 int window_total_lines
17554 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17556 this_scroll_margin
=
17557 max (0, min (scroll_margin
, window_total_lines
/ 4));
17558 this_scroll_margin
*= frame_line_height
;
17559 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17561 if ((w
->cursor
.y
< this_scroll_margin
17562 && CHARPOS (start
) > BEGV
)
17563 /* Old redisplay didn't take scroll margin into account at the bottom,
17564 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17565 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17566 ? cursor_height
+ this_scroll_margin
17567 : 1)) > it
.last_visible_y
)
17569 w
->cursor
.vpos
= -1;
17570 clear_glyph_matrix (w
->desired_matrix
);
17575 /* Scroll the display. Do it before changing the current matrix so
17576 that xterm.c doesn't get confused about where the cursor glyph is
17578 if (dy
&& run
.height
)
17582 if (FRAME_WINDOW_P (f
))
17584 FRAME_RIF (f
)->update_window_begin_hook (w
);
17585 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17586 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17587 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17591 /* Terminal frame. In this case, dvpos gives the number of
17592 lines to scroll by; dvpos < 0 means scroll up. */
17594 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17595 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17596 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17597 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17598 + window_internal_height (w
));
17600 #if defined (HAVE_GPM) || defined (MSDOS)
17601 x_clear_window_mouse_face (w
);
17603 /* Perform the operation on the screen. */
17606 /* Scroll last_unchanged_at_beg_row to the end of the
17607 window down dvpos lines. */
17608 set_terminal_window (f
, end
);
17610 /* On dumb terminals delete dvpos lines at the end
17611 before inserting dvpos empty lines. */
17612 if (!FRAME_SCROLL_REGION_OK (f
))
17613 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17615 /* Insert dvpos empty lines in front of
17616 last_unchanged_at_beg_row. */
17617 ins_del_lines (f
, from
, dvpos
);
17619 else if (dvpos
< 0)
17621 /* Scroll up last_unchanged_at_beg_vpos to the end of
17622 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17623 set_terminal_window (f
, end
);
17625 /* Delete dvpos lines in front of
17626 last_unchanged_at_beg_vpos. ins_del_lines will set
17627 the cursor to the given vpos and emit |dvpos| delete
17629 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17631 /* On a dumb terminal insert dvpos empty lines at the
17633 if (!FRAME_SCROLL_REGION_OK (f
))
17634 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17637 set_terminal_window (f
, 0);
17643 /* Shift reused rows of the current matrix to the right position.
17644 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17646 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17647 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17650 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17651 bottom_vpos
, dvpos
);
17652 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17655 else if (dvpos
> 0)
17657 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17658 bottom_vpos
, dvpos
);
17659 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17660 first_unchanged_at_end_vpos
+ dvpos
);
17663 /* For frame-based redisplay, make sure that current frame and window
17664 matrix are in sync with respect to glyph memory. */
17665 if (!FRAME_WINDOW_P (f
))
17666 sync_frame_with_window_matrix_rows (w
);
17668 /* Adjust buffer positions in reused rows. */
17669 if (delta
|| delta_bytes
)
17670 increment_matrix_positions (current_matrix
,
17671 first_unchanged_at_end_vpos
+ dvpos
,
17672 bottom_vpos
, delta
, delta_bytes
);
17674 /* Adjust Y positions. */
17676 shift_glyph_matrix (w
, current_matrix
,
17677 first_unchanged_at_end_vpos
+ dvpos
,
17680 if (first_unchanged_at_end_row
)
17682 first_unchanged_at_end_row
+= dvpos
;
17683 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17684 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17685 first_unchanged_at_end_row
= NULL
;
17688 /* If scrolling up, there may be some lines to display at the end of
17690 last_text_row_at_end
= NULL
;
17693 /* Scrolling up can leave for example a partially visible line
17694 at the end of the window to be redisplayed. */
17695 /* Set last_row to the glyph row in the current matrix where the
17696 window end line is found. It has been moved up or down in
17697 the matrix by dvpos. */
17698 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17699 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17701 /* If last_row is the window end line, it should display text. */
17702 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17704 /* If window end line was partially visible before, begin
17705 displaying at that line. Otherwise begin displaying with the
17706 line following it. */
17707 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17709 init_to_row_start (&it
, w
, last_row
);
17710 it
.vpos
= last_vpos
;
17711 it
.current_y
= last_row
->y
;
17715 init_to_row_end (&it
, w
, last_row
);
17716 it
.vpos
= 1 + last_vpos
;
17717 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17721 /* We may start in a continuation line. If so, we have to
17722 get the right continuation_lines_width and current_x. */
17723 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17724 it
.hpos
= it
.current_x
= 0;
17726 /* Display the rest of the lines at the window end. */
17727 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17728 while (it
.current_y
< it
.last_visible_y
17729 && !fonts_changed_p
)
17731 /* Is it always sure that the display agrees with lines in
17732 the current matrix? I don't think so, so we mark rows
17733 displayed invalid in the current matrix by setting their
17734 enabled_p flag to zero. */
17735 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17736 if (display_line (&it
))
17737 last_text_row_at_end
= it
.glyph_row
- 1;
17741 /* Update window_end_pos and window_end_vpos. */
17742 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17744 /* Window end line if one of the preserved rows from the current
17745 matrix. Set row to the last row displaying text in current
17746 matrix starting at first_unchanged_at_end_row, after
17748 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17749 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17750 first_unchanged_at_end_row
);
17751 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17752 adjust_window_ends (w
, row
, 1);
17753 eassert (w
->window_end_bytepos
>= 0);
17754 IF_DEBUG (debug_method_add (w
, "A"));
17756 else if (last_text_row_at_end
)
17758 adjust_window_ends (w
, last_text_row_at_end
, 0);
17759 eassert (w
->window_end_bytepos
>= 0);
17760 IF_DEBUG (debug_method_add (w
, "B"));
17762 else if (last_text_row
)
17764 /* We have displayed either to the end of the window or at the
17765 end of the window, i.e. the last row with text is to be found
17766 in the desired matrix. */
17767 adjust_window_ends (w
, last_text_row
, 0);
17768 eassert (w
->window_end_bytepos
>= 0);
17770 else if (first_unchanged_at_end_row
== NULL
17771 && last_text_row
== NULL
17772 && last_text_row_at_end
== NULL
)
17774 /* Displayed to end of window, but no line containing text was
17775 displayed. Lines were deleted at the end of the window. */
17776 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17777 int vpos
= w
->window_end_vpos
;
17778 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17779 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17782 row
== NULL
&& vpos
>= first_vpos
;
17783 --vpos
, --current_row
, --desired_row
)
17785 if (desired_row
->enabled_p
)
17787 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17790 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17794 eassert (row
!= NULL
);
17795 w
->window_end_vpos
= vpos
+ 1;
17796 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17797 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17798 eassert (w
->window_end_bytepos
>= 0);
17799 IF_DEBUG (debug_method_add (w
, "C"));
17804 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17805 debug_end_vpos
= w
->window_end_vpos
);
17807 /* Record that display has not been completed. */
17808 w
->window_end_valid
= 0;
17809 w
->desired_matrix
->no_scrolling_p
= 1;
17817 /***********************************************************************
17818 More debugging support
17819 ***********************************************************************/
17823 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17824 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17825 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17828 /* Dump the contents of glyph matrix MATRIX on stderr.
17830 GLYPHS 0 means don't show glyph contents.
17831 GLYPHS 1 means show glyphs in short form
17832 GLYPHS > 1 means show glyphs in long form. */
17835 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17838 for (i
= 0; i
< matrix
->nrows
; ++i
)
17839 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17843 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17844 the glyph row and area where the glyph comes from. */
17847 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17849 if (glyph
->type
== CHAR_GLYPH
17850 || glyph
->type
== GLYPHLESS_GLYPH
)
17853 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17854 glyph
- row
->glyphs
[TEXT_AREA
],
17855 (glyph
->type
== CHAR_GLYPH
17859 (BUFFERP (glyph
->object
)
17861 : (STRINGP (glyph
->object
)
17863 : (INTEGERP (glyph
->object
)
17866 glyph
->pixel_width
,
17868 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17872 glyph
->left_box_line_p
,
17873 glyph
->right_box_line_p
);
17875 else if (glyph
->type
== STRETCH_GLYPH
)
17878 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17879 glyph
- row
->glyphs
[TEXT_AREA
],
17882 (BUFFERP (glyph
->object
)
17884 : (STRINGP (glyph
->object
)
17886 : (INTEGERP (glyph
->object
)
17889 glyph
->pixel_width
,
17893 glyph
->left_box_line_p
,
17894 glyph
->right_box_line_p
);
17896 else if (glyph
->type
== IMAGE_GLYPH
)
17899 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17900 glyph
- row
->glyphs
[TEXT_AREA
],
17903 (BUFFERP (glyph
->object
)
17905 : (STRINGP (glyph
->object
)
17907 : (INTEGERP (glyph
->object
)
17910 glyph
->pixel_width
,
17914 glyph
->left_box_line_p
,
17915 glyph
->right_box_line_p
);
17917 else if (glyph
->type
== COMPOSITE_GLYPH
)
17920 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17921 glyph
- row
->glyphs
[TEXT_AREA
],
17924 (BUFFERP (glyph
->object
)
17926 : (STRINGP (glyph
->object
)
17928 : (INTEGERP (glyph
->object
)
17931 glyph
->pixel_width
,
17933 if (glyph
->u
.cmp
.automatic
)
17936 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17937 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17939 glyph
->left_box_line_p
,
17940 glyph
->right_box_line_p
);
17945 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17946 GLYPHS 0 means don't show glyph contents.
17947 GLYPHS 1 means show glyphs in short form
17948 GLYPHS > 1 means show glyphs in long form. */
17951 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17955 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17956 fprintf (stderr
, "==============================================================================\n");
17958 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17959 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17961 MATRIX_ROW_START_CHARPOS (row
),
17962 MATRIX_ROW_END_CHARPOS (row
),
17963 row
->used
[TEXT_AREA
],
17964 row
->contains_overlapping_glyphs_p
,
17966 row
->truncated_on_left_p
,
17967 row
->truncated_on_right_p
,
17969 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17970 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
17973 row
->ends_in_middle_of_char_p
,
17974 row
->starts_in_middle_of_char_p
,
17980 row
->visible_height
,
17983 /* The next 3 lines should align to "Start" in the header. */
17984 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17985 row
->end
.overlay_string_index
,
17986 row
->continuation_lines_width
);
17987 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17988 CHARPOS (row
->start
.string_pos
),
17989 CHARPOS (row
->end
.string_pos
));
17990 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17991 row
->end
.dpvec_index
);
17998 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18000 struct glyph
*glyph
= row
->glyphs
[area
];
18001 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18003 /* Glyph for a line end in text. */
18004 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18007 if (glyph
< glyph_end
)
18008 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18010 for (; glyph
< glyph_end
; ++glyph
)
18011 dump_glyph (row
, glyph
, area
);
18014 else if (glyphs
== 1)
18018 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18020 char *s
= alloca (row
->used
[area
] + 4);
18023 for (i
= 0; i
< row
->used
[area
]; ++i
)
18025 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18026 if (i
== row
->used
[area
] - 1
18027 && area
== TEXT_AREA
18028 && INTEGERP (glyph
->object
)
18029 && glyph
->type
== CHAR_GLYPH
18030 && glyph
->u
.ch
== ' ')
18032 strcpy (&s
[i
], "[\\n]");
18035 else if (glyph
->type
== CHAR_GLYPH
18036 && glyph
->u
.ch
< 0x80
18037 && glyph
->u
.ch
>= ' ')
18038 s
[i
] = glyph
->u
.ch
;
18044 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18050 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18051 Sdump_glyph_matrix
, 0, 1, "p",
18052 doc
: /* Dump the current matrix of the selected window to stderr.
18053 Shows contents of glyph row structures. With non-nil
18054 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18055 glyphs in short form, otherwise show glyphs in long form. */)
18056 (Lisp_Object glyphs
)
18058 struct window
*w
= XWINDOW (selected_window
);
18059 struct buffer
*buffer
= XBUFFER (w
->contents
);
18061 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18062 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18063 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18064 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18065 fprintf (stderr
, "=============================================\n");
18066 dump_glyph_matrix (w
->current_matrix
,
18067 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18072 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18073 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18076 struct frame
*f
= XFRAME (selected_frame
);
18077 dump_glyph_matrix (f
->current_matrix
, 1);
18082 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18083 doc
: /* Dump glyph row ROW to stderr.
18084 GLYPH 0 means don't dump glyphs.
18085 GLYPH 1 means dump glyphs in short form.
18086 GLYPH > 1 or omitted means dump glyphs in long form. */)
18087 (Lisp_Object row
, Lisp_Object glyphs
)
18089 struct glyph_matrix
*matrix
;
18092 CHECK_NUMBER (row
);
18093 matrix
= XWINDOW (selected_window
)->current_matrix
;
18095 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18096 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18098 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18103 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18104 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18105 GLYPH 0 means don't dump glyphs.
18106 GLYPH 1 means dump glyphs in short form.
18107 GLYPH > 1 or omitted means dump glyphs in long form. */)
18108 (Lisp_Object row
, Lisp_Object glyphs
)
18110 struct frame
*sf
= SELECTED_FRAME ();
18111 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18114 CHECK_NUMBER (row
);
18116 if (vpos
>= 0 && vpos
< m
->nrows
)
18117 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18118 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18123 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18124 doc
: /* Toggle tracing of redisplay.
18125 With ARG, turn tracing on if and only if ARG is positive. */)
18129 trace_redisplay_p
= !trace_redisplay_p
;
18132 arg
= Fprefix_numeric_value (arg
);
18133 trace_redisplay_p
= XINT (arg
) > 0;
18140 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18141 doc
: /* Like `format', but print result to stderr.
18142 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18143 (ptrdiff_t nargs
, Lisp_Object
*args
)
18145 Lisp_Object s
= Fformat (nargs
, args
);
18146 fprintf (stderr
, "%s", SDATA (s
));
18150 #endif /* GLYPH_DEBUG */
18154 /***********************************************************************
18155 Building Desired Matrix Rows
18156 ***********************************************************************/
18158 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18159 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18161 static struct glyph_row
*
18162 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18164 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18165 struct buffer
*buffer
= XBUFFER (w
->contents
);
18166 struct buffer
*old
= current_buffer
;
18167 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18168 int arrow_len
= SCHARS (overlay_arrow_string
);
18169 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18170 const unsigned char *p
;
18173 int n_glyphs_before
;
18175 set_buffer_temp (buffer
);
18176 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18177 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18178 SET_TEXT_POS (it
.position
, 0, 0);
18180 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18182 while (p
< arrow_end
)
18184 Lisp_Object face
, ilisp
;
18186 /* Get the next character. */
18188 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18191 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18192 if (! ASCII_CHAR_P (it
.c
))
18193 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18197 /* Get its face. */
18198 ilisp
= make_number (p
- arrow_string
);
18199 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18200 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18202 /* Compute its width, get its glyphs. */
18203 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18204 SET_TEXT_POS (it
.position
, -1, -1);
18205 PRODUCE_GLYPHS (&it
);
18207 /* If this character doesn't fit any more in the line, we have
18208 to remove some glyphs. */
18209 if (it
.current_x
> it
.last_visible_x
)
18211 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18216 set_buffer_temp (old
);
18217 return it
.glyph_row
;
18221 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18222 glyphs to insert is determined by produce_special_glyphs. */
18225 insert_left_trunc_glyphs (struct it
*it
)
18227 struct it truncate_it
;
18228 struct glyph
*from
, *end
, *to
, *toend
;
18230 eassert (!FRAME_WINDOW_P (it
->f
)
18231 || (!it
->glyph_row
->reversed_p
18232 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18233 || (it
->glyph_row
->reversed_p
18234 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18236 /* Get the truncation glyphs. */
18238 truncate_it
.current_x
= 0;
18239 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18240 truncate_it
.glyph_row
= &scratch_glyph_row
;
18241 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18242 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18243 truncate_it
.object
= make_number (0);
18244 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18246 /* Overwrite glyphs from IT with truncation glyphs. */
18247 if (!it
->glyph_row
->reversed_p
)
18249 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18251 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18252 end
= from
+ tused
;
18253 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18254 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18255 if (FRAME_WINDOW_P (it
->f
))
18257 /* On GUI frames, when variable-size fonts are displayed,
18258 the truncation glyphs may need more pixels than the row's
18259 glyphs they overwrite. We overwrite more glyphs to free
18260 enough screen real estate, and enlarge the stretch glyph
18261 on the right (see display_line), if there is one, to
18262 preserve the screen position of the truncation glyphs on
18265 struct glyph
*g
= to
;
18268 /* The first glyph could be partially visible, in which case
18269 it->glyph_row->x will be negative. But we want the left
18270 truncation glyphs to be aligned at the left margin of the
18271 window, so we override the x coordinate at which the row
18273 it
->glyph_row
->x
= 0;
18274 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18276 w
+= g
->pixel_width
;
18279 if (g
- to
- tused
> 0)
18281 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18282 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18284 used
= it
->glyph_row
->used
[TEXT_AREA
];
18285 if (it
->glyph_row
->truncated_on_right_p
18286 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18287 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18290 int extra
= w
- it
->truncation_pixel_width
;
18292 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18299 /* There may be padding glyphs left over. Overwrite them too. */
18300 if (!FRAME_WINDOW_P (it
->f
))
18302 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18304 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18311 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18315 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18317 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18318 that back to front. */
18319 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18320 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18321 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18322 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18323 if (FRAME_WINDOW_P (it
->f
))
18326 struct glyph
*g
= to
;
18328 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18330 w
+= g
->pixel_width
;
18333 if (to
- g
- tused
> 0)
18335 if (it
->glyph_row
->truncated_on_right_p
18336 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18337 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18339 int extra
= w
- it
->truncation_pixel_width
;
18341 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18345 while (from
>= end
&& to
>= toend
)
18347 if (!FRAME_WINDOW_P (it
->f
))
18349 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18352 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18353 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18354 while (from
>= end
&& to
>= toend
)
18360 /* Need to free some room before prepending additional
18362 int move_by
= from
- end
+ 1;
18363 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18364 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18366 for ( ; g
>= g0
; g
--)
18368 while (from
>= end
)
18370 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18375 /* Compute the hash code for ROW. */
18377 row_hash (struct glyph_row
*row
)
18380 unsigned hashval
= 0;
18382 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18383 for (k
= 0; k
< row
->used
[area
]; ++k
)
18384 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18385 + row
->glyphs
[area
][k
].u
.val
18386 + row
->glyphs
[area
][k
].face_id
18387 + row
->glyphs
[area
][k
].padding_p
18388 + (row
->glyphs
[area
][k
].type
<< 2));
18393 /* Compute the pixel height and width of IT->glyph_row.
18395 Most of the time, ascent and height of a display line will be equal
18396 to the max_ascent and max_height values of the display iterator
18397 structure. This is not the case if
18399 1. We hit ZV without displaying anything. In this case, max_ascent
18400 and max_height will be zero.
18402 2. We have some glyphs that don't contribute to the line height.
18403 (The glyph row flag contributes_to_line_height_p is for future
18404 pixmap extensions).
18406 The first case is easily covered by using default values because in
18407 these cases, the line height does not really matter, except that it
18408 must not be zero. */
18411 compute_line_metrics (struct it
*it
)
18413 struct glyph_row
*row
= it
->glyph_row
;
18415 if (FRAME_WINDOW_P (it
->f
))
18417 int i
, min_y
, max_y
;
18419 /* The line may consist of one space only, that was added to
18420 place the cursor on it. If so, the row's height hasn't been
18422 if (row
->height
== 0)
18424 if (it
->max_ascent
+ it
->max_descent
== 0)
18425 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18426 row
->ascent
= it
->max_ascent
;
18427 row
->height
= it
->max_ascent
+ it
->max_descent
;
18428 row
->phys_ascent
= it
->max_phys_ascent
;
18429 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18430 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18433 /* Compute the width of this line. */
18434 row
->pixel_width
= row
->x
;
18435 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18436 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18438 eassert (row
->pixel_width
>= 0);
18439 eassert (row
->ascent
>= 0 && row
->height
> 0);
18441 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18442 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18444 /* If first line's physical ascent is larger than its logical
18445 ascent, use the physical ascent, and make the row taller.
18446 This makes accented characters fully visible. */
18447 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18448 && row
->phys_ascent
> row
->ascent
)
18450 row
->height
+= row
->phys_ascent
- row
->ascent
;
18451 row
->ascent
= row
->phys_ascent
;
18454 /* Compute how much of the line is visible. */
18455 row
->visible_height
= row
->height
;
18457 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18458 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18460 if (row
->y
< min_y
)
18461 row
->visible_height
-= min_y
- row
->y
;
18462 if (row
->y
+ row
->height
> max_y
)
18463 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18467 row
->pixel_width
= row
->used
[TEXT_AREA
];
18468 if (row
->continued_p
)
18469 row
->pixel_width
-= it
->continuation_pixel_width
;
18470 else if (row
->truncated_on_right_p
)
18471 row
->pixel_width
-= it
->truncation_pixel_width
;
18472 row
->ascent
= row
->phys_ascent
= 0;
18473 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18474 row
->extra_line_spacing
= 0;
18477 /* Compute a hash code for this row. */
18478 row
->hash
= row_hash (row
);
18480 it
->max_ascent
= it
->max_descent
= 0;
18481 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18485 /* Append one space to the glyph row of iterator IT if doing a
18486 window-based redisplay. The space has the same face as
18487 IT->face_id. Value is non-zero if a space was added.
18489 This function is called to make sure that there is always one glyph
18490 at the end of a glyph row that the cursor can be set on under
18491 window-systems. (If there weren't such a glyph we would not know
18492 how wide and tall a box cursor should be displayed).
18494 At the same time this space let's a nicely handle clearing to the
18495 end of the line if the row ends in italic text. */
18498 append_space_for_newline (struct it
*it
, int default_face_p
)
18500 if (FRAME_WINDOW_P (it
->f
))
18502 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18504 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18505 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18507 /* Save some values that must not be changed.
18508 Must save IT->c and IT->len because otherwise
18509 ITERATOR_AT_END_P wouldn't work anymore after
18510 append_space_for_newline has been called. */
18511 enum display_element_type saved_what
= it
->what
;
18512 int saved_c
= it
->c
, saved_len
= it
->len
;
18513 int saved_char_to_display
= it
->char_to_display
;
18514 int saved_x
= it
->current_x
;
18515 int saved_face_id
= it
->face_id
;
18516 int saved_box_end
= it
->end_of_box_run_p
;
18517 struct text_pos saved_pos
;
18518 Lisp_Object saved_object
;
18521 saved_object
= it
->object
;
18522 saved_pos
= it
->position
;
18524 it
->what
= IT_CHARACTER
;
18525 memset (&it
->position
, 0, sizeof it
->position
);
18526 it
->object
= make_number (0);
18527 it
->c
= it
->char_to_display
= ' ';
18530 /* If the default face was remapped, be sure to use the
18531 remapped face for the appended newline. */
18532 if (default_face_p
)
18533 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18534 else if (it
->face_before_selective_p
)
18535 it
->face_id
= it
->saved_face_id
;
18536 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18537 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18538 /* In R2L rows, we will prepend a stretch glyph that will
18539 have the end_of_box_run_p flag set for it, so there's no
18540 need for the appended newline glyph to have that flag
18542 if (it
->glyph_row
->reversed_p
18543 /* But if the appended newline glyph goes all the way to
18544 the end of the row, there will be no stretch glyph,
18545 so leave the box flag set. */
18546 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18547 it
->end_of_box_run_p
= 0;
18549 PRODUCE_GLYPHS (it
);
18551 it
->override_ascent
= -1;
18552 it
->constrain_row_ascent_descent_p
= 0;
18553 it
->current_x
= saved_x
;
18554 it
->object
= saved_object
;
18555 it
->position
= saved_pos
;
18556 it
->what
= saved_what
;
18557 it
->face_id
= saved_face_id
;
18558 it
->len
= saved_len
;
18560 it
->char_to_display
= saved_char_to_display
;
18561 it
->end_of_box_run_p
= saved_box_end
;
18570 /* Extend the face of the last glyph in the text area of IT->glyph_row
18571 to the end of the display line. Called from display_line. If the
18572 glyph row is empty, add a space glyph to it so that we know the
18573 face to draw. Set the glyph row flag fill_line_p. If the glyph
18574 row is R2L, prepend a stretch glyph to cover the empty space to the
18575 left of the leftmost glyph. */
18578 extend_face_to_end_of_line (struct it
*it
)
18580 struct face
*face
, *default_face
;
18581 struct frame
*f
= it
->f
;
18583 /* If line is already filled, do nothing. Non window-system frames
18584 get a grace of one more ``pixel'' because their characters are
18585 1-``pixel'' wide, so they hit the equality too early. This grace
18586 is needed only for R2L rows that are not continued, to produce
18587 one extra blank where we could display the cursor. */
18588 if (it
->current_x
>= it
->last_visible_x
18589 + (!FRAME_WINDOW_P (f
)
18590 && it
->glyph_row
->reversed_p
18591 && !it
->glyph_row
->continued_p
))
18594 /* The default face, possibly remapped. */
18595 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18597 /* Face extension extends the background and box of IT->face_id
18598 to the end of the line. If the background equals the background
18599 of the frame, we don't have to do anything. */
18600 if (it
->face_before_selective_p
)
18601 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18603 face
= FACE_FROM_ID (f
, it
->face_id
);
18605 if (FRAME_WINDOW_P (f
)
18606 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18607 && face
->box
== FACE_NO_BOX
18608 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18610 && !it
->glyph_row
->reversed_p
)
18613 /* Set the glyph row flag indicating that the face of the last glyph
18614 in the text area has to be drawn to the end of the text area. */
18615 it
->glyph_row
->fill_line_p
= 1;
18617 /* If current character of IT is not ASCII, make sure we have the
18618 ASCII face. This will be automatically undone the next time
18619 get_next_display_element returns a multibyte character. Note
18620 that the character will always be single byte in unibyte
18622 if (!ASCII_CHAR_P (it
->c
))
18624 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18627 if (FRAME_WINDOW_P (f
))
18629 /* If the row is empty, add a space with the current face of IT,
18630 so that we know which face to draw. */
18631 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18633 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18634 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18635 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18637 #ifdef HAVE_WINDOW_SYSTEM
18638 if (it
->glyph_row
->reversed_p
)
18640 /* Prepend a stretch glyph to the row, such that the
18641 rightmost glyph will be drawn flushed all the way to the
18642 right margin of the window. The stretch glyph that will
18643 occupy the empty space, if any, to the left of the
18645 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18646 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18647 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18649 int row_width
, stretch_ascent
, stretch_width
;
18650 struct text_pos saved_pos
;
18651 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18653 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18654 row_width
+= g
->pixel_width
;
18655 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18656 if (stretch_width
> 0)
18659 (((it
->ascent
+ it
->descent
)
18660 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18661 saved_pos
= it
->position
;
18662 memset (&it
->position
, 0, sizeof it
->position
);
18663 saved_avoid_cursor
= it
->avoid_cursor_p
;
18664 it
->avoid_cursor_p
= 1;
18665 saved_face_id
= it
->face_id
;
18666 saved_box_start
= it
->start_of_box_run_p
;
18667 /* The last row's stretch glyph should get the default
18668 face, to avoid painting the rest of the window with
18669 the region face, if the region ends at ZV. */
18670 if (it
->glyph_row
->ends_at_zv_p
)
18671 it
->face_id
= default_face
->id
;
18673 it
->face_id
= face
->id
;
18674 it
->start_of_box_run_p
= 0;
18675 append_stretch_glyph (it
, make_number (0), stretch_width
,
18676 it
->ascent
+ it
->descent
, stretch_ascent
);
18677 it
->position
= saved_pos
;
18678 it
->avoid_cursor_p
= saved_avoid_cursor
;
18679 it
->face_id
= saved_face_id
;
18680 it
->start_of_box_run_p
= saved_box_start
;
18683 #endif /* HAVE_WINDOW_SYSTEM */
18687 /* Save some values that must not be changed. */
18688 int saved_x
= it
->current_x
;
18689 struct text_pos saved_pos
;
18690 Lisp_Object saved_object
;
18691 enum display_element_type saved_what
= it
->what
;
18692 int saved_face_id
= it
->face_id
;
18694 saved_object
= it
->object
;
18695 saved_pos
= it
->position
;
18697 it
->what
= IT_CHARACTER
;
18698 memset (&it
->position
, 0, sizeof it
->position
);
18699 it
->object
= make_number (0);
18700 it
->c
= it
->char_to_display
= ' ';
18702 /* The last row's blank glyphs should get the default face, to
18703 avoid painting the rest of the window with the region face,
18704 if the region ends at ZV. */
18705 if (it
->glyph_row
->ends_at_zv_p
)
18706 it
->face_id
= default_face
->id
;
18708 it
->face_id
= face
->id
;
18710 PRODUCE_GLYPHS (it
);
18712 while (it
->current_x
<= it
->last_visible_x
)
18713 PRODUCE_GLYPHS (it
);
18715 /* Don't count these blanks really. It would let us insert a left
18716 truncation glyph below and make us set the cursor on them, maybe. */
18717 it
->current_x
= saved_x
;
18718 it
->object
= saved_object
;
18719 it
->position
= saved_pos
;
18720 it
->what
= saved_what
;
18721 it
->face_id
= saved_face_id
;
18726 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18727 trailing whitespace. */
18730 trailing_whitespace_p (ptrdiff_t charpos
)
18732 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18735 while (bytepos
< ZV_BYTE
18736 && (c
= FETCH_CHAR (bytepos
),
18737 c
== ' ' || c
== '\t'))
18740 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18742 if (bytepos
!= PT_BYTE
)
18749 /* Highlight trailing whitespace, if any, in ROW. */
18752 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18754 int used
= row
->used
[TEXT_AREA
];
18758 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18759 struct glyph
*glyph
= start
+ used
- 1;
18761 if (row
->reversed_p
)
18763 /* Right-to-left rows need to be processed in the opposite
18764 direction, so swap the edge pointers. */
18766 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18769 /* Skip over glyphs inserted to display the cursor at the
18770 end of a line, for extending the face of the last glyph
18771 to the end of the line on terminals, and for truncation
18772 and continuation glyphs. */
18773 if (!row
->reversed_p
)
18775 while (glyph
>= start
18776 && glyph
->type
== CHAR_GLYPH
18777 && INTEGERP (glyph
->object
))
18782 while (glyph
<= start
18783 && glyph
->type
== CHAR_GLYPH
18784 && INTEGERP (glyph
->object
))
18788 /* If last glyph is a space or stretch, and it's trailing
18789 whitespace, set the face of all trailing whitespace glyphs in
18790 IT->glyph_row to `trailing-whitespace'. */
18791 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18792 && BUFFERP (glyph
->object
)
18793 && (glyph
->type
== STRETCH_GLYPH
18794 || (glyph
->type
== CHAR_GLYPH
18795 && glyph
->u
.ch
== ' '))
18796 && trailing_whitespace_p (glyph
->charpos
))
18798 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18802 if (!row
->reversed_p
)
18804 while (glyph
>= start
18805 && BUFFERP (glyph
->object
)
18806 && (glyph
->type
== STRETCH_GLYPH
18807 || (glyph
->type
== CHAR_GLYPH
18808 && glyph
->u
.ch
== ' ')))
18809 (glyph
--)->face_id
= face_id
;
18813 while (glyph
<= start
18814 && BUFFERP (glyph
->object
)
18815 && (glyph
->type
== STRETCH_GLYPH
18816 || (glyph
->type
== CHAR_GLYPH
18817 && glyph
->u
.ch
== ' ')))
18818 (glyph
++)->face_id
= face_id
;
18825 /* Value is non-zero if glyph row ROW should be
18826 considered to hold the buffer position CHARPOS. */
18829 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18833 if (charpos
== CHARPOS (row
->end
.pos
)
18834 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18836 /* Suppose the row ends on a string.
18837 Unless the row is continued, that means it ends on a newline
18838 in the string. If it's anything other than a display string
18839 (e.g., a before-string from an overlay), we don't want the
18840 cursor there. (This heuristic seems to give the optimal
18841 behavior for the various types of multi-line strings.)
18842 One exception: if the string has `cursor' property on one of
18843 its characters, we _do_ want the cursor there. */
18844 if (CHARPOS (row
->end
.string_pos
) >= 0)
18846 if (row
->continued_p
)
18850 /* Check for `display' property. */
18851 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18852 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18853 struct glyph
*glyph
;
18856 for (glyph
= end
; glyph
>= beg
; --glyph
)
18857 if (STRINGP (glyph
->object
))
18860 = Fget_char_property (make_number (charpos
),
18864 && display_prop_string_p (prop
, glyph
->object
));
18865 /* If there's a `cursor' property on one of the
18866 string's characters, this row is a cursor row,
18867 even though this is not a display string. */
18870 Lisp_Object s
= glyph
->object
;
18872 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18874 ptrdiff_t gpos
= glyph
->charpos
;
18876 if (!NILP (Fget_char_property (make_number (gpos
),
18888 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18890 /* If the row ends in middle of a real character,
18891 and the line is continued, we want the cursor here.
18892 That's because CHARPOS (ROW->end.pos) would equal
18893 PT if PT is before the character. */
18894 if (!row
->ends_in_ellipsis_p
)
18895 result
= row
->continued_p
;
18897 /* If the row ends in an ellipsis, then
18898 CHARPOS (ROW->end.pos) will equal point after the
18899 invisible text. We want that position to be displayed
18900 after the ellipsis. */
18903 /* If the row ends at ZV, display the cursor at the end of that
18904 row instead of at the start of the row below. */
18905 else if (row
->ends_at_zv_p
)
18914 /* Value is non-zero if glyph row ROW should be
18915 used to hold the cursor. */
18918 cursor_row_p (struct glyph_row
*row
)
18920 return row_for_charpos_p (row
, PT
);
18925 /* Push the property PROP so that it will be rendered at the current
18926 position in IT. Return 1 if PROP was successfully pushed, 0
18927 otherwise. Called from handle_line_prefix to handle the
18928 `line-prefix' and `wrap-prefix' properties. */
18931 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18933 struct text_pos pos
=
18934 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18936 eassert (it
->method
== GET_FROM_BUFFER
18937 || it
->method
== GET_FROM_DISPLAY_VECTOR
18938 || it
->method
== GET_FROM_STRING
);
18940 /* We need to save the current buffer/string position, so it will be
18941 restored by pop_it, because iterate_out_of_display_property
18942 depends on that being set correctly, but some situations leave
18943 it->position not yet set when this function is called. */
18944 push_it (it
, &pos
);
18946 if (STRINGP (prop
))
18948 if (SCHARS (prop
) == 0)
18955 it
->string_from_prefix_prop_p
= 1;
18956 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18957 it
->current
.overlay_string_index
= -1;
18958 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18959 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18960 it
->method
= GET_FROM_STRING
;
18961 it
->stop_charpos
= 0;
18963 it
->base_level_stop
= 0;
18965 /* Force paragraph direction to be that of the parent
18967 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18968 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18970 it
->paragraph_embedding
= L2R
;
18972 /* Set up the bidi iterator for this display string. */
18975 it
->bidi_it
.string
.lstring
= it
->string
;
18976 it
->bidi_it
.string
.s
= NULL
;
18977 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18978 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18979 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18980 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18981 it
->bidi_it
.w
= it
->w
;
18982 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18985 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18987 it
->method
= GET_FROM_STRETCH
;
18990 #ifdef HAVE_WINDOW_SYSTEM
18991 else if (IMAGEP (prop
))
18993 it
->what
= IT_IMAGE
;
18994 it
->image_id
= lookup_image (it
->f
, prop
);
18995 it
->method
= GET_FROM_IMAGE
;
18997 #endif /* HAVE_WINDOW_SYSTEM */
19000 pop_it (it
); /* bogus display property, give up */
19007 /* Return the character-property PROP at the current position in IT. */
19010 get_it_property (struct it
*it
, Lisp_Object prop
)
19012 Lisp_Object position
, object
= it
->object
;
19014 if (STRINGP (object
))
19015 position
= make_number (IT_STRING_CHARPOS (*it
));
19016 else if (BUFFERP (object
))
19018 position
= make_number (IT_CHARPOS (*it
));
19019 object
= it
->window
;
19024 return Fget_char_property (position
, prop
, object
);
19027 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19030 handle_line_prefix (struct it
*it
)
19032 Lisp_Object prefix
;
19034 if (it
->continuation_lines_width
> 0)
19036 prefix
= get_it_property (it
, Qwrap_prefix
);
19038 prefix
= Vwrap_prefix
;
19042 prefix
= get_it_property (it
, Qline_prefix
);
19044 prefix
= Vline_prefix
;
19046 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19048 /* If the prefix is wider than the window, and we try to wrap
19049 it, it would acquire its own wrap prefix, and so on till the
19050 iterator stack overflows. So, don't wrap the prefix. */
19051 it
->line_wrap
= TRUNCATE
;
19052 it
->avoid_cursor_p
= 1;
19058 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19059 only for R2L lines from display_line and display_string, when they
19060 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19061 the line/string needs to be continued on the next glyph row. */
19063 unproduce_glyphs (struct it
*it
, int n
)
19065 struct glyph
*glyph
, *end
;
19067 eassert (it
->glyph_row
);
19068 eassert (it
->glyph_row
->reversed_p
);
19069 eassert (it
->area
== TEXT_AREA
);
19070 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19072 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19073 n
= it
->glyph_row
->used
[TEXT_AREA
];
19074 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19075 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19076 for ( ; glyph
< end
; glyph
++)
19077 glyph
[-n
] = *glyph
;
19080 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19081 and ROW->maxpos. */
19083 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19084 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19085 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19087 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19088 lines' rows is implemented for bidi-reordered rows. */
19090 /* ROW->minpos is the value of min_pos, the minimal buffer position
19091 we have in ROW, or ROW->start.pos if that is smaller. */
19092 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19093 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19095 /* We didn't find buffer positions smaller than ROW->start, or
19096 didn't find _any_ valid buffer positions in any of the glyphs,
19097 so we must trust the iterator's computed positions. */
19098 row
->minpos
= row
->start
.pos
;
19101 max_pos
= CHARPOS (it
->current
.pos
);
19102 max_bpos
= BYTEPOS (it
->current
.pos
);
19105 /* Here are the various use-cases for ending the row, and the
19106 corresponding values for ROW->maxpos:
19108 Line ends in a newline from buffer eol_pos + 1
19109 Line is continued from buffer max_pos + 1
19110 Line is truncated on right it->current.pos
19111 Line ends in a newline from string max_pos + 1(*)
19112 (*) + 1 only when line ends in a forward scan
19113 Line is continued from string max_pos
19114 Line is continued from display vector max_pos
19115 Line is entirely from a string min_pos == max_pos
19116 Line is entirely from a display vector min_pos == max_pos
19117 Line that ends at ZV ZV
19119 If you discover other use-cases, please add them here as
19121 if (row
->ends_at_zv_p
)
19122 row
->maxpos
= it
->current
.pos
;
19123 else if (row
->used
[TEXT_AREA
])
19125 int seen_this_string
= 0;
19126 struct glyph_row
*r1
= row
- 1;
19128 /* Did we see the same display string on the previous row? */
19129 if (STRINGP (it
->object
)
19130 /* this is not the first row */
19131 && row
> it
->w
->desired_matrix
->rows
19132 /* previous row is not the header line */
19133 && !r1
->mode_line_p
19134 /* previous row also ends in a newline from a string */
19135 && r1
->ends_in_newline_from_string_p
)
19137 struct glyph
*start
, *end
;
19139 /* Search for the last glyph of the previous row that came
19140 from buffer or string. Depending on whether the row is
19141 L2R or R2L, we need to process it front to back or the
19142 other way round. */
19143 if (!r1
->reversed_p
)
19145 start
= r1
->glyphs
[TEXT_AREA
];
19146 end
= start
+ r1
->used
[TEXT_AREA
];
19147 /* Glyphs inserted by redisplay have an integer (zero)
19148 as their object. */
19150 && INTEGERP ((end
- 1)->object
)
19151 && (end
- 1)->charpos
<= 0)
19155 if (EQ ((end
- 1)->object
, it
->object
))
19156 seen_this_string
= 1;
19159 /* If all the glyphs of the previous row were inserted
19160 by redisplay, it means the previous row was
19161 produced from a single newline, which is only
19162 possible if that newline came from the same string
19163 as the one which produced this ROW. */
19164 seen_this_string
= 1;
19168 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19169 start
= end
+ r1
->used
[TEXT_AREA
];
19171 && INTEGERP ((end
+ 1)->object
)
19172 && (end
+ 1)->charpos
<= 0)
19176 if (EQ ((end
+ 1)->object
, it
->object
))
19177 seen_this_string
= 1;
19180 seen_this_string
= 1;
19183 /* Take note of each display string that covers a newline only
19184 once, the first time we see it. This is for when a display
19185 string includes more than one newline in it. */
19186 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19188 /* If we were scanning the buffer forward when we displayed
19189 the string, we want to account for at least one buffer
19190 position that belongs to this row (position covered by
19191 the display string), so that cursor positioning will
19192 consider this row as a candidate when point is at the end
19193 of the visual line represented by this row. This is not
19194 required when scanning back, because max_pos will already
19195 have a much larger value. */
19196 if (CHARPOS (row
->end
.pos
) > max_pos
)
19197 INC_BOTH (max_pos
, max_bpos
);
19198 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19200 else if (CHARPOS (it
->eol_pos
) > 0)
19201 SET_TEXT_POS (row
->maxpos
,
19202 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19203 else if (row
->continued_p
)
19205 /* If max_pos is different from IT's current position, it
19206 means IT->method does not belong to the display element
19207 at max_pos. However, it also means that the display
19208 element at max_pos was displayed in its entirety on this
19209 line, which is equivalent to saying that the next line
19210 starts at the next buffer position. */
19211 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19212 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19215 INC_BOTH (max_pos
, max_bpos
);
19216 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19219 else if (row
->truncated_on_right_p
)
19220 /* display_line already called reseat_at_next_visible_line_start,
19221 which puts the iterator at the beginning of the next line, in
19222 the logical order. */
19223 row
->maxpos
= it
->current
.pos
;
19224 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19225 /* A line that is entirely from a string/image/stretch... */
19226 row
->maxpos
= row
->minpos
;
19231 row
->maxpos
= it
->current
.pos
;
19234 /* Construct the glyph row IT->glyph_row in the desired matrix of
19235 IT->w from text at the current position of IT. See dispextern.h
19236 for an overview of struct it. Value is non-zero if
19237 IT->glyph_row displays text, as opposed to a line displaying ZV
19241 display_line (struct it
*it
)
19243 struct glyph_row
*row
= it
->glyph_row
;
19244 Lisp_Object overlay_arrow_string
;
19246 void *wrap_data
= NULL
;
19247 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19248 int wrap_row_used
= -1;
19249 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19250 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19251 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19252 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19253 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19255 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19256 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19258 /* We always start displaying at hpos zero even if hscrolled. */
19259 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19261 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19262 >= it
->w
->desired_matrix
->nrows
)
19264 it
->w
->nrows_scale_factor
++;
19265 fonts_changed_p
= 1;
19269 /* Is IT->w showing the region? */
19270 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19272 /* Clear the result glyph row and enable it. */
19273 prepare_desired_row (row
);
19275 row
->y
= it
->current_y
;
19276 row
->start
= it
->start
;
19277 row
->continuation_lines_width
= it
->continuation_lines_width
;
19278 row
->displays_text_p
= 1;
19279 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19280 it
->starts_in_middle_of_char_p
= 0;
19282 /* Arrange the overlays nicely for our purposes. Usually, we call
19283 display_line on only one line at a time, in which case this
19284 can't really hurt too much, or we call it on lines which appear
19285 one after another in the buffer, in which case all calls to
19286 recenter_overlay_lists but the first will be pretty cheap. */
19287 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19289 /* Move over display elements that are not visible because we are
19290 hscrolled. This may stop at an x-position < IT->first_visible_x
19291 if the first glyph is partially visible or if we hit a line end. */
19292 if (it
->current_x
< it
->first_visible_x
)
19294 enum move_it_result move_result
;
19296 this_line_min_pos
= row
->start
.pos
;
19297 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19298 MOVE_TO_POS
| MOVE_TO_X
);
19299 /* If we are under a large hscroll, move_it_in_display_line_to
19300 could hit the end of the line without reaching
19301 it->first_visible_x. Pretend that we did reach it. This is
19302 especially important on a TTY, where we will call
19303 extend_face_to_end_of_line, which needs to know how many
19304 blank glyphs to produce. */
19305 if (it
->current_x
< it
->first_visible_x
19306 && (move_result
== MOVE_NEWLINE_OR_CR
19307 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19308 it
->current_x
= it
->first_visible_x
;
19310 /* Record the smallest positions seen while we moved over
19311 display elements that are not visible. This is needed by
19312 redisplay_internal for optimizing the case where the cursor
19313 stays inside the same line. The rest of this function only
19314 considers positions that are actually displayed, so
19315 RECORD_MAX_MIN_POS will not otherwise record positions that
19316 are hscrolled to the left of the left edge of the window. */
19317 min_pos
= CHARPOS (this_line_min_pos
);
19318 min_bpos
= BYTEPOS (this_line_min_pos
);
19322 /* We only do this when not calling `move_it_in_display_line_to'
19323 above, because move_it_in_display_line_to calls
19324 handle_line_prefix itself. */
19325 handle_line_prefix (it
);
19328 /* Get the initial row height. This is either the height of the
19329 text hscrolled, if there is any, or zero. */
19330 row
->ascent
= it
->max_ascent
;
19331 row
->height
= it
->max_ascent
+ it
->max_descent
;
19332 row
->phys_ascent
= it
->max_phys_ascent
;
19333 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19334 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19336 /* Utility macro to record max and min buffer positions seen until now. */
19337 #define RECORD_MAX_MIN_POS(IT) \
19340 int composition_p = !STRINGP ((IT)->string) \
19341 && ((IT)->what == IT_COMPOSITION); \
19342 ptrdiff_t current_pos = \
19343 composition_p ? (IT)->cmp_it.charpos \
19344 : IT_CHARPOS (*(IT)); \
19345 ptrdiff_t current_bpos = \
19346 composition_p ? CHAR_TO_BYTE (current_pos) \
19347 : IT_BYTEPOS (*(IT)); \
19348 if (current_pos < min_pos) \
19350 min_pos = current_pos; \
19351 min_bpos = current_bpos; \
19353 if (IT_CHARPOS (*it) > max_pos) \
19355 max_pos = IT_CHARPOS (*it); \
19356 max_bpos = IT_BYTEPOS (*it); \
19361 /* Loop generating characters. The loop is left with IT on the next
19362 character to display. */
19365 int n_glyphs_before
, hpos_before
, x_before
;
19367 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19369 /* Retrieve the next thing to display. Value is zero if end of
19371 if (!get_next_display_element (it
))
19373 /* Maybe add a space at the end of this line that is used to
19374 display the cursor there under X. Set the charpos of the
19375 first glyph of blank lines not corresponding to any text
19377 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19378 row
->exact_window_width_line_p
= 1;
19379 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19380 || row
->used
[TEXT_AREA
] == 0)
19382 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19383 row
->displays_text_p
= 0;
19385 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19386 && (!MINI_WINDOW_P (it
->w
)
19387 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19388 row
->indicate_empty_line_p
= 1;
19391 it
->continuation_lines_width
= 0;
19392 row
->ends_at_zv_p
= 1;
19393 /* A row that displays right-to-left text must always have
19394 its last face extended all the way to the end of line,
19395 even if this row ends in ZV, because we still write to
19396 the screen left to right. We also need to extend the
19397 last face if the default face is remapped to some
19398 different face, otherwise the functions that clear
19399 portions of the screen will clear with the default face's
19400 background color. */
19401 if (row
->reversed_p
19402 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19403 extend_face_to_end_of_line (it
);
19407 /* Now, get the metrics of what we want to display. This also
19408 generates glyphs in `row' (which is IT->glyph_row). */
19409 n_glyphs_before
= row
->used
[TEXT_AREA
];
19412 /* Remember the line height so far in case the next element doesn't
19413 fit on the line. */
19414 if (it
->line_wrap
!= TRUNCATE
)
19416 ascent
= it
->max_ascent
;
19417 descent
= it
->max_descent
;
19418 phys_ascent
= it
->max_phys_ascent
;
19419 phys_descent
= it
->max_phys_descent
;
19421 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19423 if (IT_DISPLAYING_WHITESPACE (it
))
19427 SAVE_IT (wrap_it
, *it
, wrap_data
);
19429 wrap_row_used
= row
->used
[TEXT_AREA
];
19430 wrap_row_ascent
= row
->ascent
;
19431 wrap_row_height
= row
->height
;
19432 wrap_row_phys_ascent
= row
->phys_ascent
;
19433 wrap_row_phys_height
= row
->phys_height
;
19434 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19435 wrap_row_min_pos
= min_pos
;
19436 wrap_row_min_bpos
= min_bpos
;
19437 wrap_row_max_pos
= max_pos
;
19438 wrap_row_max_bpos
= max_bpos
;
19444 PRODUCE_GLYPHS (it
);
19446 /* If this display element was in marginal areas, continue with
19448 if (it
->area
!= TEXT_AREA
)
19450 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19451 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19452 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19453 row
->phys_height
= max (row
->phys_height
,
19454 it
->max_phys_ascent
+ it
->max_phys_descent
);
19455 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19456 it
->max_extra_line_spacing
);
19457 set_iterator_to_next (it
, 1);
19461 /* Does the display element fit on the line? If we truncate
19462 lines, we should draw past the right edge of the window. If
19463 we don't truncate, we want to stop so that we can display the
19464 continuation glyph before the right margin. If lines are
19465 continued, there are two possible strategies for characters
19466 resulting in more than 1 glyph (e.g. tabs): Display as many
19467 glyphs as possible in this line and leave the rest for the
19468 continuation line, or display the whole element in the next
19469 line. Original redisplay did the former, so we do it also. */
19470 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19471 hpos_before
= it
->hpos
;
19474 if (/* Not a newline. */
19476 /* Glyphs produced fit entirely in the line. */
19477 && it
->current_x
< it
->last_visible_x
)
19479 it
->hpos
+= nglyphs
;
19480 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19481 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19482 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19483 row
->phys_height
= max (row
->phys_height
,
19484 it
->max_phys_ascent
+ it
->max_phys_descent
);
19485 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19486 it
->max_extra_line_spacing
);
19487 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19488 row
->x
= x
- it
->first_visible_x
;
19489 /* Record the maximum and minimum buffer positions seen so
19490 far in glyphs that will be displayed by this row. */
19492 RECORD_MAX_MIN_POS (it
);
19497 struct glyph
*glyph
;
19499 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19501 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19502 new_x
= x
+ glyph
->pixel_width
;
19504 if (/* Lines are continued. */
19505 it
->line_wrap
!= TRUNCATE
19506 && (/* Glyph doesn't fit on the line. */
19507 new_x
> it
->last_visible_x
19508 /* Or it fits exactly on a window system frame. */
19509 || (new_x
== it
->last_visible_x
19510 && FRAME_WINDOW_P (it
->f
)
19511 && (row
->reversed_p
19512 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19513 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19515 /* End of a continued line. */
19518 || (new_x
== it
->last_visible_x
19519 && FRAME_WINDOW_P (it
->f
)
19520 && (row
->reversed_p
19521 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19522 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19524 /* Current glyph is the only one on the line or
19525 fits exactly on the line. We must continue
19526 the line because we can't draw the cursor
19527 after the glyph. */
19528 row
->continued_p
= 1;
19529 it
->current_x
= new_x
;
19530 it
->continuation_lines_width
+= new_x
;
19532 if (i
== nglyphs
- 1)
19534 /* If line-wrap is on, check if a previous
19535 wrap point was found. */
19536 if (wrap_row_used
> 0
19537 /* Even if there is a previous wrap
19538 point, continue the line here as
19539 usual, if (i) the previous character
19540 was a space or tab AND (ii) the
19541 current character is not. */
19543 || IT_DISPLAYING_WHITESPACE (it
)))
19546 /* Record the maximum and minimum buffer
19547 positions seen so far in glyphs that will be
19548 displayed by this row. */
19550 RECORD_MAX_MIN_POS (it
);
19551 set_iterator_to_next (it
, 1);
19552 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19554 if (!get_next_display_element (it
))
19556 row
->exact_window_width_line_p
= 1;
19557 it
->continuation_lines_width
= 0;
19558 row
->continued_p
= 0;
19559 row
->ends_at_zv_p
= 1;
19561 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19563 row
->continued_p
= 0;
19564 row
->exact_window_width_line_p
= 1;
19568 else if (it
->bidi_p
)
19569 RECORD_MAX_MIN_POS (it
);
19571 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19572 && !FRAME_WINDOW_P (it
->f
))
19574 /* A padding glyph that doesn't fit on this line.
19575 This means the whole character doesn't fit
19577 if (row
->reversed_p
)
19578 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19579 - n_glyphs_before
);
19580 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19582 /* Fill the rest of the row with continuation
19583 glyphs like in 20.x. */
19584 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19585 < row
->glyphs
[1 + TEXT_AREA
])
19586 produce_special_glyphs (it
, IT_CONTINUATION
);
19588 row
->continued_p
= 1;
19589 it
->current_x
= x_before
;
19590 it
->continuation_lines_width
+= x_before
;
19592 /* Restore the height to what it was before the
19593 element not fitting on the line. */
19594 it
->max_ascent
= ascent
;
19595 it
->max_descent
= descent
;
19596 it
->max_phys_ascent
= phys_ascent
;
19597 it
->max_phys_descent
= phys_descent
;
19599 else if (wrap_row_used
> 0)
19602 if (row
->reversed_p
)
19603 unproduce_glyphs (it
,
19604 row
->used
[TEXT_AREA
] - wrap_row_used
);
19605 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19606 it
->continuation_lines_width
+= wrap_x
;
19607 row
->used
[TEXT_AREA
] = wrap_row_used
;
19608 row
->ascent
= wrap_row_ascent
;
19609 row
->height
= wrap_row_height
;
19610 row
->phys_ascent
= wrap_row_phys_ascent
;
19611 row
->phys_height
= wrap_row_phys_height
;
19612 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19613 min_pos
= wrap_row_min_pos
;
19614 min_bpos
= wrap_row_min_bpos
;
19615 max_pos
= wrap_row_max_pos
;
19616 max_bpos
= wrap_row_max_bpos
;
19617 row
->continued_p
= 1;
19618 row
->ends_at_zv_p
= 0;
19619 row
->exact_window_width_line_p
= 0;
19620 it
->continuation_lines_width
+= x
;
19622 /* Make sure that a non-default face is extended
19623 up to the right margin of the window. */
19624 extend_face_to_end_of_line (it
);
19626 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19628 /* A TAB that extends past the right edge of the
19629 window. This produces a single glyph on
19630 window system frames. We leave the glyph in
19631 this row and let it fill the row, but don't
19632 consume the TAB. */
19633 if ((row
->reversed_p
19634 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19635 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19636 produce_special_glyphs (it
, IT_CONTINUATION
);
19637 it
->continuation_lines_width
+= it
->last_visible_x
;
19638 row
->ends_in_middle_of_char_p
= 1;
19639 row
->continued_p
= 1;
19640 glyph
->pixel_width
= it
->last_visible_x
- x
;
19641 it
->starts_in_middle_of_char_p
= 1;
19645 /* Something other than a TAB that draws past
19646 the right edge of the window. Restore
19647 positions to values before the element. */
19648 if (row
->reversed_p
)
19649 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19650 - (n_glyphs_before
+ i
));
19651 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19653 /* Display continuation glyphs. */
19654 it
->current_x
= x_before
;
19655 it
->continuation_lines_width
+= x
;
19656 if (!FRAME_WINDOW_P (it
->f
)
19657 || (row
->reversed_p
19658 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19659 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19660 produce_special_glyphs (it
, IT_CONTINUATION
);
19661 row
->continued_p
= 1;
19663 extend_face_to_end_of_line (it
);
19665 if (nglyphs
> 1 && i
> 0)
19667 row
->ends_in_middle_of_char_p
= 1;
19668 it
->starts_in_middle_of_char_p
= 1;
19671 /* Restore the height to what it was before the
19672 element not fitting on the line. */
19673 it
->max_ascent
= ascent
;
19674 it
->max_descent
= descent
;
19675 it
->max_phys_ascent
= phys_ascent
;
19676 it
->max_phys_descent
= phys_descent
;
19681 else if (new_x
> it
->first_visible_x
)
19683 /* Increment number of glyphs actually displayed. */
19686 /* Record the maximum and minimum buffer positions
19687 seen so far in glyphs that will be displayed by
19690 RECORD_MAX_MIN_POS (it
);
19692 if (x
< it
->first_visible_x
)
19693 /* Glyph is partially visible, i.e. row starts at
19694 negative X position. */
19695 row
->x
= x
- it
->first_visible_x
;
19699 /* Glyph is completely off the left margin of the
19700 window. This should not happen because of the
19701 move_it_in_display_line at the start of this
19702 function, unless the text display area of the
19703 window is empty. */
19704 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19707 /* Even if this display element produced no glyphs at all,
19708 we want to record its position. */
19709 if (it
->bidi_p
&& nglyphs
== 0)
19710 RECORD_MAX_MIN_POS (it
);
19712 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19713 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19714 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19715 row
->phys_height
= max (row
->phys_height
,
19716 it
->max_phys_ascent
+ it
->max_phys_descent
);
19717 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19718 it
->max_extra_line_spacing
);
19720 /* End of this display line if row is continued. */
19721 if (row
->continued_p
|| row
->ends_at_zv_p
)
19726 /* Is this a line end? If yes, we're also done, after making
19727 sure that a non-default face is extended up to the right
19728 margin of the window. */
19729 if (ITERATOR_AT_END_OF_LINE_P (it
))
19731 int used_before
= row
->used
[TEXT_AREA
];
19733 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19735 /* Add a space at the end of the line that is used to
19736 display the cursor there. */
19737 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19738 append_space_for_newline (it
, 0);
19740 /* Extend the face to the end of the line. */
19741 extend_face_to_end_of_line (it
);
19743 /* Make sure we have the position. */
19744 if (used_before
== 0)
19745 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19747 /* Record the position of the newline, for use in
19749 it
->eol_pos
= it
->current
.pos
;
19751 /* Consume the line end. This skips over invisible lines. */
19752 set_iterator_to_next (it
, 1);
19753 it
->continuation_lines_width
= 0;
19757 /* Proceed with next display element. Note that this skips
19758 over lines invisible because of selective display. */
19759 set_iterator_to_next (it
, 1);
19761 /* If we truncate lines, we are done when the last displayed
19762 glyphs reach past the right margin of the window. */
19763 if (it
->line_wrap
== TRUNCATE
19764 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19765 ? (it
->current_x
>= it
->last_visible_x
)
19766 : (it
->current_x
> it
->last_visible_x
)))
19768 /* Maybe add truncation glyphs. */
19769 if (!FRAME_WINDOW_P (it
->f
)
19770 || (row
->reversed_p
19771 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19772 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19776 if (!row
->reversed_p
)
19778 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19779 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19784 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19785 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19787 /* Remove any padding glyphs at the front of ROW, to
19788 make room for the truncation glyphs we will be
19789 adding below. The loop below always inserts at
19790 least one truncation glyph, so also remove the
19791 last glyph added to ROW. */
19792 unproduce_glyphs (it
, i
+ 1);
19793 /* Adjust i for the loop below. */
19794 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19797 it
->current_x
= x_before
;
19798 if (!FRAME_WINDOW_P (it
->f
))
19800 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19802 row
->used
[TEXT_AREA
] = i
;
19803 produce_special_glyphs (it
, IT_TRUNCATION
);
19808 row
->used
[TEXT_AREA
] = i
;
19809 produce_special_glyphs (it
, IT_TRUNCATION
);
19812 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19814 /* Don't truncate if we can overflow newline into fringe. */
19815 if (!get_next_display_element (it
))
19817 it
->continuation_lines_width
= 0;
19818 row
->ends_at_zv_p
= 1;
19819 row
->exact_window_width_line_p
= 1;
19822 if (ITERATOR_AT_END_OF_LINE_P (it
))
19824 row
->exact_window_width_line_p
= 1;
19825 goto at_end_of_line
;
19827 it
->current_x
= x_before
;
19830 row
->truncated_on_right_p
= 1;
19831 it
->continuation_lines_width
= 0;
19832 reseat_at_next_visible_line_start (it
, 0);
19833 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19834 it
->hpos
= hpos_before
;
19840 bidi_unshelve_cache (wrap_data
, 1);
19842 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19843 at the left window margin. */
19844 if (it
->first_visible_x
19845 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19847 if (!FRAME_WINDOW_P (it
->f
)
19848 || (row
->reversed_p
19849 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19850 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19851 insert_left_trunc_glyphs (it
);
19852 row
->truncated_on_left_p
= 1;
19855 /* Remember the position at which this line ends.
19857 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19858 cannot be before the call to find_row_edges below, since that is
19859 where these positions are determined. */
19860 row
->end
= it
->current
;
19863 row
->minpos
= row
->start
.pos
;
19864 row
->maxpos
= row
->end
.pos
;
19868 /* ROW->minpos and ROW->maxpos must be the smallest and
19869 `1 + the largest' buffer positions in ROW. But if ROW was
19870 bidi-reordered, these two positions can be anywhere in the
19871 row, so we must determine them now. */
19872 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19875 /* If the start of this line is the overlay arrow-position, then
19876 mark this glyph row as the one containing the overlay arrow.
19877 This is clearly a mess with variable size fonts. It would be
19878 better to let it be displayed like cursors under X. */
19879 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19880 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19881 !NILP (overlay_arrow_string
)))
19883 /* Overlay arrow in window redisplay is a fringe bitmap. */
19884 if (STRINGP (overlay_arrow_string
))
19886 struct glyph_row
*arrow_row
19887 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19888 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19889 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19890 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19891 struct glyph
*p2
, *end
;
19893 /* Copy the arrow glyphs. */
19894 while (glyph
< arrow_end
)
19897 /* Throw away padding glyphs. */
19899 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19900 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19906 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19911 eassert (INTEGERP (overlay_arrow_string
));
19912 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19914 overlay_arrow_seen
= 1;
19917 /* Highlight trailing whitespace. */
19918 if (!NILP (Vshow_trailing_whitespace
))
19919 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19921 /* Compute pixel dimensions of this line. */
19922 compute_line_metrics (it
);
19924 /* Implementation note: No changes in the glyphs of ROW or in their
19925 faces can be done past this point, because compute_line_metrics
19926 computes ROW's hash value and stores it within the glyph_row
19929 /* Record whether this row ends inside an ellipsis. */
19930 row
->ends_in_ellipsis_p
19931 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19932 && it
->ellipsis_p
);
19934 /* Save fringe bitmaps in this row. */
19935 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19936 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19937 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19938 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19940 it
->left_user_fringe_bitmap
= 0;
19941 it
->left_user_fringe_face_id
= 0;
19942 it
->right_user_fringe_bitmap
= 0;
19943 it
->right_user_fringe_face_id
= 0;
19945 /* Maybe set the cursor. */
19946 cvpos
= it
->w
->cursor
.vpos
;
19948 /* In bidi-reordered rows, keep checking for proper cursor
19949 position even if one has been found already, because buffer
19950 positions in such rows change non-linearly with ROW->VPOS,
19951 when a line is continued. One exception: when we are at ZV,
19952 display cursor on the first suitable glyph row, since all
19953 the empty rows after that also have their position set to ZV. */
19954 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19955 lines' rows is implemented for bidi-reordered rows. */
19957 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19958 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19959 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19960 && cursor_row_p (row
))
19961 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19963 /* Prepare for the next line. This line starts horizontally at (X
19964 HPOS) = (0 0). Vertical positions are incremented. As a
19965 convenience for the caller, IT->glyph_row is set to the next
19967 it
->current_x
= it
->hpos
= 0;
19968 it
->current_y
+= row
->height
;
19969 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19972 /* The next row should by default use the same value of the
19973 reversed_p flag as this one. set_iterator_to_next decides when
19974 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19975 the flag accordingly. */
19976 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19977 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19978 it
->start
= row
->end
;
19979 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
19981 #undef RECORD_MAX_MIN_POS
19984 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19985 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19986 doc
: /* Return paragraph direction at point in BUFFER.
19987 Value is either `left-to-right' or `right-to-left'.
19988 If BUFFER is omitted or nil, it defaults to the current buffer.
19990 Paragraph direction determines how the text in the paragraph is displayed.
19991 In left-to-right paragraphs, text begins at the left margin of the window
19992 and the reading direction is generally left to right. In right-to-left
19993 paragraphs, text begins at the right margin and is read from right to left.
19995 See also `bidi-paragraph-direction'. */)
19996 (Lisp_Object buffer
)
19998 struct buffer
*buf
= current_buffer
;
19999 struct buffer
*old
= buf
;
20001 if (! NILP (buffer
))
20003 CHECK_BUFFER (buffer
);
20004 buf
= XBUFFER (buffer
);
20007 if (NILP (BVAR (buf
, bidi_display_reordering
))
20008 || NILP (BVAR (buf
, enable_multibyte_characters
))
20009 /* When we are loading loadup.el, the character property tables
20010 needed for bidi iteration are not yet available. */
20011 || !NILP (Vpurify_flag
))
20012 return Qleft_to_right
;
20013 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20014 return BVAR (buf
, bidi_paragraph_direction
);
20017 /* Determine the direction from buffer text. We could try to
20018 use current_matrix if it is up to date, but this seems fast
20019 enough as it is. */
20020 struct bidi_it itb
;
20021 ptrdiff_t pos
= BUF_PT (buf
);
20022 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20024 void *itb_data
= bidi_shelve_cache ();
20026 set_buffer_temp (buf
);
20027 /* bidi_paragraph_init finds the base direction of the paragraph
20028 by searching forward from paragraph start. We need the base
20029 direction of the current or _previous_ paragraph, so we need
20030 to make sure we are within that paragraph. To that end, find
20031 the previous non-empty line. */
20032 if (pos
>= ZV
&& pos
> BEGV
)
20033 DEC_BOTH (pos
, bytepos
);
20034 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20035 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20037 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20038 || c
== ' ' || c
== '\t' || c
== '\f')
20040 if (bytepos
<= BEGV_BYTE
)
20045 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20048 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20049 itb
.paragraph_dir
= NEUTRAL_DIR
;
20050 itb
.string
.s
= NULL
;
20051 itb
.string
.lstring
= Qnil
;
20052 itb
.string
.bufpos
= 0;
20053 itb
.string
.unibyte
= 0;
20054 /* We have no window to use here for ignoring window-specific
20055 overlays. Using NULL for window pointer will cause
20056 compute_display_string_pos to use the current buffer. */
20058 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20059 bidi_unshelve_cache (itb_data
, 0);
20060 set_buffer_temp (old
);
20061 switch (itb
.paragraph_dir
)
20064 return Qleft_to_right
;
20067 return Qright_to_left
;
20075 DEFUN ("move-point-visually", Fmove_point_visually
,
20076 Smove_point_visually
, 1, 1, 0,
20077 doc
: /* Move point in the visual order in the specified DIRECTION.
20078 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20081 Value is the new character position of point. */)
20082 (Lisp_Object direction
)
20084 struct window
*w
= XWINDOW (selected_window
);
20085 struct buffer
*b
= XBUFFER (w
->contents
);
20086 struct glyph_row
*row
;
20088 Lisp_Object paragraph_dir
;
20090 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20091 (!(ROW)->continued_p \
20092 && INTEGERP ((GLYPH)->object) \
20093 && (GLYPH)->type == CHAR_GLYPH \
20094 && (GLYPH)->u.ch == ' ' \
20095 && (GLYPH)->charpos >= 0 \
20096 && !(GLYPH)->avoid_cursor_p)
20098 CHECK_NUMBER (direction
);
20099 dir
= XINT (direction
);
20105 /* If current matrix is up-to-date, we can use the information
20106 recorded in the glyphs, at least as long as the goal is on the
20108 if (w
->window_end_valid
20109 && !windows_or_buffers_changed
20111 && !b
->clip_changed
20112 && !b
->prevent_redisplay_optimizations_p
20113 && !window_outdated (w
)
20114 && w
->cursor
.vpos
>= 0
20115 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20116 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20118 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20119 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20120 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20122 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20124 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20126 SET_PT (g
->charpos
);
20127 w
->cursor
.vpos
= -1;
20128 return make_number (PT
);
20130 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20134 if (BUFFERP (gpt
->object
))
20137 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20138 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20140 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20142 else if (BUFFERP (g
->object
))
20143 new_pos
= g
->charpos
;
20147 w
->cursor
.vpos
= -1;
20148 return make_number (PT
);
20150 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20152 /* Glyphs inserted at the end of a non-empty line for
20153 positioning the cursor have zero charpos, so we must
20154 deduce the value of point by other means. */
20155 if (g
->charpos
> 0)
20156 SET_PT (g
->charpos
);
20157 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20159 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20160 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20163 w
->cursor
.vpos
= -1;
20164 return make_number (PT
);
20167 if (g
== e
|| INTEGERP (g
->object
))
20169 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20170 goto simulate_display
;
20171 if (!row
->reversed_p
)
20175 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20176 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20177 goto simulate_display
;
20181 if (row
->reversed_p
&& !row
->continued_p
)
20183 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20184 w
->cursor
.vpos
= -1;
20185 return make_number (PT
);
20187 g
= row
->glyphs
[TEXT_AREA
];
20188 e
= g
+ row
->used
[TEXT_AREA
];
20189 for ( ; g
< e
; g
++)
20191 if (BUFFERP (g
->object
)
20192 /* Empty lines have only one glyph, which stands
20193 for the newline, and whose charpos is the
20194 buffer position of the newline. */
20195 || ROW_GLYPH_NEWLINE_P (row
, g
)
20196 /* When the buffer ends in a newline, the line at
20197 EOB also has one glyph, but its charpos is -1. */
20198 || (row
->ends_at_zv_p
20199 && !row
->reversed_p
20200 && INTEGERP (g
->object
)
20201 && g
->type
== CHAR_GLYPH
20202 && g
->u
.ch
== ' '))
20204 if (g
->charpos
> 0)
20205 SET_PT (g
->charpos
);
20206 else if (!row
->reversed_p
20207 && row
->ends_at_zv_p
20212 w
->cursor
.vpos
= -1;
20213 return make_number (PT
);
20219 if (!row
->reversed_p
&& !row
->continued_p
)
20221 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20222 w
->cursor
.vpos
= -1;
20223 return make_number (PT
);
20225 e
= row
->glyphs
[TEXT_AREA
];
20226 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20227 for ( ; g
>= e
; g
--)
20229 if (BUFFERP (g
->object
)
20230 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20232 /* Empty R2L lines on GUI frames have the buffer
20233 position of the newline stored in the stretch
20235 || g
->type
== STRETCH_GLYPH
20236 || (row
->ends_at_zv_p
20238 && INTEGERP (g
->object
)
20239 && g
->type
== CHAR_GLYPH
20240 && g
->u
.ch
== ' '))
20242 if (g
->charpos
> 0)
20243 SET_PT (g
->charpos
);
20244 else if (row
->reversed_p
20245 && row
->ends_at_zv_p
20250 w
->cursor
.vpos
= -1;
20251 return make_number (PT
);
20260 /* If we wind up here, we failed to move by using the glyphs, so we
20261 need to simulate display instead. */
20264 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20266 paragraph_dir
= Qleft_to_right
;
20267 if (EQ (paragraph_dir
, Qright_to_left
))
20269 if (PT
<= BEGV
&& dir
< 0)
20270 xsignal0 (Qbeginning_of_buffer
);
20271 else if (PT
>= ZV
&& dir
> 0)
20272 xsignal0 (Qend_of_buffer
);
20275 struct text_pos pt
;
20277 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20279 bool overshoot_expected
= false;
20280 bool target_is_eol_p
= false;
20282 /* Setup the arena. */
20283 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20284 start_display (&it
, w
, pt
);
20286 if (it
.cmp_it
.id
< 0
20287 && it
.method
== GET_FROM_STRING
20288 && it
.area
== TEXT_AREA
20289 && it
.string_from_display_prop_p
20290 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20291 overshoot_expected
= true;
20293 /* Find the X coordinate of point. We start from the beginning
20294 of this or previous line to make sure we are before point in
20295 the logical order (since the move_it_* functions can only
20297 reseat_at_previous_visible_line_start (&it
);
20298 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20299 if (IT_CHARPOS (it
) != PT
)
20300 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20301 -1, -1, -1, MOVE_TO_POS
);
20302 pt_x
= it
.current_x
;
20304 if (dir
> 0 || overshoot_expected
)
20306 struct glyph_row
*row
= it
.glyph_row
;
20308 /* When point is at beginning of line, we don't have
20309 information about the glyph there loaded into struct
20310 it. Calling get_next_display_element fixes that. */
20312 get_next_display_element (&it
);
20313 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20314 it
.glyph_row
= NULL
;
20315 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20316 it
.glyph_row
= row
;
20317 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20318 it, lest it will become out of sync with it's buffer
20320 it
.current_x
= pt_x
;
20323 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20324 pixel_width
= it
.pixel_width
;
20325 if (overshoot_expected
&& at_eol_p
)
20327 else if (pixel_width
<= 0)
20330 /* If there's a display string at point, we are actually at the
20331 glyph to the left of point, so we need to correct the X
20333 if (overshoot_expected
)
20334 pt_x
+= pixel_width
;
20336 /* Compute target X coordinate, either to the left or to the
20337 right of point. On TTY frames, all characters have the same
20338 pixel width of 1, so we can use that. On GUI frames we don't
20339 have an easy way of getting at the pixel width of the
20340 character to the left of point, so we use a different method
20341 of getting to that place. */
20343 target_x
= pt_x
+ pixel_width
;
20345 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20347 /* Target X coordinate could be one line above or below the line
20348 of point, in which case we need to adjust the target X
20349 coordinate. Also, if moving to the left, we need to begin at
20350 the left edge of the point's screen line. */
20355 start_display (&it
, w
, pt
);
20356 reseat_at_previous_visible_line_start (&it
);
20357 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20359 move_it_by_lines (&it
, pt_vpos
);
20363 move_it_by_lines (&it
, -1);
20364 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20365 target_is_eol_p
= true;
20371 || (target_x
>= it
.last_visible_x
20372 && it
.line_wrap
!= TRUNCATE
))
20375 move_it_by_lines (&it
, 0);
20376 move_it_by_lines (&it
, 1);
20381 /* Move to the target X coordinate. */
20382 #ifdef HAVE_WINDOW_SYSTEM
20383 /* On GUI frames, as we don't know the X coordinate of the
20384 character to the left of point, moving point to the left
20385 requires walking, one grapheme cluster at a time, until we
20386 find ourself at a place immediately to the left of the
20387 character at point. */
20388 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20390 struct text_pos new_pos
= it
.current
.pos
;
20391 enum move_it_result rc
= MOVE_X_REACHED
;
20393 while (it
.current_x
+ it
.pixel_width
<= target_x
20394 && rc
== MOVE_X_REACHED
)
20396 int new_x
= it
.current_x
+ it
.pixel_width
;
20398 new_pos
= it
.current
.pos
;
20399 if (new_x
== it
.current_x
)
20401 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20402 MOVE_TO_POS
| MOVE_TO_X
);
20403 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20406 /* If we ended up on a composed character inside
20407 bidi-reordered text (e.g., Hebrew text with diacritics),
20408 the iterator gives us the buffer position of the last (in
20409 logical order) character of the composed grapheme cluster,
20410 which is not what we want. So we cheat: we compute the
20411 character position of the character that follows (in the
20412 logical order) the one where the above loop stopped. That
20413 character will appear on display to the left of point. */
20415 && it
.bidi_it
.scan_dir
== -1
20416 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20418 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20419 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20421 it
.current
.pos
= new_pos
;
20425 if (it
.current_x
!= target_x
)
20426 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20428 /* When lines are truncated, the above loop will stop at the
20429 window edge. But we want to get to the end of line, even if
20430 it is beyond the window edge; automatic hscroll will then
20431 scroll the window to show point as appropriate. */
20432 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20433 && get_next_display_element (&it
))
20435 struct text_pos new_pos
= it
.current
.pos
;
20437 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20439 set_iterator_to_next (&it
, 0);
20440 if (it
.method
== GET_FROM_BUFFER
)
20441 new_pos
= it
.current
.pos
;
20442 if (!get_next_display_element (&it
))
20446 it
.current
.pos
= new_pos
;
20449 /* If we ended up in a display string that covers point, move to
20450 buffer position to the right in the visual order. */
20453 while (IT_CHARPOS (it
) == PT
)
20455 set_iterator_to_next (&it
, 0);
20456 if (!get_next_display_element (&it
))
20461 /* Move point to that position. */
20462 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20465 return make_number (PT
);
20467 #undef ROW_GLYPH_NEWLINE_P
20471 /***********************************************************************
20473 ***********************************************************************/
20475 /* Redisplay the menu bar in the frame for window W.
20477 The menu bar of X frames that don't have X toolkit support is
20478 displayed in a special window W->frame->menu_bar_window.
20480 The menu bar of terminal frames is treated specially as far as
20481 glyph matrices are concerned. Menu bar lines are not part of
20482 windows, so the update is done directly on the frame matrix rows
20483 for the menu bar. */
20486 display_menu_bar (struct window
*w
)
20488 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20493 /* Don't do all this for graphical frames. */
20495 if (FRAME_W32_P (f
))
20498 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20504 if (FRAME_NS_P (f
))
20506 #endif /* HAVE_NS */
20508 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20509 eassert (!FRAME_WINDOW_P (f
));
20510 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20511 it
.first_visible_x
= 0;
20512 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20513 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20514 if (FRAME_WINDOW_P (f
))
20516 /* Menu bar lines are displayed in the desired matrix of the
20517 dummy window menu_bar_window. */
20518 struct window
*menu_w
;
20519 menu_w
= XWINDOW (f
->menu_bar_window
);
20520 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20522 it
.first_visible_x
= 0;
20523 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20526 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20528 /* This is a TTY frame, i.e. character hpos/vpos are used as
20530 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20532 it
.first_visible_x
= 0;
20533 it
.last_visible_x
= FRAME_COLS (f
);
20536 /* FIXME: This should be controlled by a user option. See the
20537 comments in redisplay_tool_bar and display_mode_line about
20539 it
.paragraph_embedding
= L2R
;
20541 /* Clear all rows of the menu bar. */
20542 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20544 struct glyph_row
*row
= it
.glyph_row
+ i
;
20545 clear_glyph_row (row
);
20546 row
->enabled_p
= 1;
20547 row
->full_width_p
= 1;
20550 /* Display all items of the menu bar. */
20551 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20552 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20554 Lisp_Object string
;
20556 /* Stop at nil string. */
20557 string
= AREF (items
, i
+ 1);
20561 /* Remember where item was displayed. */
20562 ASET (items
, i
+ 3, make_number (it
.hpos
));
20564 /* Display the item, pad with one space. */
20565 if (it
.current_x
< it
.last_visible_x
)
20566 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20567 SCHARS (string
) + 1, 0, 0, -1);
20570 /* Fill out the line with spaces. */
20571 if (it
.current_x
< it
.last_visible_x
)
20572 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20574 /* Compute the total height of the lines. */
20575 compute_line_metrics (&it
);
20579 /* Display one menu item on a TTY, by overwriting the glyphs in the
20580 desired glyph matrix with glyphs produced from the menu item text.
20581 Called from term.c to display TTY drop-down menus one item at a
20584 ITEM_TEXT is the menu item text as a C string.
20586 FACE_ID is the face ID to be used for this menu item. FACE_ID
20587 could specify one of 3 faces: a face for an enabled item, a face
20588 for a disabled item, or a face for a selected item.
20590 X and Y are coordinates of the first glyph in the desired matrix to
20591 be overwritten by the menu item. Since this is a TTY, Y is the
20592 glyph row and X is the glyph number in the row, where to start
20593 displaying the item.
20595 SUBMENU non-zero means this menu item drops down a submenu, which
20596 should be indicated by displaying a proper visual cue after the
20600 display_tty_menu_item (const char *item_text
, int face_id
, int x
, int y
,
20604 struct frame
*f
= SELECTED_FRAME ();
20605 struct window
*w
= XWINDOW (f
->selected_window
);
20606 int saved_used
, saved_truncated
, saved_width
;
20607 struct glyph_row
*row
;
20609 eassert (FRAME_TERMCAP_P (f
));
20611 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20612 it
.first_visible_x
= 0;
20613 it
.last_visible_x
= FRAME_COLS (f
);
20614 row
= it
.glyph_row
;
20615 saved_width
= row
->full_width_p
;
20616 row
->full_width_p
= 1;
20618 /* Arrange for the menu item glyphs to start at X and have the
20620 it
.current_x
= it
.hpos
= x
;
20621 saved_used
= row
->used
[TEXT_AREA
];
20622 saved_truncated
= row
->truncated_on_right_p
;
20623 row
->used
[TEXT_AREA
] = x
- row
->used
[LEFT_MARGIN_AREA
];
20624 it
.face_id
= face_id
;
20626 /* FIXME: This should be controlled by a user option. See the
20627 comments in redisplay_tool_bar and display_mode_line about this.
20628 Also, if paragraph_embedding could ever be R2L, changes will be
20629 needed to avoid shifting to the right the row characters in
20630 term.c:append_glyph. */
20631 it
.paragraph_embedding
= L2R
;
20635 /* Indicate with ">" that there's a submenu. */
20636 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20637 strlen (item_text
), 0, FRAME_COLS (f
) - 2, -1);
20638 display_string (">", Qnil
, Qnil
, 0, 0, &it
, 1, 0, 0, -1);
20642 /* Display the menu item, pad with one space. */
20643 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20644 strlen (item_text
) + 1, 0, 0, -1);
20647 row
->used
[TEXT_AREA
] = saved_used
;
20648 row
->truncated_on_right_p
= saved_truncated
;
20649 row
->hash
- row_hash (row
);
20650 row
->full_width_p
= saved_width
;
20652 #endif /* HAVE_MENUS */
20654 /***********************************************************************
20656 ***********************************************************************/
20658 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20659 FORCE is non-zero, redisplay mode lines unconditionally.
20660 Otherwise, redisplay only mode lines that are garbaged. Value is
20661 the number of windows whose mode lines were redisplayed. */
20664 redisplay_mode_lines (Lisp_Object window
, int force
)
20668 while (!NILP (window
))
20670 struct window
*w
= XWINDOW (window
);
20672 if (WINDOWP (w
->contents
))
20673 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20675 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20676 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20678 struct text_pos lpoint
;
20679 struct buffer
*old
= current_buffer
;
20681 /* Set the window's buffer for the mode line display. */
20682 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20683 set_buffer_internal_1 (XBUFFER (w
->contents
));
20685 /* Point refers normally to the selected window. For any
20686 other window, set up appropriate value. */
20687 if (!EQ (window
, selected_window
))
20689 struct text_pos pt
;
20691 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20692 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20695 /* Display mode lines. */
20696 clear_glyph_matrix (w
->desired_matrix
);
20697 if (display_mode_lines (w
))
20700 w
->must_be_updated_p
= 1;
20703 /* Restore old settings. */
20704 set_buffer_internal_1 (old
);
20705 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20715 /* Display the mode and/or header line of window W. Value is the
20716 sum number of mode lines and header lines displayed. */
20719 display_mode_lines (struct window
*w
)
20721 Lisp_Object old_selected_window
= selected_window
;
20722 Lisp_Object old_selected_frame
= selected_frame
;
20723 Lisp_Object new_frame
= w
->frame
;
20724 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20727 selected_frame
= new_frame
;
20728 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20729 or window's point, then we'd need select_window_1 here as well. */
20730 XSETWINDOW (selected_window
, w
);
20731 XFRAME (new_frame
)->selected_window
= selected_window
;
20733 /* These will be set while the mode line specs are processed. */
20734 line_number_displayed
= 0;
20735 w
->column_number_displayed
= -1;
20737 if (WINDOW_WANTS_MODELINE_P (w
))
20739 struct window
*sel_w
= XWINDOW (old_selected_window
);
20741 /* Select mode line face based on the real selected window. */
20742 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20743 BVAR (current_buffer
, mode_line_format
));
20747 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20749 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20750 BVAR (current_buffer
, header_line_format
));
20754 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20755 selected_frame
= old_selected_frame
;
20756 selected_window
= old_selected_window
;
20761 /* Display mode or header line of window W. FACE_ID specifies which
20762 line to display; it is either MODE_LINE_FACE_ID or
20763 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20764 display. Value is the pixel height of the mode/header line
20768 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20772 ptrdiff_t count
= SPECPDL_INDEX ();
20774 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20775 /* Don't extend on a previously drawn mode-line.
20776 This may happen if called from pos_visible_p. */
20777 it
.glyph_row
->enabled_p
= 0;
20778 prepare_desired_row (it
.glyph_row
);
20780 it
.glyph_row
->mode_line_p
= 1;
20782 /* FIXME: This should be controlled by a user option. But
20783 supporting such an option is not trivial, since the mode line is
20784 made up of many separate strings. */
20785 it
.paragraph_embedding
= L2R
;
20787 record_unwind_protect (unwind_format_mode_line
,
20788 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20790 mode_line_target
= MODE_LINE_DISPLAY
;
20792 /* Temporarily make frame's keyboard the current kboard so that
20793 kboard-local variables in the mode_line_format will get the right
20795 push_kboard (FRAME_KBOARD (it
.f
));
20796 record_unwind_save_match_data ();
20797 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20800 unbind_to (count
, Qnil
);
20802 /* Fill up with spaces. */
20803 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20805 compute_line_metrics (&it
);
20806 it
.glyph_row
->full_width_p
= 1;
20807 it
.glyph_row
->continued_p
= 0;
20808 it
.glyph_row
->truncated_on_left_p
= 0;
20809 it
.glyph_row
->truncated_on_right_p
= 0;
20811 /* Make a 3D mode-line have a shadow at its right end. */
20812 face
= FACE_FROM_ID (it
.f
, face_id
);
20813 extend_face_to_end_of_line (&it
);
20814 if (face
->box
!= FACE_NO_BOX
)
20816 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20817 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20818 last
->right_box_line_p
= 1;
20821 return it
.glyph_row
->height
;
20824 /* Move element ELT in LIST to the front of LIST.
20825 Return the updated list. */
20828 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20830 register Lisp_Object tail
, prev
;
20831 register Lisp_Object tem
;
20835 while (CONSP (tail
))
20841 /* Splice out the link TAIL. */
20843 list
= XCDR (tail
);
20845 Fsetcdr (prev
, XCDR (tail
));
20847 /* Now make it the first. */
20848 Fsetcdr (tail
, list
);
20853 tail
= XCDR (tail
);
20857 /* Not found--return unchanged LIST. */
20861 /* Contribute ELT to the mode line for window IT->w. How it
20862 translates into text depends on its data type.
20864 IT describes the display environment in which we display, as usual.
20866 DEPTH is the depth in recursion. It is used to prevent
20867 infinite recursion here.
20869 FIELD_WIDTH is the number of characters the display of ELT should
20870 occupy in the mode line, and PRECISION is the maximum number of
20871 characters to display from ELT's representation. See
20872 display_string for details.
20874 Returns the hpos of the end of the text generated by ELT.
20876 PROPS is a property list to add to any string we encounter.
20878 If RISKY is nonzero, remove (disregard) any properties in any string
20879 we encounter, and ignore :eval and :propertize.
20881 The global variable `mode_line_target' determines whether the
20882 output is passed to `store_mode_line_noprop',
20883 `store_mode_line_string', or `display_string'. */
20886 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20887 Lisp_Object elt
, Lisp_Object props
, int risky
)
20889 int n
= 0, field
, prec
;
20894 elt
= build_string ("*too-deep*");
20898 switch (XTYPE (elt
))
20902 /* A string: output it and check for %-constructs within it. */
20904 ptrdiff_t offset
= 0;
20906 if (SCHARS (elt
) > 0
20907 && (!NILP (props
) || risky
))
20909 Lisp_Object oprops
, aelt
;
20910 oprops
= Ftext_properties_at (make_number (0), elt
);
20912 /* If the starting string's properties are not what
20913 we want, translate the string. Also, if the string
20914 is risky, do that anyway. */
20916 if (NILP (Fequal (props
, oprops
)) || risky
)
20918 /* If the starting string has properties,
20919 merge the specified ones onto the existing ones. */
20920 if (! NILP (oprops
) && !risky
)
20924 oprops
= Fcopy_sequence (oprops
);
20926 while (CONSP (tem
))
20928 oprops
= Fplist_put (oprops
, XCAR (tem
),
20929 XCAR (XCDR (tem
)));
20930 tem
= XCDR (XCDR (tem
));
20935 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20936 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20938 /* AELT is what we want. Move it to the front
20939 without consing. */
20941 mode_line_proptrans_alist
20942 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20948 /* If AELT has the wrong props, it is useless.
20949 so get rid of it. */
20951 mode_line_proptrans_alist
20952 = Fdelq (aelt
, mode_line_proptrans_alist
);
20954 elt
= Fcopy_sequence (elt
);
20955 Fset_text_properties (make_number (0), Flength (elt
),
20957 /* Add this item to mode_line_proptrans_alist. */
20958 mode_line_proptrans_alist
20959 = Fcons (Fcons (elt
, props
),
20960 mode_line_proptrans_alist
);
20961 /* Truncate mode_line_proptrans_alist
20962 to at most 50 elements. */
20963 tem
= Fnthcdr (make_number (50),
20964 mode_line_proptrans_alist
);
20966 XSETCDR (tem
, Qnil
);
20975 prec
= precision
- n
;
20976 switch (mode_line_target
)
20978 case MODE_LINE_NOPROP
:
20979 case MODE_LINE_TITLE
:
20980 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20982 case MODE_LINE_STRING
:
20983 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20985 case MODE_LINE_DISPLAY
:
20986 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20987 0, prec
, 0, STRING_MULTIBYTE (elt
));
20994 /* Handle the non-literal case. */
20996 while ((precision
<= 0 || n
< precision
)
20997 && SREF (elt
, offset
) != 0
20998 && (mode_line_target
!= MODE_LINE_DISPLAY
20999 || it
->current_x
< it
->last_visible_x
))
21001 ptrdiff_t last_offset
= offset
;
21003 /* Advance to end of string or next format specifier. */
21004 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21007 if (offset
- 1 != last_offset
)
21009 ptrdiff_t nchars
, nbytes
;
21011 /* Output to end of string or up to '%'. Field width
21012 is length of string. Don't output more than
21013 PRECISION allows us. */
21016 prec
= c_string_width (SDATA (elt
) + last_offset
,
21017 offset
- last_offset
, precision
- n
,
21020 switch (mode_line_target
)
21022 case MODE_LINE_NOPROP
:
21023 case MODE_LINE_TITLE
:
21024 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21026 case MODE_LINE_STRING
:
21028 ptrdiff_t bytepos
= last_offset
;
21029 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21030 ptrdiff_t endpos
= (precision
<= 0
21031 ? string_byte_to_char (elt
, offset
)
21032 : charpos
+ nchars
);
21034 n
+= store_mode_line_string (NULL
,
21035 Fsubstring (elt
, make_number (charpos
),
21036 make_number (endpos
)),
21040 case MODE_LINE_DISPLAY
:
21042 ptrdiff_t bytepos
= last_offset
;
21043 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21045 if (precision
<= 0)
21046 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21047 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21049 STRING_MULTIBYTE (elt
));
21054 else /* c == '%' */
21056 ptrdiff_t percent_position
= offset
;
21058 /* Get the specified minimum width. Zero means
21061 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21062 field
= field
* 10 + c
- '0';
21064 /* Don't pad beyond the total padding allowed. */
21065 if (field_width
- n
> 0 && field
> field_width
- n
)
21066 field
= field_width
- n
;
21068 /* Note that either PRECISION <= 0 or N < PRECISION. */
21069 prec
= precision
- n
;
21072 n
+= display_mode_element (it
, depth
, field
, prec
,
21073 Vglobal_mode_string
, props
,
21078 ptrdiff_t bytepos
, charpos
;
21080 Lisp_Object string
;
21082 bytepos
= percent_position
;
21083 charpos
= (STRING_MULTIBYTE (elt
)
21084 ? string_byte_to_char (elt
, bytepos
)
21086 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21087 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21089 switch (mode_line_target
)
21091 case MODE_LINE_NOPROP
:
21092 case MODE_LINE_TITLE
:
21093 n
+= store_mode_line_noprop (spec
, field
, prec
);
21095 case MODE_LINE_STRING
:
21097 Lisp_Object tem
= build_string (spec
);
21098 props
= Ftext_properties_at (make_number (charpos
), elt
);
21099 /* Should only keep face property in props */
21100 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21103 case MODE_LINE_DISPLAY
:
21105 int nglyphs_before
, nwritten
;
21107 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21108 nwritten
= display_string (spec
, string
, elt
,
21113 /* Assign to the glyphs written above the
21114 string where the `%x' came from, position
21118 struct glyph
*glyph
21119 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21123 for (i
= 0; i
< nwritten
; ++i
)
21125 glyph
[i
].object
= elt
;
21126 glyph
[i
].charpos
= charpos
;
21143 /* A symbol: process the value of the symbol recursively
21144 as if it appeared here directly. Avoid error if symbol void.
21145 Special case: if value of symbol is a string, output the string
21148 register Lisp_Object tem
;
21150 /* If the variable is not marked as risky to set
21151 then its contents are risky to use. */
21152 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21155 tem
= Fboundp (elt
);
21158 tem
= Fsymbol_value (elt
);
21159 /* If value is a string, output that string literally:
21160 don't check for % within it. */
21164 if (!EQ (tem
, elt
))
21166 /* Give up right away for nil or t. */
21176 register Lisp_Object car
, tem
;
21178 /* A cons cell: five distinct cases.
21179 If first element is :eval or :propertize, do something special.
21180 If first element is a string or a cons, process all the elements
21181 and effectively concatenate them.
21182 If first element is a negative number, truncate displaying cdr to
21183 at most that many characters. If positive, pad (with spaces)
21184 to at least that many characters.
21185 If first element is a symbol, process the cadr or caddr recursively
21186 according to whether the symbol's value is non-nil or nil. */
21188 if (EQ (car
, QCeval
))
21190 /* An element of the form (:eval FORM) means evaluate FORM
21191 and use the result as mode line elements. */
21196 if (CONSP (XCDR (elt
)))
21199 spec
= safe_eval (XCAR (XCDR (elt
)));
21200 n
+= display_mode_element (it
, depth
, field_width
- n
,
21201 precision
- n
, spec
, props
,
21205 else if (EQ (car
, QCpropertize
))
21207 /* An element of the form (:propertize ELT PROPS...)
21208 means display ELT but applying properties PROPS. */
21213 if (CONSP (XCDR (elt
)))
21214 n
+= display_mode_element (it
, depth
, field_width
- n
,
21215 precision
- n
, XCAR (XCDR (elt
)),
21216 XCDR (XCDR (elt
)), risky
);
21218 else if (SYMBOLP (car
))
21220 tem
= Fboundp (car
);
21224 /* elt is now the cdr, and we know it is a cons cell.
21225 Use its car if CAR has a non-nil value. */
21228 tem
= Fsymbol_value (car
);
21235 /* Symbol's value is nil (or symbol is unbound)
21236 Get the cddr of the original list
21237 and if possible find the caddr and use that. */
21241 else if (!CONSP (elt
))
21246 else if (INTEGERP (car
))
21248 register int lim
= XINT (car
);
21252 /* Negative int means reduce maximum width. */
21253 if (precision
<= 0)
21256 precision
= min (precision
, -lim
);
21260 /* Padding specified. Don't let it be more than
21261 current maximum. */
21263 lim
= min (precision
, lim
);
21265 /* If that's more padding than already wanted, queue it.
21266 But don't reduce padding already specified even if
21267 that is beyond the current truncation point. */
21268 field_width
= max (lim
, field_width
);
21272 else if (STRINGP (car
) || CONSP (car
))
21274 Lisp_Object halftail
= elt
;
21278 && (precision
<= 0 || n
< precision
))
21280 n
+= display_mode_element (it
, depth
,
21281 /* Do padding only after the last
21282 element in the list. */
21283 (! CONSP (XCDR (elt
))
21286 precision
- n
, XCAR (elt
),
21290 if ((len
& 1) == 0)
21291 halftail
= XCDR (halftail
);
21292 /* Check for cycle. */
21293 if (EQ (halftail
, elt
))
21302 elt
= build_string ("*invalid*");
21306 /* Pad to FIELD_WIDTH. */
21307 if (field_width
> 0 && n
< field_width
)
21309 switch (mode_line_target
)
21311 case MODE_LINE_NOPROP
:
21312 case MODE_LINE_TITLE
:
21313 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21315 case MODE_LINE_STRING
:
21316 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21318 case MODE_LINE_DISPLAY
:
21319 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21328 /* Store a mode-line string element in mode_line_string_list.
21330 If STRING is non-null, display that C string. Otherwise, the Lisp
21331 string LISP_STRING is displayed.
21333 FIELD_WIDTH is the minimum number of output glyphs to produce.
21334 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21335 with spaces. FIELD_WIDTH <= 0 means don't pad.
21337 PRECISION is the maximum number of characters to output from
21338 STRING. PRECISION <= 0 means don't truncate the string.
21340 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21341 properties to the string.
21343 PROPS are the properties to add to the string.
21344 The mode_line_string_face face property is always added to the string.
21348 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21349 int field_width
, int precision
, Lisp_Object props
)
21354 if (string
!= NULL
)
21356 len
= strlen (string
);
21357 if (precision
> 0 && len
> precision
)
21359 lisp_string
= make_string (string
, len
);
21361 props
= mode_line_string_face_prop
;
21362 else if (!NILP (mode_line_string_face
))
21364 Lisp_Object face
= Fplist_get (props
, Qface
);
21365 props
= Fcopy_sequence (props
);
21367 face
= mode_line_string_face
;
21369 face
= list2 (face
, mode_line_string_face
);
21370 props
= Fplist_put (props
, Qface
, face
);
21372 Fadd_text_properties (make_number (0), make_number (len
),
21373 props
, lisp_string
);
21377 len
= XFASTINT (Flength (lisp_string
));
21378 if (precision
> 0 && len
> precision
)
21381 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21384 if (!NILP (mode_line_string_face
))
21388 props
= Ftext_properties_at (make_number (0), lisp_string
);
21389 face
= Fplist_get (props
, Qface
);
21391 face
= mode_line_string_face
;
21393 face
= list2 (face
, mode_line_string_face
);
21394 props
= list2 (Qface
, face
);
21396 lisp_string
= Fcopy_sequence (lisp_string
);
21399 Fadd_text_properties (make_number (0), make_number (len
),
21400 props
, lisp_string
);
21405 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21409 if (field_width
> len
)
21411 field_width
-= len
;
21412 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21414 Fadd_text_properties (make_number (0), make_number (field_width
),
21415 props
, lisp_string
);
21416 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21424 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21426 doc
: /* Format a string out of a mode line format specification.
21427 First arg FORMAT specifies the mode line format (see `mode-line-format'
21428 for details) to use.
21430 By default, the format is evaluated for the currently selected window.
21432 Optional second arg FACE specifies the face property to put on all
21433 characters for which no face is specified. The value nil means the
21434 default face. The value t means whatever face the window's mode line
21435 currently uses (either `mode-line' or `mode-line-inactive',
21436 depending on whether the window is the selected window or not).
21437 An integer value means the value string has no text
21440 Optional third and fourth args WINDOW and BUFFER specify the window
21441 and buffer to use as the context for the formatting (defaults
21442 are the selected window and the WINDOW's buffer). */)
21443 (Lisp_Object format
, Lisp_Object face
,
21444 Lisp_Object window
, Lisp_Object buffer
)
21449 struct buffer
*old_buffer
= NULL
;
21451 int no_props
= INTEGERP (face
);
21452 ptrdiff_t count
= SPECPDL_INDEX ();
21454 int string_start
= 0;
21456 w
= decode_any_window (window
);
21457 XSETWINDOW (window
, w
);
21460 buffer
= w
->contents
;
21461 CHECK_BUFFER (buffer
);
21463 /* Make formatting the modeline a non-op when noninteractive, otherwise
21464 there will be problems later caused by a partially initialized frame. */
21465 if (NILP (format
) || noninteractive
)
21466 return empty_unibyte_string
;
21471 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21472 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21473 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21474 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21475 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21476 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21477 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21480 old_buffer
= current_buffer
;
21482 /* Save things including mode_line_proptrans_alist,
21483 and set that to nil so that we don't alter the outer value. */
21484 record_unwind_protect (unwind_format_mode_line
,
21485 format_mode_line_unwind_data
21486 (XFRAME (WINDOW_FRAME (w
)),
21487 old_buffer
, selected_window
, 1));
21488 mode_line_proptrans_alist
= Qnil
;
21490 Fselect_window (window
, Qt
);
21491 set_buffer_internal_1 (XBUFFER (buffer
));
21493 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21497 mode_line_target
= MODE_LINE_NOPROP
;
21498 mode_line_string_face_prop
= Qnil
;
21499 mode_line_string_list
= Qnil
;
21500 string_start
= MODE_LINE_NOPROP_LEN (0);
21504 mode_line_target
= MODE_LINE_STRING
;
21505 mode_line_string_list
= Qnil
;
21506 mode_line_string_face
= face
;
21507 mode_line_string_face_prop
21508 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21511 push_kboard (FRAME_KBOARD (it
.f
));
21512 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21517 len
= MODE_LINE_NOPROP_LEN (string_start
);
21518 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21522 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21523 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21524 empty_unibyte_string
);
21527 unbind_to (count
, Qnil
);
21531 /* Write a null-terminated, right justified decimal representation of
21532 the positive integer D to BUF using a minimal field width WIDTH. */
21535 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21537 register char *p
= buf
;
21545 *p
++ = d
% 10 + '0';
21550 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21561 /* Write a null-terminated, right justified decimal and "human
21562 readable" representation of the nonnegative integer D to BUF using
21563 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21565 static const char power_letter
[] =
21579 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21581 /* We aim to represent the nonnegative integer D as
21582 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21583 ptrdiff_t quotient
= d
;
21585 /* -1 means: do not use TENTHS. */
21589 /* Length of QUOTIENT.TENTHS as a string. */
21595 if (quotient
>= 1000)
21597 /* Scale to the appropriate EXPONENT. */
21600 remainder
= quotient
% 1000;
21604 while (quotient
>= 1000);
21606 /* Round to nearest and decide whether to use TENTHS or not. */
21609 tenths
= remainder
/ 100;
21610 if (remainder
% 100 >= 50)
21617 if (quotient
== 10)
21625 if (remainder
>= 500)
21627 if (quotient
< 999)
21638 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21639 if (tenths
== -1 && quotient
<= 99)
21646 p
= psuffix
= buf
+ max (width
, length
);
21648 /* Print EXPONENT. */
21649 *psuffix
++ = power_letter
[exponent
];
21652 /* Print TENTHS. */
21655 *--p
= '0' + tenths
;
21659 /* Print QUOTIENT. */
21662 int digit
= quotient
% 10;
21663 *--p
= '0' + digit
;
21665 while ((quotient
/= 10) != 0);
21667 /* Print leading spaces. */
21672 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21673 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21674 type of CODING_SYSTEM. Return updated pointer into BUF. */
21676 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21679 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21682 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21683 const unsigned char *eol_str
;
21685 /* The EOL conversion we are using. */
21686 Lisp_Object eoltype
;
21688 val
= CODING_SYSTEM_SPEC (coding_system
);
21691 if (!VECTORP (val
)) /* Not yet decided. */
21693 *buf
++ = multibyte
? '-' : ' ';
21695 eoltype
= eol_mnemonic_undecided
;
21696 /* Don't mention EOL conversion if it isn't decided. */
21701 Lisp_Object eolvalue
;
21703 attrs
= AREF (val
, 0);
21704 eolvalue
= AREF (val
, 2);
21707 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21712 /* The EOL conversion that is normal on this system. */
21714 if (NILP (eolvalue
)) /* Not yet decided. */
21715 eoltype
= eol_mnemonic_undecided
;
21716 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21717 eoltype
= eol_mnemonic_undecided
;
21718 else /* eolvalue is Qunix, Qdos, or Qmac. */
21719 eoltype
= (EQ (eolvalue
, Qunix
)
21720 ? eol_mnemonic_unix
21721 : (EQ (eolvalue
, Qdos
) == 1
21722 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21728 /* Mention the EOL conversion if it is not the usual one. */
21729 if (STRINGP (eoltype
))
21731 eol_str
= SDATA (eoltype
);
21732 eol_str_len
= SBYTES (eoltype
);
21734 else if (CHARACTERP (eoltype
))
21736 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21737 int c
= XFASTINT (eoltype
);
21738 eol_str_len
= CHAR_STRING (c
, tmp
);
21743 eol_str
= invalid_eol_type
;
21744 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21746 memcpy (buf
, eol_str
, eol_str_len
);
21747 buf
+= eol_str_len
;
21753 /* Return a string for the output of a mode line %-spec for window W,
21754 generated by character C. FIELD_WIDTH > 0 means pad the string
21755 returned with spaces to that value. Return a Lisp string in
21756 *STRING if the resulting string is taken from that Lisp string.
21758 Note we operate on the current buffer for most purposes. */
21760 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21762 static const char *
21763 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21764 Lisp_Object
*string
)
21767 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21768 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21769 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21770 produce strings from numerical values, so limit preposterously
21771 large values of FIELD_WIDTH to avoid overrunning the buffer's
21772 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21773 bytes plus the terminating null. */
21774 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21775 struct buffer
*b
= current_buffer
;
21783 if (!NILP (BVAR (b
, read_only
)))
21785 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21790 /* This differs from %* only for a modified read-only buffer. */
21791 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21793 if (!NILP (BVAR (b
, read_only
)))
21798 /* This differs from %* in ignoring read-only-ness. */
21799 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21811 if (command_loop_level
> 5)
21813 p
= decode_mode_spec_buf
;
21814 for (i
= 0; i
< command_loop_level
; i
++)
21817 return decode_mode_spec_buf
;
21825 if (command_loop_level
> 5)
21827 p
= decode_mode_spec_buf
;
21828 for (i
= 0; i
< command_loop_level
; i
++)
21831 return decode_mode_spec_buf
;
21838 /* Let lots_of_dashes be a string of infinite length. */
21839 if (mode_line_target
== MODE_LINE_NOPROP
21840 || mode_line_target
== MODE_LINE_STRING
)
21842 if (field_width
<= 0
21843 || field_width
> sizeof (lots_of_dashes
))
21845 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21846 decode_mode_spec_buf
[i
] = '-';
21847 decode_mode_spec_buf
[i
] = '\0';
21848 return decode_mode_spec_buf
;
21851 return lots_of_dashes
;
21855 obj
= BVAR (b
, name
);
21859 /* %c and %l are ignored in `frame-title-format'.
21860 (In redisplay_internal, the frame title is drawn _before_ the
21861 windows are updated, so the stuff which depends on actual
21862 window contents (such as %l) may fail to render properly, or
21863 even crash emacs.) */
21864 if (mode_line_target
== MODE_LINE_TITLE
)
21868 ptrdiff_t col
= current_column ();
21869 w
->column_number_displayed
= col
;
21870 pint2str (decode_mode_spec_buf
, width
, col
);
21871 return decode_mode_spec_buf
;
21875 #ifndef SYSTEM_MALLOC
21877 if (NILP (Vmemory_full
))
21880 return "!MEM FULL! ";
21887 /* %F displays the frame name. */
21888 if (!NILP (f
->title
))
21889 return SSDATA (f
->title
);
21890 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21891 return SSDATA (f
->name
);
21895 obj
= BVAR (b
, filename
);
21900 ptrdiff_t size
= ZV
- BEGV
;
21901 pint2str (decode_mode_spec_buf
, width
, size
);
21902 return decode_mode_spec_buf
;
21907 ptrdiff_t size
= ZV
- BEGV
;
21908 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21909 return decode_mode_spec_buf
;
21914 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21915 ptrdiff_t topline
, nlines
, height
;
21918 /* %c and %l are ignored in `frame-title-format'. */
21919 if (mode_line_target
== MODE_LINE_TITLE
)
21922 startpos
= marker_position (w
->start
);
21923 startpos_byte
= marker_byte_position (w
->start
);
21924 height
= WINDOW_TOTAL_LINES (w
);
21926 /* If we decided that this buffer isn't suitable for line numbers,
21927 don't forget that too fast. */
21928 if (w
->base_line_pos
== -1)
21931 /* If the buffer is very big, don't waste time. */
21932 if (INTEGERP (Vline_number_display_limit
)
21933 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21935 w
->base_line_pos
= 0;
21936 w
->base_line_number
= 0;
21940 if (w
->base_line_number
> 0
21941 && w
->base_line_pos
> 0
21942 && w
->base_line_pos
<= startpos
)
21944 line
= w
->base_line_number
;
21945 linepos
= w
->base_line_pos
;
21946 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21951 linepos
= BUF_BEGV (b
);
21952 linepos_byte
= BUF_BEGV_BYTE (b
);
21955 /* Count lines from base line to window start position. */
21956 nlines
= display_count_lines (linepos_byte
,
21960 topline
= nlines
+ line
;
21962 /* Determine a new base line, if the old one is too close
21963 or too far away, or if we did not have one.
21964 "Too close" means it's plausible a scroll-down would
21965 go back past it. */
21966 if (startpos
== BUF_BEGV (b
))
21968 w
->base_line_number
= topline
;
21969 w
->base_line_pos
= BUF_BEGV (b
);
21971 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21972 || linepos
== BUF_BEGV (b
))
21974 ptrdiff_t limit
= BUF_BEGV (b
);
21975 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21976 ptrdiff_t position
;
21977 ptrdiff_t distance
=
21978 (height
* 2 + 30) * line_number_display_limit_width
;
21980 if (startpos
- distance
> limit
)
21982 limit
= startpos
- distance
;
21983 limit_byte
= CHAR_TO_BYTE (limit
);
21986 nlines
= display_count_lines (startpos_byte
,
21988 - (height
* 2 + 30),
21990 /* If we couldn't find the lines we wanted within
21991 line_number_display_limit_width chars per line,
21992 give up on line numbers for this window. */
21993 if (position
== limit_byte
&& limit
== startpos
- distance
)
21995 w
->base_line_pos
= -1;
21996 w
->base_line_number
= 0;
22000 w
->base_line_number
= topline
- nlines
;
22001 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22004 /* Now count lines from the start pos to point. */
22005 nlines
= display_count_lines (startpos_byte
,
22006 PT_BYTE
, PT
, &junk
);
22008 /* Record that we did display the line number. */
22009 line_number_displayed
= 1;
22011 /* Make the string to show. */
22012 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22013 return decode_mode_spec_buf
;
22016 char* p
= decode_mode_spec_buf
;
22017 int pad
= width
- 2;
22023 return decode_mode_spec_buf
;
22029 obj
= BVAR (b
, mode_name
);
22033 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22039 ptrdiff_t pos
= marker_position (w
->start
);
22040 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22042 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22044 if (pos
<= BUF_BEGV (b
))
22049 else if (pos
<= BUF_BEGV (b
))
22053 if (total
> 1000000)
22054 /* Do it differently for a large value, to avoid overflow. */
22055 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22057 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22058 /* We can't normally display a 3-digit number,
22059 so get us a 2-digit number that is close. */
22062 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22063 return decode_mode_spec_buf
;
22067 /* Display percentage of size above the bottom of the screen. */
22070 ptrdiff_t toppos
= marker_position (w
->start
);
22071 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22072 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22074 if (botpos
>= BUF_ZV (b
))
22076 if (toppos
<= BUF_BEGV (b
))
22083 if (total
> 1000000)
22084 /* Do it differently for a large value, to avoid overflow. */
22085 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22087 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22088 /* We can't normally display a 3-digit number,
22089 so get us a 2-digit number that is close. */
22092 if (toppos
<= BUF_BEGV (b
))
22093 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22095 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22096 return decode_mode_spec_buf
;
22101 /* status of process */
22102 obj
= Fget_buffer_process (Fcurrent_buffer ());
22104 return "no process";
22106 obj
= Fsymbol_name (Fprocess_status (obj
));
22112 ptrdiff_t count
= inhibit_garbage_collection ();
22113 Lisp_Object val
= call1 (intern ("file-remote-p"),
22114 BVAR (current_buffer
, directory
));
22115 unbind_to (count
, Qnil
);
22124 /* coding-system (not including end-of-line format) */
22126 /* coding-system (including end-of-line type) */
22128 int eol_flag
= (c
== 'Z');
22129 char *p
= decode_mode_spec_buf
;
22131 if (! FRAME_WINDOW_P (f
))
22133 /* No need to mention EOL here--the terminal never needs
22134 to do EOL conversion. */
22135 p
= decode_mode_spec_coding (CODING_ID_NAME
22136 (FRAME_KEYBOARD_CODING (f
)->id
),
22138 p
= decode_mode_spec_coding (CODING_ID_NAME
22139 (FRAME_TERMINAL_CODING (f
)->id
),
22142 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22145 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22146 #ifdef subprocesses
22147 obj
= Fget_buffer_process (Fcurrent_buffer ());
22148 if (PROCESSP (obj
))
22150 p
= decode_mode_spec_coding
22151 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22152 p
= decode_mode_spec_coding
22153 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22155 #endif /* subprocesses */
22158 return decode_mode_spec_buf
;
22165 return SSDATA (obj
);
22172 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22173 means count lines back from START_BYTE. But don't go beyond
22174 LIMIT_BYTE. Return the number of lines thus found (always
22177 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22178 either the position COUNT lines after/before START_BYTE, if we
22179 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22183 display_count_lines (ptrdiff_t start_byte
,
22184 ptrdiff_t limit_byte
, ptrdiff_t count
,
22185 ptrdiff_t *byte_pos_ptr
)
22187 register unsigned char *cursor
;
22188 unsigned char *base
;
22190 register ptrdiff_t ceiling
;
22191 register unsigned char *ceiling_addr
;
22192 ptrdiff_t orig_count
= count
;
22194 /* If we are not in selective display mode,
22195 check only for newlines. */
22196 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22197 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22201 while (start_byte
< limit_byte
)
22203 ceiling
= BUFFER_CEILING_OF (start_byte
);
22204 ceiling
= min (limit_byte
- 1, ceiling
);
22205 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22206 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22210 if (selective_display
)
22212 while (*cursor
!= '\n' && *cursor
!= 015
22213 && ++cursor
!= ceiling_addr
)
22215 if (cursor
== ceiling_addr
)
22220 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22229 start_byte
+= cursor
- base
;
22230 *byte_pos_ptr
= start_byte
;
22234 while (cursor
< ceiling_addr
);
22236 start_byte
+= ceiling_addr
- base
;
22241 while (start_byte
> limit_byte
)
22243 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22244 ceiling
= max (limit_byte
, ceiling
);
22245 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22246 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22249 if (selective_display
)
22251 while (--cursor
>= ceiling_addr
22252 && *cursor
!= '\n' && *cursor
!= 015)
22254 if (cursor
< ceiling_addr
)
22259 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22266 start_byte
+= cursor
- base
+ 1;
22267 *byte_pos_ptr
= start_byte
;
22268 /* When scanning backwards, we should
22269 not count the newline posterior to which we stop. */
22270 return - orig_count
- 1;
22273 start_byte
+= ceiling_addr
- base
;
22277 *byte_pos_ptr
= limit_byte
;
22280 return - orig_count
+ count
;
22281 return orig_count
- count
;
22287 /***********************************************************************
22289 ***********************************************************************/
22291 /* Display a NUL-terminated string, starting with index START.
22293 If STRING is non-null, display that C string. Otherwise, the Lisp
22294 string LISP_STRING is displayed. There's a case that STRING is
22295 non-null and LISP_STRING is not nil. It means STRING is a string
22296 data of LISP_STRING. In that case, we display LISP_STRING while
22297 ignoring its text properties.
22299 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22300 FACE_STRING. Display STRING or LISP_STRING with the face at
22301 FACE_STRING_POS in FACE_STRING:
22303 Display the string in the environment given by IT, but use the
22304 standard display table, temporarily.
22306 FIELD_WIDTH is the minimum number of output glyphs to produce.
22307 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22308 with spaces. If STRING has more characters, more than FIELD_WIDTH
22309 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22311 PRECISION is the maximum number of characters to output from
22312 STRING. PRECISION < 0 means don't truncate the string.
22314 This is roughly equivalent to printf format specifiers:
22316 FIELD_WIDTH PRECISION PRINTF
22317 ----------------------------------------
22323 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22324 display them, and < 0 means obey the current buffer's value of
22325 enable_multibyte_characters.
22327 Value is the number of columns displayed. */
22330 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22331 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22332 int field_width
, int precision
, int max_x
, int multibyte
)
22334 int hpos_at_start
= it
->hpos
;
22335 int saved_face_id
= it
->face_id
;
22336 struct glyph_row
*row
= it
->glyph_row
;
22337 ptrdiff_t it_charpos
;
22339 /* Initialize the iterator IT for iteration over STRING beginning
22340 with index START. */
22341 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22342 precision
, field_width
, multibyte
);
22343 if (string
&& STRINGP (lisp_string
))
22344 /* LISP_STRING is the one returned by decode_mode_spec. We should
22345 ignore its text properties. */
22346 it
->stop_charpos
= it
->end_charpos
;
22348 /* If displaying STRING, set up the face of the iterator from
22349 FACE_STRING, if that's given. */
22350 if (STRINGP (face_string
))
22356 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22357 0, it
->region_beg_charpos
,
22358 it
->region_end_charpos
,
22359 &endptr
, it
->base_face_id
, 0);
22360 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22361 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22364 /* Set max_x to the maximum allowed X position. Don't let it go
22365 beyond the right edge of the window. */
22367 max_x
= it
->last_visible_x
;
22369 max_x
= min (max_x
, it
->last_visible_x
);
22371 /* Skip over display elements that are not visible. because IT->w is
22373 if (it
->current_x
< it
->first_visible_x
)
22374 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22375 MOVE_TO_POS
| MOVE_TO_X
);
22377 row
->ascent
= it
->max_ascent
;
22378 row
->height
= it
->max_ascent
+ it
->max_descent
;
22379 row
->phys_ascent
= it
->max_phys_ascent
;
22380 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22381 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22383 if (STRINGP (it
->string
))
22384 it_charpos
= IT_STRING_CHARPOS (*it
);
22386 it_charpos
= IT_CHARPOS (*it
);
22388 /* This condition is for the case that we are called with current_x
22389 past last_visible_x. */
22390 while (it
->current_x
< max_x
)
22392 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22394 /* Get the next display element. */
22395 if (!get_next_display_element (it
))
22398 /* Produce glyphs. */
22399 x_before
= it
->current_x
;
22400 n_glyphs_before
= row
->used
[TEXT_AREA
];
22401 PRODUCE_GLYPHS (it
);
22403 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22406 while (i
< nglyphs
)
22408 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22410 if (it
->line_wrap
!= TRUNCATE
22411 && x
+ glyph
->pixel_width
> max_x
)
22413 /* End of continued line or max_x reached. */
22414 if (CHAR_GLYPH_PADDING_P (*glyph
))
22416 /* A wide character is unbreakable. */
22417 if (row
->reversed_p
)
22418 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22419 - n_glyphs_before
);
22420 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22421 it
->current_x
= x_before
;
22425 if (row
->reversed_p
)
22426 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22427 - (n_glyphs_before
+ i
));
22428 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22433 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22435 /* Glyph is at least partially visible. */
22437 if (x
< it
->first_visible_x
)
22438 row
->x
= x
- it
->first_visible_x
;
22442 /* Glyph is off the left margin of the display area.
22443 Should not happen. */
22447 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22448 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22449 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22450 row
->phys_height
= max (row
->phys_height
,
22451 it
->max_phys_ascent
+ it
->max_phys_descent
);
22452 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22453 it
->max_extra_line_spacing
);
22454 x
+= glyph
->pixel_width
;
22458 /* Stop if max_x reached. */
22462 /* Stop at line ends. */
22463 if (ITERATOR_AT_END_OF_LINE_P (it
))
22465 it
->continuation_lines_width
= 0;
22469 set_iterator_to_next (it
, 1);
22470 if (STRINGP (it
->string
))
22471 it_charpos
= IT_STRING_CHARPOS (*it
);
22473 it_charpos
= IT_CHARPOS (*it
);
22475 /* Stop if truncating at the right edge. */
22476 if (it
->line_wrap
== TRUNCATE
22477 && it
->current_x
>= it
->last_visible_x
)
22479 /* Add truncation mark, but don't do it if the line is
22480 truncated at a padding space. */
22481 if (it_charpos
< it
->string_nchars
)
22483 if (!FRAME_WINDOW_P (it
->f
))
22487 if (it
->current_x
> it
->last_visible_x
)
22489 if (!row
->reversed_p
)
22491 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22492 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22497 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22498 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22500 unproduce_glyphs (it
, ii
+ 1);
22501 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22503 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22505 row
->used
[TEXT_AREA
] = ii
;
22506 produce_special_glyphs (it
, IT_TRUNCATION
);
22509 produce_special_glyphs (it
, IT_TRUNCATION
);
22511 row
->truncated_on_right_p
= 1;
22517 /* Maybe insert a truncation at the left. */
22518 if (it
->first_visible_x
22521 if (!FRAME_WINDOW_P (it
->f
)
22522 || (row
->reversed_p
22523 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22524 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22525 insert_left_trunc_glyphs (it
);
22526 row
->truncated_on_left_p
= 1;
22529 it
->face_id
= saved_face_id
;
22531 /* Value is number of columns displayed. */
22532 return it
->hpos
- hpos_at_start
;
22537 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22538 appears as an element of LIST or as the car of an element of LIST.
22539 If PROPVAL is a list, compare each element against LIST in that
22540 way, and return 1/2 if any element of PROPVAL is found in LIST.
22541 Otherwise return 0. This function cannot quit.
22542 The return value is 2 if the text is invisible but with an ellipsis
22543 and 1 if it's invisible and without an ellipsis. */
22546 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22548 register Lisp_Object tail
, proptail
;
22550 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22552 register Lisp_Object tem
;
22554 if (EQ (propval
, tem
))
22556 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22557 return NILP (XCDR (tem
)) ? 1 : 2;
22560 if (CONSP (propval
))
22562 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22564 Lisp_Object propelt
;
22565 propelt
= XCAR (proptail
);
22566 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22568 register Lisp_Object tem
;
22570 if (EQ (propelt
, tem
))
22572 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22573 return NILP (XCDR (tem
)) ? 1 : 2;
22581 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22582 doc
: /* Non-nil if the property makes the text invisible.
22583 POS-OR-PROP can be a marker or number, in which case it is taken to be
22584 a position in the current buffer and the value of the `invisible' property
22585 is checked; or it can be some other value, which is then presumed to be the
22586 value of the `invisible' property of the text of interest.
22587 The non-nil value returned can be t for truly invisible text or something
22588 else if the text is replaced by an ellipsis. */)
22589 (Lisp_Object pos_or_prop
)
22592 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22593 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22595 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22596 return (invis
== 0 ? Qnil
22598 : make_number (invis
));
22601 /* Calculate a width or height in pixels from a specification using
22602 the following elements:
22605 NUM - a (fractional) multiple of the default font width/height
22606 (NUM) - specifies exactly NUM pixels
22607 UNIT - a fixed number of pixels, see below.
22608 ELEMENT - size of a display element in pixels, see below.
22609 (NUM . SPEC) - equals NUM * SPEC
22610 (+ SPEC SPEC ...) - add pixel values
22611 (- SPEC SPEC ...) - subtract pixel values
22612 (- SPEC) - negate pixel value
22615 INT or FLOAT - a number constant
22616 SYMBOL - use symbol's (buffer local) variable binding.
22619 in - pixels per inch *)
22620 mm - pixels per 1/1000 meter *)
22621 cm - pixels per 1/100 meter *)
22622 width - width of current font in pixels.
22623 height - height of current font in pixels.
22625 *) using the ratio(s) defined in display-pixels-per-inch.
22629 left-fringe - left fringe width in pixels
22630 right-fringe - right fringe width in pixels
22632 left-margin - left margin width in pixels
22633 right-margin - right margin width in pixels
22635 scroll-bar - scroll-bar area width in pixels
22639 Pixels corresponding to 5 inches:
22642 Total width of non-text areas on left side of window (if scroll-bar is on left):
22643 '(space :width (+ left-fringe left-margin scroll-bar))
22645 Align to first text column (in header line):
22646 '(space :align-to 0)
22648 Align to middle of text area minus half the width of variable `my-image'
22649 containing a loaded image:
22650 '(space :align-to (0.5 . (- text my-image)))
22652 Width of left margin minus width of 1 character in the default font:
22653 '(space :width (- left-margin 1))
22655 Width of left margin minus width of 2 characters in the current font:
22656 '(space :width (- left-margin (2 . width)))
22658 Center 1 character over left-margin (in header line):
22659 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22661 Different ways to express width of left fringe plus left margin minus one pixel:
22662 '(space :width (- (+ left-fringe left-margin) (1)))
22663 '(space :width (+ left-fringe left-margin (- (1))))
22664 '(space :width (+ left-fringe left-margin (-1)))
22669 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22670 struct font
*font
, int width_p
, int *align_to
)
22674 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22675 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22678 return OK_PIXELS (0);
22680 eassert (FRAME_LIVE_P (it
->f
));
22682 if (SYMBOLP (prop
))
22684 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22686 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22688 if (unit
[0] == 'i' && unit
[1] == 'n')
22690 else if (unit
[0] == 'm' && unit
[1] == 'm')
22692 else if (unit
[0] == 'c' && unit
[1] == 'm')
22698 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22699 : FRAME_RES_Y (it
->f
));
22702 return OK_PIXELS (ppi
/ pixels
);
22707 #ifdef HAVE_WINDOW_SYSTEM
22708 if (EQ (prop
, Qheight
))
22709 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22710 if (EQ (prop
, Qwidth
))
22711 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22713 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22714 return OK_PIXELS (1);
22717 if (EQ (prop
, Qtext
))
22718 return OK_PIXELS (width_p
22719 ? window_box_width (it
->w
, TEXT_AREA
)
22720 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22722 if (align_to
&& *align_to
< 0)
22725 if (EQ (prop
, Qleft
))
22726 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22727 if (EQ (prop
, Qright
))
22728 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22729 if (EQ (prop
, Qcenter
))
22730 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22731 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22732 if (EQ (prop
, Qleft_fringe
))
22733 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22734 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22735 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22736 if (EQ (prop
, Qright_fringe
))
22737 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22738 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22739 : window_box_right_offset (it
->w
, TEXT_AREA
));
22740 if (EQ (prop
, Qleft_margin
))
22741 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22742 if (EQ (prop
, Qright_margin
))
22743 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22744 if (EQ (prop
, Qscroll_bar
))
22745 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22747 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22748 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22749 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22754 if (EQ (prop
, Qleft_fringe
))
22755 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22756 if (EQ (prop
, Qright_fringe
))
22757 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22758 if (EQ (prop
, Qleft_margin
))
22759 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22760 if (EQ (prop
, Qright_margin
))
22761 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22762 if (EQ (prop
, Qscroll_bar
))
22763 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22766 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22767 if (EQ (prop
, Qunbound
))
22771 if (INTEGERP (prop
) || FLOATP (prop
))
22773 int base_unit
= (width_p
22774 ? FRAME_COLUMN_WIDTH (it
->f
)
22775 : FRAME_LINE_HEIGHT (it
->f
));
22776 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22781 Lisp_Object car
= XCAR (prop
);
22782 Lisp_Object cdr
= XCDR (prop
);
22786 #ifdef HAVE_WINDOW_SYSTEM
22787 if (FRAME_WINDOW_P (it
->f
)
22788 && valid_image_p (prop
))
22790 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22791 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22793 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22796 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22802 while (CONSP (cdr
))
22804 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22805 font
, width_p
, align_to
))
22808 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22813 if (EQ (car
, Qminus
))
22815 return OK_PIXELS (pixels
);
22818 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22819 if (EQ (car
, Qunbound
))
22823 if (INTEGERP (car
) || FLOATP (car
))
22826 pixels
= XFLOATINT (car
);
22828 return OK_PIXELS (pixels
);
22829 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22830 font
, width_p
, align_to
))
22831 return OK_PIXELS (pixels
* fact
);
22842 /***********************************************************************
22844 ***********************************************************************/
22846 #ifdef HAVE_WINDOW_SYSTEM
22851 dump_glyph_string (struct glyph_string
*s
)
22853 fprintf (stderr
, "glyph string\n");
22854 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22855 s
->x
, s
->y
, s
->width
, s
->height
);
22856 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22857 fprintf (stderr
, " hl = %d\n", s
->hl
);
22858 fprintf (stderr
, " left overhang = %d, right = %d\n",
22859 s
->left_overhang
, s
->right_overhang
);
22860 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22861 fprintf (stderr
, " extends to end of line = %d\n",
22862 s
->extends_to_end_of_line_p
);
22863 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22864 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22867 #endif /* GLYPH_DEBUG */
22869 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22870 of XChar2b structures for S; it can't be allocated in
22871 init_glyph_string because it must be allocated via `alloca'. W
22872 is the window on which S is drawn. ROW and AREA are the glyph row
22873 and area within the row from which S is constructed. START is the
22874 index of the first glyph structure covered by S. HL is a
22875 face-override for drawing S. */
22878 #define OPTIONAL_HDC(hdc) HDC hdc,
22879 #define DECLARE_HDC(hdc) HDC hdc;
22880 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22881 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22884 #ifndef OPTIONAL_HDC
22885 #define OPTIONAL_HDC(hdc)
22886 #define DECLARE_HDC(hdc)
22887 #define ALLOCATE_HDC(hdc, f)
22888 #define RELEASE_HDC(hdc, f)
22892 init_glyph_string (struct glyph_string
*s
,
22894 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22895 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22897 memset (s
, 0, sizeof *s
);
22899 s
->f
= XFRAME (w
->frame
);
22903 s
->display
= FRAME_X_DISPLAY (s
->f
);
22904 s
->window
= FRAME_X_WINDOW (s
->f
);
22905 s
->char2b
= char2b
;
22909 s
->first_glyph
= row
->glyphs
[area
] + start
;
22910 s
->height
= row
->height
;
22911 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22912 s
->ybase
= s
->y
+ row
->ascent
;
22916 /* Append the list of glyph strings with head H and tail T to the list
22917 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22920 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22921 struct glyph_string
*h
, struct glyph_string
*t
)
22935 /* Prepend the list of glyph strings with head H and tail T to the
22936 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22940 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22941 struct glyph_string
*h
, struct glyph_string
*t
)
22955 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22956 Set *HEAD and *TAIL to the resulting list. */
22959 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22960 struct glyph_string
*s
)
22962 s
->next
= s
->prev
= NULL
;
22963 append_glyph_string_lists (head
, tail
, s
, s
);
22967 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22968 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22969 make sure that X resources for the face returned are allocated.
22970 Value is a pointer to a realized face that is ready for display if
22971 DISPLAY_P is non-zero. */
22973 static struct face
*
22974 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22975 XChar2b
*char2b
, int display_p
)
22977 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22982 code
= face
->font
->driver
->encode_char (face
->font
, c
);
22984 if (code
== FONT_INVALID_CODE
)
22987 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22989 /* Make sure X resources of the face are allocated. */
22990 #ifdef HAVE_X_WINDOWS
22994 eassert (face
!= NULL
);
22995 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23002 /* Get face and two-byte form of character glyph GLYPH on frame F.
23003 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23004 a pointer to a realized face that is ready for display. */
23006 static struct face
*
23007 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23008 XChar2b
*char2b
, int *two_byte_p
)
23013 eassert (glyph
->type
== CHAR_GLYPH
);
23014 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23016 /* Make sure X resources of the face are allocated. */
23017 eassert (face
!= NULL
);
23018 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23025 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23026 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23028 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23030 if (code
== FONT_INVALID_CODE
)
23034 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23039 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23040 Return 1 if FONT has a glyph for C, otherwise return 0. */
23043 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23047 if (CHAR_BYTE8_P (c
))
23048 code
= CHAR_TO_BYTE8 (c
);
23050 code
= font
->driver
->encode_char (font
, c
);
23052 if (code
== FONT_INVALID_CODE
)
23054 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23059 /* Fill glyph string S with composition components specified by S->cmp.
23061 BASE_FACE is the base face of the composition.
23062 S->cmp_from is the index of the first component for S.
23064 OVERLAPS non-zero means S should draw the foreground only, and use
23065 its physical height for clipping. See also draw_glyphs.
23067 Value is the index of a component not in S. */
23070 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23074 /* For all glyphs of this composition, starting at the offset
23075 S->cmp_from, until we reach the end of the definition or encounter a
23076 glyph that requires the different face, add it to S. */
23081 s
->for_overlaps
= overlaps
;
23084 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23086 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23088 /* TAB in a composition means display glyphs with padding space
23089 on the left or right. */
23092 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23095 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23102 s
->font
= s
->face
->font
;
23104 else if (s
->face
!= face
)
23112 if (s
->face
== NULL
)
23114 s
->face
= base_face
->ascii_face
;
23115 s
->font
= s
->face
->font
;
23118 /* All glyph strings for the same composition has the same width,
23119 i.e. the width set for the first component of the composition. */
23120 s
->width
= s
->first_glyph
->pixel_width
;
23122 /* If the specified font could not be loaded, use the frame's
23123 default font, but record the fact that we couldn't load it in
23124 the glyph string so that we can draw rectangles for the
23125 characters of the glyph string. */
23126 if (s
->font
== NULL
)
23128 s
->font_not_found_p
= 1;
23129 s
->font
= FRAME_FONT (s
->f
);
23132 /* Adjust base line for subscript/superscript text. */
23133 s
->ybase
+= s
->first_glyph
->voffset
;
23135 /* This glyph string must always be drawn with 16-bit functions. */
23142 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23143 int start
, int end
, int overlaps
)
23145 struct glyph
*glyph
, *last
;
23146 Lisp_Object lgstring
;
23149 s
->for_overlaps
= overlaps
;
23150 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23151 last
= s
->row
->glyphs
[s
->area
] + end
;
23152 s
->cmp_id
= glyph
->u
.cmp
.id
;
23153 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23154 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23155 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23156 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23157 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23159 while (glyph
< last
23160 && glyph
->u
.cmp
.automatic
23161 && glyph
->u
.cmp
.id
== s
->cmp_id
23162 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23163 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23165 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23167 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23168 unsigned code
= LGLYPH_CODE (lglyph
);
23170 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23172 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23173 return glyph
- s
->row
->glyphs
[s
->area
];
23177 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23178 See the comment of fill_glyph_string for arguments.
23179 Value is the index of the first glyph not in S. */
23183 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23184 int start
, int end
, int overlaps
)
23186 struct glyph
*glyph
, *last
;
23189 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23190 s
->for_overlaps
= overlaps
;
23191 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23192 last
= s
->row
->glyphs
[s
->area
] + end
;
23193 voffset
= glyph
->voffset
;
23194 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23195 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23197 s
->width
= glyph
->pixel_width
;
23199 while (glyph
< last
23200 && glyph
->type
== GLYPHLESS_GLYPH
23201 && glyph
->voffset
== voffset
23202 && glyph
->face_id
== face_id
)
23205 s
->width
+= glyph
->pixel_width
;
23208 s
->ybase
+= voffset
;
23209 return glyph
- s
->row
->glyphs
[s
->area
];
23213 /* Fill glyph string S from a sequence of character glyphs.
23215 FACE_ID is the face id of the string. START is the index of the
23216 first glyph to consider, END is the index of the last + 1.
23217 OVERLAPS non-zero means S should draw the foreground only, and use
23218 its physical height for clipping. See also draw_glyphs.
23220 Value is the index of the first glyph not in S. */
23223 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23224 int start
, int end
, int overlaps
)
23226 struct glyph
*glyph
, *last
;
23228 int glyph_not_available_p
;
23230 eassert (s
->f
== XFRAME (s
->w
->frame
));
23231 eassert (s
->nchars
== 0);
23232 eassert (start
>= 0 && end
> start
);
23234 s
->for_overlaps
= overlaps
;
23235 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23236 last
= s
->row
->glyphs
[s
->area
] + end
;
23237 voffset
= glyph
->voffset
;
23238 s
->padding_p
= glyph
->padding_p
;
23239 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23241 while (glyph
< last
23242 && glyph
->type
== CHAR_GLYPH
23243 && glyph
->voffset
== voffset
23244 /* Same face id implies same font, nowadays. */
23245 && glyph
->face_id
== face_id
23246 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23250 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23251 s
->char2b
+ s
->nchars
,
23253 s
->two_byte_p
= two_byte_p
;
23255 eassert (s
->nchars
<= end
- start
);
23256 s
->width
+= glyph
->pixel_width
;
23257 if (glyph
++->padding_p
!= s
->padding_p
)
23261 s
->font
= s
->face
->font
;
23263 /* If the specified font could not be loaded, use the frame's font,
23264 but record the fact that we couldn't load it in
23265 S->font_not_found_p so that we can draw rectangles for the
23266 characters of the glyph string. */
23267 if (s
->font
== NULL
|| glyph_not_available_p
)
23269 s
->font_not_found_p
= 1;
23270 s
->font
= FRAME_FONT (s
->f
);
23273 /* Adjust base line for subscript/superscript text. */
23274 s
->ybase
+= voffset
;
23276 eassert (s
->face
&& s
->face
->gc
);
23277 return glyph
- s
->row
->glyphs
[s
->area
];
23281 /* Fill glyph string S from image glyph S->first_glyph. */
23284 fill_image_glyph_string (struct glyph_string
*s
)
23286 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23287 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23289 s
->slice
= s
->first_glyph
->slice
.img
;
23290 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23291 s
->font
= s
->face
->font
;
23292 s
->width
= s
->first_glyph
->pixel_width
;
23294 /* Adjust base line for subscript/superscript text. */
23295 s
->ybase
+= s
->first_glyph
->voffset
;
23299 /* Fill glyph string S from a sequence of stretch glyphs.
23301 START is the index of the first glyph to consider,
23302 END is the index of the last + 1.
23304 Value is the index of the first glyph not in S. */
23307 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23309 struct glyph
*glyph
, *last
;
23310 int voffset
, face_id
;
23312 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23314 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23315 last
= s
->row
->glyphs
[s
->area
] + end
;
23316 face_id
= glyph
->face_id
;
23317 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23318 s
->font
= s
->face
->font
;
23319 s
->width
= glyph
->pixel_width
;
23321 voffset
= glyph
->voffset
;
23325 && glyph
->type
== STRETCH_GLYPH
23326 && glyph
->voffset
== voffset
23327 && glyph
->face_id
== face_id
);
23329 s
->width
+= glyph
->pixel_width
;
23331 /* Adjust base line for subscript/superscript text. */
23332 s
->ybase
+= voffset
;
23334 /* The case that face->gc == 0 is handled when drawing the glyph
23335 string by calling PREPARE_FACE_FOR_DISPLAY. */
23337 return glyph
- s
->row
->glyphs
[s
->area
];
23340 static struct font_metrics
*
23341 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23343 static struct font_metrics metrics
;
23348 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23349 if (code
== FONT_INVALID_CODE
)
23351 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23356 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23357 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23358 assumed to be zero. */
23361 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23363 *left
= *right
= 0;
23365 if (glyph
->type
== CHAR_GLYPH
)
23369 struct font_metrics
*pcm
;
23371 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23372 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23374 if (pcm
->rbearing
> pcm
->width
)
23375 *right
= pcm
->rbearing
- pcm
->width
;
23376 if (pcm
->lbearing
< 0)
23377 *left
= -pcm
->lbearing
;
23380 else if (glyph
->type
== COMPOSITE_GLYPH
)
23382 if (! glyph
->u
.cmp
.automatic
)
23384 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23386 if (cmp
->rbearing
> cmp
->pixel_width
)
23387 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23388 if (cmp
->lbearing
< 0)
23389 *left
= - cmp
->lbearing
;
23393 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23394 struct font_metrics metrics
;
23396 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23397 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23398 if (metrics
.rbearing
> metrics
.width
)
23399 *right
= metrics
.rbearing
- metrics
.width
;
23400 if (metrics
.lbearing
< 0)
23401 *left
= - metrics
.lbearing
;
23407 /* Return the index of the first glyph preceding glyph string S that
23408 is overwritten by S because of S's left overhang. Value is -1
23409 if no glyphs are overwritten. */
23412 left_overwritten (struct glyph_string
*s
)
23416 if (s
->left_overhang
)
23419 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23420 int first
= s
->first_glyph
- glyphs
;
23422 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23423 x
-= glyphs
[i
].pixel_width
;
23434 /* Return the index of the first glyph preceding glyph string S that
23435 is overwriting S because of its right overhang. Value is -1 if no
23436 glyph in front of S overwrites S. */
23439 left_overwriting (struct glyph_string
*s
)
23442 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23443 int first
= s
->first_glyph
- glyphs
;
23447 for (i
= first
- 1; i
>= 0; --i
)
23450 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23453 x
-= glyphs
[i
].pixel_width
;
23460 /* Return the index of the last glyph following glyph string S that is
23461 overwritten by S because of S's right overhang. Value is -1 if
23462 no such glyph is found. */
23465 right_overwritten (struct glyph_string
*s
)
23469 if (s
->right_overhang
)
23472 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23473 int first
= (s
->first_glyph
- glyphs
23474 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23475 int end
= s
->row
->used
[s
->area
];
23477 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23478 x
+= glyphs
[i
].pixel_width
;
23487 /* Return the index of the last glyph following glyph string S that
23488 overwrites S because of its left overhang. Value is negative
23489 if no such glyph is found. */
23492 right_overwriting (struct glyph_string
*s
)
23495 int end
= s
->row
->used
[s
->area
];
23496 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23497 int first
= (s
->first_glyph
- glyphs
23498 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23502 for (i
= first
; i
< end
; ++i
)
23505 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23508 x
+= glyphs
[i
].pixel_width
;
23515 /* Set background width of glyph string S. START is the index of the
23516 first glyph following S. LAST_X is the right-most x-position + 1
23517 in the drawing area. */
23520 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23522 /* If the face of this glyph string has to be drawn to the end of
23523 the drawing area, set S->extends_to_end_of_line_p. */
23525 if (start
== s
->row
->used
[s
->area
]
23526 && s
->area
== TEXT_AREA
23527 && ((s
->row
->fill_line_p
23528 && (s
->hl
== DRAW_NORMAL_TEXT
23529 || s
->hl
== DRAW_IMAGE_RAISED
23530 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23531 || s
->hl
== DRAW_MOUSE_FACE
))
23532 s
->extends_to_end_of_line_p
= 1;
23534 /* If S extends its face to the end of the line, set its
23535 background_width to the distance to the right edge of the drawing
23537 if (s
->extends_to_end_of_line_p
)
23538 s
->background_width
= last_x
- s
->x
+ 1;
23540 s
->background_width
= s
->width
;
23544 /* Compute overhangs and x-positions for glyph string S and its
23545 predecessors, or successors. X is the starting x-position for S.
23546 BACKWARD_P non-zero means process predecessors. */
23549 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23555 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23556 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23566 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23567 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23577 /* The following macros are only called from draw_glyphs below.
23578 They reference the following parameters of that function directly:
23579 `w', `row', `area', and `overlap_p'
23580 as well as the following local variables:
23581 `s', `f', and `hdc' (in W32) */
23584 /* On W32, silently add local `hdc' variable to argument list of
23585 init_glyph_string. */
23586 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23587 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23589 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23590 init_glyph_string (s, char2b, w, row, area, start, hl)
23593 /* Add a glyph string for a stretch glyph to the list of strings
23594 between HEAD and TAIL. START is the index of the stretch 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 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23602 and below -- keep them on one line. */
23603 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23606 s = alloca (sizeof *s); \
23607 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23608 START = fill_stretch_glyph_string (s, START, END); \
23609 append_glyph_string (&HEAD, &TAIL, s); \
23615 /* Add a glyph string for an image glyph to the list of strings
23616 between HEAD and TAIL. START is the index of the image glyph in
23617 row area AREA of glyph row ROW. END is the index of the last glyph
23618 in that glyph row area. X is the current output position assigned
23619 to the new glyph string constructed. HL overrides that face of the
23620 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23621 is the right-most x-position of the drawing area. */
23623 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23626 s = alloca (sizeof *s); \
23627 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23628 fill_image_glyph_string (s); \
23629 append_glyph_string (&HEAD, &TAIL, s); \
23636 /* Add a glyph string for a sequence of character glyphs to the list
23637 of strings between HEAD and TAIL. START is the index of the first
23638 glyph in row area AREA of glyph row ROW that is part of the new
23639 glyph string. END is the index of the last glyph in that glyph row
23640 area. X is the current output position assigned to the new glyph
23641 string constructed. HL overrides that face of the glyph; e.g. it
23642 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23643 right-most x-position of the drawing area. */
23645 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23651 face_id = (row)->glyphs[area][START].face_id; \
23653 s = alloca (sizeof *s); \
23654 char2b = alloca ((END - START) * sizeof *char2b); \
23655 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23656 append_glyph_string (&HEAD, &TAIL, s); \
23658 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23663 /* Add a glyph string for a composite sequence to the list of strings
23664 between HEAD and TAIL. START is the index of the first glyph in
23665 row area AREA of glyph row ROW that is part of the new glyph
23666 string. END is the index of the last glyph in that glyph row area.
23667 X is the current output position assigned to the new glyph string
23668 constructed. HL overrides that face of the glyph; e.g. it is
23669 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23670 x-position of the drawing area. */
23672 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23674 int face_id = (row)->glyphs[area][START].face_id; \
23675 struct face *base_face = FACE_FROM_ID (f, face_id); \
23676 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23677 struct composition *cmp = composition_table[cmp_id]; \
23679 struct glyph_string *first_s = NULL; \
23682 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23684 /* Make glyph_strings for each glyph sequence that is drawable by \
23685 the same face, and append them to HEAD/TAIL. */ \
23686 for (n = 0; n < cmp->glyph_len;) \
23688 s = alloca (sizeof *s); \
23689 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23690 append_glyph_string (&(HEAD), &(TAIL), s); \
23696 n = fill_composite_glyph_string (s, base_face, overlaps); \
23704 /* Add a glyph string for a glyph-string sequence to the list of strings
23705 between HEAD and TAIL. */
23707 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23711 Lisp_Object gstring; \
23713 face_id = (row)->glyphs[area][START].face_id; \
23714 gstring = (composition_gstring_from_id \
23715 ((row)->glyphs[area][START].u.cmp.id)); \
23716 s = alloca (sizeof *s); \
23717 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23718 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23719 append_glyph_string (&(HEAD), &(TAIL), s); \
23721 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23725 /* Add a glyph string for a sequence of glyphless character's glyphs
23726 to the list of strings between HEAD and TAIL. The meanings of
23727 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23729 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23734 face_id = (row)->glyphs[area][START].face_id; \
23736 s = alloca (sizeof *s); \
23737 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23738 append_glyph_string (&HEAD, &TAIL, s); \
23740 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23746 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23747 of AREA of glyph row ROW on window W between indices START and END.
23748 HL overrides the face for drawing glyph strings, e.g. it is
23749 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23750 x-positions of the drawing area.
23752 This is an ugly monster macro construct because we must use alloca
23753 to allocate glyph strings (because draw_glyphs can be called
23754 asynchronously). */
23756 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23759 HEAD = TAIL = NULL; \
23760 while (START < END) \
23762 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23763 switch (first_glyph->type) \
23766 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23770 case COMPOSITE_GLYPH: \
23771 if (first_glyph->u.cmp.automatic) \
23772 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23775 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23779 case STRETCH_GLYPH: \
23780 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23784 case IMAGE_GLYPH: \
23785 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23789 case GLYPHLESS_GLYPH: \
23790 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23800 set_glyph_string_background_width (s, START, LAST_X); \
23807 /* Draw glyphs between START and END in AREA of ROW on window W,
23808 starting at x-position X. X is relative to AREA in W. HL is a
23809 face-override with the following meaning:
23811 DRAW_NORMAL_TEXT draw normally
23812 DRAW_CURSOR draw in cursor face
23813 DRAW_MOUSE_FACE draw in mouse face.
23814 DRAW_INVERSE_VIDEO draw in mode line face
23815 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23816 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23818 If OVERLAPS is non-zero, draw only the foreground of characters and
23819 clip to the physical height of ROW. Non-zero value also defines
23820 the overlapping part to be drawn:
23822 OVERLAPS_PRED overlap with preceding rows
23823 OVERLAPS_SUCC overlap with succeeding rows
23824 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23825 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23827 Value is the x-position reached, relative to AREA of W. */
23830 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23831 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23832 enum draw_glyphs_face hl
, int overlaps
)
23834 struct glyph_string
*head
, *tail
;
23835 struct glyph_string
*s
;
23836 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23837 int i
, j
, x_reached
, last_x
, area_left
= 0;
23838 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23841 ALLOCATE_HDC (hdc
, f
);
23843 /* Let's rather be paranoid than getting a SEGV. */
23844 end
= min (end
, row
->used
[area
]);
23845 start
= clip_to_bounds (0, start
, end
);
23847 /* Translate X to frame coordinates. Set last_x to the right
23848 end of the drawing area. */
23849 if (row
->full_width_p
)
23851 /* X is relative to the left edge of W, without scroll bars
23853 area_left
= WINDOW_LEFT_EDGE_X (w
);
23854 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23858 area_left
= window_box_left (w
, area
);
23859 last_x
= area_left
+ window_box_width (w
, area
);
23863 /* Build a doubly-linked list of glyph_string structures between
23864 head and tail from what we have to draw. Note that the macro
23865 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23866 the reason we use a separate variable `i'. */
23868 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23870 x_reached
= tail
->x
+ tail
->background_width
;
23874 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23875 the row, redraw some glyphs in front or following the glyph
23876 strings built above. */
23877 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23879 struct glyph_string
*h
, *t
;
23880 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23881 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23882 int check_mouse_face
= 0;
23885 /* If mouse highlighting is on, we may need to draw adjacent
23886 glyphs using mouse-face highlighting. */
23887 if (area
== TEXT_AREA
&& row
->mouse_face_p
23888 && hlinfo
->mouse_face_beg_row
>= 0
23889 && hlinfo
->mouse_face_end_row
>= 0)
23891 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23893 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23894 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23896 check_mouse_face
= 1;
23897 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23898 ? hlinfo
->mouse_face_beg_col
: 0;
23899 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23900 ? hlinfo
->mouse_face_end_col
23901 : row
->used
[TEXT_AREA
];
23905 /* Compute overhangs for all glyph strings. */
23906 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23907 for (s
= head
; s
; s
= s
->next
)
23908 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23910 /* Prepend glyph strings for glyphs in front of the first glyph
23911 string that are overwritten because of the first glyph
23912 string's left overhang. The background of all strings
23913 prepended must be drawn because the first glyph string
23915 i
= left_overwritten (head
);
23918 enum draw_glyphs_face overlap_hl
;
23920 /* If this row contains mouse highlighting, attempt to draw
23921 the overlapped glyphs with the correct highlight. This
23922 code fails if the overlap encompasses more than one glyph
23923 and mouse-highlight spans only some of these glyphs.
23924 However, making it work perfectly involves a lot more
23925 code, and I don't know if the pathological case occurs in
23926 practice, so we'll stick to this for now. --- cyd */
23927 if (check_mouse_face
23928 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23929 overlap_hl
= DRAW_MOUSE_FACE
;
23931 overlap_hl
= DRAW_NORMAL_TEXT
;
23934 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23935 overlap_hl
, dummy_x
, last_x
);
23937 compute_overhangs_and_x (t
, head
->x
, 1);
23938 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23942 /* Prepend glyph strings for glyphs in front of the first glyph
23943 string that overwrite that glyph string because of their
23944 right overhang. For these strings, only the foreground must
23945 be drawn, because it draws over the glyph string at `head'.
23946 The background must not be drawn because this would overwrite
23947 right overhangs of preceding glyphs for which no glyph
23949 i
= left_overwriting (head
);
23952 enum draw_glyphs_face overlap_hl
;
23954 if (check_mouse_face
23955 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23956 overlap_hl
= DRAW_MOUSE_FACE
;
23958 overlap_hl
= DRAW_NORMAL_TEXT
;
23961 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23962 overlap_hl
, dummy_x
, last_x
);
23963 for (s
= h
; s
; s
= s
->next
)
23964 s
->background_filled_p
= 1;
23965 compute_overhangs_and_x (t
, head
->x
, 1);
23966 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23969 /* Append glyphs strings for glyphs following the last glyph
23970 string tail that are overwritten by tail. The background of
23971 these strings has to be drawn because tail's foreground draws
23973 i
= right_overwritten (tail
);
23976 enum draw_glyphs_face overlap_hl
;
23978 if (check_mouse_face
23979 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23980 overlap_hl
= DRAW_MOUSE_FACE
;
23982 overlap_hl
= DRAW_NORMAL_TEXT
;
23984 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23985 overlap_hl
, x
, last_x
);
23986 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23987 we don't have `end = i;' here. */
23988 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23989 append_glyph_string_lists (&head
, &tail
, h
, t
);
23993 /* Append glyph strings for glyphs following the last glyph
23994 string tail that overwrite tail. The foreground of such
23995 glyphs has to be drawn because it writes into the background
23996 of tail. The background must not be drawn because it could
23997 paint over the foreground of following glyphs. */
23998 i
= right_overwriting (tail
);
24001 enum draw_glyphs_face overlap_hl
;
24002 if (check_mouse_face
24003 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24004 overlap_hl
= DRAW_MOUSE_FACE
;
24006 overlap_hl
= DRAW_NORMAL_TEXT
;
24009 i
++; /* We must include the Ith glyph. */
24010 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24011 overlap_hl
, x
, last_x
);
24012 for (s
= h
; s
; s
= s
->next
)
24013 s
->background_filled_p
= 1;
24014 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24015 append_glyph_string_lists (&head
, &tail
, h
, t
);
24017 if (clip_head
|| clip_tail
)
24018 for (s
= head
; s
; s
= s
->next
)
24020 s
->clip_head
= clip_head
;
24021 s
->clip_tail
= clip_tail
;
24025 /* Draw all strings. */
24026 for (s
= head
; s
; s
= s
->next
)
24027 FRAME_RIF (f
)->draw_glyph_string (s
);
24030 /* When focus a sole frame and move horizontally, this sets on_p to 0
24031 causing a failure to erase prev cursor position. */
24032 if (area
== TEXT_AREA
24033 && !row
->full_width_p
24034 /* When drawing overlapping rows, only the glyph strings'
24035 foreground is drawn, which doesn't erase a cursor
24039 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24040 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24041 : (tail
? tail
->x
+ tail
->background_width
: x
));
24045 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24046 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24050 /* Value is the x-position up to which drawn, relative to AREA of W.
24051 This doesn't include parts drawn because of overhangs. */
24052 if (row
->full_width_p
)
24053 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24055 x_reached
-= area_left
;
24057 RELEASE_HDC (hdc
, f
);
24062 /* Expand row matrix if too narrow. Don't expand if area
24065 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24067 if (!fonts_changed_p \
24068 && (it->glyph_row->glyphs[area] \
24069 < it->glyph_row->glyphs[area + 1])) \
24071 it->w->ncols_scale_factor++; \
24072 fonts_changed_p = 1; \
24076 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24077 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24080 append_glyph (struct it
*it
)
24082 struct glyph
*glyph
;
24083 enum glyph_row_area area
= it
->area
;
24085 eassert (it
->glyph_row
);
24086 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24088 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24089 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24091 /* If the glyph row is reversed, we need to prepend the glyph
24092 rather than append it. */
24093 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24097 /* Make room for the additional glyph. */
24098 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24100 glyph
= it
->glyph_row
->glyphs
[area
];
24102 glyph
->charpos
= CHARPOS (it
->position
);
24103 glyph
->object
= it
->object
;
24104 if (it
->pixel_width
> 0)
24106 glyph
->pixel_width
= it
->pixel_width
;
24107 glyph
->padding_p
= 0;
24111 /* Assure at least 1-pixel width. Otherwise, cursor can't
24112 be displayed correctly. */
24113 glyph
->pixel_width
= 1;
24114 glyph
->padding_p
= 1;
24116 glyph
->ascent
= it
->ascent
;
24117 glyph
->descent
= it
->descent
;
24118 glyph
->voffset
= it
->voffset
;
24119 glyph
->type
= CHAR_GLYPH
;
24120 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24121 glyph
->multibyte_p
= it
->multibyte_p
;
24122 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24124 /* In R2L rows, the left and the right box edges need to be
24125 drawn in reverse direction. */
24126 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24127 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24131 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24132 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24134 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24135 || it
->phys_descent
> it
->descent
);
24136 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24137 glyph
->face_id
= it
->face_id
;
24138 glyph
->u
.ch
= it
->char_to_display
;
24139 glyph
->slice
.img
= null_glyph_slice
;
24140 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24143 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24144 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24146 glyph
->bidi_type
= it
->bidi_it
.type
;
24150 glyph
->resolved_level
= 0;
24151 glyph
->bidi_type
= UNKNOWN_BT
;
24153 ++it
->glyph_row
->used
[area
];
24156 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24159 /* Store one glyph for the composition IT->cmp_it.id in
24160 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24164 append_composite_glyph (struct it
*it
)
24166 struct glyph
*glyph
;
24167 enum glyph_row_area area
= it
->area
;
24169 eassert (it
->glyph_row
);
24171 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24172 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24174 /* If the glyph row is reversed, we need to prepend the glyph
24175 rather than append it. */
24176 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24180 /* Make room for the new glyph. */
24181 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24183 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24185 glyph
->charpos
= it
->cmp_it
.charpos
;
24186 glyph
->object
= it
->object
;
24187 glyph
->pixel_width
= it
->pixel_width
;
24188 glyph
->ascent
= it
->ascent
;
24189 glyph
->descent
= it
->descent
;
24190 glyph
->voffset
= it
->voffset
;
24191 glyph
->type
= COMPOSITE_GLYPH
;
24192 if (it
->cmp_it
.ch
< 0)
24194 glyph
->u
.cmp
.automatic
= 0;
24195 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24196 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24200 glyph
->u
.cmp
.automatic
= 1;
24201 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24202 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24203 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24205 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24206 glyph
->multibyte_p
= it
->multibyte_p
;
24207 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24209 /* In R2L rows, the left and the right box edges need to be
24210 drawn in reverse direction. */
24211 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24212 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24216 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24217 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24219 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24220 || it
->phys_descent
> it
->descent
);
24221 glyph
->padding_p
= 0;
24222 glyph
->glyph_not_available_p
= 0;
24223 glyph
->face_id
= it
->face_id
;
24224 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24227 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24228 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24230 glyph
->bidi_type
= it
->bidi_it
.type
;
24232 ++it
->glyph_row
->used
[area
];
24235 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24239 /* Change IT->ascent and IT->height according to the setting of
24243 take_vertical_position_into_account (struct it
*it
)
24247 if (it
->voffset
< 0)
24248 /* Increase the ascent so that we can display the text higher
24250 it
->ascent
-= it
->voffset
;
24252 /* Increase the descent so that we can display the text lower
24254 it
->descent
+= it
->voffset
;
24259 /* Produce glyphs/get display metrics for the image IT is loaded with.
24260 See the description of struct display_iterator in dispextern.h for
24261 an overview of struct display_iterator. */
24264 produce_image_glyph (struct it
*it
)
24268 int glyph_ascent
, crop
;
24269 struct glyph_slice slice
;
24271 eassert (it
->what
== IT_IMAGE
);
24273 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24275 /* Make sure X resources of the face is loaded. */
24276 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24278 if (it
->image_id
< 0)
24280 /* Fringe bitmap. */
24281 it
->ascent
= it
->phys_ascent
= 0;
24282 it
->descent
= it
->phys_descent
= 0;
24283 it
->pixel_width
= 0;
24288 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24290 /* Make sure X resources of the image is loaded. */
24291 prepare_image_for_display (it
->f
, img
);
24293 slice
.x
= slice
.y
= 0;
24294 slice
.width
= img
->width
;
24295 slice
.height
= img
->height
;
24297 if (INTEGERP (it
->slice
.x
))
24298 slice
.x
= XINT (it
->slice
.x
);
24299 else if (FLOATP (it
->slice
.x
))
24300 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24302 if (INTEGERP (it
->slice
.y
))
24303 slice
.y
= XINT (it
->slice
.y
);
24304 else if (FLOATP (it
->slice
.y
))
24305 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24307 if (INTEGERP (it
->slice
.width
))
24308 slice
.width
= XINT (it
->slice
.width
);
24309 else if (FLOATP (it
->slice
.width
))
24310 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24312 if (INTEGERP (it
->slice
.height
))
24313 slice
.height
= XINT (it
->slice
.height
);
24314 else if (FLOATP (it
->slice
.height
))
24315 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24317 if (slice
.x
>= img
->width
)
24318 slice
.x
= img
->width
;
24319 if (slice
.y
>= img
->height
)
24320 slice
.y
= img
->height
;
24321 if (slice
.x
+ slice
.width
>= img
->width
)
24322 slice
.width
= img
->width
- slice
.x
;
24323 if (slice
.y
+ slice
.height
> img
->height
)
24324 slice
.height
= img
->height
- slice
.y
;
24326 if (slice
.width
== 0 || slice
.height
== 0)
24329 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24331 it
->descent
= slice
.height
- glyph_ascent
;
24333 it
->descent
+= img
->vmargin
;
24334 if (slice
.y
+ slice
.height
== img
->height
)
24335 it
->descent
+= img
->vmargin
;
24336 it
->phys_descent
= it
->descent
;
24338 it
->pixel_width
= slice
.width
;
24340 it
->pixel_width
+= img
->hmargin
;
24341 if (slice
.x
+ slice
.width
== img
->width
)
24342 it
->pixel_width
+= img
->hmargin
;
24344 /* It's quite possible for images to have an ascent greater than
24345 their height, so don't get confused in that case. */
24346 if (it
->descent
< 0)
24351 if (face
->box
!= FACE_NO_BOX
)
24353 if (face
->box_line_width
> 0)
24356 it
->ascent
+= face
->box_line_width
;
24357 if (slice
.y
+ slice
.height
== img
->height
)
24358 it
->descent
+= face
->box_line_width
;
24361 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24362 it
->pixel_width
+= eabs (face
->box_line_width
);
24363 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24364 it
->pixel_width
+= eabs (face
->box_line_width
);
24367 take_vertical_position_into_account (it
);
24369 /* Automatically crop wide image glyphs at right edge so we can
24370 draw the cursor on same display row. */
24371 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24372 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24374 it
->pixel_width
-= crop
;
24375 slice
.width
-= crop
;
24380 struct glyph
*glyph
;
24381 enum glyph_row_area area
= it
->area
;
24383 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24384 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24386 glyph
->charpos
= CHARPOS (it
->position
);
24387 glyph
->object
= it
->object
;
24388 glyph
->pixel_width
= it
->pixel_width
;
24389 glyph
->ascent
= glyph_ascent
;
24390 glyph
->descent
= it
->descent
;
24391 glyph
->voffset
= it
->voffset
;
24392 glyph
->type
= IMAGE_GLYPH
;
24393 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24394 glyph
->multibyte_p
= it
->multibyte_p
;
24395 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24397 /* In R2L rows, the left and the right box edges need to be
24398 drawn in reverse direction. */
24399 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24400 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24404 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24405 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24407 glyph
->overlaps_vertically_p
= 0;
24408 glyph
->padding_p
= 0;
24409 glyph
->glyph_not_available_p
= 0;
24410 glyph
->face_id
= it
->face_id
;
24411 glyph
->u
.img_id
= img
->id
;
24412 glyph
->slice
.img
= slice
;
24413 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24416 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24417 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24419 glyph
->bidi_type
= it
->bidi_it
.type
;
24421 ++it
->glyph_row
->used
[area
];
24424 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24429 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24430 of the glyph, WIDTH and HEIGHT are the width and height of the
24431 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24434 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24435 int width
, int height
, int ascent
)
24437 struct glyph
*glyph
;
24438 enum glyph_row_area area
= it
->area
;
24440 eassert (ascent
>= 0 && ascent
<= height
);
24442 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24443 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24445 /* If the glyph row is reversed, we need to prepend the glyph
24446 rather than append it. */
24447 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24451 /* Make room for the additional glyph. */
24452 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24454 glyph
= it
->glyph_row
->glyphs
[area
];
24456 glyph
->charpos
= CHARPOS (it
->position
);
24457 glyph
->object
= object
;
24458 glyph
->pixel_width
= width
;
24459 glyph
->ascent
= ascent
;
24460 glyph
->descent
= height
- ascent
;
24461 glyph
->voffset
= it
->voffset
;
24462 glyph
->type
= STRETCH_GLYPH
;
24463 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24464 glyph
->multibyte_p
= it
->multibyte_p
;
24465 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24467 /* In R2L rows, the left and the right box edges need to be
24468 drawn in reverse direction. */
24469 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24470 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24474 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24475 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24477 glyph
->overlaps_vertically_p
= 0;
24478 glyph
->padding_p
= 0;
24479 glyph
->glyph_not_available_p
= 0;
24480 glyph
->face_id
= it
->face_id
;
24481 glyph
->u
.stretch
.ascent
= ascent
;
24482 glyph
->u
.stretch
.height
= height
;
24483 glyph
->slice
.img
= null_glyph_slice
;
24484 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24487 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24488 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24490 glyph
->bidi_type
= it
->bidi_it
.type
;
24494 glyph
->resolved_level
= 0;
24495 glyph
->bidi_type
= UNKNOWN_BT
;
24497 ++it
->glyph_row
->used
[area
];
24500 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24503 #endif /* HAVE_WINDOW_SYSTEM */
24505 /* Produce a stretch glyph for iterator IT. IT->object is the value
24506 of the glyph property displayed. The value must be a list
24507 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24510 1. `:width WIDTH' specifies that the space should be WIDTH *
24511 canonical char width wide. WIDTH may be an integer or floating
24514 2. `:relative-width FACTOR' specifies that the width of the stretch
24515 should be computed from the width of the first character having the
24516 `glyph' property, and should be FACTOR times that width.
24518 3. `:align-to HPOS' specifies that the space should be wide enough
24519 to reach HPOS, a value in canonical character units.
24521 Exactly one of the above pairs must be present.
24523 4. `:height HEIGHT' specifies that the height of the stretch produced
24524 should be HEIGHT, measured in canonical character units.
24526 5. `:relative-height FACTOR' specifies that the height of the
24527 stretch should be FACTOR times the height of the characters having
24528 the glyph property.
24530 Either none or exactly one of 4 or 5 must be present.
24532 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24533 of the stretch should be used for the ascent of the stretch.
24534 ASCENT must be in the range 0 <= ASCENT <= 100. */
24537 produce_stretch_glyph (struct it
*it
)
24539 /* (space :width WIDTH :height HEIGHT ...) */
24540 Lisp_Object prop
, plist
;
24541 int width
= 0, height
= 0, align_to
= -1;
24542 int zero_width_ok_p
= 0;
24544 struct font
*font
= NULL
;
24546 #ifdef HAVE_WINDOW_SYSTEM
24548 int zero_height_ok_p
= 0;
24550 if (FRAME_WINDOW_P (it
->f
))
24552 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24553 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24554 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24558 /* List should start with `space'. */
24559 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24560 plist
= XCDR (it
->object
);
24562 /* Compute the width of the stretch. */
24563 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24564 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24566 /* Absolute width `:width WIDTH' specified and valid. */
24567 zero_width_ok_p
= 1;
24570 #ifdef HAVE_WINDOW_SYSTEM
24571 else if (FRAME_WINDOW_P (it
->f
)
24572 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24574 /* Relative width `:relative-width FACTOR' specified and valid.
24575 Compute the width of the characters having the `glyph'
24578 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24581 if (it
->multibyte_p
)
24582 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24585 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24586 if (! ASCII_CHAR_P (it2
.c
))
24587 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24590 it2
.glyph_row
= NULL
;
24591 it2
.what
= IT_CHARACTER
;
24592 x_produce_glyphs (&it2
);
24593 width
= NUMVAL (prop
) * it2
.pixel_width
;
24595 #endif /* HAVE_WINDOW_SYSTEM */
24596 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24597 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24599 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24600 align_to
= (align_to
< 0
24602 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24603 else if (align_to
< 0)
24604 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24605 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24606 zero_width_ok_p
= 1;
24609 /* Nothing specified -> width defaults to canonical char width. */
24610 width
= FRAME_COLUMN_WIDTH (it
->f
);
24612 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24615 #ifdef HAVE_WINDOW_SYSTEM
24616 /* Compute height. */
24617 if (FRAME_WINDOW_P (it
->f
))
24619 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24620 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24623 zero_height_ok_p
= 1;
24625 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24627 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24629 height
= FONT_HEIGHT (font
);
24631 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24634 /* Compute percentage of height used for ascent. If
24635 `:ascent ASCENT' is present and valid, use that. Otherwise,
24636 derive the ascent from the font in use. */
24637 if (prop
= Fplist_get (plist
, QCascent
),
24638 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24639 ascent
= height
* NUMVAL (prop
) / 100.0;
24640 else if (!NILP (prop
)
24641 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24642 ascent
= min (max (0, (int)tem
), height
);
24644 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24647 #endif /* HAVE_WINDOW_SYSTEM */
24650 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24651 && it
->current_x
+ width
> it
->last_visible_x
)
24653 width
= it
->last_visible_x
- it
->current_x
;
24654 #ifdef HAVE_WINDOW_SYSTEM
24655 /* Subtract one more pixel from the stretch width, but only on
24656 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24657 width
-= FRAME_WINDOW_P (it
->f
);
24661 if (width
> 0 && height
> 0 && it
->glyph_row
)
24663 Lisp_Object o_object
= it
->object
;
24664 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24667 if (!STRINGP (object
))
24668 object
= it
->w
->contents
;
24669 #ifdef HAVE_WINDOW_SYSTEM
24670 if (FRAME_WINDOW_P (it
->f
))
24671 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24675 it
->object
= object
;
24676 it
->char_to_display
= ' ';
24677 it
->pixel_width
= it
->len
= 1;
24679 tty_append_glyph (it
);
24680 it
->object
= o_object
;
24684 it
->pixel_width
= width
;
24685 #ifdef HAVE_WINDOW_SYSTEM
24686 if (FRAME_WINDOW_P (it
->f
))
24688 it
->ascent
= it
->phys_ascent
= ascent
;
24689 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24690 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24691 take_vertical_position_into_account (it
);
24695 it
->nglyphs
= width
;
24698 /* Get information about special display element WHAT in an
24699 environment described by IT. WHAT is one of IT_TRUNCATION or
24700 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24701 non-null glyph_row member. This function ensures that fields like
24702 face_id, c, len of IT are left untouched. */
24705 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24712 temp_it
.object
= make_number (0);
24713 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24715 if (what
== IT_CONTINUATION
)
24717 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24718 if (it
->bidi_it
.paragraph_dir
== R2L
)
24719 SET_GLYPH_FROM_CHAR (glyph
, '/');
24721 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24723 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24725 /* FIXME: Should we mirror GC for R2L lines? */
24726 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24727 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24730 else if (what
== IT_TRUNCATION
)
24732 /* Truncation glyph. */
24733 SET_GLYPH_FROM_CHAR (glyph
, '$');
24735 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24737 /* FIXME: Should we mirror GC for R2L lines? */
24738 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24739 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24745 #ifdef HAVE_WINDOW_SYSTEM
24746 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24747 is turned off, we precede the truncation/continuation glyphs by a
24748 stretch glyph whose width is computed such that these special
24749 glyphs are aligned at the window margin, even when very different
24750 fonts are used in different glyph rows. */
24751 if (FRAME_WINDOW_P (temp_it
.f
)
24752 /* init_iterator calls this with it->glyph_row == NULL, and it
24753 wants only the pixel width of the truncation/continuation
24755 && temp_it
.glyph_row
24756 /* insert_left_trunc_glyphs calls us at the beginning of the
24757 row, and it has its own calculation of the stretch glyph
24759 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24760 && (temp_it
.glyph_row
->reversed_p
24761 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24762 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24764 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24766 if (stretch_width
> 0)
24768 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24769 struct font
*font
=
24770 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24771 int stretch_ascent
=
24772 (((temp_it
.ascent
+ temp_it
.descent
)
24773 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24775 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24776 temp_it
.ascent
+ temp_it
.descent
,
24783 temp_it
.what
= IT_CHARACTER
;
24785 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24786 temp_it
.face_id
= GLYPH_FACE (glyph
);
24787 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24789 PRODUCE_GLYPHS (&temp_it
);
24790 it
->pixel_width
= temp_it
.pixel_width
;
24791 it
->nglyphs
= temp_it
.pixel_width
;
24794 #ifdef HAVE_WINDOW_SYSTEM
24796 /* Calculate line-height and line-spacing properties.
24797 An integer value specifies explicit pixel value.
24798 A float value specifies relative value to current face height.
24799 A cons (float . face-name) specifies relative value to
24800 height of specified face font.
24802 Returns height in pixels, or nil. */
24806 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24807 int boff
, int override
)
24809 Lisp_Object face_name
= Qnil
;
24810 int ascent
, descent
, height
;
24812 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24817 face_name
= XCAR (val
);
24819 if (!NUMBERP (val
))
24820 val
= make_number (1);
24821 if (NILP (face_name
))
24823 height
= it
->ascent
+ it
->descent
;
24828 if (NILP (face_name
))
24830 font
= FRAME_FONT (it
->f
);
24831 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24833 else if (EQ (face_name
, Qt
))
24842 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24844 return make_number (-1);
24846 face
= FACE_FROM_ID (it
->f
, face_id
);
24849 return make_number (-1);
24850 boff
= font
->baseline_offset
;
24851 if (font
->vertical_centering
)
24852 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24855 ascent
= FONT_BASE (font
) + boff
;
24856 descent
= FONT_DESCENT (font
) - boff
;
24860 it
->override_ascent
= ascent
;
24861 it
->override_descent
= descent
;
24862 it
->override_boff
= boff
;
24865 height
= ascent
+ descent
;
24869 height
= (int)(XFLOAT_DATA (val
) * height
);
24870 else if (INTEGERP (val
))
24871 height
*= XINT (val
);
24873 return make_number (height
);
24877 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24878 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24879 and only if this is for a character for which no font was found.
24881 If the display method (it->glyphless_method) is
24882 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24883 length of the acronym or the hexadecimal string, UPPER_XOFF and
24884 UPPER_YOFF are pixel offsets for the upper part of the string,
24885 LOWER_XOFF and LOWER_YOFF are for the lower part.
24887 For the other display methods, LEN through LOWER_YOFF are zero. */
24890 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24891 short upper_xoff
, short upper_yoff
,
24892 short lower_xoff
, short lower_yoff
)
24894 struct glyph
*glyph
;
24895 enum glyph_row_area area
= it
->area
;
24897 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24898 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24900 /* If the glyph row is reversed, we need to prepend the glyph
24901 rather than append it. */
24902 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24906 /* Make room for the additional glyph. */
24907 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24909 glyph
= it
->glyph_row
->glyphs
[area
];
24911 glyph
->charpos
= CHARPOS (it
->position
);
24912 glyph
->object
= it
->object
;
24913 glyph
->pixel_width
= it
->pixel_width
;
24914 glyph
->ascent
= it
->ascent
;
24915 glyph
->descent
= it
->descent
;
24916 glyph
->voffset
= it
->voffset
;
24917 glyph
->type
= GLYPHLESS_GLYPH
;
24918 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24919 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24920 glyph
->u
.glyphless
.len
= len
;
24921 glyph
->u
.glyphless
.ch
= it
->c
;
24922 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24923 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24924 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24925 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24926 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24927 glyph
->multibyte_p
= it
->multibyte_p
;
24928 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24930 /* In R2L rows, the left and the right box edges need to be
24931 drawn in reverse direction. */
24932 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24933 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24937 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24938 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24940 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24941 || it
->phys_descent
> it
->descent
);
24942 glyph
->padding_p
= 0;
24943 glyph
->glyph_not_available_p
= 0;
24944 glyph
->face_id
= face_id
;
24945 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24948 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24949 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24951 glyph
->bidi_type
= it
->bidi_it
.type
;
24953 ++it
->glyph_row
->used
[area
];
24956 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24960 /* Produce a glyph for a glyphless character for iterator IT.
24961 IT->glyphless_method specifies which method to use for displaying
24962 the character. See the description of enum
24963 glyphless_display_method in dispextern.h for the detail.
24965 FOR_NO_FONT is nonzero if and only if this is for a character for
24966 which no font was found. ACRONYM, if non-nil, is an acronym string
24967 for the character. */
24970 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24975 int base_width
, base_height
, width
, height
;
24976 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24979 /* Get the metrics of the base font. We always refer to the current
24981 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24982 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24983 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24984 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24985 base_height
= it
->ascent
+ it
->descent
;
24986 base_width
= font
->average_width
;
24988 /* Get a face ID for the glyph by utilizing a cache (the same way as
24989 done for `escape-glyph' in get_next_display_element). */
24990 if (it
->f
== last_glyphless_glyph_frame
24991 && it
->face_id
== last_glyphless_glyph_face_id
)
24993 face_id
= last_glyphless_glyph_merged_face_id
;
24997 /* Merge the `glyphless-char' face into the current face. */
24998 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24999 last_glyphless_glyph_frame
= it
->f
;
25000 last_glyphless_glyph_face_id
= it
->face_id
;
25001 last_glyphless_glyph_merged_face_id
= face_id
;
25004 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25006 it
->pixel_width
= THIN_SPACE_WIDTH
;
25008 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25010 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25012 width
= CHAR_WIDTH (it
->c
);
25015 else if (width
> 4)
25017 it
->pixel_width
= base_width
* width
;
25019 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25025 unsigned int code
[6];
25027 int ascent
, descent
;
25028 struct font_metrics metrics_upper
, metrics_lower
;
25030 face
= FACE_FROM_ID (it
->f
, face_id
);
25031 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25032 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25034 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25036 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25037 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25038 if (CONSP (acronym
))
25039 acronym
= XCAR (acronym
);
25040 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25044 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25045 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25048 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25049 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25050 upper_len
= (len
+ 1) / 2;
25051 font
->driver
->text_extents (font
, code
, upper_len
,
25053 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25058 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25059 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25060 upper_xoff
= upper_yoff
= 2; /* the typical case */
25061 if (base_width
>= width
)
25063 /* Align the upper to the left, the lower to the right. */
25064 it
->pixel_width
= base_width
;
25065 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25069 /* Center the shorter one. */
25070 it
->pixel_width
= width
;
25071 if (metrics_upper
.width
>= metrics_lower
.width
)
25072 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25075 /* FIXME: This code doesn't look right. It formerly was
25076 missing the "lower_xoff = 0;", which couldn't have
25077 been right since it left lower_xoff uninitialized. */
25079 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25083 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25084 top, bottom, and between upper and lower strings. */
25085 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25086 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25087 /* Center vertically.
25088 H:base_height, D:base_descent
25089 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25091 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25092 descent = D - H/2 + h/2;
25093 lower_yoff = descent - 2 - ld;
25094 upper_yoff = lower_yoff - la - 1 - ud; */
25095 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25096 descent
= it
->descent
- (base_height
- height
) / 2;
25097 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25098 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25099 - metrics_upper
.descent
);
25100 /* Don't make the height shorter than the base height. */
25101 if (height
> base_height
)
25103 it
->ascent
= ascent
;
25104 it
->descent
= descent
;
25108 it
->phys_ascent
= it
->ascent
;
25109 it
->phys_descent
= it
->descent
;
25111 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25112 upper_xoff
, upper_yoff
,
25113 lower_xoff
, lower_yoff
);
25115 take_vertical_position_into_account (it
);
25120 Produce glyphs/get display metrics for the display element IT is
25121 loaded with. See the description of struct it in dispextern.h
25122 for an overview of struct it. */
25125 x_produce_glyphs (struct it
*it
)
25127 int extra_line_spacing
= it
->extra_line_spacing
;
25129 it
->glyph_not_available_p
= 0;
25131 if (it
->what
== IT_CHARACTER
)
25134 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25135 struct font
*font
= face
->font
;
25136 struct font_metrics
*pcm
= NULL
;
25137 int boff
; /* baseline offset */
25141 /* When no suitable font is found, display this character by
25142 the method specified in the first extra slot of
25143 Vglyphless_char_display. */
25144 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25146 eassert (it
->what
== IT_GLYPHLESS
);
25147 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25151 boff
= font
->baseline_offset
;
25152 if (font
->vertical_centering
)
25153 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25155 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25161 if (it
->override_ascent
>= 0)
25163 it
->ascent
= it
->override_ascent
;
25164 it
->descent
= it
->override_descent
;
25165 boff
= it
->override_boff
;
25169 it
->ascent
= FONT_BASE (font
) + boff
;
25170 it
->descent
= FONT_DESCENT (font
) - boff
;
25173 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25175 pcm
= get_per_char_metric (font
, &char2b
);
25176 if (pcm
->width
== 0
25177 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25183 it
->phys_ascent
= pcm
->ascent
+ boff
;
25184 it
->phys_descent
= pcm
->descent
- boff
;
25185 it
->pixel_width
= pcm
->width
;
25189 it
->glyph_not_available_p
= 1;
25190 it
->phys_ascent
= it
->ascent
;
25191 it
->phys_descent
= it
->descent
;
25192 it
->pixel_width
= font
->space_width
;
25195 if (it
->constrain_row_ascent_descent_p
)
25197 if (it
->descent
> it
->max_descent
)
25199 it
->ascent
+= it
->descent
- it
->max_descent
;
25200 it
->descent
= it
->max_descent
;
25202 if (it
->ascent
> it
->max_ascent
)
25204 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25205 it
->ascent
= it
->max_ascent
;
25207 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25208 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25209 extra_line_spacing
= 0;
25212 /* If this is a space inside a region of text with
25213 `space-width' property, change its width. */
25214 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25216 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25218 /* If face has a box, add the box thickness to the character
25219 height. If character has a box line to the left and/or
25220 right, add the box line width to the character's width. */
25221 if (face
->box
!= FACE_NO_BOX
)
25223 int thick
= face
->box_line_width
;
25227 it
->ascent
+= thick
;
25228 it
->descent
+= thick
;
25233 if (it
->start_of_box_run_p
)
25234 it
->pixel_width
+= thick
;
25235 if (it
->end_of_box_run_p
)
25236 it
->pixel_width
+= thick
;
25239 /* If face has an overline, add the height of the overline
25240 (1 pixel) and a 1 pixel margin to the character height. */
25241 if (face
->overline_p
)
25242 it
->ascent
+= overline_margin
;
25244 if (it
->constrain_row_ascent_descent_p
)
25246 if (it
->ascent
> it
->max_ascent
)
25247 it
->ascent
= it
->max_ascent
;
25248 if (it
->descent
> it
->max_descent
)
25249 it
->descent
= it
->max_descent
;
25252 take_vertical_position_into_account (it
);
25254 /* If we have to actually produce glyphs, do it. */
25259 /* Translate a space with a `space-width' property
25260 into a stretch glyph. */
25261 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25262 / FONT_HEIGHT (font
));
25263 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25264 it
->ascent
+ it
->descent
, ascent
);
25269 /* If characters with lbearing or rbearing are displayed
25270 in this line, record that fact in a flag of the
25271 glyph row. This is used to optimize X output code. */
25272 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25273 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25275 if (! stretched_p
&& it
->pixel_width
== 0)
25276 /* We assure that all visible glyphs have at least 1-pixel
25278 it
->pixel_width
= 1;
25280 else if (it
->char_to_display
== '\n')
25282 /* A newline has no width, but we need the height of the
25283 line. But if previous part of the line sets a height,
25284 don't increase that height */
25286 Lisp_Object height
;
25287 Lisp_Object total_height
= Qnil
;
25289 it
->override_ascent
= -1;
25290 it
->pixel_width
= 0;
25293 height
= get_it_property (it
, Qline_height
);
25294 /* Split (line-height total-height) list */
25296 && CONSP (XCDR (height
))
25297 && NILP (XCDR (XCDR (height
))))
25299 total_height
= XCAR (XCDR (height
));
25300 height
= XCAR (height
);
25302 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25304 if (it
->override_ascent
>= 0)
25306 it
->ascent
= it
->override_ascent
;
25307 it
->descent
= it
->override_descent
;
25308 boff
= it
->override_boff
;
25312 it
->ascent
= FONT_BASE (font
) + boff
;
25313 it
->descent
= FONT_DESCENT (font
) - boff
;
25316 if (EQ (height
, Qt
))
25318 if (it
->descent
> it
->max_descent
)
25320 it
->ascent
+= it
->descent
- it
->max_descent
;
25321 it
->descent
= it
->max_descent
;
25323 if (it
->ascent
> it
->max_ascent
)
25325 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25326 it
->ascent
= it
->max_ascent
;
25328 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25329 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25330 it
->constrain_row_ascent_descent_p
= 1;
25331 extra_line_spacing
= 0;
25335 Lisp_Object spacing
;
25337 it
->phys_ascent
= it
->ascent
;
25338 it
->phys_descent
= it
->descent
;
25340 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25341 && face
->box
!= FACE_NO_BOX
25342 && face
->box_line_width
> 0)
25344 it
->ascent
+= face
->box_line_width
;
25345 it
->descent
+= face
->box_line_width
;
25348 && XINT (height
) > it
->ascent
+ it
->descent
)
25349 it
->ascent
= XINT (height
) - it
->descent
;
25351 if (!NILP (total_height
))
25352 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25355 spacing
= get_it_property (it
, Qline_spacing
);
25356 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25358 if (INTEGERP (spacing
))
25360 extra_line_spacing
= XINT (spacing
);
25361 if (!NILP (total_height
))
25362 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25366 else /* i.e. (it->char_to_display == '\t') */
25368 if (font
->space_width
> 0)
25370 int tab_width
= it
->tab_width
* font
->space_width
;
25371 int x
= it
->current_x
+ it
->continuation_lines_width
;
25372 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25374 /* If the distance from the current position to the next tab
25375 stop is less than a space character width, use the
25376 tab stop after that. */
25377 if (next_tab_x
- x
< font
->space_width
)
25378 next_tab_x
+= tab_width
;
25380 it
->pixel_width
= next_tab_x
- x
;
25382 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25383 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25387 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25388 it
->ascent
+ it
->descent
, it
->ascent
);
25393 it
->pixel_width
= 0;
25398 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25400 /* A static composition.
25402 Note: A composition is represented as one glyph in the
25403 glyph matrix. There are no padding glyphs.
25405 Important note: pixel_width, ascent, and descent are the
25406 values of what is drawn by draw_glyphs (i.e. the values of
25407 the overall glyphs composed). */
25408 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25409 int boff
; /* baseline offset */
25410 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25411 int glyph_len
= cmp
->glyph_len
;
25412 struct font
*font
= face
->font
;
25416 /* If we have not yet calculated pixel size data of glyphs of
25417 the composition for the current face font, calculate them
25418 now. Theoretically, we have to check all fonts for the
25419 glyphs, but that requires much time and memory space. So,
25420 here we check only the font of the first glyph. This may
25421 lead to incorrect display, but it's very rare, and C-l
25422 (recenter-top-bottom) can correct the display anyway. */
25423 if (! cmp
->font
|| cmp
->font
!= font
)
25425 /* Ascent and descent of the font of the first character
25426 of this composition (adjusted by baseline offset).
25427 Ascent and descent of overall glyphs should not be less
25428 than these, respectively. */
25429 int font_ascent
, font_descent
, font_height
;
25430 /* Bounding box of the overall glyphs. */
25431 int leftmost
, rightmost
, lowest
, highest
;
25432 int lbearing
, rbearing
;
25433 int i
, width
, ascent
, descent
;
25434 int left_padded
= 0, right_padded
= 0;
25435 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25437 struct font_metrics
*pcm
;
25438 int font_not_found_p
;
25441 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25442 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25444 if (glyph_len
< cmp
->glyph_len
)
25446 for (i
= 0; i
< glyph_len
; i
++)
25448 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25450 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25455 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25456 : IT_CHARPOS (*it
));
25457 /* If no suitable font is found, use the default font. */
25458 font_not_found_p
= font
== NULL
;
25459 if (font_not_found_p
)
25461 face
= face
->ascii_face
;
25464 boff
= font
->baseline_offset
;
25465 if (font
->vertical_centering
)
25466 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25467 font_ascent
= FONT_BASE (font
) + boff
;
25468 font_descent
= FONT_DESCENT (font
) - boff
;
25469 font_height
= FONT_HEIGHT (font
);
25474 if (! font_not_found_p
)
25476 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25478 pcm
= get_per_char_metric (font
, &char2b
);
25481 /* Initialize the bounding box. */
25484 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25485 ascent
= pcm
->ascent
;
25486 descent
= pcm
->descent
;
25487 lbearing
= pcm
->lbearing
;
25488 rbearing
= pcm
->rbearing
;
25492 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25493 ascent
= FONT_BASE (font
);
25494 descent
= FONT_DESCENT (font
);
25501 lowest
= - descent
+ boff
;
25502 highest
= ascent
+ boff
;
25504 if (! font_not_found_p
25505 && font
->default_ascent
25506 && CHAR_TABLE_P (Vuse_default_ascent
)
25507 && !NILP (Faref (Vuse_default_ascent
,
25508 make_number (it
->char_to_display
))))
25509 highest
= font
->default_ascent
+ boff
;
25511 /* Draw the first glyph at the normal position. It may be
25512 shifted to right later if some other glyphs are drawn
25514 cmp
->offsets
[i
* 2] = 0;
25515 cmp
->offsets
[i
* 2 + 1] = boff
;
25516 cmp
->lbearing
= lbearing
;
25517 cmp
->rbearing
= rbearing
;
25519 /* Set cmp->offsets for the remaining glyphs. */
25520 for (i
++; i
< glyph_len
; i
++)
25522 int left
, right
, btm
, top
;
25523 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25525 struct face
*this_face
;
25529 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25530 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25531 font
= this_face
->font
;
25537 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25539 pcm
= get_per_char_metric (font
, &char2b
);
25542 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25545 width
= pcm
->width
;
25546 ascent
= pcm
->ascent
;
25547 descent
= pcm
->descent
;
25548 lbearing
= pcm
->lbearing
;
25549 rbearing
= pcm
->rbearing
;
25550 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25552 /* Relative composition with or without
25553 alternate chars. */
25554 left
= (leftmost
+ rightmost
- width
) / 2;
25555 btm
= - descent
+ boff
;
25556 if (font
->relative_compose
25557 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25558 || NILP (Faref (Vignore_relative_composition
,
25559 make_number (ch
)))))
25562 if (- descent
>= font
->relative_compose
)
25563 /* One extra pixel between two glyphs. */
25565 else if (ascent
<= 0)
25566 /* One extra pixel between two glyphs. */
25567 btm
= lowest
- 1 - ascent
- descent
;
25572 /* A composition rule is specified by an integer
25573 value that encodes global and new reference
25574 points (GREF and NREF). GREF and NREF are
25575 specified by numbers as below:
25577 0---1---2 -- ascent
25581 9--10--11 -- center
25583 ---3---4---5--- baseline
25585 6---7---8 -- descent
25587 int rule
= COMPOSITION_RULE (cmp
, i
);
25588 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25590 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25591 grefx
= gref
% 3, nrefx
= nref
% 3;
25592 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25594 xoff
= font_height
* (xoff
- 128) / 256;
25596 yoff
= font_height
* (yoff
- 128) / 256;
25599 + grefx
* (rightmost
- leftmost
) / 2
25600 - nrefx
* width
/ 2
25603 btm
= ((grefy
== 0 ? highest
25605 : grefy
== 2 ? lowest
25606 : (highest
+ lowest
) / 2)
25607 - (nrefy
== 0 ? ascent
+ descent
25608 : nrefy
== 1 ? descent
- boff
25610 : (ascent
+ descent
) / 2)
25614 cmp
->offsets
[i
* 2] = left
;
25615 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25617 /* Update the bounding box of the overall glyphs. */
25620 right
= left
+ width
;
25621 if (left
< leftmost
)
25623 if (right
> rightmost
)
25626 top
= btm
+ descent
+ ascent
;
25632 if (cmp
->lbearing
> left
+ lbearing
)
25633 cmp
->lbearing
= left
+ lbearing
;
25634 if (cmp
->rbearing
< left
+ rbearing
)
25635 cmp
->rbearing
= left
+ rbearing
;
25639 /* If there are glyphs whose x-offsets are negative,
25640 shift all glyphs to the right and make all x-offsets
25644 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25645 cmp
->offsets
[i
* 2] -= leftmost
;
25646 rightmost
-= leftmost
;
25647 cmp
->lbearing
-= leftmost
;
25648 cmp
->rbearing
-= leftmost
;
25651 if (left_padded
&& cmp
->lbearing
< 0)
25653 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25654 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25655 rightmost
-= cmp
->lbearing
;
25656 cmp
->rbearing
-= cmp
->lbearing
;
25659 if (right_padded
&& rightmost
< cmp
->rbearing
)
25661 rightmost
= cmp
->rbearing
;
25664 cmp
->pixel_width
= rightmost
;
25665 cmp
->ascent
= highest
;
25666 cmp
->descent
= - lowest
;
25667 if (cmp
->ascent
< font_ascent
)
25668 cmp
->ascent
= font_ascent
;
25669 if (cmp
->descent
< font_descent
)
25670 cmp
->descent
= font_descent
;
25674 && (cmp
->lbearing
< 0
25675 || cmp
->rbearing
> cmp
->pixel_width
))
25676 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25678 it
->pixel_width
= cmp
->pixel_width
;
25679 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25680 it
->descent
= it
->phys_descent
= cmp
->descent
;
25681 if (face
->box
!= FACE_NO_BOX
)
25683 int thick
= face
->box_line_width
;
25687 it
->ascent
+= thick
;
25688 it
->descent
+= thick
;
25693 if (it
->start_of_box_run_p
)
25694 it
->pixel_width
+= thick
;
25695 if (it
->end_of_box_run_p
)
25696 it
->pixel_width
+= thick
;
25699 /* If face has an overline, add the height of the overline
25700 (1 pixel) and a 1 pixel margin to the character height. */
25701 if (face
->overline_p
)
25702 it
->ascent
+= overline_margin
;
25704 take_vertical_position_into_account (it
);
25705 if (it
->ascent
< 0)
25707 if (it
->descent
< 0)
25710 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25711 append_composite_glyph (it
);
25713 else if (it
->what
== IT_COMPOSITION
)
25715 /* A dynamic (automatic) composition. */
25716 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25717 Lisp_Object gstring
;
25718 struct font_metrics metrics
;
25722 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25724 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25727 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25728 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25729 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25730 it
->descent
= it
->phys_descent
= metrics
.descent
;
25731 if (face
->box
!= FACE_NO_BOX
)
25733 int thick
= face
->box_line_width
;
25737 it
->ascent
+= thick
;
25738 it
->descent
+= thick
;
25743 if (it
->start_of_box_run_p
)
25744 it
->pixel_width
+= thick
;
25745 if (it
->end_of_box_run_p
)
25746 it
->pixel_width
+= thick
;
25748 /* If face has an overline, add the height of the overline
25749 (1 pixel) and a 1 pixel margin to the character height. */
25750 if (face
->overline_p
)
25751 it
->ascent
+= overline_margin
;
25752 take_vertical_position_into_account (it
);
25753 if (it
->ascent
< 0)
25755 if (it
->descent
< 0)
25759 append_composite_glyph (it
);
25761 else if (it
->what
== IT_GLYPHLESS
)
25762 produce_glyphless_glyph (it
, 0, Qnil
);
25763 else if (it
->what
== IT_IMAGE
)
25764 produce_image_glyph (it
);
25765 else if (it
->what
== IT_STRETCH
)
25766 produce_stretch_glyph (it
);
25769 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25770 because this isn't true for images with `:ascent 100'. */
25771 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25772 if (it
->area
== TEXT_AREA
)
25773 it
->current_x
+= it
->pixel_width
;
25775 if (extra_line_spacing
> 0)
25777 it
->descent
+= extra_line_spacing
;
25778 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25779 it
->max_extra_line_spacing
= extra_line_spacing
;
25782 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25783 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25784 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25785 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25789 Output LEN glyphs starting at START at the nominal cursor position.
25790 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25791 being updated, and UPDATED_AREA is the area of that row being updated. */
25794 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25795 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25797 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25799 eassert (updated_row
);
25800 /* When the window is hscrolled, cursor hpos can legitimately be out
25801 of bounds, but we draw the cursor at the corresponding window
25802 margin in that case. */
25803 if (!updated_row
->reversed_p
&& chpos
< 0)
25805 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25806 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25810 /* Write glyphs. */
25812 hpos
= start
- updated_row
->glyphs
[updated_area
];
25813 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25814 updated_row
, updated_area
,
25816 DRAW_NORMAL_TEXT
, 0);
25818 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25819 if (updated_area
== TEXT_AREA
25820 && w
->phys_cursor_on_p
25821 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25823 && chpos
< hpos
+ len
)
25824 w
->phys_cursor_on_p
= 0;
25828 /* Advance the output cursor. */
25829 w
->output_cursor
.hpos
+= len
;
25830 w
->output_cursor
.x
= x
;
25835 Insert LEN glyphs from START at the nominal cursor position. */
25838 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25839 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25842 int line_height
, shift_by_width
, shifted_region_width
;
25843 struct glyph_row
*row
;
25844 struct glyph
*glyph
;
25845 int frame_x
, frame_y
;
25848 eassert (updated_row
);
25850 f
= XFRAME (WINDOW_FRAME (w
));
25852 /* Get the height of the line we are in. */
25854 line_height
= row
->height
;
25856 /* Get the width of the glyphs to insert. */
25857 shift_by_width
= 0;
25858 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25859 shift_by_width
+= glyph
->pixel_width
;
25861 /* Get the width of the region to shift right. */
25862 shifted_region_width
= (window_box_width (w
, updated_area
)
25863 - w
->output_cursor
.x
25867 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25868 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25870 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25871 line_height
, shift_by_width
);
25873 /* Write the glyphs. */
25874 hpos
= start
- row
->glyphs
[updated_area
];
25875 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25877 DRAW_NORMAL_TEXT
, 0);
25879 /* Advance the output cursor. */
25880 w
->output_cursor
.hpos
+= len
;
25881 w
->output_cursor
.x
+= shift_by_width
;
25887 Erase the current text line from the nominal cursor position
25888 (inclusive) to pixel column TO_X (exclusive). The idea is that
25889 everything from TO_X onward is already erased.
25891 TO_X is a pixel position relative to UPDATED_AREA of currently
25892 updated window W. TO_X == -1 means clear to the end of this area. */
25895 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25896 enum glyph_row_area updated_area
, int to_x
)
25899 int max_x
, min_y
, max_y
;
25900 int from_x
, from_y
, to_y
;
25902 eassert (updated_row
);
25903 f
= XFRAME (w
->frame
);
25905 if (updated_row
->full_width_p
)
25906 max_x
= WINDOW_TOTAL_WIDTH (w
);
25908 max_x
= window_box_width (w
, updated_area
);
25909 max_y
= window_text_bottom_y (w
);
25911 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25912 of window. For TO_X > 0, truncate to end of drawing area. */
25918 to_x
= min (to_x
, max_x
);
25920 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25922 /* Notice if the cursor will be cleared by this operation. */
25923 if (!updated_row
->full_width_p
)
25924 notice_overwritten_cursor (w
, updated_area
,
25925 w
->output_cursor
.x
, -1,
25927 MATRIX_ROW_BOTTOM_Y (updated_row
));
25929 from_x
= w
->output_cursor
.x
;
25931 /* Translate to frame coordinates. */
25932 if (updated_row
->full_width_p
)
25934 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25935 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25939 int area_left
= window_box_left (w
, updated_area
);
25940 from_x
+= area_left
;
25944 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25945 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
25946 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25948 /* Prevent inadvertently clearing to end of the X window. */
25949 if (to_x
> from_x
&& to_y
> from_y
)
25952 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25953 to_x
- from_x
, to_y
- from_y
);
25958 #endif /* HAVE_WINDOW_SYSTEM */
25962 /***********************************************************************
25964 ***********************************************************************/
25966 /* Value is the internal representation of the specified cursor type
25967 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25968 of the bar cursor. */
25970 static enum text_cursor_kinds
25971 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25973 enum text_cursor_kinds type
;
25978 if (EQ (arg
, Qbox
))
25979 return FILLED_BOX_CURSOR
;
25981 if (EQ (arg
, Qhollow
))
25982 return HOLLOW_BOX_CURSOR
;
25984 if (EQ (arg
, Qbar
))
25991 && EQ (XCAR (arg
), Qbar
)
25992 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25994 *width
= XINT (XCDR (arg
));
25998 if (EQ (arg
, Qhbar
))
26001 return HBAR_CURSOR
;
26005 && EQ (XCAR (arg
), Qhbar
)
26006 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26008 *width
= XINT (XCDR (arg
));
26009 return HBAR_CURSOR
;
26012 /* Treat anything unknown as "hollow box cursor".
26013 It was bad to signal an error; people have trouble fixing
26014 .Xdefaults with Emacs, when it has something bad in it. */
26015 type
= HOLLOW_BOX_CURSOR
;
26020 /* Set the default cursor types for specified frame. */
26022 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26027 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26028 FRAME_CURSOR_WIDTH (f
) = width
;
26030 /* By default, set up the blink-off state depending on the on-state. */
26032 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26035 FRAME_BLINK_OFF_CURSOR (f
)
26036 = get_specified_cursor_type (XCDR (tem
), &width
);
26037 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26040 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26042 /* Make sure the cursor gets redrawn. */
26043 cursor_type_changed
= 1;
26047 #ifdef HAVE_WINDOW_SYSTEM
26049 /* Return the cursor we want to be displayed in window W. Return
26050 width of bar/hbar cursor through WIDTH arg. Return with
26051 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26052 (i.e. if the `system caret' should track this cursor).
26054 In a mini-buffer window, we want the cursor only to appear if we
26055 are reading input from this window. For the selected window, we
26056 want the cursor type given by the frame parameter or buffer local
26057 setting of cursor-type. If explicitly marked off, draw no cursor.
26058 In all other cases, we want a hollow box cursor. */
26060 static enum text_cursor_kinds
26061 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26062 int *active_cursor
)
26064 struct frame
*f
= XFRAME (w
->frame
);
26065 struct buffer
*b
= XBUFFER (w
->contents
);
26066 int cursor_type
= DEFAULT_CURSOR
;
26067 Lisp_Object alt_cursor
;
26068 int non_selected
= 0;
26070 *active_cursor
= 1;
26073 if (cursor_in_echo_area
26074 && FRAME_HAS_MINIBUF_P (f
)
26075 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26077 if (w
== XWINDOW (echo_area_window
))
26079 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26081 *width
= FRAME_CURSOR_WIDTH (f
);
26082 return FRAME_DESIRED_CURSOR (f
);
26085 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26088 *active_cursor
= 0;
26092 /* Detect a nonselected window or nonselected frame. */
26093 else if (w
!= XWINDOW (f
->selected_window
)
26094 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26096 *active_cursor
= 0;
26098 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26104 /* Never display a cursor in a window in which cursor-type is nil. */
26105 if (NILP (BVAR (b
, cursor_type
)))
26108 /* Get the normal cursor type for this window. */
26109 if (EQ (BVAR (b
, cursor_type
), Qt
))
26111 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26112 *width
= FRAME_CURSOR_WIDTH (f
);
26115 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26117 /* Use cursor-in-non-selected-windows instead
26118 for non-selected window or frame. */
26121 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26122 if (!EQ (Qt
, alt_cursor
))
26123 return get_specified_cursor_type (alt_cursor
, width
);
26124 /* t means modify the normal cursor type. */
26125 if (cursor_type
== FILLED_BOX_CURSOR
)
26126 cursor_type
= HOLLOW_BOX_CURSOR
;
26127 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26129 return cursor_type
;
26132 /* Use normal cursor if not blinked off. */
26133 if (!w
->cursor_off_p
)
26135 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26137 if (cursor_type
== FILLED_BOX_CURSOR
)
26139 /* Using a block cursor on large images can be very annoying.
26140 So use a hollow cursor for "large" images.
26141 If image is not transparent (no mask), also use hollow cursor. */
26142 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26143 if (img
!= NULL
&& IMAGEP (img
->spec
))
26145 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26146 where N = size of default frame font size.
26147 This should cover most of the "tiny" icons people may use. */
26149 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26150 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26151 cursor_type
= HOLLOW_BOX_CURSOR
;
26154 else if (cursor_type
!= NO_CURSOR
)
26156 /* Display current only supports BOX and HOLLOW cursors for images.
26157 So for now, unconditionally use a HOLLOW cursor when cursor is
26158 not a solid box cursor. */
26159 cursor_type
= HOLLOW_BOX_CURSOR
;
26162 return cursor_type
;
26165 /* Cursor is blinked off, so determine how to "toggle" it. */
26167 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26168 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26169 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26171 /* Then see if frame has specified a specific blink off cursor type. */
26172 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26174 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26175 return FRAME_BLINK_OFF_CURSOR (f
);
26179 /* Some people liked having a permanently visible blinking cursor,
26180 while others had very strong opinions against it. So it was
26181 decided to remove it. KFS 2003-09-03 */
26183 /* Finally perform built-in cursor blinking:
26184 filled box <-> hollow box
26185 wide [h]bar <-> narrow [h]bar
26186 narrow [h]bar <-> no cursor
26187 other type <-> no cursor */
26189 if (cursor_type
== FILLED_BOX_CURSOR
)
26190 return HOLLOW_BOX_CURSOR
;
26192 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26195 return cursor_type
;
26203 /* Notice when the text cursor of window W has been completely
26204 overwritten by a drawing operation that outputs glyphs in AREA
26205 starting at X0 and ending at X1 in the line starting at Y0 and
26206 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26207 the rest of the line after X0 has been written. Y coordinates
26208 are window-relative. */
26211 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26212 int x0
, int x1
, int y0
, int y1
)
26214 int cx0
, cx1
, cy0
, cy1
;
26215 struct glyph_row
*row
;
26217 if (!w
->phys_cursor_on_p
)
26219 if (area
!= TEXT_AREA
)
26222 if (w
->phys_cursor
.vpos
< 0
26223 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26224 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26225 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26228 if (row
->cursor_in_fringe_p
)
26230 row
->cursor_in_fringe_p
= 0;
26231 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26232 w
->phys_cursor_on_p
= 0;
26236 cx0
= w
->phys_cursor
.x
;
26237 cx1
= cx0
+ w
->phys_cursor_width
;
26238 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26241 /* The cursor image will be completely removed from the
26242 screen if the output area intersects the cursor area in
26243 y-direction. When we draw in [y0 y1[, and some part of
26244 the cursor is at y < y0, that part must have been drawn
26245 before. When scrolling, the cursor is erased before
26246 actually scrolling, so we don't come here. When not
26247 scrolling, the rows above the old cursor row must have
26248 changed, and in this case these rows must have written
26249 over the cursor image.
26251 Likewise if part of the cursor is below y1, with the
26252 exception of the cursor being in the first blank row at
26253 the buffer and window end because update_text_area
26254 doesn't draw that row. (Except when it does, but
26255 that's handled in update_text_area.) */
26257 cy0
= w
->phys_cursor
.y
;
26258 cy1
= cy0
+ w
->phys_cursor_height
;
26259 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26262 w
->phys_cursor_on_p
= 0;
26265 #endif /* HAVE_WINDOW_SYSTEM */
26268 /************************************************************************
26270 ************************************************************************/
26272 #ifdef HAVE_WINDOW_SYSTEM
26275 Fix the display of area AREA of overlapping row ROW in window W
26276 with respect to the overlapping part OVERLAPS. */
26279 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26280 enum glyph_row_area area
, int overlaps
)
26287 for (i
= 0; i
< row
->used
[area
];)
26289 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26291 int start
= i
, start_x
= x
;
26295 x
+= row
->glyphs
[area
][i
].pixel_width
;
26298 while (i
< row
->used
[area
]
26299 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26301 draw_glyphs (w
, start_x
, row
, area
,
26303 DRAW_NORMAL_TEXT
, overlaps
);
26307 x
+= row
->glyphs
[area
][i
].pixel_width
;
26317 Draw the cursor glyph of window W in glyph row ROW. See the
26318 comment of draw_glyphs for the meaning of HL. */
26321 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26322 enum draw_glyphs_face hl
)
26324 /* If cursor hpos is out of bounds, don't draw garbage. This can
26325 happen in mini-buffer windows when switching between echo area
26326 glyphs and mini-buffer. */
26327 if ((row
->reversed_p
26328 ? (w
->phys_cursor
.hpos
>= 0)
26329 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26331 int on_p
= w
->phys_cursor_on_p
;
26333 int hpos
= w
->phys_cursor
.hpos
;
26335 /* When the window is hscrolled, cursor hpos can legitimately be
26336 out of bounds, but we draw the cursor at the corresponding
26337 window margin in that case. */
26338 if (!row
->reversed_p
&& hpos
< 0)
26340 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26341 hpos
= row
->used
[TEXT_AREA
] - 1;
26343 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26345 w
->phys_cursor_on_p
= on_p
;
26347 if (hl
== DRAW_CURSOR
)
26348 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26349 /* When we erase the cursor, and ROW is overlapped by other
26350 rows, make sure that these overlapping parts of other rows
26352 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26354 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26356 if (row
> w
->current_matrix
->rows
26357 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26358 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26359 OVERLAPS_ERASED_CURSOR
);
26361 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26362 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26363 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26364 OVERLAPS_ERASED_CURSOR
);
26371 Erase the image of a cursor of window W from the screen. */
26374 erase_phys_cursor (struct window
*w
)
26376 struct frame
*f
= XFRAME (w
->frame
);
26377 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26378 int hpos
= w
->phys_cursor
.hpos
;
26379 int vpos
= w
->phys_cursor
.vpos
;
26380 int mouse_face_here_p
= 0;
26381 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26382 struct glyph_row
*cursor_row
;
26383 struct glyph
*cursor_glyph
;
26384 enum draw_glyphs_face hl
;
26386 /* No cursor displayed or row invalidated => nothing to do on the
26388 if (w
->phys_cursor_type
== NO_CURSOR
)
26389 goto mark_cursor_off
;
26391 /* VPOS >= active_glyphs->nrows means that window has been resized.
26392 Don't bother to erase the cursor. */
26393 if (vpos
>= active_glyphs
->nrows
)
26394 goto mark_cursor_off
;
26396 /* If row containing cursor is marked invalid, there is nothing we
26398 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26399 if (!cursor_row
->enabled_p
)
26400 goto mark_cursor_off
;
26402 /* If line spacing is > 0, old cursor may only be partially visible in
26403 window after split-window. So adjust visible height. */
26404 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26405 window_text_bottom_y (w
) - cursor_row
->y
);
26407 /* If row is completely invisible, don't attempt to delete a cursor which
26408 isn't there. This can happen if cursor is at top of a window, and
26409 we switch to a buffer with a header line in that window. */
26410 if (cursor_row
->visible_height
<= 0)
26411 goto mark_cursor_off
;
26413 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26414 if (cursor_row
->cursor_in_fringe_p
)
26416 cursor_row
->cursor_in_fringe_p
= 0;
26417 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26418 goto mark_cursor_off
;
26421 /* This can happen when the new row is shorter than the old one.
26422 In this case, either draw_glyphs or clear_end_of_line
26423 should have cleared the cursor. Note that we wouldn't be
26424 able to erase the cursor in this case because we don't have a
26425 cursor glyph at hand. */
26426 if ((cursor_row
->reversed_p
26427 ? (w
->phys_cursor
.hpos
< 0)
26428 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26429 goto mark_cursor_off
;
26431 /* When the window is hscrolled, cursor hpos can legitimately be out
26432 of bounds, but we draw the cursor at the corresponding window
26433 margin in that case. */
26434 if (!cursor_row
->reversed_p
&& hpos
< 0)
26436 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26437 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26439 /* If the cursor is in the mouse face area, redisplay that when
26440 we clear the cursor. */
26441 if (! NILP (hlinfo
->mouse_face_window
)
26442 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26443 /* Don't redraw the cursor's spot in mouse face if it is at the
26444 end of a line (on a newline). The cursor appears there, but
26445 mouse highlighting does not. */
26446 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26447 mouse_face_here_p
= 1;
26449 /* Maybe clear the display under the cursor. */
26450 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26453 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26456 cursor_glyph
= get_phys_cursor_glyph (w
);
26457 if (cursor_glyph
== NULL
)
26458 goto mark_cursor_off
;
26460 width
= cursor_glyph
->pixel_width
;
26461 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26462 x
= w
->phys_cursor
.x
;
26464 width
-= left_x
- x
;
26465 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26466 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26467 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26470 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26473 /* Erase the cursor by redrawing the character underneath it. */
26474 if (mouse_face_here_p
)
26475 hl
= DRAW_MOUSE_FACE
;
26477 hl
= DRAW_NORMAL_TEXT
;
26478 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26481 w
->phys_cursor_on_p
= 0;
26482 w
->phys_cursor_type
= NO_CURSOR
;
26487 Display or clear cursor of window W. If ON is zero, clear the
26488 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26489 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26492 display_and_set_cursor (struct window
*w
, bool on
,
26493 int hpos
, int vpos
, int x
, int y
)
26495 struct frame
*f
= XFRAME (w
->frame
);
26496 int new_cursor_type
;
26497 int new_cursor_width
;
26499 struct glyph_row
*glyph_row
;
26500 struct glyph
*glyph
;
26502 /* This is pointless on invisible frames, and dangerous on garbaged
26503 windows and frames; in the latter case, the frame or window may
26504 be in the midst of changing its size, and x and y may be off the
26506 if (! FRAME_VISIBLE_P (f
)
26507 || FRAME_GARBAGED_P (f
)
26508 || vpos
>= w
->current_matrix
->nrows
26509 || hpos
>= w
->current_matrix
->matrix_w
)
26512 /* If cursor is off and we want it off, return quickly. */
26513 if (!on
&& !w
->phys_cursor_on_p
)
26516 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26517 /* If cursor row is not enabled, we don't really know where to
26518 display the cursor. */
26519 if (!glyph_row
->enabled_p
)
26521 w
->phys_cursor_on_p
= 0;
26526 if (!glyph_row
->exact_window_width_line_p
26527 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26528 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26530 eassert (input_blocked_p ());
26532 /* Set new_cursor_type to the cursor we want to be displayed. */
26533 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26534 &new_cursor_width
, &active_cursor
);
26536 /* If cursor is currently being shown and we don't want it to be or
26537 it is in the wrong place, or the cursor type is not what we want,
26539 if (w
->phys_cursor_on_p
26541 || w
->phys_cursor
.x
!= x
26542 || w
->phys_cursor
.y
!= y
26543 || new_cursor_type
!= w
->phys_cursor_type
26544 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26545 && new_cursor_width
!= w
->phys_cursor_width
)))
26546 erase_phys_cursor (w
);
26548 /* Don't check phys_cursor_on_p here because that flag is only set
26549 to zero in some cases where we know that the cursor has been
26550 completely erased, to avoid the extra work of erasing the cursor
26551 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26552 still not be visible, or it has only been partly erased. */
26555 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26556 w
->phys_cursor_height
= glyph_row
->height
;
26558 /* Set phys_cursor_.* before x_draw_.* is called because some
26559 of them may need the information. */
26560 w
->phys_cursor
.x
= x
;
26561 w
->phys_cursor
.y
= glyph_row
->y
;
26562 w
->phys_cursor
.hpos
= hpos
;
26563 w
->phys_cursor
.vpos
= vpos
;
26566 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26567 new_cursor_type
, new_cursor_width
,
26568 on
, active_cursor
);
26572 /* Switch the display of W's cursor on or off, according to the value
26576 update_window_cursor (struct window
*w
, bool on
)
26578 /* Don't update cursor in windows whose frame is in the process
26579 of being deleted. */
26580 if (w
->current_matrix
)
26582 int hpos
= w
->phys_cursor
.hpos
;
26583 int vpos
= w
->phys_cursor
.vpos
;
26584 struct glyph_row
*row
;
26586 if (vpos
>= w
->current_matrix
->nrows
26587 || hpos
>= w
->current_matrix
->matrix_w
)
26590 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26592 /* When the window is hscrolled, cursor hpos can legitimately be
26593 out of bounds, but we draw the cursor at the corresponding
26594 window margin in that case. */
26595 if (!row
->reversed_p
&& hpos
< 0)
26597 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26598 hpos
= row
->used
[TEXT_AREA
] - 1;
26601 display_and_set_cursor (w
, on
, hpos
, vpos
,
26602 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26608 /* Call update_window_cursor with parameter ON_P on all leaf windows
26609 in the window tree rooted at W. */
26612 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26616 if (WINDOWP (w
->contents
))
26617 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26619 update_window_cursor (w
, on_p
);
26621 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26627 Display the cursor on window W, or clear it, according to ON_P.
26628 Don't change the cursor's position. */
26631 x_update_cursor (struct frame
*f
, bool on_p
)
26633 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26638 Clear the cursor of window W to background color, and mark the
26639 cursor as not shown. This is used when the text where the cursor
26640 is about to be rewritten. */
26643 x_clear_cursor (struct window
*w
)
26645 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26646 update_window_cursor (w
, 0);
26649 #endif /* HAVE_WINDOW_SYSTEM */
26651 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26654 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26655 int start_hpos
, int end_hpos
,
26656 enum draw_glyphs_face draw
)
26658 #ifdef HAVE_WINDOW_SYSTEM
26659 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26661 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26665 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26666 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26670 /* Display the active region described by mouse_face_* according to DRAW. */
26673 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26675 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26676 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26678 if (/* If window is in the process of being destroyed, don't bother
26680 w
->current_matrix
!= NULL
26681 /* Don't update mouse highlight if hidden */
26682 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26683 /* Recognize when we are called to operate on rows that don't exist
26684 anymore. This can happen when a window is split. */
26685 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26687 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26688 struct glyph_row
*row
, *first
, *last
;
26690 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26691 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26693 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26695 int start_hpos
, end_hpos
, start_x
;
26697 /* For all but the first row, the highlight starts at column 0. */
26700 /* R2L rows have BEG and END in reversed order, but the
26701 screen drawing geometry is always left to right. So
26702 we need to mirror the beginning and end of the
26703 highlighted area in R2L rows. */
26704 if (!row
->reversed_p
)
26706 start_hpos
= hlinfo
->mouse_face_beg_col
;
26707 start_x
= hlinfo
->mouse_face_beg_x
;
26709 else if (row
== last
)
26711 start_hpos
= hlinfo
->mouse_face_end_col
;
26712 start_x
= hlinfo
->mouse_face_end_x
;
26720 else if (row
->reversed_p
&& row
== last
)
26722 start_hpos
= hlinfo
->mouse_face_end_col
;
26723 start_x
= hlinfo
->mouse_face_end_x
;
26733 if (!row
->reversed_p
)
26734 end_hpos
= hlinfo
->mouse_face_end_col
;
26735 else if (row
== first
)
26736 end_hpos
= hlinfo
->mouse_face_beg_col
;
26739 end_hpos
= row
->used
[TEXT_AREA
];
26740 if (draw
== DRAW_NORMAL_TEXT
)
26741 row
->fill_line_p
= 1; /* Clear to end of line */
26744 else if (row
->reversed_p
&& row
== first
)
26745 end_hpos
= hlinfo
->mouse_face_beg_col
;
26748 end_hpos
= row
->used
[TEXT_AREA
];
26749 if (draw
== DRAW_NORMAL_TEXT
)
26750 row
->fill_line_p
= 1; /* Clear to end of line */
26753 if (end_hpos
> start_hpos
)
26755 draw_row_with_mouse_face (w
, start_x
, row
,
26756 start_hpos
, end_hpos
, draw
);
26759 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26763 #ifdef HAVE_WINDOW_SYSTEM
26764 /* When we've written over the cursor, arrange for it to
26765 be displayed again. */
26766 if (FRAME_WINDOW_P (f
)
26767 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26769 int hpos
= w
->phys_cursor
.hpos
;
26771 /* When the window is hscrolled, cursor hpos can legitimately be
26772 out of bounds, but we draw the cursor at the corresponding
26773 window margin in that case. */
26774 if (!row
->reversed_p
&& hpos
< 0)
26776 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26777 hpos
= row
->used
[TEXT_AREA
] - 1;
26780 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26781 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26784 #endif /* HAVE_WINDOW_SYSTEM */
26787 #ifdef HAVE_WINDOW_SYSTEM
26788 /* Change the mouse cursor. */
26789 if (FRAME_WINDOW_P (f
))
26791 if (draw
== DRAW_NORMAL_TEXT
26792 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26793 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26794 else if (draw
== DRAW_MOUSE_FACE
)
26795 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26797 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26799 #endif /* HAVE_WINDOW_SYSTEM */
26803 Clear out the mouse-highlighted active region.
26804 Redraw it un-highlighted first. Value is non-zero if mouse
26805 face was actually drawn unhighlighted. */
26808 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26812 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26814 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26818 reset_mouse_highlight (hlinfo
);
26822 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26823 within the mouse face on that window. */
26825 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26827 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26829 /* Quickly resolve the easy cases. */
26830 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26831 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26833 if (vpos
< hlinfo
->mouse_face_beg_row
26834 || vpos
> hlinfo
->mouse_face_end_row
)
26836 if (vpos
> hlinfo
->mouse_face_beg_row
26837 && vpos
< hlinfo
->mouse_face_end_row
)
26840 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26842 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26844 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26847 else if ((vpos
== hlinfo
->mouse_face_beg_row
26848 && hpos
>= hlinfo
->mouse_face_beg_col
)
26849 || (vpos
== hlinfo
->mouse_face_end_row
26850 && hpos
< hlinfo
->mouse_face_end_col
))
26855 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26857 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26860 else if ((vpos
== hlinfo
->mouse_face_beg_row
26861 && hpos
<= hlinfo
->mouse_face_beg_col
)
26862 || (vpos
== hlinfo
->mouse_face_end_row
26863 && hpos
> hlinfo
->mouse_face_end_col
))
26871 Non-zero if physical cursor of window W is within mouse face. */
26874 cursor_in_mouse_face_p (struct window
*w
)
26876 int hpos
= w
->phys_cursor
.hpos
;
26877 int vpos
= w
->phys_cursor
.vpos
;
26878 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26880 /* When the window is hscrolled, cursor hpos can legitimately be out
26881 of bounds, but we draw the cursor at the corresponding window
26882 margin in that case. */
26883 if (!row
->reversed_p
&& hpos
< 0)
26885 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26886 hpos
= row
->used
[TEXT_AREA
] - 1;
26888 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26893 /* Find the glyph rows START_ROW and END_ROW of window W that display
26894 characters between buffer positions START_CHARPOS and END_CHARPOS
26895 (excluding END_CHARPOS). DISP_STRING is a display string that
26896 covers these buffer positions. This is similar to
26897 row_containing_pos, but is more accurate when bidi reordering makes
26898 buffer positions change non-linearly with glyph rows. */
26900 rows_from_pos_range (struct window
*w
,
26901 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26902 Lisp_Object disp_string
,
26903 struct glyph_row
**start
, struct glyph_row
**end
)
26905 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26906 int last_y
= window_text_bottom_y (w
);
26907 struct glyph_row
*row
;
26912 while (!first
->enabled_p
26913 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26916 /* Find the START row. */
26918 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26921 /* A row can potentially be the START row if the range of the
26922 characters it displays intersects the range
26923 [START_CHARPOS..END_CHARPOS). */
26924 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26925 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26926 /* See the commentary in row_containing_pos, for the
26927 explanation of the complicated way to check whether
26928 some position is beyond the end of the characters
26929 displayed by a row. */
26930 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26931 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26932 && !row
->ends_at_zv_p
26933 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26934 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26935 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26936 && !row
->ends_at_zv_p
26937 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26939 /* Found a candidate row. Now make sure at least one of the
26940 glyphs it displays has a charpos from the range
26941 [START_CHARPOS..END_CHARPOS).
26943 This is not obvious because bidi reordering could make
26944 buffer positions of a row be 1,2,3,102,101,100, and if we
26945 want to highlight characters in [50..60), we don't want
26946 this row, even though [50..60) does intersect [1..103),
26947 the range of character positions given by the row's start
26948 and end positions. */
26949 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26950 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26954 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26955 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26956 /* A glyph that comes from DISP_STRING is by
26957 definition to be highlighted. */
26958 || EQ (g
->object
, disp_string
))
26967 /* Find the END row. */
26969 /* If the last row is partially visible, start looking for END
26970 from that row, instead of starting from FIRST. */
26971 && !(row
->enabled_p
26972 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26974 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26976 struct glyph_row
*next
= row
+ 1;
26977 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26979 if (!next
->enabled_p
26980 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26981 /* The first row >= START whose range of displayed characters
26982 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26983 is the row END + 1. */
26984 || (start_charpos
< next_start
26985 && end_charpos
< next_start
)
26986 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26987 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26988 && !next
->ends_at_zv_p
26989 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26990 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26991 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26992 && !next
->ends_at_zv_p
26993 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27000 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27001 but none of the characters it displays are in the range, it is
27003 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27004 struct glyph
*s
= g
;
27005 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27009 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27010 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27011 /* If the buffer position of the first glyph in
27012 the row is equal to END_CHARPOS, it means
27013 the last character to be highlighted is the
27014 newline of ROW, and we must consider NEXT as
27016 || (((!next
->reversed_p
&& g
== s
)
27017 || (next
->reversed_p
&& g
== e
- 1))
27018 && (g
->charpos
== end_charpos
27019 /* Special case for when NEXT is an
27020 empty line at ZV. */
27021 || (g
->charpos
== -1
27022 && !row
->ends_at_zv_p
27023 && next_start
== end_charpos
)))))
27024 /* A glyph that comes from DISP_STRING is by
27025 definition to be highlighted. */
27026 || EQ (g
->object
, disp_string
))
27035 /* The first row that ends at ZV must be the last to be
27037 else if (next
->ends_at_zv_p
)
27046 /* This function sets the mouse_face_* elements of HLINFO, assuming
27047 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27048 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27049 for the overlay or run of text properties specifying the mouse
27050 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27051 before-string and after-string that must also be highlighted.
27052 DISP_STRING, if non-nil, is a display string that may cover some
27053 or all of the highlighted text. */
27056 mouse_face_from_buffer_pos (Lisp_Object window
,
27057 Mouse_HLInfo
*hlinfo
,
27058 ptrdiff_t mouse_charpos
,
27059 ptrdiff_t start_charpos
,
27060 ptrdiff_t end_charpos
,
27061 Lisp_Object before_string
,
27062 Lisp_Object after_string
,
27063 Lisp_Object disp_string
)
27065 struct window
*w
= XWINDOW (window
);
27066 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27067 struct glyph_row
*r1
, *r2
;
27068 struct glyph
*glyph
, *end
;
27069 ptrdiff_t ignore
, pos
;
27072 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27073 eassert (NILP (before_string
) || STRINGP (before_string
));
27074 eassert (NILP (after_string
) || STRINGP (after_string
));
27076 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27077 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27079 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27080 /* If the before-string or display-string contains newlines,
27081 rows_from_pos_range skips to its last row. Move back. */
27082 if (!NILP (before_string
) || !NILP (disp_string
))
27084 struct glyph_row
*prev
;
27085 while ((prev
= r1
- 1, prev
>= first
)
27086 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27087 && prev
->used
[TEXT_AREA
] > 0)
27089 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27090 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27091 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27093 || !(EQ (glyph
->object
, before_string
)
27094 || EQ (glyph
->object
, disp_string
)))
27101 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27102 hlinfo
->mouse_face_past_end
= 1;
27104 else if (!NILP (after_string
))
27106 /* If the after-string has newlines, advance to its last row. */
27107 struct glyph_row
*next
;
27108 struct glyph_row
*last
27109 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27111 for (next
= r2
+ 1;
27113 && next
->used
[TEXT_AREA
] > 0
27114 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27118 /* The rest of the display engine assumes that mouse_face_beg_row is
27119 either above mouse_face_end_row or identical to it. But with
27120 bidi-reordered continued lines, the row for START_CHARPOS could
27121 be below the row for END_CHARPOS. If so, swap the rows and store
27122 them in correct order. */
27125 struct glyph_row
*tem
= r2
;
27131 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27132 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27134 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27135 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27136 could be anywhere in the row and in any order. The strategy
27137 below is to find the leftmost and the rightmost glyph that
27138 belongs to either of these 3 strings, or whose position is
27139 between START_CHARPOS and END_CHARPOS, and highlight all the
27140 glyphs between those two. This may cover more than just the text
27141 between START_CHARPOS and END_CHARPOS if the range of characters
27142 strides the bidi level boundary, e.g. if the beginning is in R2L
27143 text while the end is in L2R text or vice versa. */
27144 if (!r1
->reversed_p
)
27146 /* This row is in a left to right paragraph. Scan it left to
27148 glyph
= r1
->glyphs
[TEXT_AREA
];
27149 end
= glyph
+ r1
->used
[TEXT_AREA
];
27152 /* Skip truncation glyphs at the start of the glyph row. */
27153 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27155 && INTEGERP (glyph
->object
)
27156 && glyph
->charpos
< 0;
27158 x
+= glyph
->pixel_width
;
27160 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27161 or DISP_STRING, and the first glyph from buffer whose
27162 position is between START_CHARPOS and END_CHARPOS. */
27164 && !INTEGERP (glyph
->object
)
27165 && !EQ (glyph
->object
, disp_string
)
27166 && !(BUFFERP (glyph
->object
)
27167 && (glyph
->charpos
>= start_charpos
27168 && glyph
->charpos
< end_charpos
));
27171 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27172 are present at buffer positions between START_CHARPOS and
27173 END_CHARPOS, or if they come from an overlay. */
27174 if (EQ (glyph
->object
, before_string
))
27176 pos
= string_buffer_position (before_string
,
27178 /* If pos == 0, it means before_string came from an
27179 overlay, not from a buffer position. */
27180 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27183 else if (EQ (glyph
->object
, after_string
))
27185 pos
= string_buffer_position (after_string
, end_charpos
);
27186 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27189 x
+= glyph
->pixel_width
;
27191 hlinfo
->mouse_face_beg_x
= x
;
27192 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27196 /* This row is in a right to left paragraph. Scan it right to
27200 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27201 glyph
= end
+ r1
->used
[TEXT_AREA
];
27203 /* Skip truncation glyphs at the start of the glyph row. */
27204 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27206 && INTEGERP (glyph
->object
)
27207 && glyph
->charpos
< 0;
27211 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27212 or DISP_STRING, and the first glyph from buffer whose
27213 position is between START_CHARPOS and END_CHARPOS. */
27215 && !INTEGERP (glyph
->object
)
27216 && !EQ (glyph
->object
, disp_string
)
27217 && !(BUFFERP (glyph
->object
)
27218 && (glyph
->charpos
>= start_charpos
27219 && glyph
->charpos
< end_charpos
));
27222 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27223 are present at buffer positions between START_CHARPOS and
27224 END_CHARPOS, or if they come from an overlay. */
27225 if (EQ (glyph
->object
, before_string
))
27227 pos
= string_buffer_position (before_string
, start_charpos
);
27228 /* If pos == 0, it means before_string came from an
27229 overlay, not from a buffer position. */
27230 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27233 else if (EQ (glyph
->object
, after_string
))
27235 pos
= string_buffer_position (after_string
, end_charpos
);
27236 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27241 glyph
++; /* first glyph to the right of the highlighted area */
27242 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27243 x
+= g
->pixel_width
;
27244 hlinfo
->mouse_face_beg_x
= x
;
27245 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27248 /* If the highlight ends in a different row, compute GLYPH and END
27249 for the end row. Otherwise, reuse the values computed above for
27250 the row where the highlight begins. */
27253 if (!r2
->reversed_p
)
27255 glyph
= r2
->glyphs
[TEXT_AREA
];
27256 end
= glyph
+ r2
->used
[TEXT_AREA
];
27261 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27262 glyph
= end
+ r2
->used
[TEXT_AREA
];
27266 if (!r2
->reversed_p
)
27268 /* Skip truncation and continuation glyphs near the end of the
27269 row, and also blanks and stretch glyphs inserted by
27270 extend_face_to_end_of_line. */
27272 && INTEGERP ((end
- 1)->object
))
27274 /* Scan the rest of the glyph row from the end, looking for the
27275 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27276 DISP_STRING, or whose position is between START_CHARPOS
27280 && !INTEGERP (end
->object
)
27281 && !EQ (end
->object
, disp_string
)
27282 && !(BUFFERP (end
->object
)
27283 && (end
->charpos
>= start_charpos
27284 && end
->charpos
< end_charpos
));
27287 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27288 are present at buffer positions between START_CHARPOS and
27289 END_CHARPOS, or if they come from an overlay. */
27290 if (EQ (end
->object
, before_string
))
27292 pos
= string_buffer_position (before_string
, start_charpos
);
27293 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27296 else if (EQ (end
->object
, after_string
))
27298 pos
= string_buffer_position (after_string
, end_charpos
);
27299 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27303 /* Find the X coordinate of the last glyph to be highlighted. */
27304 for (; glyph
<= end
; ++glyph
)
27305 x
+= glyph
->pixel_width
;
27307 hlinfo
->mouse_face_end_x
= x
;
27308 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27312 /* Skip truncation and continuation glyphs near the end of the
27313 row, and also blanks and stretch glyphs inserted by
27314 extend_face_to_end_of_line. */
27318 && INTEGERP (end
->object
))
27320 x
+= end
->pixel_width
;
27323 /* Scan the rest of the glyph row from the end, looking for the
27324 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27325 DISP_STRING, or whose position is between START_CHARPOS
27329 && !INTEGERP (end
->object
)
27330 && !EQ (end
->object
, disp_string
)
27331 && !(BUFFERP (end
->object
)
27332 && (end
->charpos
>= start_charpos
27333 && end
->charpos
< end_charpos
));
27336 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27337 are present at buffer positions between START_CHARPOS and
27338 END_CHARPOS, or if they come from an overlay. */
27339 if (EQ (end
->object
, before_string
))
27341 pos
= string_buffer_position (before_string
, start_charpos
);
27342 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27345 else if (EQ (end
->object
, after_string
))
27347 pos
= string_buffer_position (after_string
, end_charpos
);
27348 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27351 x
+= end
->pixel_width
;
27353 /* If we exited the above loop because we arrived at the last
27354 glyph of the row, and its buffer position is still not in
27355 range, it means the last character in range is the preceding
27356 newline. Bump the end column and x values to get past the
27359 && BUFFERP (end
->object
)
27360 && (end
->charpos
< start_charpos
27361 || end
->charpos
>= end_charpos
))
27363 x
+= end
->pixel_width
;
27366 hlinfo
->mouse_face_end_x
= x
;
27367 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27370 hlinfo
->mouse_face_window
= window
;
27371 hlinfo
->mouse_face_face_id
27372 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27374 !hlinfo
->mouse_face_hidden
, -1);
27375 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27378 /* The following function is not used anymore (replaced with
27379 mouse_face_from_string_pos), but I leave it here for the time
27380 being, in case someone would. */
27382 #if 0 /* not used */
27384 /* Find the position of the glyph for position POS in OBJECT in
27385 window W's current matrix, and return in *X, *Y the pixel
27386 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27388 RIGHT_P non-zero means return the position of the right edge of the
27389 glyph, RIGHT_P zero means return the left edge position.
27391 If no glyph for POS exists in the matrix, return the position of
27392 the glyph with the next smaller position that is in the matrix, if
27393 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27394 exists in the matrix, return the position of the glyph with the
27395 next larger position in OBJECT.
27397 Value is non-zero if a glyph was found. */
27400 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27401 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27403 int yb
= window_text_bottom_y (w
);
27404 struct glyph_row
*r
;
27405 struct glyph
*best_glyph
= NULL
;
27406 struct glyph_row
*best_row
= NULL
;
27409 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27410 r
->enabled_p
&& r
->y
< yb
;
27413 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27414 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27417 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27418 if (EQ (g
->object
, object
))
27420 if (g
->charpos
== pos
)
27427 else if (best_glyph
== NULL
27428 || ((eabs (g
->charpos
- pos
)
27429 < eabs (best_glyph
->charpos
- pos
))
27432 : g
->charpos
> pos
)))
27446 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27450 *x
+= best_glyph
->pixel_width
;
27455 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27458 return best_glyph
!= NULL
;
27460 #endif /* not used */
27462 /* Find the positions of the first and the last glyphs in window W's
27463 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27464 (assumed to be a string), and return in HLINFO's mouse_face_*
27465 members the pixel and column/row coordinates of those glyphs. */
27468 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27469 Lisp_Object object
,
27470 ptrdiff_t startpos
, ptrdiff_t endpos
)
27472 int yb
= window_text_bottom_y (w
);
27473 struct glyph_row
*r
;
27474 struct glyph
*g
, *e
;
27478 /* Find the glyph row with at least one position in the range
27479 [STARTPOS..ENDPOS], and the first glyph in that row whose
27480 position belongs to that range. */
27481 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27482 r
->enabled_p
&& r
->y
< yb
;
27485 if (!r
->reversed_p
)
27487 g
= r
->glyphs
[TEXT_AREA
];
27488 e
= g
+ r
->used
[TEXT_AREA
];
27489 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27490 if (EQ (g
->object
, object
)
27491 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27493 hlinfo
->mouse_face_beg_row
27494 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27495 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27496 hlinfo
->mouse_face_beg_x
= gx
;
27505 e
= r
->glyphs
[TEXT_AREA
];
27506 g
= e
+ r
->used
[TEXT_AREA
];
27507 for ( ; g
> e
; --g
)
27508 if (EQ ((g
-1)->object
, object
)
27509 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27511 hlinfo
->mouse_face_beg_row
27512 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27513 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27514 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27515 gx
+= g1
->pixel_width
;
27516 hlinfo
->mouse_face_beg_x
= gx
;
27528 /* Starting with the next row, look for the first row which does NOT
27529 include any glyphs whose positions are in the range. */
27530 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27532 g
= r
->glyphs
[TEXT_AREA
];
27533 e
= g
+ r
->used
[TEXT_AREA
];
27535 for ( ; g
< e
; ++g
)
27536 if (EQ (g
->object
, object
)
27537 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27546 /* The highlighted region ends on the previous row. */
27549 /* Set the end row. */
27550 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27552 /* Compute and set the end column and the end column's horizontal
27553 pixel coordinate. */
27554 if (!r
->reversed_p
)
27556 g
= r
->glyphs
[TEXT_AREA
];
27557 e
= g
+ r
->used
[TEXT_AREA
];
27558 for ( ; e
> g
; --e
)
27559 if (EQ ((e
-1)->object
, object
)
27560 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27562 hlinfo
->mouse_face_end_col
= e
- g
;
27564 for (gx
= r
->x
; g
< e
; ++g
)
27565 gx
+= g
->pixel_width
;
27566 hlinfo
->mouse_face_end_x
= gx
;
27570 e
= r
->glyphs
[TEXT_AREA
];
27571 g
= e
+ r
->used
[TEXT_AREA
];
27572 for (gx
= r
->x
; e
< g
; ++e
)
27574 if (EQ (e
->object
, object
)
27575 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27577 gx
+= e
->pixel_width
;
27579 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27580 hlinfo
->mouse_face_end_x
= gx
;
27584 #ifdef HAVE_WINDOW_SYSTEM
27586 /* See if position X, Y is within a hot-spot of an image. */
27589 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27591 if (!CONSP (hot_spot
))
27594 if (EQ (XCAR (hot_spot
), Qrect
))
27596 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27597 Lisp_Object rect
= XCDR (hot_spot
);
27601 if (!CONSP (XCAR (rect
)))
27603 if (!CONSP (XCDR (rect
)))
27605 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27607 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27609 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27611 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27615 else if (EQ (XCAR (hot_spot
), Qcircle
))
27617 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27618 Lisp_Object circ
= XCDR (hot_spot
);
27619 Lisp_Object lr
, lx0
, ly0
;
27621 && CONSP (XCAR (circ
))
27622 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27623 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27624 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27626 double r
= XFLOATINT (lr
);
27627 double dx
= XINT (lx0
) - x
;
27628 double dy
= XINT (ly0
) - y
;
27629 return (dx
* dx
+ dy
* dy
<= r
* r
);
27632 else if (EQ (XCAR (hot_spot
), Qpoly
))
27634 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27635 if (VECTORP (XCDR (hot_spot
)))
27637 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27638 Lisp_Object
*poly
= v
->contents
;
27639 ptrdiff_t n
= v
->header
.size
;
27642 Lisp_Object lx
, ly
;
27645 /* Need an even number of coordinates, and at least 3 edges. */
27646 if (n
< 6 || n
& 1)
27649 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27650 If count is odd, we are inside polygon. Pixels on edges
27651 may or may not be included depending on actual geometry of the
27653 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27654 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27656 x0
= XINT (lx
), y0
= XINT (ly
);
27657 for (i
= 0; i
< n
; i
+= 2)
27659 int x1
= x0
, y1
= y0
;
27660 if ((lx
= poly
[i
], !INTEGERP (lx
))
27661 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27663 x0
= XINT (lx
), y0
= XINT (ly
);
27665 /* Does this segment cross the X line? */
27673 if (y
> y0
&& y
> y1
)
27675 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27685 find_hot_spot (Lisp_Object map
, int x
, int y
)
27687 while (CONSP (map
))
27689 if (CONSP (XCAR (map
))
27690 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27698 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27700 doc
: /* Lookup in image map MAP coordinates X and Y.
27701 An image map is an alist where each element has the format (AREA ID PLIST).
27702 An AREA is specified as either a rectangle, a circle, or a polygon:
27703 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27704 pixel coordinates of the upper left and bottom right corners.
27705 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27706 and the radius of the circle; r may be a float or integer.
27707 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27708 vector describes one corner in the polygon.
27709 Returns the alist element for the first matching AREA in MAP. */)
27710 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27718 return find_hot_spot (map
,
27719 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27720 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27724 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27726 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27728 /* Do not change cursor shape while dragging mouse. */
27729 if (!NILP (do_mouse_tracking
))
27732 if (!NILP (pointer
))
27734 if (EQ (pointer
, Qarrow
))
27735 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27736 else if (EQ (pointer
, Qhand
))
27737 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27738 else if (EQ (pointer
, Qtext
))
27739 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27740 else if (EQ (pointer
, intern ("hdrag")))
27741 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27742 #ifdef HAVE_X_WINDOWS
27743 else if (EQ (pointer
, intern ("vdrag")))
27744 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27746 else if (EQ (pointer
, intern ("hourglass")))
27747 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27748 else if (EQ (pointer
, Qmodeline
))
27749 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27751 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27754 if (cursor
!= No_Cursor
)
27755 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27758 #endif /* HAVE_WINDOW_SYSTEM */
27760 /* Take proper action when mouse has moved to the mode or header line
27761 or marginal area AREA of window W, x-position X and y-position Y.
27762 X is relative to the start of the text display area of W, so the
27763 width of bitmap areas and scroll bars must be subtracted to get a
27764 position relative to the start of the mode line. */
27767 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27768 enum window_part area
)
27770 struct window
*w
= XWINDOW (window
);
27771 struct frame
*f
= XFRAME (w
->frame
);
27772 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27773 #ifdef HAVE_WINDOW_SYSTEM
27774 Display_Info
*dpyinfo
;
27776 Cursor cursor
= No_Cursor
;
27777 Lisp_Object pointer
= Qnil
;
27778 int dx
, dy
, width
, height
;
27780 Lisp_Object string
, object
= Qnil
;
27781 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27783 Lisp_Object mouse_face
;
27784 int original_x_pixel
= x
;
27785 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27786 struct glyph_row
*row
IF_LINT (= 0);
27788 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27793 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27794 returns them in row/column units! */
27795 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27796 &object
, &dx
, &dy
, &width
, &height
);
27798 row
= (area
== ON_MODE_LINE
27799 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27800 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27802 /* Find the glyph under the mouse pointer. */
27803 if (row
->mode_line_p
&& row
->enabled_p
)
27805 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27806 end
= glyph
+ row
->used
[TEXT_AREA
];
27808 for (x0
= original_x_pixel
;
27809 glyph
< end
&& x0
>= glyph
->pixel_width
;
27811 x0
-= glyph
->pixel_width
;
27819 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27820 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27821 returns them in row/column units! */
27822 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27823 &object
, &dx
, &dy
, &width
, &height
);
27828 #ifdef HAVE_WINDOW_SYSTEM
27829 if (IMAGEP (object
))
27831 Lisp_Object image_map
, hotspot
;
27832 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27834 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27836 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27840 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27841 If so, we could look for mouse-enter, mouse-leave
27842 properties in PLIST (and do something...). */
27843 hotspot
= XCDR (hotspot
);
27844 if (CONSP (hotspot
)
27845 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27847 pointer
= Fplist_get (plist
, Qpointer
);
27848 if (NILP (pointer
))
27850 help
= Fplist_get (plist
, Qhelp_echo
);
27853 help_echo_string
= help
;
27854 XSETWINDOW (help_echo_window
, w
);
27855 help_echo_object
= w
->contents
;
27856 help_echo_pos
= charpos
;
27860 if (NILP (pointer
))
27861 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27863 #endif /* HAVE_WINDOW_SYSTEM */
27865 if (STRINGP (string
))
27866 pos
= make_number (charpos
);
27868 /* Set the help text and mouse pointer. If the mouse is on a part
27869 of the mode line without any text (e.g. past the right edge of
27870 the mode line text), use the default help text and pointer. */
27871 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27873 /* Arrange to display the help by setting the global variables
27874 help_echo_string, help_echo_object, and help_echo_pos. */
27877 if (STRINGP (string
))
27878 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27882 help_echo_string
= help
;
27883 XSETWINDOW (help_echo_window
, w
);
27884 help_echo_object
= string
;
27885 help_echo_pos
= charpos
;
27887 else if (area
== ON_MODE_LINE
)
27889 Lisp_Object default_help
27890 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27893 if (STRINGP (default_help
))
27895 help_echo_string
= default_help
;
27896 XSETWINDOW (help_echo_window
, w
);
27897 help_echo_object
= Qnil
;
27898 help_echo_pos
= -1;
27903 #ifdef HAVE_WINDOW_SYSTEM
27904 /* Change the mouse pointer according to what is under it. */
27905 if (FRAME_WINDOW_P (f
))
27907 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27908 if (STRINGP (string
))
27910 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27912 if (NILP (pointer
))
27913 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27915 /* Change the mouse pointer according to what is under X/Y. */
27917 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27920 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27921 if (!KEYMAPP (map
))
27922 map
= Fget_text_property (pos
, Qkeymap
, string
);
27923 if (!KEYMAPP (map
))
27924 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27928 /* Default mode-line pointer. */
27929 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27934 /* Change the mouse face according to what is under X/Y. */
27935 if (STRINGP (string
))
27937 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27938 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
27939 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27944 struct glyph
* tmp_glyph
;
27948 int total_pixel_width
;
27949 ptrdiff_t begpos
, endpos
, ignore
;
27953 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27954 Qmouse_face
, string
, Qnil
);
27960 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27962 endpos
= SCHARS (string
);
27966 /* Calculate the glyph position GPOS of GLYPH in the
27967 displayed string, relative to the beginning of the
27968 highlighted part of the string.
27970 Note: GPOS is different from CHARPOS. CHARPOS is the
27971 position of GLYPH in the internal string object. A mode
27972 line string format has structures which are converted to
27973 a flattened string by the Emacs Lisp interpreter. The
27974 internal string is an element of those structures. The
27975 displayed string is the flattened string. */
27976 tmp_glyph
= row_start_glyph
;
27977 while (tmp_glyph
< glyph
27978 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27979 && begpos
<= tmp_glyph
->charpos
27980 && tmp_glyph
->charpos
< endpos
)))
27982 gpos
= glyph
- tmp_glyph
;
27984 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27985 the highlighted part of the displayed string to which
27986 GLYPH belongs. Note: GSEQ_LENGTH is different from
27987 SCHARS (STRING), because the latter returns the length of
27988 the internal string. */
27989 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27991 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27992 && begpos
<= tmp_glyph
->charpos
27993 && tmp_glyph
->charpos
< endpos
));
27996 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27998 /* Calculate the total pixel width of all the glyphs between
27999 the beginning of the highlighted area and GLYPH. */
28000 total_pixel_width
= 0;
28001 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28002 total_pixel_width
+= tmp_glyph
->pixel_width
;
28004 /* Pre calculation of re-rendering position. Note: X is in
28005 column units here, after the call to mode_line_string or
28006 marginal_area_string. */
28008 vpos
= (area
== ON_MODE_LINE
28009 ? (w
->current_matrix
)->nrows
- 1
28012 /* If GLYPH's position is included in the region that is
28013 already drawn in mouse face, we have nothing to do. */
28014 if ( EQ (window
, hlinfo
->mouse_face_window
)
28015 && (!row
->reversed_p
28016 ? (hlinfo
->mouse_face_beg_col
<= hpos
28017 && hpos
< hlinfo
->mouse_face_end_col
)
28018 /* In R2L rows we swap BEG and END, see below. */
28019 : (hlinfo
->mouse_face_end_col
<= hpos
28020 && hpos
< hlinfo
->mouse_face_beg_col
))
28021 && hlinfo
->mouse_face_beg_row
== vpos
)
28024 if (clear_mouse_face (hlinfo
))
28025 cursor
= No_Cursor
;
28027 if (!row
->reversed_p
)
28029 hlinfo
->mouse_face_beg_col
= hpos
;
28030 hlinfo
->mouse_face_beg_x
= original_x_pixel
28031 - (total_pixel_width
+ dx
);
28032 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28033 hlinfo
->mouse_face_end_x
= 0;
28037 /* In R2L rows, show_mouse_face expects BEG and END
28038 coordinates to be swapped. */
28039 hlinfo
->mouse_face_end_col
= hpos
;
28040 hlinfo
->mouse_face_end_x
= original_x_pixel
28041 - (total_pixel_width
+ dx
);
28042 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28043 hlinfo
->mouse_face_beg_x
= 0;
28046 hlinfo
->mouse_face_beg_row
= vpos
;
28047 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28048 hlinfo
->mouse_face_past_end
= 0;
28049 hlinfo
->mouse_face_window
= window
;
28051 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28057 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28059 if (NILP (pointer
))
28062 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28063 clear_mouse_face (hlinfo
);
28065 #ifdef HAVE_WINDOW_SYSTEM
28066 if (FRAME_WINDOW_P (f
))
28067 define_frame_cursor1 (f
, cursor
, pointer
);
28073 Take proper action when the mouse has moved to position X, Y on
28074 frame F with regards to highlighting portions of display that have
28075 mouse-face properties. Also de-highlight portions of display where
28076 the mouse was before, set the mouse pointer shape as appropriate
28077 for the mouse coordinates, and activate help echo (tooltips).
28078 X and Y can be negative or out of range. */
28081 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28083 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28084 enum window_part part
= ON_NOTHING
;
28085 Lisp_Object window
;
28087 Cursor cursor
= No_Cursor
;
28088 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28091 /* When a menu is active, don't highlight because this looks odd. */
28092 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28093 if (popup_activated ())
28097 if (!f
->glyphs_initialized_p
28098 || f
->pointer_invisible
)
28101 hlinfo
->mouse_face_mouse_x
= x
;
28102 hlinfo
->mouse_face_mouse_y
= y
;
28103 hlinfo
->mouse_face_mouse_frame
= f
;
28105 if (hlinfo
->mouse_face_defer
)
28108 /* Which window is that in? */
28109 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28111 /* If displaying active text in another window, clear that. */
28112 if (! EQ (window
, hlinfo
->mouse_face_window
)
28113 /* Also clear if we move out of text area in same window. */
28114 || (!NILP (hlinfo
->mouse_face_window
)
28117 && part
!= ON_MODE_LINE
28118 && part
!= ON_HEADER_LINE
))
28119 clear_mouse_face (hlinfo
);
28121 /* Not on a window -> return. */
28122 if (!WINDOWP (window
))
28125 /* Reset help_echo_string. It will get recomputed below. */
28126 help_echo_string
= Qnil
;
28128 /* Convert to window-relative pixel coordinates. */
28129 w
= XWINDOW (window
);
28130 frame_to_window_pixel_xy (w
, &x
, &y
);
28132 #ifdef HAVE_WINDOW_SYSTEM
28133 /* Handle tool-bar window differently since it doesn't display a
28135 if (EQ (window
, f
->tool_bar_window
))
28137 note_tool_bar_highlight (f
, x
, y
);
28142 /* Mouse is on the mode, header line or margin? */
28143 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28144 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28146 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28150 #ifdef HAVE_WINDOW_SYSTEM
28151 if (part
== ON_VERTICAL_BORDER
)
28153 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28154 help_echo_string
= build_string ("drag-mouse-1: resize");
28156 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28157 || part
== ON_SCROLL_BAR
)
28158 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28160 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28163 /* Are we in a window whose display is up to date?
28164 And verify the buffer's text has not changed. */
28165 b
= XBUFFER (w
->contents
);
28166 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28168 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28170 struct glyph
*glyph
;
28171 Lisp_Object object
;
28172 Lisp_Object mouse_face
= Qnil
, position
;
28173 Lisp_Object
*overlay_vec
= NULL
;
28174 ptrdiff_t i
, noverlays
;
28175 struct buffer
*obuf
;
28176 ptrdiff_t obegv
, ozv
;
28179 /* Find the glyph under X/Y. */
28180 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28182 #ifdef HAVE_WINDOW_SYSTEM
28183 /* Look for :pointer property on image. */
28184 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28186 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28187 if (img
!= NULL
&& IMAGEP (img
->spec
))
28189 Lisp_Object image_map
, hotspot
;
28190 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28192 && (hotspot
= find_hot_spot (image_map
,
28193 glyph
->slice
.img
.x
+ dx
,
28194 glyph
->slice
.img
.y
+ dy
),
28196 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28200 /* Could check XCAR (hotspot) to see if we enter/leave
28202 If so, we could look for mouse-enter, mouse-leave
28203 properties in PLIST (and do something...). */
28204 hotspot
= XCDR (hotspot
);
28205 if (CONSP (hotspot
)
28206 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28208 pointer
= Fplist_get (plist
, Qpointer
);
28209 if (NILP (pointer
))
28211 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28212 if (!NILP (help_echo_string
))
28214 help_echo_window
= window
;
28215 help_echo_object
= glyph
->object
;
28216 help_echo_pos
= glyph
->charpos
;
28220 if (NILP (pointer
))
28221 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28224 #endif /* HAVE_WINDOW_SYSTEM */
28226 /* Clear mouse face if X/Y not over text. */
28228 || area
!= TEXT_AREA
28229 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28230 /* Glyph's OBJECT is an integer for glyphs inserted by the
28231 display engine for its internal purposes, like truncation
28232 and continuation glyphs and blanks beyond the end of
28233 line's text on text terminals. If we are over such a
28234 glyph, we are not over any text. */
28235 || INTEGERP (glyph
->object
)
28236 /* R2L rows have a stretch glyph at their front, which
28237 stands for no text, whereas L2R rows have no glyphs at
28238 all beyond the end of text. Treat such stretch glyphs
28239 like we do with NULL glyphs in L2R rows. */
28240 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28241 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28242 && glyph
->type
== STRETCH_GLYPH
28243 && glyph
->avoid_cursor_p
))
28245 if (clear_mouse_face (hlinfo
))
28246 cursor
= No_Cursor
;
28247 #ifdef HAVE_WINDOW_SYSTEM
28248 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28250 if (area
!= TEXT_AREA
)
28251 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28253 pointer
= Vvoid_text_area_pointer
;
28259 pos
= glyph
->charpos
;
28260 object
= glyph
->object
;
28261 if (!STRINGP (object
) && !BUFFERP (object
))
28264 /* If we get an out-of-range value, return now; avoid an error. */
28265 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28268 /* Make the window's buffer temporarily current for
28269 overlays_at and compute_char_face. */
28270 obuf
= current_buffer
;
28271 current_buffer
= b
;
28277 /* Is this char mouse-active or does it have help-echo? */
28278 position
= make_number (pos
);
28280 if (BUFFERP (object
))
28282 /* Put all the overlays we want in a vector in overlay_vec. */
28283 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28284 /* Sort overlays into increasing priority order. */
28285 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28290 if (NILP (Vmouse_highlight
))
28292 clear_mouse_face (hlinfo
);
28293 goto check_help_echo
;
28296 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28299 cursor
= No_Cursor
;
28301 /* Check mouse-face highlighting. */
28303 /* If there exists an overlay with mouse-face overlapping
28304 the one we are currently highlighting, we have to
28305 check if we enter the overlapping overlay, and then
28306 highlight only that. */
28307 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28308 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28310 /* Find the highest priority overlay with a mouse-face. */
28311 Lisp_Object overlay
= Qnil
;
28312 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28314 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28315 if (!NILP (mouse_face
))
28316 overlay
= overlay_vec
[i
];
28319 /* If we're highlighting the same overlay as before, there's
28320 no need to do that again. */
28321 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28322 goto check_help_echo
;
28323 hlinfo
->mouse_face_overlay
= overlay
;
28325 /* Clear the display of the old active region, if any. */
28326 if (clear_mouse_face (hlinfo
))
28327 cursor
= No_Cursor
;
28329 /* If no overlay applies, get a text property. */
28330 if (NILP (overlay
))
28331 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28333 /* Next, compute the bounds of the mouse highlighting and
28335 if (!NILP (mouse_face
) && STRINGP (object
))
28337 /* The mouse-highlighting comes from a display string
28338 with a mouse-face. */
28342 s
= Fprevious_single_property_change
28343 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28344 e
= Fnext_single_property_change
28345 (position
, Qmouse_face
, object
, Qnil
);
28347 s
= make_number (0);
28349 e
= make_number (SCHARS (object
) - 1);
28350 mouse_face_from_string_pos (w
, hlinfo
, object
,
28351 XINT (s
), XINT (e
));
28352 hlinfo
->mouse_face_past_end
= 0;
28353 hlinfo
->mouse_face_window
= window
;
28354 hlinfo
->mouse_face_face_id
28355 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28356 glyph
->face_id
, 1);
28357 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28358 cursor
= No_Cursor
;
28362 /* The mouse-highlighting, if any, comes from an overlay
28363 or text property in the buffer. */
28364 Lisp_Object buffer
IF_LINT (= Qnil
);
28365 Lisp_Object disp_string
IF_LINT (= Qnil
);
28367 if (STRINGP (object
))
28369 /* If we are on a display string with no mouse-face,
28370 check if the text under it has one. */
28371 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28372 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28373 pos
= string_buffer_position (object
, start
);
28376 mouse_face
= get_char_property_and_overlay
28377 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28378 buffer
= w
->contents
;
28379 disp_string
= object
;
28385 disp_string
= Qnil
;
28388 if (!NILP (mouse_face
))
28390 Lisp_Object before
, after
;
28391 Lisp_Object before_string
, after_string
;
28392 /* To correctly find the limits of mouse highlight
28393 in a bidi-reordered buffer, we must not use the
28394 optimization of limiting the search in
28395 previous-single-property-change and
28396 next-single-property-change, because
28397 rows_from_pos_range needs the real start and end
28398 positions to DTRT in this case. That's because
28399 the first row visible in a window does not
28400 necessarily display the character whose position
28401 is the smallest. */
28403 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28404 ? Fmarker_position (w
->start
)
28407 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28408 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28411 if (NILP (overlay
))
28413 /* Handle the text property case. */
28414 before
= Fprevious_single_property_change
28415 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28416 after
= Fnext_single_property_change
28417 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28418 before_string
= after_string
= Qnil
;
28422 /* Handle the overlay case. */
28423 before
= Foverlay_start (overlay
);
28424 after
= Foverlay_end (overlay
);
28425 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28426 after_string
= Foverlay_get (overlay
, Qafter_string
);
28428 if (!STRINGP (before_string
)) before_string
= Qnil
;
28429 if (!STRINGP (after_string
)) after_string
= Qnil
;
28432 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28435 : XFASTINT (before
),
28437 ? BUF_Z (XBUFFER (buffer
))
28438 : XFASTINT (after
),
28439 before_string
, after_string
,
28441 cursor
= No_Cursor
;
28448 /* Look for a `help-echo' property. */
28449 if (NILP (help_echo_string
)) {
28450 Lisp_Object help
, overlay
;
28452 /* Check overlays first. */
28453 help
= overlay
= Qnil
;
28454 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28456 overlay
= overlay_vec
[i
];
28457 help
= Foverlay_get (overlay
, Qhelp_echo
);
28462 help_echo_string
= help
;
28463 help_echo_window
= window
;
28464 help_echo_object
= overlay
;
28465 help_echo_pos
= pos
;
28469 Lisp_Object obj
= glyph
->object
;
28470 ptrdiff_t charpos
= glyph
->charpos
;
28472 /* Try text properties. */
28475 && charpos
< SCHARS (obj
))
28477 help
= Fget_text_property (make_number (charpos
),
28481 /* If the string itself doesn't specify a help-echo,
28482 see if the buffer text ``under'' it does. */
28483 struct glyph_row
*r
28484 = MATRIX_ROW (w
->current_matrix
, vpos
);
28485 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28486 ptrdiff_t p
= string_buffer_position (obj
, start
);
28489 help
= Fget_char_property (make_number (p
),
28490 Qhelp_echo
, w
->contents
);
28499 else if (BUFFERP (obj
)
28502 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28507 help_echo_string
= help
;
28508 help_echo_window
= window
;
28509 help_echo_object
= obj
;
28510 help_echo_pos
= charpos
;
28515 #ifdef HAVE_WINDOW_SYSTEM
28516 /* Look for a `pointer' property. */
28517 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28519 /* Check overlays first. */
28520 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28521 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28523 if (NILP (pointer
))
28525 Lisp_Object obj
= glyph
->object
;
28526 ptrdiff_t charpos
= glyph
->charpos
;
28528 /* Try text properties. */
28531 && charpos
< SCHARS (obj
))
28533 pointer
= Fget_text_property (make_number (charpos
),
28535 if (NILP (pointer
))
28537 /* If the string itself doesn't specify a pointer,
28538 see if the buffer text ``under'' it does. */
28539 struct glyph_row
*r
28540 = MATRIX_ROW (w
->current_matrix
, vpos
);
28541 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28542 ptrdiff_t p
= string_buffer_position (obj
, start
);
28544 pointer
= Fget_char_property (make_number (p
),
28545 Qpointer
, w
->contents
);
28548 else if (BUFFERP (obj
)
28551 pointer
= Fget_text_property (make_number (charpos
),
28555 #endif /* HAVE_WINDOW_SYSTEM */
28559 current_buffer
= obuf
;
28564 #ifdef HAVE_WINDOW_SYSTEM
28565 if (FRAME_WINDOW_P (f
))
28566 define_frame_cursor1 (f
, cursor
, pointer
);
28568 /* This is here to prevent a compiler error, about "label at end of
28569 compound statement". */
28576 Clear any mouse-face on window W. This function is part of the
28577 redisplay interface, and is called from try_window_id and similar
28578 functions to ensure the mouse-highlight is off. */
28581 x_clear_window_mouse_face (struct window
*w
)
28583 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28584 Lisp_Object window
;
28587 XSETWINDOW (window
, w
);
28588 if (EQ (window
, hlinfo
->mouse_face_window
))
28589 clear_mouse_face (hlinfo
);
28595 Just discard the mouse face information for frame F, if any.
28596 This is used when the size of F is changed. */
28599 cancel_mouse_face (struct frame
*f
)
28601 Lisp_Object window
;
28602 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28604 window
= hlinfo
->mouse_face_window
;
28605 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28606 reset_mouse_highlight (hlinfo
);
28611 /***********************************************************************
28613 ***********************************************************************/
28615 #ifdef HAVE_WINDOW_SYSTEM
28617 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28618 which intersects rectangle R. R is in window-relative coordinates. */
28621 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28622 enum glyph_row_area area
)
28624 struct glyph
*first
= row
->glyphs
[area
];
28625 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28626 struct glyph
*last
;
28627 int first_x
, start_x
, x
;
28629 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28630 /* If row extends face to end of line write the whole line. */
28631 draw_glyphs (w
, 0, row
, area
,
28632 0, row
->used
[area
],
28633 DRAW_NORMAL_TEXT
, 0);
28636 /* Set START_X to the window-relative start position for drawing glyphs of
28637 AREA. The first glyph of the text area can be partially visible.
28638 The first glyphs of other areas cannot. */
28639 start_x
= window_box_left_offset (w
, area
);
28641 if (area
== TEXT_AREA
)
28644 /* Find the first glyph that must be redrawn. */
28646 && x
+ first
->pixel_width
< r
->x
)
28648 x
+= first
->pixel_width
;
28652 /* Find the last one. */
28656 && x
< r
->x
+ r
->width
)
28658 x
+= last
->pixel_width
;
28664 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28665 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28666 DRAW_NORMAL_TEXT
, 0);
28671 /* Redraw the parts of the glyph row ROW on window W intersecting
28672 rectangle R. R is in window-relative coordinates. Value is
28673 non-zero if mouse-face was overwritten. */
28676 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28678 eassert (row
->enabled_p
);
28680 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28681 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28682 0, row
->used
[TEXT_AREA
],
28683 DRAW_NORMAL_TEXT
, 0);
28686 if (row
->used
[LEFT_MARGIN_AREA
])
28687 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28688 if (row
->used
[TEXT_AREA
])
28689 expose_area (w
, row
, r
, TEXT_AREA
);
28690 if (row
->used
[RIGHT_MARGIN_AREA
])
28691 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28692 draw_row_fringe_bitmaps (w
, row
);
28695 return row
->mouse_face_p
;
28699 /* Redraw those parts of glyphs rows during expose event handling that
28700 overlap other rows. Redrawing of an exposed line writes over parts
28701 of lines overlapping that exposed line; this function fixes that.
28703 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28704 row in W's current matrix that is exposed and overlaps other rows.
28705 LAST_OVERLAPPING_ROW is the last such row. */
28708 expose_overlaps (struct window
*w
,
28709 struct glyph_row
*first_overlapping_row
,
28710 struct glyph_row
*last_overlapping_row
,
28713 struct glyph_row
*row
;
28715 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28716 if (row
->overlapping_p
)
28718 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28721 if (row
->used
[LEFT_MARGIN_AREA
])
28722 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28724 if (row
->used
[TEXT_AREA
])
28725 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28727 if (row
->used
[RIGHT_MARGIN_AREA
])
28728 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28734 /* Return non-zero if W's cursor intersects rectangle R. */
28737 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28739 XRectangle cr
, result
;
28740 struct glyph
*cursor_glyph
;
28741 struct glyph_row
*row
;
28743 if (w
->phys_cursor
.vpos
>= 0
28744 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28745 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28747 && row
->cursor_in_fringe_p
)
28749 /* Cursor is in the fringe. */
28750 cr
.x
= window_box_right_offset (w
,
28751 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28752 ? RIGHT_MARGIN_AREA
28755 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28756 cr
.height
= row
->height
;
28757 return x_intersect_rectangles (&cr
, r
, &result
);
28760 cursor_glyph
= get_phys_cursor_glyph (w
);
28763 /* r is relative to W's box, but w->phys_cursor.x is relative
28764 to left edge of W's TEXT area. Adjust it. */
28765 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28766 cr
.y
= w
->phys_cursor
.y
;
28767 cr
.width
= cursor_glyph
->pixel_width
;
28768 cr
.height
= w
->phys_cursor_height
;
28769 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28770 I assume the effect is the same -- and this is portable. */
28771 return x_intersect_rectangles (&cr
, r
, &result
);
28773 /* If we don't understand the format, pretend we're not in the hot-spot. */
28779 Draw a vertical window border to the right of window W if W doesn't
28780 have vertical scroll bars. */
28783 x_draw_vertical_border (struct window
*w
)
28785 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28787 /* We could do better, if we knew what type of scroll-bar the adjacent
28788 windows (on either side) have... But we don't :-(
28789 However, I think this works ok. ++KFS 2003-04-25 */
28791 /* Redraw borders between horizontally adjacent windows. Don't
28792 do it for frames with vertical scroll bars because either the
28793 right scroll bar of a window, or the left scroll bar of its
28794 neighbor will suffice as a border. */
28795 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28798 /* Note: It is necessary to redraw both the left and the right
28799 borders, for when only this single window W is being
28801 if (!WINDOW_RIGHTMOST_P (w
)
28802 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28804 int x0
, x1
, y0
, y1
;
28806 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28809 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28812 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28814 if (!WINDOW_LEFTMOST_P (w
)
28815 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28817 int x0
, x1
, y0
, y1
;
28819 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28822 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28825 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28830 /* Redraw the part of window W intersection rectangle FR. Pixel
28831 coordinates in FR are frame-relative. Call this function with
28832 input blocked. Value is non-zero if the exposure overwrites
28836 expose_window (struct window
*w
, XRectangle
*fr
)
28838 struct frame
*f
= XFRAME (w
->frame
);
28840 int mouse_face_overwritten_p
= 0;
28842 /* If window is not yet fully initialized, do nothing. This can
28843 happen when toolkit scroll bars are used and a window is split.
28844 Reconfiguring the scroll bar will generate an expose for a newly
28846 if (w
->current_matrix
== NULL
)
28849 /* When we're currently updating the window, display and current
28850 matrix usually don't agree. Arrange for a thorough display
28852 if (w
->must_be_updated_p
)
28854 SET_FRAME_GARBAGED (f
);
28858 /* Frame-relative pixel rectangle of W. */
28859 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28860 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28861 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28862 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28864 if (x_intersect_rectangles (fr
, &wr
, &r
))
28866 int yb
= window_text_bottom_y (w
);
28867 struct glyph_row
*row
;
28868 int cursor_cleared_p
, phys_cursor_on_p
;
28869 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28871 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28872 r
.x
, r
.y
, r
.width
, r
.height
));
28874 /* Convert to window coordinates. */
28875 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28876 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28878 /* Turn off the cursor. */
28879 if (!w
->pseudo_window_p
28880 && phys_cursor_in_rect_p (w
, &r
))
28882 x_clear_cursor (w
);
28883 cursor_cleared_p
= 1;
28886 cursor_cleared_p
= 0;
28888 /* If the row containing the cursor extends face to end of line,
28889 then expose_area might overwrite the cursor outside the
28890 rectangle and thus notice_overwritten_cursor might clear
28891 w->phys_cursor_on_p. We remember the original value and
28892 check later if it is changed. */
28893 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28895 /* Update lines intersecting rectangle R. */
28896 first_overlapping_row
= last_overlapping_row
= NULL
;
28897 for (row
= w
->current_matrix
->rows
;
28902 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28904 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28905 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28906 || (r
.y
>= y0
&& r
.y
< y1
)
28907 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28909 /* A header line may be overlapping, but there is no need
28910 to fix overlapping areas for them. KFS 2005-02-12 */
28911 if (row
->overlapping_p
&& !row
->mode_line_p
)
28913 if (first_overlapping_row
== NULL
)
28914 first_overlapping_row
= row
;
28915 last_overlapping_row
= row
;
28919 if (expose_line (w
, row
, &r
))
28920 mouse_face_overwritten_p
= 1;
28923 else if (row
->overlapping_p
)
28925 /* We must redraw a row overlapping the exposed area. */
28927 ? y0
+ row
->phys_height
> r
.y
28928 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28930 if (first_overlapping_row
== NULL
)
28931 first_overlapping_row
= row
;
28932 last_overlapping_row
= row
;
28940 /* Display the mode line if there is one. */
28941 if (WINDOW_WANTS_MODELINE_P (w
)
28942 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28944 && row
->y
< r
.y
+ r
.height
)
28946 if (expose_line (w
, row
, &r
))
28947 mouse_face_overwritten_p
= 1;
28950 if (!w
->pseudo_window_p
)
28952 /* Fix the display of overlapping rows. */
28953 if (first_overlapping_row
)
28954 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28957 /* Draw border between windows. */
28958 x_draw_vertical_border (w
);
28960 /* Turn the cursor on again. */
28961 if (cursor_cleared_p
28962 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28963 update_window_cursor (w
, 1);
28967 return mouse_face_overwritten_p
;
28972 /* Redraw (parts) of all windows in the window tree rooted at W that
28973 intersect R. R contains frame pixel coordinates. Value is
28974 non-zero if the exposure overwrites mouse-face. */
28977 expose_window_tree (struct window
*w
, XRectangle
*r
)
28979 struct frame
*f
= XFRAME (w
->frame
);
28980 int mouse_face_overwritten_p
= 0;
28982 while (w
&& !FRAME_GARBAGED_P (f
))
28984 if (WINDOWP (w
->contents
))
28985 mouse_face_overwritten_p
28986 |= expose_window_tree (XWINDOW (w
->contents
), r
);
28988 mouse_face_overwritten_p
|= expose_window (w
, r
);
28990 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28993 return mouse_face_overwritten_p
;
28998 Redisplay an exposed area of frame F. X and Y are the upper-left
28999 corner of the exposed rectangle. W and H are width and height of
29000 the exposed area. All are pixel values. W or H zero means redraw
29001 the entire frame. */
29004 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29007 int mouse_face_overwritten_p
= 0;
29009 TRACE ((stderr
, "expose_frame "));
29011 /* No need to redraw if frame will be redrawn soon. */
29012 if (FRAME_GARBAGED_P (f
))
29014 TRACE ((stderr
, " garbaged\n"));
29018 /* If basic faces haven't been realized yet, there is no point in
29019 trying to redraw anything. This can happen when we get an expose
29020 event while Emacs is starting, e.g. by moving another window. */
29021 if (FRAME_FACE_CACHE (f
) == NULL
29022 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29024 TRACE ((stderr
, " no faces\n"));
29028 if (w
== 0 || h
== 0)
29031 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29032 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29042 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29043 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29045 if (WINDOWP (f
->tool_bar_window
))
29046 mouse_face_overwritten_p
29047 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29049 #ifdef HAVE_X_WINDOWS
29051 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29052 if (WINDOWP (f
->menu_bar_window
))
29053 mouse_face_overwritten_p
29054 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29055 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29059 /* Some window managers support a focus-follows-mouse style with
29060 delayed raising of frames. Imagine a partially obscured frame,
29061 and moving the mouse into partially obscured mouse-face on that
29062 frame. The visible part of the mouse-face will be highlighted,
29063 then the WM raises the obscured frame. With at least one WM, KDE
29064 2.1, Emacs is not getting any event for the raising of the frame
29065 (even tried with SubstructureRedirectMask), only Expose events.
29066 These expose events will draw text normally, i.e. not
29067 highlighted. Which means we must redo the highlight here.
29068 Subsume it under ``we love X''. --gerd 2001-08-15 */
29069 /* Included in Windows version because Windows most likely does not
29070 do the right thing if any third party tool offers
29071 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29072 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29074 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29075 if (f
== hlinfo
->mouse_face_mouse_frame
)
29077 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29078 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29079 clear_mouse_face (hlinfo
);
29080 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29087 Determine the intersection of two rectangles R1 and R2. Return
29088 the intersection in *RESULT. Value is non-zero if RESULT is not
29092 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29094 XRectangle
*left
, *right
;
29095 XRectangle
*upper
, *lower
;
29096 int intersection_p
= 0;
29098 /* Rearrange so that R1 is the left-most rectangle. */
29100 left
= r1
, right
= r2
;
29102 left
= r2
, right
= r1
;
29104 /* X0 of the intersection is right.x0, if this is inside R1,
29105 otherwise there is no intersection. */
29106 if (right
->x
<= left
->x
+ left
->width
)
29108 result
->x
= right
->x
;
29110 /* The right end of the intersection is the minimum of
29111 the right ends of left and right. */
29112 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29115 /* Same game for Y. */
29117 upper
= r1
, lower
= r2
;
29119 upper
= r2
, lower
= r1
;
29121 /* The upper end of the intersection is lower.y0, if this is inside
29122 of upper. Otherwise, there is no intersection. */
29123 if (lower
->y
<= upper
->y
+ upper
->height
)
29125 result
->y
= lower
->y
;
29127 /* The lower end of the intersection is the minimum of the lower
29128 ends of upper and lower. */
29129 result
->height
= (min (lower
->y
+ lower
->height
,
29130 upper
->y
+ upper
->height
)
29132 intersection_p
= 1;
29136 return intersection_p
;
29139 #endif /* HAVE_WINDOW_SYSTEM */
29142 /***********************************************************************
29144 ***********************************************************************/
29147 syms_of_xdisp (void)
29149 Vwith_echo_area_save_vector
= Qnil
;
29150 staticpro (&Vwith_echo_area_save_vector
);
29152 Vmessage_stack
= Qnil
;
29153 staticpro (&Vmessage_stack
);
29155 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29156 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29158 message_dolog_marker1
= Fmake_marker ();
29159 staticpro (&message_dolog_marker1
);
29160 message_dolog_marker2
= Fmake_marker ();
29161 staticpro (&message_dolog_marker2
);
29162 message_dolog_marker3
= Fmake_marker ();
29163 staticpro (&message_dolog_marker3
);
29166 defsubr (&Sdump_frame_glyph_matrix
);
29167 defsubr (&Sdump_glyph_matrix
);
29168 defsubr (&Sdump_glyph_row
);
29169 defsubr (&Sdump_tool_bar_row
);
29170 defsubr (&Strace_redisplay
);
29171 defsubr (&Strace_to_stderr
);
29173 #ifdef HAVE_WINDOW_SYSTEM
29174 defsubr (&Stool_bar_lines_needed
);
29175 defsubr (&Slookup_image_map
);
29177 defsubr (&Sline_pixel_height
);
29178 defsubr (&Sformat_mode_line
);
29179 defsubr (&Sinvisible_p
);
29180 defsubr (&Scurrent_bidi_paragraph_direction
);
29181 defsubr (&Smove_point_visually
);
29183 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29184 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29185 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29186 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29187 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29188 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29189 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29190 DEFSYM (Qeval
, "eval");
29191 DEFSYM (QCdata
, ":data");
29192 DEFSYM (Qdisplay
, "display");
29193 DEFSYM (Qspace_width
, "space-width");
29194 DEFSYM (Qraise
, "raise");
29195 DEFSYM (Qslice
, "slice");
29196 DEFSYM (Qspace
, "space");
29197 DEFSYM (Qmargin
, "margin");
29198 DEFSYM (Qpointer
, "pointer");
29199 DEFSYM (Qleft_margin
, "left-margin");
29200 DEFSYM (Qright_margin
, "right-margin");
29201 DEFSYM (Qcenter
, "center");
29202 DEFSYM (Qline_height
, "line-height");
29203 DEFSYM (QCalign_to
, ":align-to");
29204 DEFSYM (QCrelative_width
, ":relative-width");
29205 DEFSYM (QCrelative_height
, ":relative-height");
29206 DEFSYM (QCeval
, ":eval");
29207 DEFSYM (QCpropertize
, ":propertize");
29208 DEFSYM (QCfile
, ":file");
29209 DEFSYM (Qfontified
, "fontified");
29210 DEFSYM (Qfontification_functions
, "fontification-functions");
29211 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29212 DEFSYM (Qescape_glyph
, "escape-glyph");
29213 DEFSYM (Qnobreak_space
, "nobreak-space");
29214 DEFSYM (Qimage
, "image");
29215 DEFSYM (Qtext
, "text");
29216 DEFSYM (Qboth
, "both");
29217 DEFSYM (Qboth_horiz
, "both-horiz");
29218 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29219 DEFSYM (QCmap
, ":map");
29220 DEFSYM (QCpointer
, ":pointer");
29221 DEFSYM (Qrect
, "rect");
29222 DEFSYM (Qcircle
, "circle");
29223 DEFSYM (Qpoly
, "poly");
29224 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29225 DEFSYM (Qgrow_only
, "grow-only");
29226 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29227 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29228 DEFSYM (Qposition
, "position");
29229 DEFSYM (Qbuffer_position
, "buffer-position");
29230 DEFSYM (Qobject
, "object");
29231 DEFSYM (Qbar
, "bar");
29232 DEFSYM (Qhbar
, "hbar");
29233 DEFSYM (Qbox
, "box");
29234 DEFSYM (Qhollow
, "hollow");
29235 DEFSYM (Qhand
, "hand");
29236 DEFSYM (Qarrow
, "arrow");
29237 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29239 list_of_error
= list1 (list2 (intern_c_string ("error"),
29240 intern_c_string ("void-variable")));
29241 staticpro (&list_of_error
);
29243 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29244 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29245 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29246 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29248 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29249 staticpro (&echo_buffer
[0]);
29250 staticpro (&echo_buffer
[1]);
29252 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29253 staticpro (&echo_area_buffer
[0]);
29254 staticpro (&echo_area_buffer
[1]);
29256 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29257 staticpro (&Vmessages_buffer_name
);
29259 mode_line_proptrans_alist
= Qnil
;
29260 staticpro (&mode_line_proptrans_alist
);
29261 mode_line_string_list
= Qnil
;
29262 staticpro (&mode_line_string_list
);
29263 mode_line_string_face
= Qnil
;
29264 staticpro (&mode_line_string_face
);
29265 mode_line_string_face_prop
= Qnil
;
29266 staticpro (&mode_line_string_face_prop
);
29267 Vmode_line_unwind_vector
= Qnil
;
29268 staticpro (&Vmode_line_unwind_vector
);
29270 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29272 help_echo_string
= Qnil
;
29273 staticpro (&help_echo_string
);
29274 help_echo_object
= Qnil
;
29275 staticpro (&help_echo_object
);
29276 help_echo_window
= Qnil
;
29277 staticpro (&help_echo_window
);
29278 previous_help_echo_string
= Qnil
;
29279 staticpro (&previous_help_echo_string
);
29280 help_echo_pos
= -1;
29282 DEFSYM (Qright_to_left
, "right-to-left");
29283 DEFSYM (Qleft_to_right
, "left-to-right");
29285 #ifdef HAVE_WINDOW_SYSTEM
29286 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29287 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29288 For example, if a block cursor is over a tab, it will be drawn as
29289 wide as that tab on the display. */);
29290 x_stretch_cursor_p
= 0;
29293 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29294 doc
: /* Non-nil means highlight trailing whitespace.
29295 The face used for trailing whitespace is `trailing-whitespace'. */);
29296 Vshow_trailing_whitespace
= Qnil
;
29298 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29299 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29300 If the value is t, Emacs highlights non-ASCII chars which have the
29301 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29302 or `escape-glyph' face respectively.
29304 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29305 U+2011 (non-breaking hyphen) are affected.
29307 Any other non-nil value means to display these characters as a escape
29308 glyph followed by an ordinary space or hyphen.
29310 A value of nil means no special handling of these characters. */);
29311 Vnobreak_char_display
= Qt
;
29313 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29314 doc
: /* The pointer shape to show in void text areas.
29315 A value of nil means to show the text pointer. Other options are `arrow',
29316 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29317 Vvoid_text_area_pointer
= Qarrow
;
29319 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29320 doc
: /* Non-nil means don't actually do any redisplay.
29321 This is used for internal purposes. */);
29322 Vinhibit_redisplay
= Qnil
;
29324 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29325 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29326 Vglobal_mode_string
= Qnil
;
29328 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29329 doc
: /* Marker for where to display an arrow on top of the buffer text.
29330 This must be the beginning of a line in order to work.
29331 See also `overlay-arrow-string'. */);
29332 Voverlay_arrow_position
= Qnil
;
29334 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29335 doc
: /* String to display as an arrow in non-window frames.
29336 See also `overlay-arrow-position'. */);
29337 Voverlay_arrow_string
= build_pure_c_string ("=>");
29339 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29340 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29341 The symbols on this list are examined during redisplay to determine
29342 where to display overlay arrows. */);
29343 Voverlay_arrow_variable_list
29344 = list1 (intern_c_string ("overlay-arrow-position"));
29346 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29347 doc
: /* The number of lines to try scrolling a window by when point moves out.
29348 If that fails to bring point back on frame, point is centered instead.
29349 If this is zero, point is always centered after it moves off frame.
29350 If you want scrolling to always be a line at a time, you should set
29351 `scroll-conservatively' to a large value rather than set this to 1. */);
29353 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29354 doc
: /* Scroll up to this many lines, to bring point back on screen.
29355 If point moves off-screen, redisplay will scroll by up to
29356 `scroll-conservatively' lines in order to bring point just barely
29357 onto the screen again. If that cannot be done, then redisplay
29358 recenters point as usual.
29360 If the value is greater than 100, redisplay will never recenter point,
29361 but will always scroll just enough text to bring point into view, even
29362 if you move far away.
29364 A value of zero means always recenter point if it moves off screen. */);
29365 scroll_conservatively
= 0;
29367 DEFVAR_INT ("scroll-margin", scroll_margin
,
29368 doc
: /* Number of lines of margin at the top and bottom of a window.
29369 Recenter the window whenever point gets within this many lines
29370 of the top or bottom of the window. */);
29373 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29374 doc
: /* Pixels per inch value for non-window system displays.
29375 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29376 Vdisplay_pixels_per_inch
= make_float (72.0);
29379 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29382 DEFVAR_LISP ("truncate-partial-width-windows",
29383 Vtruncate_partial_width_windows
,
29384 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29385 For an integer value, truncate lines in each window narrower than the
29386 full frame width, provided the window width is less than that integer;
29387 otherwise, respect the value of `truncate-lines'.
29389 For any other non-nil value, truncate lines in all windows that do
29390 not span the full frame width.
29392 A value of nil means to respect the value of `truncate-lines'.
29394 If `word-wrap' is enabled, you might want to reduce this. */);
29395 Vtruncate_partial_width_windows
= make_number (50);
29397 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29398 doc
: /* Maximum buffer size for which line number should be displayed.
29399 If the buffer is bigger than this, the line number does not appear
29400 in the mode line. A value of nil means no limit. */);
29401 Vline_number_display_limit
= Qnil
;
29403 DEFVAR_INT ("line-number-display-limit-width",
29404 line_number_display_limit_width
,
29405 doc
: /* Maximum line width (in characters) for line number display.
29406 If the average length of the lines near point is bigger than this, then the
29407 line number may be omitted from the mode line. */);
29408 line_number_display_limit_width
= 200;
29410 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29411 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29412 highlight_nonselected_windows
= 0;
29414 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29415 doc
: /* Non-nil if more than one frame is visible on this display.
29416 Minibuffer-only frames don't count, but iconified frames do.
29417 This variable is not guaranteed to be accurate except while processing
29418 `frame-title-format' and `icon-title-format'. */);
29420 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29421 doc
: /* Template for displaying the title bar of visible frames.
29422 \(Assuming the window manager supports this feature.)
29424 This variable has the same structure as `mode-line-format', except that
29425 the %c and %l constructs are ignored. It is used only on frames for
29426 which no explicit name has been set \(see `modify-frame-parameters'). */);
29428 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29429 doc
: /* Template for displaying the title bar of an iconified frame.
29430 \(Assuming the window manager supports this feature.)
29431 This variable has the same structure as `mode-line-format' (which see),
29432 and is used only on frames for which no explicit name has been set
29433 \(see `modify-frame-parameters'). */);
29435 = Vframe_title_format
29436 = listn (CONSTYPE_PURE
, 3,
29437 intern_c_string ("multiple-frames"),
29438 build_pure_c_string ("%b"),
29439 listn (CONSTYPE_PURE
, 4,
29440 empty_unibyte_string
,
29441 intern_c_string ("invocation-name"),
29442 build_pure_c_string ("@"),
29443 intern_c_string ("system-name")));
29445 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29446 doc
: /* Maximum number of lines to keep in the message log buffer.
29447 If nil, disable message logging. If t, log messages but don't truncate
29448 the buffer when it becomes large. */);
29449 Vmessage_log_max
= make_number (1000);
29451 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29452 doc
: /* Functions called before redisplay, if window sizes have changed.
29453 The value should be a list of functions that take one argument.
29454 Just before redisplay, for each frame, if any of its windows have changed
29455 size since the last redisplay, or have been split or deleted,
29456 all the functions in the list are called, with the frame as argument. */);
29457 Vwindow_size_change_functions
= Qnil
;
29459 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29460 doc
: /* List of functions to call before redisplaying a window with scrolling.
29461 Each function is called with two arguments, the window and its new
29462 display-start position. Note that these functions are also called by
29463 `set-window-buffer'. Also note that the value of `window-end' is not
29464 valid when these functions are called.
29466 Warning: Do not use this feature to alter the way the window
29467 is scrolled. It is not designed for that, and such use probably won't
29469 Vwindow_scroll_functions
= Qnil
;
29471 DEFVAR_LISP ("window-text-change-functions",
29472 Vwindow_text_change_functions
,
29473 doc
: /* Functions to call in redisplay when text in the window might change. */);
29474 Vwindow_text_change_functions
= Qnil
;
29476 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29477 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29478 Each function is called with two arguments, the window and the end trigger value.
29479 See `set-window-redisplay-end-trigger'. */);
29480 Vredisplay_end_trigger_functions
= Qnil
;
29482 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29483 doc
: /* Non-nil means autoselect window with mouse pointer.
29484 If nil, do not autoselect windows.
29485 A positive number means delay autoselection by that many seconds: a
29486 window is autoselected only after the mouse has remained in that
29487 window for the duration of the delay.
29488 A negative number has a similar effect, but causes windows to be
29489 autoselected only after the mouse has stopped moving. \(Because of
29490 the way Emacs compares mouse events, you will occasionally wait twice
29491 that time before the window gets selected.\)
29492 Any other value means to autoselect window instantaneously when the
29493 mouse pointer enters it.
29495 Autoselection selects the minibuffer only if it is active, and never
29496 unselects the minibuffer if it is active.
29498 When customizing this variable make sure that the actual value of
29499 `focus-follows-mouse' matches the behavior of your window manager. */);
29500 Vmouse_autoselect_window
= Qnil
;
29502 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29503 doc
: /* Non-nil means automatically resize tool-bars.
29504 This dynamically changes the tool-bar's height to the minimum height
29505 that is needed to make all tool-bar items visible.
29506 If value is `grow-only', the tool-bar's height is only increased
29507 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29508 Vauto_resize_tool_bars
= Qt
;
29510 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29511 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29512 auto_raise_tool_bar_buttons_p
= 1;
29514 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29515 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29516 make_cursor_line_fully_visible_p
= 1;
29518 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29519 doc
: /* Border below tool-bar in pixels.
29520 If an integer, use it as the height of the border.
29521 If it is one of `internal-border-width' or `border-width', use the
29522 value of the corresponding frame parameter.
29523 Otherwise, no border is added below the tool-bar. */);
29524 Vtool_bar_border
= Qinternal_border_width
;
29526 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29527 doc
: /* Margin around tool-bar buttons in pixels.
29528 If an integer, use that for both horizontal and vertical margins.
29529 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29530 HORZ specifying the horizontal margin, and VERT specifying the
29531 vertical margin. */);
29532 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29534 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29535 doc
: /* Relief thickness of tool-bar buttons. */);
29536 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29538 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29539 doc
: /* Tool bar style to use.
29541 image - show images only
29542 text - show text only
29543 both - show both, text below image
29544 both-horiz - show text to the right of the image
29545 text-image-horiz - show text to the left of the image
29546 any other - use system default or image if no system default.
29548 This variable only affects the GTK+ toolkit version of Emacs. */);
29549 Vtool_bar_style
= Qnil
;
29551 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29552 doc
: /* Maximum number of characters a label can have to be shown.
29553 The tool bar style must also show labels for this to have any effect, see
29554 `tool-bar-style'. */);
29555 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29557 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29558 doc
: /* List of functions to call to fontify regions of text.
29559 Each function is called with one argument POS. Functions must
29560 fontify a region starting at POS in the current buffer, and give
29561 fontified regions the property `fontified'. */);
29562 Vfontification_functions
= Qnil
;
29563 Fmake_variable_buffer_local (Qfontification_functions
);
29565 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29566 unibyte_display_via_language_environment
,
29567 doc
: /* Non-nil means display unibyte text according to language environment.
29568 Specifically, this means that raw bytes in the range 160-255 decimal
29569 are displayed by converting them to the equivalent multibyte characters
29570 according to the current language environment. As a result, they are
29571 displayed according to the current fontset.
29573 Note that this variable affects only how these bytes are displayed,
29574 but does not change the fact they are interpreted as raw bytes. */);
29575 unibyte_display_via_language_environment
= 0;
29577 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29578 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29579 If a float, it specifies a fraction of the mini-window frame's height.
29580 If an integer, it specifies a number of lines. */);
29581 Vmax_mini_window_height
= make_float (0.25);
29583 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29584 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29585 A value of nil means don't automatically resize mini-windows.
29586 A value of t means resize them to fit the text displayed in them.
29587 A value of `grow-only', the default, means let mini-windows grow only;
29588 they return to their normal size when the minibuffer is closed, or the
29589 echo area becomes empty. */);
29590 Vresize_mini_windows
= Qgrow_only
;
29592 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29593 doc
: /* Alist specifying how to blink the cursor off.
29594 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29595 `cursor-type' frame-parameter or variable equals ON-STATE,
29596 comparing using `equal', Emacs uses OFF-STATE to specify
29597 how to blink it off. ON-STATE and OFF-STATE are values for
29598 the `cursor-type' frame parameter.
29600 If a frame's ON-STATE has no entry in this list,
29601 the frame's other specifications determine how to blink the cursor off. */);
29602 Vblink_cursor_alist
= Qnil
;
29604 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29605 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29606 If non-nil, windows are automatically scrolled horizontally to make
29607 point visible. */);
29608 automatic_hscrolling_p
= 1;
29609 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29611 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29612 doc
: /* How many columns away from the window edge point is allowed to get
29613 before automatic hscrolling will horizontally scroll the window. */);
29614 hscroll_margin
= 5;
29616 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29617 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29618 When point is less than `hscroll-margin' columns from the window
29619 edge, automatic hscrolling will scroll the window by the amount of columns
29620 determined by this variable. If its value is a positive integer, scroll that
29621 many columns. If it's a positive floating-point number, it specifies the
29622 fraction of the window's width to scroll. If it's nil or zero, point will be
29623 centered horizontally after the scroll. Any other value, including negative
29624 numbers, are treated as if the value were zero.
29626 Automatic hscrolling always moves point outside the scroll margin, so if
29627 point was more than scroll step columns inside the margin, the window will
29628 scroll more than the value given by the scroll step.
29630 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29631 and `scroll-right' overrides this variable's effect. */);
29632 Vhscroll_step
= make_number (0);
29634 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29635 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29636 Bind this around calls to `message' to let it take effect. */);
29637 message_truncate_lines
= 0;
29639 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29640 doc
: /* Normal hook run to update the menu bar definitions.
29641 Redisplay runs this hook before it redisplays the menu bar.
29642 This is used to update submenus such as Buffers,
29643 whose contents depend on various data. */);
29644 Vmenu_bar_update_hook
= Qnil
;
29646 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29647 doc
: /* Frame for which we are updating a menu.
29648 The enable predicate for a menu binding should check this variable. */);
29649 Vmenu_updating_frame
= Qnil
;
29651 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29652 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29653 inhibit_menubar_update
= 0;
29655 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29656 doc
: /* Prefix prepended to all continuation lines at display time.
29657 The value may be a string, an image, or a stretch-glyph; it is
29658 interpreted in the same way as the value of a `display' text property.
29660 This variable is overridden by any `wrap-prefix' text or overlay
29663 To add a prefix to non-continuation lines, use `line-prefix'. */);
29664 Vwrap_prefix
= Qnil
;
29665 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29666 Fmake_variable_buffer_local (Qwrap_prefix
);
29668 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29669 doc
: /* Prefix prepended to all non-continuation lines at display time.
29670 The value may be a string, an image, or a stretch-glyph; it is
29671 interpreted in the same way as the value of a `display' text property.
29673 This variable is overridden by any `line-prefix' text or overlay
29676 To add a prefix to continuation lines, use `wrap-prefix'. */);
29677 Vline_prefix
= Qnil
;
29678 DEFSYM (Qline_prefix
, "line-prefix");
29679 Fmake_variable_buffer_local (Qline_prefix
);
29681 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29682 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29683 inhibit_eval_during_redisplay
= 0;
29685 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29686 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29687 inhibit_free_realized_faces
= 0;
29690 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29691 doc
: /* Inhibit try_window_id display optimization. */);
29692 inhibit_try_window_id
= 0;
29694 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29695 doc
: /* Inhibit try_window_reusing display optimization. */);
29696 inhibit_try_window_reusing
= 0;
29698 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29699 doc
: /* Inhibit try_cursor_movement display optimization. */);
29700 inhibit_try_cursor_movement
= 0;
29701 #endif /* GLYPH_DEBUG */
29703 DEFVAR_INT ("overline-margin", overline_margin
,
29704 doc
: /* Space between overline and text, in pixels.
29705 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29706 margin to the character height. */);
29707 overline_margin
= 2;
29709 DEFVAR_INT ("underline-minimum-offset",
29710 underline_minimum_offset
,
29711 doc
: /* Minimum distance between baseline and underline.
29712 This can improve legibility of underlined text at small font sizes,
29713 particularly when using variable `x-use-underline-position-properties'
29714 with fonts that specify an UNDERLINE_POSITION relatively close to the
29715 baseline. The default value is 1. */);
29716 underline_minimum_offset
= 1;
29718 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29719 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29720 This feature only works when on a window system that can change
29721 cursor shapes. */);
29722 display_hourglass_p
= 1;
29724 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29725 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29726 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29728 #ifdef HAVE_WINDOW_SYSTEM
29729 hourglass_atimer
= NULL
;
29730 hourglass_shown_p
= 0;
29731 #endif /* HAVE_WINDOW_SYSTEM */
29733 DEFSYM (Qglyphless_char
, "glyphless-char");
29734 DEFSYM (Qhex_code
, "hex-code");
29735 DEFSYM (Qempty_box
, "empty-box");
29736 DEFSYM (Qthin_space
, "thin-space");
29737 DEFSYM (Qzero_width
, "zero-width");
29739 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
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 #ifdef HAVE_WINDOW_SYSTEM
29820 /* Platform-independent portion of hourglass implementation. */
29822 /* Cancel a currently active hourglass timer, and start a new one. */
29824 start_hourglass (void)
29826 struct timespec delay
;
29828 cancel_hourglass ();
29830 if (INTEGERP (Vhourglass_delay
)
29831 && XINT (Vhourglass_delay
) > 0)
29832 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29833 TYPE_MAXIMUM (time_t)),
29835 else if (FLOATP (Vhourglass_delay
)
29836 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29837 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29839 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29843 extern void w32_note_current_window (void);
29844 w32_note_current_window ();
29846 #endif /* HAVE_NTGUI */
29848 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29849 show_hourglass
, NULL
);
29853 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29856 cancel_hourglass (void)
29858 if (hourglass_atimer
)
29860 cancel_atimer (hourglass_atimer
);
29861 hourglass_atimer
= NULL
;
29864 if (hourglass_shown_p
)
29868 #endif /* HAVE_WINDOW_SYSTEM */