1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest.
105 This function performs the full redisplay of a single window
106 assuming that its fonts were not changed and that the cursor
107 will not end up in the scroll margins. (Loading fonts requires
108 re-adjustment of dimensions of glyph matrices, which makes this
109 method impossible to use.)
111 These optimizations are tried in sequence (some can be skipped if
112 it is known that they are not applicable). If none of the
113 optimizations were successful, redisplay calls redisplay_windows,
114 which performs a full redisplay of all windows.
118 Desired matrices are always built per Emacs window. The function
119 `display_line' is the central function to look at if you are
120 interested. It constructs one row in a desired matrix given an
121 iterator structure containing both a buffer position and a
122 description of the environment in which the text is to be
123 displayed. But this is too early, read on.
125 Characters and pixmaps displayed for a range of buffer text depend
126 on various settings of buffers and windows, on overlays and text
127 properties, on display tables, on selective display. The good news
128 is that all this hairy stuff is hidden behind a small set of
129 interface functions taking an iterator structure (struct it)
132 Iteration over things to be displayed is then simple. It is
133 started by initializing an iterator with a call to init_iterator,
134 passing it the buffer position where to start iteration. For
135 iteration over strings, pass -1 as the position to init_iterator,
136 and call reseat_to_string when the string is ready, to initialize
137 the iterator for that string. Thereafter, calls to
138 get_next_display_element fill the iterator structure with relevant
139 information about the next thing to display. Calls to
140 set_iterator_to_next move the iterator to the next thing.
142 Besides this, an iterator also contains information about the
143 display environment in which glyphs for display elements are to be
144 produced. It has fields for the width and height of the display,
145 the information whether long lines are truncated or continued, a
146 current X and Y position, and lots of other stuff you can better
149 Glyphs in a desired matrix are normally constructed in a loop
150 calling get_next_display_element and then PRODUCE_GLYPHS. The call
151 to PRODUCE_GLYPHS will fill the iterator structure with pixel
152 information about the element being displayed and at the same time
153 produce glyphs for it. If the display element fits on the line
154 being displayed, set_iterator_to_next is called next, otherwise the
155 glyphs produced are discarded. The function display_line is the
156 workhorse of filling glyph rows in the desired matrix with glyphs.
157 In addition to producing glyphs, it also handles line truncation
158 and continuation, word wrap, and cursor positioning (for the
159 latter, see also set_cursor_from_row).
163 That just couldn't be all, could it? What about terminal types not
164 supporting operations on sub-windows of the screen? To update the
165 display on such a terminal, window-based glyph matrices are not
166 well suited. To be able to reuse part of the display (scrolling
167 lines up and down), we must instead have a view of the whole
168 screen. This is what `frame matrices' are for. They are a trick.
170 Frames on terminals like above have a glyph pool. Windows on such
171 a frame sub-allocate their glyph memory from their frame's glyph
172 pool. The frame itself is given its own glyph matrices. By
173 coincidence---or maybe something else---rows in window glyph
174 matrices are slices of corresponding rows in frame matrices. Thus
175 writing to window matrices implicitly updates a frame matrix which
176 provides us with the view of the whole screen that we originally
177 wanted to have without having to move many bytes around. To be
178 honest, there is a little bit more done, but not much more. If you
179 plan to extend that code, take a look at dispnew.c. The function
180 build_frame_matrix is a good starting point.
182 Bidirectional display.
184 Bidirectional display adds quite some hair to this already complex
185 design. The good news are that a large portion of that hairy stuff
186 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
187 reordering engine which is called by set_iterator_to_next and
188 returns the next character to display in the visual order. See
189 commentary on bidi.c for more details. As far as redisplay is
190 concerned, the effect of calling bidi_move_to_visually_next, the
191 main interface of the reordering engine, is that the iterator gets
192 magically placed on the buffer or string position that is to be
193 displayed next. In other words, a linear iteration through the
194 buffer/string is replaced with a non-linear one. All the rest of
195 the redisplay is oblivious to the bidi reordering.
197 Well, almost oblivious---there are still complications, most of
198 them due to the fact that buffer and string positions no longer
199 change monotonously with glyph indices in a glyph row. Moreover,
200 for continued lines, the buffer positions may not even be
201 monotonously changing with vertical positions. Also, accounting
202 for face changes, overlays, etc. becomes more complex because
203 non-linear iteration could potentially skip many positions with
204 changes, and then cross them again on the way back...
206 One other prominent effect of bidirectional display is that some
207 paragraphs of text need to be displayed starting at the right
208 margin of the window---the so-called right-to-left, or R2L
209 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
210 which have their reversed_p flag set. The bidi reordering engine
211 produces characters in such rows starting from the character which
212 should be the rightmost on display. PRODUCE_GLYPHS then reverses
213 the order, when it fills up the glyph row whose reversed_p flag is
214 set, by prepending each new glyph to what is already there, instead
215 of appending it. When the glyph row is complete, the function
216 extend_face_to_end_of_line fills the empty space to the left of the
217 leftmost character with special glyphs, which will display as,
218 well, empty. On text terminals, these special glyphs are simply
219 blank characters. On graphics terminals, there's a single stretch
220 glyph of a suitably computed width. Both the blanks and the
221 stretch glyph are given the face of the background of the line.
222 This way, the terminal-specific back-end can still draw the glyphs
223 left to right, even for R2L lines.
225 Bidirectional display and character compositions
227 Some scripts cannot be displayed by drawing each character
228 individually, because adjacent characters change each other's shape
229 on display. For example, Arabic and Indic scripts belong to this
232 Emacs display supports this by providing "character compositions",
233 most of which is implemented in composite.c. During the buffer
234 scan that delivers characters to PRODUCE_GLYPHS, if the next
235 character to be delivered is a composed character, the iteration
236 calls composition_reseat_it and next_element_from_composition. If
237 they succeed to compose the character with one or more of the
238 following characters, the whole sequence of characters that where
239 composed is recorded in the `struct composition_it' object that is
240 part of the buffer iterator. The composed sequence could produce
241 one or more font glyphs (called "grapheme clusters") on the screen.
242 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
243 in the direction corresponding to the current bidi scan direction
244 (recorded in the scan_dir member of the `struct bidi_it' object
245 that is part of the buffer iterator). In particular, if the bidi
246 iterator currently scans the buffer backwards, the grapheme
247 clusters are delivered back to front. This reorders the grapheme
248 clusters as appropriate for the current bidi context. Note that
249 this means that the grapheme clusters are always stored in the
250 LGSTRING object (see composite.c) in the logical order.
252 Moving an iterator in bidirectional text
253 without producing glyphs
255 Note one important detail mentioned above: that the bidi reordering
256 engine, driven by the iterator, produces characters in R2L rows
257 starting at the character that will be the rightmost on display.
258 As far as the iterator is concerned, the geometry of such rows is
259 still left to right, i.e. the iterator "thinks" the first character
260 is at the leftmost pixel position. The iterator does not know that
261 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
262 delivers. This is important when functions from the move_it_*
263 family are used to get to certain screen position or to match
264 screen coordinates with buffer coordinates: these functions use the
265 iterator geometry, which is left to right even in R2L paragraphs.
266 This works well with most callers of move_it_*, because they need
267 to get to a specific column, and columns are still numbered in the
268 reading order, i.e. the rightmost character in a R2L paragraph is
269 still column zero. But some callers do not get well with this; a
270 notable example is mouse clicks that need to find the character
271 that corresponds to certain pixel coordinates. See
272 buffer_posn_from_coords in dispnew.c for how this is handled. */
280 #include "keyboard.h"
283 #include "termchar.h"
284 #include "dispextern.h"
285 #include "character.h"
289 #include "commands.h"
293 #include "termhooks.h"
294 #include "termopts.h"
295 #include "intervals.h"
298 #include "region-cache.h"
301 #include "blockinput.h"
303 #ifdef HAVE_X_WINDOWS
318 #ifndef FRAME_X_OUTPUT
319 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
322 #define INFINITY 10000000
324 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
325 Lisp_Object Qwindow_scroll_functions
;
326 static Lisp_Object Qwindow_text_change_functions
;
327 static Lisp_Object Qredisplay_end_trigger_functions
;
328 Lisp_Object Qinhibit_point_motion_hooks
;
329 static Lisp_Object QCeval
, QCpropertize
;
330 Lisp_Object QCfile
, QCdata
;
331 static Lisp_Object Qfontified
;
332 static Lisp_Object Qgrow_only
;
333 static Lisp_Object Qinhibit_eval_during_redisplay
;
334 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
335 static Lisp_Object Qright_to_left
, Qleft_to_right
;
338 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 /* Pointer shapes. */
341 static Lisp_Object Qarrow
, Qhand
;
344 /* Holds the list (error). */
345 static Lisp_Object list_of_error
;
347 static Lisp_Object Qfontification_functions
;
349 static Lisp_Object Qwrap_prefix
;
350 static Lisp_Object Qline_prefix
;
351 static Lisp_Object Qredisplay_internal
;
353 /* Non-nil means don't actually do any redisplay. */
355 Lisp_Object Qinhibit_redisplay
;
357 /* Names of text properties relevant for redisplay. */
359 Lisp_Object Qdisplay
;
361 Lisp_Object Qspace
, QCalign_to
;
362 static Lisp_Object QCrelative_width
, QCrelative_height
;
363 Lisp_Object Qleft_margin
, Qright_margin
;
364 static Lisp_Object Qspace_width
, Qraise
;
365 static Lisp_Object Qslice
;
367 static Lisp_Object Qmargin
, Qpointer
;
368 static Lisp_Object Qline_height
;
370 #ifdef HAVE_WINDOW_SYSTEM
372 /* Test if overflow newline into fringe. Called with iterator IT
373 at or past right window margin, and with IT->current_x set. */
375 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
376 (!NILP (Voverflow_newline_into_fringe) \
377 && FRAME_WINDOW_P ((IT)->f) \
378 && ((IT)->bidi_it.paragraph_dir == R2L \
379 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
380 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
381 && (IT)->current_x == (IT)->last_visible_x \
382 && (IT)->line_wrap != WORD_WRAP)
384 #else /* !HAVE_WINDOW_SYSTEM */
385 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
386 #endif /* HAVE_WINDOW_SYSTEM */
388 /* Test if the display element loaded in IT, or the underlying buffer
389 or string character, is a space or a TAB character. This is used
390 to determine where word wrapping can occur. */
392 #define IT_DISPLAYING_WHITESPACE(it) \
393 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
394 || ((STRINGP (it->string) \
395 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
396 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
398 && (it->s[IT_BYTEPOS (*it)] == ' ' \
399 || it->s[IT_BYTEPOS (*it)] == '\t')) \
400 || (IT_BYTEPOS (*it) < ZV_BYTE \
401 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
402 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
404 /* Name of the face used to highlight trailing whitespace. */
406 static Lisp_Object Qtrailing_whitespace
;
408 /* Name and number of the face used to highlight escape glyphs. */
410 static Lisp_Object Qescape_glyph
;
412 /* Name and number of the face used to highlight non-breaking spaces. */
414 static Lisp_Object Qnobreak_space
;
416 /* The symbol `image' which is the car of the lists used to represent
417 images in Lisp. Also a tool bar style. */
421 /* The image map types. */
423 static Lisp_Object QCpointer
;
424 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
426 /* Tool bar styles */
427 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
429 /* Non-zero means print newline to stdout before next mini-buffer
432 int noninteractive_need_newline
;
434 /* Non-zero means print newline to message log before next message. */
436 static int message_log_need_newline
;
438 /* Three markers that message_dolog uses.
439 It could allocate them itself, but that causes trouble
440 in handling memory-full errors. */
441 static Lisp_Object message_dolog_marker1
;
442 static Lisp_Object message_dolog_marker2
;
443 static Lisp_Object message_dolog_marker3
;
445 /* The buffer position of the first character appearing entirely or
446 partially on the line of the selected window which contains the
447 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
448 redisplay optimization in redisplay_internal. */
450 static struct text_pos this_line_start_pos
;
452 /* Number of characters past the end of the line above, including the
453 terminating newline. */
455 static struct text_pos this_line_end_pos
;
457 /* The vertical positions and the height of this line. */
459 static int this_line_vpos
;
460 static int this_line_y
;
461 static int this_line_pixel_height
;
463 /* X position at which this display line starts. Usually zero;
464 negative if first character is partially visible. */
466 static int this_line_start_x
;
468 /* The smallest character position seen by move_it_* functions as they
469 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
470 hscrolled lines, see display_line. */
472 static struct text_pos this_line_min_pos
;
474 /* Buffer that this_line_.* variables are referring to. */
476 static struct buffer
*this_line_buffer
;
479 /* Values of those variables at last redisplay are stored as
480 properties on `overlay-arrow-position' symbol. However, if
481 Voverlay_arrow_position is a marker, last-arrow-position is its
482 numerical position. */
484 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
486 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
487 properties on a symbol in overlay-arrow-variable-list. */
489 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
491 Lisp_Object Qmenu_bar_update_hook
;
493 /* Nonzero if an overlay arrow has been displayed in this window. */
495 static int overlay_arrow_seen
;
497 /* Vector containing glyphs for an ellipsis `...'. */
499 static Lisp_Object default_invis_vector
[3];
501 /* This is the window where the echo area message was displayed. It
502 is always a mini-buffer window, but it may not be the same window
503 currently active as a mini-buffer. */
505 Lisp_Object echo_area_window
;
507 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
508 pushes the current message and the value of
509 message_enable_multibyte on the stack, the function restore_message
510 pops the stack and displays MESSAGE again. */
512 static Lisp_Object Vmessage_stack
;
514 /* Nonzero means multibyte characters were enabled when the echo area
515 message was specified. */
517 static int message_enable_multibyte
;
519 /* Nonzero if we should redraw the mode lines on the next redisplay. */
521 int update_mode_lines
;
523 /* Nonzero if window sizes or contents have changed since last
524 redisplay that finished. */
526 int windows_or_buffers_changed
;
528 /* Nonzero means a frame's cursor type has been changed. */
530 int cursor_type_changed
;
532 /* Nonzero after display_mode_line if %l was used and it displayed a
535 static int line_number_displayed
;
537 /* The name of the *Messages* buffer, a string. */
539 static Lisp_Object Vmessages_buffer_name
;
541 /* Current, index 0, and last displayed echo area message. Either
542 buffers from echo_buffers, or nil to indicate no message. */
544 Lisp_Object echo_area_buffer
[2];
546 /* The buffers referenced from echo_area_buffer. */
548 static Lisp_Object echo_buffer
[2];
550 /* A vector saved used in with_area_buffer to reduce consing. */
552 static Lisp_Object Vwith_echo_area_save_vector
;
554 /* Non-zero means display_echo_area should display the last echo area
555 message again. Set by redisplay_preserve_echo_area. */
557 static int display_last_displayed_message_p
;
559 /* Nonzero if echo area is being used by print; zero if being used by
562 static int message_buf_print
;
564 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
566 static Lisp_Object Qinhibit_menubar_update
;
567 static Lisp_Object Qmessage_truncate_lines
;
569 /* Set to 1 in clear_message to make redisplay_internal aware
570 of an emptied echo area. */
572 static int message_cleared_p
;
574 /* A scratch glyph row with contents used for generating truncation
575 glyphs. Also used in direct_output_for_insert. */
577 #define MAX_SCRATCH_GLYPHS 100
578 static struct glyph_row scratch_glyph_row
;
579 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
581 /* Ascent and height of the last line processed by move_it_to. */
583 static int last_height
;
585 /* Non-zero if there's a help-echo in the echo area. */
587 int help_echo_showing_p
;
589 /* If >= 0, computed, exact values of mode-line and header-line height
590 to use in the macros CURRENT_MODE_LINE_HEIGHT and
591 CURRENT_HEADER_LINE_HEIGHT. */
593 int current_mode_line_height
, current_header_line_height
;
595 /* The maximum distance to look ahead for text properties. Values
596 that are too small let us call compute_char_face and similar
597 functions too often which is expensive. Values that are too large
598 let us call compute_char_face and alike too often because we
599 might not be interested in text properties that far away. */
601 #define TEXT_PROP_DISTANCE_LIMIT 100
603 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
604 iterator state and later restore it. This is needed because the
605 bidi iterator on bidi.c keeps a stacked cache of its states, which
606 is really a singleton. When we use scratch iterator objects to
607 move around the buffer, we can cause the bidi cache to be pushed or
608 popped, and therefore we need to restore the cache state when we
609 return to the original iterator. */
610 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
613 bidi_unshelve_cache (CACHE, 1); \
615 CACHE = bidi_shelve_cache (); \
618 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
620 if (pITORIG != pITCOPY) \
621 *(pITORIG) = *(pITCOPY); \
622 bidi_unshelve_cache (CACHE, 0); \
628 /* Non-zero means print traces of redisplay if compiled with
629 GLYPH_DEBUG defined. */
631 int trace_redisplay_p
;
633 #endif /* GLYPH_DEBUG */
635 #ifdef DEBUG_TRACE_MOVE
636 /* Non-zero means trace with TRACE_MOVE to stderr. */
639 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
641 #define TRACE_MOVE(x) (void) 0
644 static Lisp_Object Qauto_hscroll_mode
;
646 /* Buffer being redisplayed -- for redisplay_window_error. */
648 static struct buffer
*displayed_buffer
;
650 /* Value returned from text property handlers (see below). */
655 HANDLED_RECOMPUTE_PROPS
,
656 HANDLED_OVERLAY_STRING_CONSUMED
,
660 /* A description of text properties that redisplay is interested
665 /* The name of the property. */
668 /* A unique index for the property. */
671 /* A handler function called to set up iterator IT from the property
672 at IT's current position. Value is used to steer handle_stop. */
673 enum prop_handled (*handler
) (struct it
*it
);
676 static enum prop_handled
handle_face_prop (struct it
*);
677 static enum prop_handled
handle_invisible_prop (struct it
*);
678 static enum prop_handled
handle_display_prop (struct it
*);
679 static enum prop_handled
handle_composition_prop (struct it
*);
680 static enum prop_handled
handle_overlay_change (struct it
*);
681 static enum prop_handled
handle_fontified_prop (struct it
*);
683 /* Properties handled by iterators. */
685 static struct props it_props
[] =
687 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
688 /* Handle `face' before `display' because some sub-properties of
689 `display' need to know the face. */
690 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
691 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
692 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
693 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
697 /* Value is the position described by X. If X is a marker, value is
698 the marker_position of X. Otherwise, value is X. */
700 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
702 /* Enumeration returned by some move_it_.* functions internally. */
706 /* Not used. Undefined value. */
709 /* Move ended at the requested buffer position or ZV. */
710 MOVE_POS_MATCH_OR_ZV
,
712 /* Move ended at the requested X pixel position. */
715 /* Move within a line ended at the end of a line that must be
719 /* Move within a line ended at the end of a line that would
720 be displayed truncated. */
723 /* Move within a line ended at a line end. */
727 /* This counter is used to clear the face cache every once in a while
728 in redisplay_internal. It is incremented for each redisplay.
729 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
732 #define CLEAR_FACE_CACHE_COUNT 500
733 static int clear_face_cache_count
;
735 /* Similarly for the image cache. */
737 #ifdef HAVE_WINDOW_SYSTEM
738 #define CLEAR_IMAGE_CACHE_COUNT 101
739 static int clear_image_cache_count
;
741 /* Null glyph slice */
742 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
745 /* True while redisplay_internal is in progress. */
749 static Lisp_Object Qinhibit_free_realized_faces
;
750 static Lisp_Object Qmode_line_default_help_echo
;
752 /* If a string, XTread_socket generates an event to display that string.
753 (The display is done in read_char.) */
755 Lisp_Object help_echo_string
;
756 Lisp_Object help_echo_window
;
757 Lisp_Object help_echo_object
;
758 ptrdiff_t help_echo_pos
;
760 /* Temporary variable for XTread_socket. */
762 Lisp_Object previous_help_echo_string
;
764 /* Platform-independent portion of hourglass implementation. */
766 /* Non-zero means an hourglass cursor is currently shown. */
767 int hourglass_shown_p
;
769 /* If non-null, an asynchronous timer that, when it expires, displays
770 an hourglass cursor on all frames. */
771 struct atimer
*hourglass_atimer
;
773 /* Name of the face used to display glyphless characters. */
774 Lisp_Object Qglyphless_char
;
776 /* Symbol for the purpose of Vglyphless_char_display. */
777 static Lisp_Object Qglyphless_char_display
;
779 /* Method symbols for Vglyphless_char_display. */
780 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
782 /* Default pixel width of `thin-space' display method. */
783 #define THIN_SPACE_WIDTH 1
785 /* Default number of seconds to wait before displaying an hourglass
787 #define DEFAULT_HOURGLASS_DELAY 1
790 /* Function prototypes. */
792 static void setup_for_ellipsis (struct it
*, int);
793 static void set_iterator_to_next (struct it
*, int);
794 static void mark_window_display_accurate_1 (struct window
*, int);
795 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
796 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
797 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
798 static int cursor_row_p (struct glyph_row
*);
799 static int redisplay_mode_lines (Lisp_Object
, int);
800 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
802 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
804 static void handle_line_prefix (struct it
*);
806 static void pint2str (char *, int, ptrdiff_t);
807 static void pint2hrstr (char *, int, ptrdiff_t);
808 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
810 static void reconsider_clip_changes (struct window
*, struct buffer
*);
811 static int text_outside_line_unchanged_p (struct window
*,
812 ptrdiff_t, ptrdiff_t);
813 static void store_mode_line_noprop_char (char);
814 static int store_mode_line_noprop (const char *, int, int);
815 static void handle_stop (struct it
*);
816 static void handle_stop_backwards (struct it
*, ptrdiff_t);
817 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
818 static void ensure_echo_area_buffers (void);
819 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
820 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
821 static int with_echo_area_buffer (struct window
*, int,
822 int (*) (ptrdiff_t, Lisp_Object
),
823 ptrdiff_t, Lisp_Object
);
824 static void clear_garbaged_frames (void);
825 static int current_message_1 (ptrdiff_t, Lisp_Object
);
826 static void pop_message (void);
827 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
828 static void set_message (Lisp_Object
);
829 static int set_message_1 (ptrdiff_t, Lisp_Object
);
830 static int display_echo_area (struct window
*);
831 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
832 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
833 static Lisp_Object
unwind_redisplay (Lisp_Object
);
834 static int string_char_and_length (const unsigned char *, int *);
835 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
837 static int compute_window_start_on_continuation_line (struct window
*);
838 static void insert_left_trunc_glyphs (struct it
*);
839 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
841 static void extend_face_to_end_of_line (struct it
*);
842 static int append_space_for_newline (struct it
*, int);
843 static int cursor_row_fully_visible_p (struct window
*, int, int);
844 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
845 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
846 static int trailing_whitespace_p (ptrdiff_t);
847 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
848 static void push_it (struct it
*, struct text_pos
*);
849 static void iterate_out_of_display_property (struct it
*);
850 static void pop_it (struct it
*);
851 static void sync_frame_with_window_matrix_rows (struct window
*);
852 static void redisplay_internal (void);
853 static int echo_area_display (int);
854 static void redisplay_windows (Lisp_Object
);
855 static void redisplay_window (Lisp_Object
, int);
856 static Lisp_Object
redisplay_window_error (Lisp_Object
);
857 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
858 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
859 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
860 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
862 static int update_menu_bar (struct frame
*, int, int);
863 static int try_window_reusing_current_matrix (struct window
*);
864 static int try_window_id (struct window
*);
865 static int display_line (struct it
*);
866 static int display_mode_lines (struct window
*);
867 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
868 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
869 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
870 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
871 static void display_menu_bar (struct window
*);
872 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
874 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
875 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
876 static void compute_line_metrics (struct it
*);
877 static void run_redisplay_end_trigger_hook (struct it
*);
878 static int get_overlay_strings (struct it
*, ptrdiff_t);
879 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
880 static void next_overlay_string (struct it
*);
881 static void reseat (struct it
*, struct text_pos
, int);
882 static void reseat_1 (struct it
*, struct text_pos
, int);
883 static void back_to_previous_visible_line_start (struct it
*);
884 static void reseat_at_next_visible_line_start (struct it
*, int);
885 static int next_element_from_ellipsis (struct it
*);
886 static int next_element_from_display_vector (struct it
*);
887 static int next_element_from_string (struct it
*);
888 static int next_element_from_c_string (struct it
*);
889 static int next_element_from_buffer (struct it
*);
890 static int next_element_from_composition (struct it
*);
891 static int next_element_from_image (struct it
*);
892 static int next_element_from_stretch (struct it
*);
893 static void load_overlay_strings (struct it
*, ptrdiff_t);
894 static int init_from_display_pos (struct it
*, struct window
*,
895 struct display_pos
*);
896 static void reseat_to_string (struct it
*, const char *,
897 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
898 static int get_next_display_element (struct it
*);
899 static enum move_it_result
900 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
901 enum move_operation_enum
);
902 static void get_visually_first_element (struct it
*);
903 static void init_to_row_start (struct it
*, struct window
*,
905 static int init_to_row_end (struct it
*, struct window
*,
907 static void back_to_previous_line_start (struct it
*);
908 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
909 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
910 Lisp_Object
, ptrdiff_t);
911 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
912 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
913 static ptrdiff_t number_of_chars (const char *, bool);
914 static void compute_stop_pos (struct it
*);
915 static void compute_string_pos (struct text_pos
*, struct text_pos
,
917 static int face_before_or_after_it_pos (struct it
*, int);
918 static ptrdiff_t next_overlay_change (ptrdiff_t);
919 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
920 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
921 static int handle_single_display_spec (struct it
*, Lisp_Object
,
922 Lisp_Object
, Lisp_Object
,
923 struct text_pos
*, ptrdiff_t, int, int);
924 static int underlying_face_id (struct it
*);
925 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
928 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
929 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
931 #ifdef HAVE_WINDOW_SYSTEM
933 static void x_consider_frame_title (Lisp_Object
);
934 static int tool_bar_lines_needed (struct frame
*, int *);
935 static void update_tool_bar (struct frame
*, int);
936 static void build_desired_tool_bar_string (struct frame
*f
);
937 static int redisplay_tool_bar (struct frame
*);
938 static void display_tool_bar_line (struct it
*, int);
939 static void notice_overwritten_cursor (struct window
*,
942 static void append_stretch_glyph (struct it
*, Lisp_Object
,
946 #endif /* HAVE_WINDOW_SYSTEM */
948 static void produce_special_glyphs (struct it
*, enum display_element_type
);
949 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
950 static int coords_in_mouse_face_p (struct window
*, int, int);
954 /***********************************************************************
955 Window display dimensions
956 ***********************************************************************/
958 /* Return the bottom boundary y-position for text lines in window W.
959 This is the first y position at which a line cannot start.
960 It is relative to the top of the window.
962 This is the height of W minus the height of a mode line, if any. */
965 window_text_bottom_y (struct window
*w
)
967 int height
= WINDOW_TOTAL_HEIGHT (w
);
969 if (WINDOW_WANTS_MODELINE_P (w
))
970 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
974 /* Return the pixel width of display area AREA of window W. AREA < 0
975 means return the total width of W, not including fringes to
976 the left and right of the window. */
979 window_box_width (struct window
*w
, int area
)
981 int cols
= w
->total_cols
;
984 if (!w
->pseudo_window_p
)
986 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
988 if (area
== TEXT_AREA
)
990 if (INTEGERP (w
->left_margin_cols
))
991 cols
-= XFASTINT (w
->left_margin_cols
);
992 if (INTEGERP (w
->right_margin_cols
))
993 cols
-= XFASTINT (w
->right_margin_cols
);
994 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
996 else if (area
== LEFT_MARGIN_AREA
)
998 cols
= (INTEGERP (w
->left_margin_cols
)
999 ? XFASTINT (w
->left_margin_cols
) : 0);
1002 else if (area
== RIGHT_MARGIN_AREA
)
1004 cols
= (INTEGERP (w
->right_margin_cols
)
1005 ? XFASTINT (w
->right_margin_cols
) : 0);
1010 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1014 /* Return the pixel height of the display area of window W, not
1015 including mode lines of W, if any. */
1018 window_box_height (struct window
*w
)
1020 struct frame
*f
= XFRAME (w
->frame
);
1021 int height
= WINDOW_TOTAL_HEIGHT (w
);
1023 eassert (height
>= 0);
1025 /* Note: the code below that determines the mode-line/header-line
1026 height is essentially the same as that contained in the macro
1027 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1028 the appropriate glyph row has its `mode_line_p' flag set,
1029 and if it doesn't, uses estimate_mode_line_height instead. */
1031 if (WINDOW_WANTS_MODELINE_P (w
))
1033 struct glyph_row
*ml_row
1034 = (w
->current_matrix
&& w
->current_matrix
->rows
1035 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1037 if (ml_row
&& ml_row
->mode_line_p
)
1038 height
-= ml_row
->height
;
1040 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1043 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1045 struct glyph_row
*hl_row
1046 = (w
->current_matrix
&& w
->current_matrix
->rows
1047 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1049 if (hl_row
&& hl_row
->mode_line_p
)
1050 height
-= hl_row
->height
;
1052 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1055 /* With a very small font and a mode-line that's taller than
1056 default, we might end up with a negative height. */
1057 return max (0, height
);
1060 /* Return the window-relative coordinate of the left edge of display
1061 area AREA of window W. AREA < 0 means return the left edge of the
1062 whole window, to the right of the left fringe of W. */
1065 window_box_left_offset (struct window
*w
, int area
)
1069 if (w
->pseudo_window_p
)
1072 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1074 if (area
== TEXT_AREA
)
1075 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1076 + window_box_width (w
, LEFT_MARGIN_AREA
));
1077 else if (area
== RIGHT_MARGIN_AREA
)
1078 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1079 + window_box_width (w
, LEFT_MARGIN_AREA
)
1080 + window_box_width (w
, TEXT_AREA
)
1081 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1083 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1084 else if (area
== LEFT_MARGIN_AREA
1085 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1086 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1092 /* Return the window-relative coordinate of the right edge of display
1093 area AREA of window W. AREA < 0 means return the right edge of the
1094 whole window, to the left of the right fringe of W. */
1097 window_box_right_offset (struct window
*w
, int area
)
1099 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1102 /* Return the frame-relative coordinate of the left edge of display
1103 area AREA of window W. AREA < 0 means return the left edge of the
1104 whole window, to the right of the left fringe of W. */
1107 window_box_left (struct window
*w
, int area
)
1109 struct frame
*f
= XFRAME (w
->frame
);
1112 if (w
->pseudo_window_p
)
1113 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1115 x
= (WINDOW_LEFT_EDGE_X (w
)
1116 + window_box_left_offset (w
, area
));
1122 /* Return the frame-relative coordinate of the right edge of display
1123 area AREA of window W. AREA < 0 means return the right edge of the
1124 whole window, to the left of the right fringe of W. */
1127 window_box_right (struct window
*w
, int area
)
1129 return window_box_left (w
, area
) + window_box_width (w
, area
);
1132 /* Get the bounding box of the display area AREA of window W, without
1133 mode lines, in frame-relative coordinates. AREA < 0 means the
1134 whole window, not including the left and right fringes of
1135 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1136 coordinates of the upper-left corner of the box. Return in
1137 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1140 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1141 int *box_width
, int *box_height
)
1144 *box_width
= window_box_width (w
, area
);
1146 *box_height
= window_box_height (w
);
1148 *box_x
= window_box_left (w
, area
);
1151 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1152 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1153 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1158 /* Get the bounding box of the display area AREA of window W, without
1159 mode lines. AREA < 0 means the whole window, not including the
1160 left and right fringe of the window. Return in *TOP_LEFT_X
1161 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1162 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1163 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1167 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1168 int *bottom_right_x
, int *bottom_right_y
)
1170 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1172 *bottom_right_x
+= *top_left_x
;
1173 *bottom_right_y
+= *top_left_y
;
1178 /***********************************************************************
1180 ***********************************************************************/
1182 /* Return the bottom y-position of the line the iterator IT is in.
1183 This can modify IT's settings. */
1186 line_bottom_y (struct it
*it
)
1188 int line_height
= it
->max_ascent
+ it
->max_descent
;
1189 int line_top_y
= it
->current_y
;
1191 if (line_height
== 0)
1194 line_height
= last_height
;
1195 else if (IT_CHARPOS (*it
) < ZV
)
1197 move_it_by_lines (it
, 1);
1198 line_height
= (it
->max_ascent
|| it
->max_descent
1199 ? it
->max_ascent
+ it
->max_descent
1204 struct glyph_row
*row
= it
->glyph_row
;
1206 /* Use the default character height. */
1207 it
->glyph_row
= NULL
;
1208 it
->what
= IT_CHARACTER
;
1211 PRODUCE_GLYPHS (it
);
1212 line_height
= it
->ascent
+ it
->descent
;
1213 it
->glyph_row
= row
;
1217 return line_top_y
+ line_height
;
1220 /* Subroutine of pos_visible_p below. Extracts a display string, if
1221 any, from the display spec given as its argument. */
1223 string_from_display_spec (Lisp_Object spec
)
1227 while (CONSP (spec
))
1229 if (STRINGP (XCAR (spec
)))
1234 else if (VECTORP (spec
))
1238 for (i
= 0; i
< ASIZE (spec
); i
++)
1240 if (STRINGP (AREF (spec
, i
)))
1241 return AREF (spec
, i
);
1250 /* Limit insanely large values of W->hscroll on frame F to the largest
1251 value that will still prevent first_visible_x and last_visible_x of
1252 'struct it' from overflowing an int. */
1254 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1256 ptrdiff_t window_hscroll
= w
->hscroll
;
1257 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1258 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1260 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1261 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1263 return window_hscroll
;
1266 /* Return 1 if position CHARPOS is visible in window W.
1267 CHARPOS < 0 means return info about WINDOW_END position.
1268 If visible, set *X and *Y to pixel coordinates of top left corner.
1269 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1270 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1273 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1274 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1277 void *itdata
= bidi_shelve_cache ();
1278 struct text_pos top
;
1280 struct buffer
*old_buffer
= NULL
;
1282 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1285 if (XBUFFER (w
->contents
) != current_buffer
)
1287 old_buffer
= current_buffer
;
1288 set_buffer_internal_1 (XBUFFER (w
->contents
));
1291 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1292 /* Scrolling a minibuffer window via scroll bar when the echo area
1293 shows long text sometimes resets the minibuffer contents behind
1295 if (CHARPOS (top
) > ZV
)
1296 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1298 /* Compute exact mode line heights. */
1299 if (WINDOW_WANTS_MODELINE_P (w
))
1300 current_mode_line_height
1301 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1302 BVAR (current_buffer
, mode_line_format
));
1304 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1305 current_header_line_height
1306 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1307 BVAR (current_buffer
, header_line_format
));
1309 start_display (&it
, w
, top
);
1310 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1311 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1314 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1315 && IT_CHARPOS (it
) >= charpos
)
1316 /* When scanning backwards under bidi iteration, move_it_to
1317 stops at or _before_ CHARPOS, because it stops at or to
1318 the _right_ of the character at CHARPOS. */
1319 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1320 && IT_CHARPOS (it
) <= charpos
)))
1322 /* We have reached CHARPOS, or passed it. How the call to
1323 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1324 or covered by a display property, move_it_to stops at the end
1325 of the invisible text, to the right of CHARPOS. (ii) If
1326 CHARPOS is in a display vector, move_it_to stops on its last
1328 int top_x
= it
.current_x
;
1329 int top_y
= it
.current_y
;
1330 /* Calling line_bottom_y may change it.method, it.position, etc. */
1331 enum it_method it_method
= it
.method
;
1332 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1333 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1335 if (top_y
< window_top_y
)
1336 visible_p
= bottom_y
> window_top_y
;
1337 else if (top_y
< it
.last_visible_y
)
1339 if (bottom_y
>= it
.last_visible_y
1340 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1341 && IT_CHARPOS (it
) < charpos
)
1343 /* When the last line of the window is scanned backwards
1344 under bidi iteration, we could be duped into thinking
1345 that we have passed CHARPOS, when in fact move_it_to
1346 simply stopped short of CHARPOS because it reached
1347 last_visible_y. To see if that's what happened, we call
1348 move_it_to again with a slightly larger vertical limit,
1349 and see if it actually moved vertically; if it did, we
1350 didn't really reach CHARPOS, which is beyond window end. */
1351 struct it save_it
= it
;
1352 /* Why 10? because we don't know how many canonical lines
1353 will the height of the next line(s) be. So we guess. */
1354 int ten_more_lines
=
1355 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1357 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1358 MOVE_TO_POS
| MOVE_TO_Y
);
1359 if (it
.current_y
> top_y
)
1366 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1368 /* We stopped on the last glyph of a display vector.
1369 Try and recompute. Hack alert! */
1370 if (charpos
< 2 || top
.charpos
>= charpos
)
1371 top_x
= it
.glyph_row
->x
;
1375 start_display (&it2
, w
, top
);
1376 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1377 get_next_display_element (&it2
);
1378 PRODUCE_GLYPHS (&it2
);
1379 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1380 || it2
.current_x
> it2
.last_visible_x
)
1381 top_x
= it
.glyph_row
->x
;
1384 top_x
= it2
.current_x
;
1385 top_y
= it2
.current_y
;
1389 else if (IT_CHARPOS (it
) != charpos
)
1391 Lisp_Object cpos
= make_number (charpos
);
1392 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1393 Lisp_Object string
= string_from_display_spec (spec
);
1394 struct text_pos tpos
;
1395 int replacing_spec_p
;
1396 bool newline_in_string
1398 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1400 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1403 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1404 charpos
, FRAME_WINDOW_P (it
.f
)));
1405 /* The tricky code below is needed because there's a
1406 discrepancy between move_it_to and how we set cursor
1407 when PT is at the beginning of a portion of text
1408 covered by a display property or an overlay with a
1409 display property, or the display line ends in a
1410 newline from a display string. move_it_to will stop
1411 _after_ such display strings, whereas
1412 set_cursor_from_row conspires with cursor_row_p to
1413 place the cursor on the first glyph produced from the
1416 /* We have overshoot PT because it is covered by a
1417 display property that replaces the text it covers.
1418 If the string includes embedded newlines, we are also
1419 in the wrong display line. Backtrack to the correct
1420 line, where the display property begins. */
1421 if (replacing_spec_p
)
1423 Lisp_Object startpos
, endpos
;
1424 EMACS_INT start
, end
;
1428 /* Find the first and the last buffer positions
1429 covered by the display string. */
1431 Fnext_single_char_property_change (cpos
, Qdisplay
,
1434 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1436 start
= XFASTINT (startpos
);
1437 end
= XFASTINT (endpos
);
1438 /* Move to the last buffer position before the
1439 display property. */
1440 start_display (&it3
, w
, top
);
1441 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1442 /* Move forward one more line if the position before
1443 the display string is a newline or if it is the
1444 rightmost character on a line that is
1445 continued or word-wrapped. */
1446 if (it3
.method
== GET_FROM_BUFFER
1448 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1449 move_it_by_lines (&it3
, 1);
1450 else if (move_it_in_display_line_to (&it3
, -1,
1454 == MOVE_LINE_CONTINUED
)
1456 move_it_by_lines (&it3
, 1);
1457 /* When we are under word-wrap, the #$@%!
1458 move_it_by_lines moves 2 lines, so we need to
1460 if (it3
.line_wrap
== WORD_WRAP
)
1461 move_it_by_lines (&it3
, -1);
1464 /* Record the vertical coordinate of the display
1465 line where we wound up. */
1466 top_y
= it3
.current_y
;
1469 /* When characters are reordered for display,
1470 the character displayed to the left of the
1471 display string could be _after_ the display
1472 property in the logical order. Use the
1473 smallest vertical position of these two. */
1474 start_display (&it3
, w
, top
);
1475 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1476 if (it3
.current_y
< top_y
)
1477 top_y
= it3
.current_y
;
1479 /* Move from the top of the window to the beginning
1480 of the display line where the display string
1482 start_display (&it3
, w
, top
);
1483 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1484 /* If it3_moved stays zero after the 'while' loop
1485 below, that means we already were at a newline
1486 before the loop (e.g., the display string begins
1487 with a newline), so we don't need to (and cannot)
1488 inspect the glyphs of it3.glyph_row, because
1489 PRODUCE_GLYPHS will not produce anything for a
1490 newline, and thus it3.glyph_row stays at its
1491 stale content it got at top of the window. */
1493 /* Finally, advance the iterator until we hit the
1494 first display element whose character position is
1495 CHARPOS, or until the first newline from the
1496 display string, which signals the end of the
1498 while (get_next_display_element (&it3
))
1500 PRODUCE_GLYPHS (&it3
);
1501 if (IT_CHARPOS (it3
) == charpos
1502 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1505 set_iterator_to_next (&it3
, 0);
1507 top_x
= it3
.current_x
- it3
.pixel_width
;
1508 /* Normally, we would exit the above loop because we
1509 found the display element whose character
1510 position is CHARPOS. For the contingency that we
1511 didn't, and stopped at the first newline from the
1512 display string, move back over the glyphs
1513 produced from the string, until we find the
1514 rightmost glyph not from the string. */
1516 && newline_in_string
1517 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1519 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1520 + it3
.glyph_row
->used
[TEXT_AREA
];
1522 while (EQ ((g
- 1)->object
, string
))
1525 top_x
-= g
->pixel_width
;
1527 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1528 + it3
.glyph_row
->used
[TEXT_AREA
]);
1534 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1535 *rtop
= max (0, window_top_y
- top_y
);
1536 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1537 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1538 - max (top_y
, window_top_y
)));
1544 /* We were asked to provide info about WINDOW_END. */
1546 void *it2data
= NULL
;
1548 SAVE_IT (it2
, it
, it2data
);
1549 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1550 move_it_by_lines (&it
, 1);
1551 if (charpos
< IT_CHARPOS (it
)
1552 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1555 RESTORE_IT (&it2
, &it2
, it2data
);
1556 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1558 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1559 *rtop
= max (0, -it2
.current_y
);
1560 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1561 - it
.last_visible_y
));
1562 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1564 - max (it2
.current_y
,
1565 WINDOW_HEADER_LINE_HEIGHT (w
))));
1569 bidi_unshelve_cache (it2data
, 1);
1571 bidi_unshelve_cache (itdata
, 0);
1574 set_buffer_internal_1 (old_buffer
);
1576 current_header_line_height
= current_mode_line_height
= -1;
1578 if (visible_p
&& w
->hscroll
> 0)
1580 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1581 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1584 /* Debugging code. */
1586 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1587 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1589 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1596 /* Return the next character from STR. Return in *LEN the length of
1597 the character. This is like STRING_CHAR_AND_LENGTH but never
1598 returns an invalid character. If we find one, we return a `?', but
1599 with the length of the invalid character. */
1602 string_char_and_length (const unsigned char *str
, int *len
)
1606 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1607 if (!CHAR_VALID_P (c
))
1608 /* We may not change the length here because other places in Emacs
1609 don't use this function, i.e. they silently accept invalid
1618 /* Given a position POS containing a valid character and byte position
1619 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1621 static struct text_pos
1622 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1624 eassert (STRINGP (string
) && nchars
>= 0);
1626 if (STRING_MULTIBYTE (string
))
1628 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1633 string_char_and_length (p
, &len
);
1636 BYTEPOS (pos
) += len
;
1640 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1646 /* Value is the text position, i.e. character and byte position,
1647 for character position CHARPOS in STRING. */
1649 static struct text_pos
1650 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1652 struct text_pos pos
;
1653 eassert (STRINGP (string
));
1654 eassert (charpos
>= 0);
1655 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1660 /* Value is a text position, i.e. character and byte position, for
1661 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1662 means recognize multibyte characters. */
1664 static struct text_pos
1665 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1667 struct text_pos pos
;
1669 eassert (s
!= NULL
);
1670 eassert (charpos
>= 0);
1676 SET_TEXT_POS (pos
, 0, 0);
1679 string_char_and_length ((const unsigned char *) s
, &len
);
1682 BYTEPOS (pos
) += len
;
1686 SET_TEXT_POS (pos
, charpos
, charpos
);
1692 /* Value is the number of characters in C string S. MULTIBYTE_P
1693 non-zero means recognize multibyte characters. */
1696 number_of_chars (const char *s
, bool multibyte_p
)
1702 ptrdiff_t rest
= strlen (s
);
1704 const unsigned char *p
= (const unsigned char *) s
;
1706 for (nchars
= 0; rest
> 0; ++nchars
)
1708 string_char_and_length (p
, &len
);
1709 rest
-= len
, p
+= len
;
1713 nchars
= strlen (s
);
1719 /* Compute byte position NEWPOS->bytepos corresponding to
1720 NEWPOS->charpos. POS is a known position in string STRING.
1721 NEWPOS->charpos must be >= POS.charpos. */
1724 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1726 eassert (STRINGP (string
));
1727 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1729 if (STRING_MULTIBYTE (string
))
1730 *newpos
= string_pos_nchars_ahead (pos
, string
,
1731 CHARPOS (*newpos
) - CHARPOS (pos
));
1733 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1737 Return an estimation of the pixel height of mode or header lines on
1738 frame F. FACE_ID specifies what line's height to estimate. */
1741 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1743 #ifdef HAVE_WINDOW_SYSTEM
1744 if (FRAME_WINDOW_P (f
))
1746 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1748 /* This function is called so early when Emacs starts that the face
1749 cache and mode line face are not yet initialized. */
1750 if (FRAME_FACE_CACHE (f
))
1752 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1756 height
= FONT_HEIGHT (face
->font
);
1757 if (face
->box_line_width
> 0)
1758 height
+= 2 * face
->box_line_width
;
1769 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1770 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1771 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1772 not force the value into range. */
1775 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1776 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1779 #ifdef HAVE_WINDOW_SYSTEM
1780 if (FRAME_WINDOW_P (f
))
1782 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1783 even for negative values. */
1785 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1787 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1789 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1790 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1793 STORE_NATIVE_RECT (*bounds
,
1794 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1795 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1796 FRAME_COLUMN_WIDTH (f
) - 1,
1797 FRAME_LINE_HEIGHT (f
) - 1);
1803 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1804 pix_x
= FRAME_TOTAL_COLS (f
);
1808 else if (pix_y
> FRAME_LINES (f
))
1809 pix_y
= FRAME_LINES (f
);
1819 /* Find the glyph under window-relative coordinates X/Y in window W.
1820 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1821 strings. Return in *HPOS and *VPOS the row and column number of
1822 the glyph found. Return in *AREA the glyph area containing X.
1823 Value is a pointer to the glyph found or null if X/Y is not on
1824 text, or we can't tell because W's current matrix is not up to
1829 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1830 int *dx
, int *dy
, int *area
)
1832 struct glyph
*glyph
, *end
;
1833 struct glyph_row
*row
= NULL
;
1836 /* Find row containing Y. Give up if some row is not enabled. */
1837 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1839 row
= MATRIX_ROW (w
->current_matrix
, i
);
1840 if (!row
->enabled_p
)
1842 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1849 /* Give up if Y is not in the window. */
1850 if (i
== w
->current_matrix
->nrows
)
1853 /* Get the glyph area containing X. */
1854 if (w
->pseudo_window_p
)
1861 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1863 *area
= LEFT_MARGIN_AREA
;
1864 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1866 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1869 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1873 *area
= RIGHT_MARGIN_AREA
;
1874 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1878 /* Find glyph containing X. */
1879 glyph
= row
->glyphs
[*area
];
1880 end
= glyph
+ row
->used
[*area
];
1882 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1884 x
-= glyph
->pixel_width
;
1894 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1897 *hpos
= glyph
- row
->glyphs
[*area
];
1901 /* Convert frame-relative x/y to coordinates relative to window W.
1902 Takes pseudo-windows into account. */
1905 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1907 if (w
->pseudo_window_p
)
1909 /* A pseudo-window is always full-width, and starts at the
1910 left edge of the frame, plus a frame border. */
1911 struct frame
*f
= XFRAME (w
->frame
);
1912 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1913 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1917 *x
-= WINDOW_LEFT_EDGE_X (w
);
1918 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1922 #ifdef HAVE_WINDOW_SYSTEM
1925 Return in RECTS[] at most N clipping rectangles for glyph string S.
1926 Return the number of stored rectangles. */
1929 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1936 if (s
->row
->full_width_p
)
1938 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1939 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1940 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1942 /* Unless displaying a mode or menu bar line, which are always
1943 fully visible, clip to the visible part of the row. */
1944 if (s
->w
->pseudo_window_p
)
1945 r
.height
= s
->row
->visible_height
;
1947 r
.height
= s
->height
;
1951 /* This is a text line that may be partially visible. */
1952 r
.x
= window_box_left (s
->w
, s
->area
);
1953 r
.width
= window_box_width (s
->w
, s
->area
);
1954 r
.height
= s
->row
->visible_height
;
1958 if (r
.x
< s
->clip_head
->x
)
1960 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1961 r
.width
-= s
->clip_head
->x
- r
.x
;
1964 r
.x
= s
->clip_head
->x
;
1967 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1969 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1970 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1975 /* If S draws overlapping rows, it's sufficient to use the top and
1976 bottom of the window for clipping because this glyph string
1977 intentionally draws over other lines. */
1978 if (s
->for_overlaps
)
1980 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1981 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1983 /* Alas, the above simple strategy does not work for the
1984 environments with anti-aliased text: if the same text is
1985 drawn onto the same place multiple times, it gets thicker.
1986 If the overlap we are processing is for the erased cursor, we
1987 take the intersection with the rectangle of the cursor. */
1988 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1990 XRectangle rc
, r_save
= r
;
1992 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1993 rc
.y
= s
->w
->phys_cursor
.y
;
1994 rc
.width
= s
->w
->phys_cursor_width
;
1995 rc
.height
= s
->w
->phys_cursor_height
;
1997 x_intersect_rectangles (&r_save
, &rc
, &r
);
2002 /* Don't use S->y for clipping because it doesn't take partially
2003 visible lines into account. For example, it can be negative for
2004 partially visible lines at the top of a window. */
2005 if (!s
->row
->full_width_p
2006 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2007 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2009 r
.y
= max (0, s
->row
->y
);
2012 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2014 /* If drawing the cursor, don't let glyph draw outside its
2015 advertised boundaries. Cleartype does this under some circumstances. */
2016 if (s
->hl
== DRAW_CURSOR
)
2018 struct glyph
*glyph
= s
->first_glyph
;
2023 r
.width
-= s
->x
- r
.x
;
2026 r
.width
= min (r
.width
, glyph
->pixel_width
);
2028 /* If r.y is below window bottom, ensure that we still see a cursor. */
2029 height
= min (glyph
->ascent
+ glyph
->descent
,
2030 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2031 max_y
= window_text_bottom_y (s
->w
) - height
;
2032 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2033 if (s
->ybase
- glyph
->ascent
> max_y
)
2040 /* Don't draw cursor glyph taller than our actual glyph. */
2041 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2042 if (height
< r
.height
)
2044 max_y
= r
.y
+ r
.height
;
2045 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2046 r
.height
= min (max_y
- r
.y
, height
);
2053 XRectangle r_save
= r
;
2055 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2059 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2060 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2062 #ifdef CONVERT_FROM_XRECT
2063 CONVERT_FROM_XRECT (r
, *rects
);
2071 /* If we are processing overlapping and allowed to return
2072 multiple clipping rectangles, we exclude the row of the glyph
2073 string from the clipping rectangle. This is to avoid drawing
2074 the same text on the environment with anti-aliasing. */
2075 #ifdef CONVERT_FROM_XRECT
2078 XRectangle
*rs
= rects
;
2080 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2082 if (s
->for_overlaps
& OVERLAPS_PRED
)
2085 if (r
.y
+ r
.height
> row_y
)
2088 rs
[i
].height
= row_y
- r
.y
;
2094 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2097 if (r
.y
< row_y
+ s
->row
->visible_height
)
2099 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2101 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2102 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2111 #ifdef CONVERT_FROM_XRECT
2112 for (i
= 0; i
< n
; i
++)
2113 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2120 Return in *NR the clipping rectangle for glyph string S. */
2123 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2125 get_glyph_string_clip_rects (s
, nr
, 1);
2130 Return the position and height of the phys cursor in window W.
2131 Set w->phys_cursor_width to width of phys cursor.
2135 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2136 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2138 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2139 int x
, y
, wd
, h
, h0
, y0
;
2141 /* Compute the width of the rectangle to draw. If on a stretch
2142 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2143 rectangle as wide as the glyph, but use a canonical character
2145 wd
= glyph
->pixel_width
- 1;
2146 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2150 x
= w
->phys_cursor
.x
;
2157 if (glyph
->type
== STRETCH_GLYPH
2158 && !x_stretch_cursor_p
)
2159 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2160 w
->phys_cursor_width
= wd
;
2162 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2164 /* If y is below window bottom, ensure that we still see a cursor. */
2165 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2167 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2168 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2170 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2173 h
= max (h
- (y0
- y
) + 1, h0
);
2178 y0
= window_text_bottom_y (w
) - h0
;
2186 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2187 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2192 * Remember which glyph the mouse is over.
2196 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2200 struct glyph_row
*r
, *gr
, *end_row
;
2201 enum window_part part
;
2202 enum glyph_row_area area
;
2203 int x
, y
, width
, height
;
2205 /* Try to determine frame pixel position and size of the glyph under
2206 frame pixel coordinates X/Y on frame F. */
2208 if (!f
->glyphs_initialized_p
2209 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2212 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2213 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2217 w
= XWINDOW (window
);
2218 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2219 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2221 x
= window_relative_x_coord (w
, part
, gx
);
2222 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2224 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2225 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2227 if (w
->pseudo_window_p
)
2230 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2236 case ON_LEFT_MARGIN
:
2237 area
= LEFT_MARGIN_AREA
;
2240 case ON_RIGHT_MARGIN
:
2241 area
= RIGHT_MARGIN_AREA
;
2244 case ON_HEADER_LINE
:
2246 gr
= (part
== ON_HEADER_LINE
2247 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2248 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2251 goto text_glyph_row_found
;
2258 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2259 if (r
->y
+ r
->height
> y
)
2265 text_glyph_row_found
:
2268 struct glyph
*g
= gr
->glyphs
[area
];
2269 struct glyph
*end
= g
+ gr
->used
[area
];
2271 height
= gr
->height
;
2272 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2273 if (gx
+ g
->pixel_width
> x
)
2278 if (g
->type
== IMAGE_GLYPH
)
2280 /* Don't remember when mouse is over image, as
2281 image may have hot-spots. */
2282 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2285 width
= g
->pixel_width
;
2289 /* Use nominal char spacing at end of line. */
2291 gx
+= (x
/ width
) * width
;
2294 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2295 gx
+= window_box_left_offset (w
, area
);
2299 /* Use nominal line height at end of window. */
2300 gx
= (x
/ width
) * width
;
2302 gy
+= (y
/ height
) * height
;
2306 case ON_LEFT_FRINGE
:
2307 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2308 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2309 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2310 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2313 case ON_RIGHT_FRINGE
:
2314 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2315 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2316 : window_box_right_offset (w
, TEXT_AREA
));
2317 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2321 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2323 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2324 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2325 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2327 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2331 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2332 if (r
->y
+ r
->height
> y
)
2339 height
= gr
->height
;
2342 /* Use nominal line height at end of window. */
2344 gy
+= (y
/ height
) * height
;
2351 /* If there is no glyph under the mouse, then we divide the screen
2352 into a grid of the smallest glyph in the frame, and use that
2355 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2356 round down even for negative values. */
2362 gx
= (gx
/ width
) * width
;
2363 gy
= (gy
/ height
) * height
;
2368 gx
+= WINDOW_LEFT_EDGE_X (w
);
2369 gy
+= WINDOW_TOP_EDGE_Y (w
);
2372 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2374 /* Visible feedback for debugging. */
2377 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2378 f
->output_data
.x
->normal_gc
,
2379 gx
, gy
, width
, height
);
2385 #endif /* HAVE_WINDOW_SYSTEM */
2388 /***********************************************************************
2389 Lisp form evaluation
2390 ***********************************************************************/
2392 /* Error handler for safe_eval and safe_call. */
2395 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2397 add_to_log ("Error during redisplay: %S signaled %S",
2398 Flist (nargs
, args
), arg
);
2402 /* Call function FUNC with the rest of NARGS - 1 arguments
2403 following. Return the result, or nil if something went
2404 wrong. Prevent redisplay during the evaluation. */
2407 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2411 if (inhibit_eval_during_redisplay
)
2417 ptrdiff_t count
= SPECPDL_INDEX ();
2418 struct gcpro gcpro1
;
2419 Lisp_Object
*args
= alloca (nargs
* word_size
);
2422 va_start (ap
, func
);
2423 for (i
= 1; i
< nargs
; i
++)
2424 args
[i
] = va_arg (ap
, Lisp_Object
);
2428 gcpro1
.nvars
= nargs
;
2429 specbind (Qinhibit_redisplay
, Qt
);
2430 /* Use Qt to ensure debugger does not run,
2431 so there is no possibility of wanting to redisplay. */
2432 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2435 val
= unbind_to (count
, val
);
2442 /* Call function FN with one argument ARG.
2443 Return the result, or nil if something went wrong. */
2446 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2448 return safe_call (2, fn
, arg
);
2451 static Lisp_Object Qeval
;
2454 safe_eval (Lisp_Object sexpr
)
2456 return safe_call1 (Qeval
, sexpr
);
2459 /* Call function FN with two arguments ARG1 and ARG2.
2460 Return the result, or nil if something went wrong. */
2463 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2465 return safe_call (3, fn
, arg1
, arg2
);
2470 /***********************************************************************
2472 ***********************************************************************/
2476 /* Define CHECK_IT to perform sanity checks on iterators.
2477 This is for debugging. It is too slow to do unconditionally. */
2480 check_it (struct it
*it
)
2482 if (it
->method
== GET_FROM_STRING
)
2484 eassert (STRINGP (it
->string
));
2485 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2489 eassert (IT_STRING_CHARPOS (*it
) < 0);
2490 if (it
->method
== GET_FROM_BUFFER
)
2492 /* Check that character and byte positions agree. */
2493 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2498 eassert (it
->current
.dpvec_index
>= 0);
2500 eassert (it
->current
.dpvec_index
< 0);
2503 #define CHECK_IT(IT) check_it ((IT))
2507 #define CHECK_IT(IT) (void) 0
2512 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2514 /* Check that the window end of window W is what we expect it
2515 to be---the last row in the current matrix displaying text. */
2518 check_window_end (struct window
*w
)
2520 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2522 struct glyph_row
*row
;
2523 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2524 XFASTINT (w
->window_end_vpos
)),
2526 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2527 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2531 #define CHECK_WINDOW_END(W) check_window_end ((W))
2535 #define CHECK_WINDOW_END(W) (void) 0
2537 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2539 /* Return mark position if current buffer has the region of non-zero length,
2543 markpos_of_region (void)
2545 if (!NILP (Vtransient_mark_mode
)
2546 && !NILP (BVAR (current_buffer
, mark_active
))
2547 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2549 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2557 /***********************************************************************
2558 Iterator initialization
2559 ***********************************************************************/
2561 /* Initialize IT for displaying current_buffer in window W, starting
2562 at character position CHARPOS. CHARPOS < 0 means that no buffer
2563 position is specified which is useful when the iterator is assigned
2564 a position later. BYTEPOS is the byte position corresponding to
2567 If ROW is not null, calls to produce_glyphs with IT as parameter
2568 will produce glyphs in that row.
2570 BASE_FACE_ID is the id of a base face to use. It must be one of
2571 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2572 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2573 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2575 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2576 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2577 will be initialized to use the corresponding mode line glyph row of
2578 the desired matrix of W. */
2581 init_iterator (struct it
*it
, struct window
*w
,
2582 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2583 struct glyph_row
*row
, enum face_id base_face_id
)
2586 enum face_id remapped_base_face_id
= base_face_id
;
2588 /* Some precondition checks. */
2589 eassert (w
!= NULL
&& it
!= NULL
);
2590 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2593 /* If face attributes have been changed since the last redisplay,
2594 free realized faces now because they depend on face definitions
2595 that might have changed. Don't free faces while there might be
2596 desired matrices pending which reference these faces. */
2597 if (face_change_count
&& !inhibit_free_realized_faces
)
2599 face_change_count
= 0;
2600 free_all_realized_faces (Qnil
);
2603 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2604 if (! NILP (Vface_remapping_alist
))
2605 remapped_base_face_id
2606 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2608 /* Use one of the mode line rows of W's desired matrix if
2612 if (base_face_id
== MODE_LINE_FACE_ID
2613 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2614 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2615 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2616 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2620 memset (it
, 0, sizeof *it
);
2621 it
->current
.overlay_string_index
= -1;
2622 it
->current
.dpvec_index
= -1;
2623 it
->base_face_id
= remapped_base_face_id
;
2625 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2626 it
->paragraph_embedding
= L2R
;
2627 it
->bidi_it
.string
.lstring
= Qnil
;
2628 it
->bidi_it
.string
.s
= NULL
;
2629 it
->bidi_it
.string
.bufpos
= 0;
2631 /* The window in which we iterate over current_buffer: */
2632 XSETWINDOW (it
->window
, w
);
2634 it
->f
= XFRAME (w
->frame
);
2638 /* Extra space between lines (on window systems only). */
2639 if (base_face_id
== DEFAULT_FACE_ID
2640 && FRAME_WINDOW_P (it
->f
))
2642 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2643 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2644 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2645 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2646 * FRAME_LINE_HEIGHT (it
->f
));
2647 else if (it
->f
->extra_line_spacing
> 0)
2648 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2649 it
->max_extra_line_spacing
= 0;
2652 /* If realized faces have been removed, e.g. because of face
2653 attribute changes of named faces, recompute them. When running
2654 in batch mode, the face cache of the initial frame is null. If
2655 we happen to get called, make a dummy face cache. */
2656 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2657 init_frame_faces (it
->f
);
2658 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2659 recompute_basic_faces (it
->f
);
2661 /* Current value of the `slice', `space-width', and 'height' properties. */
2662 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2663 it
->space_width
= Qnil
;
2664 it
->font_height
= Qnil
;
2665 it
->override_ascent
= -1;
2667 /* Are control characters displayed as `^C'? */
2668 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2670 /* -1 means everything between a CR and the following line end
2671 is invisible. >0 means lines indented more than this value are
2673 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2675 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2677 : (!NILP (BVAR (current_buffer
, selective_display
))
2679 it
->selective_display_ellipsis_p
2680 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2682 /* Display table to use. */
2683 it
->dp
= window_display_table (w
);
2685 /* Are multibyte characters enabled in current_buffer? */
2686 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2688 /* If visible region is of non-zero length, set IT->region_beg_charpos
2689 and IT->region_end_charpos to the start and end of a visible region
2690 in window IT->w. Set both to -1 to indicate no region. */
2691 markpos
= markpos_of_region ();
2693 /* Maybe highlight only in selected window. */
2694 && (/* Either show region everywhere. */
2695 highlight_nonselected_windows
2696 /* Or show region in the selected window. */
2697 || w
== XWINDOW (selected_window
)
2698 /* Or show the region if we are in the mini-buffer and W is
2699 the window the mini-buffer refers to. */
2700 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2701 && WINDOWP (minibuf_selected_window
)
2702 && w
== XWINDOW (minibuf_selected_window
))))
2704 it
->region_beg_charpos
= min (PT
, markpos
);
2705 it
->region_end_charpos
= max (PT
, markpos
);
2708 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2710 /* Get the position at which the redisplay_end_trigger hook should
2711 be run, if it is to be run at all. */
2712 if (MARKERP (w
->redisplay_end_trigger
)
2713 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2714 it
->redisplay_end_trigger_charpos
2715 = marker_position (w
->redisplay_end_trigger
);
2716 else if (INTEGERP (w
->redisplay_end_trigger
))
2717 it
->redisplay_end_trigger_charpos
=
2718 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2720 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2722 /* Are lines in the display truncated? */
2723 if (base_face_id
!= DEFAULT_FACE_ID
2725 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2726 && ((!NILP (Vtruncate_partial_width_windows
)
2727 && !INTEGERP (Vtruncate_partial_width_windows
))
2728 || (INTEGERP (Vtruncate_partial_width_windows
)
2729 && (WINDOW_TOTAL_COLS (it
->w
)
2730 < XINT (Vtruncate_partial_width_windows
))))))
2731 it
->line_wrap
= TRUNCATE
;
2732 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2733 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2734 ? WINDOW_WRAP
: WORD_WRAP
;
2736 it
->line_wrap
= TRUNCATE
;
2738 /* Get dimensions of truncation and continuation glyphs. These are
2739 displayed as fringe bitmaps under X, but we need them for such
2740 frames when the fringes are turned off. But leave the dimensions
2741 zero for tooltip frames, as these glyphs look ugly there and also
2742 sabotage calculations of tooltip dimensions in x-show-tip. */
2743 #ifdef HAVE_WINDOW_SYSTEM
2744 if (!(FRAME_WINDOW_P (it
->f
)
2745 && FRAMEP (tip_frame
)
2746 && it
->f
== XFRAME (tip_frame
)))
2749 if (it
->line_wrap
== TRUNCATE
)
2751 /* We will need the truncation glyph. */
2752 eassert (it
->glyph_row
== NULL
);
2753 produce_special_glyphs (it
, IT_TRUNCATION
);
2754 it
->truncation_pixel_width
= it
->pixel_width
;
2758 /* We will need the continuation glyph. */
2759 eassert (it
->glyph_row
== NULL
);
2760 produce_special_glyphs (it
, IT_CONTINUATION
);
2761 it
->continuation_pixel_width
= it
->pixel_width
;
2765 /* Reset these values to zero because the produce_special_glyphs
2766 above has changed them. */
2767 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2768 it
->phys_ascent
= it
->phys_descent
= 0;
2770 /* Set this after getting the dimensions of truncation and
2771 continuation glyphs, so that we don't produce glyphs when calling
2772 produce_special_glyphs, above. */
2773 it
->glyph_row
= row
;
2774 it
->area
= TEXT_AREA
;
2776 /* Forget any previous info about this row being reversed. */
2778 it
->glyph_row
->reversed_p
= 0;
2780 /* Get the dimensions of the display area. The display area
2781 consists of the visible window area plus a horizontally scrolled
2782 part to the left of the window. All x-values are relative to the
2783 start of this total display area. */
2784 if (base_face_id
!= DEFAULT_FACE_ID
)
2786 /* Mode lines, menu bar in terminal frames. */
2787 it
->first_visible_x
= 0;
2788 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2792 it
->first_visible_x
=
2793 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2794 it
->last_visible_x
= (it
->first_visible_x
2795 + window_box_width (w
, TEXT_AREA
));
2797 /* If we truncate lines, leave room for the truncation glyph(s) at
2798 the right margin. Otherwise, leave room for the continuation
2799 glyph(s). Done only if the window has no fringes. Since we
2800 don't know at this point whether there will be any R2L lines in
2801 the window, we reserve space for truncation/continuation glyphs
2802 even if only one of the fringes is absent. */
2803 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2804 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2806 if (it
->line_wrap
== TRUNCATE
)
2807 it
->last_visible_x
-= it
->truncation_pixel_width
;
2809 it
->last_visible_x
-= it
->continuation_pixel_width
;
2812 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2813 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2816 /* Leave room for a border glyph. */
2817 if (!FRAME_WINDOW_P (it
->f
)
2818 && !WINDOW_RIGHTMOST_P (it
->w
))
2819 it
->last_visible_x
-= 1;
2821 it
->last_visible_y
= window_text_bottom_y (w
);
2823 /* For mode lines and alike, arrange for the first glyph having a
2824 left box line if the face specifies a box. */
2825 if (base_face_id
!= DEFAULT_FACE_ID
)
2829 it
->face_id
= remapped_base_face_id
;
2831 /* If we have a boxed mode line, make the first character appear
2832 with a left box line. */
2833 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2834 if (face
->box
!= FACE_NO_BOX
)
2835 it
->start_of_box_run_p
= 1;
2838 /* If a buffer position was specified, set the iterator there,
2839 getting overlays and face properties from that position. */
2840 if (charpos
>= BUF_BEG (current_buffer
))
2842 it
->end_charpos
= ZV
;
2843 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2844 IT_CHARPOS (*it
) = charpos
;
2845 IT_BYTEPOS (*it
) = bytepos
;
2847 /* We will rely on `reseat' to set this up properly, via
2848 handle_face_prop. */
2849 it
->face_id
= it
->base_face_id
;
2851 it
->start
= it
->current
;
2852 /* Do we need to reorder bidirectional text? Not if this is a
2853 unibyte buffer: by definition, none of the single-byte
2854 characters are strong R2L, so no reordering is needed. And
2855 bidi.c doesn't support unibyte buffers anyway. Also, don't
2856 reorder while we are loading loadup.el, since the tables of
2857 character properties needed for reordering are not yet
2861 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2864 /* If we are to reorder bidirectional text, init the bidi
2868 /* Note the paragraph direction that this buffer wants to
2870 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2872 it
->paragraph_embedding
= L2R
;
2873 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2875 it
->paragraph_embedding
= R2L
;
2877 it
->paragraph_embedding
= NEUTRAL_DIR
;
2878 bidi_unshelve_cache (NULL
, 0);
2879 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2883 /* Compute faces etc. */
2884 reseat (it
, it
->current
.pos
, 1);
2891 /* Initialize IT for the display of window W with window start POS. */
2894 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2896 struct glyph_row
*row
;
2897 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2899 row
= w
->desired_matrix
->rows
+ first_vpos
;
2900 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2901 it
->first_vpos
= first_vpos
;
2903 /* Don't reseat to previous visible line start if current start
2904 position is in a string or image. */
2905 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2907 int start_at_line_beg_p
;
2908 int first_y
= it
->current_y
;
2910 /* If window start is not at a line start, skip forward to POS to
2911 get the correct continuation lines width. */
2912 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2913 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2914 if (!start_at_line_beg_p
)
2918 reseat_at_previous_visible_line_start (it
);
2919 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2921 new_x
= it
->current_x
+ it
->pixel_width
;
2923 /* If lines are continued, this line may end in the middle
2924 of a multi-glyph character (e.g. a control character
2925 displayed as \003, or in the middle of an overlay
2926 string). In this case move_it_to above will not have
2927 taken us to the start of the continuation line but to the
2928 end of the continued line. */
2929 if (it
->current_x
> 0
2930 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2931 && (/* And glyph doesn't fit on the line. */
2932 new_x
> it
->last_visible_x
2933 /* Or it fits exactly and we're on a window
2935 || (new_x
== it
->last_visible_x
2936 && FRAME_WINDOW_P (it
->f
)
2937 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2938 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2939 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2941 if ((it
->current
.dpvec_index
>= 0
2942 || it
->current
.overlay_string_index
>= 0)
2943 /* If we are on a newline from a display vector or
2944 overlay string, then we are already at the end of
2945 a screen line; no need to go to the next line in
2946 that case, as this line is not really continued.
2947 (If we do go to the next line, C-e will not DTRT.) */
2950 set_iterator_to_next (it
, 1);
2951 move_it_in_display_line_to (it
, -1, -1, 0);
2954 it
->continuation_lines_width
+= it
->current_x
;
2956 /* If the character at POS is displayed via a display
2957 vector, move_it_to above stops at the final glyph of
2958 IT->dpvec. To make the caller redisplay that character
2959 again (a.k.a. start at POS), we need to reset the
2960 dpvec_index to the beginning of IT->dpvec. */
2961 else if (it
->current
.dpvec_index
>= 0)
2962 it
->current
.dpvec_index
= 0;
2964 /* We're starting a new display line, not affected by the
2965 height of the continued line, so clear the appropriate
2966 fields in the iterator structure. */
2967 it
->max_ascent
= it
->max_descent
= 0;
2968 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2970 it
->current_y
= first_y
;
2972 it
->current_x
= it
->hpos
= 0;
2978 /* Return 1 if POS is a position in ellipses displayed for invisible
2979 text. W is the window we display, for text property lookup. */
2982 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2984 Lisp_Object prop
, window
;
2986 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2988 /* If POS specifies a position in a display vector, this might
2989 be for an ellipsis displayed for invisible text. We won't
2990 get the iterator set up for delivering that ellipsis unless
2991 we make sure that it gets aware of the invisible text. */
2992 if (pos
->dpvec_index
>= 0
2993 && pos
->overlay_string_index
< 0
2994 && CHARPOS (pos
->string_pos
) < 0
2996 && (XSETWINDOW (window
, w
),
2997 prop
= Fget_char_property (make_number (charpos
),
2998 Qinvisible
, window
),
2999 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3001 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3003 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3010 /* Initialize IT for stepping through current_buffer in window W,
3011 starting at position POS that includes overlay string and display
3012 vector/ control character translation position information. Value
3013 is zero if there are overlay strings with newlines at POS. */
3016 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3018 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3019 int i
, overlay_strings_with_newlines
= 0;
3021 /* If POS specifies a position in a display vector, this might
3022 be for an ellipsis displayed for invisible text. We won't
3023 get the iterator set up for delivering that ellipsis unless
3024 we make sure that it gets aware of the invisible text. */
3025 if (in_ellipses_for_invisible_text_p (pos
, w
))
3031 /* Keep in mind: the call to reseat in init_iterator skips invisible
3032 text, so we might end up at a position different from POS. This
3033 is only a problem when POS is a row start after a newline and an
3034 overlay starts there with an after-string, and the overlay has an
3035 invisible property. Since we don't skip invisible text in
3036 display_line and elsewhere immediately after consuming the
3037 newline before the row start, such a POS will not be in a string,
3038 but the call to init_iterator below will move us to the
3040 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3042 /* This only scans the current chunk -- it should scan all chunks.
3043 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3044 to 16 in 22.1 to make this a lesser problem. */
3045 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3047 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3048 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3050 while (s
< e
&& *s
!= '\n')
3055 overlay_strings_with_newlines
= 1;
3060 /* If position is within an overlay string, set up IT to the right
3062 if (pos
->overlay_string_index
>= 0)
3066 /* If the first overlay string happens to have a `display'
3067 property for an image, the iterator will be set up for that
3068 image, and we have to undo that setup first before we can
3069 correct the overlay string index. */
3070 if (it
->method
== GET_FROM_IMAGE
)
3073 /* We already have the first chunk of overlay strings in
3074 IT->overlay_strings. Load more until the one for
3075 pos->overlay_string_index is in IT->overlay_strings. */
3076 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3078 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3079 it
->current
.overlay_string_index
= 0;
3082 load_overlay_strings (it
, 0);
3083 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3087 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3088 relative_index
= (it
->current
.overlay_string_index
3089 % OVERLAY_STRING_CHUNK_SIZE
);
3090 it
->string
= it
->overlay_strings
[relative_index
];
3091 eassert (STRINGP (it
->string
));
3092 it
->current
.string_pos
= pos
->string_pos
;
3093 it
->method
= GET_FROM_STRING
;
3094 it
->end_charpos
= SCHARS (it
->string
);
3095 /* Set up the bidi iterator for this overlay string. */
3098 it
->bidi_it
.string
.lstring
= it
->string
;
3099 it
->bidi_it
.string
.s
= NULL
;
3100 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3101 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3102 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3103 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3104 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3105 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3107 /* Synchronize the state of the bidi iterator with
3108 pos->string_pos. For any string position other than
3109 zero, this will be done automagically when we resume
3110 iteration over the string and get_visually_first_element
3111 is called. But if string_pos is zero, and the string is
3112 to be reordered for display, we need to resync manually,
3113 since it could be that the iteration state recorded in
3114 pos ended at string_pos of 0 moving backwards in string. */
3115 if (CHARPOS (pos
->string_pos
) == 0)
3117 get_visually_first_element (it
);
3118 if (IT_STRING_CHARPOS (*it
) != 0)
3121 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3122 bidi_move_to_visually_next (&it
->bidi_it
);
3123 } while (it
->bidi_it
.charpos
!= 0);
3125 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3126 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3130 if (CHARPOS (pos
->string_pos
) >= 0)
3132 /* Recorded position is not in an overlay string, but in another
3133 string. This can only be a string from a `display' property.
3134 IT should already be filled with that string. */
3135 it
->current
.string_pos
= pos
->string_pos
;
3136 eassert (STRINGP (it
->string
));
3138 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3139 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3142 /* Restore position in display vector translations, control
3143 character translations or ellipses. */
3144 if (pos
->dpvec_index
>= 0)
3146 if (it
->dpvec
== NULL
)
3147 get_next_display_element (it
);
3148 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3149 it
->current
.dpvec_index
= pos
->dpvec_index
;
3153 return !overlay_strings_with_newlines
;
3157 /* Initialize IT for stepping through current_buffer in window W
3158 starting at ROW->start. */
3161 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3163 init_from_display_pos (it
, w
, &row
->start
);
3164 it
->start
= row
->start
;
3165 it
->continuation_lines_width
= row
->continuation_lines_width
;
3170 /* Initialize IT for stepping through current_buffer in window W
3171 starting in the line following ROW, i.e. starting at ROW->end.
3172 Value is zero if there are overlay strings with newlines at ROW's
3176 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3180 if (init_from_display_pos (it
, w
, &row
->end
))
3182 if (row
->continued_p
)
3183 it
->continuation_lines_width
3184 = row
->continuation_lines_width
+ row
->pixel_width
;
3195 /***********************************************************************
3197 ***********************************************************************/
3199 /* Called when IT reaches IT->stop_charpos. Handle text property and
3200 overlay changes. Set IT->stop_charpos to the next position where
3204 handle_stop (struct it
*it
)
3206 enum prop_handled handled
;
3207 int handle_overlay_change_p
;
3211 it
->current
.dpvec_index
= -1;
3212 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3213 it
->ignore_overlay_strings_at_pos_p
= 0;
3216 /* Use face of preceding text for ellipsis (if invisible) */
3217 if (it
->selective_display_ellipsis_p
)
3218 it
->saved_face_id
= it
->face_id
;
3222 handled
= HANDLED_NORMALLY
;
3224 /* Call text property handlers. */
3225 for (p
= it_props
; p
->handler
; ++p
)
3227 handled
= p
->handler (it
);
3229 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3231 else if (handled
== HANDLED_RETURN
)
3233 /* We still want to show before and after strings from
3234 overlays even if the actual buffer text is replaced. */
3235 if (!handle_overlay_change_p
3237 /* Don't call get_overlay_strings_1 if we already
3238 have overlay strings loaded, because doing so
3239 will load them again and push the iterator state
3240 onto the stack one more time, which is not
3241 expected by the rest of the code that processes
3243 || (it
->current
.overlay_string_index
< 0
3244 ? !get_overlay_strings_1 (it
, 0, 0)
3248 setup_for_ellipsis (it
, 0);
3249 /* When handling a display spec, we might load an
3250 empty string. In that case, discard it here. We
3251 used to discard it in handle_single_display_spec,
3252 but that causes get_overlay_strings_1, above, to
3253 ignore overlay strings that we must check. */
3254 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3258 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3262 it
->ignore_overlay_strings_at_pos_p
= 1;
3263 it
->string_from_display_prop_p
= 0;
3264 it
->from_disp_prop_p
= 0;
3265 handle_overlay_change_p
= 0;
3267 handled
= HANDLED_RECOMPUTE_PROPS
;
3270 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3271 handle_overlay_change_p
= 0;
3274 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3276 /* Don't check for overlay strings below when set to deliver
3277 characters from a display vector. */
3278 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3279 handle_overlay_change_p
= 0;
3281 /* Handle overlay changes.
3282 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3283 if it finds overlays. */
3284 if (handle_overlay_change_p
)
3285 handled
= handle_overlay_change (it
);
3290 setup_for_ellipsis (it
, 0);
3294 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3296 /* Determine where to stop next. */
3297 if (handled
== HANDLED_NORMALLY
)
3298 compute_stop_pos (it
);
3302 /* Compute IT->stop_charpos from text property and overlay change
3303 information for IT's current position. */
3306 compute_stop_pos (struct it
*it
)
3308 register INTERVAL iv
, next_iv
;
3309 Lisp_Object object
, limit
, position
;
3310 ptrdiff_t charpos
, bytepos
;
3312 if (STRINGP (it
->string
))
3314 /* Strings are usually short, so don't limit the search for
3316 it
->stop_charpos
= it
->end_charpos
;
3317 object
= it
->string
;
3319 charpos
= IT_STRING_CHARPOS (*it
);
3320 bytepos
= IT_STRING_BYTEPOS (*it
);
3326 /* If end_charpos is out of range for some reason, such as a
3327 misbehaving display function, rationalize it (Bug#5984). */
3328 if (it
->end_charpos
> ZV
)
3329 it
->end_charpos
= ZV
;
3330 it
->stop_charpos
= it
->end_charpos
;
3332 /* If next overlay change is in front of the current stop pos
3333 (which is IT->end_charpos), stop there. Note: value of
3334 next_overlay_change is point-max if no overlay change
3336 charpos
= IT_CHARPOS (*it
);
3337 bytepos
= IT_BYTEPOS (*it
);
3338 pos
= next_overlay_change (charpos
);
3339 if (pos
< it
->stop_charpos
)
3340 it
->stop_charpos
= pos
;
3342 /* If showing the region, we have to stop at the region
3343 start or end because the face might change there. */
3344 if (it
->region_beg_charpos
> 0)
3346 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3347 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3348 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3349 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3352 /* Set up variables for computing the stop position from text
3353 property changes. */
3354 XSETBUFFER (object
, current_buffer
);
3355 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3358 /* Get the interval containing IT's position. Value is a null
3359 interval if there isn't such an interval. */
3360 position
= make_number (charpos
);
3361 iv
= validate_interval_range (object
, &position
, &position
, 0);
3364 Lisp_Object values_here
[LAST_PROP_IDX
];
3367 /* Get properties here. */
3368 for (p
= it_props
; p
->handler
; ++p
)
3369 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3371 /* Look for an interval following iv that has different
3373 for (next_iv
= next_interval (iv
);
3376 || XFASTINT (limit
) > next_iv
->position
));
3377 next_iv
= next_interval (next_iv
))
3379 for (p
= it_props
; p
->handler
; ++p
)
3381 Lisp_Object new_value
;
3383 new_value
= textget (next_iv
->plist
, *p
->name
);
3384 if (!EQ (values_here
[p
->idx
], new_value
))
3394 if (INTEGERP (limit
)
3395 && next_iv
->position
>= XFASTINT (limit
))
3396 /* No text property change up to limit. */
3397 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3399 /* Text properties change in next_iv. */
3400 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3404 if (it
->cmp_it
.id
< 0)
3406 ptrdiff_t stoppos
= it
->end_charpos
;
3408 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3410 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3411 stoppos
, it
->string
);
3414 eassert (STRINGP (it
->string
)
3415 || (it
->stop_charpos
>= BEGV
3416 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3420 /* Return the position of the next overlay change after POS in
3421 current_buffer. Value is point-max if no overlay change
3422 follows. This is like `next-overlay-change' but doesn't use
3426 next_overlay_change (ptrdiff_t pos
)
3428 ptrdiff_t i
, noverlays
;
3430 Lisp_Object
*overlays
;
3432 /* Get all overlays at the given position. */
3433 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3435 /* If any of these overlays ends before endpos,
3436 use its ending point instead. */
3437 for (i
= 0; i
< noverlays
; ++i
)
3442 oend
= OVERLAY_END (overlays
[i
]);
3443 oendpos
= OVERLAY_POSITION (oend
);
3444 endpos
= min (endpos
, oendpos
);
3450 /* How many characters forward to search for a display property or
3451 display string. Searching too far forward makes the bidi display
3452 sluggish, especially in small windows. */
3453 #define MAX_DISP_SCAN 250
3455 /* Return the character position of a display string at or after
3456 position specified by POSITION. If no display string exists at or
3457 after POSITION, return ZV. A display string is either an overlay
3458 with `display' property whose value is a string, or a `display'
3459 text property whose value is a string. STRING is data about the
3460 string to iterate; if STRING->lstring is nil, we are iterating a
3461 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3462 on a GUI frame. DISP_PROP is set to zero if we searched
3463 MAX_DISP_SCAN characters forward without finding any display
3464 strings, non-zero otherwise. It is set to 2 if the display string
3465 uses any kind of `(space ...)' spec that will produce a stretch of
3466 white space in the text area. */
3468 compute_display_string_pos (struct text_pos
*position
,
3469 struct bidi_string_data
*string
,
3470 int frame_window_p
, int *disp_prop
)
3472 /* OBJECT = nil means current buffer. */
3473 Lisp_Object object
=
3474 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3475 Lisp_Object pos
, spec
, limpos
;
3476 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3477 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3478 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3479 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3481 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3482 struct text_pos tpos
;
3488 /* We don't support display properties whose values are strings
3489 that have display string properties. */
3490 || string
->from_disp_str
3491 /* C strings cannot have display properties. */
3492 || (string
->s
&& !STRINGP (object
)))
3498 /* If the character at CHARPOS is where the display string begins,
3500 pos
= make_number (charpos
);
3501 if (STRINGP (object
))
3502 bufpos
= string
->bufpos
;
3506 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3508 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3511 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3519 /* Look forward for the first character with a `display' property
3520 that will replace the underlying text when displayed. */
3521 limpos
= make_number (lim
);
3523 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3524 CHARPOS (tpos
) = XFASTINT (pos
);
3525 if (CHARPOS (tpos
) >= lim
)
3530 if (STRINGP (object
))
3531 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3533 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3534 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3535 if (!STRINGP (object
))
3536 bufpos
= CHARPOS (tpos
);
3537 } while (NILP (spec
)
3538 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3539 bufpos
, frame_window_p
)));
3543 return CHARPOS (tpos
);
3546 /* Return the character position of the end of the display string that
3547 started at CHARPOS. If there's no display string at CHARPOS,
3548 return -1. A display string is either an overlay with `display'
3549 property whose value is a string or a `display' text property whose
3550 value is a string. */
3552 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3554 /* OBJECT = nil means current buffer. */
3555 Lisp_Object object
=
3556 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3557 Lisp_Object pos
= make_number (charpos
);
3559 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3561 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3564 /* It could happen that the display property or overlay was removed
3565 since we found it in compute_display_string_pos above. One way
3566 this can happen is if JIT font-lock was called (through
3567 handle_fontified_prop), and jit-lock-functions remove text
3568 properties or overlays from the portion of buffer that includes
3569 CHARPOS. Muse mode is known to do that, for example. In this
3570 case, we return -1 to the caller, to signal that no display
3571 string is actually present at CHARPOS. See bidi_fetch_char for
3572 how this is handled.
3574 An alternative would be to never look for display properties past
3575 it->stop_charpos. But neither compute_display_string_pos nor
3576 bidi_fetch_char that calls it know or care where the next
3578 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3581 /* Look forward for the first character where the `display' property
3583 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3585 return XFASTINT (pos
);
3590 /***********************************************************************
3592 ***********************************************************************/
3594 /* Handle changes in the `fontified' property of the current buffer by
3595 calling hook functions from Qfontification_functions to fontify
3598 static enum prop_handled
3599 handle_fontified_prop (struct it
*it
)
3601 Lisp_Object prop
, pos
;
3602 enum prop_handled handled
= HANDLED_NORMALLY
;
3604 if (!NILP (Vmemory_full
))
3607 /* Get the value of the `fontified' property at IT's current buffer
3608 position. (The `fontified' property doesn't have a special
3609 meaning in strings.) If the value is nil, call functions from
3610 Qfontification_functions. */
3611 if (!STRINGP (it
->string
)
3613 && !NILP (Vfontification_functions
)
3614 && !NILP (Vrun_hooks
)
3615 && (pos
= make_number (IT_CHARPOS (*it
)),
3616 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3617 /* Ignore the special cased nil value always present at EOB since
3618 no amount of fontifying will be able to change it. */
3619 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3621 ptrdiff_t count
= SPECPDL_INDEX ();
3623 struct buffer
*obuf
= current_buffer
;
3624 int begv
= BEGV
, zv
= ZV
;
3625 int old_clip_changed
= current_buffer
->clip_changed
;
3627 val
= Vfontification_functions
;
3628 specbind (Qfontification_functions
, Qnil
);
3630 eassert (it
->end_charpos
== ZV
);
3632 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3633 safe_call1 (val
, pos
);
3636 Lisp_Object fns
, fn
;
3637 struct gcpro gcpro1
, gcpro2
;
3642 for (; CONSP (val
); val
= XCDR (val
))
3648 /* A value of t indicates this hook has a local
3649 binding; it means to run the global binding too.
3650 In a global value, t should not occur. If it
3651 does, we must ignore it to avoid an endless
3653 for (fns
= Fdefault_value (Qfontification_functions
);
3659 safe_call1 (fn
, pos
);
3663 safe_call1 (fn
, pos
);
3669 unbind_to (count
, Qnil
);
3671 /* Fontification functions routinely call `save-restriction'.
3672 Normally, this tags clip_changed, which can confuse redisplay
3673 (see discussion in Bug#6671). Since we don't perform any
3674 special handling of fontification changes in the case where
3675 `save-restriction' isn't called, there's no point doing so in
3676 this case either. So, if the buffer's restrictions are
3677 actually left unchanged, reset clip_changed. */
3678 if (obuf
== current_buffer
)
3680 if (begv
== BEGV
&& zv
== ZV
)
3681 current_buffer
->clip_changed
= old_clip_changed
;
3683 /* There isn't much we can reasonably do to protect against
3684 misbehaving fontification, but here's a fig leaf. */
3685 else if (BUFFER_LIVE_P (obuf
))
3686 set_buffer_internal_1 (obuf
);
3688 /* The fontification code may have added/removed text.
3689 It could do even a lot worse, but let's at least protect against
3690 the most obvious case where only the text past `pos' gets changed',
3691 as is/was done in grep.el where some escapes sequences are turned
3692 into face properties (bug#7876). */
3693 it
->end_charpos
= ZV
;
3695 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3696 something. This avoids an endless loop if they failed to
3697 fontify the text for which reason ever. */
3698 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3699 handled
= HANDLED_RECOMPUTE_PROPS
;
3707 /***********************************************************************
3709 ***********************************************************************/
3711 /* Set up iterator IT from face properties at its current position.
3712 Called from handle_stop. */
3714 static enum prop_handled
3715 handle_face_prop (struct it
*it
)
3718 ptrdiff_t next_stop
;
3720 if (!STRINGP (it
->string
))
3723 = face_at_buffer_position (it
->w
,
3725 it
->region_beg_charpos
,
3726 it
->region_end_charpos
,
3729 + TEXT_PROP_DISTANCE_LIMIT
),
3730 0, it
->base_face_id
);
3732 /* Is this a start of a run of characters with box face?
3733 Caveat: this can be called for a freshly initialized
3734 iterator; face_id is -1 in this case. We know that the new
3735 face will not change until limit, i.e. if the new face has a
3736 box, all characters up to limit will have one. But, as
3737 usual, we don't know whether limit is really the end. */
3738 if (new_face_id
!= it
->face_id
)
3740 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3741 /* If it->face_id is -1, old_face below will be NULL, see
3742 the definition of FACE_FROM_ID. This will happen if this
3743 is the initial call that gets the face. */
3744 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3746 /* If the value of face_id of the iterator is -1, we have to
3747 look in front of IT's position and see whether there is a
3748 face there that's different from new_face_id. */
3749 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3751 int prev_face_id
= face_before_it_pos (it
);
3753 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3756 /* If the new face has a box, but the old face does not,
3757 this is the start of a run of characters with box face,
3758 i.e. this character has a shadow on the left side. */
3759 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3760 && (old_face
== NULL
|| !old_face
->box
));
3761 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3769 Lisp_Object from_overlay
3770 = (it
->current
.overlay_string_index
>= 0
3771 ? it
->string_overlays
[it
->current
.overlay_string_index
3772 % OVERLAY_STRING_CHUNK_SIZE
]
3775 /* See if we got to this string directly or indirectly from
3776 an overlay property. That includes the before-string or
3777 after-string of an overlay, strings in display properties
3778 provided by an overlay, their text properties, etc.
3780 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3781 if (! NILP (from_overlay
))
3782 for (i
= it
->sp
- 1; i
>= 0; i
--)
3784 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3786 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3787 % OVERLAY_STRING_CHUNK_SIZE
];
3788 else if (! NILP (it
->stack
[i
].from_overlay
))
3789 from_overlay
= it
->stack
[i
].from_overlay
;
3791 if (!NILP (from_overlay
))
3795 if (! NILP (from_overlay
))
3797 bufpos
= IT_CHARPOS (*it
);
3798 /* For a string from an overlay, the base face depends
3799 only on text properties and ignores overlays. */
3801 = face_for_overlay_string (it
->w
,
3803 it
->region_beg_charpos
,
3804 it
->region_end_charpos
,
3807 + TEXT_PROP_DISTANCE_LIMIT
),
3815 /* For strings from a `display' property, use the face at
3816 IT's current buffer position as the base face to merge
3817 with, so that overlay strings appear in the same face as
3818 surrounding text, unless they specify their own
3820 base_face_id
= it
->string_from_prefix_prop_p
3822 : underlying_face_id (it
);
3825 new_face_id
= face_at_string_position (it
->w
,
3827 IT_STRING_CHARPOS (*it
),
3829 it
->region_beg_charpos
,
3830 it
->region_end_charpos
,
3834 /* Is this a start of a run of characters with box? Caveat:
3835 this can be called for a freshly allocated iterator; face_id
3836 is -1 is this case. We know that the new face will not
3837 change until the next check pos, i.e. if the new face has a
3838 box, all characters up to that position will have a
3839 box. But, as usual, we don't know whether that position
3840 is really the end. */
3841 if (new_face_id
!= it
->face_id
)
3843 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3844 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3846 /* If new face has a box but old face hasn't, this is the
3847 start of a run of characters with box, i.e. it has a
3848 shadow on the left side. */
3849 it
->start_of_box_run_p
3850 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3851 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3855 it
->face_id
= new_face_id
;
3856 return HANDLED_NORMALLY
;
3860 /* Return the ID of the face ``underlying'' IT's current position,
3861 which is in a string. If the iterator is associated with a
3862 buffer, return the face at IT's current buffer position.
3863 Otherwise, use the iterator's base_face_id. */
3866 underlying_face_id (struct it
*it
)
3868 int face_id
= it
->base_face_id
, i
;
3870 eassert (STRINGP (it
->string
));
3872 for (i
= it
->sp
- 1; i
>= 0; --i
)
3873 if (NILP (it
->stack
[i
].string
))
3874 face_id
= it
->stack
[i
].face_id
;
3880 /* Compute the face one character before or after the current position
3881 of IT, in the visual order. BEFORE_P non-zero means get the face
3882 in front (to the left in L2R paragraphs, to the right in R2L
3883 paragraphs) of IT's screen position. Value is the ID of the face. */
3886 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3889 ptrdiff_t next_check_charpos
;
3891 void *it_copy_data
= NULL
;
3893 eassert (it
->s
== NULL
);
3895 if (STRINGP (it
->string
))
3897 ptrdiff_t bufpos
, charpos
;
3900 /* No face change past the end of the string (for the case
3901 we are padding with spaces). No face change before the
3903 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3904 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3909 /* Set charpos to the position before or after IT's current
3910 position, in the logical order, which in the non-bidi
3911 case is the same as the visual order. */
3913 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3914 else if (it
->what
== IT_COMPOSITION
)
3915 /* For composition, we must check the character after the
3917 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3919 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3925 /* With bidi iteration, the character before the current
3926 in the visual order cannot be found by simple
3927 iteration, because "reverse" reordering is not
3928 supported. Instead, we need to use the move_it_*
3929 family of functions. */
3930 /* Ignore face changes before the first visible
3931 character on this display line. */
3932 if (it
->current_x
<= it
->first_visible_x
)
3934 SAVE_IT (it_copy
, *it
, it_copy_data
);
3935 /* Implementation note: Since move_it_in_display_line
3936 works in the iterator geometry, and thinks the first
3937 character is always the leftmost, even in R2L lines,
3938 we don't need to distinguish between the R2L and L2R
3940 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3941 it_copy
.current_x
- 1, MOVE_TO_X
);
3942 charpos
= IT_STRING_CHARPOS (it_copy
);
3943 RESTORE_IT (it
, it
, it_copy_data
);
3947 /* Set charpos to the string position of the character
3948 that comes after IT's current position in the visual
3950 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3954 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3956 charpos
= it_copy
.bidi_it
.charpos
;
3959 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3961 if (it
->current
.overlay_string_index
>= 0)
3962 bufpos
= IT_CHARPOS (*it
);
3966 base_face_id
= underlying_face_id (it
);
3968 /* Get the face for ASCII, or unibyte. */
3969 face_id
= face_at_string_position (it
->w
,
3973 it
->region_beg_charpos
,
3974 it
->region_end_charpos
,
3975 &next_check_charpos
,
3978 /* Correct the face for charsets different from ASCII. Do it
3979 for the multibyte case only. The face returned above is
3980 suitable for unibyte text if IT->string is unibyte. */
3981 if (STRING_MULTIBYTE (it
->string
))
3983 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3984 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3986 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3988 c
= string_char_and_length (p
, &len
);
3989 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3994 struct text_pos pos
;
3996 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3997 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4000 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4001 pos
= it
->current
.pos
;
4006 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4009 if (it
->what
== IT_COMPOSITION
)
4011 /* For composition, we must check the position after
4013 pos
.charpos
+= it
->cmp_it
.nchars
;
4014 pos
.bytepos
+= it
->len
;
4017 INC_TEXT_POS (pos
, it
->multibyte_p
);
4024 /* With bidi iteration, the character before the current
4025 in the visual order cannot be found by simple
4026 iteration, because "reverse" reordering is not
4027 supported. Instead, we need to use the move_it_*
4028 family of functions. */
4029 /* Ignore face changes before the first visible
4030 character on this display line. */
4031 if (it
->current_x
<= it
->first_visible_x
)
4033 SAVE_IT (it_copy
, *it
, it_copy_data
);
4034 /* Implementation note: Since move_it_in_display_line
4035 works in the iterator geometry, and thinks the first
4036 character is always the leftmost, even in R2L lines,
4037 we don't need to distinguish between the R2L and L2R
4039 move_it_in_display_line (&it_copy
, ZV
,
4040 it_copy
.current_x
- 1, MOVE_TO_X
);
4041 pos
= it_copy
.current
.pos
;
4042 RESTORE_IT (it
, it
, it_copy_data
);
4046 /* Set charpos to the buffer position of the character
4047 that comes after IT's current position in the visual
4049 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4053 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4056 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4059 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4061 /* Determine face for CHARSET_ASCII, or unibyte. */
4062 face_id
= face_at_buffer_position (it
->w
,
4064 it
->region_beg_charpos
,
4065 it
->region_end_charpos
,
4066 &next_check_charpos
,
4069 /* Correct the face for charsets different from ASCII. Do it
4070 for the multibyte case only. The face returned above is
4071 suitable for unibyte text if current_buffer is unibyte. */
4072 if (it
->multibyte_p
)
4074 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4075 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4076 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4085 /***********************************************************************
4087 ***********************************************************************/
4089 /* Set up iterator IT from invisible properties at its current
4090 position. Called from handle_stop. */
4092 static enum prop_handled
4093 handle_invisible_prop (struct it
*it
)
4095 enum prop_handled handled
= HANDLED_NORMALLY
;
4099 if (STRINGP (it
->string
))
4101 Lisp_Object end_charpos
, limit
, charpos
;
4103 /* Get the value of the invisible text property at the
4104 current position. Value will be nil if there is no such
4106 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4107 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4108 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4110 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4112 /* Record whether we have to display an ellipsis for the
4114 int display_ellipsis_p
= (invis_p
== 2);
4115 ptrdiff_t len
, endpos
;
4117 handled
= HANDLED_RECOMPUTE_PROPS
;
4119 /* Get the position at which the next visible text can be
4120 found in IT->string, if any. */
4121 endpos
= len
= SCHARS (it
->string
);
4122 XSETINT (limit
, len
);
4125 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4127 if (INTEGERP (end_charpos
))
4129 endpos
= XFASTINT (end_charpos
);
4130 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4131 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4133 display_ellipsis_p
= 1;
4136 while (invis_p
&& endpos
< len
);
4138 if (display_ellipsis_p
)
4143 /* Text at END_CHARPOS is visible. Move IT there. */
4144 struct text_pos old
;
4147 old
= it
->current
.string_pos
;
4148 oldpos
= CHARPOS (old
);
4151 if (it
->bidi_it
.first_elt
4152 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4153 bidi_paragraph_init (it
->paragraph_embedding
,
4155 /* Bidi-iterate out of the invisible text. */
4158 bidi_move_to_visually_next (&it
->bidi_it
);
4160 while (oldpos
<= it
->bidi_it
.charpos
4161 && it
->bidi_it
.charpos
< endpos
);
4163 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4164 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4165 if (IT_CHARPOS (*it
) >= endpos
)
4166 it
->prev_stop
= endpos
;
4170 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4171 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4176 /* The rest of the string is invisible. If this is an
4177 overlay string, proceed with the next overlay string
4178 or whatever comes and return a character from there. */
4179 if (it
->current
.overlay_string_index
>= 0
4180 && !display_ellipsis_p
)
4182 next_overlay_string (it
);
4183 /* Don't check for overlay strings when we just
4184 finished processing them. */
4185 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4189 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4190 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4197 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4198 Lisp_Object pos
, overlay
;
4200 /* First of all, is there invisible text at this position? */
4201 tem
= start_charpos
= IT_CHARPOS (*it
);
4202 pos
= make_number (tem
);
4203 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4205 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4207 /* If we are on invisible text, skip over it. */
4208 if (invis_p
&& start_charpos
< it
->end_charpos
)
4210 /* Record whether we have to display an ellipsis for the
4212 int display_ellipsis_p
= invis_p
== 2;
4214 handled
= HANDLED_RECOMPUTE_PROPS
;
4216 /* Loop skipping over invisible text. The loop is left at
4217 ZV or with IT on the first char being visible again. */
4220 /* Try to skip some invisible text. Return value is the
4221 position reached which can be equal to where we start
4222 if there is nothing invisible there. This skips both
4223 over invisible text properties and overlays with
4224 invisible property. */
4225 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4227 /* If we skipped nothing at all we weren't at invisible
4228 text in the first place. If everything to the end of
4229 the buffer was skipped, end the loop. */
4230 if (newpos
== tem
|| newpos
>= ZV
)
4234 /* We skipped some characters but not necessarily
4235 all there are. Check if we ended up on visible
4236 text. Fget_char_property returns the property of
4237 the char before the given position, i.e. if we
4238 get invis_p = 0, this means that the char at
4239 newpos is visible. */
4240 pos
= make_number (newpos
);
4241 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4242 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4245 /* If we ended up on invisible text, proceed to
4246 skip starting with next_stop. */
4250 /* If there are adjacent invisible texts, don't lose the
4251 second one's ellipsis. */
4253 display_ellipsis_p
= 1;
4257 /* The position newpos is now either ZV or on visible text. */
4260 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4262 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4264 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4266 /* If the invisible text ends on a newline or on a
4267 character after a newline, we can avoid the costly,
4268 character by character, bidi iteration to NEWPOS, and
4269 instead simply reseat the iterator there. That's
4270 because all bidi reordering information is tossed at
4271 the newline. This is a big win for modes that hide
4272 complete lines, like Outline, Org, etc. */
4273 if (on_newline
|| after_newline
)
4275 struct text_pos tpos
;
4276 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4278 SET_TEXT_POS (tpos
, newpos
, bpos
);
4279 reseat_1 (it
, tpos
, 0);
4280 /* If we reseat on a newline/ZV, we need to prep the
4281 bidi iterator for advancing to the next character
4282 after the newline/EOB, keeping the current paragraph
4283 direction (so that PRODUCE_GLYPHS does TRT wrt
4284 prepending/appending glyphs to a glyph row). */
4287 it
->bidi_it
.first_elt
= 0;
4288 it
->bidi_it
.paragraph_dir
= pdir
;
4289 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4290 it
->bidi_it
.nchars
= 1;
4291 it
->bidi_it
.ch_len
= 1;
4294 else /* Must use the slow method. */
4296 /* With bidi iteration, the region of invisible text
4297 could start and/or end in the middle of a
4298 non-base embedding level. Therefore, we need to
4299 skip invisible text using the bidi iterator,
4300 starting at IT's current position, until we find
4301 ourselves outside of the invisible text.
4302 Skipping invisible text _after_ bidi iteration
4303 avoids affecting the visual order of the
4304 displayed text when invisible properties are
4305 added or removed. */
4306 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4308 /* If we were `reseat'ed to a new paragraph,
4309 determine the paragraph base direction. We
4310 need to do it now because
4311 next_element_from_buffer may not have a
4312 chance to do it, if we are going to skip any
4313 text at the beginning, which resets the
4315 bidi_paragraph_init (it
->paragraph_embedding
,
4320 bidi_move_to_visually_next (&it
->bidi_it
);
4322 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4323 && it
->bidi_it
.charpos
< newpos
);
4324 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4325 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4326 /* If we overstepped NEWPOS, record its position in
4327 the iterator, so that we skip invisible text if
4328 later the bidi iteration lands us in the
4329 invisible region again. */
4330 if (IT_CHARPOS (*it
) >= newpos
)
4331 it
->prev_stop
= newpos
;
4336 IT_CHARPOS (*it
) = newpos
;
4337 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4340 /* If there are before-strings at the start of invisible
4341 text, and the text is invisible because of a text
4342 property, arrange to show before-strings because 20.x did
4343 it that way. (If the text is invisible because of an
4344 overlay property instead of a text property, this is
4345 already handled in the overlay code.) */
4347 && get_overlay_strings (it
, it
->stop_charpos
))
4349 handled
= HANDLED_RECOMPUTE_PROPS
;
4350 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4352 else if (display_ellipsis_p
)
4354 /* Make sure that the glyphs of the ellipsis will get
4355 correct `charpos' values. If we would not update
4356 it->position here, the glyphs would belong to the
4357 last visible character _before_ the invisible
4358 text, which confuses `set_cursor_from_row'.
4360 We use the last invisible position instead of the
4361 first because this way the cursor is always drawn on
4362 the first "." of the ellipsis, whenever PT is inside
4363 the invisible text. Otherwise the cursor would be
4364 placed _after_ the ellipsis when the point is after the
4365 first invisible character. */
4366 if (!STRINGP (it
->object
))
4368 it
->position
.charpos
= newpos
- 1;
4369 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4372 /* Let the ellipsis display before
4373 considering any properties of the following char.
4374 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4375 handled
= HANDLED_RETURN
;
4384 /* Make iterator IT return `...' next.
4385 Replaces LEN characters from buffer. */
4388 setup_for_ellipsis (struct it
*it
, int len
)
4390 /* Use the display table definition for `...'. Invalid glyphs
4391 will be handled by the method returning elements from dpvec. */
4392 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4394 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4395 it
->dpvec
= v
->contents
;
4396 it
->dpend
= v
->contents
+ v
->header
.size
;
4400 /* Default `...'. */
4401 it
->dpvec
= default_invis_vector
;
4402 it
->dpend
= default_invis_vector
+ 3;
4405 it
->dpvec_char_len
= len
;
4406 it
->current
.dpvec_index
= 0;
4407 it
->dpvec_face_id
= -1;
4409 /* Remember the current face id in case glyphs specify faces.
4410 IT's face is restored in set_iterator_to_next.
4411 saved_face_id was set to preceding char's face in handle_stop. */
4412 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4413 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4415 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4421 /***********************************************************************
4423 ***********************************************************************/
4425 /* Set up iterator IT from `display' property at its current position.
4426 Called from handle_stop.
4427 We return HANDLED_RETURN if some part of the display property
4428 overrides the display of the buffer text itself.
4429 Otherwise we return HANDLED_NORMALLY. */
4431 static enum prop_handled
4432 handle_display_prop (struct it
*it
)
4434 Lisp_Object propval
, object
, overlay
;
4435 struct text_pos
*position
;
4437 /* Nonzero if some property replaces the display of the text itself. */
4438 int display_replaced_p
= 0;
4440 if (STRINGP (it
->string
))
4442 object
= it
->string
;
4443 position
= &it
->current
.string_pos
;
4444 bufpos
= CHARPOS (it
->current
.pos
);
4448 XSETWINDOW (object
, it
->w
);
4449 position
= &it
->current
.pos
;
4450 bufpos
= CHARPOS (*position
);
4453 /* Reset those iterator values set from display property values. */
4454 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4455 it
->space_width
= Qnil
;
4456 it
->font_height
= Qnil
;
4459 /* We don't support recursive `display' properties, i.e. string
4460 values that have a string `display' property, that have a string
4461 `display' property etc. */
4462 if (!it
->string_from_display_prop_p
)
4463 it
->area
= TEXT_AREA
;
4465 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4466 Qdisplay
, object
, &overlay
);
4468 return HANDLED_NORMALLY
;
4469 /* Now OVERLAY is the overlay that gave us this property, or nil
4470 if it was a text property. */
4472 if (!STRINGP (it
->string
))
4473 object
= it
->w
->contents
;
4475 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4477 FRAME_WINDOW_P (it
->f
));
4479 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4482 /* Subroutine of handle_display_prop. Returns non-zero if the display
4483 specification in SPEC is a replacing specification, i.e. it would
4484 replace the text covered by `display' property with something else,
4485 such as an image or a display string. If SPEC includes any kind or
4486 `(space ...) specification, the value is 2; this is used by
4487 compute_display_string_pos, which see.
4489 See handle_single_display_spec for documentation of arguments.
4490 frame_window_p is non-zero if the window being redisplayed is on a
4491 GUI frame; this argument is used only if IT is NULL, see below.
4493 IT can be NULL, if this is called by the bidi reordering code
4494 through compute_display_string_pos, which see. In that case, this
4495 function only examines SPEC, but does not otherwise "handle" it, in
4496 the sense that it doesn't set up members of IT from the display
4499 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4500 Lisp_Object overlay
, struct text_pos
*position
,
4501 ptrdiff_t bufpos
, int frame_window_p
)
4503 int replacing_p
= 0;
4507 /* Simple specifications. */
4508 && !EQ (XCAR (spec
), Qimage
)
4509 && !EQ (XCAR (spec
), Qspace
)
4510 && !EQ (XCAR (spec
), Qwhen
)
4511 && !EQ (XCAR (spec
), Qslice
)
4512 && !EQ (XCAR (spec
), Qspace_width
)
4513 && !EQ (XCAR (spec
), Qheight
)
4514 && !EQ (XCAR (spec
), Qraise
)
4515 /* Marginal area specifications. */
4516 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4517 && !EQ (XCAR (spec
), Qleft_fringe
)
4518 && !EQ (XCAR (spec
), Qright_fringe
)
4519 && !NILP (XCAR (spec
)))
4521 for (; CONSP (spec
); spec
= XCDR (spec
))
4523 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4524 overlay
, position
, bufpos
,
4525 replacing_p
, frame_window_p
)))
4528 /* If some text in a string is replaced, `position' no
4529 longer points to the position of `object'. */
4530 if (!it
|| STRINGP (object
))
4535 else if (VECTORP (spec
))
4538 for (i
= 0; i
< ASIZE (spec
); ++i
)
4539 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4540 overlay
, position
, bufpos
,
4541 replacing_p
, frame_window_p
)))
4544 /* If some text in a string is replaced, `position' no
4545 longer points to the position of `object'. */
4546 if (!it
|| STRINGP (object
))
4552 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4553 position
, bufpos
, 0,
4561 /* Value is the position of the end of the `display' property starting
4562 at START_POS in OBJECT. */
4564 static struct text_pos
4565 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4568 struct text_pos end_pos
;
4570 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4571 Qdisplay
, object
, Qnil
);
4572 CHARPOS (end_pos
) = XFASTINT (end
);
4573 if (STRINGP (object
))
4574 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4576 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4582 /* Set up IT from a single `display' property specification SPEC. OBJECT
4583 is the object in which the `display' property was found. *POSITION
4584 is the position in OBJECT at which the `display' property was found.
4585 BUFPOS is the buffer position of OBJECT (different from POSITION if
4586 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4587 previously saw a display specification which already replaced text
4588 display with something else, for example an image; we ignore such
4589 properties after the first one has been processed.
4591 OVERLAY is the overlay this `display' property came from,
4592 or nil if it was a text property.
4594 If SPEC is a `space' or `image' specification, and in some other
4595 cases too, set *POSITION to the position where the `display'
4598 If IT is NULL, only examine the property specification in SPEC, but
4599 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4600 is intended to be displayed in a window on a GUI frame.
4602 Value is non-zero if something was found which replaces the display
4603 of buffer or string text. */
4606 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4607 Lisp_Object overlay
, struct text_pos
*position
,
4608 ptrdiff_t bufpos
, int display_replaced_p
,
4612 Lisp_Object location
, value
;
4613 struct text_pos start_pos
= *position
;
4616 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4617 If the result is non-nil, use VALUE instead of SPEC. */
4619 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4628 if (!NILP (form
) && !EQ (form
, Qt
))
4630 ptrdiff_t count
= SPECPDL_INDEX ();
4631 struct gcpro gcpro1
;
4633 /* Bind `object' to the object having the `display' property, a
4634 buffer or string. Bind `position' to the position in the
4635 object where the property was found, and `buffer-position'
4636 to the current position in the buffer. */
4639 XSETBUFFER (object
, current_buffer
);
4640 specbind (Qobject
, object
);
4641 specbind (Qposition
, make_number (CHARPOS (*position
)));
4642 specbind (Qbuffer_position
, make_number (bufpos
));
4644 form
= safe_eval (form
);
4646 unbind_to (count
, Qnil
);
4652 /* Handle `(height HEIGHT)' specifications. */
4654 && EQ (XCAR (spec
), Qheight
)
4655 && CONSP (XCDR (spec
)))
4659 if (!FRAME_WINDOW_P (it
->f
))
4662 it
->font_height
= XCAR (XCDR (spec
));
4663 if (!NILP (it
->font_height
))
4665 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4666 int new_height
= -1;
4668 if (CONSP (it
->font_height
)
4669 && (EQ (XCAR (it
->font_height
), Qplus
)
4670 || EQ (XCAR (it
->font_height
), Qminus
))
4671 && CONSP (XCDR (it
->font_height
))
4672 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4674 /* `(+ N)' or `(- N)' where N is an integer. */
4675 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4676 if (EQ (XCAR (it
->font_height
), Qplus
))
4678 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4680 else if (FUNCTIONP (it
->font_height
))
4682 /* Call function with current height as argument.
4683 Value is the new height. */
4685 height
= safe_call1 (it
->font_height
,
4686 face
->lface
[LFACE_HEIGHT_INDEX
]);
4687 if (NUMBERP (height
))
4688 new_height
= XFLOATINT (height
);
4690 else if (NUMBERP (it
->font_height
))
4692 /* Value is a multiple of the canonical char height. */
4695 f
= FACE_FROM_ID (it
->f
,
4696 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4697 new_height
= (XFLOATINT (it
->font_height
)
4698 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4702 /* Evaluate IT->font_height with `height' bound to the
4703 current specified height to get the new height. */
4704 ptrdiff_t count
= SPECPDL_INDEX ();
4706 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4707 value
= safe_eval (it
->font_height
);
4708 unbind_to (count
, Qnil
);
4710 if (NUMBERP (value
))
4711 new_height
= XFLOATINT (value
);
4715 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4722 /* Handle `(space-width WIDTH)'. */
4724 && EQ (XCAR (spec
), Qspace_width
)
4725 && CONSP (XCDR (spec
)))
4729 if (!FRAME_WINDOW_P (it
->f
))
4732 value
= XCAR (XCDR (spec
));
4733 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4734 it
->space_width
= value
;
4740 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4742 && EQ (XCAR (spec
), Qslice
))
4748 if (!FRAME_WINDOW_P (it
->f
))
4751 if (tem
= XCDR (spec
), CONSP (tem
))
4753 it
->slice
.x
= XCAR (tem
);
4754 if (tem
= XCDR (tem
), CONSP (tem
))
4756 it
->slice
.y
= XCAR (tem
);
4757 if (tem
= XCDR (tem
), CONSP (tem
))
4759 it
->slice
.width
= XCAR (tem
);
4760 if (tem
= XCDR (tem
), CONSP (tem
))
4761 it
->slice
.height
= XCAR (tem
);
4770 /* Handle `(raise FACTOR)'. */
4772 && EQ (XCAR (spec
), Qraise
)
4773 && CONSP (XCDR (spec
)))
4777 if (!FRAME_WINDOW_P (it
->f
))
4780 #ifdef HAVE_WINDOW_SYSTEM
4781 value
= XCAR (XCDR (spec
));
4782 if (NUMBERP (value
))
4784 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4785 it
->voffset
= - (XFLOATINT (value
)
4786 * (FONT_HEIGHT (face
->font
)));
4788 #endif /* HAVE_WINDOW_SYSTEM */
4794 /* Don't handle the other kinds of display specifications
4795 inside a string that we got from a `display' property. */
4796 if (it
&& it
->string_from_display_prop_p
)
4799 /* Characters having this form of property are not displayed, so
4800 we have to find the end of the property. */
4803 start_pos
= *position
;
4804 *position
= display_prop_end (it
, object
, start_pos
);
4808 /* Stop the scan at that end position--we assume that all
4809 text properties change there. */
4811 it
->stop_charpos
= position
->charpos
;
4813 /* Handle `(left-fringe BITMAP [FACE])'
4814 and `(right-fringe BITMAP [FACE])'. */
4816 && (EQ (XCAR (spec
), Qleft_fringe
)
4817 || EQ (XCAR (spec
), Qright_fringe
))
4818 && CONSP (XCDR (spec
)))
4824 if (!FRAME_WINDOW_P (it
->f
))
4825 /* If we return here, POSITION has been advanced
4826 across the text with this property. */
4828 /* Synchronize the bidi iterator with POSITION. This is
4829 needed because we are not going to push the iterator
4830 on behalf of this display property, so there will be
4831 no pop_it call to do this synchronization for us. */
4834 it
->position
= *position
;
4835 iterate_out_of_display_property (it
);
4836 *position
= it
->position
;
4841 else if (!frame_window_p
)
4844 #ifdef HAVE_WINDOW_SYSTEM
4845 value
= XCAR (XCDR (spec
));
4846 if (!SYMBOLP (value
)
4847 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4848 /* If we return here, POSITION has been advanced
4849 across the text with this property. */
4851 if (it
&& it
->bidi_p
)
4853 it
->position
= *position
;
4854 iterate_out_of_display_property (it
);
4855 *position
= it
->position
;
4862 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4864 if (CONSP (XCDR (XCDR (spec
))))
4866 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4867 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4873 /* Save current settings of IT so that we can restore them
4874 when we are finished with the glyph property value. */
4875 push_it (it
, position
);
4877 it
->area
= TEXT_AREA
;
4878 it
->what
= IT_IMAGE
;
4879 it
->image_id
= -1; /* no image */
4880 it
->position
= start_pos
;
4881 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4882 it
->method
= GET_FROM_IMAGE
;
4883 it
->from_overlay
= Qnil
;
4884 it
->face_id
= face_id
;
4885 it
->from_disp_prop_p
= 1;
4887 /* Say that we haven't consumed the characters with
4888 `display' property yet. The call to pop_it in
4889 set_iterator_to_next will clean this up. */
4890 *position
= start_pos
;
4892 if (EQ (XCAR (spec
), Qleft_fringe
))
4894 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4895 it
->left_user_fringe_face_id
= face_id
;
4899 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4900 it
->right_user_fringe_face_id
= face_id
;
4903 #endif /* HAVE_WINDOW_SYSTEM */
4907 /* Prepare to handle `((margin left-margin) ...)',
4908 `((margin right-margin) ...)' and `((margin nil) ...)'
4909 prefixes for display specifications. */
4910 location
= Qunbound
;
4911 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4915 value
= XCDR (spec
);
4917 value
= XCAR (value
);
4920 if (EQ (XCAR (tem
), Qmargin
)
4921 && (tem
= XCDR (tem
),
4922 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4924 || EQ (tem
, Qleft_margin
)
4925 || EQ (tem
, Qright_margin
))))
4929 if (EQ (location
, Qunbound
))
4935 /* After this point, VALUE is the property after any
4936 margin prefix has been stripped. It must be a string,
4937 an image specification, or `(space ...)'.
4939 LOCATION specifies where to display: `left-margin',
4940 `right-margin' or nil. */
4942 valid_p
= (STRINGP (value
)
4943 #ifdef HAVE_WINDOW_SYSTEM
4944 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4945 && valid_image_p (value
))
4946 #endif /* not HAVE_WINDOW_SYSTEM */
4947 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4949 if (valid_p
&& !display_replaced_p
)
4955 /* Callers need to know whether the display spec is any kind
4956 of `(space ...)' spec that is about to affect text-area
4958 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4963 /* Save current settings of IT so that we can restore them
4964 when we are finished with the glyph property value. */
4965 push_it (it
, position
);
4966 it
->from_overlay
= overlay
;
4967 it
->from_disp_prop_p
= 1;
4969 if (NILP (location
))
4970 it
->area
= TEXT_AREA
;
4971 else if (EQ (location
, Qleft_margin
))
4972 it
->area
= LEFT_MARGIN_AREA
;
4974 it
->area
= RIGHT_MARGIN_AREA
;
4976 if (STRINGP (value
))
4979 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4980 it
->current
.overlay_string_index
= -1;
4981 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4982 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4983 it
->method
= GET_FROM_STRING
;
4984 it
->stop_charpos
= 0;
4986 it
->base_level_stop
= 0;
4987 it
->string_from_display_prop_p
= 1;
4988 /* Say that we haven't consumed the characters with
4989 `display' property yet. The call to pop_it in
4990 set_iterator_to_next will clean this up. */
4991 if (BUFFERP (object
))
4992 *position
= start_pos
;
4994 /* Force paragraph direction to be that of the parent
4995 object. If the parent object's paragraph direction is
4996 not yet determined, default to L2R. */
4997 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4998 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5000 it
->paragraph_embedding
= L2R
;
5002 /* Set up the bidi iterator for this display string. */
5005 it
->bidi_it
.string
.lstring
= it
->string
;
5006 it
->bidi_it
.string
.s
= NULL
;
5007 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5008 it
->bidi_it
.string
.bufpos
= bufpos
;
5009 it
->bidi_it
.string
.from_disp_str
= 1;
5010 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5011 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5014 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5016 it
->method
= GET_FROM_STRETCH
;
5018 *position
= it
->position
= start_pos
;
5019 retval
= 1 + (it
->area
== TEXT_AREA
);
5021 #ifdef HAVE_WINDOW_SYSTEM
5024 it
->what
= IT_IMAGE
;
5025 it
->image_id
= lookup_image (it
->f
, value
);
5026 it
->position
= start_pos
;
5027 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5028 it
->method
= GET_FROM_IMAGE
;
5030 /* Say that we haven't consumed the characters with
5031 `display' property yet. The call to pop_it in
5032 set_iterator_to_next will clean this up. */
5033 *position
= start_pos
;
5035 #endif /* HAVE_WINDOW_SYSTEM */
5040 /* Invalid property or property not supported. Restore
5041 POSITION to what it was before. */
5042 *position
= start_pos
;
5046 /* Check if PROP is a display property value whose text should be
5047 treated as intangible. OVERLAY is the overlay from which PROP
5048 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5049 specify the buffer position covered by PROP. */
5052 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5053 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5055 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5056 struct text_pos position
;
5058 SET_TEXT_POS (position
, charpos
, bytepos
);
5059 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5060 &position
, charpos
, frame_window_p
);
5064 /* Return 1 if PROP is a display sub-property value containing STRING.
5066 Implementation note: this and the following function are really
5067 special cases of handle_display_spec and
5068 handle_single_display_spec, and should ideally use the same code.
5069 Until they do, these two pairs must be consistent and must be
5070 modified in sync. */
5073 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5075 if (EQ (string
, prop
))
5078 /* Skip over `when FORM'. */
5079 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5084 /* Actually, the condition following `when' should be eval'ed,
5085 like handle_single_display_spec does, and we should return
5086 zero if it evaluates to nil. However, this function is
5087 called only when the buffer was already displayed and some
5088 glyph in the glyph matrix was found to come from a display
5089 string. Therefore, the condition was already evaluated, and
5090 the result was non-nil, otherwise the display string wouldn't
5091 have been displayed and we would have never been called for
5092 this property. Thus, we can skip the evaluation and assume
5093 its result is non-nil. */
5098 /* Skip over `margin LOCATION'. */
5099 if (EQ (XCAR (prop
), Qmargin
))
5110 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5114 /* Return 1 if STRING appears in the `display' property PROP. */
5117 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5120 && !EQ (XCAR (prop
), Qwhen
)
5121 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5123 /* A list of sub-properties. */
5124 while (CONSP (prop
))
5126 if (single_display_spec_string_p (XCAR (prop
), string
))
5131 else if (VECTORP (prop
))
5133 /* A vector of sub-properties. */
5135 for (i
= 0; i
< ASIZE (prop
); ++i
)
5136 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5140 return single_display_spec_string_p (prop
, string
);
5145 /* Look for STRING in overlays and text properties in the current
5146 buffer, between character positions FROM and TO (excluding TO).
5147 BACK_P non-zero means look back (in this case, TO is supposed to be
5149 Value is the first character position where STRING was found, or
5150 zero if it wasn't found before hitting TO.
5152 This function may only use code that doesn't eval because it is
5153 called asynchronously from note_mouse_highlight. */
5156 string_buffer_position_lim (Lisp_Object string
,
5157 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5159 Lisp_Object limit
, prop
, pos
;
5162 pos
= make_number (max (from
, BEGV
));
5164 if (!back_p
) /* looking forward */
5166 limit
= make_number (min (to
, ZV
));
5167 while (!found
&& !EQ (pos
, limit
))
5169 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5170 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5173 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5177 else /* looking back */
5179 limit
= make_number (max (to
, BEGV
));
5180 while (!found
&& !EQ (pos
, limit
))
5182 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5183 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5186 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5191 return found
? XINT (pos
) : 0;
5194 /* Determine which buffer position in current buffer STRING comes from.
5195 AROUND_CHARPOS is an approximate position where it could come from.
5196 Value is the buffer position or 0 if it couldn't be determined.
5198 This function is necessary because we don't record buffer positions
5199 in glyphs generated from strings (to keep struct glyph small).
5200 This function may only use code that doesn't eval because it is
5201 called asynchronously from note_mouse_highlight. */
5204 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5206 const int MAX_DISTANCE
= 1000;
5207 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5208 around_charpos
+ MAX_DISTANCE
,
5212 found
= string_buffer_position_lim (string
, around_charpos
,
5213 around_charpos
- MAX_DISTANCE
, 1);
5219 /***********************************************************************
5220 `composition' property
5221 ***********************************************************************/
5223 /* Set up iterator IT from `composition' property at its current
5224 position. Called from handle_stop. */
5226 static enum prop_handled
5227 handle_composition_prop (struct it
*it
)
5229 Lisp_Object prop
, string
;
5230 ptrdiff_t pos
, pos_byte
, start
, end
;
5232 if (STRINGP (it
->string
))
5236 pos
= IT_STRING_CHARPOS (*it
);
5237 pos_byte
= IT_STRING_BYTEPOS (*it
);
5238 string
= it
->string
;
5239 s
= SDATA (string
) + pos_byte
;
5240 it
->c
= STRING_CHAR (s
);
5244 pos
= IT_CHARPOS (*it
);
5245 pos_byte
= IT_BYTEPOS (*it
);
5247 it
->c
= FETCH_CHAR (pos_byte
);
5250 /* If there's a valid composition and point is not inside of the
5251 composition (in the case that the composition is from the current
5252 buffer), draw a glyph composed from the composition components. */
5253 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5254 && COMPOSITION_VALID_P (start
, end
, prop
)
5255 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5258 /* As we can't handle this situation (perhaps font-lock added
5259 a new composition), we just return here hoping that next
5260 redisplay will detect this composition much earlier. */
5261 return HANDLED_NORMALLY
;
5264 if (STRINGP (it
->string
))
5265 pos_byte
= string_char_to_byte (it
->string
, start
);
5267 pos_byte
= CHAR_TO_BYTE (start
);
5269 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5272 if (it
->cmp_it
.id
>= 0)
5275 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5276 it
->cmp_it
.nglyphs
= -1;
5280 return HANDLED_NORMALLY
;
5285 /***********************************************************************
5287 ***********************************************************************/
5289 /* The following structure is used to record overlay strings for
5290 later sorting in load_overlay_strings. */
5292 struct overlay_entry
5294 Lisp_Object overlay
;
5301 /* Set up iterator IT from overlay strings at its current position.
5302 Called from handle_stop. */
5304 static enum prop_handled
5305 handle_overlay_change (struct it
*it
)
5307 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5308 return HANDLED_RECOMPUTE_PROPS
;
5310 return HANDLED_NORMALLY
;
5314 /* Set up the next overlay string for delivery by IT, if there is an
5315 overlay string to deliver. Called by set_iterator_to_next when the
5316 end of the current overlay string is reached. If there are more
5317 overlay strings to display, IT->string and
5318 IT->current.overlay_string_index are set appropriately here.
5319 Otherwise IT->string is set to nil. */
5322 next_overlay_string (struct it
*it
)
5324 ++it
->current
.overlay_string_index
;
5325 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5327 /* No more overlay strings. Restore IT's settings to what
5328 they were before overlay strings were processed, and
5329 continue to deliver from current_buffer. */
5331 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5334 || (NILP (it
->string
)
5335 && it
->method
== GET_FROM_BUFFER
5336 && it
->stop_charpos
>= BEGV
5337 && it
->stop_charpos
<= it
->end_charpos
));
5338 it
->current
.overlay_string_index
= -1;
5339 it
->n_overlay_strings
= 0;
5340 it
->overlay_strings_charpos
= -1;
5341 /* If there's an empty display string on the stack, pop the
5342 stack, to resync the bidi iterator with IT's position. Such
5343 empty strings are pushed onto the stack in
5344 get_overlay_strings_1. */
5345 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5348 /* If we're at the end of the buffer, record that we have
5349 processed the overlay strings there already, so that
5350 next_element_from_buffer doesn't try it again. */
5351 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5352 it
->overlay_strings_at_end_processed_p
= 1;
5356 /* There are more overlay strings to process. If
5357 IT->current.overlay_string_index has advanced to a position
5358 where we must load IT->overlay_strings with more strings, do
5359 it. We must load at the IT->overlay_strings_charpos where
5360 IT->n_overlay_strings was originally computed; when invisible
5361 text is present, this might not be IT_CHARPOS (Bug#7016). */
5362 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5364 if (it
->current
.overlay_string_index
&& i
== 0)
5365 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5367 /* Initialize IT to deliver display elements from the overlay
5369 it
->string
= it
->overlay_strings
[i
];
5370 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5371 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5372 it
->method
= GET_FROM_STRING
;
5373 it
->stop_charpos
= 0;
5374 it
->end_charpos
= SCHARS (it
->string
);
5375 if (it
->cmp_it
.stop_pos
>= 0)
5376 it
->cmp_it
.stop_pos
= 0;
5378 it
->base_level_stop
= 0;
5380 /* Set up the bidi iterator for this overlay string. */
5383 it
->bidi_it
.string
.lstring
= it
->string
;
5384 it
->bidi_it
.string
.s
= NULL
;
5385 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5386 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5387 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5388 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5389 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5397 /* Compare two overlay_entry structures E1 and E2. Used as a
5398 comparison function for qsort in load_overlay_strings. Overlay
5399 strings for the same position are sorted so that
5401 1. All after-strings come in front of before-strings, except
5402 when they come from the same overlay.
5404 2. Within after-strings, strings are sorted so that overlay strings
5405 from overlays with higher priorities come first.
5407 2. Within before-strings, strings are sorted so that overlay
5408 strings from overlays with higher priorities come last.
5410 Value is analogous to strcmp. */
5414 compare_overlay_entries (const void *e1
, const void *e2
)
5416 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5417 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5420 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5422 /* Let after-strings appear in front of before-strings if
5423 they come from different overlays. */
5424 if (EQ (entry1
->overlay
, entry2
->overlay
))
5425 result
= entry1
->after_string_p
? 1 : -1;
5427 result
= entry1
->after_string_p
? -1 : 1;
5429 else if (entry1
->priority
!= entry2
->priority
)
5431 if (entry1
->after_string_p
)
5432 /* After-strings sorted in order of decreasing priority. */
5433 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5435 /* Before-strings sorted in order of increasing priority. */
5436 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5445 /* Load the vector IT->overlay_strings with overlay strings from IT's
5446 current buffer position, or from CHARPOS if that is > 0. Set
5447 IT->n_overlays to the total number of overlay strings found.
5449 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5450 a time. On entry into load_overlay_strings,
5451 IT->current.overlay_string_index gives the number of overlay
5452 strings that have already been loaded by previous calls to this
5455 IT->add_overlay_start contains an additional overlay start
5456 position to consider for taking overlay strings from, if non-zero.
5457 This position comes into play when the overlay has an `invisible'
5458 property, and both before and after-strings. When we've skipped to
5459 the end of the overlay, because of its `invisible' property, we
5460 nevertheless want its before-string to appear.
5461 IT->add_overlay_start will contain the overlay start position
5464 Overlay strings are sorted so that after-string strings come in
5465 front of before-string strings. Within before and after-strings,
5466 strings are sorted by overlay priority. See also function
5467 compare_overlay_entries. */
5470 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5472 Lisp_Object overlay
, window
, str
, invisible
;
5473 struct Lisp_Overlay
*ov
;
5474 ptrdiff_t start
, end
;
5475 ptrdiff_t size
= 20;
5476 ptrdiff_t n
= 0, i
, j
;
5478 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5482 charpos
= IT_CHARPOS (*it
);
5484 /* Append the overlay string STRING of overlay OVERLAY to vector
5485 `entries' which has size `size' and currently contains `n'
5486 elements. AFTER_P non-zero means STRING is an after-string of
5488 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5491 Lisp_Object priority; \
5495 struct overlay_entry *old = entries; \
5496 SAFE_NALLOCA (entries, 2, size); \
5497 memcpy (entries, old, size * sizeof *entries); \
5501 entries[n].string = (STRING); \
5502 entries[n].overlay = (OVERLAY); \
5503 priority = Foverlay_get ((OVERLAY), Qpriority); \
5504 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5505 entries[n].after_string_p = (AFTER_P); \
5510 /* Process overlay before the overlay center. */
5511 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5513 XSETMISC (overlay
, ov
);
5514 eassert (OVERLAYP (overlay
));
5515 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5516 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5521 /* Skip this overlay if it doesn't start or end at IT's current
5523 if (end
!= charpos
&& start
!= charpos
)
5526 /* Skip this overlay if it doesn't apply to IT->w. */
5527 window
= Foverlay_get (overlay
, Qwindow
);
5528 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5531 /* If the text ``under'' the overlay is invisible, both before-
5532 and after-strings from this overlay are visible; start and
5533 end position are indistinguishable. */
5534 invisible
= Foverlay_get (overlay
, Qinvisible
);
5535 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5537 /* If overlay has a non-empty before-string, record it. */
5538 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5539 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5541 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5543 /* If overlay has a non-empty after-string, record it. */
5544 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5545 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5547 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5550 /* Process overlays after the overlay center. */
5551 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5553 XSETMISC (overlay
, ov
);
5554 eassert (OVERLAYP (overlay
));
5555 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5556 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5558 if (start
> charpos
)
5561 /* Skip this overlay if it doesn't start or end at IT's current
5563 if (end
!= charpos
&& start
!= charpos
)
5566 /* Skip this overlay if it doesn't apply to IT->w. */
5567 window
= Foverlay_get (overlay
, Qwindow
);
5568 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5571 /* If the text ``under'' the overlay is invisible, it has a zero
5572 dimension, and both before- and after-strings apply. */
5573 invisible
= Foverlay_get (overlay
, Qinvisible
);
5574 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5576 /* If overlay has a non-empty before-string, record it. */
5577 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5578 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5580 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5582 /* If overlay has a non-empty after-string, record it. */
5583 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5584 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5586 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5589 #undef RECORD_OVERLAY_STRING
5593 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5595 /* Record number of overlay strings, and where we computed it. */
5596 it
->n_overlay_strings
= n
;
5597 it
->overlay_strings_charpos
= charpos
;
5599 /* IT->current.overlay_string_index is the number of overlay strings
5600 that have already been consumed by IT. Copy some of the
5601 remaining overlay strings to IT->overlay_strings. */
5603 j
= it
->current
.overlay_string_index
;
5604 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5606 it
->overlay_strings
[i
] = entries
[j
].string
;
5607 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5615 /* Get the first chunk of overlay strings at IT's current buffer
5616 position, or at CHARPOS if that is > 0. Value is non-zero if at
5617 least one overlay string was found. */
5620 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5622 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5623 process. This fills IT->overlay_strings with strings, and sets
5624 IT->n_overlay_strings to the total number of strings to process.
5625 IT->pos.overlay_string_index has to be set temporarily to zero
5626 because load_overlay_strings needs this; it must be set to -1
5627 when no overlay strings are found because a zero value would
5628 indicate a position in the first overlay string. */
5629 it
->current
.overlay_string_index
= 0;
5630 load_overlay_strings (it
, charpos
);
5632 /* If we found overlay strings, set up IT to deliver display
5633 elements from the first one. Otherwise set up IT to deliver
5634 from current_buffer. */
5635 if (it
->n_overlay_strings
)
5637 /* Make sure we know settings in current_buffer, so that we can
5638 restore meaningful values when we're done with the overlay
5641 compute_stop_pos (it
);
5642 eassert (it
->face_id
>= 0);
5644 /* Save IT's settings. They are restored after all overlay
5645 strings have been processed. */
5646 eassert (!compute_stop_p
|| it
->sp
== 0);
5648 /* When called from handle_stop, there might be an empty display
5649 string loaded. In that case, don't bother saving it. But
5650 don't use this optimization with the bidi iterator, since we
5651 need the corresponding pop_it call to resync the bidi
5652 iterator's position with IT's position, after we are done
5653 with the overlay strings. (The corresponding call to pop_it
5654 in case of an empty display string is in
5655 next_overlay_string.) */
5657 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5660 /* Set up IT to deliver display elements from the first overlay
5662 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5663 it
->string
= it
->overlay_strings
[0];
5664 it
->from_overlay
= Qnil
;
5665 it
->stop_charpos
= 0;
5666 eassert (STRINGP (it
->string
));
5667 it
->end_charpos
= SCHARS (it
->string
);
5669 it
->base_level_stop
= 0;
5670 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5671 it
->method
= GET_FROM_STRING
;
5672 it
->from_disp_prop_p
= 0;
5674 /* Force paragraph direction to be that of the parent
5676 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5677 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5679 it
->paragraph_embedding
= L2R
;
5681 /* Set up the bidi iterator for this overlay string. */
5684 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5686 it
->bidi_it
.string
.lstring
= it
->string
;
5687 it
->bidi_it
.string
.s
= NULL
;
5688 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5689 it
->bidi_it
.string
.bufpos
= pos
;
5690 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5691 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5692 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5697 it
->current
.overlay_string_index
= -1;
5702 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5705 it
->method
= GET_FROM_BUFFER
;
5707 (void) get_overlay_strings_1 (it
, charpos
, 1);
5711 /* Value is non-zero if we found at least one overlay string. */
5712 return STRINGP (it
->string
);
5717 /***********************************************************************
5718 Saving and restoring state
5719 ***********************************************************************/
5721 /* Save current settings of IT on IT->stack. Called, for example,
5722 before setting up IT for an overlay string, to be able to restore
5723 IT's settings to what they were after the overlay string has been
5724 processed. If POSITION is non-NULL, it is the position to save on
5725 the stack instead of IT->position. */
5728 push_it (struct it
*it
, struct text_pos
*position
)
5730 struct iterator_stack_entry
*p
;
5732 eassert (it
->sp
< IT_STACK_SIZE
);
5733 p
= it
->stack
+ it
->sp
;
5735 p
->stop_charpos
= it
->stop_charpos
;
5736 p
->prev_stop
= it
->prev_stop
;
5737 p
->base_level_stop
= it
->base_level_stop
;
5738 p
->cmp_it
= it
->cmp_it
;
5739 eassert (it
->face_id
>= 0);
5740 p
->face_id
= it
->face_id
;
5741 p
->string
= it
->string
;
5742 p
->method
= it
->method
;
5743 p
->from_overlay
= it
->from_overlay
;
5746 case GET_FROM_IMAGE
:
5747 p
->u
.image
.object
= it
->object
;
5748 p
->u
.image
.image_id
= it
->image_id
;
5749 p
->u
.image
.slice
= it
->slice
;
5751 case GET_FROM_STRETCH
:
5752 p
->u
.stretch
.object
= it
->object
;
5755 p
->position
= position
? *position
: it
->position
;
5756 p
->current
= it
->current
;
5757 p
->end_charpos
= it
->end_charpos
;
5758 p
->string_nchars
= it
->string_nchars
;
5760 p
->multibyte_p
= it
->multibyte_p
;
5761 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5762 p
->space_width
= it
->space_width
;
5763 p
->font_height
= it
->font_height
;
5764 p
->voffset
= it
->voffset
;
5765 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5766 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5767 p
->display_ellipsis_p
= 0;
5768 p
->line_wrap
= it
->line_wrap
;
5769 p
->bidi_p
= it
->bidi_p
;
5770 p
->paragraph_embedding
= it
->paragraph_embedding
;
5771 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5774 /* Save the state of the bidi iterator as well. */
5776 bidi_push_it (&it
->bidi_it
);
5780 iterate_out_of_display_property (struct it
*it
)
5782 int buffer_p
= !STRINGP (it
->string
);
5783 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5784 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5786 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5788 /* Maybe initialize paragraph direction. If we are at the beginning
5789 of a new paragraph, next_element_from_buffer may not have a
5790 chance to do that. */
5791 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5792 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5793 /* prev_stop can be zero, so check against BEGV as well. */
5794 while (it
->bidi_it
.charpos
>= bob
5795 && it
->prev_stop
<= it
->bidi_it
.charpos
5796 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5797 && it
->bidi_it
.charpos
< eob
)
5798 bidi_move_to_visually_next (&it
->bidi_it
);
5799 /* Record the stop_pos we just crossed, for when we cross it
5801 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5802 it
->prev_stop
= CHARPOS (it
->position
);
5803 /* If we ended up not where pop_it put us, resync IT's
5804 positional members with the bidi iterator. */
5805 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5806 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5808 it
->current
.pos
= it
->position
;
5810 it
->current
.string_pos
= it
->position
;
5813 /* Restore IT's settings from IT->stack. Called, for example, when no
5814 more overlay strings must be processed, and we return to delivering
5815 display elements from a buffer, or when the end of a string from a
5816 `display' property is reached and we return to delivering display
5817 elements from an overlay string, or from a buffer. */
5820 pop_it (struct it
*it
)
5822 struct iterator_stack_entry
*p
;
5823 int from_display_prop
= it
->from_disp_prop_p
;
5825 eassert (it
->sp
> 0);
5827 p
= it
->stack
+ it
->sp
;
5828 it
->stop_charpos
= p
->stop_charpos
;
5829 it
->prev_stop
= p
->prev_stop
;
5830 it
->base_level_stop
= p
->base_level_stop
;
5831 it
->cmp_it
= p
->cmp_it
;
5832 it
->face_id
= p
->face_id
;
5833 it
->current
= p
->current
;
5834 it
->position
= p
->position
;
5835 it
->string
= p
->string
;
5836 it
->from_overlay
= p
->from_overlay
;
5837 if (NILP (it
->string
))
5838 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5839 it
->method
= p
->method
;
5842 case GET_FROM_IMAGE
:
5843 it
->image_id
= p
->u
.image
.image_id
;
5844 it
->object
= p
->u
.image
.object
;
5845 it
->slice
= p
->u
.image
.slice
;
5847 case GET_FROM_STRETCH
:
5848 it
->object
= p
->u
.stretch
.object
;
5850 case GET_FROM_BUFFER
:
5851 it
->object
= it
->w
->contents
;
5853 case GET_FROM_STRING
:
5854 it
->object
= it
->string
;
5856 case GET_FROM_DISPLAY_VECTOR
:
5858 it
->method
= GET_FROM_C_STRING
;
5859 else if (STRINGP (it
->string
))
5860 it
->method
= GET_FROM_STRING
;
5863 it
->method
= GET_FROM_BUFFER
;
5864 it
->object
= it
->w
->contents
;
5867 it
->end_charpos
= p
->end_charpos
;
5868 it
->string_nchars
= p
->string_nchars
;
5870 it
->multibyte_p
= p
->multibyte_p
;
5871 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5872 it
->space_width
= p
->space_width
;
5873 it
->font_height
= p
->font_height
;
5874 it
->voffset
= p
->voffset
;
5875 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5876 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5877 it
->line_wrap
= p
->line_wrap
;
5878 it
->bidi_p
= p
->bidi_p
;
5879 it
->paragraph_embedding
= p
->paragraph_embedding
;
5880 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5883 bidi_pop_it (&it
->bidi_it
);
5884 /* Bidi-iterate until we get out of the portion of text, if any,
5885 covered by a `display' text property or by an overlay with
5886 `display' property. (We cannot just jump there, because the
5887 internal coherency of the bidi iterator state can not be
5888 preserved across such jumps.) We also must determine the
5889 paragraph base direction if the overlay we just processed is
5890 at the beginning of a new paragraph. */
5891 if (from_display_prop
5892 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5893 iterate_out_of_display_property (it
);
5895 eassert ((BUFFERP (it
->object
)
5896 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5897 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5898 || (STRINGP (it
->object
)
5899 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5900 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5901 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5907 /***********************************************************************
5909 ***********************************************************************/
5911 /* Set IT's current position to the previous line start. */
5914 back_to_previous_line_start (struct it
*it
)
5916 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
5919 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
5923 /* Move IT to the next line start.
5925 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5926 we skipped over part of the text (as opposed to moving the iterator
5927 continuously over the text). Otherwise, don't change the value
5930 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5931 iterator on the newline, if it was found.
5933 Newlines may come from buffer text, overlay strings, or strings
5934 displayed via the `display' property. That's the reason we can't
5935 simply use find_newline_no_quit.
5937 Note that this function may not skip over invisible text that is so
5938 because of text properties and immediately follows a newline. If
5939 it would, function reseat_at_next_visible_line_start, when called
5940 from set_iterator_to_next, would effectively make invisible
5941 characters following a newline part of the wrong glyph row, which
5942 leads to wrong cursor motion. */
5945 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5946 struct bidi_it
*bidi_it_prev
)
5948 ptrdiff_t old_selective
;
5949 int newline_found_p
, n
;
5950 const int MAX_NEWLINE_DISTANCE
= 500;
5952 /* If already on a newline, just consume it to avoid unintended
5953 skipping over invisible text below. */
5954 if (it
->what
== IT_CHARACTER
5956 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5958 if (it
->bidi_p
&& bidi_it_prev
)
5959 *bidi_it_prev
= it
->bidi_it
;
5960 set_iterator_to_next (it
, 0);
5965 /* Don't handle selective display in the following. It's (a)
5966 unnecessary because it's done by the caller, and (b) leads to an
5967 infinite recursion because next_element_from_ellipsis indirectly
5968 calls this function. */
5969 old_selective
= it
->selective
;
5972 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5973 from buffer text. */
5974 for (n
= newline_found_p
= 0;
5975 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5976 n
+= STRINGP (it
->string
) ? 0 : 1)
5978 if (!get_next_display_element (it
))
5980 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5981 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5982 *bidi_it_prev
= it
->bidi_it
;
5983 set_iterator_to_next (it
, 0);
5986 /* If we didn't find a newline near enough, see if we can use a
5988 if (!newline_found_p
)
5990 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
5991 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
5995 eassert (!STRINGP (it
->string
));
5997 /* If there isn't any `display' property in sight, and no
5998 overlays, we can just use the position of the newline in
6000 if (it
->stop_charpos
>= limit
6001 || ((pos
= Fnext_single_property_change (make_number (start
),
6003 make_number (limit
)),
6005 && next_overlay_change (start
) == ZV
))
6009 IT_CHARPOS (*it
) = limit
;
6010 IT_BYTEPOS (*it
) = bytepos
;
6014 struct bidi_it bprev
;
6016 /* Help bidi.c avoid expensive searches for display
6017 properties and overlays, by telling it that there are
6018 none up to `limit'. */
6019 if (it
->bidi_it
.disp_pos
< limit
)
6021 it
->bidi_it
.disp_pos
= limit
;
6022 it
->bidi_it
.disp_prop
= 0;
6025 bprev
= it
->bidi_it
;
6026 bidi_move_to_visually_next (&it
->bidi_it
);
6027 } while (it
->bidi_it
.charpos
!= limit
);
6028 IT_CHARPOS (*it
) = limit
;
6029 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6031 *bidi_it_prev
= bprev
;
6033 *skipped_p
= newline_found_p
= 1;
6037 while (get_next_display_element (it
)
6038 && !newline_found_p
)
6040 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6041 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6042 *bidi_it_prev
= it
->bidi_it
;
6043 set_iterator_to_next (it
, 0);
6048 it
->selective
= old_selective
;
6049 return newline_found_p
;
6053 /* Set IT's current position to the previous visible line start. Skip
6054 invisible text that is so either due to text properties or due to
6055 selective display. Caution: this does not change IT->current_x and
6059 back_to_previous_visible_line_start (struct it
*it
)
6061 while (IT_CHARPOS (*it
) > BEGV
)
6063 back_to_previous_line_start (it
);
6065 if (IT_CHARPOS (*it
) <= BEGV
)
6068 /* If selective > 0, then lines indented more than its value are
6070 if (it
->selective
> 0
6071 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6075 /* Check the newline before point for invisibility. */
6078 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6079 Qinvisible
, it
->window
);
6080 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6084 if (IT_CHARPOS (*it
) <= BEGV
)
6089 void *it2data
= NULL
;
6092 Lisp_Object val
, overlay
;
6094 SAVE_IT (it2
, *it
, it2data
);
6096 /* If newline is part of a composition, continue from start of composition */
6097 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6098 && beg
< IT_CHARPOS (*it
))
6101 /* If newline is replaced by a display property, find start of overlay
6102 or interval and continue search from that point. */
6103 pos
= --IT_CHARPOS (it2
);
6106 bidi_unshelve_cache (NULL
, 0);
6107 it2
.string_from_display_prop_p
= 0;
6108 it2
.from_disp_prop_p
= 0;
6109 if (handle_display_prop (&it2
) == HANDLED_RETURN
6110 && !NILP (val
= get_char_property_and_overlay
6111 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6112 && (OVERLAYP (overlay
)
6113 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6114 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6116 RESTORE_IT (it
, it
, it2data
);
6120 /* Newline is not replaced by anything -- so we are done. */
6121 RESTORE_IT (it
, it
, it2data
);
6127 IT_CHARPOS (*it
) = beg
;
6128 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6132 it
->continuation_lines_width
= 0;
6134 eassert (IT_CHARPOS (*it
) >= BEGV
);
6135 eassert (IT_CHARPOS (*it
) == BEGV
6136 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6141 /* Reseat iterator IT at the previous visible line start. Skip
6142 invisible text that is so either due to text properties or due to
6143 selective display. At the end, update IT's overlay information,
6144 face information etc. */
6147 reseat_at_previous_visible_line_start (struct it
*it
)
6149 back_to_previous_visible_line_start (it
);
6150 reseat (it
, it
->current
.pos
, 1);
6155 /* Reseat iterator IT on the next visible line start in the current
6156 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6157 preceding the line start. Skip over invisible text that is so
6158 because of selective display. Compute faces, overlays etc at the
6159 new position. Note that this function does not skip over text that
6160 is invisible because of text properties. */
6163 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6165 int newline_found_p
, skipped_p
= 0;
6166 struct bidi_it bidi_it_prev
;
6168 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6170 /* Skip over lines that are invisible because they are indented
6171 more than the value of IT->selective. */
6172 if (it
->selective
> 0)
6173 while (IT_CHARPOS (*it
) < ZV
6174 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6177 eassert (IT_BYTEPOS (*it
) == BEGV
6178 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6180 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6183 /* Position on the newline if that's what's requested. */
6184 if (on_newline_p
&& newline_found_p
)
6186 if (STRINGP (it
->string
))
6188 if (IT_STRING_CHARPOS (*it
) > 0)
6192 --IT_STRING_CHARPOS (*it
);
6193 --IT_STRING_BYTEPOS (*it
);
6197 /* We need to restore the bidi iterator to the state
6198 it had on the newline, and resync the IT's
6199 position with that. */
6200 it
->bidi_it
= bidi_it_prev
;
6201 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6202 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6206 else if (IT_CHARPOS (*it
) > BEGV
)
6215 /* We need to restore the bidi iterator to the state it
6216 had on the newline and resync IT with that. */
6217 it
->bidi_it
= bidi_it_prev
;
6218 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6219 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6221 reseat (it
, it
->current
.pos
, 0);
6225 reseat (it
, it
->current
.pos
, 0);
6232 /***********************************************************************
6233 Changing an iterator's position
6234 ***********************************************************************/
6236 /* Change IT's current position to POS in current_buffer. If FORCE_P
6237 is non-zero, always check for text properties at the new position.
6238 Otherwise, text properties are only looked up if POS >=
6239 IT->check_charpos of a property. */
6242 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6244 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6246 reseat_1 (it
, pos
, 0);
6248 /* Determine where to check text properties. Avoid doing it
6249 where possible because text property lookup is very expensive. */
6251 || CHARPOS (pos
) > it
->stop_charpos
6252 || CHARPOS (pos
) < original_pos
)
6256 /* For bidi iteration, we need to prime prev_stop and
6257 base_level_stop with our best estimations. */
6258 /* Implementation note: Of course, POS is not necessarily a
6259 stop position, so assigning prev_pos to it is a lie; we
6260 should have called compute_stop_backwards. However, if
6261 the current buffer does not include any R2L characters,
6262 that call would be a waste of cycles, because the
6263 iterator will never move back, and thus never cross this
6264 "fake" stop position. So we delay that backward search
6265 until the time we really need it, in next_element_from_buffer. */
6266 if (CHARPOS (pos
) != it
->prev_stop
)
6267 it
->prev_stop
= CHARPOS (pos
);
6268 if (CHARPOS (pos
) < it
->base_level_stop
)
6269 it
->base_level_stop
= 0; /* meaning it's unknown */
6275 it
->prev_stop
= it
->base_level_stop
= 0;
6284 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6285 IT->stop_pos to POS, also. */
6288 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6290 /* Don't call this function when scanning a C string. */
6291 eassert (it
->s
== NULL
);
6293 /* POS must be a reasonable value. */
6294 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6296 it
->current
.pos
= it
->position
= pos
;
6297 it
->end_charpos
= ZV
;
6299 it
->current
.dpvec_index
= -1;
6300 it
->current
.overlay_string_index
= -1;
6301 IT_STRING_CHARPOS (*it
) = -1;
6302 IT_STRING_BYTEPOS (*it
) = -1;
6304 it
->method
= GET_FROM_BUFFER
;
6305 it
->object
= it
->w
->contents
;
6306 it
->area
= TEXT_AREA
;
6307 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6309 it
->string_from_display_prop_p
= 0;
6310 it
->string_from_prefix_prop_p
= 0;
6312 it
->from_disp_prop_p
= 0;
6313 it
->face_before_selective_p
= 0;
6316 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6318 bidi_unshelve_cache (NULL
, 0);
6319 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6320 it
->bidi_it
.string
.s
= NULL
;
6321 it
->bidi_it
.string
.lstring
= Qnil
;
6322 it
->bidi_it
.string
.bufpos
= 0;
6323 it
->bidi_it
.string
.unibyte
= 0;
6328 it
->stop_charpos
= CHARPOS (pos
);
6329 it
->base_level_stop
= CHARPOS (pos
);
6331 /* This make the information stored in it->cmp_it invalidate. */
6336 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6337 If S is non-null, it is a C string to iterate over. Otherwise,
6338 STRING gives a Lisp string to iterate over.
6340 If PRECISION > 0, don't return more then PRECISION number of
6341 characters from the string.
6343 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6344 characters have been returned. FIELD_WIDTH < 0 means an infinite
6347 MULTIBYTE = 0 means disable processing of multibyte characters,
6348 MULTIBYTE > 0 means enable it,
6349 MULTIBYTE < 0 means use IT->multibyte_p.
6351 IT must be initialized via a prior call to init_iterator before
6352 calling this function. */
6355 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6356 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6359 /* No region in strings. */
6360 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6362 /* No text property checks performed by default, but see below. */
6363 it
->stop_charpos
= -1;
6365 /* Set iterator position and end position. */
6366 memset (&it
->current
, 0, sizeof it
->current
);
6367 it
->current
.overlay_string_index
= -1;
6368 it
->current
.dpvec_index
= -1;
6369 eassert (charpos
>= 0);
6371 /* If STRING is specified, use its multibyteness, otherwise use the
6372 setting of MULTIBYTE, if specified. */
6374 it
->multibyte_p
= multibyte
> 0;
6376 /* Bidirectional reordering of strings is controlled by the default
6377 value of bidi-display-reordering. Don't try to reorder while
6378 loading loadup.el, as the necessary character property tables are
6379 not yet available. */
6382 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6386 eassert (STRINGP (string
));
6387 it
->string
= string
;
6389 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6390 it
->method
= GET_FROM_STRING
;
6391 it
->current
.string_pos
= string_pos (charpos
, string
);
6395 it
->bidi_it
.string
.lstring
= string
;
6396 it
->bidi_it
.string
.s
= NULL
;
6397 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6398 it
->bidi_it
.string
.bufpos
= 0;
6399 it
->bidi_it
.string
.from_disp_str
= 0;
6400 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6401 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6402 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6407 it
->s
= (const unsigned char *) s
;
6410 /* Note that we use IT->current.pos, not it->current.string_pos,
6411 for displaying C strings. */
6412 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6413 if (it
->multibyte_p
)
6415 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6416 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6420 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6421 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6426 it
->bidi_it
.string
.lstring
= Qnil
;
6427 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6428 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6429 it
->bidi_it
.string
.bufpos
= 0;
6430 it
->bidi_it
.string
.from_disp_str
= 0;
6431 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6432 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6435 it
->method
= GET_FROM_C_STRING
;
6438 /* PRECISION > 0 means don't return more than PRECISION characters
6440 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6442 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6444 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6447 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6448 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6449 FIELD_WIDTH < 0 means infinite field width. This is useful for
6450 padding with `-' at the end of a mode line. */
6451 if (field_width
< 0)
6452 field_width
= INFINITY
;
6453 /* Implementation note: We deliberately don't enlarge
6454 it->bidi_it.string.schars here to fit it->end_charpos, because
6455 the bidi iterator cannot produce characters out of thin air. */
6456 if (field_width
> it
->end_charpos
- charpos
)
6457 it
->end_charpos
= charpos
+ field_width
;
6459 /* Use the standard display table for displaying strings. */
6460 if (DISP_TABLE_P (Vstandard_display_table
))
6461 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6463 it
->stop_charpos
= charpos
;
6464 it
->prev_stop
= charpos
;
6465 it
->base_level_stop
= 0;
6468 it
->bidi_it
.first_elt
= 1;
6469 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6470 it
->bidi_it
.disp_pos
= -1;
6472 if (s
== NULL
&& it
->multibyte_p
)
6474 ptrdiff_t endpos
= SCHARS (it
->string
);
6475 if (endpos
> it
->end_charpos
)
6476 endpos
= it
->end_charpos
;
6477 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6485 /***********************************************************************
6487 ***********************************************************************/
6489 /* Map enum it_method value to corresponding next_element_from_* function. */
6491 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6493 next_element_from_buffer
,
6494 next_element_from_display_vector
,
6495 next_element_from_string
,
6496 next_element_from_c_string
,
6497 next_element_from_image
,
6498 next_element_from_stretch
6501 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6504 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6505 (possibly with the following characters). */
6507 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6508 ((IT)->cmp_it.id >= 0 \
6509 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6510 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6511 END_CHARPOS, (IT)->w, \
6512 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6516 /* Lookup the char-table Vglyphless_char_display for character C (-1
6517 if we want information for no-font case), and return the display
6518 method symbol. By side-effect, update it->what and
6519 it->glyphless_method. This function is called from
6520 get_next_display_element for each character element, and from
6521 x_produce_glyphs when no suitable font was found. */
6524 lookup_glyphless_char_display (int c
, struct it
*it
)
6526 Lisp_Object glyphless_method
= Qnil
;
6528 if (CHAR_TABLE_P (Vglyphless_char_display
)
6529 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6533 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6534 if (CONSP (glyphless_method
))
6535 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6536 ? XCAR (glyphless_method
)
6537 : XCDR (glyphless_method
);
6540 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6544 if (NILP (glyphless_method
))
6547 /* The default is to display the character by a proper font. */
6549 /* The default for the no-font case is to display an empty box. */
6550 glyphless_method
= Qempty_box
;
6552 if (EQ (glyphless_method
, Qzero_width
))
6555 return glyphless_method
;
6556 /* This method can't be used for the no-font case. */
6557 glyphless_method
= Qempty_box
;
6559 if (EQ (glyphless_method
, Qthin_space
))
6560 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6561 else if (EQ (glyphless_method
, Qempty_box
))
6562 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6563 else if (EQ (glyphless_method
, Qhex_code
))
6564 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6565 else if (STRINGP (glyphless_method
))
6566 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6569 /* Invalid value. We use the default method. */
6570 glyphless_method
= Qnil
;
6573 it
->what
= IT_GLYPHLESS
;
6574 return glyphless_method
;
6577 /* Load IT's display element fields with information about the next
6578 display element from the current position of IT. Value is zero if
6579 end of buffer (or C string) is reached. */
6581 static struct frame
*last_escape_glyph_frame
= NULL
;
6582 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6583 static int last_escape_glyph_merged_face_id
= 0;
6585 struct frame
*last_glyphless_glyph_frame
= NULL
;
6586 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6587 int last_glyphless_glyph_merged_face_id
= 0;
6590 get_next_display_element (struct it
*it
)
6592 /* Non-zero means that we found a display element. Zero means that
6593 we hit the end of what we iterate over. Performance note: the
6594 function pointer `method' used here turns out to be faster than
6595 using a sequence of if-statements. */
6599 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6601 if (it
->what
== IT_CHARACTER
)
6603 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6604 and only if (a) the resolved directionality of that character
6606 /* FIXME: Do we need an exception for characters from display
6608 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6609 it
->c
= bidi_mirror_char (it
->c
);
6610 /* Map via display table or translate control characters.
6611 IT->c, IT->len etc. have been set to the next character by
6612 the function call above. If we have a display table, and it
6613 contains an entry for IT->c, translate it. Don't do this if
6614 IT->c itself comes from a display table, otherwise we could
6615 end up in an infinite recursion. (An alternative could be to
6616 count the recursion depth of this function and signal an
6617 error when a certain maximum depth is reached.) Is it worth
6619 if (success_p
&& it
->dpvec
== NULL
)
6622 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6623 int nonascii_space_p
= 0;
6624 int nonascii_hyphen_p
= 0;
6625 int c
= it
->c
; /* This is the character to display. */
6627 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6629 eassert (SINGLE_BYTE_CHAR_P (c
));
6630 if (unibyte_display_via_language_environment
)
6632 c
= DECODE_CHAR (unibyte
, c
);
6634 c
= BYTE8_TO_CHAR (it
->c
);
6637 c
= BYTE8_TO_CHAR (it
->c
);
6641 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6644 struct Lisp_Vector
*v
= XVECTOR (dv
);
6646 /* Return the first character from the display table
6647 entry, if not empty. If empty, don't display the
6648 current character. */
6651 it
->dpvec_char_len
= it
->len
;
6652 it
->dpvec
= v
->contents
;
6653 it
->dpend
= v
->contents
+ v
->header
.size
;
6654 it
->current
.dpvec_index
= 0;
6655 it
->dpvec_face_id
= -1;
6656 it
->saved_face_id
= it
->face_id
;
6657 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6662 set_iterator_to_next (it
, 0);
6667 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6669 if (it
->what
== IT_GLYPHLESS
)
6671 /* Don't display this character. */
6672 set_iterator_to_next (it
, 0);
6676 /* If `nobreak-char-display' is non-nil, we display
6677 non-ASCII spaces and hyphens specially. */
6678 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6681 nonascii_space_p
= 1;
6682 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6683 nonascii_hyphen_p
= 1;
6686 /* Translate control characters into `\003' or `^C' form.
6687 Control characters coming from a display table entry are
6688 currently not translated because we use IT->dpvec to hold
6689 the translation. This could easily be changed but I
6690 don't believe that it is worth doing.
6692 The characters handled by `nobreak-char-display' must be
6695 Non-printable characters and raw-byte characters are also
6696 translated to octal form. */
6697 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6698 ? (it
->area
!= TEXT_AREA
6699 /* In mode line, treat \n, \t like other crl chars. */
6702 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6703 || (c
!= '\n' && c
!= '\t'))
6705 || nonascii_hyphen_p
6707 || ! CHAR_PRINTABLE_P (c
))))
6709 /* C is a control character, non-ASCII space/hyphen,
6710 raw-byte, or a non-printable character which must be
6711 displayed either as '\003' or as `^C' where the '\\'
6712 and '^' can be defined in the display table. Fill
6713 IT->ctl_chars with glyphs for what we have to
6714 display. Then, set IT->dpvec to these glyphs. */
6721 /* Handle control characters with ^. */
6723 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6727 g
= '^'; /* default glyph for Control */
6728 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6730 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6732 g
= GLYPH_CODE_CHAR (gc
);
6733 lface_id
= GLYPH_CODE_FACE (gc
);
6737 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6739 else if (it
->f
== last_escape_glyph_frame
6740 && it
->face_id
== last_escape_glyph_face_id
)
6742 face_id
= last_escape_glyph_merged_face_id
;
6746 /* Merge the escape-glyph face into the current face. */
6747 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6749 last_escape_glyph_frame
= it
->f
;
6750 last_escape_glyph_face_id
= it
->face_id
;
6751 last_escape_glyph_merged_face_id
= face_id
;
6754 XSETINT (it
->ctl_chars
[0], g
);
6755 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6757 goto display_control
;
6760 /* Handle non-ascii space in the mode where it only gets
6763 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6765 /* Merge `nobreak-space' into the current face. */
6766 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6768 XSETINT (it
->ctl_chars
[0], ' ');
6770 goto display_control
;
6773 /* Handle sequences that start with the "escape glyph". */
6775 /* the default escape glyph is \. */
6776 escape_glyph
= '\\';
6779 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6781 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6782 lface_id
= GLYPH_CODE_FACE (gc
);
6786 /* The display table specified a face.
6787 Merge it into face_id and also into escape_glyph. */
6788 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6791 else if (it
->f
== last_escape_glyph_frame
6792 && it
->face_id
== last_escape_glyph_face_id
)
6794 face_id
= last_escape_glyph_merged_face_id
;
6798 /* Merge the escape-glyph face into the current face. */
6799 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6801 last_escape_glyph_frame
= it
->f
;
6802 last_escape_glyph_face_id
= it
->face_id
;
6803 last_escape_glyph_merged_face_id
= face_id
;
6806 /* Draw non-ASCII hyphen with just highlighting: */
6808 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6810 XSETINT (it
->ctl_chars
[0], '-');
6812 goto display_control
;
6815 /* Draw non-ASCII space/hyphen with escape glyph: */
6817 if (nonascii_space_p
|| nonascii_hyphen_p
)
6819 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6820 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6822 goto display_control
;
6829 if (CHAR_BYTE8_P (c
))
6830 /* Display \200 instead of \17777600. */
6831 c
= CHAR_TO_BYTE8 (c
);
6832 len
= sprintf (str
, "%03o", c
);
6834 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6835 for (i
= 0; i
< len
; i
++)
6836 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6841 /* Set up IT->dpvec and return first character from it. */
6842 it
->dpvec_char_len
= it
->len
;
6843 it
->dpvec
= it
->ctl_chars
;
6844 it
->dpend
= it
->dpvec
+ ctl_len
;
6845 it
->current
.dpvec_index
= 0;
6846 it
->dpvec_face_id
= face_id
;
6847 it
->saved_face_id
= it
->face_id
;
6848 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6852 it
->char_to_display
= c
;
6856 it
->char_to_display
= it
->c
;
6860 /* Adjust face id for a multibyte character. There are no multibyte
6861 character in unibyte text. */
6862 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6865 && FRAME_WINDOW_P (it
->f
))
6867 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6869 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6871 /* Automatic composition with glyph-string. */
6872 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6874 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6878 ptrdiff_t pos
= (it
->s
? -1
6879 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6880 : IT_CHARPOS (*it
));
6883 if (it
->what
== IT_CHARACTER
)
6884 c
= it
->char_to_display
;
6887 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6891 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6892 /* TAB in a composition means display glyphs with
6893 padding space on the left or right. */
6894 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6897 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6902 /* Is this character the last one of a run of characters with
6903 box? If yes, set IT->end_of_box_run_p to 1. */
6907 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6909 int face_id
= underlying_face_id (it
);
6910 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6914 if (face
->box
== FACE_NO_BOX
)
6916 /* If the box comes from face properties in a
6917 display string, check faces in that string. */
6918 int string_face_id
= face_after_it_pos (it
);
6919 it
->end_of_box_run_p
6920 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6923 /* Otherwise, the box comes from the underlying face.
6924 If this is the last string character displayed, check
6925 the next buffer location. */
6926 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6927 && (it
->current
.overlay_string_index
6928 == it
->n_overlay_strings
- 1))
6932 struct text_pos pos
= it
->current
.pos
;
6933 INC_TEXT_POS (pos
, it
->multibyte_p
);
6935 next_face_id
= face_at_buffer_position
6936 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6937 it
->region_end_charpos
, &ignore
,
6938 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6940 it
->end_of_box_run_p
6941 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6948 int face_id
= face_after_it_pos (it
);
6949 it
->end_of_box_run_p
6950 = (face_id
!= it
->face_id
6951 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6954 /* If we reached the end of the object we've been iterating (e.g., a
6955 display string or an overlay string), and there's something on
6956 IT->stack, proceed with what's on the stack. It doesn't make
6957 sense to return zero if there's unprocessed stuff on the stack,
6958 because otherwise that stuff will never be displayed. */
6959 if (!success_p
&& it
->sp
> 0)
6961 set_iterator_to_next (it
, 0);
6962 success_p
= get_next_display_element (it
);
6965 /* Value is 0 if end of buffer or string reached. */
6970 /* Move IT to the next display element.
6972 RESEAT_P non-zero means if called on a newline in buffer text,
6973 skip to the next visible line start.
6975 Functions get_next_display_element and set_iterator_to_next are
6976 separate because I find this arrangement easier to handle than a
6977 get_next_display_element function that also increments IT's
6978 position. The way it is we can first look at an iterator's current
6979 display element, decide whether it fits on a line, and if it does,
6980 increment the iterator position. The other way around we probably
6981 would either need a flag indicating whether the iterator has to be
6982 incremented the next time, or we would have to implement a
6983 decrement position function which would not be easy to write. */
6986 set_iterator_to_next (struct it
*it
, int reseat_p
)
6988 /* Reset flags indicating start and end of a sequence of characters
6989 with box. Reset them at the start of this function because
6990 moving the iterator to a new position might set them. */
6991 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6995 case GET_FROM_BUFFER
:
6996 /* The current display element of IT is a character from
6997 current_buffer. Advance in the buffer, and maybe skip over
6998 invisible lines that are so because of selective display. */
6999 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7000 reseat_at_next_visible_line_start (it
, 0);
7001 else if (it
->cmp_it
.id
>= 0)
7003 /* We are currently getting glyphs from a composition. */
7008 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7009 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7010 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7012 it
->cmp_it
.from
= it
->cmp_it
.to
;
7017 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7019 it
->end_charpos
, Qnil
);
7022 else if (! it
->cmp_it
.reversed_p
)
7024 /* Composition created while scanning forward. */
7025 /* Update IT's char/byte positions to point to the first
7026 character of the next grapheme cluster, or to the
7027 character visually after the current composition. */
7028 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7029 bidi_move_to_visually_next (&it
->bidi_it
);
7030 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7031 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7033 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7035 /* Proceed to the next grapheme cluster. */
7036 it
->cmp_it
.from
= it
->cmp_it
.to
;
7040 /* No more grapheme clusters in this composition.
7041 Find the next stop position. */
7042 ptrdiff_t stop
= it
->end_charpos
;
7043 if (it
->bidi_it
.scan_dir
< 0)
7044 /* Now we are scanning backward and don't know
7047 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7048 IT_BYTEPOS (*it
), stop
, Qnil
);
7053 /* Composition created while scanning backward. */
7054 /* Update IT's char/byte positions to point to the last
7055 character of the previous grapheme cluster, or the
7056 character visually after the current composition. */
7057 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7058 bidi_move_to_visually_next (&it
->bidi_it
);
7059 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7060 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7061 if (it
->cmp_it
.from
> 0)
7063 /* Proceed to the previous grapheme cluster. */
7064 it
->cmp_it
.to
= it
->cmp_it
.from
;
7068 /* No more grapheme clusters in this composition.
7069 Find the next stop position. */
7070 ptrdiff_t stop
= it
->end_charpos
;
7071 if (it
->bidi_it
.scan_dir
< 0)
7072 /* Now we are scanning backward and don't know
7075 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7076 IT_BYTEPOS (*it
), stop
, Qnil
);
7082 eassert (it
->len
!= 0);
7086 IT_BYTEPOS (*it
) += it
->len
;
7087 IT_CHARPOS (*it
) += 1;
7091 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7092 /* If this is a new paragraph, determine its base
7093 direction (a.k.a. its base embedding level). */
7094 if (it
->bidi_it
.new_paragraph
)
7095 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7096 bidi_move_to_visually_next (&it
->bidi_it
);
7097 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7098 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7099 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7101 /* As the scan direction was changed, we must
7102 re-compute the stop position for composition. */
7103 ptrdiff_t stop
= it
->end_charpos
;
7104 if (it
->bidi_it
.scan_dir
< 0)
7106 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7107 IT_BYTEPOS (*it
), stop
, Qnil
);
7110 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7114 case GET_FROM_C_STRING
:
7115 /* Current display element of IT is from a C string. */
7117 /* If the string position is beyond string's end, it means
7118 next_element_from_c_string is padding the string with
7119 blanks, in which case we bypass the bidi iterator,
7120 because it cannot deal with such virtual characters. */
7121 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7123 IT_BYTEPOS (*it
) += it
->len
;
7124 IT_CHARPOS (*it
) += 1;
7128 bidi_move_to_visually_next (&it
->bidi_it
);
7129 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7130 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7134 case GET_FROM_DISPLAY_VECTOR
:
7135 /* Current display element of IT is from a display table entry.
7136 Advance in the display table definition. Reset it to null if
7137 end reached, and continue with characters from buffers/
7139 ++it
->current
.dpvec_index
;
7141 /* Restore face of the iterator to what they were before the
7142 display vector entry (these entries may contain faces). */
7143 it
->face_id
= it
->saved_face_id
;
7145 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7147 int recheck_faces
= it
->ellipsis_p
;
7150 it
->method
= GET_FROM_C_STRING
;
7151 else if (STRINGP (it
->string
))
7152 it
->method
= GET_FROM_STRING
;
7155 it
->method
= GET_FROM_BUFFER
;
7156 it
->object
= it
->w
->contents
;
7160 it
->current
.dpvec_index
= -1;
7162 /* Skip over characters which were displayed via IT->dpvec. */
7163 if (it
->dpvec_char_len
< 0)
7164 reseat_at_next_visible_line_start (it
, 1);
7165 else if (it
->dpvec_char_len
> 0)
7167 if (it
->method
== GET_FROM_STRING
7168 && it
->current
.overlay_string_index
>= 0
7169 && it
->n_overlay_strings
> 0)
7170 it
->ignore_overlay_strings_at_pos_p
= 1;
7171 it
->len
= it
->dpvec_char_len
;
7172 set_iterator_to_next (it
, reseat_p
);
7175 /* Maybe recheck faces after display vector */
7177 it
->stop_charpos
= IT_CHARPOS (*it
);
7181 case GET_FROM_STRING
:
7182 /* Current display element is a character from a Lisp string. */
7183 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7184 /* Don't advance past string end. These conditions are true
7185 when set_iterator_to_next is called at the end of
7186 get_next_display_element, in which case the Lisp string is
7187 already exhausted, and all we want is pop the iterator
7189 if (it
->current
.overlay_string_index
>= 0)
7191 /* This is an overlay string, so there's no padding with
7192 spaces, and the number of characters in the string is
7193 where the string ends. */
7194 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7195 goto consider_string_end
;
7199 /* Not an overlay string. There could be padding, so test
7200 against it->end_charpos . */
7201 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7202 goto consider_string_end
;
7204 if (it
->cmp_it
.id
>= 0)
7210 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7211 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7212 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7213 it
->cmp_it
.from
= it
->cmp_it
.to
;
7217 composition_compute_stop_pos (&it
->cmp_it
,
7218 IT_STRING_CHARPOS (*it
),
7219 IT_STRING_BYTEPOS (*it
),
7220 it
->end_charpos
, it
->string
);
7223 else if (! it
->cmp_it
.reversed_p
)
7225 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7226 bidi_move_to_visually_next (&it
->bidi_it
);
7227 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7228 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7230 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7231 it
->cmp_it
.from
= it
->cmp_it
.to
;
7234 ptrdiff_t stop
= it
->end_charpos
;
7235 if (it
->bidi_it
.scan_dir
< 0)
7237 composition_compute_stop_pos (&it
->cmp_it
,
7238 IT_STRING_CHARPOS (*it
),
7239 IT_STRING_BYTEPOS (*it
), stop
,
7245 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7246 bidi_move_to_visually_next (&it
->bidi_it
);
7247 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7248 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7249 if (it
->cmp_it
.from
> 0)
7250 it
->cmp_it
.to
= it
->cmp_it
.from
;
7253 ptrdiff_t stop
= it
->end_charpos
;
7254 if (it
->bidi_it
.scan_dir
< 0)
7256 composition_compute_stop_pos (&it
->cmp_it
,
7257 IT_STRING_CHARPOS (*it
),
7258 IT_STRING_BYTEPOS (*it
), stop
,
7266 /* If the string position is beyond string's end, it
7267 means next_element_from_string is padding the string
7268 with blanks, in which case we bypass the bidi
7269 iterator, because it cannot deal with such virtual
7271 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7273 IT_STRING_BYTEPOS (*it
) += it
->len
;
7274 IT_STRING_CHARPOS (*it
) += 1;
7278 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7280 bidi_move_to_visually_next (&it
->bidi_it
);
7281 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7282 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7283 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7285 ptrdiff_t stop
= it
->end_charpos
;
7287 if (it
->bidi_it
.scan_dir
< 0)
7289 composition_compute_stop_pos (&it
->cmp_it
,
7290 IT_STRING_CHARPOS (*it
),
7291 IT_STRING_BYTEPOS (*it
), stop
,
7297 consider_string_end
:
7299 if (it
->current
.overlay_string_index
>= 0)
7301 /* IT->string is an overlay string. Advance to the
7302 next, if there is one. */
7303 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7306 next_overlay_string (it
);
7308 setup_for_ellipsis (it
, 0);
7313 /* IT->string is not an overlay string. If we reached
7314 its end, and there is something on IT->stack, proceed
7315 with what is on the stack. This can be either another
7316 string, this time an overlay string, or a buffer. */
7317 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7321 if (it
->method
== GET_FROM_STRING
)
7322 goto consider_string_end
;
7327 case GET_FROM_IMAGE
:
7328 case GET_FROM_STRETCH
:
7329 /* The position etc with which we have to proceed are on
7330 the stack. The position may be at the end of a string,
7331 if the `display' property takes up the whole string. */
7332 eassert (it
->sp
> 0);
7334 if (it
->method
== GET_FROM_STRING
)
7335 goto consider_string_end
;
7339 /* There are no other methods defined, so this should be a bug. */
7343 eassert (it
->method
!= GET_FROM_STRING
7344 || (STRINGP (it
->string
)
7345 && IT_STRING_CHARPOS (*it
) >= 0));
7348 /* Load IT's display element fields with information about the next
7349 display element which comes from a display table entry or from the
7350 result of translating a control character to one of the forms `^C'
7353 IT->dpvec holds the glyphs to return as characters.
7354 IT->saved_face_id holds the face id before the display vector--it
7355 is restored into IT->face_id in set_iterator_to_next. */
7358 next_element_from_display_vector (struct it
*it
)
7363 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7365 it
->face_id
= it
->saved_face_id
;
7367 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7368 That seemed totally bogus - so I changed it... */
7369 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7371 if (GLYPH_CODE_P (gc
))
7373 it
->c
= GLYPH_CODE_CHAR (gc
);
7374 it
->len
= CHAR_BYTES (it
->c
);
7376 /* The entry may contain a face id to use. Such a face id is
7377 the id of a Lisp face, not a realized face. A face id of
7378 zero means no face is specified. */
7379 if (it
->dpvec_face_id
>= 0)
7380 it
->face_id
= it
->dpvec_face_id
;
7383 int lface_id
= GLYPH_CODE_FACE (gc
);
7385 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7390 /* Display table entry is invalid. Return a space. */
7391 it
->c
= ' ', it
->len
= 1;
7393 /* Don't change position and object of the iterator here. They are
7394 still the values of the character that had this display table
7395 entry or was translated, and that's what we want. */
7396 it
->what
= IT_CHARACTER
;
7400 /* Get the first element of string/buffer in the visual order, after
7401 being reseated to a new position in a string or a buffer. */
7403 get_visually_first_element (struct it
*it
)
7405 int string_p
= STRINGP (it
->string
) || it
->s
;
7406 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7407 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7409 if (STRINGP (it
->string
))
7411 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7412 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7416 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7417 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7420 if (it
->bidi_it
.charpos
== eob
)
7422 /* Nothing to do, but reset the FIRST_ELT flag, like
7423 bidi_paragraph_init does, because we are not going to
7425 it
->bidi_it
.first_elt
= 0;
7427 else if (it
->bidi_it
.charpos
== bob
7429 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7430 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7432 /* If we are at the beginning of a line/string, we can produce
7433 the next element right away. */
7434 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7435 bidi_move_to_visually_next (&it
->bidi_it
);
7439 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7441 /* We need to prime the bidi iterator starting at the line's or
7442 string's beginning, before we will be able to produce the
7445 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7447 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7448 IT_BYTEPOS (*it
), -1,
7449 &it
->bidi_it
.bytepos
);
7450 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7453 /* Now return to buffer/string position where we were asked
7454 to get the next display element, and produce that. */
7455 bidi_move_to_visually_next (&it
->bidi_it
);
7457 while (it
->bidi_it
.bytepos
!= orig_bytepos
7458 && it
->bidi_it
.charpos
< eob
);
7461 /* Adjust IT's position information to where we ended up. */
7462 if (STRINGP (it
->string
))
7464 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7465 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7469 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7470 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7473 if (STRINGP (it
->string
) || !it
->s
)
7475 ptrdiff_t stop
, charpos
, bytepos
;
7477 if (STRINGP (it
->string
))
7480 stop
= SCHARS (it
->string
);
7481 if (stop
> it
->end_charpos
)
7482 stop
= it
->end_charpos
;
7483 charpos
= IT_STRING_CHARPOS (*it
);
7484 bytepos
= IT_STRING_BYTEPOS (*it
);
7488 stop
= it
->end_charpos
;
7489 charpos
= IT_CHARPOS (*it
);
7490 bytepos
= IT_BYTEPOS (*it
);
7492 if (it
->bidi_it
.scan_dir
< 0)
7494 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7499 /* Load IT with the next display element from Lisp string IT->string.
7500 IT->current.string_pos is the current position within the string.
7501 If IT->current.overlay_string_index >= 0, the Lisp string is an
7505 next_element_from_string (struct it
*it
)
7507 struct text_pos position
;
7509 eassert (STRINGP (it
->string
));
7510 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7511 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7512 position
= it
->current
.string_pos
;
7514 /* With bidi reordering, the character to display might not be the
7515 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7516 that we were reseat()ed to a new string, whose paragraph
7517 direction is not known. */
7518 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7520 get_visually_first_element (it
);
7521 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7524 /* Time to check for invisible text? */
7525 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7527 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7530 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7531 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7533 /* With bidi non-linear iteration, we could find
7534 ourselves far beyond the last computed stop_charpos,
7535 with several other stop positions in between that we
7536 missed. Scan them all now, in buffer's logical
7537 order, until we find and handle the last stop_charpos
7538 that precedes our current position. */
7539 handle_stop_backwards (it
, it
->stop_charpos
);
7540 return GET_NEXT_DISPLAY_ELEMENT (it
);
7546 /* Take note of the stop position we just moved
7547 across, for when we will move back across it. */
7548 it
->prev_stop
= it
->stop_charpos
;
7549 /* If we are at base paragraph embedding level, take
7550 note of the last stop position seen at this
7552 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7553 it
->base_level_stop
= it
->stop_charpos
;
7557 /* Since a handler may have changed IT->method, we must
7559 return GET_NEXT_DISPLAY_ELEMENT (it
);
7563 /* If we are before prev_stop, we may have overstepped
7564 on our way backwards a stop_pos, and if so, we need
7565 to handle that stop_pos. */
7566 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7567 /* We can sometimes back up for reasons that have nothing
7568 to do with bidi reordering. E.g., compositions. The
7569 code below is only needed when we are above the base
7570 embedding level, so test for that explicitly. */
7571 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7573 /* If we lost track of base_level_stop, we have no better
7574 place for handle_stop_backwards to start from than string
7575 beginning. This happens, e.g., when we were reseated to
7576 the previous screenful of text by vertical-motion. */
7577 if (it
->base_level_stop
<= 0
7578 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7579 it
->base_level_stop
= 0;
7580 handle_stop_backwards (it
, it
->base_level_stop
);
7581 return GET_NEXT_DISPLAY_ELEMENT (it
);
7585 if (it
->current
.overlay_string_index
>= 0)
7587 /* Get the next character from an overlay string. In overlay
7588 strings, there is no field width or padding with spaces to
7590 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7595 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7596 IT_STRING_BYTEPOS (*it
),
7597 it
->bidi_it
.scan_dir
< 0
7599 : SCHARS (it
->string
))
7600 && next_element_from_composition (it
))
7604 else if (STRING_MULTIBYTE (it
->string
))
7606 const unsigned char *s
= (SDATA (it
->string
)
7607 + IT_STRING_BYTEPOS (*it
));
7608 it
->c
= string_char_and_length (s
, &it
->len
);
7612 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7618 /* Get the next character from a Lisp string that is not an
7619 overlay string. Such strings come from the mode line, for
7620 example. We may have to pad with spaces, or truncate the
7621 string. See also next_element_from_c_string. */
7622 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7627 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7629 /* Pad with spaces. */
7630 it
->c
= ' ', it
->len
= 1;
7631 CHARPOS (position
) = BYTEPOS (position
) = -1;
7633 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7634 IT_STRING_BYTEPOS (*it
),
7635 it
->bidi_it
.scan_dir
< 0
7637 : it
->string_nchars
)
7638 && next_element_from_composition (it
))
7642 else if (STRING_MULTIBYTE (it
->string
))
7644 const unsigned char *s
= (SDATA (it
->string
)
7645 + IT_STRING_BYTEPOS (*it
));
7646 it
->c
= string_char_and_length (s
, &it
->len
);
7650 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7655 /* Record what we have and where it came from. */
7656 it
->what
= IT_CHARACTER
;
7657 it
->object
= it
->string
;
7658 it
->position
= position
;
7663 /* Load IT with next display element from C string IT->s.
7664 IT->string_nchars is the maximum number of characters to return
7665 from the string. IT->end_charpos may be greater than
7666 IT->string_nchars when this function is called, in which case we
7667 may have to return padding spaces. Value is zero if end of string
7668 reached, including padding spaces. */
7671 next_element_from_c_string (struct it
*it
)
7676 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7677 it
->what
= IT_CHARACTER
;
7678 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7681 /* With bidi reordering, the character to display might not be the
7682 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7683 we were reseated to a new string, whose paragraph direction is
7685 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7686 get_visually_first_element (it
);
7688 /* IT's position can be greater than IT->string_nchars in case a
7689 field width or precision has been specified when the iterator was
7691 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7693 /* End of the game. */
7697 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7699 /* Pad with spaces. */
7700 it
->c
= ' ', it
->len
= 1;
7701 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7703 else if (it
->multibyte_p
)
7704 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7706 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7712 /* Set up IT to return characters from an ellipsis, if appropriate.
7713 The definition of the ellipsis glyphs may come from a display table
7714 entry. This function fills IT with the first glyph from the
7715 ellipsis if an ellipsis is to be displayed. */
7718 next_element_from_ellipsis (struct it
*it
)
7720 if (it
->selective_display_ellipsis_p
)
7721 setup_for_ellipsis (it
, it
->len
);
7724 /* The face at the current position may be different from the
7725 face we find after the invisible text. Remember what it
7726 was in IT->saved_face_id, and signal that it's there by
7727 setting face_before_selective_p. */
7728 it
->saved_face_id
= it
->face_id
;
7729 it
->method
= GET_FROM_BUFFER
;
7730 it
->object
= it
->w
->contents
;
7731 reseat_at_next_visible_line_start (it
, 1);
7732 it
->face_before_selective_p
= 1;
7735 return GET_NEXT_DISPLAY_ELEMENT (it
);
7739 /* Deliver an image display element. The iterator IT is already
7740 filled with image information (done in handle_display_prop). Value
7745 next_element_from_image (struct it
*it
)
7747 it
->what
= IT_IMAGE
;
7748 it
->ignore_overlay_strings_at_pos_p
= 0;
7753 /* Fill iterator IT with next display element from a stretch glyph
7754 property. IT->object is the value of the text property. Value is
7758 next_element_from_stretch (struct it
*it
)
7760 it
->what
= IT_STRETCH
;
7764 /* Scan backwards from IT's current position until we find a stop
7765 position, or until BEGV. This is called when we find ourself
7766 before both the last known prev_stop and base_level_stop while
7767 reordering bidirectional text. */
7770 compute_stop_pos_backwards (struct it
*it
)
7772 const int SCAN_BACK_LIMIT
= 1000;
7773 struct text_pos pos
;
7774 struct display_pos save_current
= it
->current
;
7775 struct text_pos save_position
= it
->position
;
7776 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7777 ptrdiff_t where_we_are
= charpos
;
7778 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7779 ptrdiff_t save_end_pos
= it
->end_charpos
;
7781 eassert (NILP (it
->string
) && !it
->s
);
7782 eassert (it
->bidi_p
);
7786 it
->end_charpos
= min (charpos
+ 1, ZV
);
7787 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7788 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7789 reseat_1 (it
, pos
, 0);
7790 compute_stop_pos (it
);
7791 /* We must advance forward, right? */
7792 if (it
->stop_charpos
<= charpos
)
7795 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7797 if (it
->stop_charpos
<= where_we_are
)
7798 it
->prev_stop
= it
->stop_charpos
;
7800 it
->prev_stop
= BEGV
;
7802 it
->current
= save_current
;
7803 it
->position
= save_position
;
7804 it
->stop_charpos
= save_stop_pos
;
7805 it
->end_charpos
= save_end_pos
;
7808 /* Scan forward from CHARPOS in the current buffer/string, until we
7809 find a stop position > current IT's position. Then handle the stop
7810 position before that. This is called when we bump into a stop
7811 position while reordering bidirectional text. CHARPOS should be
7812 the last previously processed stop_pos (or BEGV/0, if none were
7813 processed yet) whose position is less that IT's current
7817 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7819 int bufp
= !STRINGP (it
->string
);
7820 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7821 struct display_pos save_current
= it
->current
;
7822 struct text_pos save_position
= it
->position
;
7823 struct text_pos pos1
;
7824 ptrdiff_t next_stop
;
7826 /* Scan in strict logical order. */
7827 eassert (it
->bidi_p
);
7831 it
->prev_stop
= charpos
;
7834 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7835 reseat_1 (it
, pos1
, 0);
7838 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7839 compute_stop_pos (it
);
7840 /* We must advance forward, right? */
7841 if (it
->stop_charpos
<= it
->prev_stop
)
7843 charpos
= it
->stop_charpos
;
7845 while (charpos
<= where_we_are
);
7848 it
->current
= save_current
;
7849 it
->position
= save_position
;
7850 next_stop
= it
->stop_charpos
;
7851 it
->stop_charpos
= it
->prev_stop
;
7853 it
->stop_charpos
= next_stop
;
7856 /* Load IT with the next display element from current_buffer. Value
7857 is zero if end of buffer reached. IT->stop_charpos is the next
7858 position at which to stop and check for text properties or buffer
7862 next_element_from_buffer (struct it
*it
)
7866 eassert (IT_CHARPOS (*it
) >= BEGV
);
7867 eassert (NILP (it
->string
) && !it
->s
);
7868 eassert (!it
->bidi_p
7869 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7870 && it
->bidi_it
.string
.s
== NULL
));
7872 /* With bidi reordering, the character to display might not be the
7873 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7874 we were reseat()ed to a new buffer position, which is potentially
7875 a different paragraph. */
7876 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7878 get_visually_first_element (it
);
7879 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7882 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7884 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7886 int overlay_strings_follow_p
;
7888 /* End of the game, except when overlay strings follow that
7889 haven't been returned yet. */
7890 if (it
->overlay_strings_at_end_processed_p
)
7891 overlay_strings_follow_p
= 0;
7894 it
->overlay_strings_at_end_processed_p
= 1;
7895 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7898 if (overlay_strings_follow_p
)
7899 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7903 it
->position
= it
->current
.pos
;
7907 else if (!(!it
->bidi_p
7908 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7909 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7911 /* With bidi non-linear iteration, we could find ourselves
7912 far beyond the last computed stop_charpos, with several
7913 other stop positions in between that we missed. Scan
7914 them all now, in buffer's logical order, until we find
7915 and handle the last stop_charpos that precedes our
7916 current position. */
7917 handle_stop_backwards (it
, it
->stop_charpos
);
7918 return GET_NEXT_DISPLAY_ELEMENT (it
);
7924 /* Take note of the stop position we just moved across,
7925 for when we will move back across it. */
7926 it
->prev_stop
= it
->stop_charpos
;
7927 /* If we are at base paragraph embedding level, take
7928 note of the last stop position seen at this
7930 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7931 it
->base_level_stop
= it
->stop_charpos
;
7934 return GET_NEXT_DISPLAY_ELEMENT (it
);
7938 /* If we are before prev_stop, we may have overstepped on
7939 our way backwards a stop_pos, and if so, we need to
7940 handle that stop_pos. */
7941 && IT_CHARPOS (*it
) < it
->prev_stop
7942 /* We can sometimes back up for reasons that have nothing
7943 to do with bidi reordering. E.g., compositions. The
7944 code below is only needed when we are above the base
7945 embedding level, so test for that explicitly. */
7946 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7948 if (it
->base_level_stop
<= 0
7949 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7951 /* If we lost track of base_level_stop, we need to find
7952 prev_stop by looking backwards. This happens, e.g., when
7953 we were reseated to the previous screenful of text by
7955 it
->base_level_stop
= BEGV
;
7956 compute_stop_pos_backwards (it
);
7957 handle_stop_backwards (it
, it
->prev_stop
);
7960 handle_stop_backwards (it
, it
->base_level_stop
);
7961 return GET_NEXT_DISPLAY_ELEMENT (it
);
7965 /* No face changes, overlays etc. in sight, so just return a
7966 character from current_buffer. */
7970 /* Maybe run the redisplay end trigger hook. Performance note:
7971 This doesn't seem to cost measurable time. */
7972 if (it
->redisplay_end_trigger_charpos
7974 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7975 run_redisplay_end_trigger_hook (it
);
7977 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7978 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7980 && next_element_from_composition (it
))
7985 /* Get the next character, maybe multibyte. */
7986 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7987 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7988 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7990 it
->c
= *p
, it
->len
= 1;
7992 /* Record what we have and where it came from. */
7993 it
->what
= IT_CHARACTER
;
7994 it
->object
= it
->w
->contents
;
7995 it
->position
= it
->current
.pos
;
7997 /* Normally we return the character found above, except when we
7998 really want to return an ellipsis for selective display. */
8003 /* A value of selective > 0 means hide lines indented more
8004 than that number of columns. */
8005 if (it
->selective
> 0
8006 && IT_CHARPOS (*it
) + 1 < ZV
8007 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8008 IT_BYTEPOS (*it
) + 1,
8011 success_p
= next_element_from_ellipsis (it
);
8012 it
->dpvec_char_len
= -1;
8015 else if (it
->c
== '\r' && it
->selective
== -1)
8017 /* A value of selective == -1 means that everything from the
8018 CR to the end of the line is invisible, with maybe an
8019 ellipsis displayed for it. */
8020 success_p
= next_element_from_ellipsis (it
);
8021 it
->dpvec_char_len
= -1;
8026 /* Value is zero if end of buffer reached. */
8027 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8032 /* Run the redisplay end trigger hook for IT. */
8035 run_redisplay_end_trigger_hook (struct it
*it
)
8037 Lisp_Object args
[3];
8039 /* IT->glyph_row should be non-null, i.e. we should be actually
8040 displaying something, or otherwise we should not run the hook. */
8041 eassert (it
->glyph_row
);
8043 /* Set up hook arguments. */
8044 args
[0] = Qredisplay_end_trigger_functions
;
8045 args
[1] = it
->window
;
8046 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8047 it
->redisplay_end_trigger_charpos
= 0;
8049 /* Since we are *trying* to run these functions, don't try to run
8050 them again, even if they get an error. */
8051 wset_redisplay_end_trigger (it
->w
, Qnil
);
8052 Frun_hook_with_args (3, args
);
8054 /* Notice if it changed the face of the character we are on. */
8055 handle_face_prop (it
);
8059 /* Deliver a composition display element. Unlike the other
8060 next_element_from_XXX, this function is not registered in the array
8061 get_next_element[]. It is called from next_element_from_buffer and
8062 next_element_from_string when necessary. */
8065 next_element_from_composition (struct it
*it
)
8067 it
->what
= IT_COMPOSITION
;
8068 it
->len
= it
->cmp_it
.nbytes
;
8069 if (STRINGP (it
->string
))
8073 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8074 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8077 it
->position
= it
->current
.string_pos
;
8078 it
->object
= it
->string
;
8079 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8080 IT_STRING_BYTEPOS (*it
), it
->string
);
8086 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8087 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8090 if (it
->bidi_it
.new_paragraph
)
8091 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8092 /* Resync the bidi iterator with IT's new position.
8093 FIXME: this doesn't support bidirectional text. */
8094 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8095 bidi_move_to_visually_next (&it
->bidi_it
);
8099 it
->position
= it
->current
.pos
;
8100 it
->object
= it
->w
->contents
;
8101 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8102 IT_BYTEPOS (*it
), Qnil
);
8109 /***********************************************************************
8110 Moving an iterator without producing glyphs
8111 ***********************************************************************/
8113 /* Check if iterator is at a position corresponding to a valid buffer
8114 position after some move_it_ call. */
8116 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8117 ((it)->method == GET_FROM_STRING \
8118 ? IT_STRING_CHARPOS (*it) == 0 \
8122 /* Move iterator IT to a specified buffer or X position within one
8123 line on the display without producing glyphs.
8125 OP should be a bit mask including some or all of these bits:
8126 MOVE_TO_X: Stop upon reaching x-position TO_X.
8127 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8128 Regardless of OP's value, stop upon reaching the end of the display line.
8130 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8131 This means, in particular, that TO_X includes window's horizontal
8134 The return value has several possible values that
8135 say what condition caused the scan to stop:
8137 MOVE_POS_MATCH_OR_ZV
8138 - when TO_POS or ZV was reached.
8141 -when TO_X was reached before TO_POS or ZV were reached.
8144 - when we reached the end of the display area and the line must
8148 - when we reached the end of the display area and the line is
8152 - when we stopped at a line end, i.e. a newline or a CR and selective
8155 static enum move_it_result
8156 move_it_in_display_line_to (struct it
*it
,
8157 ptrdiff_t to_charpos
, int to_x
,
8158 enum move_operation_enum op
)
8160 enum move_it_result result
= MOVE_UNDEFINED
;
8161 struct glyph_row
*saved_glyph_row
;
8162 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8163 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8164 void *ppos_data
= NULL
;
8166 enum it_method prev_method
= it
->method
;
8167 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8168 int saw_smaller_pos
= prev_pos
< to_charpos
;
8170 /* Don't produce glyphs in produce_glyphs. */
8171 saved_glyph_row
= it
->glyph_row
;
8172 it
->glyph_row
= NULL
;
8174 /* Use wrap_it to save a copy of IT wherever a word wrap could
8175 occur. Use atpos_it to save a copy of IT at the desired buffer
8176 position, if found, so that we can scan ahead and check if the
8177 word later overshoots the window edge. Use atx_it similarly, for
8183 /* Use ppos_it under bidi reordering to save a copy of IT for the
8184 position > CHARPOS that is the closest to CHARPOS. We restore
8185 that position in IT when we have scanned the entire display line
8186 without finding a match for CHARPOS and all the character
8187 positions are greater than CHARPOS. */
8190 SAVE_IT (ppos_it
, *it
, ppos_data
);
8191 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8192 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8193 SAVE_IT (ppos_it
, *it
, ppos_data
);
8196 #define BUFFER_POS_REACHED_P() \
8197 ((op & MOVE_TO_POS) != 0 \
8198 && BUFFERP (it->object) \
8199 && (IT_CHARPOS (*it) == to_charpos \
8201 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8202 && IT_CHARPOS (*it) > to_charpos) \
8203 || (it->what == IT_COMPOSITION \
8204 && ((IT_CHARPOS (*it) > to_charpos \
8205 && to_charpos >= it->cmp_it.charpos) \
8206 || (IT_CHARPOS (*it) < to_charpos \
8207 && to_charpos <= it->cmp_it.charpos)))) \
8208 && (it->method == GET_FROM_BUFFER \
8209 || (it->method == GET_FROM_DISPLAY_VECTOR \
8210 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8212 /* If there's a line-/wrap-prefix, handle it. */
8213 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8214 && it
->current_y
< it
->last_visible_y
)
8215 handle_line_prefix (it
);
8217 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8218 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8222 int x
, i
, ascent
= 0, descent
= 0;
8224 /* Utility macro to reset an iterator with x, ascent, and descent. */
8225 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8226 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8227 (IT)->max_descent = descent)
8229 /* Stop if we move beyond TO_CHARPOS (after an image or a
8230 display string or stretch glyph). */
8231 if ((op
& MOVE_TO_POS
) != 0
8232 && BUFFERP (it
->object
)
8233 && it
->method
== GET_FROM_BUFFER
8235 /* When the iterator is at base embedding level, we
8236 are guaranteed that characters are delivered for
8237 display in strictly increasing order of their
8238 buffer positions. */
8239 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8240 && IT_CHARPOS (*it
) > to_charpos
)
8242 && (prev_method
== GET_FROM_IMAGE
8243 || prev_method
== GET_FROM_STRETCH
8244 || prev_method
== GET_FROM_STRING
)
8245 /* Passed TO_CHARPOS from left to right. */
8246 && ((prev_pos
< to_charpos
8247 && IT_CHARPOS (*it
) > to_charpos
)
8248 /* Passed TO_CHARPOS from right to left. */
8249 || (prev_pos
> to_charpos
8250 && IT_CHARPOS (*it
) < to_charpos
)))))
8252 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8254 result
= MOVE_POS_MATCH_OR_ZV
;
8257 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8258 /* If wrap_it is valid, the current position might be in a
8259 word that is wrapped. So, save the iterator in
8260 atpos_it and continue to see if wrapping happens. */
8261 SAVE_IT (atpos_it
, *it
, atpos_data
);
8264 /* Stop when ZV reached.
8265 We used to stop here when TO_CHARPOS reached as well, but that is
8266 too soon if this glyph does not fit on this line. So we handle it
8267 explicitly below. */
8268 if (!get_next_display_element (it
))
8270 result
= MOVE_POS_MATCH_OR_ZV
;
8274 if (it
->line_wrap
== TRUNCATE
)
8276 if (BUFFER_POS_REACHED_P ())
8278 result
= MOVE_POS_MATCH_OR_ZV
;
8284 if (it
->line_wrap
== WORD_WRAP
)
8286 if (IT_DISPLAYING_WHITESPACE (it
))
8290 /* We have reached a glyph that follows one or more
8291 whitespace characters. If the position is
8292 already found, we are done. */
8293 if (atpos_it
.sp
>= 0)
8295 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8296 result
= MOVE_POS_MATCH_OR_ZV
;
8301 RESTORE_IT (it
, &atx_it
, atx_data
);
8302 result
= MOVE_X_REACHED
;
8305 /* Otherwise, we can wrap here. */
8306 SAVE_IT (wrap_it
, *it
, wrap_data
);
8312 /* Remember the line height for the current line, in case
8313 the next element doesn't fit on the line. */
8314 ascent
= it
->max_ascent
;
8315 descent
= it
->max_descent
;
8317 /* The call to produce_glyphs will get the metrics of the
8318 display element IT is loaded with. Record the x-position
8319 before this display element, in case it doesn't fit on the
8323 PRODUCE_GLYPHS (it
);
8325 if (it
->area
!= TEXT_AREA
)
8327 prev_method
= it
->method
;
8328 if (it
->method
== GET_FROM_BUFFER
)
8329 prev_pos
= IT_CHARPOS (*it
);
8330 set_iterator_to_next (it
, 1);
8331 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8332 SET_TEXT_POS (this_line_min_pos
,
8333 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8335 && (op
& MOVE_TO_POS
)
8336 && IT_CHARPOS (*it
) > to_charpos
8337 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8338 SAVE_IT (ppos_it
, *it
, ppos_data
);
8342 /* The number of glyphs we get back in IT->nglyphs will normally
8343 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8344 character on a terminal frame, or (iii) a line end. For the
8345 second case, IT->nglyphs - 1 padding glyphs will be present.
8346 (On X frames, there is only one glyph produced for a
8347 composite character.)
8349 The behavior implemented below means, for continuation lines,
8350 that as many spaces of a TAB as fit on the current line are
8351 displayed there. For terminal frames, as many glyphs of a
8352 multi-glyph character are displayed in the current line, too.
8353 This is what the old redisplay code did, and we keep it that
8354 way. Under X, the whole shape of a complex character must
8355 fit on the line or it will be completely displayed in the
8358 Note that both for tabs and padding glyphs, all glyphs have
8362 /* More than one glyph or glyph doesn't fit on line. All
8363 glyphs have the same width. */
8364 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8366 int x_before_this_char
= x
;
8367 int hpos_before_this_char
= it
->hpos
;
8369 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8371 new_x
= x
+ single_glyph_width
;
8373 /* We want to leave anything reaching TO_X to the caller. */
8374 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8376 if (BUFFER_POS_REACHED_P ())
8378 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8379 goto buffer_pos_reached
;
8380 if (atpos_it
.sp
< 0)
8382 SAVE_IT (atpos_it
, *it
, atpos_data
);
8383 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8388 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8391 result
= MOVE_X_REACHED
;
8396 SAVE_IT (atx_it
, *it
, atx_data
);
8397 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8402 if (/* Lines are continued. */
8403 it
->line_wrap
!= TRUNCATE
8404 && (/* And glyph doesn't fit on the line. */
8405 new_x
> it
->last_visible_x
8406 /* Or it fits exactly and we're on a window
8408 || (new_x
== it
->last_visible_x
8409 && FRAME_WINDOW_P (it
->f
)
8410 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8411 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8412 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8414 if (/* IT->hpos == 0 means the very first glyph
8415 doesn't fit on the line, e.g. a wide image. */
8417 || (new_x
== it
->last_visible_x
8418 && FRAME_WINDOW_P (it
->f
)))
8421 it
->current_x
= new_x
;
8423 /* The character's last glyph just barely fits
8425 if (i
== it
->nglyphs
- 1)
8427 /* If this is the destination position,
8428 return a position *before* it in this row,
8429 now that we know it fits in this row. */
8430 if (BUFFER_POS_REACHED_P ())
8432 if (it
->line_wrap
!= WORD_WRAP
8435 it
->hpos
= hpos_before_this_char
;
8436 it
->current_x
= x_before_this_char
;
8437 result
= MOVE_POS_MATCH_OR_ZV
;
8440 if (it
->line_wrap
== WORD_WRAP
8443 SAVE_IT (atpos_it
, *it
, atpos_data
);
8444 atpos_it
.current_x
= x_before_this_char
;
8445 atpos_it
.hpos
= hpos_before_this_char
;
8449 prev_method
= it
->method
;
8450 if (it
->method
== GET_FROM_BUFFER
)
8451 prev_pos
= IT_CHARPOS (*it
);
8452 set_iterator_to_next (it
, 1);
8453 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8454 SET_TEXT_POS (this_line_min_pos
,
8455 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8456 /* On graphical terminals, newlines may
8457 "overflow" into the fringe if
8458 overflow-newline-into-fringe is non-nil.
8459 On text terminals, and on graphical
8460 terminals with no right margin, newlines
8461 may overflow into the last glyph on the
8463 if (!FRAME_WINDOW_P (it
->f
)
8465 && it
->bidi_it
.paragraph_dir
== R2L
)
8466 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8467 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8468 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8470 if (!get_next_display_element (it
))
8472 result
= MOVE_POS_MATCH_OR_ZV
;
8475 if (BUFFER_POS_REACHED_P ())
8477 if (ITERATOR_AT_END_OF_LINE_P (it
))
8478 result
= MOVE_POS_MATCH_OR_ZV
;
8480 result
= MOVE_LINE_CONTINUED
;
8483 if (ITERATOR_AT_END_OF_LINE_P (it
))
8485 result
= MOVE_NEWLINE_OR_CR
;
8492 IT_RESET_X_ASCENT_DESCENT (it
);
8494 if (wrap_it
.sp
>= 0)
8496 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8501 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8503 result
= MOVE_LINE_CONTINUED
;
8507 if (BUFFER_POS_REACHED_P ())
8509 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8510 goto buffer_pos_reached
;
8511 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8513 SAVE_IT (atpos_it
, *it
, atpos_data
);
8514 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8518 if (new_x
> it
->first_visible_x
)
8520 /* Glyph is visible. Increment number of glyphs that
8521 would be displayed. */
8526 if (result
!= MOVE_UNDEFINED
)
8529 else if (BUFFER_POS_REACHED_P ())
8532 IT_RESET_X_ASCENT_DESCENT (it
);
8533 result
= MOVE_POS_MATCH_OR_ZV
;
8536 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8538 /* Stop when TO_X specified and reached. This check is
8539 necessary here because of lines consisting of a line end,
8540 only. The line end will not produce any glyphs and we
8541 would never get MOVE_X_REACHED. */
8542 eassert (it
->nglyphs
== 0);
8543 result
= MOVE_X_REACHED
;
8547 /* Is this a line end? If yes, we're done. */
8548 if (ITERATOR_AT_END_OF_LINE_P (it
))
8550 /* If we are past TO_CHARPOS, but never saw any character
8551 positions smaller than TO_CHARPOS, return
8552 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8554 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8556 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8558 if (IT_CHARPOS (ppos_it
) < ZV
)
8560 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8561 result
= MOVE_POS_MATCH_OR_ZV
;
8564 goto buffer_pos_reached
;
8566 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8567 && IT_CHARPOS (*it
) > to_charpos
)
8568 goto buffer_pos_reached
;
8570 result
= MOVE_NEWLINE_OR_CR
;
8573 result
= MOVE_NEWLINE_OR_CR
;
8577 prev_method
= it
->method
;
8578 if (it
->method
== GET_FROM_BUFFER
)
8579 prev_pos
= IT_CHARPOS (*it
);
8580 /* The current display element has been consumed. Advance
8582 set_iterator_to_next (it
, 1);
8583 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8584 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8585 if (IT_CHARPOS (*it
) < to_charpos
)
8586 saw_smaller_pos
= 1;
8588 && (op
& MOVE_TO_POS
)
8589 && IT_CHARPOS (*it
) >= to_charpos
8590 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8591 SAVE_IT (ppos_it
, *it
, ppos_data
);
8593 /* Stop if lines are truncated and IT's current x-position is
8594 past the right edge of the window now. */
8595 if (it
->line_wrap
== TRUNCATE
8596 && it
->current_x
>= it
->last_visible_x
)
8598 if (!FRAME_WINDOW_P (it
->f
)
8599 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8600 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8601 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8602 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8606 if ((at_eob_p
= !get_next_display_element (it
))
8607 || BUFFER_POS_REACHED_P ()
8608 /* If we are past TO_CHARPOS, but never saw any
8609 character positions smaller than TO_CHARPOS,
8610 return MOVE_POS_MATCH_OR_ZV, like the
8611 unidirectional display did. */
8612 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8614 && IT_CHARPOS (*it
) > to_charpos
))
8617 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8618 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8619 result
= MOVE_POS_MATCH_OR_ZV
;
8622 if (ITERATOR_AT_END_OF_LINE_P (it
))
8624 result
= MOVE_NEWLINE_OR_CR
;
8628 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8630 && IT_CHARPOS (*it
) > to_charpos
)
8632 if (IT_CHARPOS (ppos_it
) < ZV
)
8633 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8634 result
= MOVE_POS_MATCH_OR_ZV
;
8637 result
= MOVE_LINE_TRUNCATED
;
8640 #undef IT_RESET_X_ASCENT_DESCENT
8643 #undef BUFFER_POS_REACHED_P
8645 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8646 restore the saved iterator. */
8647 if (atpos_it
.sp
>= 0)
8648 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8649 else if (atx_it
.sp
>= 0)
8650 RESTORE_IT (it
, &atx_it
, atx_data
);
8655 bidi_unshelve_cache (atpos_data
, 1);
8657 bidi_unshelve_cache (atx_data
, 1);
8659 bidi_unshelve_cache (wrap_data
, 1);
8661 bidi_unshelve_cache (ppos_data
, 1);
8663 /* Restore the iterator settings altered at the beginning of this
8665 it
->glyph_row
= saved_glyph_row
;
8669 /* For external use. */
8671 move_it_in_display_line (struct it
*it
,
8672 ptrdiff_t to_charpos
, int to_x
,
8673 enum move_operation_enum op
)
8675 if (it
->line_wrap
== WORD_WRAP
8676 && (op
& MOVE_TO_X
))
8679 void *save_data
= NULL
;
8682 SAVE_IT (save_it
, *it
, save_data
);
8683 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8684 /* When word-wrap is on, TO_X may lie past the end
8685 of a wrapped line. Then it->current is the
8686 character on the next line, so backtrack to the
8687 space before the wrap point. */
8688 if (skip
== MOVE_LINE_CONTINUED
)
8690 int prev_x
= max (it
->current_x
- 1, 0);
8691 RESTORE_IT (it
, &save_it
, save_data
);
8692 move_it_in_display_line_to
8693 (it
, -1, prev_x
, MOVE_TO_X
);
8696 bidi_unshelve_cache (save_data
, 1);
8699 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8703 /* Move IT forward until it satisfies one or more of the criteria in
8704 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8706 OP is a bit-mask that specifies where to stop, and in particular,
8707 which of those four position arguments makes a difference. See the
8708 description of enum move_operation_enum.
8710 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8711 screen line, this function will set IT to the next position that is
8712 displayed to the right of TO_CHARPOS on the screen. */
8715 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8717 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8718 int line_height
, line_start_x
= 0, reached
= 0;
8719 void *backup_data
= NULL
;
8723 if (op
& MOVE_TO_VPOS
)
8725 /* If no TO_CHARPOS and no TO_X specified, stop at the
8726 start of the line TO_VPOS. */
8727 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8729 if (it
->vpos
== to_vpos
)
8735 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8739 /* TO_VPOS >= 0 means stop at TO_X in the line at
8740 TO_VPOS, or at TO_POS, whichever comes first. */
8741 if (it
->vpos
== to_vpos
)
8747 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8749 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8754 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8756 /* We have reached TO_X but not in the line we want. */
8757 skip
= move_it_in_display_line_to (it
, to_charpos
,
8759 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8767 else if (op
& MOVE_TO_Y
)
8769 struct it it_backup
;
8771 if (it
->line_wrap
== WORD_WRAP
)
8772 SAVE_IT (it_backup
, *it
, backup_data
);
8774 /* TO_Y specified means stop at TO_X in the line containing
8775 TO_Y---or at TO_CHARPOS if this is reached first. The
8776 problem is that we can't really tell whether the line
8777 contains TO_Y before we have completely scanned it, and
8778 this may skip past TO_X. What we do is to first scan to
8781 If TO_X is not specified, use a TO_X of zero. The reason
8782 is to make the outcome of this function more predictable.
8783 If we didn't use TO_X == 0, we would stop at the end of
8784 the line which is probably not what a caller would expect
8786 skip
= move_it_in_display_line_to
8787 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8788 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8790 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8791 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8793 else if (skip
== MOVE_X_REACHED
)
8795 /* If TO_X was reached, we want to know whether TO_Y is
8796 in the line. We know this is the case if the already
8797 scanned glyphs make the line tall enough. Otherwise,
8798 we must check by scanning the rest of the line. */
8799 line_height
= it
->max_ascent
+ it
->max_descent
;
8800 if (to_y
>= it
->current_y
8801 && to_y
< it
->current_y
+ line_height
)
8806 SAVE_IT (it_backup
, *it
, backup_data
);
8807 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8808 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8810 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8811 line_height
= it
->max_ascent
+ it
->max_descent
;
8812 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8814 if (to_y
>= it
->current_y
8815 && to_y
< it
->current_y
+ line_height
)
8817 /* If TO_Y is in this line and TO_X was reached
8818 above, we scanned too far. We have to restore
8819 IT's settings to the ones before skipping. But
8820 keep the more accurate values of max_ascent and
8821 max_descent we've found while skipping the rest
8822 of the line, for the sake of callers, such as
8823 pos_visible_p, that need to know the line
8825 int max_ascent
= it
->max_ascent
;
8826 int max_descent
= it
->max_descent
;
8828 RESTORE_IT (it
, &it_backup
, backup_data
);
8829 it
->max_ascent
= max_ascent
;
8830 it
->max_descent
= max_descent
;
8836 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8842 /* Check whether TO_Y is in this line. */
8843 line_height
= it
->max_ascent
+ it
->max_descent
;
8844 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8846 if (to_y
>= it
->current_y
8847 && to_y
< it
->current_y
+ line_height
)
8849 /* When word-wrap is on, TO_X may lie past the end
8850 of a wrapped line. Then it->current is the
8851 character on the next line, so backtrack to the
8852 space before the wrap point. */
8853 if (skip
== MOVE_LINE_CONTINUED
8854 && it
->line_wrap
== WORD_WRAP
)
8856 int prev_x
= max (it
->current_x
- 1, 0);
8857 RESTORE_IT (it
, &it_backup
, backup_data
);
8858 skip
= move_it_in_display_line_to
8859 (it
, -1, prev_x
, MOVE_TO_X
);
8868 else if (BUFFERP (it
->object
)
8869 && (it
->method
== GET_FROM_BUFFER
8870 || it
->method
== GET_FROM_STRETCH
)
8871 && IT_CHARPOS (*it
) >= to_charpos
8872 /* Under bidi iteration, a call to set_iterator_to_next
8873 can scan far beyond to_charpos if the initial
8874 portion of the next line needs to be reordered. In
8875 that case, give move_it_in_display_line_to another
8878 && it
->bidi_it
.scan_dir
== -1))
8879 skip
= MOVE_POS_MATCH_OR_ZV
;
8881 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8885 case MOVE_POS_MATCH_OR_ZV
:
8889 case MOVE_NEWLINE_OR_CR
:
8890 set_iterator_to_next (it
, 1);
8891 it
->continuation_lines_width
= 0;
8894 case MOVE_LINE_TRUNCATED
:
8895 it
->continuation_lines_width
= 0;
8896 reseat_at_next_visible_line_start (it
, 0);
8897 if ((op
& MOVE_TO_POS
) != 0
8898 && IT_CHARPOS (*it
) > to_charpos
)
8905 case MOVE_LINE_CONTINUED
:
8906 /* For continued lines ending in a tab, some of the glyphs
8907 associated with the tab are displayed on the current
8908 line. Since it->current_x does not include these glyphs,
8909 we use it->last_visible_x instead. */
8912 it
->continuation_lines_width
+= it
->last_visible_x
;
8913 /* When moving by vpos, ensure that the iterator really
8914 advances to the next line (bug#847, bug#969). Fixme:
8915 do we need to do this in other circumstances? */
8916 if (it
->current_x
!= it
->last_visible_x
8917 && (op
& MOVE_TO_VPOS
)
8918 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8920 line_start_x
= it
->current_x
+ it
->pixel_width
8921 - it
->last_visible_x
;
8922 set_iterator_to_next (it
, 0);
8926 it
->continuation_lines_width
+= it
->current_x
;
8933 /* Reset/increment for the next run. */
8934 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8935 it
->current_x
= line_start_x
;
8938 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8940 last_height
= it
->max_ascent
+ it
->max_descent
;
8941 it
->max_ascent
= it
->max_descent
= 0;
8946 /* On text terminals, we may stop at the end of a line in the middle
8947 of a multi-character glyph. If the glyph itself is continued,
8948 i.e. it is actually displayed on the next line, don't treat this
8949 stopping point as valid; move to the next line instead (unless
8950 that brings us offscreen). */
8951 if (!FRAME_WINDOW_P (it
->f
)
8953 && IT_CHARPOS (*it
) == to_charpos
8954 && it
->what
== IT_CHARACTER
8956 && it
->line_wrap
== WINDOW_WRAP
8957 && it
->current_x
== it
->last_visible_x
- 1
8960 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8962 it
->continuation_lines_width
+= it
->current_x
;
8963 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8964 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8966 last_height
= it
->max_ascent
+ it
->max_descent
;
8970 bidi_unshelve_cache (backup_data
, 1);
8972 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8976 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8978 If DY > 0, move IT backward at least that many pixels. DY = 0
8979 means move IT backward to the preceding line start or BEGV. This
8980 function may move over more than DY pixels if IT->current_y - DY
8981 ends up in the middle of a line; in this case IT->current_y will be
8982 set to the top of the line moved to. */
8985 move_it_vertically_backward (struct it
*it
, int dy
)
8989 void *it2data
= NULL
, *it3data
= NULL
;
8990 ptrdiff_t start_pos
;
8992 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
8993 ptrdiff_t pos_limit
;
8998 start_pos
= IT_CHARPOS (*it
);
9000 /* Estimate how many newlines we must move back. */
9001 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9002 if (it
->line_wrap
== TRUNCATE
)
9005 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9007 /* Set the iterator's position that many lines back. But don't go
9008 back more than NLINES full screen lines -- this wins a day with
9009 buffers which have very long lines. */
9010 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9011 back_to_previous_visible_line_start (it
);
9013 /* Reseat the iterator here. When moving backward, we don't want
9014 reseat to skip forward over invisible text, set up the iterator
9015 to deliver from overlay strings at the new position etc. So,
9016 use reseat_1 here. */
9017 reseat_1 (it
, it
->current
.pos
, 1);
9019 /* We are now surely at a line start. */
9020 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9021 reordering is in effect. */
9022 it
->continuation_lines_width
= 0;
9024 /* Move forward and see what y-distance we moved. First move to the
9025 start of the next line so that we get its height. We need this
9026 height to be able to tell whether we reached the specified
9028 SAVE_IT (it2
, *it
, it2data
);
9029 it2
.max_ascent
= it2
.max_descent
= 0;
9032 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9033 MOVE_TO_POS
| MOVE_TO_VPOS
);
9035 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9036 /* If we are in a display string which starts at START_POS,
9037 and that display string includes a newline, and we are
9038 right after that newline (i.e. at the beginning of a
9039 display line), exit the loop, because otherwise we will
9040 infloop, since move_it_to will see that it is already at
9041 START_POS and will not move. */
9042 || (it2
.method
== GET_FROM_STRING
9043 && IT_CHARPOS (it2
) == start_pos
9044 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9045 eassert (IT_CHARPOS (*it
) >= BEGV
);
9046 SAVE_IT (it3
, it2
, it3data
);
9048 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9049 eassert (IT_CHARPOS (*it
) >= BEGV
);
9050 /* H is the actual vertical distance from the position in *IT
9051 and the starting position. */
9052 h
= it2
.current_y
- it
->current_y
;
9053 /* NLINES is the distance in number of lines. */
9054 nlines
= it2
.vpos
- it
->vpos
;
9056 /* Correct IT's y and vpos position
9057 so that they are relative to the starting point. */
9063 /* DY == 0 means move to the start of the screen line. The
9064 value of nlines is > 0 if continuation lines were involved,
9065 or if the original IT position was at start of a line. */
9066 RESTORE_IT (it
, it
, it2data
);
9068 move_it_by_lines (it
, nlines
);
9069 /* The above code moves us to some position NLINES down,
9070 usually to its first glyph (leftmost in an L2R line), but
9071 that's not necessarily the start of the line, under bidi
9072 reordering. We want to get to the character position
9073 that is immediately after the newline of the previous
9076 && !it
->continuation_lines_width
9077 && !STRINGP (it
->string
)
9078 && IT_CHARPOS (*it
) > BEGV
9079 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9081 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9084 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9085 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9087 bidi_unshelve_cache (it3data
, 1);
9091 /* The y-position we try to reach, relative to *IT.
9092 Note that H has been subtracted in front of the if-statement. */
9093 int target_y
= it
->current_y
+ h
- dy
;
9094 int y0
= it3
.current_y
;
9098 RESTORE_IT (&it3
, &it3
, it3data
);
9099 y1
= line_bottom_y (&it3
);
9100 line_height
= y1
- y0
;
9101 RESTORE_IT (it
, it
, it2data
);
9102 /* If we did not reach target_y, try to move further backward if
9103 we can. If we moved too far backward, try to move forward. */
9104 if (target_y
< it
->current_y
9105 /* This is heuristic. In a window that's 3 lines high, with
9106 a line height of 13 pixels each, recentering with point
9107 on the bottom line will try to move -39/2 = 19 pixels
9108 backward. Try to avoid moving into the first line. */
9109 && (it
->current_y
- target_y
9110 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9111 && IT_CHARPOS (*it
) > BEGV
)
9113 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9114 target_y
- it
->current_y
));
9115 dy
= it
->current_y
- target_y
;
9116 goto move_further_back
;
9118 else if (target_y
>= it
->current_y
+ line_height
9119 && IT_CHARPOS (*it
) < ZV
)
9121 /* Should move forward by at least one line, maybe more.
9123 Note: Calling move_it_by_lines can be expensive on
9124 terminal frames, where compute_motion is used (via
9125 vmotion) to do the job, when there are very long lines
9126 and truncate-lines is nil. That's the reason for
9127 treating terminal frames specially here. */
9129 if (!FRAME_WINDOW_P (it
->f
))
9130 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9135 move_it_by_lines (it
, 1);
9137 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9144 /* Move IT by a specified amount of pixel lines DY. DY negative means
9145 move backwards. DY = 0 means move to start of screen line. At the
9146 end, IT will be on the start of a screen line. */
9149 move_it_vertically (struct it
*it
, int dy
)
9152 move_it_vertically_backward (it
, -dy
);
9155 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9156 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9157 MOVE_TO_POS
| MOVE_TO_Y
);
9158 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9160 /* If buffer ends in ZV without a newline, move to the start of
9161 the line to satisfy the post-condition. */
9162 if (IT_CHARPOS (*it
) == ZV
9164 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9165 move_it_by_lines (it
, 0);
9170 /* Move iterator IT past the end of the text line it is in. */
9173 move_it_past_eol (struct it
*it
)
9175 enum move_it_result rc
;
9177 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9178 if (rc
== MOVE_NEWLINE_OR_CR
)
9179 set_iterator_to_next (it
, 0);
9183 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9184 negative means move up. DVPOS == 0 means move to the start of the
9187 Optimization idea: If we would know that IT->f doesn't use
9188 a face with proportional font, we could be faster for
9189 truncate-lines nil. */
9192 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9195 /* The commented-out optimization uses vmotion on terminals. This
9196 gives bad results, because elements like it->what, on which
9197 callers such as pos_visible_p rely, aren't updated. */
9198 /* struct position pos;
9199 if (!FRAME_WINDOW_P (it->f))
9201 struct text_pos textpos;
9203 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9204 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9205 reseat (it, textpos, 1);
9206 it->vpos += pos.vpos;
9207 it->current_y += pos.vpos;
9213 /* DVPOS == 0 means move to the start of the screen line. */
9214 move_it_vertically_backward (it
, 0);
9215 /* Let next call to line_bottom_y calculate real line height */
9220 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9221 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9223 /* Only move to the next buffer position if we ended up in a
9224 string from display property, not in an overlay string
9225 (before-string or after-string). That is because the
9226 latter don't conceal the underlying buffer position, so
9227 we can ask to move the iterator to the exact position we
9228 are interested in. Note that, even if we are already at
9229 IT_CHARPOS (*it), the call below is not a no-op, as it
9230 will detect that we are at the end of the string, pop the
9231 iterator, and compute it->current_x and it->hpos
9233 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9234 -1, -1, -1, MOVE_TO_POS
);
9240 void *it2data
= NULL
;
9241 ptrdiff_t start_charpos
, i
;
9243 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9244 ptrdiff_t pos_limit
;
9246 /* Start at the beginning of the screen line containing IT's
9247 position. This may actually move vertically backwards,
9248 in case of overlays, so adjust dvpos accordingly. */
9250 move_it_vertically_backward (it
, 0);
9253 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9254 screen lines, and reseat the iterator there. */
9255 start_charpos
= IT_CHARPOS (*it
);
9256 if (it
->line_wrap
== TRUNCATE
)
9259 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9260 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9261 back_to_previous_visible_line_start (it
);
9262 reseat (it
, it
->current
.pos
, 1);
9264 /* Move further back if we end up in a string or an image. */
9265 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9267 /* First try to move to start of display line. */
9269 move_it_vertically_backward (it
, 0);
9271 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9273 /* If start of line is still in string or image,
9274 move further back. */
9275 back_to_previous_visible_line_start (it
);
9276 reseat (it
, it
->current
.pos
, 1);
9280 it
->current_x
= it
->hpos
= 0;
9282 /* Above call may have moved too far if continuation lines
9283 are involved. Scan forward and see if it did. */
9284 SAVE_IT (it2
, *it
, it2data
);
9285 it2
.vpos
= it2
.current_y
= 0;
9286 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9287 it
->vpos
-= it2
.vpos
;
9288 it
->current_y
-= it2
.current_y
;
9289 it
->current_x
= it
->hpos
= 0;
9291 /* If we moved too far back, move IT some lines forward. */
9292 if (it2
.vpos
> -dvpos
)
9294 int delta
= it2
.vpos
+ dvpos
;
9296 RESTORE_IT (&it2
, &it2
, it2data
);
9297 SAVE_IT (it2
, *it
, it2data
);
9298 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9299 /* Move back again if we got too far ahead. */
9300 if (IT_CHARPOS (*it
) >= start_charpos
)
9301 RESTORE_IT (it
, &it2
, it2data
);
9303 bidi_unshelve_cache (it2data
, 1);
9306 RESTORE_IT (it
, it
, it2data
);
9310 /* Return 1 if IT points into the middle of a display vector. */
9313 in_display_vector_p (struct it
*it
)
9315 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9316 && it
->current
.dpvec_index
> 0
9317 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9321 /***********************************************************************
9323 ***********************************************************************/
9326 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9330 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9332 Lisp_Object args
[3];
9333 Lisp_Object msg
, fmt
;
9336 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9340 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9342 args
[0] = fmt
= build_string (format
);
9345 msg
= Fformat (3, args
);
9347 len
= SBYTES (msg
) + 1;
9348 buffer
= SAFE_ALLOCA (len
);
9349 memcpy (buffer
, SDATA (msg
), len
);
9351 message_dolog (buffer
, len
- 1, 1, 0);
9358 /* Output a newline in the *Messages* buffer if "needs" one. */
9361 message_log_maybe_newline (void)
9363 if (message_log_need_newline
)
9364 message_dolog ("", 0, 1, 0);
9368 /* Add a string M of length NBYTES to the message log, optionally
9369 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9370 true, means interpret the contents of M as multibyte. This
9371 function calls low-level routines in order to bypass text property
9372 hooks, etc. which might not be safe to run.
9374 This may GC (insert may run before/after change hooks),
9375 so the buffer M must NOT point to a Lisp string. */
9378 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9380 const unsigned char *msg
= (const unsigned char *) m
;
9382 if (!NILP (Vmemory_full
))
9385 if (!NILP (Vmessage_log_max
))
9387 struct buffer
*oldbuf
;
9388 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9389 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9390 ptrdiff_t point_at_end
= 0;
9391 ptrdiff_t zv_at_end
= 0;
9392 Lisp_Object old_deactivate_mark
;
9394 struct gcpro gcpro1
;
9396 old_deactivate_mark
= Vdeactivate_mark
;
9397 oldbuf
= current_buffer
;
9398 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9399 bset_undo_list (current_buffer
, Qt
);
9401 oldpoint
= message_dolog_marker1
;
9402 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9403 oldbegv
= message_dolog_marker2
;
9404 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9405 oldzv
= message_dolog_marker3
;
9406 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9407 GCPRO1 (old_deactivate_mark
);
9415 BEGV_BYTE
= BEG_BYTE
;
9418 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9420 /* Insert the string--maybe converting multibyte to single byte
9421 or vice versa, so that all the text fits the buffer. */
9423 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9429 /* Convert a multibyte string to single-byte
9430 for the *Message* buffer. */
9431 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9433 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9434 work
[0] = (ASCII_CHAR_P (c
)
9436 : multibyte_char_to_unibyte (c
));
9437 insert_1_both (work
, 1, 1, 1, 0, 0);
9440 else if (! multibyte
9441 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9445 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9446 /* Convert a single-byte string to multibyte
9447 for the *Message* buffer. */
9448 for (i
= 0; i
< nbytes
; i
++)
9451 MAKE_CHAR_MULTIBYTE (c
);
9452 char_bytes
= CHAR_STRING (c
, str
);
9453 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9457 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9461 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9464 insert_1_both ("\n", 1, 1, 1, 0, 0);
9466 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9468 this_bol_byte
= PT_BYTE
;
9470 /* See if this line duplicates the previous one.
9471 If so, combine duplicates. */
9474 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9476 prev_bol_byte
= PT_BYTE
;
9478 dups
= message_log_check_duplicate (prev_bol_byte
,
9482 del_range_both (prev_bol
, prev_bol_byte
,
9483 this_bol
, this_bol_byte
, 0);
9486 char dupstr
[sizeof " [ times]"
9487 + INT_STRLEN_BOUND (printmax_t
)];
9489 /* If you change this format, don't forget to also
9490 change message_log_check_duplicate. */
9491 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9492 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9493 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9498 /* If we have more than the desired maximum number of lines
9499 in the *Messages* buffer now, delete the oldest ones.
9500 This is safe because we don't have undo in this buffer. */
9502 if (NATNUMP (Vmessage_log_max
))
9504 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9505 -XFASTINT (Vmessage_log_max
) - 1, 0);
9506 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9509 BEGV
= marker_position (oldbegv
);
9510 BEGV_BYTE
= marker_byte_position (oldbegv
);
9519 ZV
= marker_position (oldzv
);
9520 ZV_BYTE
= marker_byte_position (oldzv
);
9524 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9526 /* We can't do Fgoto_char (oldpoint) because it will run some
9528 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9529 marker_byte_position (oldpoint
));
9532 unchain_marker (XMARKER (oldpoint
));
9533 unchain_marker (XMARKER (oldbegv
));
9534 unchain_marker (XMARKER (oldzv
));
9536 shown
= buffer_window_count (current_buffer
) > 0;
9537 set_buffer_internal (oldbuf
);
9538 /* We called insert_1_both above with its 5th argument (PREPARE)
9539 zero, which prevents insert_1_both from calling
9540 prepare_to_modify_buffer, which in turns prevents us from
9541 incrementing windows_or_buffers_changed even if *Messages* is
9542 shown in some window. So we must manually incrementing
9543 windows_or_buffers_changed here to make up for that. */
9545 windows_or_buffers_changed
++;
9547 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9548 message_log_need_newline
= !nlflag
;
9549 Vdeactivate_mark
= old_deactivate_mark
;
9554 /* We are at the end of the buffer after just having inserted a newline.
9555 (Note: We depend on the fact we won't be crossing the gap.)
9556 Check to see if the most recent message looks a lot like the previous one.
9557 Return 0 if different, 1 if the new one should just replace it, or a
9558 value N > 1 if we should also append " [N times]". */
9561 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9564 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9566 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9567 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9569 for (i
= 0; i
< len
; i
++)
9571 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9579 if (*p1
++ == ' ' && *p1
++ == '[')
9582 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9583 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9590 /* Display an echo area message M with a specified length of NBYTES
9591 bytes. The string may include null characters. If M is not a
9592 string, clear out any existing message, and let the mini-buffer
9595 This function cancels echoing. */
9598 message3 (Lisp_Object m
)
9600 struct gcpro gcpro1
;
9603 clear_message (1,1);
9606 /* First flush out any partial line written with print. */
9607 message_log_maybe_newline ();
9610 ptrdiff_t nbytes
= SBYTES (m
);
9611 bool multibyte
= STRING_MULTIBYTE (m
);
9613 char *buffer
= SAFE_ALLOCA (nbytes
);
9614 memcpy (buffer
, SDATA (m
), nbytes
);
9615 message_dolog (buffer
, nbytes
, 1, multibyte
);
9624 /* The non-logging version of message3.
9625 This does not cancel echoing, because it is used for echoing.
9626 Perhaps we need to make a separate function for echoing
9627 and make this cancel echoing. */
9630 message3_nolog (Lisp_Object m
)
9632 struct frame
*sf
= SELECTED_FRAME ();
9634 if (FRAME_INITIAL_P (sf
))
9636 if (noninteractive_need_newline
)
9637 putc ('\n', stderr
);
9638 noninteractive_need_newline
= 0;
9640 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9641 if (cursor_in_echo_area
== 0)
9642 fprintf (stderr
, "\n");
9645 /* Error messages get reported properly by cmd_error, so this must be just an
9646 informative message; if the frame hasn't really been initialized yet, just
9648 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9650 /* Get the frame containing the mini-buffer
9651 that the selected frame is using. */
9652 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9653 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9654 struct frame
*f
= XFRAME (frame
);
9656 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9657 Fmake_frame_visible (frame
);
9659 if (STRINGP (m
) && SCHARS (m
) > 0)
9662 if (minibuffer_auto_raise
)
9663 Fraise_frame (frame
);
9664 /* Assume we are not echoing.
9665 (If we are, echo_now will override this.) */
9666 echo_message_buffer
= Qnil
;
9669 clear_message (1, 1);
9671 do_pending_window_change (0);
9672 echo_area_display (1);
9673 do_pending_window_change (0);
9674 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9675 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9680 /* Display a null-terminated echo area message M. If M is 0, clear
9681 out any existing message, and let the mini-buffer text show through.
9683 The buffer M must continue to exist until after the echo area gets
9684 cleared or some other message gets displayed there. Do not pass
9685 text that is stored in a Lisp string. Do not pass text in a buffer
9686 that was alloca'd. */
9689 message1 (const char *m
)
9691 message3 (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9695 /* The non-logging counterpart of message1. */
9698 message1_nolog (const char *m
)
9700 message3_nolog (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9703 /* Display a message M which contains a single %s
9704 which gets replaced with STRING. */
9707 message_with_string (const char *m
, Lisp_Object string
, int log
)
9709 CHECK_STRING (string
);
9715 if (noninteractive_need_newline
)
9716 putc ('\n', stderr
);
9717 noninteractive_need_newline
= 0;
9718 fprintf (stderr
, m
, SDATA (string
));
9719 if (!cursor_in_echo_area
)
9720 fprintf (stderr
, "\n");
9724 else if (INTERACTIVE
)
9726 /* The frame whose minibuffer we're going to display the message on.
9727 It may be larger than the selected frame, so we need
9728 to use its buffer, not the selected frame's buffer. */
9729 Lisp_Object mini_window
;
9730 struct frame
*f
, *sf
= SELECTED_FRAME ();
9732 /* Get the frame containing the minibuffer
9733 that the selected frame is using. */
9734 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9735 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9737 /* Error messages get reported properly by cmd_error, so this must be
9738 just an informative message; if the frame hasn't really been
9739 initialized yet, just toss it. */
9740 if (f
->glyphs_initialized_p
)
9742 Lisp_Object args
[2], msg
;
9743 struct gcpro gcpro1
, gcpro2
;
9745 args
[0] = build_string (m
);
9746 args
[1] = msg
= string
;
9747 GCPRO2 (args
[0], msg
);
9750 msg
= Fformat (2, args
);
9755 message3_nolog (msg
);
9759 /* Print should start at the beginning of the message
9760 buffer next time. */
9761 message_buf_print
= 0;
9767 /* Dump an informative message to the minibuf. If M is 0, clear out
9768 any existing message, and let the mini-buffer text show through. */
9771 vmessage (const char *m
, va_list ap
)
9777 if (noninteractive_need_newline
)
9778 putc ('\n', stderr
);
9779 noninteractive_need_newline
= 0;
9780 vfprintf (stderr
, m
, ap
);
9781 if (cursor_in_echo_area
== 0)
9782 fprintf (stderr
, "\n");
9786 else if (INTERACTIVE
)
9788 /* The frame whose mini-buffer we're going to display the message
9789 on. It may be larger than the selected frame, so we need to
9790 use its buffer, not the selected frame's buffer. */
9791 Lisp_Object mini_window
;
9792 struct frame
*f
, *sf
= SELECTED_FRAME ();
9794 /* Get the frame containing the mini-buffer
9795 that the selected frame is using. */
9796 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9797 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9799 /* Error messages get reported properly by cmd_error, so this must be
9800 just an informative message; if the frame hasn't really been
9801 initialized yet, just toss it. */
9802 if (f
->glyphs_initialized_p
)
9807 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9808 char *message_buf
= alloca (maxsize
+ 1);
9810 len
= doprnt (message_buf
, maxsize
, m
, (char *)0, ap
);
9812 message3 (make_string (message_buf
, len
));
9817 /* Print should start at the beginning of the message
9818 buffer next time. */
9819 message_buf_print
= 0;
9825 message (const char *m
, ...)
9835 /* The non-logging version of message. */
9838 message_nolog (const char *m
, ...)
9840 Lisp_Object old_log_max
;
9843 old_log_max
= Vmessage_log_max
;
9844 Vmessage_log_max
= Qnil
;
9846 Vmessage_log_max
= old_log_max
;
9852 /* Display the current message in the current mini-buffer. This is
9853 only called from error handlers in process.c, and is not time
9857 update_echo_area (void)
9859 if (!NILP (echo_area_buffer
[0]))
9862 string
= Fcurrent_message ();
9868 /* Make sure echo area buffers in `echo_buffers' are live.
9869 If they aren't, make new ones. */
9872 ensure_echo_area_buffers (void)
9876 for (i
= 0; i
< 2; ++i
)
9877 if (!BUFFERP (echo_buffer
[i
])
9878 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9881 Lisp_Object old_buffer
;
9884 old_buffer
= echo_buffer
[i
];
9885 echo_buffer
[i
] = Fget_buffer_create
9886 (make_formatted_string (name
, " *Echo Area %d*", i
));
9887 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9888 /* to force word wrap in echo area -
9889 it was decided to postpone this*/
9890 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9892 for (j
= 0; j
< 2; ++j
)
9893 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9894 echo_area_buffer
[j
] = echo_buffer
[i
];
9899 /* Call FN with args A1..A2 with either the current or last displayed
9900 echo_area_buffer as current buffer.
9902 WHICH zero means use the current message buffer
9903 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9904 from echo_buffer[] and clear it.
9906 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9907 suitable buffer from echo_buffer[] and clear it.
9909 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9910 that the current message becomes the last displayed one, make
9911 choose a suitable buffer for echo_area_buffer[0], and clear it.
9913 Value is what FN returns. */
9916 with_echo_area_buffer (struct window
*w
, int which
,
9917 int (*fn
) (ptrdiff_t, Lisp_Object
),
9918 ptrdiff_t a1
, Lisp_Object a2
)
9921 int this_one
, the_other
, clear_buffer_p
, rc
;
9922 ptrdiff_t count
= SPECPDL_INDEX ();
9924 /* If buffers aren't live, make new ones. */
9925 ensure_echo_area_buffers ();
9930 this_one
= 0, the_other
= 1;
9932 this_one
= 1, the_other
= 0;
9935 this_one
= 0, the_other
= 1;
9938 /* We need a fresh one in case the current echo buffer equals
9939 the one containing the last displayed echo area message. */
9940 if (!NILP (echo_area_buffer
[this_one
])
9941 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9942 echo_area_buffer
[this_one
] = Qnil
;
9945 /* Choose a suitable buffer from echo_buffer[] is we don't
9947 if (NILP (echo_area_buffer
[this_one
]))
9949 echo_area_buffer
[this_one
]
9950 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9951 ? echo_buffer
[the_other
]
9952 : echo_buffer
[this_one
]);
9956 buffer
= echo_area_buffer
[this_one
];
9958 /* Don't get confused by reusing the buffer used for echoing
9959 for a different purpose. */
9960 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9963 record_unwind_protect (unwind_with_echo_area_buffer
,
9964 with_echo_area_buffer_unwind_data (w
));
9966 /* Make the echo area buffer current. Note that for display
9967 purposes, it is not necessary that the displayed window's buffer
9968 == current_buffer, except for text property lookup. So, let's
9969 only set that buffer temporarily here without doing a full
9970 Fset_window_buffer. We must also change w->pointm, though,
9971 because otherwise an assertions in unshow_buffer fails, and Emacs
9973 set_buffer_internal_1 (XBUFFER (buffer
));
9976 wset_buffer (w
, buffer
);
9977 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9980 bset_undo_list (current_buffer
, Qt
);
9981 bset_read_only (current_buffer
, Qnil
);
9982 specbind (Qinhibit_read_only
, Qt
);
9983 specbind (Qinhibit_modification_hooks
, Qt
);
9985 if (clear_buffer_p
&& Z
> BEG
)
9988 eassert (BEGV
>= BEG
);
9989 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9993 eassert (BEGV
>= BEG
);
9994 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9996 unbind_to (count
, Qnil
);
10001 /* Save state that should be preserved around the call to the function
10002 FN called in with_echo_area_buffer. */
10005 with_echo_area_buffer_unwind_data (struct window
*w
)
10008 Lisp_Object vector
, tmp
;
10010 /* Reduce consing by keeping one vector in
10011 Vwith_echo_area_save_vector. */
10012 vector
= Vwith_echo_area_save_vector
;
10013 Vwith_echo_area_save_vector
= Qnil
;
10016 vector
= Fmake_vector (make_number (9), Qnil
);
10018 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10019 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10020 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10024 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10025 ASET (vector
, i
, w
->contents
); ++i
;
10026 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10027 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10028 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10029 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10034 for (; i
< end
; ++i
)
10035 ASET (vector
, i
, Qnil
);
10038 eassert (i
== ASIZE (vector
));
10043 /* Restore global state from VECTOR which was created by
10044 with_echo_area_buffer_unwind_data. */
10047 unwind_with_echo_area_buffer (Lisp_Object vector
)
10049 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10050 Vdeactivate_mark
= AREF (vector
, 1);
10051 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10053 if (WINDOWP (AREF (vector
, 3)))
10056 Lisp_Object buffer
;
10058 w
= XWINDOW (AREF (vector
, 3));
10059 buffer
= AREF (vector
, 4);
10061 wset_buffer (w
, buffer
);
10062 set_marker_both (w
->pointm
, buffer
,
10063 XFASTINT (AREF (vector
, 5)),
10064 XFASTINT (AREF (vector
, 6)));
10065 set_marker_both (w
->start
, buffer
,
10066 XFASTINT (AREF (vector
, 7)),
10067 XFASTINT (AREF (vector
, 8)));
10070 Vwith_echo_area_save_vector
= vector
;
10075 /* Set up the echo area for use by print functions. MULTIBYTE_P
10076 non-zero means we will print multibyte. */
10079 setup_echo_area_for_printing (int multibyte_p
)
10081 /* If we can't find an echo area any more, exit. */
10082 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10083 Fkill_emacs (Qnil
);
10085 ensure_echo_area_buffers ();
10087 if (!message_buf_print
)
10089 /* A message has been output since the last time we printed.
10090 Choose a fresh echo area buffer. */
10091 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10092 echo_area_buffer
[0] = echo_buffer
[1];
10094 echo_area_buffer
[0] = echo_buffer
[0];
10096 /* Switch to that buffer and clear it. */
10097 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10098 bset_truncate_lines (current_buffer
, Qnil
);
10102 ptrdiff_t count
= SPECPDL_INDEX ();
10103 specbind (Qinhibit_read_only
, Qt
);
10104 /* Note that undo recording is always disabled. */
10105 del_range (BEG
, Z
);
10106 unbind_to (count
, Qnil
);
10108 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10110 /* Set up the buffer for the multibyteness we need. */
10112 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10113 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10115 /* Raise the frame containing the echo area. */
10116 if (minibuffer_auto_raise
)
10118 struct frame
*sf
= SELECTED_FRAME ();
10119 Lisp_Object mini_window
;
10120 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10121 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10124 message_log_maybe_newline ();
10125 message_buf_print
= 1;
10129 if (NILP (echo_area_buffer
[0]))
10131 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10132 echo_area_buffer
[0] = echo_buffer
[1];
10134 echo_area_buffer
[0] = echo_buffer
[0];
10137 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10139 /* Someone switched buffers between print requests. */
10140 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10141 bset_truncate_lines (current_buffer
, Qnil
);
10147 /* Display an echo area message in window W. Value is non-zero if W's
10148 height is changed. If display_last_displayed_message_p is
10149 non-zero, display the message that was last displayed, otherwise
10150 display the current message. */
10153 display_echo_area (struct window
*w
)
10155 int i
, no_message_p
, window_height_changed_p
;
10157 /* Temporarily disable garbage collections while displaying the echo
10158 area. This is done because a GC can print a message itself.
10159 That message would modify the echo area buffer's contents while a
10160 redisplay of the buffer is going on, and seriously confuse
10162 ptrdiff_t count
= inhibit_garbage_collection ();
10164 /* If there is no message, we must call display_echo_area_1
10165 nevertheless because it resizes the window. But we will have to
10166 reset the echo_area_buffer in question to nil at the end because
10167 with_echo_area_buffer will sets it to an empty buffer. */
10168 i
= display_last_displayed_message_p
? 1 : 0;
10169 no_message_p
= NILP (echo_area_buffer
[i
]);
10171 window_height_changed_p
10172 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10173 display_echo_area_1
,
10174 (intptr_t) w
, Qnil
);
10177 echo_area_buffer
[i
] = Qnil
;
10179 unbind_to (count
, Qnil
);
10180 return window_height_changed_p
;
10184 /* Helper for display_echo_area. Display the current buffer which
10185 contains the current echo area message in window W, a mini-window,
10186 a pointer to which is passed in A1. A2..A4 are currently not used.
10187 Change the height of W so that all of the message is displayed.
10188 Value is non-zero if height of W was changed. */
10191 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10194 struct window
*w
= (struct window
*) i1
;
10195 Lisp_Object window
;
10196 struct text_pos start
;
10197 int window_height_changed_p
= 0;
10199 /* Do this before displaying, so that we have a large enough glyph
10200 matrix for the display. If we can't get enough space for the
10201 whole text, display the last N lines. That works by setting w->start. */
10202 window_height_changed_p
= resize_mini_window (w
, 0);
10204 /* Use the starting position chosen by resize_mini_window. */
10205 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10208 clear_glyph_matrix (w
->desired_matrix
);
10209 XSETWINDOW (window
, w
);
10210 try_window (window
, start
, 0);
10212 return window_height_changed_p
;
10216 /* Resize the echo area window to exactly the size needed for the
10217 currently displayed message, if there is one. If a mini-buffer
10218 is active, don't shrink it. */
10221 resize_echo_area_exactly (void)
10223 if (BUFFERP (echo_area_buffer
[0])
10224 && WINDOWP (echo_area_window
))
10226 struct window
*w
= XWINDOW (echo_area_window
);
10228 Lisp_Object resize_exactly
;
10230 if (minibuf_level
== 0)
10231 resize_exactly
= Qt
;
10233 resize_exactly
= Qnil
;
10235 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10236 (intptr_t) w
, resize_exactly
);
10239 ++windows_or_buffers_changed
;
10240 ++update_mode_lines
;
10241 redisplay_internal ();
10247 /* Callback function for with_echo_area_buffer, when used from
10248 resize_echo_area_exactly. A1 contains a pointer to the window to
10249 resize, EXACTLY non-nil means resize the mini-window exactly to the
10250 size of the text displayed. A3 and A4 are not used. Value is what
10251 resize_mini_window returns. */
10254 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10257 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10261 /* Resize mini-window W to fit the size of its contents. EXACT_P
10262 means size the window exactly to the size needed. Otherwise, it's
10263 only enlarged until W's buffer is empty.
10265 Set W->start to the right place to begin display. If the whole
10266 contents fit, start at the beginning. Otherwise, start so as
10267 to make the end of the contents appear. This is particularly
10268 important for y-or-n-p, but seems desirable generally.
10270 Value is non-zero if the window height has been changed. */
10273 resize_mini_window (struct window
*w
, int exact_p
)
10275 struct frame
*f
= XFRAME (w
->frame
);
10276 int window_height_changed_p
= 0;
10278 eassert (MINI_WINDOW_P (w
));
10280 /* By default, start display at the beginning. */
10281 set_marker_both (w
->start
, w
->contents
,
10282 BUF_BEGV (XBUFFER (w
->contents
)),
10283 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10285 /* Don't resize windows while redisplaying a window; it would
10286 confuse redisplay functions when the size of the window they are
10287 displaying changes from under them. Such a resizing can happen,
10288 for instance, when which-func prints a long message while
10289 we are running fontification-functions. We're running these
10290 functions with safe_call which binds inhibit-redisplay to t. */
10291 if (!NILP (Vinhibit_redisplay
))
10294 /* Nil means don't try to resize. */
10295 if (NILP (Vresize_mini_windows
)
10296 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10299 if (!FRAME_MINIBUF_ONLY_P (f
))
10302 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10303 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10305 EMACS_INT max_height
;
10306 int unit
= FRAME_LINE_HEIGHT (f
);
10307 struct text_pos start
;
10308 struct buffer
*old_current_buffer
= NULL
;
10310 if (current_buffer
!= XBUFFER (w
->contents
))
10312 old_current_buffer
= current_buffer
;
10313 set_buffer_internal (XBUFFER (w
->contents
));
10316 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10318 /* Compute the max. number of lines specified by the user. */
10319 if (FLOATP (Vmax_mini_window_height
))
10320 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10321 else if (INTEGERP (Vmax_mini_window_height
))
10322 max_height
= XINT (Vmax_mini_window_height
);
10324 max_height
= total_height
/ 4;
10326 /* Correct that max. height if it's bogus. */
10327 max_height
= clip_to_bounds (1, max_height
, total_height
);
10329 /* Find out the height of the text in the window. */
10330 if (it
.line_wrap
== TRUNCATE
)
10335 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10336 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10337 height
= it
.current_y
+ last_height
;
10339 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10340 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10341 height
= (height
+ unit
- 1) / unit
;
10344 /* Compute a suitable window start. */
10345 if (height
> max_height
)
10347 height
= max_height
;
10348 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10349 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10350 start
= it
.current
.pos
;
10353 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10354 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10356 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10358 /* Let it grow only, until we display an empty message, in which
10359 case the window shrinks again. */
10360 if (height
> WINDOW_TOTAL_LINES (w
))
10362 int old_height
= WINDOW_TOTAL_LINES (w
);
10363 freeze_window_starts (f
, 1);
10364 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10365 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10367 else if (height
< WINDOW_TOTAL_LINES (w
)
10368 && (exact_p
|| BEGV
== ZV
))
10370 int old_height
= WINDOW_TOTAL_LINES (w
);
10371 freeze_window_starts (f
, 0);
10372 shrink_mini_window (w
);
10373 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10378 /* Always resize to exact size needed. */
10379 if (height
> WINDOW_TOTAL_LINES (w
))
10381 int old_height
= WINDOW_TOTAL_LINES (w
);
10382 freeze_window_starts (f
, 1);
10383 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10384 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10386 else if (height
< WINDOW_TOTAL_LINES (w
))
10388 int old_height
= WINDOW_TOTAL_LINES (w
);
10389 freeze_window_starts (f
, 0);
10390 shrink_mini_window (w
);
10394 freeze_window_starts (f
, 1);
10395 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10398 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10402 if (old_current_buffer
)
10403 set_buffer_internal (old_current_buffer
);
10406 return window_height_changed_p
;
10410 /* Value is the current message, a string, or nil if there is no
10411 current message. */
10414 current_message (void)
10418 if (!BUFFERP (echo_area_buffer
[0]))
10422 with_echo_area_buffer (0, 0, current_message_1
,
10423 (intptr_t) &msg
, Qnil
);
10425 echo_area_buffer
[0] = Qnil
;
10433 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10436 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10439 *msg
= make_buffer_string (BEG
, Z
, 1);
10446 /* Push the current message on Vmessage_stack for later restoration
10447 by restore_message. Value is non-zero if the current message isn't
10448 empty. This is a relatively infrequent operation, so it's not
10449 worth optimizing. */
10452 push_message (void)
10454 Lisp_Object msg
= current_message ();
10455 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10456 return STRINGP (msg
);
10460 /* Restore message display from the top of Vmessage_stack. */
10463 restore_message (void)
10465 eassert (CONSP (Vmessage_stack
));
10466 message3_nolog (XCAR (Vmessage_stack
));
10470 /* Handler for record_unwind_protect calling pop_message. */
10473 pop_message_unwind (Lisp_Object dummy
)
10479 /* Pop the top-most entry off Vmessage_stack. */
10484 eassert (CONSP (Vmessage_stack
));
10485 Vmessage_stack
= XCDR (Vmessage_stack
);
10489 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10490 exits. If the stack is not empty, we have a missing pop_message
10494 check_message_stack (void)
10496 if (!NILP (Vmessage_stack
))
10501 /* Truncate to NCHARS what will be displayed in the echo area the next
10502 time we display it---but don't redisplay it now. */
10505 truncate_echo_area (ptrdiff_t nchars
)
10508 echo_area_buffer
[0] = Qnil
;
10509 else if (!noninteractive
10511 && !NILP (echo_area_buffer
[0]))
10513 struct frame
*sf
= SELECTED_FRAME ();
10514 /* Error messages get reported properly by cmd_error, so this must be
10515 just an informative message; if the frame hasn't really been
10516 initialized yet, just toss it. */
10517 if (sf
->glyphs_initialized_p
)
10518 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10523 /* Helper function for truncate_echo_area. Truncate the current
10524 message to at most NCHARS characters. */
10527 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10529 if (BEG
+ nchars
< Z
)
10530 del_range (BEG
+ nchars
, Z
);
10532 echo_area_buffer
[0] = Qnil
;
10536 /* Set the current message to STRING. */
10539 set_message (Lisp_Object string
)
10541 eassert (STRINGP (string
));
10543 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10545 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10546 message_buf_print
= 0;
10547 help_echo_showing_p
= 0;
10549 if (STRINGP (Vdebug_on_message
)
10550 && STRINGP (string
)
10551 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10552 call_debugger (list2 (Qerror
, string
));
10556 /* Helper function for set_message. First argument is ignored and second
10557 argument has the same meaning as for set_message.
10558 This function is called with the echo area buffer being current. */
10561 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10563 eassert (STRINGP (string
));
10565 /* Change multibyteness of the echo buffer appropriately. */
10566 if (message_enable_multibyte
10567 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10568 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10570 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10571 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10572 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10574 /* Insert new message at BEG. */
10575 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10577 /* This function takes care of single/multibyte conversion.
10578 We just have to ensure that the echo area buffer has the right
10579 setting of enable_multibyte_characters. */
10580 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10586 /* Clear messages. CURRENT_P non-zero means clear the current
10587 message. LAST_DISPLAYED_P non-zero means clear the message
10591 clear_message (int current_p
, int last_displayed_p
)
10595 echo_area_buffer
[0] = Qnil
;
10596 message_cleared_p
= 1;
10599 if (last_displayed_p
)
10600 echo_area_buffer
[1] = Qnil
;
10602 message_buf_print
= 0;
10605 /* Clear garbaged frames.
10607 This function is used where the old redisplay called
10608 redraw_garbaged_frames which in turn called redraw_frame which in
10609 turn called clear_frame. The call to clear_frame was a source of
10610 flickering. I believe a clear_frame is not necessary. It should
10611 suffice in the new redisplay to invalidate all current matrices,
10612 and ensure a complete redisplay of all windows. */
10615 clear_garbaged_frames (void)
10617 if (frame_garbaged
)
10619 Lisp_Object tail
, frame
;
10620 int changed_count
= 0;
10622 FOR_EACH_FRAME (tail
, frame
)
10624 struct frame
*f
= XFRAME (frame
);
10626 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10631 f
->force_flush_display_p
= 1;
10633 clear_current_matrices (f
);
10640 frame_garbaged
= 0;
10642 ++windows_or_buffers_changed
;
10647 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10648 is non-zero update selected_frame. Value is non-zero if the
10649 mini-windows height has been changed. */
10652 echo_area_display (int update_frame_p
)
10654 Lisp_Object mini_window
;
10657 int window_height_changed_p
= 0;
10658 struct frame
*sf
= SELECTED_FRAME ();
10660 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10661 w
= XWINDOW (mini_window
);
10662 f
= XFRAME (WINDOW_FRAME (w
));
10664 /* Don't display if frame is invisible or not yet initialized. */
10665 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10668 #ifdef HAVE_WINDOW_SYSTEM
10669 /* When Emacs starts, selected_frame may be the initial terminal
10670 frame. If we let this through, a message would be displayed on
10672 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10674 #endif /* HAVE_WINDOW_SYSTEM */
10676 /* Redraw garbaged frames. */
10677 clear_garbaged_frames ();
10679 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10681 echo_area_window
= mini_window
;
10682 window_height_changed_p
= display_echo_area (w
);
10683 w
->must_be_updated_p
= 1;
10685 /* Update the display, unless called from redisplay_internal.
10686 Also don't update the screen during redisplay itself. The
10687 update will happen at the end of redisplay, and an update
10688 here could cause confusion. */
10689 if (update_frame_p
&& !redisplaying_p
)
10693 /* If the display update has been interrupted by pending
10694 input, update mode lines in the frame. Due to the
10695 pending input, it might have been that redisplay hasn't
10696 been called, so that mode lines above the echo area are
10697 garbaged. This looks odd, so we prevent it here. */
10698 if (!display_completed
)
10699 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10701 if (window_height_changed_p
10702 /* Don't do this if Emacs is shutting down. Redisplay
10703 needs to run hooks. */
10704 && !NILP (Vrun_hooks
))
10706 /* Must update other windows. Likewise as in other
10707 cases, don't let this update be interrupted by
10709 ptrdiff_t count
= SPECPDL_INDEX ();
10710 specbind (Qredisplay_dont_pause
, Qt
);
10711 windows_or_buffers_changed
= 1;
10712 redisplay_internal ();
10713 unbind_to (count
, Qnil
);
10715 else if (FRAME_WINDOW_P (f
) && n
== 0)
10717 /* Window configuration is the same as before.
10718 Can do with a display update of the echo area,
10719 unless we displayed some mode lines. */
10720 update_single_window (w
, 1);
10721 FRAME_RIF (f
)->flush_display (f
);
10724 update_frame (f
, 1, 1);
10726 /* If cursor is in the echo area, make sure that the next
10727 redisplay displays the minibuffer, so that the cursor will
10728 be replaced with what the minibuffer wants. */
10729 if (cursor_in_echo_area
)
10730 ++windows_or_buffers_changed
;
10733 else if (!EQ (mini_window
, selected_window
))
10734 windows_or_buffers_changed
++;
10736 /* Last displayed message is now the current message. */
10737 echo_area_buffer
[1] = echo_area_buffer
[0];
10738 /* Inform read_char that we're not echoing. */
10739 echo_message_buffer
= Qnil
;
10741 /* Prevent redisplay optimization in redisplay_internal by resetting
10742 this_line_start_pos. This is done because the mini-buffer now
10743 displays the message instead of its buffer text. */
10744 if (EQ (mini_window
, selected_window
))
10745 CHARPOS (this_line_start_pos
) = 0;
10747 return window_height_changed_p
;
10750 /* Nonzero if the current window's buffer is shown in more than one
10751 window and was modified since last redisplay. */
10754 buffer_shared_and_changed (void)
10756 return (buffer_window_count (current_buffer
) > 1
10757 && UNCHANGED_MODIFIED
< MODIFF
);
10760 /* Nonzero if W doesn't reflect the actual state of current buffer due
10761 to its text or overlays change. FIXME: this may be called when
10762 XBUFFER (w->contents) != current_buffer, which looks suspicious. */
10765 window_outdated (struct window
*w
)
10767 return (w
->last_modified
< MODIFF
10768 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10771 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10772 is enabled and mark of W's buffer was changed since last W's update. */
10775 window_buffer_changed (struct window
*w
)
10777 struct buffer
*b
= XBUFFER (w
->contents
);
10779 eassert (BUFFER_LIVE_P (b
));
10781 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10782 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10783 != (w
->region_showing
!= 0)));
10786 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10789 mode_line_update_needed (struct window
*w
)
10791 return (w
->column_number_displayed
!= -1
10792 && !(PT
== w
->last_point
&& !window_outdated (w
))
10793 && (w
->column_number_displayed
!= current_column ()));
10796 /***********************************************************************
10797 Mode Lines and Frame Titles
10798 ***********************************************************************/
10800 /* A buffer for constructing non-propertized mode-line strings and
10801 frame titles in it; allocated from the heap in init_xdisp and
10802 resized as needed in store_mode_line_noprop_char. */
10804 static char *mode_line_noprop_buf
;
10806 /* The buffer's end, and a current output position in it. */
10808 static char *mode_line_noprop_buf_end
;
10809 static char *mode_line_noprop_ptr
;
10811 #define MODE_LINE_NOPROP_LEN(start) \
10812 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10815 MODE_LINE_DISPLAY
= 0,
10819 } mode_line_target
;
10821 /* Alist that caches the results of :propertize.
10822 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10823 static Lisp_Object mode_line_proptrans_alist
;
10825 /* List of strings making up the mode-line. */
10826 static Lisp_Object mode_line_string_list
;
10828 /* Base face property when building propertized mode line string. */
10829 static Lisp_Object mode_line_string_face
;
10830 static Lisp_Object mode_line_string_face_prop
;
10833 /* Unwind data for mode line strings */
10835 static Lisp_Object Vmode_line_unwind_vector
;
10838 format_mode_line_unwind_data (struct frame
*target_frame
,
10839 struct buffer
*obuf
,
10841 int save_proptrans
)
10843 Lisp_Object vector
, tmp
;
10845 /* Reduce consing by keeping one vector in
10846 Vwith_echo_area_save_vector. */
10847 vector
= Vmode_line_unwind_vector
;
10848 Vmode_line_unwind_vector
= Qnil
;
10851 vector
= Fmake_vector (make_number (10), Qnil
);
10853 ASET (vector
, 0, make_number (mode_line_target
));
10854 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10855 ASET (vector
, 2, mode_line_string_list
);
10856 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10857 ASET (vector
, 4, mode_line_string_face
);
10858 ASET (vector
, 5, mode_line_string_face_prop
);
10861 XSETBUFFER (tmp
, obuf
);
10864 ASET (vector
, 6, tmp
);
10865 ASET (vector
, 7, owin
);
10868 /* Similarly to `with-selected-window', if the operation selects
10869 a window on another frame, we must restore that frame's
10870 selected window, and (for a tty) the top-frame. */
10871 ASET (vector
, 8, target_frame
->selected_window
);
10872 if (FRAME_TERMCAP_P (target_frame
))
10873 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10880 unwind_format_mode_line (Lisp_Object vector
)
10882 Lisp_Object old_window
= AREF (vector
, 7);
10883 Lisp_Object target_frame_window
= AREF (vector
, 8);
10884 Lisp_Object old_top_frame
= AREF (vector
, 9);
10886 mode_line_target
= XINT (AREF (vector
, 0));
10887 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10888 mode_line_string_list
= AREF (vector
, 2);
10889 if (! EQ (AREF (vector
, 3), Qt
))
10890 mode_line_proptrans_alist
= AREF (vector
, 3);
10891 mode_line_string_face
= AREF (vector
, 4);
10892 mode_line_string_face_prop
= AREF (vector
, 5);
10894 /* Select window before buffer, since it may change the buffer. */
10895 if (!NILP (old_window
))
10897 /* If the operation that we are unwinding had selected a window
10898 on a different frame, reset its frame-selected-window. For a
10899 text terminal, reset its top-frame if necessary. */
10900 if (!NILP (target_frame_window
))
10903 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10905 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10906 Fselect_window (target_frame_window
, Qt
);
10908 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10909 Fselect_frame (old_top_frame
, Qt
);
10912 Fselect_window (old_window
, Qt
);
10915 if (!NILP (AREF (vector
, 6)))
10917 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10918 ASET (vector
, 6, Qnil
);
10921 Vmode_line_unwind_vector
= vector
;
10926 /* Store a single character C for the frame title in mode_line_noprop_buf.
10927 Re-allocate mode_line_noprop_buf if necessary. */
10930 store_mode_line_noprop_char (char c
)
10932 /* If output position has reached the end of the allocated buffer,
10933 increase the buffer's size. */
10934 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10936 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10937 ptrdiff_t size
= len
;
10938 mode_line_noprop_buf
=
10939 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10940 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10941 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10944 *mode_line_noprop_ptr
++ = c
;
10948 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10949 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10950 characters that yield more columns than PRECISION; PRECISION <= 0
10951 means copy the whole string. Pad with spaces until FIELD_WIDTH
10952 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10953 pad. Called from display_mode_element when it is used to build a
10957 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10959 const unsigned char *str
= (const unsigned char *) string
;
10961 ptrdiff_t dummy
, nbytes
;
10963 /* Copy at most PRECISION chars from STR. */
10964 nbytes
= strlen (string
);
10965 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10967 store_mode_line_noprop_char (*str
++);
10969 /* Fill up with spaces until FIELD_WIDTH reached. */
10970 while (field_width
> 0
10971 && n
< field_width
)
10973 store_mode_line_noprop_char (' ');
10980 /***********************************************************************
10982 ***********************************************************************/
10984 #ifdef HAVE_WINDOW_SYSTEM
10986 /* Set the title of FRAME, if it has changed. The title format is
10987 Vicon_title_format if FRAME is iconified, otherwise it is
10988 frame_title_format. */
10991 x_consider_frame_title (Lisp_Object frame
)
10993 struct frame
*f
= XFRAME (frame
);
10995 if (FRAME_WINDOW_P (f
)
10996 || FRAME_MINIBUF_ONLY_P (f
)
10997 || f
->explicit_name
)
10999 /* Do we have more than one visible frame on this X display? */
11000 Lisp_Object tail
, other_frame
, fmt
;
11001 ptrdiff_t title_start
;
11005 ptrdiff_t count
= SPECPDL_INDEX ();
11007 FOR_EACH_FRAME (tail
, other_frame
)
11009 struct frame
*tf
= XFRAME (other_frame
);
11012 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11013 && !FRAME_MINIBUF_ONLY_P (tf
)
11014 && !EQ (other_frame
, tip_frame
)
11015 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11019 /* Set global variable indicating that multiple frames exist. */
11020 multiple_frames
= CONSP (tail
);
11022 /* Switch to the buffer of selected window of the frame. Set up
11023 mode_line_target so that display_mode_element will output into
11024 mode_line_noprop_buf; then display the title. */
11025 record_unwind_protect (unwind_format_mode_line
,
11026 format_mode_line_unwind_data
11027 (f
, current_buffer
, selected_window
, 0));
11029 Fselect_window (f
->selected_window
, Qt
);
11030 set_buffer_internal_1
11031 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11032 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11034 mode_line_target
= MODE_LINE_TITLE
;
11035 title_start
= MODE_LINE_NOPROP_LEN (0);
11036 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11037 NULL
, DEFAULT_FACE_ID
);
11038 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11039 len
= MODE_LINE_NOPROP_LEN (title_start
);
11040 title
= mode_line_noprop_buf
+ title_start
;
11041 unbind_to (count
, Qnil
);
11043 /* Set the title only if it's changed. This avoids consing in
11044 the common case where it hasn't. (If it turns out that we've
11045 already wasted too much time by walking through the list with
11046 display_mode_element, then we might need to optimize at a
11047 higher level than this.) */
11048 if (! STRINGP (f
->name
)
11049 || SBYTES (f
->name
) != len
11050 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11051 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11055 #endif /* not HAVE_WINDOW_SYSTEM */
11058 /***********************************************************************
11060 ***********************************************************************/
11063 /* Prepare for redisplay by updating menu-bar item lists when
11064 appropriate. This can call eval. */
11067 prepare_menu_bars (void)
11070 struct gcpro gcpro1
, gcpro2
;
11072 Lisp_Object tooltip_frame
;
11074 #ifdef HAVE_WINDOW_SYSTEM
11075 tooltip_frame
= tip_frame
;
11077 tooltip_frame
= Qnil
;
11080 /* Update all frame titles based on their buffer names, etc. We do
11081 this before the menu bars so that the buffer-menu will show the
11082 up-to-date frame titles. */
11083 #ifdef HAVE_WINDOW_SYSTEM
11084 if (windows_or_buffers_changed
|| update_mode_lines
)
11086 Lisp_Object tail
, frame
;
11088 FOR_EACH_FRAME (tail
, frame
)
11090 f
= XFRAME (frame
);
11091 if (!EQ (frame
, tooltip_frame
)
11092 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11093 x_consider_frame_title (frame
);
11096 #endif /* HAVE_WINDOW_SYSTEM */
11098 /* Update the menu bar item lists, if appropriate. This has to be
11099 done before any actual redisplay or generation of display lines. */
11100 all_windows
= (update_mode_lines
11101 || buffer_shared_and_changed ()
11102 || windows_or_buffers_changed
);
11105 Lisp_Object tail
, frame
;
11106 ptrdiff_t count
= SPECPDL_INDEX ();
11107 /* 1 means that update_menu_bar has run its hooks
11108 so any further calls to update_menu_bar shouldn't do so again. */
11109 int menu_bar_hooks_run
= 0;
11111 record_unwind_save_match_data ();
11113 FOR_EACH_FRAME (tail
, frame
)
11115 f
= XFRAME (frame
);
11117 /* Ignore tooltip frame. */
11118 if (EQ (frame
, tooltip_frame
))
11121 /* If a window on this frame changed size, report that to
11122 the user and clear the size-change flag. */
11123 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11125 Lisp_Object functions
;
11127 /* Clear flag first in case we get an error below. */
11128 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11129 functions
= Vwindow_size_change_functions
;
11130 GCPRO2 (tail
, functions
);
11132 while (CONSP (functions
))
11134 if (!EQ (XCAR (functions
), Qt
))
11135 call1 (XCAR (functions
), frame
);
11136 functions
= XCDR (functions
);
11142 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11143 #ifdef HAVE_WINDOW_SYSTEM
11144 update_tool_bar (f
, 0);
11147 if (windows_or_buffers_changed
11150 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11155 unbind_to (count
, Qnil
);
11159 struct frame
*sf
= SELECTED_FRAME ();
11160 update_menu_bar (sf
, 1, 0);
11161 #ifdef HAVE_WINDOW_SYSTEM
11162 update_tool_bar (sf
, 1);
11168 /* Update the menu bar item list for frame F. This has to be done
11169 before we start to fill in any display lines, because it can call
11172 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11174 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11175 already ran the menu bar hooks for this redisplay, so there
11176 is no need to run them again. The return value is the
11177 updated value of this flag, to pass to the next call. */
11180 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11182 Lisp_Object window
;
11183 register struct window
*w
;
11185 /* If called recursively during a menu update, do nothing. This can
11186 happen when, for instance, an activate-menubar-hook causes a
11188 if (inhibit_menubar_update
)
11191 window
= FRAME_SELECTED_WINDOW (f
);
11192 w
= XWINDOW (window
);
11194 if (FRAME_WINDOW_P (f
)
11196 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11197 || defined (HAVE_NS) || defined (USE_GTK)
11198 FRAME_EXTERNAL_MENU_BAR (f
)
11200 FRAME_MENU_BAR_LINES (f
) > 0
11202 : FRAME_MENU_BAR_LINES (f
) > 0)
11204 /* If the user has switched buffers or windows, we need to
11205 recompute to reflect the new bindings. But we'll
11206 recompute when update_mode_lines is set too; that means
11207 that people can use force-mode-line-update to request
11208 that the menu bar be recomputed. The adverse effect on
11209 the rest of the redisplay algorithm is about the same as
11210 windows_or_buffers_changed anyway. */
11211 if (windows_or_buffers_changed
11212 /* This used to test w->update_mode_line, but we believe
11213 there is no need to recompute the menu in that case. */
11214 || update_mode_lines
11215 || window_buffer_changed (w
))
11217 struct buffer
*prev
= current_buffer
;
11218 ptrdiff_t count
= SPECPDL_INDEX ();
11220 specbind (Qinhibit_menubar_update
, Qt
);
11222 set_buffer_internal_1 (XBUFFER (w
->contents
));
11223 if (save_match_data
)
11224 record_unwind_save_match_data ();
11225 if (NILP (Voverriding_local_map_menu_flag
))
11227 specbind (Qoverriding_terminal_local_map
, Qnil
);
11228 specbind (Qoverriding_local_map
, Qnil
);
11233 /* Run the Lucid hook. */
11234 safe_run_hooks (Qactivate_menubar_hook
);
11236 /* If it has changed current-menubar from previous value,
11237 really recompute the menu-bar from the value. */
11238 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11239 call0 (Qrecompute_lucid_menubar
);
11241 safe_run_hooks (Qmenu_bar_update_hook
);
11246 XSETFRAME (Vmenu_updating_frame
, f
);
11247 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11249 /* Redisplay the menu bar in case we changed it. */
11250 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11251 || defined (HAVE_NS) || defined (USE_GTK)
11252 if (FRAME_WINDOW_P (f
))
11254 #if defined (HAVE_NS)
11255 /* All frames on Mac OS share the same menubar. So only
11256 the selected frame should be allowed to set it. */
11257 if (f
== SELECTED_FRAME ())
11259 set_frame_menubar (f
, 0, 0);
11262 /* On a terminal screen, the menu bar is an ordinary screen
11263 line, and this makes it get updated. */
11264 w
->update_mode_line
= 1;
11265 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11266 /* In the non-toolkit version, the menu bar is an ordinary screen
11267 line, and this makes it get updated. */
11268 w
->update_mode_line
= 1;
11269 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11271 unbind_to (count
, Qnil
);
11272 set_buffer_internal_1 (prev
);
11281 /***********************************************************************
11283 ***********************************************************************/
11285 #ifdef HAVE_WINDOW_SYSTEM
11288 Nominal cursor position -- where to draw output.
11289 HPOS and VPOS are window relative glyph matrix coordinates.
11290 X and Y are window relative pixel coordinates. */
11292 struct cursor_pos output_cursor
;
11296 Set the global variable output_cursor to CURSOR. All cursor
11297 positions are relative to updated_window. */
11300 set_output_cursor (struct cursor_pos
*cursor
)
11302 output_cursor
.hpos
= cursor
->hpos
;
11303 output_cursor
.vpos
= cursor
->vpos
;
11304 output_cursor
.x
= cursor
->x
;
11305 output_cursor
.y
= cursor
->y
;
11310 Set a nominal cursor position.
11312 HPOS and VPOS are column/row positions in a window glyph matrix. X
11313 and Y are window text area relative pixel positions.
11315 If this is done during an update, updated_window will contain the
11316 window that is being updated and the position is the future output
11317 cursor position for that window. If updated_window is null, use
11318 selected_window and display the cursor at the given position. */
11321 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11325 /* If updated_window is not set, work on selected_window. */
11326 if (updated_window
)
11327 w
= updated_window
;
11329 w
= XWINDOW (selected_window
);
11331 /* Set the output cursor. */
11332 output_cursor
.hpos
= hpos
;
11333 output_cursor
.vpos
= vpos
;
11334 output_cursor
.x
= x
;
11335 output_cursor
.y
= y
;
11337 /* If not called as part of an update, really display the cursor.
11338 This will also set the cursor position of W. */
11339 if (updated_window
== NULL
)
11342 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11343 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11344 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11349 #endif /* HAVE_WINDOW_SYSTEM */
11352 /***********************************************************************
11354 ***********************************************************************/
11356 #ifdef HAVE_WINDOW_SYSTEM
11358 /* Where the mouse was last time we reported a mouse event. */
11360 FRAME_PTR last_mouse_frame
;
11362 /* Tool-bar item index of the item on which a mouse button was pressed
11365 int last_tool_bar_item
;
11367 /* Select `frame' temporarily without running all the code in
11369 FIXME: Maybe do_switch_frame should be trimmed down similarly
11370 when `norecord' is set. */
11372 fast_set_selected_frame (Lisp_Object frame
)
11374 if (!EQ (selected_frame
, frame
))
11376 selected_frame
= frame
;
11377 selected_window
= XFRAME (frame
)->selected_window
;
11382 /* Update the tool-bar item list for frame F. This has to be done
11383 before we start to fill in any display lines. Called from
11384 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11385 and restore it here. */
11388 update_tool_bar (struct frame
*f
, int save_match_data
)
11390 #if defined (USE_GTK) || defined (HAVE_NS)
11391 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11393 int do_update
= WINDOWP (f
->tool_bar_window
)
11394 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11399 Lisp_Object window
;
11402 window
= FRAME_SELECTED_WINDOW (f
);
11403 w
= XWINDOW (window
);
11405 /* If the user has switched buffers or windows, we need to
11406 recompute to reflect the new bindings. But we'll
11407 recompute when update_mode_lines is set too; that means
11408 that people can use force-mode-line-update to request
11409 that the menu bar be recomputed. The adverse effect on
11410 the rest of the redisplay algorithm is about the same as
11411 windows_or_buffers_changed anyway. */
11412 if (windows_or_buffers_changed
11413 || w
->update_mode_line
11414 || update_mode_lines
11415 || window_buffer_changed (w
))
11417 struct buffer
*prev
= current_buffer
;
11418 ptrdiff_t count
= SPECPDL_INDEX ();
11419 Lisp_Object frame
, new_tool_bar
;
11420 int new_n_tool_bar
;
11421 struct gcpro gcpro1
;
11423 /* Set current_buffer to the buffer of the selected
11424 window of the frame, so that we get the right local
11426 set_buffer_internal_1 (XBUFFER (w
->contents
));
11428 /* Save match data, if we must. */
11429 if (save_match_data
)
11430 record_unwind_save_match_data ();
11432 /* Make sure that we don't accidentally use bogus keymaps. */
11433 if (NILP (Voverriding_local_map_menu_flag
))
11435 specbind (Qoverriding_terminal_local_map
, Qnil
);
11436 specbind (Qoverriding_local_map
, Qnil
);
11439 GCPRO1 (new_tool_bar
);
11441 /* We must temporarily set the selected frame to this frame
11442 before calling tool_bar_items, because the calculation of
11443 the tool-bar keymap uses the selected frame (see
11444 `tool-bar-make-keymap' in tool-bar.el). */
11445 eassert (EQ (selected_window
,
11446 /* Since we only explicitly preserve selected_frame,
11447 check that selected_window would be redundant. */
11448 XFRAME (selected_frame
)->selected_window
));
11449 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11450 XSETFRAME (frame
, f
);
11451 fast_set_selected_frame (frame
);
11453 /* Build desired tool-bar items from keymaps. */
11455 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11458 /* Redisplay the tool-bar if we changed it. */
11459 if (new_n_tool_bar
!= f
->n_tool_bar_items
11460 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11462 /* Redisplay that happens asynchronously due to an expose event
11463 may access f->tool_bar_items. Make sure we update both
11464 variables within BLOCK_INPUT so no such event interrupts. */
11466 fset_tool_bar_items (f
, new_tool_bar
);
11467 f
->n_tool_bar_items
= new_n_tool_bar
;
11468 w
->update_mode_line
= 1;
11474 unbind_to (count
, Qnil
);
11475 set_buffer_internal_1 (prev
);
11481 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11482 F's desired tool-bar contents. F->tool_bar_items must have
11483 been set up previously by calling prepare_menu_bars. */
11486 build_desired_tool_bar_string (struct frame
*f
)
11488 int i
, size
, size_needed
;
11489 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11490 Lisp_Object image
, plist
, props
;
11492 image
= plist
= props
= Qnil
;
11493 GCPRO3 (image
, plist
, props
);
11495 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11496 Otherwise, make a new string. */
11498 /* The size of the string we might be able to reuse. */
11499 size
= (STRINGP (f
->desired_tool_bar_string
)
11500 ? SCHARS (f
->desired_tool_bar_string
)
11503 /* We need one space in the string for each image. */
11504 size_needed
= f
->n_tool_bar_items
;
11506 /* Reuse f->desired_tool_bar_string, if possible. */
11507 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11508 fset_desired_tool_bar_string
11509 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11512 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11513 Fremove_text_properties (make_number (0), make_number (size
),
11514 props
, f
->desired_tool_bar_string
);
11517 /* Put a `display' property on the string for the images to display,
11518 put a `menu_item' property on tool-bar items with a value that
11519 is the index of the item in F's tool-bar item vector. */
11520 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11522 #define PROP(IDX) \
11523 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11525 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11526 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11527 int hmargin
, vmargin
, relief
, idx
, end
;
11529 /* If image is a vector, choose the image according to the
11531 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11532 if (VECTORP (image
))
11536 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11537 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11540 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11541 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11543 eassert (ASIZE (image
) >= idx
);
11544 image
= AREF (image
, idx
);
11549 /* Ignore invalid image specifications. */
11550 if (!valid_image_p (image
))
11553 /* Display the tool-bar button pressed, or depressed. */
11554 plist
= Fcopy_sequence (XCDR (image
));
11556 /* Compute margin and relief to draw. */
11557 relief
= (tool_bar_button_relief
>= 0
11558 ? tool_bar_button_relief
11559 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11560 hmargin
= vmargin
= relief
;
11562 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11563 INT_MAX
- max (hmargin
, vmargin
)))
11565 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11566 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11568 else if (CONSP (Vtool_bar_button_margin
))
11570 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11571 INT_MAX
- hmargin
))
11572 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11574 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11575 INT_MAX
- vmargin
))
11576 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11579 if (auto_raise_tool_bar_buttons_p
)
11581 /* Add a `:relief' property to the image spec if the item is
11585 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11592 /* If image is selected, display it pressed, i.e. with a
11593 negative relief. If it's not selected, display it with a
11595 plist
= Fplist_put (plist
, QCrelief
,
11597 ? make_number (-relief
)
11598 : make_number (relief
)));
11603 /* Put a margin around the image. */
11604 if (hmargin
|| vmargin
)
11606 if (hmargin
== vmargin
)
11607 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11609 plist
= Fplist_put (plist
, QCmargin
,
11610 Fcons (make_number (hmargin
),
11611 make_number (vmargin
)));
11614 /* If button is not enabled, and we don't have special images
11615 for the disabled state, make the image appear disabled by
11616 applying an appropriate algorithm to it. */
11617 if (!enabled_p
&& idx
< 0)
11618 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11620 /* Put a `display' text property on the string for the image to
11621 display. Put a `menu-item' property on the string that gives
11622 the start of this item's properties in the tool-bar items
11624 image
= Fcons (Qimage
, plist
);
11625 props
= list4 (Qdisplay
, image
,
11626 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11628 /* Let the last image hide all remaining spaces in the tool bar
11629 string. The string can be longer than needed when we reuse a
11630 previous string. */
11631 if (i
+ 1 == f
->n_tool_bar_items
)
11632 end
= SCHARS (f
->desired_tool_bar_string
);
11635 Fadd_text_properties (make_number (i
), make_number (end
),
11636 props
, f
->desired_tool_bar_string
);
11644 /* Display one line of the tool-bar of frame IT->f.
11646 HEIGHT specifies the desired height of the tool-bar line.
11647 If the actual height of the glyph row is less than HEIGHT, the
11648 row's height is increased to HEIGHT, and the icons are centered
11649 vertically in the new height.
11651 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11652 count a final empty row in case the tool-bar width exactly matches
11657 display_tool_bar_line (struct it
*it
, int height
)
11659 struct glyph_row
*row
= it
->glyph_row
;
11660 int max_x
= it
->last_visible_x
;
11661 struct glyph
*last
;
11663 prepare_desired_row (row
);
11664 row
->y
= it
->current_y
;
11666 /* Note that this isn't made use of if the face hasn't a box,
11667 so there's no need to check the face here. */
11668 it
->start_of_box_run_p
= 1;
11670 while (it
->current_x
< max_x
)
11672 int x
, n_glyphs_before
, i
, nglyphs
;
11673 struct it it_before
;
11675 /* Get the next display element. */
11676 if (!get_next_display_element (it
))
11678 /* Don't count empty row if we are counting needed tool-bar lines. */
11679 if (height
< 0 && !it
->hpos
)
11684 /* Produce glyphs. */
11685 n_glyphs_before
= row
->used
[TEXT_AREA
];
11688 PRODUCE_GLYPHS (it
);
11690 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11692 x
= it_before
.current_x
;
11693 while (i
< nglyphs
)
11695 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11697 if (x
+ glyph
->pixel_width
> max_x
)
11699 /* Glyph doesn't fit on line. Backtrack. */
11700 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11702 /* If this is the only glyph on this line, it will never fit on the
11703 tool-bar, so skip it. But ensure there is at least one glyph,
11704 so we don't accidentally disable the tool-bar. */
11705 if (n_glyphs_before
== 0
11706 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11712 x
+= glyph
->pixel_width
;
11716 /* Stop at line end. */
11717 if (ITERATOR_AT_END_OF_LINE_P (it
))
11720 set_iterator_to_next (it
, 1);
11725 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11727 /* Use default face for the border below the tool bar.
11729 FIXME: When auto-resize-tool-bars is grow-only, there is
11730 no additional border below the possibly empty tool-bar lines.
11731 So to make the extra empty lines look "normal", we have to
11732 use the tool-bar face for the border too. */
11733 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11734 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11735 it
->face_id
= DEFAULT_FACE_ID
;
11737 extend_face_to_end_of_line (it
);
11738 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11739 last
->right_box_line_p
= 1;
11740 if (last
== row
->glyphs
[TEXT_AREA
])
11741 last
->left_box_line_p
= 1;
11743 /* Make line the desired height and center it vertically. */
11744 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11746 /* Don't add more than one line height. */
11747 height
%= FRAME_LINE_HEIGHT (it
->f
);
11748 it
->max_ascent
+= height
/ 2;
11749 it
->max_descent
+= (height
+ 1) / 2;
11752 compute_line_metrics (it
);
11754 /* If line is empty, make it occupy the rest of the tool-bar. */
11755 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11757 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11758 row
->visible_height
= row
->height
;
11759 row
->ascent
= row
->phys_ascent
= 0;
11760 row
->extra_line_spacing
= 0;
11763 row
->full_width_p
= 1;
11764 row
->continued_p
= 0;
11765 row
->truncated_on_left_p
= 0;
11766 row
->truncated_on_right_p
= 0;
11768 it
->current_x
= it
->hpos
= 0;
11769 it
->current_y
+= row
->height
;
11775 /* Max tool-bar height. */
11777 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11778 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11780 /* Value is the number of screen lines needed to make all tool-bar
11781 items of frame F visible. The number of actual rows needed is
11782 returned in *N_ROWS if non-NULL. */
11785 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11787 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11789 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11790 the desired matrix, so use (unused) mode-line row as temporary row to
11791 avoid destroying the first tool-bar row. */
11792 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11794 /* Initialize an iterator for iteration over
11795 F->desired_tool_bar_string in the tool-bar window of frame F. */
11796 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11797 it
.first_visible_x
= 0;
11798 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11799 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11800 it
.paragraph_embedding
= L2R
;
11802 while (!ITERATOR_AT_END_P (&it
))
11804 clear_glyph_row (temp_row
);
11805 it
.glyph_row
= temp_row
;
11806 display_tool_bar_line (&it
, -1);
11808 clear_glyph_row (temp_row
);
11810 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11812 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11814 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11818 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11820 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11821 If FRAME is nil or omitted, use the selected frame. */)
11822 (Lisp_Object frame
)
11824 struct frame
*f
= decode_any_frame (frame
);
11828 if (WINDOWP (f
->tool_bar_window
)
11829 && (w
= XWINDOW (f
->tool_bar_window
),
11830 WINDOW_TOTAL_LINES (w
) > 0))
11832 update_tool_bar (f
, 1);
11833 if (f
->n_tool_bar_items
)
11835 build_desired_tool_bar_string (f
);
11836 nlines
= tool_bar_lines_needed (f
, NULL
);
11840 return make_number (nlines
);
11844 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11845 height should be changed. */
11848 redisplay_tool_bar (struct frame
*f
)
11852 struct glyph_row
*row
;
11854 #if defined (USE_GTK) || defined (HAVE_NS)
11855 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11856 update_frame_tool_bar (f
);
11860 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11861 do anything. This means you must start with tool-bar-lines
11862 non-zero to get the auto-sizing effect. Or in other words, you
11863 can turn off tool-bars by specifying tool-bar-lines zero. */
11864 if (!WINDOWP (f
->tool_bar_window
)
11865 || (w
= XWINDOW (f
->tool_bar_window
),
11866 WINDOW_TOTAL_LINES (w
) == 0))
11869 /* Set up an iterator for the tool-bar window. */
11870 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11871 it
.first_visible_x
= 0;
11872 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11873 row
= it
.glyph_row
;
11875 /* Build a string that represents the contents of the tool-bar. */
11876 build_desired_tool_bar_string (f
);
11877 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11878 /* FIXME: This should be controlled by a user option. But it
11879 doesn't make sense to have an R2L tool bar if the menu bar cannot
11880 be drawn also R2L, and making the menu bar R2L is tricky due
11881 toolkit-specific code that implements it. If an R2L tool bar is
11882 ever supported, display_tool_bar_line should also be augmented to
11883 call unproduce_glyphs like display_line and display_string
11885 it
.paragraph_embedding
= L2R
;
11887 if (f
->n_tool_bar_rows
== 0)
11891 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11892 nlines
!= WINDOW_TOTAL_LINES (w
)))
11895 int old_height
= WINDOW_TOTAL_LINES (w
);
11897 XSETFRAME (frame
, f
);
11898 Fmodify_frame_parameters (frame
,
11899 Fcons (Fcons (Qtool_bar_lines
,
11900 make_number (nlines
)),
11902 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11904 clear_glyph_matrix (w
->desired_matrix
);
11905 fonts_changed_p
= 1;
11911 /* Display as many lines as needed to display all tool-bar items. */
11913 if (f
->n_tool_bar_rows
> 0)
11915 int border
, rows
, height
, extra
;
11917 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11918 border
= XINT (Vtool_bar_border
);
11919 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11920 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11921 else if (EQ (Vtool_bar_border
, Qborder_width
))
11922 border
= f
->border_width
;
11928 rows
= f
->n_tool_bar_rows
;
11929 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11930 extra
= it
.last_visible_y
- border
- height
* rows
;
11932 while (it
.current_y
< it
.last_visible_y
)
11935 if (extra
> 0 && rows
-- > 0)
11937 h
= (extra
+ rows
- 1) / rows
;
11940 display_tool_bar_line (&it
, height
+ h
);
11945 while (it
.current_y
< it
.last_visible_y
)
11946 display_tool_bar_line (&it
, 0);
11949 /* It doesn't make much sense to try scrolling in the tool-bar
11950 window, so don't do it. */
11951 w
->desired_matrix
->no_scrolling_p
= 1;
11952 w
->must_be_updated_p
= 1;
11954 if (!NILP (Vauto_resize_tool_bars
))
11956 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11957 int change_height_p
= 0;
11959 /* If we couldn't display everything, change the tool-bar's
11960 height if there is room for more. */
11961 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11962 && it
.current_y
< max_tool_bar_height
)
11963 change_height_p
= 1;
11965 row
= it
.glyph_row
- 1;
11967 /* If there are blank lines at the end, except for a partially
11968 visible blank line at the end that is smaller than
11969 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11970 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11971 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11972 change_height_p
= 1;
11974 /* If row displays tool-bar items, but is partially visible,
11975 change the tool-bar's height. */
11976 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11977 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11978 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11979 change_height_p
= 1;
11981 /* Resize windows as needed by changing the `tool-bar-lines'
11982 frame parameter. */
11983 if (change_height_p
)
11986 int old_height
= WINDOW_TOTAL_LINES (w
);
11988 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11990 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11991 && !f
->minimize_tool_bar_window_p
)
11992 ? (nlines
> old_height
)
11993 : (nlines
!= old_height
));
11994 f
->minimize_tool_bar_window_p
= 0;
11996 if (change_height_p
)
11998 XSETFRAME (frame
, f
);
11999 Fmodify_frame_parameters (frame
,
12000 Fcons (Fcons (Qtool_bar_lines
,
12001 make_number (nlines
)),
12003 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12005 clear_glyph_matrix (w
->desired_matrix
);
12006 f
->n_tool_bar_rows
= nrows
;
12007 fonts_changed_p
= 1;
12014 f
->minimize_tool_bar_window_p
= 0;
12019 /* Get information about the tool-bar item which is displayed in GLYPH
12020 on frame F. Return in *PROP_IDX the index where tool-bar item
12021 properties start in F->tool_bar_items. Value is zero if
12022 GLYPH doesn't display a tool-bar item. */
12025 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12031 /* This function can be called asynchronously, which means we must
12032 exclude any possibility that Fget_text_property signals an
12034 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12035 charpos
= max (0, charpos
);
12037 /* Get the text property `menu-item' at pos. The value of that
12038 property is the start index of this item's properties in
12039 F->tool_bar_items. */
12040 prop
= Fget_text_property (make_number (charpos
),
12041 Qmenu_item
, f
->current_tool_bar_string
);
12042 if (INTEGERP (prop
))
12044 *prop_idx
= XINT (prop
);
12054 /* Get information about the tool-bar item at position X/Y on frame F.
12055 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12056 the current matrix of the tool-bar window of F, or NULL if not
12057 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12058 item in F->tool_bar_items. Value is
12060 -1 if X/Y is not on a tool-bar item
12061 0 if X/Y is on the same item that was highlighted before.
12065 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12066 int *hpos
, int *vpos
, int *prop_idx
)
12068 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12069 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12072 /* Find the glyph under X/Y. */
12073 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12074 if (*glyph
== NULL
)
12077 /* Get the start of this tool-bar item's properties in
12078 f->tool_bar_items. */
12079 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12082 /* Is mouse on the highlighted item? */
12083 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12084 && *vpos
>= hlinfo
->mouse_face_beg_row
12085 && *vpos
<= hlinfo
->mouse_face_end_row
12086 && (*vpos
> hlinfo
->mouse_face_beg_row
12087 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12088 && (*vpos
< hlinfo
->mouse_face_end_row
12089 || *hpos
< hlinfo
->mouse_face_end_col
12090 || hlinfo
->mouse_face_past_end
))
12098 Handle mouse button event on the tool-bar of frame F, at
12099 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12100 0 for button release. MODIFIERS is event modifiers for button
12104 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12107 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12108 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12109 int hpos
, vpos
, prop_idx
;
12110 struct glyph
*glyph
;
12111 Lisp_Object enabled_p
;
12113 /* If not on the highlighted tool-bar item, return. */
12114 frame_to_window_pixel_xy (w
, &x
, &y
);
12115 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12118 /* If item is disabled, do nothing. */
12119 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12120 if (NILP (enabled_p
))
12125 /* Show item in pressed state. */
12126 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12127 last_tool_bar_item
= prop_idx
;
12131 Lisp_Object key
, frame
;
12132 struct input_event event
;
12133 EVENT_INIT (event
);
12135 /* Show item in released state. */
12136 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12138 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12140 XSETFRAME (frame
, f
);
12141 event
.kind
= TOOL_BAR_EVENT
;
12142 event
.frame_or_window
= frame
;
12144 kbd_buffer_store_event (&event
);
12146 event
.kind
= TOOL_BAR_EVENT
;
12147 event
.frame_or_window
= frame
;
12149 event
.modifiers
= modifiers
;
12150 kbd_buffer_store_event (&event
);
12151 last_tool_bar_item
= -1;
12156 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12157 tool-bar window-relative coordinates X/Y. Called from
12158 note_mouse_highlight. */
12161 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12163 Lisp_Object window
= f
->tool_bar_window
;
12164 struct window
*w
= XWINDOW (window
);
12165 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12166 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12168 struct glyph
*glyph
;
12169 struct glyph_row
*row
;
12171 Lisp_Object enabled_p
;
12173 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12174 int mouse_down_p
, rc
;
12176 /* Function note_mouse_highlight is called with negative X/Y
12177 values when mouse moves outside of the frame. */
12178 if (x
<= 0 || y
<= 0)
12180 clear_mouse_face (hlinfo
);
12184 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12187 /* Not on tool-bar item. */
12188 clear_mouse_face (hlinfo
);
12192 /* On same tool-bar item as before. */
12193 goto set_help_echo
;
12195 clear_mouse_face (hlinfo
);
12197 /* Mouse is down, but on different tool-bar item? */
12198 mouse_down_p
= (dpyinfo
->grabbed
12199 && f
== last_mouse_frame
12200 && FRAME_LIVE_P (f
));
12202 && last_tool_bar_item
!= prop_idx
)
12205 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12207 /* If tool-bar item is not enabled, don't highlight it. */
12208 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12209 if (!NILP (enabled_p
))
12211 /* Compute the x-position of the glyph. In front and past the
12212 image is a space. We include this in the highlighted area. */
12213 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12214 for (i
= x
= 0; i
< hpos
; ++i
)
12215 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12217 /* Record this as the current active region. */
12218 hlinfo
->mouse_face_beg_col
= hpos
;
12219 hlinfo
->mouse_face_beg_row
= vpos
;
12220 hlinfo
->mouse_face_beg_x
= x
;
12221 hlinfo
->mouse_face_beg_y
= row
->y
;
12222 hlinfo
->mouse_face_past_end
= 0;
12224 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12225 hlinfo
->mouse_face_end_row
= vpos
;
12226 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12227 hlinfo
->mouse_face_end_y
= row
->y
;
12228 hlinfo
->mouse_face_window
= window
;
12229 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12231 /* Display it as active. */
12232 show_mouse_face (hlinfo
, draw
);
12237 /* Set help_echo_string to a help string to display for this tool-bar item.
12238 XTread_socket does the rest. */
12239 help_echo_object
= help_echo_window
= Qnil
;
12240 help_echo_pos
= -1;
12241 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12242 if (NILP (help_echo_string
))
12243 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12246 #endif /* HAVE_WINDOW_SYSTEM */
12250 /************************************************************************
12251 Horizontal scrolling
12252 ************************************************************************/
12254 static int hscroll_window_tree (Lisp_Object
);
12255 static int hscroll_windows (Lisp_Object
);
12257 /* For all leaf windows in the window tree rooted at WINDOW, set their
12258 hscroll value so that PT is (i) visible in the window, and (ii) so
12259 that it is not within a certain margin at the window's left and
12260 right border. Value is non-zero if any window's hscroll has been
12264 hscroll_window_tree (Lisp_Object window
)
12266 int hscrolled_p
= 0;
12267 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12268 int hscroll_step_abs
= 0;
12269 double hscroll_step_rel
= 0;
12271 if (hscroll_relative_p
)
12273 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12274 if (hscroll_step_rel
< 0)
12276 hscroll_relative_p
= 0;
12277 hscroll_step_abs
= 0;
12280 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12282 hscroll_step_abs
= XINT (Vhscroll_step
);
12283 if (hscroll_step_abs
< 0)
12284 hscroll_step_abs
= 0;
12287 hscroll_step_abs
= 0;
12289 while (WINDOWP (window
))
12291 struct window
*w
= XWINDOW (window
);
12293 if (WINDOWP (w
->contents
))
12294 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12295 else if (w
->cursor
.vpos
>= 0)
12298 int text_area_width
;
12299 struct glyph_row
*current_cursor_row
12300 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12301 struct glyph_row
*desired_cursor_row
12302 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12303 struct glyph_row
*cursor_row
12304 = (desired_cursor_row
->enabled_p
12305 ? desired_cursor_row
12306 : current_cursor_row
);
12307 int row_r2l_p
= cursor_row
->reversed_p
;
12309 text_area_width
= window_box_width (w
, TEXT_AREA
);
12311 /* Scroll when cursor is inside this scroll margin. */
12312 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12314 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12315 /* For left-to-right rows, hscroll when cursor is either
12316 (i) inside the right hscroll margin, or (ii) if it is
12317 inside the left margin and the window is already
12321 && w
->cursor
.x
<= h_margin
)
12322 || (cursor_row
->enabled_p
12323 && cursor_row
->truncated_on_right_p
12324 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12325 /* For right-to-left rows, the logic is similar,
12326 except that rules for scrolling to left and right
12327 are reversed. E.g., if cursor.x <= h_margin, we
12328 need to hscroll "to the right" unconditionally,
12329 and that will scroll the screen to the left so as
12330 to reveal the next portion of the row. */
12332 && ((cursor_row
->enabled_p
12333 /* FIXME: It is confusing to set the
12334 truncated_on_right_p flag when R2L rows
12335 are actually truncated on the left. */
12336 && cursor_row
->truncated_on_right_p
12337 && w
->cursor
.x
<= h_margin
)
12339 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12343 struct buffer
*saved_current_buffer
;
12347 /* Find point in a display of infinite width. */
12348 saved_current_buffer
= current_buffer
;
12349 current_buffer
= XBUFFER (w
->contents
);
12351 if (w
== XWINDOW (selected_window
))
12354 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12356 /* Move iterator to pt starting at cursor_row->start in
12357 a line with infinite width. */
12358 init_to_row_start (&it
, w
, cursor_row
);
12359 it
.last_visible_x
= INFINITY
;
12360 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12361 current_buffer
= saved_current_buffer
;
12363 /* Position cursor in window. */
12364 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12365 hscroll
= max (0, (it
.current_x
12366 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12367 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12368 : (text_area_width
/ 2))))
12369 / FRAME_COLUMN_WIDTH (it
.f
);
12370 else if ((!row_r2l_p
12371 && w
->cursor
.x
>= text_area_width
- h_margin
)
12372 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12374 if (hscroll_relative_p
)
12375 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12378 wanted_x
= text_area_width
12379 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12382 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12386 if (hscroll_relative_p
)
12387 wanted_x
= text_area_width
* hscroll_step_rel
12390 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12393 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12395 hscroll
= max (hscroll
, w
->min_hscroll
);
12397 /* Don't prevent redisplay optimizations if hscroll
12398 hasn't changed, as it will unnecessarily slow down
12400 if (w
->hscroll
!= hscroll
)
12402 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12403 w
->hscroll
= hscroll
;
12412 /* Value is non-zero if hscroll of any leaf window has been changed. */
12413 return hscrolled_p
;
12417 /* Set hscroll so that cursor is visible and not inside horizontal
12418 scroll margins for all windows in the tree rooted at WINDOW. See
12419 also hscroll_window_tree above. Value is non-zero if any window's
12420 hscroll has been changed. If it has, desired matrices on the frame
12421 of WINDOW are cleared. */
12424 hscroll_windows (Lisp_Object window
)
12426 int hscrolled_p
= hscroll_window_tree (window
);
12428 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12429 return hscrolled_p
;
12434 /************************************************************************
12436 ************************************************************************/
12438 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12439 to a non-zero value. This is sometimes handy to have in a debugger
12444 /* First and last unchanged row for try_window_id. */
12446 static int debug_first_unchanged_at_end_vpos
;
12447 static int debug_last_unchanged_at_beg_vpos
;
12449 /* Delta vpos and y. */
12451 static int debug_dvpos
, debug_dy
;
12453 /* Delta in characters and bytes for try_window_id. */
12455 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12457 /* Values of window_end_pos and window_end_vpos at the end of
12460 static ptrdiff_t debug_end_vpos
;
12462 /* Append a string to W->desired_matrix->method. FMT is a printf
12463 format string. If trace_redisplay_p is non-zero also printf the
12464 resulting string to stderr. */
12466 static void debug_method_add (struct window
*, char const *, ...)
12467 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12470 debug_method_add (struct window
*w
, char const *fmt
, ...)
12472 char *method
= w
->desired_matrix
->method
;
12473 int len
= strlen (method
);
12474 int size
= sizeof w
->desired_matrix
->method
;
12475 int remaining
= size
- len
- 1;
12478 if (len
&& remaining
)
12481 --remaining
, ++len
;
12484 va_start (ap
, fmt
);
12485 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12488 if (trace_redisplay_p
)
12489 fprintf (stderr
, "%p (%s): %s\n",
12491 ((BUFFERP (w
->contents
)
12492 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12493 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12498 #endif /* GLYPH_DEBUG */
12501 /* Value is non-zero if all changes in window W, which displays
12502 current_buffer, are in the text between START and END. START is a
12503 buffer position, END is given as a distance from Z. Used in
12504 redisplay_internal for display optimization. */
12507 text_outside_line_unchanged_p (struct window
*w
,
12508 ptrdiff_t start
, ptrdiff_t end
)
12510 int unchanged_p
= 1;
12512 /* If text or overlays have changed, see where. */
12513 if (window_outdated (w
))
12515 /* Gap in the line? */
12516 if (GPT
< start
|| Z
- GPT
< end
)
12519 /* Changes start in front of the line, or end after it? */
12521 && (BEG_UNCHANGED
< start
- 1
12522 || END_UNCHANGED
< end
))
12525 /* If selective display, can't optimize if changes start at the
12526 beginning of the line. */
12528 && INTEGERP (BVAR (current_buffer
, selective_display
))
12529 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12530 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12533 /* If there are overlays at the start or end of the line, these
12534 may have overlay strings with newlines in them. A change at
12535 START, for instance, may actually concern the display of such
12536 overlay strings as well, and they are displayed on different
12537 lines. So, quickly rule out this case. (For the future, it
12538 might be desirable to implement something more telling than
12539 just BEG/END_UNCHANGED.) */
12542 if (BEG
+ BEG_UNCHANGED
== start
12543 && overlay_touches_p (start
))
12545 if (END_UNCHANGED
== end
12546 && overlay_touches_p (Z
- end
))
12550 /* Under bidi reordering, adding or deleting a character in the
12551 beginning of a paragraph, before the first strong directional
12552 character, can change the base direction of the paragraph (unless
12553 the buffer specifies a fixed paragraph direction), which will
12554 require to redisplay the whole paragraph. It might be worthwhile
12555 to find the paragraph limits and widen the range of redisplayed
12556 lines to that, but for now just give up this optimization. */
12557 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12558 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12562 return unchanged_p
;
12566 /* Do a frame update, taking possible shortcuts into account. This is
12567 the main external entry point for redisplay.
12569 If the last redisplay displayed an echo area message and that message
12570 is no longer requested, we clear the echo area or bring back the
12571 mini-buffer if that is in use. */
12576 redisplay_internal ();
12581 overlay_arrow_string_or_property (Lisp_Object var
)
12585 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12588 return Voverlay_arrow_string
;
12591 /* Return 1 if there are any overlay-arrows in current_buffer. */
12593 overlay_arrow_in_current_buffer_p (void)
12597 for (vlist
= Voverlay_arrow_variable_list
;
12599 vlist
= XCDR (vlist
))
12601 Lisp_Object var
= XCAR (vlist
);
12604 if (!SYMBOLP (var
))
12606 val
= find_symbol_value (var
);
12608 && current_buffer
== XMARKER (val
)->buffer
)
12615 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12619 overlay_arrows_changed_p (void)
12623 for (vlist
= Voverlay_arrow_variable_list
;
12625 vlist
= XCDR (vlist
))
12627 Lisp_Object var
= XCAR (vlist
);
12628 Lisp_Object val
, pstr
;
12630 if (!SYMBOLP (var
))
12632 val
= find_symbol_value (var
);
12633 if (!MARKERP (val
))
12635 if (! EQ (COERCE_MARKER (val
),
12636 Fget (var
, Qlast_arrow_position
))
12637 || ! (pstr
= overlay_arrow_string_or_property (var
),
12638 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12644 /* Mark overlay arrows to be updated on next redisplay. */
12647 update_overlay_arrows (int up_to_date
)
12651 for (vlist
= Voverlay_arrow_variable_list
;
12653 vlist
= XCDR (vlist
))
12655 Lisp_Object var
= XCAR (vlist
);
12657 if (!SYMBOLP (var
))
12660 if (up_to_date
> 0)
12662 Lisp_Object val
= find_symbol_value (var
);
12663 Fput (var
, Qlast_arrow_position
,
12664 COERCE_MARKER (val
));
12665 Fput (var
, Qlast_arrow_string
,
12666 overlay_arrow_string_or_property (var
));
12668 else if (up_to_date
< 0
12669 || !NILP (Fget (var
, Qlast_arrow_position
)))
12671 Fput (var
, Qlast_arrow_position
, Qt
);
12672 Fput (var
, Qlast_arrow_string
, Qt
);
12678 /* Return overlay arrow string to display at row.
12679 Return integer (bitmap number) for arrow bitmap in left fringe.
12680 Return nil if no overlay arrow. */
12683 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12687 for (vlist
= Voverlay_arrow_variable_list
;
12689 vlist
= XCDR (vlist
))
12691 Lisp_Object var
= XCAR (vlist
);
12694 if (!SYMBOLP (var
))
12697 val
= find_symbol_value (var
);
12700 && current_buffer
== XMARKER (val
)->buffer
12701 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12703 if (FRAME_WINDOW_P (it
->f
)
12704 /* FIXME: if ROW->reversed_p is set, this should test
12705 the right fringe, not the left one. */
12706 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12708 #ifdef HAVE_WINDOW_SYSTEM
12709 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12712 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12713 return make_number (fringe_bitmap
);
12716 return make_number (-1); /* Use default arrow bitmap. */
12718 return overlay_arrow_string_or_property (var
);
12725 /* Return 1 if point moved out of or into a composition. Otherwise
12726 return 0. PREV_BUF and PREV_PT are the last point buffer and
12727 position. BUF and PT are the current point buffer and position. */
12730 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12731 struct buffer
*buf
, ptrdiff_t pt
)
12733 ptrdiff_t start
, end
;
12735 Lisp_Object buffer
;
12737 XSETBUFFER (buffer
, buf
);
12738 /* Check a composition at the last point if point moved within the
12740 if (prev_buf
== buf
)
12743 /* Point didn't move. */
12746 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12747 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12748 && COMPOSITION_VALID_P (start
, end
, prop
)
12749 && start
< prev_pt
&& end
> prev_pt
)
12750 /* The last point was within the composition. Return 1 iff
12751 point moved out of the composition. */
12752 return (pt
<= start
|| pt
>= end
);
12755 /* Check a composition at the current point. */
12756 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12757 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12758 && COMPOSITION_VALID_P (start
, end
, prop
)
12759 && start
< pt
&& end
> pt
);
12763 /* Reconsider the setting of B->clip_changed which is displayed
12767 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12769 if (b
->clip_changed
12770 && w
->window_end_valid
12771 && w
->current_matrix
->buffer
== b
12772 && w
->current_matrix
->zv
== BUF_ZV (b
)
12773 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12774 b
->clip_changed
= 0;
12776 /* If display wasn't paused, and W is not a tool bar window, see if
12777 point has been moved into or out of a composition. In that case,
12778 we set b->clip_changed to 1 to force updating the screen. If
12779 b->clip_changed has already been set to 1, we can skip this
12781 if (!b
->clip_changed
&& BUFFERP (w
->contents
) && w
->window_end_valid
)
12785 if (w
== XWINDOW (selected_window
))
12788 pt
= marker_position (w
->pointm
);
12790 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->contents
)
12791 || pt
!= w
->last_point
)
12792 && check_point_in_composition (w
->current_matrix
->buffer
,
12794 XBUFFER (w
->contents
), pt
))
12795 b
->clip_changed
= 1;
12800 #define STOP_POLLING \
12801 do { if (! polling_stopped_here) stop_polling (); \
12802 polling_stopped_here = 1; } while (0)
12804 #define RESUME_POLLING \
12805 do { if (polling_stopped_here) start_polling (); \
12806 polling_stopped_here = 0; } while (0)
12809 /* Perhaps in the future avoid recentering windows if it
12810 is not necessary; currently that causes some problems. */
12813 redisplay_internal (void)
12815 struct window
*w
= XWINDOW (selected_window
);
12819 int must_finish
= 0;
12820 struct text_pos tlbufpos
, tlendpos
;
12821 int number_of_visible_frames
;
12822 ptrdiff_t count
, count1
;
12824 int polling_stopped_here
= 0;
12825 Lisp_Object tail
, frame
;
12826 struct backtrace backtrace
;
12828 /* Non-zero means redisplay has to consider all windows on all
12829 frames. Zero means, only selected_window is considered. */
12830 int consider_all_windows_p
;
12832 /* Non-zero means redisplay has to redisplay the miniwindow. */
12833 int update_miniwindow_p
= 0;
12835 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12837 /* No redisplay if running in batch mode or frame is not yet fully
12838 initialized, or redisplay is explicitly turned off by setting
12839 Vinhibit_redisplay. */
12840 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12841 || !NILP (Vinhibit_redisplay
))
12844 /* Don't examine these until after testing Vinhibit_redisplay.
12845 When Emacs is shutting down, perhaps because its connection to
12846 X has dropped, we should not look at them at all. */
12847 fr
= XFRAME (w
->frame
);
12848 sf
= SELECTED_FRAME ();
12850 if (!fr
->glyphs_initialized_p
)
12853 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12854 if (popup_activated ())
12858 /* I don't think this happens but let's be paranoid. */
12859 if (redisplaying_p
)
12862 /* Record a function that clears redisplaying_p
12863 when we leave this function. */
12864 count
= SPECPDL_INDEX ();
12865 record_unwind_protect (unwind_redisplay
, selected_frame
);
12866 redisplaying_p
= 1;
12867 specbind (Qinhibit_free_realized_faces
, Qnil
);
12869 /* Record this function, so it appears on the profiler's backtraces. */
12870 backtrace
.next
= backtrace_list
;
12871 backtrace
.function
= Qredisplay_internal
;
12872 backtrace
.args
= &Qnil
;
12873 backtrace
.nargs
= 0;
12874 backtrace
.debug_on_exit
= 0;
12875 backtrace_list
= &backtrace
;
12877 FOR_EACH_FRAME (tail
, frame
)
12878 XFRAME (frame
)->already_hscrolled_p
= 0;
12881 /* Remember the currently selected window. */
12885 reconsider_clip_changes (w
, current_buffer
);
12886 last_escape_glyph_frame
= NULL
;
12887 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12888 last_glyphless_glyph_frame
= NULL
;
12889 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12891 /* If new fonts have been loaded that make a glyph matrix adjustment
12892 necessary, do it. */
12893 if (fonts_changed_p
)
12895 adjust_glyphs (NULL
);
12896 ++windows_or_buffers_changed
;
12897 fonts_changed_p
= 0;
12900 /* If face_change_count is non-zero, init_iterator will free all
12901 realized faces, which includes the faces referenced from current
12902 matrices. So, we can't reuse current matrices in this case. */
12903 if (face_change_count
)
12904 ++windows_or_buffers_changed
;
12906 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12907 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12909 /* Since frames on a single ASCII terminal share the same
12910 display area, displaying a different frame means redisplay
12911 the whole thing. */
12912 windows_or_buffers_changed
++;
12913 SET_FRAME_GARBAGED (sf
);
12915 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12917 FRAME_TTY (sf
)->previous_frame
= sf
;
12920 /* Set the visible flags for all frames. Do this before checking for
12921 resized or garbaged frames; they want to know if their frames are
12922 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
12923 number_of_visible_frames
= 0;
12925 FOR_EACH_FRAME (tail
, frame
)
12927 struct frame
*f
= XFRAME (frame
);
12929 if (FRAME_VISIBLE_P (f
))
12930 ++number_of_visible_frames
;
12931 clear_desired_matrices (f
);
12934 /* Notice any pending interrupt request to change frame size. */
12935 do_pending_window_change (1);
12937 /* do_pending_window_change could change the selected_window due to
12938 frame resizing which makes the selected window too small. */
12939 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12942 reconsider_clip_changes (w
, current_buffer
);
12945 /* Clear frames marked as garbaged. */
12946 clear_garbaged_frames ();
12948 /* Build menubar and tool-bar items. */
12949 if (NILP (Vmemory_full
))
12950 prepare_menu_bars ();
12952 if (windows_or_buffers_changed
)
12953 update_mode_lines
++;
12955 /* Detect case that we need to write or remove a star in the mode line. */
12956 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
12958 w
->update_mode_line
= 1;
12959 if (buffer_shared_and_changed ())
12960 update_mode_lines
++;
12963 /* Avoid invocation of point motion hooks by `current_column' below. */
12964 count1
= SPECPDL_INDEX ();
12965 specbind (Qinhibit_point_motion_hooks
, Qt
);
12967 if (mode_line_update_needed (w
))
12968 w
->update_mode_line
= 1;
12970 unbind_to (count1
, Qnil
);
12972 consider_all_windows_p
= (update_mode_lines
12973 || buffer_shared_and_changed ()
12974 || cursor_type_changed
);
12976 /* If specs for an arrow have changed, do thorough redisplay
12977 to ensure we remove any arrow that should no longer exist. */
12978 if (overlay_arrows_changed_p ())
12979 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12981 /* Normally the message* functions will have already displayed and
12982 updated the echo area, but the frame may have been trashed, or
12983 the update may have been preempted, so display the echo area
12984 again here. Checking message_cleared_p captures the case that
12985 the echo area should be cleared. */
12986 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12987 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12988 || (message_cleared_p
12989 && minibuf_level
== 0
12990 /* If the mini-window is currently selected, this means the
12991 echo-area doesn't show through. */
12992 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12994 int window_height_changed_p
= echo_area_display (0);
12996 if (message_cleared_p
)
12997 update_miniwindow_p
= 1;
13001 /* If we don't display the current message, don't clear the
13002 message_cleared_p flag, because, if we did, we wouldn't clear
13003 the echo area in the next redisplay which doesn't preserve
13005 if (!display_last_displayed_message_p
)
13006 message_cleared_p
= 0;
13008 if (fonts_changed_p
)
13010 else if (window_height_changed_p
)
13012 consider_all_windows_p
= 1;
13013 ++update_mode_lines
;
13014 ++windows_or_buffers_changed
;
13016 /* If window configuration was changed, frames may have been
13017 marked garbaged. Clear them or we will experience
13018 surprises wrt scrolling. */
13019 clear_garbaged_frames ();
13022 else if (EQ (selected_window
, minibuf_window
)
13023 && (current_buffer
->clip_changed
|| window_outdated (w
))
13024 && resize_mini_window (w
, 0))
13026 /* Resized active mini-window to fit the size of what it is
13027 showing if its contents might have changed. */
13029 /* FIXME: this causes all frames to be updated, which seems unnecessary
13030 since only the current frame needs to be considered. This function
13031 needs to be rewritten with two variables, consider_all_windows and
13032 consider_all_frames. */
13033 consider_all_windows_p
= 1;
13034 ++windows_or_buffers_changed
;
13035 ++update_mode_lines
;
13037 /* If window configuration was changed, frames may have been
13038 marked garbaged. Clear them or we will experience
13039 surprises wrt scrolling. */
13040 clear_garbaged_frames ();
13043 /* If showing the region, and mark has changed, we must redisplay
13044 the whole window. The assignment to this_line_start_pos prevents
13045 the optimization directly below this if-statement. */
13046 if (((!NILP (Vtransient_mark_mode
)
13047 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13048 != (w
->region_showing
> 0))
13049 || (w
->region_showing
13050 && w
->region_showing
13051 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13052 CHARPOS (this_line_start_pos
) = 0;
13054 /* Optimize the case that only the line containing the cursor in the
13055 selected window has changed. Variables starting with this_ are
13056 set in display_line and record information about the line
13057 containing the cursor. */
13058 tlbufpos
= this_line_start_pos
;
13059 tlendpos
= this_line_end_pos
;
13060 if (!consider_all_windows_p
13061 && CHARPOS (tlbufpos
) > 0
13062 && !w
->update_mode_line
13063 && !current_buffer
->clip_changed
13064 && !current_buffer
->prevent_redisplay_optimizations_p
13065 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13066 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13067 /* Make sure recorded data applies to current buffer, etc. */
13068 && this_line_buffer
== current_buffer
13069 && current_buffer
== XBUFFER (w
->contents
)
13071 && !w
->optional_new_start
13072 /* Point must be on the line that we have info recorded about. */
13073 && PT
>= CHARPOS (tlbufpos
)
13074 && PT
<= Z
- CHARPOS (tlendpos
)
13075 /* All text outside that line, including its final newline,
13076 must be unchanged. */
13077 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13078 CHARPOS (tlendpos
)))
13080 if (CHARPOS (tlbufpos
) > BEGV
13081 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13082 && (CHARPOS (tlbufpos
) == ZV
13083 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13084 /* Former continuation line has disappeared by becoming empty. */
13086 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13088 /* We have to handle the case of continuation around a
13089 wide-column character (see the comment in indent.c around
13092 For instance, in the following case:
13094 -------- Insert --------
13095 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13096 J_I_ ==> J_I_ `^^' are cursors.
13100 As we have to redraw the line above, we cannot use this
13104 int line_height_before
= this_line_pixel_height
;
13106 /* Note that start_display will handle the case that the
13107 line starting at tlbufpos is a continuation line. */
13108 start_display (&it
, w
, tlbufpos
);
13110 /* Implementation note: It this still necessary? */
13111 if (it
.current_x
!= this_line_start_x
)
13114 TRACE ((stderr
, "trying display optimization 1\n"));
13115 w
->cursor
.vpos
= -1;
13116 overlay_arrow_seen
= 0;
13117 it
.vpos
= this_line_vpos
;
13118 it
.current_y
= this_line_y
;
13119 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13120 display_line (&it
);
13122 /* If line contains point, is not continued,
13123 and ends at same distance from eob as before, we win. */
13124 if (w
->cursor
.vpos
>= 0
13125 /* Line is not continued, otherwise this_line_start_pos
13126 would have been set to 0 in display_line. */
13127 && CHARPOS (this_line_start_pos
)
13128 /* Line ends as before. */
13129 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13130 /* Line has same height as before. Otherwise other lines
13131 would have to be shifted up or down. */
13132 && this_line_pixel_height
== line_height_before
)
13134 /* If this is not the window's last line, we must adjust
13135 the charstarts of the lines below. */
13136 if (it
.current_y
< it
.last_visible_y
)
13138 struct glyph_row
*row
13139 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13140 ptrdiff_t delta
, delta_bytes
;
13142 /* We used to distinguish between two cases here,
13143 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13144 when the line ends in a newline or the end of the
13145 buffer's accessible portion. But both cases did
13146 the same, so they were collapsed. */
13148 - CHARPOS (tlendpos
)
13149 - MATRIX_ROW_START_CHARPOS (row
));
13150 delta_bytes
= (Z_BYTE
13151 - BYTEPOS (tlendpos
)
13152 - MATRIX_ROW_START_BYTEPOS (row
));
13154 increment_matrix_positions (w
->current_matrix
,
13155 this_line_vpos
+ 1,
13156 w
->current_matrix
->nrows
,
13157 delta
, delta_bytes
);
13160 /* If this row displays text now but previously didn't,
13161 or vice versa, w->window_end_vpos may have to be
13163 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13165 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13166 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13168 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13169 && this_line_vpos
> 0)
13170 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13171 w
->window_end_valid
= 0;
13173 /* Update hint: No need to try to scroll in update_window. */
13174 w
->desired_matrix
->no_scrolling_p
= 1;
13177 *w
->desired_matrix
->method
= 0;
13178 debug_method_add (w
, "optimization 1");
13180 #ifdef HAVE_WINDOW_SYSTEM
13181 update_window_fringes (w
, 0);
13188 else if (/* Cursor position hasn't changed. */
13189 PT
== w
->last_point
13190 /* Make sure the cursor was last displayed
13191 in this window. Otherwise we have to reposition it. */
13192 && 0 <= w
->cursor
.vpos
13193 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13197 do_pending_window_change (1);
13198 /* If selected_window changed, redisplay again. */
13199 if (WINDOWP (selected_window
)
13200 && (w
= XWINDOW (selected_window
)) != sw
)
13203 /* We used to always goto end_of_redisplay here, but this
13204 isn't enough if we have a blinking cursor. */
13205 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13206 goto end_of_redisplay
;
13210 /* If highlighting the region, or if the cursor is in the echo area,
13211 then we can't just move the cursor. */
13212 else if (! (!NILP (Vtransient_mark_mode
)
13213 && !NILP (BVAR (current_buffer
, mark_active
)))
13214 && (EQ (selected_window
,
13215 BVAR (current_buffer
, last_selected_window
))
13216 || highlight_nonselected_windows
)
13217 && !w
->region_showing
13218 && NILP (Vshow_trailing_whitespace
)
13219 && !cursor_in_echo_area
)
13222 struct glyph_row
*row
;
13224 /* Skip from tlbufpos to PT and see where it is. Note that
13225 PT may be in invisible text. If so, we will end at the
13226 next visible position. */
13227 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13228 NULL
, DEFAULT_FACE_ID
);
13229 it
.current_x
= this_line_start_x
;
13230 it
.current_y
= this_line_y
;
13231 it
.vpos
= this_line_vpos
;
13233 /* The call to move_it_to stops in front of PT, but
13234 moves over before-strings. */
13235 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13237 if (it
.vpos
== this_line_vpos
13238 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13241 eassert (this_line_vpos
== it
.vpos
);
13242 eassert (this_line_y
== it
.current_y
);
13243 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13245 *w
->desired_matrix
->method
= 0;
13246 debug_method_add (w
, "optimization 3");
13255 /* Text changed drastically or point moved off of line. */
13256 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13259 CHARPOS (this_line_start_pos
) = 0;
13260 consider_all_windows_p
|= buffer_shared_and_changed ();
13261 ++clear_face_cache_count
;
13262 #ifdef HAVE_WINDOW_SYSTEM
13263 ++clear_image_cache_count
;
13266 /* Build desired matrices, and update the display. If
13267 consider_all_windows_p is non-zero, do it for all windows on all
13268 frames. Otherwise do it for selected_window, only. */
13270 if (consider_all_windows_p
)
13272 FOR_EACH_FRAME (tail
, frame
)
13273 XFRAME (frame
)->updated_p
= 0;
13275 FOR_EACH_FRAME (tail
, frame
)
13277 struct frame
*f
= XFRAME (frame
);
13279 /* We don't have to do anything for unselected terminal
13281 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13282 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13285 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13287 /* Mark all the scroll bars to be removed; we'll redeem
13288 the ones we want when we redisplay their windows. */
13289 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13290 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13292 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13293 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13295 /* The X error handler may have deleted that frame. */
13296 if (!FRAME_LIVE_P (f
))
13299 /* Any scroll bars which redisplay_windows should have
13300 nuked should now go away. */
13301 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13302 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13304 /* If fonts changed, display again. */
13305 /* ??? rms: I suspect it is a mistake to jump all the way
13306 back to retry here. It should just retry this frame. */
13307 if (fonts_changed_p
)
13310 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13312 /* See if we have to hscroll. */
13313 if (!f
->already_hscrolled_p
)
13315 f
->already_hscrolled_p
= 1;
13316 if (hscroll_windows (f
->root_window
))
13320 /* Prevent various kinds of signals during display
13321 update. stdio is not robust about handling
13322 signals, which can cause an apparent I/O
13324 if (interrupt_input
)
13325 unrequest_sigio ();
13328 /* Update the display. */
13329 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13330 pending
|= update_frame (f
, 0, 0);
13336 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13340 /* Do the mark_window_display_accurate after all windows have
13341 been redisplayed because this call resets flags in buffers
13342 which are needed for proper redisplay. */
13343 FOR_EACH_FRAME (tail
, frame
)
13345 struct frame
*f
= XFRAME (frame
);
13348 mark_window_display_accurate (f
->root_window
, 1);
13349 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13350 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13355 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13357 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13358 struct frame
*mini_frame
;
13360 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13361 /* Use list_of_error, not Qerror, so that
13362 we catch only errors and don't run the debugger. */
13363 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13365 redisplay_window_error
);
13366 if (update_miniwindow_p
)
13367 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13369 redisplay_window_error
);
13371 /* Compare desired and current matrices, perform output. */
13374 /* If fonts changed, display again. */
13375 if (fonts_changed_p
)
13378 /* Prevent various kinds of signals during display update.
13379 stdio is not robust about handling signals,
13380 which can cause an apparent I/O error. */
13381 if (interrupt_input
)
13382 unrequest_sigio ();
13385 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13387 if (hscroll_windows (selected_window
))
13390 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13391 pending
= update_frame (sf
, 0, 0);
13394 /* We may have called echo_area_display at the top of this
13395 function. If the echo area is on another frame, that may
13396 have put text on a frame other than the selected one, so the
13397 above call to update_frame would not have caught it. Catch
13399 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13400 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13402 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13404 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13405 pending
|= update_frame (mini_frame
, 0, 0);
13406 if (!pending
&& hscroll_windows (mini_window
))
13411 /* If display was paused because of pending input, make sure we do a
13412 thorough update the next time. */
13415 /* Prevent the optimization at the beginning of
13416 redisplay_internal that tries a single-line update of the
13417 line containing the cursor in the selected window. */
13418 CHARPOS (this_line_start_pos
) = 0;
13420 /* Let the overlay arrow be updated the next time. */
13421 update_overlay_arrows (0);
13423 /* If we pause after scrolling, some rows in the current
13424 matrices of some windows are not valid. */
13425 if (!WINDOW_FULL_WIDTH_P (w
)
13426 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13427 update_mode_lines
= 1;
13431 if (!consider_all_windows_p
)
13433 /* This has already been done above if
13434 consider_all_windows_p is set. */
13435 mark_window_display_accurate_1 (w
, 1);
13437 /* Say overlay arrows are up to date. */
13438 update_overlay_arrows (1);
13440 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13441 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13444 update_mode_lines
= 0;
13445 windows_or_buffers_changed
= 0;
13446 cursor_type_changed
= 0;
13449 /* Start SIGIO interrupts coming again. Having them off during the
13450 code above makes it less likely one will discard output, but not
13451 impossible, since there might be stuff in the system buffer here.
13452 But it is much hairier to try to do anything about that. */
13453 if (interrupt_input
)
13457 /* If a frame has become visible which was not before, redisplay
13458 again, so that we display it. Expose events for such a frame
13459 (which it gets when becoming visible) don't call the parts of
13460 redisplay constructing glyphs, so simply exposing a frame won't
13461 display anything in this case. So, we have to display these
13462 frames here explicitly. */
13467 FOR_EACH_FRAME (tail
, frame
)
13469 int this_is_visible
= 0;
13471 if (XFRAME (frame
)->visible
)
13472 this_is_visible
= 1;
13474 if (this_is_visible
)
13478 if (new_count
!= number_of_visible_frames
)
13479 windows_or_buffers_changed
++;
13482 /* Change frame size now if a change is pending. */
13483 do_pending_window_change (1);
13485 /* If we just did a pending size change, or have additional
13486 visible frames, or selected_window changed, redisplay again. */
13487 if ((windows_or_buffers_changed
&& !pending
)
13488 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13491 /* Clear the face and image caches.
13493 We used to do this only if consider_all_windows_p. But the cache
13494 needs to be cleared if a timer creates images in the current
13495 buffer (e.g. the test case in Bug#6230). */
13497 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13499 clear_face_cache (0);
13500 clear_face_cache_count
= 0;
13503 #ifdef HAVE_WINDOW_SYSTEM
13504 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13506 clear_image_caches (Qnil
);
13507 clear_image_cache_count
= 0;
13509 #endif /* HAVE_WINDOW_SYSTEM */
13512 backtrace_list
= backtrace
.next
;
13513 unbind_to (count
, Qnil
);
13518 /* Redisplay, but leave alone any recent echo area message unless
13519 another message has been requested in its place.
13521 This is useful in situations where you need to redisplay but no
13522 user action has occurred, making it inappropriate for the message
13523 area to be cleared. See tracking_off and
13524 wait_reading_process_output for examples of these situations.
13526 FROM_WHERE is an integer saying from where this function was
13527 called. This is useful for debugging. */
13530 redisplay_preserve_echo_area (int from_where
)
13532 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13534 if (!NILP (echo_area_buffer
[1]))
13536 /* We have a previously displayed message, but no current
13537 message. Redisplay the previous message. */
13538 display_last_displayed_message_p
= 1;
13539 redisplay_internal ();
13540 display_last_displayed_message_p
= 0;
13543 redisplay_internal ();
13545 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13546 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13547 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13551 /* Function registered with record_unwind_protect in redisplay_internal.
13552 Clear redisplaying_p. Also select the previously selected frame. */
13555 unwind_redisplay (Lisp_Object old_frame
)
13557 redisplaying_p
= 0;
13562 /* Mark the display of leaf window W as accurate or inaccurate.
13563 If ACCURATE_P is non-zero mark display of W as accurate. If
13564 ACCURATE_P is zero, arrange for W to be redisplayed the next
13565 time redisplay_internal is called. */
13568 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13570 struct buffer
*b
= XBUFFER (w
->contents
);
13572 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13573 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13574 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13578 b
->clip_changed
= 0;
13579 b
->prevent_redisplay_optimizations_p
= 0;
13581 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13582 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13583 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13584 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13586 w
->current_matrix
->buffer
= b
;
13587 w
->current_matrix
->begv
= BUF_BEGV (b
);
13588 w
->current_matrix
->zv
= BUF_ZV (b
);
13590 w
->last_cursor
= w
->cursor
;
13591 w
->last_cursor_off_p
= w
->cursor_off_p
;
13593 if (w
== XWINDOW (selected_window
))
13594 w
->last_point
= BUF_PT (b
);
13596 w
->last_point
= marker_position (w
->pointm
);
13598 w
->window_end_valid
= 1;
13599 w
->update_mode_line
= 0;
13604 /* Mark the display of windows in the window tree rooted at WINDOW as
13605 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13606 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13607 be redisplayed the next time redisplay_internal is called. */
13610 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13614 for (; !NILP (window
); window
= w
->next
)
13616 w
= XWINDOW (window
);
13617 if (WINDOWP (w
->contents
))
13618 mark_window_display_accurate (w
->contents
, accurate_p
);
13620 mark_window_display_accurate_1 (w
, accurate_p
);
13624 update_overlay_arrows (1);
13626 /* Force a thorough redisplay the next time by setting
13627 last_arrow_position and last_arrow_string to t, which is
13628 unequal to any useful value of Voverlay_arrow_... */
13629 update_overlay_arrows (-1);
13633 /* Return value in display table DP (Lisp_Char_Table *) for character
13634 C. Since a display table doesn't have any parent, we don't have to
13635 follow parent. Do not call this function directly but use the
13636 macro DISP_CHAR_VECTOR. */
13639 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13643 if (ASCII_CHAR_P (c
))
13646 if (SUB_CHAR_TABLE_P (val
))
13647 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13653 XSETCHAR_TABLE (table
, dp
);
13654 val
= char_table_ref (table
, c
);
13663 /***********************************************************************
13665 ***********************************************************************/
13667 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13670 redisplay_windows (Lisp_Object window
)
13672 while (!NILP (window
))
13674 struct window
*w
= XWINDOW (window
);
13676 if (WINDOWP (w
->contents
))
13677 redisplay_windows (w
->contents
);
13678 else if (BUFFERP (w
->contents
))
13680 displayed_buffer
= XBUFFER (w
->contents
);
13681 /* Use list_of_error, not Qerror, so that
13682 we catch only errors and don't run the debugger. */
13683 internal_condition_case_1 (redisplay_window_0
, window
,
13685 redisplay_window_error
);
13693 redisplay_window_error (Lisp_Object ignore
)
13695 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13700 redisplay_window_0 (Lisp_Object window
)
13702 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13703 redisplay_window (window
, 0);
13708 redisplay_window_1 (Lisp_Object window
)
13710 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13711 redisplay_window (window
, 1);
13716 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13717 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13718 which positions recorded in ROW differ from current buffer
13721 Return 0 if cursor is not on this row, 1 otherwise. */
13724 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13725 struct glyph_matrix
*matrix
,
13726 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13729 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13730 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13731 struct glyph
*cursor
= NULL
;
13732 /* The last known character position in row. */
13733 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13735 ptrdiff_t pt_old
= PT
- delta
;
13736 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13737 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13738 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13739 /* A glyph beyond the edge of TEXT_AREA which we should never
13741 struct glyph
*glyphs_end
= end
;
13742 /* Non-zero means we've found a match for cursor position, but that
13743 glyph has the avoid_cursor_p flag set. */
13744 int match_with_avoid_cursor
= 0;
13745 /* Non-zero means we've seen at least one glyph that came from a
13747 int string_seen
= 0;
13748 /* Largest and smallest buffer positions seen so far during scan of
13750 ptrdiff_t bpos_max
= pos_before
;
13751 ptrdiff_t bpos_min
= pos_after
;
13752 /* Last buffer position covered by an overlay string with an integer
13753 `cursor' property. */
13754 ptrdiff_t bpos_covered
= 0;
13755 /* Non-zero means the display string on which to display the cursor
13756 comes from a text property, not from an overlay. */
13757 int string_from_text_prop
= 0;
13759 /* Don't even try doing anything if called for a mode-line or
13760 header-line row, since the rest of the code isn't prepared to
13761 deal with such calamities. */
13762 eassert (!row
->mode_line_p
);
13763 if (row
->mode_line_p
)
13766 /* Skip over glyphs not having an object at the start and the end of
13767 the row. These are special glyphs like truncation marks on
13768 terminal frames. */
13769 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13771 if (!row
->reversed_p
)
13774 && INTEGERP (glyph
->object
)
13775 && glyph
->charpos
< 0)
13777 x
+= glyph
->pixel_width
;
13781 && INTEGERP ((end
- 1)->object
)
13782 /* CHARPOS is zero for blanks and stretch glyphs
13783 inserted by extend_face_to_end_of_line. */
13784 && (end
- 1)->charpos
<= 0)
13786 glyph_before
= glyph
- 1;
13793 /* If the glyph row is reversed, we need to process it from back
13794 to front, so swap the edge pointers. */
13795 glyphs_end
= end
= glyph
- 1;
13796 glyph
+= row
->used
[TEXT_AREA
] - 1;
13798 while (glyph
> end
+ 1
13799 && INTEGERP (glyph
->object
)
13800 && glyph
->charpos
< 0)
13803 x
-= glyph
->pixel_width
;
13805 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13807 /* By default, in reversed rows we put the cursor on the
13808 rightmost (first in the reading order) glyph. */
13809 for (g
= end
+ 1; g
< glyph
; g
++)
13810 x
+= g
->pixel_width
;
13812 && INTEGERP ((end
+ 1)->object
)
13813 && (end
+ 1)->charpos
<= 0)
13815 glyph_before
= glyph
+ 1;
13819 else if (row
->reversed_p
)
13821 /* In R2L rows that don't display text, put the cursor on the
13822 rightmost glyph. Case in point: an empty last line that is
13823 part of an R2L paragraph. */
13825 /* Avoid placing the cursor on the last glyph of the row, where
13826 on terminal frames we hold the vertical border between
13827 adjacent windows. */
13828 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13829 && !WINDOW_RIGHTMOST_P (w
)
13830 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13832 x
= -1; /* will be computed below, at label compute_x */
13835 /* Step 1: Try to find the glyph whose character position
13836 corresponds to point. If that's not possible, find 2 glyphs
13837 whose character positions are the closest to point, one before
13838 point, the other after it. */
13839 if (!row
->reversed_p
)
13840 while (/* not marched to end of glyph row */
13842 /* glyph was not inserted by redisplay for internal purposes */
13843 && !INTEGERP (glyph
->object
))
13845 if (BUFFERP (glyph
->object
))
13847 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13849 if (glyph
->charpos
> bpos_max
)
13850 bpos_max
= glyph
->charpos
;
13851 if (glyph
->charpos
< bpos_min
)
13852 bpos_min
= glyph
->charpos
;
13853 if (!glyph
->avoid_cursor_p
)
13855 /* If we hit point, we've found the glyph on which to
13856 display the cursor. */
13859 match_with_avoid_cursor
= 0;
13862 /* See if we've found a better approximation to
13863 POS_BEFORE or to POS_AFTER. */
13864 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13866 pos_before
= glyph
->charpos
;
13867 glyph_before
= glyph
;
13869 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13871 pos_after
= glyph
->charpos
;
13872 glyph_after
= glyph
;
13875 else if (dpos
== 0)
13876 match_with_avoid_cursor
= 1;
13878 else if (STRINGP (glyph
->object
))
13880 Lisp_Object chprop
;
13881 ptrdiff_t glyph_pos
= glyph
->charpos
;
13883 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13885 if (!NILP (chprop
))
13887 /* If the string came from a `display' text property,
13888 look up the buffer position of that property and
13889 use that position to update bpos_max, as if we
13890 actually saw such a position in one of the row's
13891 glyphs. This helps with supporting integer values
13892 of `cursor' property on the display string in
13893 situations where most or all of the row's buffer
13894 text is completely covered by display properties,
13895 so that no glyph with valid buffer positions is
13896 ever seen in the row. */
13897 ptrdiff_t prop_pos
=
13898 string_buffer_position_lim (glyph
->object
, pos_before
,
13901 if (prop_pos
>= pos_before
)
13902 bpos_max
= prop_pos
- 1;
13904 if (INTEGERP (chprop
))
13906 bpos_covered
= bpos_max
+ XINT (chprop
);
13907 /* If the `cursor' property covers buffer positions up
13908 to and including point, we should display cursor on
13909 this glyph. Note that, if a `cursor' property on one
13910 of the string's characters has an integer value, we
13911 will break out of the loop below _before_ we get to
13912 the position match above. IOW, integer values of
13913 the `cursor' property override the "exact match for
13914 point" strategy of positioning the cursor. */
13915 /* Implementation note: bpos_max == pt_old when, e.g.,
13916 we are in an empty line, where bpos_max is set to
13917 MATRIX_ROW_START_CHARPOS, see above. */
13918 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13927 x
+= glyph
->pixel_width
;
13930 else if (glyph
> end
) /* row is reversed */
13931 while (!INTEGERP (glyph
->object
))
13933 if (BUFFERP (glyph
->object
))
13935 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13937 if (glyph
->charpos
> bpos_max
)
13938 bpos_max
= glyph
->charpos
;
13939 if (glyph
->charpos
< bpos_min
)
13940 bpos_min
= glyph
->charpos
;
13941 if (!glyph
->avoid_cursor_p
)
13945 match_with_avoid_cursor
= 0;
13948 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13950 pos_before
= glyph
->charpos
;
13951 glyph_before
= glyph
;
13953 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13955 pos_after
= glyph
->charpos
;
13956 glyph_after
= glyph
;
13959 else if (dpos
== 0)
13960 match_with_avoid_cursor
= 1;
13962 else if (STRINGP (glyph
->object
))
13964 Lisp_Object chprop
;
13965 ptrdiff_t glyph_pos
= glyph
->charpos
;
13967 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13969 if (!NILP (chprop
))
13971 ptrdiff_t prop_pos
=
13972 string_buffer_position_lim (glyph
->object
, pos_before
,
13975 if (prop_pos
>= pos_before
)
13976 bpos_max
= prop_pos
- 1;
13978 if (INTEGERP (chprop
))
13980 bpos_covered
= bpos_max
+ XINT (chprop
);
13981 /* If the `cursor' property covers buffer positions up
13982 to and including point, we should display cursor on
13984 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13993 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13995 x
--; /* can't use any pixel_width */
13998 x
-= glyph
->pixel_width
;
14001 /* Step 2: If we didn't find an exact match for point, we need to
14002 look for a proper place to put the cursor among glyphs between
14003 GLYPH_BEFORE and GLYPH_AFTER. */
14004 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14005 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14006 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14008 /* An empty line has a single glyph whose OBJECT is zero and
14009 whose CHARPOS is the position of a newline on that line.
14010 Note that on a TTY, there are more glyphs after that, which
14011 were produced by extend_face_to_end_of_line, but their
14012 CHARPOS is zero or negative. */
14014 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14015 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14016 /* On a TTY, continued and truncated rows also have a glyph at
14017 their end whose OBJECT is zero and whose CHARPOS is
14018 positive (the continuation and truncation glyphs), but such
14019 rows are obviously not "empty". */
14020 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14022 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14024 ptrdiff_t ellipsis_pos
;
14026 /* Scan back over the ellipsis glyphs. */
14027 if (!row
->reversed_p
)
14029 ellipsis_pos
= (glyph
- 1)->charpos
;
14030 while (glyph
> row
->glyphs
[TEXT_AREA
]
14031 && (glyph
- 1)->charpos
== ellipsis_pos
)
14032 glyph
--, x
-= glyph
->pixel_width
;
14033 /* That loop always goes one position too far, including
14034 the glyph before the ellipsis. So scan forward over
14036 x
+= glyph
->pixel_width
;
14039 else /* row is reversed */
14041 ellipsis_pos
= (glyph
+ 1)->charpos
;
14042 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14043 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14044 glyph
++, x
+= glyph
->pixel_width
;
14045 x
-= glyph
->pixel_width
;
14049 else if (match_with_avoid_cursor
)
14051 cursor
= glyph_after
;
14054 else if (string_seen
)
14056 int incr
= row
->reversed_p
? -1 : +1;
14058 /* Need to find the glyph that came out of a string which is
14059 present at point. That glyph is somewhere between
14060 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14061 positioned between POS_BEFORE and POS_AFTER in the
14063 struct glyph
*start
, *stop
;
14064 ptrdiff_t pos
= pos_before
;
14068 /* If the row ends in a newline from a display string,
14069 reordering could have moved the glyphs belonging to the
14070 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14071 in this case we extend the search to the last glyph in
14072 the row that was not inserted by redisplay. */
14073 if (row
->ends_in_newline_from_string_p
)
14076 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14079 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14080 correspond to POS_BEFORE and POS_AFTER, respectively. We
14081 need START and STOP in the order that corresponds to the
14082 row's direction as given by its reversed_p flag. If the
14083 directionality of characters between POS_BEFORE and
14084 POS_AFTER is the opposite of the row's base direction,
14085 these characters will have been reordered for display,
14086 and we need to reverse START and STOP. */
14087 if (!row
->reversed_p
)
14089 start
= min (glyph_before
, glyph_after
);
14090 stop
= max (glyph_before
, glyph_after
);
14094 start
= max (glyph_before
, glyph_after
);
14095 stop
= min (glyph_before
, glyph_after
);
14097 for (glyph
= start
+ incr
;
14098 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14101 /* Any glyphs that come from the buffer are here because
14102 of bidi reordering. Skip them, and only pay
14103 attention to glyphs that came from some string. */
14104 if (STRINGP (glyph
->object
))
14108 /* If the display property covers the newline, we
14109 need to search for it one position farther. */
14110 ptrdiff_t lim
= pos_after
14111 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14113 string_from_text_prop
= 0;
14114 str
= glyph
->object
;
14115 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14116 if (tem
== 0 /* from overlay */
14119 /* If the string from which this glyph came is
14120 found in the buffer at point, or at position
14121 that is closer to point than pos_after, then
14122 we've found the glyph we've been looking for.
14123 If it comes from an overlay (tem == 0), and
14124 it has the `cursor' property on one of its
14125 glyphs, record that glyph as a candidate for
14126 displaying the cursor. (As in the
14127 unidirectional version, we will display the
14128 cursor on the last candidate we find.) */
14131 || (tem
- pt_old
> 0 && tem
< pos_after
))
14133 /* The glyphs from this string could have
14134 been reordered. Find the one with the
14135 smallest string position. Or there could
14136 be a character in the string with the
14137 `cursor' property, which means display
14138 cursor on that character's glyph. */
14139 ptrdiff_t strpos
= glyph
->charpos
;
14144 string_from_text_prop
= 1;
14147 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14148 && EQ (glyph
->object
, str
);
14152 ptrdiff_t gpos
= glyph
->charpos
;
14154 cprop
= Fget_char_property (make_number (gpos
),
14162 if (tem
&& glyph
->charpos
< strpos
)
14164 strpos
= glyph
->charpos
;
14170 || (tem
- pt_old
> 0 && tem
< pos_after
))
14174 pos
= tem
+ 1; /* don't find previous instances */
14176 /* This string is not what we want; skip all of the
14177 glyphs that came from it. */
14178 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14179 && EQ (glyph
->object
, str
))
14186 /* If we reached the end of the line, and END was from a string,
14187 the cursor is not on this line. */
14189 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14190 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14191 && STRINGP (end
->object
)
14192 && row
->continued_p
)
14195 /* A truncated row may not include PT among its character positions.
14196 Setting the cursor inside the scroll margin will trigger
14197 recalculation of hscroll in hscroll_window_tree. But if a
14198 display string covers point, defer to the string-handling
14199 code below to figure this out. */
14200 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14202 cursor
= glyph_before
;
14205 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14206 /* Zero-width characters produce no glyphs. */
14208 && (row
->reversed_p
14209 ? glyph_after
> glyphs_end
14210 : glyph_after
< glyphs_end
)))
14212 cursor
= glyph_after
;
14218 if (cursor
!= NULL
)
14220 else if (glyph
== glyphs_end
14221 && pos_before
== pos_after
14222 && STRINGP ((row
->reversed_p
14223 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14224 : row
->glyphs
[TEXT_AREA
])->object
))
14226 /* If all the glyphs of this row came from strings, put the
14227 cursor on the first glyph of the row. This avoids having the
14228 cursor outside of the text area in this very rare and hard
14232 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14233 : row
->glyphs
[TEXT_AREA
];
14239 /* Need to compute x that corresponds to GLYPH. */
14240 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14242 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14244 x
+= g
->pixel_width
;
14248 /* ROW could be part of a continued line, which, under bidi
14249 reordering, might have other rows whose start and end charpos
14250 occlude point. Only set w->cursor if we found a better
14251 approximation to the cursor position than we have from previously
14252 examined candidate rows belonging to the same continued line. */
14253 if (/* we already have a candidate row */
14254 w
->cursor
.vpos
>= 0
14255 /* that candidate is not the row we are processing */
14256 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14257 /* Make sure cursor.vpos specifies a row whose start and end
14258 charpos occlude point, and it is valid candidate for being a
14259 cursor-row. This is because some callers of this function
14260 leave cursor.vpos at the row where the cursor was displayed
14261 during the last redisplay cycle. */
14262 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14263 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14264 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14267 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14269 /* Don't consider glyphs that are outside TEXT_AREA. */
14270 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14272 /* Keep the candidate whose buffer position is the closest to
14273 point or has the `cursor' property. */
14274 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14275 w
->cursor
.hpos
>= 0
14276 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14277 && ((BUFFERP (g1
->object
)
14278 && (g1
->charpos
== pt_old
/* an exact match always wins */
14279 || (BUFFERP (glyph
->object
)
14280 && eabs (g1
->charpos
- pt_old
)
14281 < eabs (glyph
->charpos
- pt_old
))))
14282 /* previous candidate is a glyph from a string that has
14283 a non-nil `cursor' property */
14284 || (STRINGP (g1
->object
)
14285 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14286 Qcursor
, g1
->object
))
14287 /* previous candidate is from the same display
14288 string as this one, and the display string
14289 came from a text property */
14290 || (EQ (g1
->object
, glyph
->object
)
14291 && string_from_text_prop
)
14292 /* this candidate is from newline and its
14293 position is not an exact match */
14294 || (INTEGERP (glyph
->object
)
14295 && glyph
->charpos
!= pt_old
)))))
14297 /* If this candidate gives an exact match, use that. */
14298 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14299 /* If this candidate is a glyph created for the
14300 terminating newline of a line, and point is on that
14301 newline, it wins because it's an exact match. */
14302 || (!row
->continued_p
14303 && INTEGERP (glyph
->object
)
14304 && glyph
->charpos
== 0
14305 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14306 /* Otherwise, keep the candidate that comes from a row
14307 spanning less buffer positions. This may win when one or
14308 both candidate positions are on glyphs that came from
14309 display strings, for which we cannot compare buffer
14311 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14312 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14313 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14316 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14318 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14319 w
->cursor
.y
= row
->y
+ dy
;
14321 if (w
== XWINDOW (selected_window
))
14323 if (!row
->continued_p
14324 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14327 this_line_buffer
= XBUFFER (w
->contents
);
14329 CHARPOS (this_line_start_pos
)
14330 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14331 BYTEPOS (this_line_start_pos
)
14332 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14334 CHARPOS (this_line_end_pos
)
14335 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14336 BYTEPOS (this_line_end_pos
)
14337 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14339 this_line_y
= w
->cursor
.y
;
14340 this_line_pixel_height
= row
->height
;
14341 this_line_vpos
= w
->cursor
.vpos
;
14342 this_line_start_x
= row
->x
;
14345 CHARPOS (this_line_start_pos
) = 0;
14352 /* Run window scroll functions, if any, for WINDOW with new window
14353 start STARTP. Sets the window start of WINDOW to that position.
14355 We assume that the window's buffer is really current. */
14357 static struct text_pos
14358 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14360 struct window
*w
= XWINDOW (window
);
14361 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14363 if (current_buffer
!= XBUFFER (w
->contents
))
14366 if (!NILP (Vwindow_scroll_functions
))
14368 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14369 make_number (CHARPOS (startp
)));
14370 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14371 /* In case the hook functions switch buffers. */
14372 set_buffer_internal (XBUFFER (w
->contents
));
14379 /* Make sure the line containing the cursor is fully visible.
14380 A value of 1 means there is nothing to be done.
14381 (Either the line is fully visible, or it cannot be made so,
14382 or we cannot tell.)
14384 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14385 is higher than window.
14387 A value of 0 means the caller should do scrolling
14388 as if point had gone off the screen. */
14391 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14393 struct glyph_matrix
*matrix
;
14394 struct glyph_row
*row
;
14397 if (!make_cursor_line_fully_visible_p
)
14400 /* It's not always possible to find the cursor, e.g, when a window
14401 is full of overlay strings. Don't do anything in that case. */
14402 if (w
->cursor
.vpos
< 0)
14405 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14406 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14408 /* If the cursor row is not partially visible, there's nothing to do. */
14409 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14412 /* If the row the cursor is in is taller than the window's height,
14413 it's not clear what to do, so do nothing. */
14414 window_height
= window_box_height (w
);
14415 if (row
->height
>= window_height
)
14417 if (!force_p
|| MINI_WINDOW_P (w
)
14418 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14425 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14426 non-zero means only WINDOW is redisplayed in redisplay_internal.
14427 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14428 in redisplay_window to bring a partially visible line into view in
14429 the case that only the cursor has moved.
14431 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14432 last screen line's vertical height extends past the end of the screen.
14436 1 if scrolling succeeded
14438 0 if scrolling didn't find point.
14440 -1 if new fonts have been loaded so that we must interrupt
14441 redisplay, adjust glyph matrices, and try again. */
14447 SCROLLING_NEED_LARGER_MATRICES
14450 /* If scroll-conservatively is more than this, never recenter.
14452 If you change this, don't forget to update the doc string of
14453 `scroll-conservatively' and the Emacs manual. */
14454 #define SCROLL_LIMIT 100
14457 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14458 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14459 int temp_scroll_step
, int last_line_misfit
)
14461 struct window
*w
= XWINDOW (window
);
14462 struct frame
*f
= XFRAME (w
->frame
);
14463 struct text_pos pos
, startp
;
14465 int this_scroll_margin
, scroll_max
, rc
, height
;
14466 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14467 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14468 Lisp_Object aggressive
;
14469 /* We will never try scrolling more than this number of lines. */
14470 int scroll_limit
= SCROLL_LIMIT
;
14473 debug_method_add (w
, "try_scrolling");
14476 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14478 /* Compute scroll margin height in pixels. We scroll when point is
14479 within this distance from the top or bottom of the window. */
14480 if (scroll_margin
> 0)
14481 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14482 * FRAME_LINE_HEIGHT (f
);
14484 this_scroll_margin
= 0;
14486 /* Force arg_scroll_conservatively to have a reasonable value, to
14487 avoid scrolling too far away with slow move_it_* functions. Note
14488 that the user can supply scroll-conservatively equal to
14489 `most-positive-fixnum', which can be larger than INT_MAX. */
14490 if (arg_scroll_conservatively
> scroll_limit
)
14492 arg_scroll_conservatively
= scroll_limit
+ 1;
14493 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14495 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14496 /* Compute how much we should try to scroll maximally to bring
14497 point into view. */
14498 scroll_max
= (max (scroll_step
,
14499 max (arg_scroll_conservatively
, temp_scroll_step
))
14500 * FRAME_LINE_HEIGHT (f
));
14501 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14502 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14503 /* We're trying to scroll because of aggressive scrolling but no
14504 scroll_step is set. Choose an arbitrary one. */
14505 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14511 /* Decide whether to scroll down. */
14512 if (PT
> CHARPOS (startp
))
14514 int scroll_margin_y
;
14516 /* Compute the pixel ypos of the scroll margin, then move IT to
14517 either that ypos or PT, whichever comes first. */
14518 start_display (&it
, w
, startp
);
14519 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14520 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14521 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14522 (MOVE_TO_POS
| MOVE_TO_Y
));
14524 if (PT
> CHARPOS (it
.current
.pos
))
14526 int y0
= line_bottom_y (&it
);
14527 /* Compute how many pixels below window bottom to stop searching
14528 for PT. This avoids costly search for PT that is far away if
14529 the user limited scrolling by a small number of lines, but
14530 always finds PT if scroll_conservatively is set to a large
14531 number, such as most-positive-fixnum. */
14532 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14533 int y_to_move
= it
.last_visible_y
+ slack
;
14535 /* Compute the distance from the scroll margin to PT or to
14536 the scroll limit, whichever comes first. This should
14537 include the height of the cursor line, to make that line
14539 move_it_to (&it
, PT
, -1, y_to_move
,
14540 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14541 dy
= line_bottom_y (&it
) - y0
;
14543 if (dy
> scroll_max
)
14544 return SCROLLING_FAILED
;
14553 /* Point is in or below the bottom scroll margin, so move the
14554 window start down. If scrolling conservatively, move it just
14555 enough down to make point visible. If scroll_step is set,
14556 move it down by scroll_step. */
14557 if (arg_scroll_conservatively
)
14559 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14560 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14561 else if (scroll_step
|| temp_scroll_step
)
14562 amount_to_scroll
= scroll_max
;
14565 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14566 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14567 if (NUMBERP (aggressive
))
14569 double float_amount
= XFLOATINT (aggressive
) * height
;
14570 int aggressive_scroll
= float_amount
;
14571 if (aggressive_scroll
== 0 && float_amount
> 0)
14572 aggressive_scroll
= 1;
14573 /* Don't let point enter the scroll margin near top of
14574 the window. This could happen if the value of
14575 scroll_up_aggressively is too large and there are
14576 non-zero margins, because scroll_up_aggressively
14577 means put point that fraction of window height
14578 _from_the_bottom_margin_. */
14579 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14580 aggressive_scroll
= height
- 2*this_scroll_margin
;
14581 amount_to_scroll
= dy
+ aggressive_scroll
;
14585 if (amount_to_scroll
<= 0)
14586 return SCROLLING_FAILED
;
14588 start_display (&it
, w
, startp
);
14589 if (arg_scroll_conservatively
<= scroll_limit
)
14590 move_it_vertically (&it
, amount_to_scroll
);
14593 /* Extra precision for users who set scroll-conservatively
14594 to a large number: make sure the amount we scroll
14595 the window start is never less than amount_to_scroll,
14596 which was computed as distance from window bottom to
14597 point. This matters when lines at window top and lines
14598 below window bottom have different height. */
14600 void *it1data
= NULL
;
14601 /* We use a temporary it1 because line_bottom_y can modify
14602 its argument, if it moves one line down; see there. */
14605 SAVE_IT (it1
, it
, it1data
);
14606 start_y
= line_bottom_y (&it1
);
14608 RESTORE_IT (&it
, &it
, it1data
);
14609 move_it_by_lines (&it
, 1);
14610 SAVE_IT (it1
, it
, it1data
);
14611 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14614 /* If STARTP is unchanged, move it down another screen line. */
14615 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14616 move_it_by_lines (&it
, 1);
14617 startp
= it
.current
.pos
;
14621 struct text_pos scroll_margin_pos
= startp
;
14624 /* See if point is inside the scroll margin at the top of the
14626 if (this_scroll_margin
)
14630 start_display (&it
, w
, startp
);
14631 y_start
= it
.current_y
;
14632 move_it_vertically (&it
, this_scroll_margin
);
14633 scroll_margin_pos
= it
.current
.pos
;
14634 /* If we didn't move enough before hitting ZV, request
14635 additional amount of scroll, to move point out of the
14637 if (IT_CHARPOS (it
) == ZV
14638 && it
.current_y
- y_start
< this_scroll_margin
)
14639 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14642 if (PT
< CHARPOS (scroll_margin_pos
))
14644 /* Point is in the scroll margin at the top of the window or
14645 above what is displayed in the window. */
14648 /* Compute the vertical distance from PT to the scroll
14649 margin position. Move as far as scroll_max allows, or
14650 one screenful, or 10 screen lines, whichever is largest.
14651 Give up if distance is greater than scroll_max or if we
14652 didn't reach the scroll margin position. */
14653 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14654 start_display (&it
, w
, pos
);
14656 y_to_move
= max (it
.last_visible_y
,
14657 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14658 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14660 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14661 dy
= it
.current_y
- y0
;
14662 if (dy
> scroll_max
14663 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14664 return SCROLLING_FAILED
;
14666 /* Additional scroll for when ZV was too close to point. */
14669 /* Compute new window start. */
14670 start_display (&it
, w
, startp
);
14672 if (arg_scroll_conservatively
)
14673 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14674 max (scroll_step
, temp_scroll_step
));
14675 else if (scroll_step
|| temp_scroll_step
)
14676 amount_to_scroll
= scroll_max
;
14679 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14680 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14681 if (NUMBERP (aggressive
))
14683 double float_amount
= XFLOATINT (aggressive
) * height
;
14684 int aggressive_scroll
= float_amount
;
14685 if (aggressive_scroll
== 0 && float_amount
> 0)
14686 aggressive_scroll
= 1;
14687 /* Don't let point enter the scroll margin near
14688 bottom of the window, if the value of
14689 scroll_down_aggressively happens to be too
14691 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14692 aggressive_scroll
= height
- 2*this_scroll_margin
;
14693 amount_to_scroll
= dy
+ aggressive_scroll
;
14697 if (amount_to_scroll
<= 0)
14698 return SCROLLING_FAILED
;
14700 move_it_vertically_backward (&it
, amount_to_scroll
);
14701 startp
= it
.current
.pos
;
14705 /* Run window scroll functions. */
14706 startp
= run_window_scroll_functions (window
, startp
);
14708 /* Display the window. Give up if new fonts are loaded, or if point
14710 if (!try_window (window
, startp
, 0))
14711 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14712 else if (w
->cursor
.vpos
< 0)
14714 clear_glyph_matrix (w
->desired_matrix
);
14715 rc
= SCROLLING_FAILED
;
14719 /* Maybe forget recorded base line for line number display. */
14720 if (!just_this_one_p
14721 || current_buffer
->clip_changed
14722 || BEG_UNCHANGED
< CHARPOS (startp
))
14723 w
->base_line_number
= 0;
14725 /* If cursor ends up on a partially visible line,
14726 treat that as being off the bottom of the screen. */
14727 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14728 /* It's possible that the cursor is on the first line of the
14729 buffer, which is partially obscured due to a vscroll
14730 (Bug#7537). In that case, avoid looping forever . */
14731 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14733 clear_glyph_matrix (w
->desired_matrix
);
14734 ++extra_scroll_margin_lines
;
14737 rc
= SCROLLING_SUCCESS
;
14744 /* Compute a suitable window start for window W if display of W starts
14745 on a continuation line. Value is non-zero if a new window start
14748 The new window start will be computed, based on W's width, starting
14749 from the start of the continued line. It is the start of the
14750 screen line with the minimum distance from the old start W->start. */
14753 compute_window_start_on_continuation_line (struct window
*w
)
14755 struct text_pos pos
, start_pos
;
14756 int window_start_changed_p
= 0;
14758 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14760 /* If window start is on a continuation line... Window start may be
14761 < BEGV in case there's invisible text at the start of the
14762 buffer (M-x rmail, for example). */
14763 if (CHARPOS (start_pos
) > BEGV
14764 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14767 struct glyph_row
*row
;
14769 /* Handle the case that the window start is out of range. */
14770 if (CHARPOS (start_pos
) < BEGV
)
14771 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14772 else if (CHARPOS (start_pos
) > ZV
)
14773 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14775 /* Find the start of the continued line. This should be fast
14776 because find_newline is fast (newline cache). */
14777 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14778 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14779 row
, DEFAULT_FACE_ID
);
14780 reseat_at_previous_visible_line_start (&it
);
14782 /* If the line start is "too far" away from the window start,
14783 say it takes too much time to compute a new window start. */
14784 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14785 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14787 int min_distance
, distance
;
14789 /* Move forward by display lines to find the new window
14790 start. If window width was enlarged, the new start can
14791 be expected to be > the old start. If window width was
14792 decreased, the new window start will be < the old start.
14793 So, we're looking for the display line start with the
14794 minimum distance from the old window start. */
14795 pos
= it
.current
.pos
;
14796 min_distance
= INFINITY
;
14797 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14798 distance
< min_distance
)
14800 min_distance
= distance
;
14801 pos
= it
.current
.pos
;
14802 move_it_by_lines (&it
, 1);
14805 /* Set the window start there. */
14806 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14807 window_start_changed_p
= 1;
14811 return window_start_changed_p
;
14815 /* Try cursor movement in case text has not changed in window WINDOW,
14816 with window start STARTP. Value is
14818 CURSOR_MOVEMENT_SUCCESS if successful
14820 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14822 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14823 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14824 we want to scroll as if scroll-step were set to 1. See the code.
14826 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14827 which case we have to abort this redisplay, and adjust matrices
14832 CURSOR_MOVEMENT_SUCCESS
,
14833 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14834 CURSOR_MOVEMENT_MUST_SCROLL
,
14835 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14839 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14841 struct window
*w
= XWINDOW (window
);
14842 struct frame
*f
= XFRAME (w
->frame
);
14843 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14846 if (inhibit_try_cursor_movement
)
14850 /* Previously, there was a check for Lisp integer in the
14851 if-statement below. Now, this field is converted to
14852 ptrdiff_t, thus zero means invalid position in a buffer. */
14853 eassert (w
->last_point
> 0);
14855 /* Handle case where text has not changed, only point, and it has
14856 not moved off the frame. */
14857 if (/* Point may be in this window. */
14858 PT
>= CHARPOS (startp
)
14859 /* Selective display hasn't changed. */
14860 && !current_buffer
->clip_changed
14861 /* Function force-mode-line-update is used to force a thorough
14862 redisplay. It sets either windows_or_buffers_changed or
14863 update_mode_lines. So don't take a shortcut here for these
14865 && !update_mode_lines
14866 && !windows_or_buffers_changed
14867 && !cursor_type_changed
14868 /* Can't use this case if highlighting a region. When a
14869 region exists, cursor movement has to do more than just
14871 && markpos_of_region () < 0
14872 && !w
->region_showing
14873 && NILP (Vshow_trailing_whitespace
)
14874 /* This code is not used for mini-buffer for the sake of the case
14875 of redisplaying to replace an echo area message; since in
14876 that case the mini-buffer contents per se are usually
14877 unchanged. This code is of no real use in the mini-buffer
14878 since the handling of this_line_start_pos, etc., in redisplay
14879 handles the same cases. */
14880 && !EQ (window
, minibuf_window
)
14881 /* When splitting windows or for new windows, it happens that
14882 redisplay is called with a nil window_end_vpos or one being
14883 larger than the window. This should really be fixed in
14884 window.c. I don't have this on my list, now, so we do
14885 approximately the same as the old redisplay code. --gerd. */
14886 && INTEGERP (w
->window_end_vpos
)
14887 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14888 && (FRAME_WINDOW_P (f
)
14889 || !overlay_arrow_in_current_buffer_p ()))
14891 int this_scroll_margin
, top_scroll_margin
;
14892 struct glyph_row
*row
= NULL
;
14895 debug_method_add (w
, "cursor movement");
14898 /* Scroll if point within this distance from the top or bottom
14899 of the window. This is a pixel value. */
14900 if (scroll_margin
> 0)
14902 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14903 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14906 this_scroll_margin
= 0;
14908 top_scroll_margin
= this_scroll_margin
;
14909 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14910 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14912 /* Start with the row the cursor was displayed during the last
14913 not paused redisplay. Give up if that row is not valid. */
14914 if (w
->last_cursor
.vpos
< 0
14915 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14916 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14919 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14920 if (row
->mode_line_p
)
14922 if (!row
->enabled_p
)
14923 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14926 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14928 int scroll_p
= 0, must_scroll
= 0;
14929 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14931 if (PT
> w
->last_point
)
14933 /* Point has moved forward. */
14934 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14935 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14937 eassert (row
->enabled_p
);
14941 /* If the end position of a row equals the start
14942 position of the next row, and PT is at that position,
14943 we would rather display cursor in the next line. */
14944 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14945 && MATRIX_ROW_END_CHARPOS (row
) == PT
14946 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
14947 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14948 && !cursor_row_p (row
))
14951 /* If within the scroll margin, scroll. Note that
14952 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14953 the next line would be drawn, and that
14954 this_scroll_margin can be zero. */
14955 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14956 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14957 /* Line is completely visible last line in window
14958 and PT is to be set in the next line. */
14959 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14960 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14961 && !row
->ends_at_zv_p
14962 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14965 else if (PT
< w
->last_point
)
14967 /* Cursor has to be moved backward. Note that PT >=
14968 CHARPOS (startp) because of the outer if-statement. */
14969 while (!row
->mode_line_p
14970 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14971 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14972 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14973 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14974 row
> w
->current_matrix
->rows
14975 && (row
-1)->ends_in_newline_from_string_p
))))
14976 && (row
->y
> top_scroll_margin
14977 || CHARPOS (startp
) == BEGV
))
14979 eassert (row
->enabled_p
);
14983 /* Consider the following case: Window starts at BEGV,
14984 there is invisible, intangible text at BEGV, so that
14985 display starts at some point START > BEGV. It can
14986 happen that we are called with PT somewhere between
14987 BEGV and START. Try to handle that case. */
14988 if (row
< w
->current_matrix
->rows
14989 || row
->mode_line_p
)
14991 row
= w
->current_matrix
->rows
;
14992 if (row
->mode_line_p
)
14996 /* Due to newlines in overlay strings, we may have to
14997 skip forward over overlay strings. */
14998 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14999 && MATRIX_ROW_END_CHARPOS (row
) == PT
15000 && !cursor_row_p (row
))
15003 /* If within the scroll margin, scroll. */
15004 if (row
->y
< top_scroll_margin
15005 && CHARPOS (startp
) != BEGV
)
15010 /* Cursor did not move. So don't scroll even if cursor line
15011 is partially visible, as it was so before. */
15012 rc
= CURSOR_MOVEMENT_SUCCESS
;
15015 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15016 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15018 /* if PT is not in the glyph row, give up. */
15019 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15022 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15023 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15025 struct glyph_row
*row1
;
15027 /* If rows are bidi-reordered and point moved, back up
15028 until we find a row that does not belong to a
15029 continuation line. This is because we must consider
15030 all rows of a continued line as candidates for the
15031 new cursor positioning, since row start and end
15032 positions change non-linearly with vertical position
15034 /* FIXME: Revisit this when glyph ``spilling'' in
15035 continuation lines' rows is implemented for
15036 bidi-reordered rows. */
15037 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15038 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15041 /* If we hit the beginning of the displayed portion
15042 without finding the first row of a continued
15046 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15049 eassert (row
->enabled_p
);
15054 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15055 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15056 /* Make sure this isn't a header line by any chance, since
15057 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15058 && !row
->mode_line_p
15059 && make_cursor_line_fully_visible_p
)
15061 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15062 && !row
->ends_at_zv_p
15063 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15064 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15065 else if (row
->height
> window_box_height (w
))
15067 /* If we end up in a partially visible line, let's
15068 make it fully visible, except when it's taller
15069 than the window, in which case we can't do much
15072 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15076 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15077 if (!cursor_row_fully_visible_p (w
, 0, 1))
15078 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15080 rc
= CURSOR_MOVEMENT_SUCCESS
;
15084 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15085 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15086 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15088 /* With bidi-reordered rows, there could be more than
15089 one candidate row whose start and end positions
15090 occlude point. We need to let set_cursor_from_row
15091 find the best candidate. */
15092 /* FIXME: Revisit this when glyph ``spilling'' in
15093 continuation lines' rows is implemented for
15094 bidi-reordered rows. */
15099 int at_zv_p
= 0, exact_match_p
= 0;
15101 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15102 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15103 && cursor_row_p (row
))
15104 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15106 /* As soon as we've found the exact match for point,
15107 or the first suitable row whose ends_at_zv_p flag
15108 is set, we are done. */
15110 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15112 && w
->cursor
.hpos
>= 0
15113 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15116 struct glyph_row
*candidate
=
15117 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15119 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15120 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15123 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15124 || (INTEGERP (g
->object
)
15125 && (g
->charpos
== PT
15126 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15128 if (rv
&& (at_zv_p
|| exact_match_p
))
15130 rc
= CURSOR_MOVEMENT_SUCCESS
;
15133 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15137 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15138 || row
->continued_p
)
15139 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15140 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15141 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15142 /* If we didn't find any candidate rows, or exited the
15143 loop before all the candidates were examined, signal
15144 to the caller that this method failed. */
15145 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15147 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15148 && !row
->continued_p
))
15149 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15151 rc
= CURSOR_MOVEMENT_SUCCESS
;
15157 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15159 rc
= CURSOR_MOVEMENT_SUCCESS
;
15164 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15165 && MATRIX_ROW_START_CHARPOS (row
) == PT
15166 && cursor_row_p (row
));
15174 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15178 set_vertical_scroll_bar (struct window
*w
)
15180 ptrdiff_t start
, end
, whole
;
15182 /* Calculate the start and end positions for the current window.
15183 At some point, it would be nice to choose between scrollbars
15184 which reflect the whole buffer size, with special markers
15185 indicating narrowing, and scrollbars which reflect only the
15188 Note that mini-buffers sometimes aren't displaying any text. */
15189 if (!MINI_WINDOW_P (w
)
15190 || (w
== XWINDOW (minibuf_window
)
15191 && NILP (echo_area_buffer
[0])))
15193 struct buffer
*buf
= XBUFFER (w
->contents
);
15194 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15195 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15196 /* I don't think this is guaranteed to be right. For the
15197 moment, we'll pretend it is. */
15198 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15202 if (whole
< (end
- start
))
15203 whole
= end
- start
;
15206 start
= end
= whole
= 0;
15208 /* Indicate what this scroll bar ought to be displaying now. */
15209 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15210 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15211 (w
, end
- start
, whole
, start
);
15215 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15216 selected_window is redisplayed.
15218 We can return without actually redisplaying the window if
15219 fonts_changed_p. In that case, redisplay_internal will
15223 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15225 struct window
*w
= XWINDOW (window
);
15226 struct frame
*f
= XFRAME (w
->frame
);
15227 struct buffer
*buffer
= XBUFFER (w
->contents
);
15228 struct buffer
*old
= current_buffer
;
15229 struct text_pos lpoint
, opoint
, startp
;
15230 int update_mode_line
;
15233 /* Record it now because it's overwritten. */
15234 int current_matrix_up_to_date_p
= 0;
15235 int used_current_matrix_p
= 0;
15236 /* This is less strict than current_matrix_up_to_date_p.
15237 It indicates that the buffer contents and narrowing are unchanged. */
15238 int buffer_unchanged_p
= 0;
15239 int temp_scroll_step
= 0;
15240 ptrdiff_t count
= SPECPDL_INDEX ();
15242 int centering_position
= -1;
15243 int last_line_misfit
= 0;
15244 ptrdiff_t beg_unchanged
, end_unchanged
;
15246 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15250 *w
->desired_matrix
->method
= 0;
15253 /* Make sure that both W's markers are valid. */
15254 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15255 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15258 reconsider_clip_changes (w
, buffer
);
15260 /* Has the mode line to be updated? */
15261 update_mode_line
= (w
->update_mode_line
15262 || update_mode_lines
15263 || buffer
->clip_changed
15264 || buffer
->prevent_redisplay_optimizations_p
);
15266 if (MINI_WINDOW_P (w
))
15268 if (w
== XWINDOW (echo_area_window
)
15269 && !NILP (echo_area_buffer
[0]))
15271 if (update_mode_line
)
15272 /* We may have to update a tty frame's menu bar or a
15273 tool-bar. Example `M-x C-h C-h C-g'. */
15274 goto finish_menu_bars
;
15276 /* We've already displayed the echo area glyphs in this window. */
15277 goto finish_scroll_bars
;
15279 else if ((w
!= XWINDOW (minibuf_window
)
15280 || minibuf_level
== 0)
15281 /* When buffer is nonempty, redisplay window normally. */
15282 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15283 /* Quail displays non-mini buffers in minibuffer window.
15284 In that case, redisplay the window normally. */
15285 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15287 /* W is a mini-buffer window, but it's not active, so clear
15289 int yb
= window_text_bottom_y (w
);
15290 struct glyph_row
*row
;
15293 for (y
= 0, row
= w
->desired_matrix
->rows
;
15295 y
+= row
->height
, ++row
)
15296 blank_row (w
, row
, y
);
15297 goto finish_scroll_bars
;
15300 clear_glyph_matrix (w
->desired_matrix
);
15303 /* Otherwise set up data on this window; select its buffer and point
15305 /* Really select the buffer, for the sake of buffer-local
15307 set_buffer_internal_1 (XBUFFER (w
->contents
));
15309 current_matrix_up_to_date_p
15310 = (w
->window_end_valid
15311 && !current_buffer
->clip_changed
15312 && !current_buffer
->prevent_redisplay_optimizations_p
15313 && !window_outdated (w
));
15315 /* Run the window-bottom-change-functions
15316 if it is possible that the text on the screen has changed
15317 (either due to modification of the text, or any other reason). */
15318 if (!current_matrix_up_to_date_p
15319 && !NILP (Vwindow_text_change_functions
))
15321 safe_run_hooks (Qwindow_text_change_functions
);
15325 beg_unchanged
= BEG_UNCHANGED
;
15326 end_unchanged
= END_UNCHANGED
;
15328 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15330 specbind (Qinhibit_point_motion_hooks
, Qt
);
15333 = (w
->window_end_valid
15334 && !current_buffer
->clip_changed
15335 && !window_outdated (w
));
15337 /* When windows_or_buffers_changed is non-zero, we can't rely on
15338 the window end being valid, so set it to nil there. */
15339 if (windows_or_buffers_changed
)
15341 /* If window starts on a continuation line, maybe adjust the
15342 window start in case the window's width changed. */
15343 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15344 compute_window_start_on_continuation_line (w
);
15346 w
->window_end_valid
= 0;
15349 /* Some sanity checks. */
15350 CHECK_WINDOW_END (w
);
15351 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15353 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15356 if (mode_line_update_needed (w
))
15357 update_mode_line
= 1;
15359 /* Point refers normally to the selected window. For any other
15360 window, set up appropriate value. */
15361 if (!EQ (window
, selected_window
))
15363 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15364 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15368 new_pt_byte
= BEGV_BYTE
;
15369 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15371 else if (new_pt
> (ZV
- 1))
15374 new_pt_byte
= ZV_BYTE
;
15375 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15378 /* We don't use SET_PT so that the point-motion hooks don't run. */
15379 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15382 /* If any of the character widths specified in the display table
15383 have changed, invalidate the width run cache. It's true that
15384 this may be a bit late to catch such changes, but the rest of
15385 redisplay goes (non-fatally) haywire when the display table is
15386 changed, so why should we worry about doing any better? */
15387 if (current_buffer
->width_run_cache
)
15389 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15391 if (! disptab_matches_widthtab
15392 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15394 invalidate_region_cache (current_buffer
,
15395 current_buffer
->width_run_cache
,
15397 recompute_width_table (current_buffer
, disptab
);
15401 /* If window-start is screwed up, choose a new one. */
15402 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15405 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15407 /* If someone specified a new starting point but did not insist,
15408 check whether it can be used. */
15409 if (w
->optional_new_start
15410 && CHARPOS (startp
) >= BEGV
15411 && CHARPOS (startp
) <= ZV
)
15413 w
->optional_new_start
= 0;
15414 start_display (&it
, w
, startp
);
15415 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15416 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15417 if (IT_CHARPOS (it
) == PT
)
15418 w
->force_start
= 1;
15419 /* IT may overshoot PT if text at PT is invisible. */
15420 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15421 w
->force_start
= 1;
15426 /* Handle case where place to start displaying has been specified,
15427 unless the specified location is outside the accessible range. */
15428 if (w
->force_start
|| w
->frozen_window_start_p
)
15430 /* We set this later on if we have to adjust point. */
15433 w
->force_start
= 0;
15435 w
->window_end_valid
= 0;
15437 /* Forget any recorded base line for line number display. */
15438 if (!buffer_unchanged_p
)
15439 w
->base_line_number
= 0;
15441 /* Redisplay the mode line. Select the buffer properly for that.
15442 Also, run the hook window-scroll-functions
15443 because we have scrolled. */
15444 /* Note, we do this after clearing force_start because
15445 if there's an error, it is better to forget about force_start
15446 than to get into an infinite loop calling the hook functions
15447 and having them get more errors. */
15448 if (!update_mode_line
15449 || ! NILP (Vwindow_scroll_functions
))
15451 update_mode_line
= 1;
15452 w
->update_mode_line
= 1;
15453 startp
= run_window_scroll_functions (window
, startp
);
15456 w
->last_modified
= 0;
15457 w
->last_overlay_modified
= 0;
15458 if (CHARPOS (startp
) < BEGV
)
15459 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15460 else if (CHARPOS (startp
) > ZV
)
15461 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15463 /* Redisplay, then check if cursor has been set during the
15464 redisplay. Give up if new fonts were loaded. */
15465 /* We used to issue a CHECK_MARGINS argument to try_window here,
15466 but this causes scrolling to fail when point begins inside
15467 the scroll margin (bug#148) -- cyd */
15468 if (!try_window (window
, startp
, 0))
15470 w
->force_start
= 1;
15471 clear_glyph_matrix (w
->desired_matrix
);
15472 goto need_larger_matrices
;
15475 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15477 /* If point does not appear, try to move point so it does
15478 appear. The desired matrix has been built above, so we
15479 can use it here. */
15480 new_vpos
= window_box_height (w
) / 2;
15483 if (!cursor_row_fully_visible_p (w
, 0, 0))
15485 /* Point does appear, but on a line partly visible at end of window.
15486 Move it back to a fully-visible line. */
15487 new_vpos
= window_box_height (w
);
15489 else if (w
->cursor
.vpos
>=0)
15491 /* Some people insist on not letting point enter the scroll
15492 margin, even though this part handles windows that didn't
15494 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15495 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15496 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15498 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15499 below, which finds the row to move point to, advances by
15500 the Y coordinate of the _next_ row, see the definition of
15501 MATRIX_ROW_BOTTOM_Y. */
15502 if (w
->cursor
.vpos
< margin
+ header_line
)
15504 = pixel_margin
+ (header_line
15505 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15506 : 0) + FRAME_LINE_HEIGHT (f
);
15509 int window_height
= window_box_height (w
);
15512 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15513 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15514 new_vpos
= window_height
- pixel_margin
;
15518 /* If we need to move point for either of the above reasons,
15519 now actually do it. */
15522 struct glyph_row
*row
;
15524 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15525 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15528 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15529 MATRIX_ROW_START_BYTEPOS (row
));
15531 if (w
!= XWINDOW (selected_window
))
15532 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15533 else if (current_buffer
== old
)
15534 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15536 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15538 /* If we are highlighting the region, then we just changed
15539 the region, so redisplay to show it. */
15540 if (markpos_of_region () >= 0)
15542 clear_glyph_matrix (w
->desired_matrix
);
15543 if (!try_window (window
, startp
, 0))
15544 goto need_larger_matrices
;
15549 debug_method_add (w
, "forced window start");
15554 /* Handle case where text has not changed, only point, and it has
15555 not moved off the frame, and we are not retrying after hscroll.
15556 (current_matrix_up_to_date_p is nonzero when retrying.) */
15557 if (current_matrix_up_to_date_p
15558 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15559 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15563 case CURSOR_MOVEMENT_SUCCESS
:
15564 used_current_matrix_p
= 1;
15567 case CURSOR_MOVEMENT_MUST_SCROLL
:
15568 goto try_to_scroll
;
15574 /* If current starting point was originally the beginning of a line
15575 but no longer is, find a new starting point. */
15576 else if (w
->start_at_line_beg
15577 && !(CHARPOS (startp
) <= BEGV
15578 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15581 debug_method_add (w
, "recenter 1");
15586 /* Try scrolling with try_window_id. Value is > 0 if update has
15587 been done, it is -1 if we know that the same window start will
15588 not work. It is 0 if unsuccessful for some other reason. */
15589 else if ((tem
= try_window_id (w
)) != 0)
15592 debug_method_add (w
, "try_window_id %d", tem
);
15595 if (fonts_changed_p
)
15596 goto need_larger_matrices
;
15600 /* Otherwise try_window_id has returned -1 which means that we
15601 don't want the alternative below this comment to execute. */
15603 else if (CHARPOS (startp
) >= BEGV
15604 && CHARPOS (startp
) <= ZV
15605 && PT
>= CHARPOS (startp
)
15606 && (CHARPOS (startp
) < ZV
15607 /* Avoid starting at end of buffer. */
15608 || CHARPOS (startp
) == BEGV
15609 || !window_outdated (w
)))
15611 int d1
, d2
, d3
, d4
, d5
, d6
;
15613 /* If first window line is a continuation line, and window start
15614 is inside the modified region, but the first change is before
15615 current window start, we must select a new window start.
15617 However, if this is the result of a down-mouse event (e.g. by
15618 extending the mouse-drag-overlay), we don't want to select a
15619 new window start, since that would change the position under
15620 the mouse, resulting in an unwanted mouse-movement rather
15621 than a simple mouse-click. */
15622 if (!w
->start_at_line_beg
15623 && NILP (do_mouse_tracking
)
15624 && CHARPOS (startp
) > BEGV
15625 && CHARPOS (startp
) > BEG
+ beg_unchanged
15626 && CHARPOS (startp
) <= Z
- end_unchanged
15627 /* Even if w->start_at_line_beg is nil, a new window may
15628 start at a line_beg, since that's how set_buffer_window
15629 sets it. So, we need to check the return value of
15630 compute_window_start_on_continuation_line. (See also
15632 && XMARKER (w
->start
)->buffer
== current_buffer
15633 && compute_window_start_on_continuation_line (w
)
15634 /* It doesn't make sense to force the window start like we
15635 do at label force_start if it is already known that point
15636 will not be visible in the resulting window, because
15637 doing so will move point from its correct position
15638 instead of scrolling the window to bring point into view.
15640 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15642 w
->force_start
= 1;
15643 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15648 debug_method_add (w
, "same window start");
15651 /* Try to redisplay starting at same place as before.
15652 If point has not moved off frame, accept the results. */
15653 if (!current_matrix_up_to_date_p
15654 /* Don't use try_window_reusing_current_matrix in this case
15655 because a window scroll function can have changed the
15657 || !NILP (Vwindow_scroll_functions
)
15658 || MINI_WINDOW_P (w
)
15659 || !(used_current_matrix_p
15660 = try_window_reusing_current_matrix (w
)))
15662 IF_DEBUG (debug_method_add (w
, "1"));
15663 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15664 /* -1 means we need to scroll.
15665 0 means we need new matrices, but fonts_changed_p
15666 is set in that case, so we will detect it below. */
15667 goto try_to_scroll
;
15670 if (fonts_changed_p
)
15671 goto need_larger_matrices
;
15673 if (w
->cursor
.vpos
>= 0)
15675 if (!just_this_one_p
15676 || current_buffer
->clip_changed
15677 || BEG_UNCHANGED
< CHARPOS (startp
))
15678 /* Forget any recorded base line for line number display. */
15679 w
->base_line_number
= 0;
15681 if (!cursor_row_fully_visible_p (w
, 1, 0))
15683 clear_glyph_matrix (w
->desired_matrix
);
15684 last_line_misfit
= 1;
15686 /* Drop through and scroll. */
15691 clear_glyph_matrix (w
->desired_matrix
);
15696 w
->last_modified
= 0;
15697 w
->last_overlay_modified
= 0;
15699 /* Redisplay the mode line. Select the buffer properly for that. */
15700 if (!update_mode_line
)
15702 update_mode_line
= 1;
15703 w
->update_mode_line
= 1;
15706 /* Try to scroll by specified few lines. */
15707 if ((scroll_conservatively
15708 || emacs_scroll_step
15709 || temp_scroll_step
15710 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15711 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15712 && CHARPOS (startp
) >= BEGV
15713 && CHARPOS (startp
) <= ZV
)
15715 /* The function returns -1 if new fonts were loaded, 1 if
15716 successful, 0 if not successful. */
15717 int ss
= try_scrolling (window
, just_this_one_p
,
15718 scroll_conservatively
,
15720 temp_scroll_step
, last_line_misfit
);
15723 case SCROLLING_SUCCESS
:
15726 case SCROLLING_NEED_LARGER_MATRICES
:
15727 goto need_larger_matrices
;
15729 case SCROLLING_FAILED
:
15737 /* Finally, just choose a place to start which positions point
15738 according to user preferences. */
15743 debug_method_add (w
, "recenter");
15746 /* Forget any previously recorded base line for line number display. */
15747 if (!buffer_unchanged_p
)
15748 w
->base_line_number
= 0;
15750 /* Determine the window start relative to point. */
15751 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15752 it
.current_y
= it
.last_visible_y
;
15753 if (centering_position
< 0)
15757 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15759 ptrdiff_t margin_pos
= CHARPOS (startp
);
15760 Lisp_Object aggressive
;
15763 /* If there is a scroll margin at the top of the window, find
15764 its character position. */
15766 /* Cannot call start_display if startp is not in the
15767 accessible region of the buffer. This can happen when we
15768 have just switched to a different buffer and/or changed
15769 its restriction. In that case, startp is initialized to
15770 the character position 1 (BEGV) because we did not yet
15771 have chance to display the buffer even once. */
15772 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15775 void *it1data
= NULL
;
15777 SAVE_IT (it1
, it
, it1data
);
15778 start_display (&it1
, w
, startp
);
15779 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15780 margin_pos
= IT_CHARPOS (it1
);
15781 RESTORE_IT (&it
, &it
, it1data
);
15783 scrolling_up
= PT
> margin_pos
;
15786 ? BVAR (current_buffer
, scroll_up_aggressively
)
15787 : BVAR (current_buffer
, scroll_down_aggressively
);
15789 if (!MINI_WINDOW_P (w
)
15790 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15794 /* Setting scroll-conservatively overrides
15795 scroll-*-aggressively. */
15796 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15798 double float_amount
= XFLOATINT (aggressive
);
15800 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15801 if (pt_offset
== 0 && float_amount
> 0)
15803 if (pt_offset
&& margin
> 0)
15806 /* Compute how much to move the window start backward from
15807 point so that point will be displayed where the user
15811 centering_position
= it
.last_visible_y
;
15813 centering_position
-= pt_offset
;
15814 centering_position
-=
15815 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15816 + WINDOW_HEADER_LINE_HEIGHT (w
);
15817 /* Don't let point enter the scroll margin near top of
15819 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15820 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15823 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15826 /* Set the window start half the height of the window backward
15828 centering_position
= window_box_height (w
) / 2;
15830 move_it_vertically_backward (&it
, centering_position
);
15832 eassert (IT_CHARPOS (it
) >= BEGV
);
15834 /* The function move_it_vertically_backward may move over more
15835 than the specified y-distance. If it->w is small, e.g. a
15836 mini-buffer window, we may end up in front of the window's
15837 display area. Start displaying at the start of the line
15838 containing PT in this case. */
15839 if (it
.current_y
<= 0)
15841 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15842 move_it_vertically_backward (&it
, 0);
15846 it
.current_x
= it
.hpos
= 0;
15848 /* Set the window start position here explicitly, to avoid an
15849 infinite loop in case the functions in window-scroll-functions
15851 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15853 /* Run scroll hooks. */
15854 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15856 /* Redisplay the window. */
15857 if (!current_matrix_up_to_date_p
15858 || windows_or_buffers_changed
15859 || cursor_type_changed
15860 /* Don't use try_window_reusing_current_matrix in this case
15861 because it can have changed the buffer. */
15862 || !NILP (Vwindow_scroll_functions
)
15863 || !just_this_one_p
15864 || MINI_WINDOW_P (w
)
15865 || !(used_current_matrix_p
15866 = try_window_reusing_current_matrix (w
)))
15867 try_window (window
, startp
, 0);
15869 /* If new fonts have been loaded (due to fontsets), give up. We
15870 have to start a new redisplay since we need to re-adjust glyph
15872 if (fonts_changed_p
)
15873 goto need_larger_matrices
;
15875 /* If cursor did not appear assume that the middle of the window is
15876 in the first line of the window. Do it again with the next line.
15877 (Imagine a window of height 100, displaying two lines of height
15878 60. Moving back 50 from it->last_visible_y will end in the first
15880 if (w
->cursor
.vpos
< 0)
15882 if (w
->window_end_valid
&& PT
>= Z
- XFASTINT (w
->window_end_pos
))
15884 clear_glyph_matrix (w
->desired_matrix
);
15885 move_it_by_lines (&it
, 1);
15886 try_window (window
, it
.current
.pos
, 0);
15888 else if (PT
< IT_CHARPOS (it
))
15890 clear_glyph_matrix (w
->desired_matrix
);
15891 move_it_by_lines (&it
, -1);
15892 try_window (window
, it
.current
.pos
, 0);
15896 /* Not much we can do about it. */
15900 /* Consider the following case: Window starts at BEGV, there is
15901 invisible, intangible text at BEGV, so that display starts at
15902 some point START > BEGV. It can happen that we are called with
15903 PT somewhere between BEGV and START. Try to handle that case. */
15904 if (w
->cursor
.vpos
< 0)
15906 struct glyph_row
*row
= w
->current_matrix
->rows
;
15907 if (row
->mode_line_p
)
15909 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15912 if (!cursor_row_fully_visible_p (w
, 0, 0))
15914 /* If vscroll is enabled, disable it and try again. */
15918 clear_glyph_matrix (w
->desired_matrix
);
15922 /* Users who set scroll-conservatively to a large number want
15923 point just above/below the scroll margin. If we ended up
15924 with point's row partially visible, move the window start to
15925 make that row fully visible and out of the margin. */
15926 if (scroll_conservatively
> SCROLL_LIMIT
)
15930 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15932 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15934 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15935 clear_glyph_matrix (w
->desired_matrix
);
15936 if (1 == try_window (window
, it
.current
.pos
,
15937 TRY_WINDOW_CHECK_MARGINS
))
15941 /* If centering point failed to make the whole line visible,
15942 put point at the top instead. That has to make the whole line
15943 visible, if it can be done. */
15944 if (centering_position
== 0)
15947 clear_glyph_matrix (w
->desired_matrix
);
15948 centering_position
= 0;
15954 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15955 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
15956 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
15958 /* Display the mode line, if we must. */
15959 if ((update_mode_line
15960 /* If window not full width, must redo its mode line
15961 if (a) the window to its side is being redone and
15962 (b) we do a frame-based redisplay. This is a consequence
15963 of how inverted lines are drawn in frame-based redisplay. */
15964 || (!just_this_one_p
15965 && !FRAME_WINDOW_P (f
)
15966 && !WINDOW_FULL_WIDTH_P (w
))
15967 /* Line number to display. */
15968 || w
->base_line_pos
> 0
15969 /* Column number is displayed and different from the one displayed. */
15970 || (w
->column_number_displayed
!= -1
15971 && (w
->column_number_displayed
!= current_column ())))
15972 /* This means that the window has a mode line. */
15973 && (WINDOW_WANTS_MODELINE_P (w
)
15974 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15976 display_mode_lines (w
);
15978 /* If mode line height has changed, arrange for a thorough
15979 immediate redisplay using the correct mode line height. */
15980 if (WINDOW_WANTS_MODELINE_P (w
)
15981 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15983 fonts_changed_p
= 1;
15984 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15985 = DESIRED_MODE_LINE_HEIGHT (w
);
15988 /* If header line height has changed, arrange for a thorough
15989 immediate redisplay using the correct header line height. */
15990 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15991 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15993 fonts_changed_p
= 1;
15994 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15995 = DESIRED_HEADER_LINE_HEIGHT (w
);
15998 if (fonts_changed_p
)
15999 goto need_larger_matrices
;
16002 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16004 w
->base_line_pos
= 0;
16005 w
->base_line_number
= 0;
16010 /* When we reach a frame's selected window, redo the frame's menu bar. */
16011 if (update_mode_line
16012 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16014 int redisplay_menu_p
= 0;
16016 if (FRAME_WINDOW_P (f
))
16018 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16019 || defined (HAVE_NS) || defined (USE_GTK)
16020 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16022 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16026 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16028 if (redisplay_menu_p
)
16029 display_menu_bar (w
);
16031 #ifdef HAVE_WINDOW_SYSTEM
16032 if (FRAME_WINDOW_P (f
))
16034 #if defined (USE_GTK) || defined (HAVE_NS)
16035 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16036 redisplay_tool_bar (f
);
16038 if (WINDOWP (f
->tool_bar_window
)
16039 && (FRAME_TOOL_BAR_LINES (f
) > 0
16040 || !NILP (Vauto_resize_tool_bars
))
16041 && redisplay_tool_bar (f
))
16042 ignore_mouse_drag_p
= 1;
16048 #ifdef HAVE_WINDOW_SYSTEM
16049 if (FRAME_WINDOW_P (f
)
16050 && update_window_fringes (w
, (just_this_one_p
16051 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16052 || w
->pseudo_window_p
)))
16056 if (draw_window_fringes (w
, 1))
16057 x_draw_vertical_border (w
);
16061 #endif /* HAVE_WINDOW_SYSTEM */
16063 /* We go to this label, with fonts_changed_p set,
16064 if it is necessary to try again using larger glyph matrices.
16065 We have to redeem the scroll bar even in this case,
16066 because the loop in redisplay_internal expects that. */
16067 need_larger_matrices
:
16069 finish_scroll_bars
:
16071 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16073 /* Set the thumb's position and size. */
16074 set_vertical_scroll_bar (w
);
16076 /* Note that we actually used the scroll bar attached to this
16077 window, so it shouldn't be deleted at the end of redisplay. */
16078 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16079 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16082 /* Restore current_buffer and value of point in it. The window
16083 update may have changed the buffer, so first make sure `opoint'
16084 is still valid (Bug#6177). */
16085 if (CHARPOS (opoint
) < BEGV
)
16086 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16087 else if (CHARPOS (opoint
) > ZV
)
16088 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16090 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16092 set_buffer_internal_1 (old
);
16093 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16094 shorter. This can be caused by log truncation in *Messages*. */
16095 if (CHARPOS (lpoint
) <= ZV
)
16096 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16098 unbind_to (count
, Qnil
);
16102 /* Build the complete desired matrix of WINDOW with a window start
16103 buffer position POS.
16105 Value is 1 if successful. It is zero if fonts were loaded during
16106 redisplay which makes re-adjusting glyph matrices necessary, and -1
16107 if point would appear in the scroll margins.
16108 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16109 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16113 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16115 struct window
*w
= XWINDOW (window
);
16117 struct glyph_row
*last_text_row
= NULL
;
16118 struct frame
*f
= XFRAME (w
->frame
);
16120 /* Make POS the new window start. */
16121 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16123 /* Mark cursor position as unknown. No overlay arrow seen. */
16124 w
->cursor
.vpos
= -1;
16125 overlay_arrow_seen
= 0;
16127 /* Initialize iterator and info to start at POS. */
16128 start_display (&it
, w
, pos
);
16130 /* Display all lines of W. */
16131 while (it
.current_y
< it
.last_visible_y
)
16133 if (display_line (&it
))
16134 last_text_row
= it
.glyph_row
- 1;
16135 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16139 /* Don't let the cursor end in the scroll margins. */
16140 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16141 && !MINI_WINDOW_P (w
))
16143 int this_scroll_margin
;
16145 if (scroll_margin
> 0)
16147 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16148 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16151 this_scroll_margin
= 0;
16153 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16154 && w
->cursor
.y
< this_scroll_margin
16155 && CHARPOS (pos
) > BEGV
16156 && IT_CHARPOS (it
) < ZV
)
16157 /* rms: considering make_cursor_line_fully_visible_p here
16158 seems to give wrong results. We don't want to recenter
16159 when the last line is partly visible, we want to allow
16160 that case to be handled in the usual way. */
16161 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16163 w
->cursor
.vpos
= -1;
16164 clear_glyph_matrix (w
->desired_matrix
);
16169 /* If bottom moved off end of frame, change mode line percentage. */
16170 if (XFASTINT (w
->window_end_pos
) <= 0
16171 && Z
!= IT_CHARPOS (it
))
16172 w
->update_mode_line
= 1;
16174 /* Set window_end_pos to the offset of the last character displayed
16175 on the window from the end of current_buffer. Set
16176 window_end_vpos to its row number. */
16179 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16180 w
->window_end_bytepos
16181 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16182 wset_window_end_pos
16183 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16184 wset_window_end_vpos
16185 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16187 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16188 XFASTINT (w
->window_end_vpos
))));
16192 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16193 wset_window_end_pos (w
, make_number (Z
- ZV
));
16194 wset_window_end_vpos (w
, make_number (0));
16197 /* But that is not valid info until redisplay finishes. */
16198 w
->window_end_valid
= 0;
16204 /************************************************************************
16205 Window redisplay reusing current matrix when buffer has not changed
16206 ************************************************************************/
16208 /* Try redisplay of window W showing an unchanged buffer with a
16209 different window start than the last time it was displayed by
16210 reusing its current matrix. Value is non-zero if successful.
16211 W->start is the new window start. */
16214 try_window_reusing_current_matrix (struct window
*w
)
16216 struct frame
*f
= XFRAME (w
->frame
);
16217 struct glyph_row
*bottom_row
;
16220 struct text_pos start
, new_start
;
16221 int nrows_scrolled
, i
;
16222 struct glyph_row
*last_text_row
;
16223 struct glyph_row
*last_reused_text_row
;
16224 struct glyph_row
*start_row
;
16225 int start_vpos
, min_y
, max_y
;
16228 if (inhibit_try_window_reusing
)
16232 if (/* This function doesn't handle terminal frames. */
16233 !FRAME_WINDOW_P (f
)
16234 /* Don't try to reuse the display if windows have been split
16236 || windows_or_buffers_changed
16237 || cursor_type_changed
)
16240 /* Can't do this if region may have changed. */
16241 if (markpos_of_region () >= 0
16242 || w
->region_showing
16243 || !NILP (Vshow_trailing_whitespace
))
16246 /* If top-line visibility has changed, give up. */
16247 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16248 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16251 /* Give up if old or new display is scrolled vertically. We could
16252 make this function handle this, but right now it doesn't. */
16253 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16254 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16257 /* The variable new_start now holds the new window start. The old
16258 start `start' can be determined from the current matrix. */
16259 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16260 start
= start_row
->minpos
;
16261 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16263 /* Clear the desired matrix for the display below. */
16264 clear_glyph_matrix (w
->desired_matrix
);
16266 if (CHARPOS (new_start
) <= CHARPOS (start
))
16268 /* Don't use this method if the display starts with an ellipsis
16269 displayed for invisible text. It's not easy to handle that case
16270 below, and it's certainly not worth the effort since this is
16271 not a frequent case. */
16272 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16275 IF_DEBUG (debug_method_add (w
, "twu1"));
16277 /* Display up to a row that can be reused. The variable
16278 last_text_row is set to the last row displayed that displays
16279 text. Note that it.vpos == 0 if or if not there is a
16280 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16281 start_display (&it
, w
, new_start
);
16282 w
->cursor
.vpos
= -1;
16283 last_text_row
= last_reused_text_row
= NULL
;
16285 while (it
.current_y
< it
.last_visible_y
16286 && !fonts_changed_p
)
16288 /* If we have reached into the characters in the START row,
16289 that means the line boundaries have changed. So we
16290 can't start copying with the row START. Maybe it will
16291 work to start copying with the following row. */
16292 while (IT_CHARPOS (it
) > CHARPOS (start
))
16294 /* Advance to the next row as the "start". */
16296 start
= start_row
->minpos
;
16297 /* If there are no more rows to try, or just one, give up. */
16298 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16299 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16300 || CHARPOS (start
) == ZV
)
16302 clear_glyph_matrix (w
->desired_matrix
);
16306 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16308 /* If we have reached alignment, we can copy the rest of the
16310 if (IT_CHARPOS (it
) == CHARPOS (start
)
16311 /* Don't accept "alignment" inside a display vector,
16312 since start_row could have started in the middle of
16313 that same display vector (thus their character
16314 positions match), and we have no way of telling if
16315 that is the case. */
16316 && it
.current
.dpvec_index
< 0)
16319 if (display_line (&it
))
16320 last_text_row
= it
.glyph_row
- 1;
16324 /* A value of current_y < last_visible_y means that we stopped
16325 at the previous window start, which in turn means that we
16326 have at least one reusable row. */
16327 if (it
.current_y
< it
.last_visible_y
)
16329 struct glyph_row
*row
;
16331 /* IT.vpos always starts from 0; it counts text lines. */
16332 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16334 /* Find PT if not already found in the lines displayed. */
16335 if (w
->cursor
.vpos
< 0)
16337 int dy
= it
.current_y
- start_row
->y
;
16339 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16340 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16342 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16343 dy
, nrows_scrolled
);
16346 clear_glyph_matrix (w
->desired_matrix
);
16351 /* Scroll the display. Do it before the current matrix is
16352 changed. The problem here is that update has not yet
16353 run, i.e. part of the current matrix is not up to date.
16354 scroll_run_hook will clear the cursor, and use the
16355 current matrix to get the height of the row the cursor is
16357 run
.current_y
= start_row
->y
;
16358 run
.desired_y
= it
.current_y
;
16359 run
.height
= it
.last_visible_y
- it
.current_y
;
16361 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16364 FRAME_RIF (f
)->update_window_begin_hook (w
);
16365 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16366 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16367 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16371 /* Shift current matrix down by nrows_scrolled lines. */
16372 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16373 rotate_matrix (w
->current_matrix
,
16375 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16378 /* Disable lines that must be updated. */
16379 for (i
= 0; i
< nrows_scrolled
; ++i
)
16380 (start_row
+ i
)->enabled_p
= 0;
16382 /* Re-compute Y positions. */
16383 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16384 max_y
= it
.last_visible_y
;
16385 for (row
= start_row
+ nrows_scrolled
;
16389 row
->y
= it
.current_y
;
16390 row
->visible_height
= row
->height
;
16392 if (row
->y
< min_y
)
16393 row
->visible_height
-= min_y
- row
->y
;
16394 if (row
->y
+ row
->height
> max_y
)
16395 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16396 if (row
->fringe_bitmap_periodic_p
)
16397 row
->redraw_fringe_bitmaps_p
= 1;
16399 it
.current_y
+= row
->height
;
16401 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16402 last_reused_text_row
= row
;
16403 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16407 /* Disable lines in the current matrix which are now
16408 below the window. */
16409 for (++row
; row
< bottom_row
; ++row
)
16410 row
->enabled_p
= row
->mode_line_p
= 0;
16413 /* Update window_end_pos etc.; last_reused_text_row is the last
16414 reused row from the current matrix containing text, if any.
16415 The value of last_text_row is the last displayed line
16416 containing text. */
16417 if (last_reused_text_row
)
16419 w
->window_end_bytepos
16420 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16421 wset_window_end_pos
16423 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16424 wset_window_end_vpos
16425 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16426 w
->current_matrix
)));
16428 else if (last_text_row
)
16430 w
->window_end_bytepos
16431 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16432 wset_window_end_pos
16433 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16434 wset_window_end_vpos
16435 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16436 w
->desired_matrix
)));
16440 /* This window must be completely empty. */
16441 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16442 wset_window_end_pos (w
, make_number (Z
- ZV
));
16443 wset_window_end_vpos (w
, make_number (0));
16445 w
->window_end_valid
= 0;
16447 /* Update hint: don't try scrolling again in update_window. */
16448 w
->desired_matrix
->no_scrolling_p
= 1;
16451 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16455 else if (CHARPOS (new_start
) > CHARPOS (start
))
16457 struct glyph_row
*pt_row
, *row
;
16458 struct glyph_row
*first_reusable_row
;
16459 struct glyph_row
*first_row_to_display
;
16461 int yb
= window_text_bottom_y (w
);
16463 /* Find the row starting at new_start, if there is one. Don't
16464 reuse a partially visible line at the end. */
16465 first_reusable_row
= start_row
;
16466 while (first_reusable_row
->enabled_p
16467 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16468 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16469 < CHARPOS (new_start
)))
16470 ++first_reusable_row
;
16472 /* Give up if there is no row to reuse. */
16473 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16474 || !first_reusable_row
->enabled_p
16475 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16476 != CHARPOS (new_start
)))
16479 /* We can reuse fully visible rows beginning with
16480 first_reusable_row to the end of the window. Set
16481 first_row_to_display to the first row that cannot be reused.
16482 Set pt_row to the row containing point, if there is any. */
16484 for (first_row_to_display
= first_reusable_row
;
16485 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16486 ++first_row_to_display
)
16488 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16489 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16490 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16491 && first_row_to_display
->ends_at_zv_p
16492 && pt_row
== NULL
)))
16493 pt_row
= first_row_to_display
;
16496 /* Start displaying at the start of first_row_to_display. */
16497 eassert (first_row_to_display
->y
< yb
);
16498 init_to_row_start (&it
, w
, first_row_to_display
);
16500 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16502 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16504 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16505 + WINDOW_HEADER_LINE_HEIGHT (w
));
16507 /* Display lines beginning with first_row_to_display in the
16508 desired matrix. Set last_text_row to the last row displayed
16509 that displays text. */
16510 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16511 if (pt_row
== NULL
)
16512 w
->cursor
.vpos
= -1;
16513 last_text_row
= NULL
;
16514 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16515 if (display_line (&it
))
16516 last_text_row
= it
.glyph_row
- 1;
16518 /* If point is in a reused row, adjust y and vpos of the cursor
16522 w
->cursor
.vpos
-= nrows_scrolled
;
16523 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16526 /* Give up if point isn't in a row displayed or reused. (This
16527 also handles the case where w->cursor.vpos < nrows_scrolled
16528 after the calls to display_line, which can happen with scroll
16529 margins. See bug#1295.) */
16530 if (w
->cursor
.vpos
< 0)
16532 clear_glyph_matrix (w
->desired_matrix
);
16536 /* Scroll the display. */
16537 run
.current_y
= first_reusable_row
->y
;
16538 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16539 run
.height
= it
.last_visible_y
- run
.current_y
;
16540 dy
= run
.current_y
- run
.desired_y
;
16545 FRAME_RIF (f
)->update_window_begin_hook (w
);
16546 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16547 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16548 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16552 /* Adjust Y positions of reused rows. */
16553 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16554 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16555 max_y
= it
.last_visible_y
;
16556 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16559 row
->visible_height
= row
->height
;
16560 if (row
->y
< min_y
)
16561 row
->visible_height
-= min_y
- row
->y
;
16562 if (row
->y
+ row
->height
> max_y
)
16563 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16564 if (row
->fringe_bitmap_periodic_p
)
16565 row
->redraw_fringe_bitmaps_p
= 1;
16568 /* Scroll the current matrix. */
16569 eassert (nrows_scrolled
> 0);
16570 rotate_matrix (w
->current_matrix
,
16572 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16575 /* Disable rows not reused. */
16576 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16577 row
->enabled_p
= 0;
16579 /* Point may have moved to a different line, so we cannot assume that
16580 the previous cursor position is valid; locate the correct row. */
16583 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16585 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16586 && !row
->ends_at_zv_p
;
16590 w
->cursor
.y
= row
->y
;
16592 if (row
< bottom_row
)
16594 /* Can't simply scan the row for point with
16595 bidi-reordered glyph rows. Let set_cursor_from_row
16596 figure out where to put the cursor, and if it fails,
16598 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16600 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16603 clear_glyph_matrix (w
->desired_matrix
);
16609 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16610 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16613 && (!BUFFERP (glyph
->object
)
16614 || glyph
->charpos
< PT
);
16618 w
->cursor
.x
+= glyph
->pixel_width
;
16624 /* Adjust window end. A null value of last_text_row means that
16625 the window end is in reused rows which in turn means that
16626 only its vpos can have changed. */
16629 w
->window_end_bytepos
16630 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16631 wset_window_end_pos
16632 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16633 wset_window_end_vpos
16634 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16635 w
->desired_matrix
)));
16639 wset_window_end_vpos
16640 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16643 w
->window_end_valid
= 0;
16644 w
->desired_matrix
->no_scrolling_p
= 1;
16647 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16657 /************************************************************************
16658 Window redisplay reusing current matrix when buffer has changed
16659 ************************************************************************/
16661 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16662 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16663 ptrdiff_t *, ptrdiff_t *);
16664 static struct glyph_row
*
16665 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16666 struct glyph_row
*);
16669 /* Return the last row in MATRIX displaying text. If row START is
16670 non-null, start searching with that row. IT gives the dimensions
16671 of the display. Value is null if matrix is empty; otherwise it is
16672 a pointer to the row found. */
16674 static struct glyph_row
*
16675 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16676 struct glyph_row
*start
)
16678 struct glyph_row
*row
, *row_found
;
16680 /* Set row_found to the last row in IT->w's current matrix
16681 displaying text. The loop looks funny but think of partially
16684 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16685 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16687 eassert (row
->enabled_p
);
16689 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16698 /* Return the last row in the current matrix of W that is not affected
16699 by changes at the start of current_buffer that occurred since W's
16700 current matrix was built. Value is null if no such row exists.
16702 BEG_UNCHANGED us the number of characters unchanged at the start of
16703 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16704 first changed character in current_buffer. Characters at positions <
16705 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16706 when the current matrix was built. */
16708 static struct glyph_row
*
16709 find_last_unchanged_at_beg_row (struct window
*w
)
16711 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16712 struct glyph_row
*row
;
16713 struct glyph_row
*row_found
= NULL
;
16714 int yb
= window_text_bottom_y (w
);
16716 /* Find the last row displaying unchanged text. */
16717 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16718 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16719 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16722 if (/* If row ends before first_changed_pos, it is unchanged,
16723 except in some case. */
16724 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16725 /* When row ends in ZV and we write at ZV it is not
16727 && !row
->ends_at_zv_p
16728 /* When first_changed_pos is the end of a continued line,
16729 row is not unchanged because it may be no longer
16731 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16732 && (row
->continued_p
16733 || row
->exact_window_width_line_p
))
16734 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16735 needs to be recomputed, so don't consider this row as
16736 unchanged. This happens when the last line was
16737 bidi-reordered and was killed immediately before this
16738 redisplay cycle. In that case, ROW->end stores the
16739 buffer position of the first visual-order character of
16740 the killed text, which is now beyond ZV. */
16741 && CHARPOS (row
->end
.pos
) <= ZV
)
16744 /* Stop if last visible row. */
16745 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16753 /* Find the first glyph row in the current matrix of W that is not
16754 affected by changes at the end of current_buffer since the
16755 time W's current matrix was built.
16757 Return in *DELTA the number of chars by which buffer positions in
16758 unchanged text at the end of current_buffer must be adjusted.
16760 Return in *DELTA_BYTES the corresponding number of bytes.
16762 Value is null if no such row exists, i.e. all rows are affected by
16765 static struct glyph_row
*
16766 find_first_unchanged_at_end_row (struct window
*w
,
16767 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16769 struct glyph_row
*row
;
16770 struct glyph_row
*row_found
= NULL
;
16772 *delta
= *delta_bytes
= 0;
16774 /* Display must not have been paused, otherwise the current matrix
16775 is not up to date. */
16776 eassert (w
->window_end_valid
);
16778 /* A value of window_end_pos >= END_UNCHANGED means that the window
16779 end is in the range of changed text. If so, there is no
16780 unchanged row at the end of W's current matrix. */
16781 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16784 /* Set row to the last row in W's current matrix displaying text. */
16785 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16787 /* If matrix is entirely empty, no unchanged row exists. */
16788 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16790 /* The value of row is the last glyph row in the matrix having a
16791 meaningful buffer position in it. The end position of row
16792 corresponds to window_end_pos. This allows us to translate
16793 buffer positions in the current matrix to current buffer
16794 positions for characters not in changed text. */
16796 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16797 ptrdiff_t Z_BYTE_old
=
16798 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16799 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16800 struct glyph_row
*first_text_row
16801 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16803 *delta
= Z
- Z_old
;
16804 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16806 /* Set last_unchanged_pos to the buffer position of the last
16807 character in the buffer that has not been changed. Z is the
16808 index + 1 of the last character in current_buffer, i.e. by
16809 subtracting END_UNCHANGED we get the index of the last
16810 unchanged character, and we have to add BEG to get its buffer
16812 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16813 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16815 /* Search backward from ROW for a row displaying a line that
16816 starts at a minimum position >= last_unchanged_pos_old. */
16817 for (; row
> first_text_row
; --row
)
16819 /* This used to abort, but it can happen.
16820 It is ok to just stop the search instead here. KFS. */
16821 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16824 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16829 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16835 /* Make sure that glyph rows in the current matrix of window W
16836 reference the same glyph memory as corresponding rows in the
16837 frame's frame matrix. This function is called after scrolling W's
16838 current matrix on a terminal frame in try_window_id and
16839 try_window_reusing_current_matrix. */
16842 sync_frame_with_window_matrix_rows (struct window
*w
)
16844 struct frame
*f
= XFRAME (w
->frame
);
16845 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16847 /* Preconditions: W must be a leaf window and full-width. Its frame
16848 must have a frame matrix. */
16849 eassert (BUFFERP (w
->contents
));
16850 eassert (WINDOW_FULL_WIDTH_P (w
));
16851 eassert (!FRAME_WINDOW_P (f
));
16853 /* If W is a full-width window, glyph pointers in W's current matrix
16854 have, by definition, to be the same as glyph pointers in the
16855 corresponding frame matrix. Note that frame matrices have no
16856 marginal areas (see build_frame_matrix). */
16857 window_row
= w
->current_matrix
->rows
;
16858 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16859 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16860 while (window_row
< window_row_end
)
16862 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16863 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16865 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16866 frame_row
->glyphs
[TEXT_AREA
] = start
;
16867 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16868 frame_row
->glyphs
[LAST_AREA
] = end
;
16870 /* Disable frame rows whose corresponding window rows have
16871 been disabled in try_window_id. */
16872 if (!window_row
->enabled_p
)
16873 frame_row
->enabled_p
= 0;
16875 ++window_row
, ++frame_row
;
16880 /* Find the glyph row in window W containing CHARPOS. Consider all
16881 rows between START and END (not inclusive). END null means search
16882 all rows to the end of the display area of W. Value is the row
16883 containing CHARPOS or null. */
16886 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16887 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16889 struct glyph_row
*row
= start
;
16890 struct glyph_row
*best_row
= NULL
;
16891 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
16894 /* If we happen to start on a header-line, skip that. */
16895 if (row
->mode_line_p
)
16898 if ((end
&& row
>= end
) || !row
->enabled_p
)
16901 last_y
= window_text_bottom_y (w
) - dy
;
16905 /* Give up if we have gone too far. */
16906 if (end
&& row
>= end
)
16908 /* This formerly returned if they were equal.
16909 I think that both quantities are of a "last plus one" type;
16910 if so, when they are equal, the row is within the screen. -- rms. */
16911 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16914 /* If it is in this row, return this row. */
16915 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16916 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16917 /* The end position of a row equals the start
16918 position of the next row. If CHARPOS is there, we
16919 would rather consider it displayed in the next
16920 line, except when this line ends in ZV. */
16921 && !row_for_charpos_p (row
, charpos
)))
16922 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16926 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
16927 || (!best_row
&& !row
->continued_p
))
16929 /* In bidi-reordered rows, there could be several rows whose
16930 edges surround CHARPOS, all of these rows belonging to
16931 the same continued line. We need to find the row which
16932 fits CHARPOS the best. */
16933 for (g
= row
->glyphs
[TEXT_AREA
];
16934 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16937 if (!STRINGP (g
->object
))
16939 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16941 mindif
= eabs (g
->charpos
- charpos
);
16943 /* Exact match always wins. */
16950 else if (best_row
&& !row
->continued_p
)
16957 /* Try to redisplay window W by reusing its existing display. W's
16958 current matrix must be up to date when this function is called,
16959 i.e. window_end_valid must be nonzero.
16963 1 if display has been updated
16964 0 if otherwise unsuccessful
16965 -1 if redisplay with same window start is known not to succeed
16967 The following steps are performed:
16969 1. Find the last row in the current matrix of W that is not
16970 affected by changes at the start of current_buffer. If no such row
16973 2. Find the first row in W's current matrix that is not affected by
16974 changes at the end of current_buffer. Maybe there is no such row.
16976 3. Display lines beginning with the row + 1 found in step 1 to the
16977 row found in step 2 or, if step 2 didn't find a row, to the end of
16980 4. If cursor is not known to appear on the window, give up.
16982 5. If display stopped at the row found in step 2, scroll the
16983 display and current matrix as needed.
16985 6. Maybe display some lines at the end of W, if we must. This can
16986 happen under various circumstances, like a partially visible line
16987 becoming fully visible, or because newly displayed lines are displayed
16988 in smaller font sizes.
16990 7. Update W's window end information. */
16993 try_window_id (struct window
*w
)
16995 struct frame
*f
= XFRAME (w
->frame
);
16996 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16997 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16998 struct glyph_row
*last_unchanged_at_beg_row
;
16999 struct glyph_row
*first_unchanged_at_end_row
;
17000 struct glyph_row
*row
;
17001 struct glyph_row
*bottom_row
;
17004 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17006 struct text_pos start_pos
;
17008 int first_unchanged_at_end_vpos
= 0;
17009 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17010 struct text_pos start
;
17011 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17014 if (inhibit_try_window_id
)
17018 /* This is handy for debugging. */
17020 #define GIVE_UP(X) \
17022 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17026 #define GIVE_UP(X) return 0
17029 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17031 /* Don't use this for mini-windows because these can show
17032 messages and mini-buffers, and we don't handle that here. */
17033 if (MINI_WINDOW_P (w
))
17036 /* This flag is used to prevent redisplay optimizations. */
17037 if (windows_or_buffers_changed
|| cursor_type_changed
)
17040 /* Verify that narrowing has not changed.
17041 Also verify that we were not told to prevent redisplay optimizations.
17042 It would be nice to further
17043 reduce the number of cases where this prevents try_window_id. */
17044 if (current_buffer
->clip_changed
17045 || current_buffer
->prevent_redisplay_optimizations_p
)
17048 /* Window must either use window-based redisplay or be full width. */
17049 if (!FRAME_WINDOW_P (f
)
17050 && (!FRAME_LINE_INS_DEL_OK (f
)
17051 || !WINDOW_FULL_WIDTH_P (w
)))
17054 /* Give up if point is known NOT to appear in W. */
17055 if (PT
< CHARPOS (start
))
17058 /* Another way to prevent redisplay optimizations. */
17059 if (w
->last_modified
== 0)
17062 /* Verify that window is not hscrolled. */
17063 if (w
->hscroll
!= 0)
17066 /* Verify that display wasn't paused. */
17067 if (!w
->window_end_valid
)
17070 /* Can't use this if highlighting a region because a cursor movement
17071 will do more than just set the cursor. */
17072 if (markpos_of_region () >= 0)
17075 /* Likewise if highlighting trailing whitespace. */
17076 if (!NILP (Vshow_trailing_whitespace
))
17079 /* Likewise if showing a region. */
17080 if (w
->region_showing
)
17083 /* Can't use this if overlay arrow position and/or string have
17085 if (overlay_arrows_changed_p ())
17088 /* When word-wrap is on, adding a space to the first word of a
17089 wrapped line can change the wrap position, altering the line
17090 above it. It might be worthwhile to handle this more
17091 intelligently, but for now just redisplay from scratch. */
17092 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17095 /* Under bidi reordering, adding or deleting a character in the
17096 beginning of a paragraph, before the first strong directional
17097 character, can change the base direction of the paragraph (unless
17098 the buffer specifies a fixed paragraph direction), which will
17099 require to redisplay the whole paragraph. It might be worthwhile
17100 to find the paragraph limits and widen the range of redisplayed
17101 lines to that, but for now just give up this optimization and
17102 redisplay from scratch. */
17103 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17104 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17107 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17108 only if buffer has really changed. The reason is that the gap is
17109 initially at Z for freshly visited files. The code below would
17110 set end_unchanged to 0 in that case. */
17111 if (MODIFF
> SAVE_MODIFF
17112 /* This seems to happen sometimes after saving a buffer. */
17113 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17115 if (GPT
- BEG
< BEG_UNCHANGED
)
17116 BEG_UNCHANGED
= GPT
- BEG
;
17117 if (Z
- GPT
< END_UNCHANGED
)
17118 END_UNCHANGED
= Z
- GPT
;
17121 /* The position of the first and last character that has been changed. */
17122 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17123 last_changed_charpos
= Z
- END_UNCHANGED
;
17125 /* If window starts after a line end, and the last change is in
17126 front of that newline, then changes don't affect the display.
17127 This case happens with stealth-fontification. Note that although
17128 the display is unchanged, glyph positions in the matrix have to
17129 be adjusted, of course. */
17130 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17131 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17132 && ((last_changed_charpos
< CHARPOS (start
)
17133 && CHARPOS (start
) == BEGV
)
17134 || (last_changed_charpos
< CHARPOS (start
) - 1
17135 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17137 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17138 struct glyph_row
*r0
;
17140 /* Compute how many chars/bytes have been added to or removed
17141 from the buffer. */
17142 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17143 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17144 Z_delta
= Z
- Z_old
;
17145 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17147 /* Give up if PT is not in the window. Note that it already has
17148 been checked at the start of try_window_id that PT is not in
17149 front of the window start. */
17150 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17153 /* If window start is unchanged, we can reuse the whole matrix
17154 as is, after adjusting glyph positions. No need to compute
17155 the window end again, since its offset from Z hasn't changed. */
17156 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17157 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17158 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17159 /* PT must not be in a partially visible line. */
17160 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17161 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17163 /* Adjust positions in the glyph matrix. */
17164 if (Z_delta
|| Z_delta_bytes
)
17166 struct glyph_row
*r1
17167 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17168 increment_matrix_positions (w
->current_matrix
,
17169 MATRIX_ROW_VPOS (r0
, current_matrix
),
17170 MATRIX_ROW_VPOS (r1
, current_matrix
),
17171 Z_delta
, Z_delta_bytes
);
17174 /* Set the cursor. */
17175 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17177 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17184 /* Handle the case that changes are all below what is displayed in
17185 the window, and that PT is in the window. This shortcut cannot
17186 be taken if ZV is visible in the window, and text has been added
17187 there that is visible in the window. */
17188 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17189 /* ZV is not visible in the window, or there are no
17190 changes at ZV, actually. */
17191 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17192 || first_changed_charpos
== last_changed_charpos
))
17194 struct glyph_row
*r0
;
17196 /* Give up if PT is not in the window. Note that it already has
17197 been checked at the start of try_window_id that PT is not in
17198 front of the window start. */
17199 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17202 /* If window start is unchanged, we can reuse the whole matrix
17203 as is, without changing glyph positions since no text has
17204 been added/removed in front of the window end. */
17205 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17206 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17207 /* PT must not be in a partially visible line. */
17208 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17209 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17211 /* We have to compute the window end anew since text
17212 could have been added/removed after it. */
17213 wset_window_end_pos
17214 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17215 w
->window_end_bytepos
17216 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17218 /* Set the cursor. */
17219 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17221 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17228 /* Give up if window start is in the changed area.
17230 The condition used to read
17232 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17234 but why that was tested escapes me at the moment. */
17235 if (CHARPOS (start
) >= first_changed_charpos
17236 && CHARPOS (start
) <= last_changed_charpos
)
17239 /* Check that window start agrees with the start of the first glyph
17240 row in its current matrix. Check this after we know the window
17241 start is not in changed text, otherwise positions would not be
17243 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17244 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17247 /* Give up if the window ends in strings. Overlay strings
17248 at the end are difficult to handle, so don't try. */
17249 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17250 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17253 /* Compute the position at which we have to start displaying new
17254 lines. Some of the lines at the top of the window might be
17255 reusable because they are not displaying changed text. Find the
17256 last row in W's current matrix not affected by changes at the
17257 start of current_buffer. Value is null if changes start in the
17258 first line of window. */
17259 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17260 if (last_unchanged_at_beg_row
)
17262 /* Avoid starting to display in the middle of a character, a TAB
17263 for instance. This is easier than to set up the iterator
17264 exactly, and it's not a frequent case, so the additional
17265 effort wouldn't really pay off. */
17266 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17267 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17268 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17269 --last_unchanged_at_beg_row
;
17271 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17274 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17276 start_pos
= it
.current
.pos
;
17278 /* Start displaying new lines in the desired matrix at the same
17279 vpos we would use in the current matrix, i.e. below
17280 last_unchanged_at_beg_row. */
17281 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17283 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17284 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17286 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17290 /* There are no reusable lines at the start of the window.
17291 Start displaying in the first text line. */
17292 start_display (&it
, w
, start
);
17293 it
.vpos
= it
.first_vpos
;
17294 start_pos
= it
.current
.pos
;
17297 /* Find the first row that is not affected by changes at the end of
17298 the buffer. Value will be null if there is no unchanged row, in
17299 which case we must redisplay to the end of the window. delta
17300 will be set to the value by which buffer positions beginning with
17301 first_unchanged_at_end_row have to be adjusted due to text
17303 first_unchanged_at_end_row
17304 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17305 IF_DEBUG (debug_delta
= delta
);
17306 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17308 /* Set stop_pos to the buffer position up to which we will have to
17309 display new lines. If first_unchanged_at_end_row != NULL, this
17310 is the buffer position of the start of the line displayed in that
17311 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17312 that we don't stop at a buffer position. */
17314 if (first_unchanged_at_end_row
)
17316 eassert (last_unchanged_at_beg_row
== NULL
17317 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17319 /* If this is a continuation line, move forward to the next one
17320 that isn't. Changes in lines above affect this line.
17321 Caution: this may move first_unchanged_at_end_row to a row
17322 not displaying text. */
17323 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17324 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17325 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17326 < it
.last_visible_y
))
17327 ++first_unchanged_at_end_row
;
17329 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17330 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17331 >= it
.last_visible_y
))
17332 first_unchanged_at_end_row
= NULL
;
17335 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17337 first_unchanged_at_end_vpos
17338 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17339 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17342 else if (last_unchanged_at_beg_row
== NULL
)
17348 /* Either there is no unchanged row at the end, or the one we have
17349 now displays text. This is a necessary condition for the window
17350 end pos calculation at the end of this function. */
17351 eassert (first_unchanged_at_end_row
== NULL
17352 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17354 debug_last_unchanged_at_beg_vpos
17355 = (last_unchanged_at_beg_row
17356 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17358 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17360 #endif /* GLYPH_DEBUG */
17363 /* Display new lines. Set last_text_row to the last new line
17364 displayed which has text on it, i.e. might end up as being the
17365 line where the window_end_vpos is. */
17366 w
->cursor
.vpos
= -1;
17367 last_text_row
= NULL
;
17368 overlay_arrow_seen
= 0;
17369 while (it
.current_y
< it
.last_visible_y
17370 && !fonts_changed_p
17371 && (first_unchanged_at_end_row
== NULL
17372 || IT_CHARPOS (it
) < stop_pos
))
17374 if (display_line (&it
))
17375 last_text_row
= it
.glyph_row
- 1;
17378 if (fonts_changed_p
)
17382 /* Compute differences in buffer positions, y-positions etc. for
17383 lines reused at the bottom of the window. Compute what we can
17385 if (first_unchanged_at_end_row
17386 /* No lines reused because we displayed everything up to the
17387 bottom of the window. */
17388 && it
.current_y
< it
.last_visible_y
)
17391 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17393 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17394 run
.current_y
= first_unchanged_at_end_row
->y
;
17395 run
.desired_y
= run
.current_y
+ dy
;
17396 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17400 delta
= delta_bytes
= dvpos
= dy
17401 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17402 first_unchanged_at_end_row
= NULL
;
17404 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17407 /* Find the cursor if not already found. We have to decide whether
17408 PT will appear on this window (it sometimes doesn't, but this is
17409 not a very frequent case.) This decision has to be made before
17410 the current matrix is altered. A value of cursor.vpos < 0 means
17411 that PT is either in one of the lines beginning at
17412 first_unchanged_at_end_row or below the window. Don't care for
17413 lines that might be displayed later at the window end; as
17414 mentioned, this is not a frequent case. */
17415 if (w
->cursor
.vpos
< 0)
17417 /* Cursor in unchanged rows at the top? */
17418 if (PT
< CHARPOS (start_pos
)
17419 && last_unchanged_at_beg_row
)
17421 row
= row_containing_pos (w
, PT
,
17422 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17423 last_unchanged_at_beg_row
+ 1, 0);
17425 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17428 /* Start from first_unchanged_at_end_row looking for PT. */
17429 else if (first_unchanged_at_end_row
)
17431 row
= row_containing_pos (w
, PT
- delta
,
17432 first_unchanged_at_end_row
, NULL
, 0);
17434 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17435 delta_bytes
, dy
, dvpos
);
17438 /* Give up if cursor was not found. */
17439 if (w
->cursor
.vpos
< 0)
17441 clear_glyph_matrix (w
->desired_matrix
);
17446 /* Don't let the cursor end in the scroll margins. */
17448 int this_scroll_margin
, cursor_height
;
17450 this_scroll_margin
=
17451 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17452 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17453 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17455 if ((w
->cursor
.y
< this_scroll_margin
17456 && CHARPOS (start
) > BEGV
)
17457 /* Old redisplay didn't take scroll margin into account at the bottom,
17458 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17459 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17460 ? cursor_height
+ this_scroll_margin
17461 : 1)) > it
.last_visible_y
)
17463 w
->cursor
.vpos
= -1;
17464 clear_glyph_matrix (w
->desired_matrix
);
17469 /* Scroll the display. Do it before changing the current matrix so
17470 that xterm.c doesn't get confused about where the cursor glyph is
17472 if (dy
&& run
.height
)
17476 if (FRAME_WINDOW_P (f
))
17478 FRAME_RIF (f
)->update_window_begin_hook (w
);
17479 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17480 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17481 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17485 /* Terminal frame. In this case, dvpos gives the number of
17486 lines to scroll by; dvpos < 0 means scroll up. */
17488 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17489 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17490 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17491 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17492 + window_internal_height (w
));
17494 #if defined (HAVE_GPM) || defined (MSDOS)
17495 x_clear_window_mouse_face (w
);
17497 /* Perform the operation on the screen. */
17500 /* Scroll last_unchanged_at_beg_row to the end of the
17501 window down dvpos lines. */
17502 set_terminal_window (f
, end
);
17504 /* On dumb terminals delete dvpos lines at the end
17505 before inserting dvpos empty lines. */
17506 if (!FRAME_SCROLL_REGION_OK (f
))
17507 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17509 /* Insert dvpos empty lines in front of
17510 last_unchanged_at_beg_row. */
17511 ins_del_lines (f
, from
, dvpos
);
17513 else if (dvpos
< 0)
17515 /* Scroll up last_unchanged_at_beg_vpos to the end of
17516 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17517 set_terminal_window (f
, end
);
17519 /* Delete dvpos lines in front of
17520 last_unchanged_at_beg_vpos. ins_del_lines will set
17521 the cursor to the given vpos and emit |dvpos| delete
17523 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17525 /* On a dumb terminal insert dvpos empty lines at the
17527 if (!FRAME_SCROLL_REGION_OK (f
))
17528 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17531 set_terminal_window (f
, 0);
17537 /* Shift reused rows of the current matrix to the right position.
17538 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17540 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17541 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17544 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17545 bottom_vpos
, dvpos
);
17546 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17549 else if (dvpos
> 0)
17551 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17552 bottom_vpos
, dvpos
);
17553 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17554 first_unchanged_at_end_vpos
+ dvpos
);
17557 /* For frame-based redisplay, make sure that current frame and window
17558 matrix are in sync with respect to glyph memory. */
17559 if (!FRAME_WINDOW_P (f
))
17560 sync_frame_with_window_matrix_rows (w
);
17562 /* Adjust buffer positions in reused rows. */
17563 if (delta
|| delta_bytes
)
17564 increment_matrix_positions (current_matrix
,
17565 first_unchanged_at_end_vpos
+ dvpos
,
17566 bottom_vpos
, delta
, delta_bytes
);
17568 /* Adjust Y positions. */
17570 shift_glyph_matrix (w
, current_matrix
,
17571 first_unchanged_at_end_vpos
+ dvpos
,
17574 if (first_unchanged_at_end_row
)
17576 first_unchanged_at_end_row
+= dvpos
;
17577 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17578 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17579 first_unchanged_at_end_row
= NULL
;
17582 /* If scrolling up, there may be some lines to display at the end of
17584 last_text_row_at_end
= NULL
;
17587 /* Scrolling up can leave for example a partially visible line
17588 at the end of the window to be redisplayed. */
17589 /* Set last_row to the glyph row in the current matrix where the
17590 window end line is found. It has been moved up or down in
17591 the matrix by dvpos. */
17592 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17593 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17595 /* If last_row is the window end line, it should display text. */
17596 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17598 /* If window end line was partially visible before, begin
17599 displaying at that line. Otherwise begin displaying with the
17600 line following it. */
17601 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17603 init_to_row_start (&it
, w
, last_row
);
17604 it
.vpos
= last_vpos
;
17605 it
.current_y
= last_row
->y
;
17609 init_to_row_end (&it
, w
, last_row
);
17610 it
.vpos
= 1 + last_vpos
;
17611 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17615 /* We may start in a continuation line. If so, we have to
17616 get the right continuation_lines_width and current_x. */
17617 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17618 it
.hpos
= it
.current_x
= 0;
17620 /* Display the rest of the lines at the window end. */
17621 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17622 while (it
.current_y
< it
.last_visible_y
17623 && !fonts_changed_p
)
17625 /* Is it always sure that the display agrees with lines in
17626 the current matrix? I don't think so, so we mark rows
17627 displayed invalid in the current matrix by setting their
17628 enabled_p flag to zero. */
17629 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17630 if (display_line (&it
))
17631 last_text_row_at_end
= it
.glyph_row
- 1;
17635 /* Update window_end_pos and window_end_vpos. */
17636 if (first_unchanged_at_end_row
17637 && !last_text_row_at_end
)
17639 /* Window end line if one of the preserved rows from the current
17640 matrix. Set row to the last row displaying text in current
17641 matrix starting at first_unchanged_at_end_row, after
17643 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17644 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17645 first_unchanged_at_end_row
);
17646 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17648 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17649 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17650 wset_window_end_vpos
17651 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17652 eassert (w
->window_end_bytepos
>= 0);
17653 IF_DEBUG (debug_method_add (w
, "A"));
17655 else if (last_text_row_at_end
)
17657 wset_window_end_pos
17658 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17659 w
->window_end_bytepos
17660 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17661 wset_window_end_vpos
17662 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17664 eassert (w
->window_end_bytepos
>= 0);
17665 IF_DEBUG (debug_method_add (w
, "B"));
17667 else if (last_text_row
)
17669 /* We have displayed either to the end of the window or at the
17670 end of the window, i.e. the last row with text is to be found
17671 in the desired matrix. */
17672 wset_window_end_pos
17673 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17674 w
->window_end_bytepos
17675 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17676 wset_window_end_vpos
17677 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17678 eassert (w
->window_end_bytepos
>= 0);
17680 else if (first_unchanged_at_end_row
== NULL
17681 && last_text_row
== NULL
17682 && last_text_row_at_end
== NULL
)
17684 /* Displayed to end of window, but no line containing text was
17685 displayed. Lines were deleted at the end of the window. */
17686 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17687 int vpos
= XFASTINT (w
->window_end_vpos
);
17688 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17689 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17692 row
== NULL
&& vpos
>= first_vpos
;
17693 --vpos
, --current_row
, --desired_row
)
17695 if (desired_row
->enabled_p
)
17697 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17700 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17704 eassert (row
!= NULL
);
17705 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17706 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17707 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17708 eassert (w
->window_end_bytepos
>= 0);
17709 IF_DEBUG (debug_method_add (w
, "C"));
17714 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17715 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17717 /* Record that display has not been completed. */
17718 w
->window_end_valid
= 0;
17719 w
->desired_matrix
->no_scrolling_p
= 1;
17727 /***********************************************************************
17728 More debugging support
17729 ***********************************************************************/
17733 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17734 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17735 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17738 /* Dump the contents of glyph matrix MATRIX on stderr.
17740 GLYPHS 0 means don't show glyph contents.
17741 GLYPHS 1 means show glyphs in short form
17742 GLYPHS > 1 means show glyphs in long form. */
17745 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17748 for (i
= 0; i
< matrix
->nrows
; ++i
)
17749 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17753 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17754 the glyph row and area where the glyph comes from. */
17757 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17759 if (glyph
->type
== CHAR_GLYPH
17760 || glyph
->type
== GLYPHLESS_GLYPH
)
17763 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17764 glyph
- row
->glyphs
[TEXT_AREA
],
17765 (glyph
->type
== CHAR_GLYPH
17769 (BUFFERP (glyph
->object
)
17771 : (STRINGP (glyph
->object
)
17773 : (INTEGERP (glyph
->object
)
17776 glyph
->pixel_width
,
17778 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17782 glyph
->left_box_line_p
,
17783 glyph
->right_box_line_p
);
17785 else if (glyph
->type
== STRETCH_GLYPH
)
17788 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17789 glyph
- row
->glyphs
[TEXT_AREA
],
17792 (BUFFERP (glyph
->object
)
17794 : (STRINGP (glyph
->object
)
17796 : (INTEGERP (glyph
->object
)
17799 glyph
->pixel_width
,
17803 glyph
->left_box_line_p
,
17804 glyph
->right_box_line_p
);
17806 else if (glyph
->type
== IMAGE_GLYPH
)
17809 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17810 glyph
- row
->glyphs
[TEXT_AREA
],
17813 (BUFFERP (glyph
->object
)
17815 : (STRINGP (glyph
->object
)
17817 : (INTEGERP (glyph
->object
)
17820 glyph
->pixel_width
,
17824 glyph
->left_box_line_p
,
17825 glyph
->right_box_line_p
);
17827 else if (glyph
->type
== COMPOSITE_GLYPH
)
17830 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17831 glyph
- row
->glyphs
[TEXT_AREA
],
17834 (BUFFERP (glyph
->object
)
17836 : (STRINGP (glyph
->object
)
17838 : (INTEGERP (glyph
->object
)
17841 glyph
->pixel_width
,
17843 if (glyph
->u
.cmp
.automatic
)
17846 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17847 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17849 glyph
->left_box_line_p
,
17850 glyph
->right_box_line_p
);
17855 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17856 GLYPHS 0 means don't show glyph contents.
17857 GLYPHS 1 means show glyphs in short form
17858 GLYPHS > 1 means show glyphs in long form. */
17861 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17865 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17866 fprintf (stderr
, "==============================================================================\n");
17868 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17869 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17871 MATRIX_ROW_START_CHARPOS (row
),
17872 MATRIX_ROW_END_CHARPOS (row
),
17873 row
->used
[TEXT_AREA
],
17874 row
->contains_overlapping_glyphs_p
,
17876 row
->truncated_on_left_p
,
17877 row
->truncated_on_right_p
,
17879 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17880 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
17883 row
->ends_in_middle_of_char_p
,
17884 row
->starts_in_middle_of_char_p
,
17890 row
->visible_height
,
17893 /* The next 3 lines should align to "Start" in the header. */
17894 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17895 row
->end
.overlay_string_index
,
17896 row
->continuation_lines_width
);
17897 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17898 CHARPOS (row
->start
.string_pos
),
17899 CHARPOS (row
->end
.string_pos
));
17900 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17901 row
->end
.dpvec_index
);
17908 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17910 struct glyph
*glyph
= row
->glyphs
[area
];
17911 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17913 /* Glyph for a line end in text. */
17914 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17917 if (glyph
< glyph_end
)
17918 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
17920 for (; glyph
< glyph_end
; ++glyph
)
17921 dump_glyph (row
, glyph
, area
);
17924 else if (glyphs
== 1)
17928 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17930 char *s
= alloca (row
->used
[area
] + 4);
17933 for (i
= 0; i
< row
->used
[area
]; ++i
)
17935 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17936 if (i
== row
->used
[area
] - 1
17937 && area
== TEXT_AREA
17938 && INTEGERP (glyph
->object
)
17939 && glyph
->type
== CHAR_GLYPH
17940 && glyph
->u
.ch
== ' ')
17942 strcpy (&s
[i
], "[\\n]");
17945 else if (glyph
->type
== CHAR_GLYPH
17946 && glyph
->u
.ch
< 0x80
17947 && glyph
->u
.ch
>= ' ')
17948 s
[i
] = glyph
->u
.ch
;
17954 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17960 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17961 Sdump_glyph_matrix
, 0, 1, "p",
17962 doc
: /* Dump the current matrix of the selected window to stderr.
17963 Shows contents of glyph row structures. With non-nil
17964 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17965 glyphs in short form, otherwise show glyphs in long form. */)
17966 (Lisp_Object glyphs
)
17968 struct window
*w
= XWINDOW (selected_window
);
17969 struct buffer
*buffer
= XBUFFER (w
->contents
);
17971 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17972 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17973 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17974 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17975 fprintf (stderr
, "=============================================\n");
17976 dump_glyph_matrix (w
->current_matrix
,
17977 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17982 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17983 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17986 struct frame
*f
= XFRAME (selected_frame
);
17987 dump_glyph_matrix (f
->current_matrix
, 1);
17992 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17993 doc
: /* Dump glyph row ROW to stderr.
17994 GLYPH 0 means don't dump glyphs.
17995 GLYPH 1 means dump glyphs in short form.
17996 GLYPH > 1 or omitted means dump glyphs in long form. */)
17997 (Lisp_Object row
, Lisp_Object glyphs
)
17999 struct glyph_matrix
*matrix
;
18002 CHECK_NUMBER (row
);
18003 matrix
= XWINDOW (selected_window
)->current_matrix
;
18005 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18006 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18008 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18013 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18014 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18015 GLYPH 0 means don't dump glyphs.
18016 GLYPH 1 means dump glyphs in short form.
18017 GLYPH > 1 or omitted means dump glyphs in long form. */)
18018 (Lisp_Object row
, Lisp_Object glyphs
)
18020 struct frame
*sf
= SELECTED_FRAME ();
18021 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18024 CHECK_NUMBER (row
);
18026 if (vpos
>= 0 && vpos
< m
->nrows
)
18027 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18028 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18033 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18034 doc
: /* Toggle tracing of redisplay.
18035 With ARG, turn tracing on if and only if ARG is positive. */)
18039 trace_redisplay_p
= !trace_redisplay_p
;
18042 arg
= Fprefix_numeric_value (arg
);
18043 trace_redisplay_p
= XINT (arg
) > 0;
18050 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18051 doc
: /* Like `format', but print result to stderr.
18052 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18053 (ptrdiff_t nargs
, Lisp_Object
*args
)
18055 Lisp_Object s
= Fformat (nargs
, args
);
18056 fprintf (stderr
, "%s", SDATA (s
));
18060 #endif /* GLYPH_DEBUG */
18064 /***********************************************************************
18065 Building Desired Matrix Rows
18066 ***********************************************************************/
18068 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18069 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18071 static struct glyph_row
*
18072 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18074 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18075 struct buffer
*buffer
= XBUFFER (w
->contents
);
18076 struct buffer
*old
= current_buffer
;
18077 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18078 int arrow_len
= SCHARS (overlay_arrow_string
);
18079 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18080 const unsigned char *p
;
18083 int n_glyphs_before
;
18085 set_buffer_temp (buffer
);
18086 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18087 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18088 SET_TEXT_POS (it
.position
, 0, 0);
18090 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18092 while (p
< arrow_end
)
18094 Lisp_Object face
, ilisp
;
18096 /* Get the next character. */
18098 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18101 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18102 if (! ASCII_CHAR_P (it
.c
))
18103 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18107 /* Get its face. */
18108 ilisp
= make_number (p
- arrow_string
);
18109 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18110 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18112 /* Compute its width, get its glyphs. */
18113 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18114 SET_TEXT_POS (it
.position
, -1, -1);
18115 PRODUCE_GLYPHS (&it
);
18117 /* If this character doesn't fit any more in the line, we have
18118 to remove some glyphs. */
18119 if (it
.current_x
> it
.last_visible_x
)
18121 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18126 set_buffer_temp (old
);
18127 return it
.glyph_row
;
18131 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18132 glyphs to insert is determined by produce_special_glyphs. */
18135 insert_left_trunc_glyphs (struct it
*it
)
18137 struct it truncate_it
;
18138 struct glyph
*from
, *end
, *to
, *toend
;
18140 eassert (!FRAME_WINDOW_P (it
->f
)
18141 || (!it
->glyph_row
->reversed_p
18142 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18143 || (it
->glyph_row
->reversed_p
18144 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18146 /* Get the truncation glyphs. */
18148 truncate_it
.current_x
= 0;
18149 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18150 truncate_it
.glyph_row
= &scratch_glyph_row
;
18151 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18152 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18153 truncate_it
.object
= make_number (0);
18154 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18156 /* Overwrite glyphs from IT with truncation glyphs. */
18157 if (!it
->glyph_row
->reversed_p
)
18159 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18161 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18162 end
= from
+ tused
;
18163 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18164 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18165 if (FRAME_WINDOW_P (it
->f
))
18167 /* On GUI frames, when variable-size fonts are displayed,
18168 the truncation glyphs may need more pixels than the row's
18169 glyphs they overwrite. We overwrite more glyphs to free
18170 enough screen real estate, and enlarge the stretch glyph
18171 on the right (see display_line), if there is one, to
18172 preserve the screen position of the truncation glyphs on
18175 struct glyph
*g
= to
;
18178 /* The first glyph could be partially visible, in which case
18179 it->glyph_row->x will be negative. But we want the left
18180 truncation glyphs to be aligned at the left margin of the
18181 window, so we override the x coordinate at which the row
18183 it
->glyph_row
->x
= 0;
18184 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18186 w
+= g
->pixel_width
;
18189 if (g
- to
- tused
> 0)
18191 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18192 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18194 used
= it
->glyph_row
->used
[TEXT_AREA
];
18195 if (it
->glyph_row
->truncated_on_right_p
18196 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18197 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18200 int extra
= w
- it
->truncation_pixel_width
;
18202 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18209 /* There may be padding glyphs left over. Overwrite them too. */
18210 if (!FRAME_WINDOW_P (it
->f
))
18212 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18214 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18221 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18225 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18227 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18228 that back to front. */
18229 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18230 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18231 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18232 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18233 if (FRAME_WINDOW_P (it
->f
))
18236 struct glyph
*g
= to
;
18238 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18240 w
+= g
->pixel_width
;
18243 if (to
- g
- tused
> 0)
18245 if (it
->glyph_row
->truncated_on_right_p
18246 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18247 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18249 int extra
= w
- it
->truncation_pixel_width
;
18251 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18255 while (from
>= end
&& to
>= toend
)
18257 if (!FRAME_WINDOW_P (it
->f
))
18259 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18262 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18263 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18264 while (from
>= end
&& to
>= toend
)
18270 /* Need to free some room before prepending additional
18272 int move_by
= from
- end
+ 1;
18273 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18274 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18276 for ( ; g
>= g0
; g
--)
18278 while (from
>= end
)
18280 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18285 /* Compute the hash code for ROW. */
18287 row_hash (struct glyph_row
*row
)
18290 unsigned hashval
= 0;
18292 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18293 for (k
= 0; k
< row
->used
[area
]; ++k
)
18294 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18295 + row
->glyphs
[area
][k
].u
.val
18296 + row
->glyphs
[area
][k
].face_id
18297 + row
->glyphs
[area
][k
].padding_p
18298 + (row
->glyphs
[area
][k
].type
<< 2));
18303 /* Compute the pixel height and width of IT->glyph_row.
18305 Most of the time, ascent and height of a display line will be equal
18306 to the max_ascent and max_height values of the display iterator
18307 structure. This is not the case if
18309 1. We hit ZV without displaying anything. In this case, max_ascent
18310 and max_height will be zero.
18312 2. We have some glyphs that don't contribute to the line height.
18313 (The glyph row flag contributes_to_line_height_p is for future
18314 pixmap extensions).
18316 The first case is easily covered by using default values because in
18317 these cases, the line height does not really matter, except that it
18318 must not be zero. */
18321 compute_line_metrics (struct it
*it
)
18323 struct glyph_row
*row
= it
->glyph_row
;
18325 if (FRAME_WINDOW_P (it
->f
))
18327 int i
, min_y
, max_y
;
18329 /* The line may consist of one space only, that was added to
18330 place the cursor on it. If so, the row's height hasn't been
18332 if (row
->height
== 0)
18334 if (it
->max_ascent
+ it
->max_descent
== 0)
18335 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18336 row
->ascent
= it
->max_ascent
;
18337 row
->height
= it
->max_ascent
+ it
->max_descent
;
18338 row
->phys_ascent
= it
->max_phys_ascent
;
18339 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18340 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18343 /* Compute the width of this line. */
18344 row
->pixel_width
= row
->x
;
18345 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18346 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18348 eassert (row
->pixel_width
>= 0);
18349 eassert (row
->ascent
>= 0 && row
->height
> 0);
18351 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18352 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18354 /* If first line's physical ascent is larger than its logical
18355 ascent, use the physical ascent, and make the row taller.
18356 This makes accented characters fully visible. */
18357 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18358 && row
->phys_ascent
> row
->ascent
)
18360 row
->height
+= row
->phys_ascent
- row
->ascent
;
18361 row
->ascent
= row
->phys_ascent
;
18364 /* Compute how much of the line is visible. */
18365 row
->visible_height
= row
->height
;
18367 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18368 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18370 if (row
->y
< min_y
)
18371 row
->visible_height
-= min_y
- row
->y
;
18372 if (row
->y
+ row
->height
> max_y
)
18373 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18377 row
->pixel_width
= row
->used
[TEXT_AREA
];
18378 if (row
->continued_p
)
18379 row
->pixel_width
-= it
->continuation_pixel_width
;
18380 else if (row
->truncated_on_right_p
)
18381 row
->pixel_width
-= it
->truncation_pixel_width
;
18382 row
->ascent
= row
->phys_ascent
= 0;
18383 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18384 row
->extra_line_spacing
= 0;
18387 /* Compute a hash code for this row. */
18388 row
->hash
= row_hash (row
);
18390 it
->max_ascent
= it
->max_descent
= 0;
18391 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18395 /* Append one space to the glyph row of iterator IT if doing a
18396 window-based redisplay. The space has the same face as
18397 IT->face_id. Value is non-zero if a space was added.
18399 This function is called to make sure that there is always one glyph
18400 at the end of a glyph row that the cursor can be set on under
18401 window-systems. (If there weren't such a glyph we would not know
18402 how wide and tall a box cursor should be displayed).
18404 At the same time this space let's a nicely handle clearing to the
18405 end of the line if the row ends in italic text. */
18408 append_space_for_newline (struct it
*it
, int default_face_p
)
18410 if (FRAME_WINDOW_P (it
->f
))
18412 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18414 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18415 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18417 /* Save some values that must not be changed.
18418 Must save IT->c and IT->len because otherwise
18419 ITERATOR_AT_END_P wouldn't work anymore after
18420 append_space_for_newline has been called. */
18421 enum display_element_type saved_what
= it
->what
;
18422 int saved_c
= it
->c
, saved_len
= it
->len
;
18423 int saved_char_to_display
= it
->char_to_display
;
18424 int saved_x
= it
->current_x
;
18425 int saved_face_id
= it
->face_id
;
18426 int saved_box_end
= it
->end_of_box_run_p
;
18427 struct text_pos saved_pos
;
18428 Lisp_Object saved_object
;
18431 saved_object
= it
->object
;
18432 saved_pos
= it
->position
;
18434 it
->what
= IT_CHARACTER
;
18435 memset (&it
->position
, 0, sizeof it
->position
);
18436 it
->object
= make_number (0);
18437 it
->c
= it
->char_to_display
= ' ';
18440 /* If the default face was remapped, be sure to use the
18441 remapped face for the appended newline. */
18442 if (default_face_p
)
18443 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18444 else if (it
->face_before_selective_p
)
18445 it
->face_id
= it
->saved_face_id
;
18446 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18447 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18448 /* In R2L rows, we will prepend a stretch glyph that will
18449 have the end_of_box_run_p flag set for it, so there's no
18450 need for the appended newline glyph to have that flag
18452 if (it
->glyph_row
->reversed_p
18453 /* But if the appended newline glyph goes all the way to
18454 the end of the row, there will be no stretch glyph,
18455 so leave the box flag set. */
18456 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18457 it
->end_of_box_run_p
= 0;
18459 PRODUCE_GLYPHS (it
);
18461 it
->override_ascent
= -1;
18462 it
->constrain_row_ascent_descent_p
= 0;
18463 it
->current_x
= saved_x
;
18464 it
->object
= saved_object
;
18465 it
->position
= saved_pos
;
18466 it
->what
= saved_what
;
18467 it
->face_id
= saved_face_id
;
18468 it
->len
= saved_len
;
18470 it
->char_to_display
= saved_char_to_display
;
18471 it
->end_of_box_run_p
= saved_box_end
;
18480 /* Extend the face of the last glyph in the text area of IT->glyph_row
18481 to the end of the display line. Called from display_line. If the
18482 glyph row is empty, add a space glyph to it so that we know the
18483 face to draw. Set the glyph row flag fill_line_p. If the glyph
18484 row is R2L, prepend a stretch glyph to cover the empty space to the
18485 left of the leftmost glyph. */
18488 extend_face_to_end_of_line (struct it
*it
)
18490 struct face
*face
, *default_face
;
18491 struct frame
*f
= it
->f
;
18493 /* If line is already filled, do nothing. Non window-system frames
18494 get a grace of one more ``pixel'' because their characters are
18495 1-``pixel'' wide, so they hit the equality too early. This grace
18496 is needed only for R2L rows that are not continued, to produce
18497 one extra blank where we could display the cursor. */
18498 if (it
->current_x
>= it
->last_visible_x
18499 + (!FRAME_WINDOW_P (f
)
18500 && it
->glyph_row
->reversed_p
18501 && !it
->glyph_row
->continued_p
))
18504 /* The default face, possibly remapped. */
18505 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18507 /* Face extension extends the background and box of IT->face_id
18508 to the end of the line. If the background equals the background
18509 of the frame, we don't have to do anything. */
18510 if (it
->face_before_selective_p
)
18511 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18513 face
= FACE_FROM_ID (f
, it
->face_id
);
18515 if (FRAME_WINDOW_P (f
)
18516 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18517 && face
->box
== FACE_NO_BOX
18518 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18520 && !it
->glyph_row
->reversed_p
)
18523 /* Set the glyph row flag indicating that the face of the last glyph
18524 in the text area has to be drawn to the end of the text area. */
18525 it
->glyph_row
->fill_line_p
= 1;
18527 /* If current character of IT is not ASCII, make sure we have the
18528 ASCII face. This will be automatically undone the next time
18529 get_next_display_element returns a multibyte character. Note
18530 that the character will always be single byte in unibyte
18532 if (!ASCII_CHAR_P (it
->c
))
18534 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18537 if (FRAME_WINDOW_P (f
))
18539 /* If the row is empty, add a space with the current face of IT,
18540 so that we know which face to draw. */
18541 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18543 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18544 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18545 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18547 #ifdef HAVE_WINDOW_SYSTEM
18548 if (it
->glyph_row
->reversed_p
)
18550 /* Prepend a stretch glyph to the row, such that the
18551 rightmost glyph will be drawn flushed all the way to the
18552 right margin of the window. The stretch glyph that will
18553 occupy the empty space, if any, to the left of the
18555 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18556 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18557 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18559 int row_width
, stretch_ascent
, stretch_width
;
18560 struct text_pos saved_pos
;
18561 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18563 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18564 row_width
+= g
->pixel_width
;
18565 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18566 if (stretch_width
> 0)
18569 (((it
->ascent
+ it
->descent
)
18570 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18571 saved_pos
= it
->position
;
18572 memset (&it
->position
, 0, sizeof it
->position
);
18573 saved_avoid_cursor
= it
->avoid_cursor_p
;
18574 it
->avoid_cursor_p
= 1;
18575 saved_face_id
= it
->face_id
;
18576 saved_box_start
= it
->start_of_box_run_p
;
18577 /* The last row's stretch glyph should get the default
18578 face, to avoid painting the rest of the window with
18579 the region face, if the region ends at ZV. */
18580 if (it
->glyph_row
->ends_at_zv_p
)
18581 it
->face_id
= default_face
->id
;
18583 it
->face_id
= face
->id
;
18584 it
->start_of_box_run_p
= 0;
18585 append_stretch_glyph (it
, make_number (0), stretch_width
,
18586 it
->ascent
+ it
->descent
, stretch_ascent
);
18587 it
->position
= saved_pos
;
18588 it
->avoid_cursor_p
= saved_avoid_cursor
;
18589 it
->face_id
= saved_face_id
;
18590 it
->start_of_box_run_p
= saved_box_start
;
18593 #endif /* HAVE_WINDOW_SYSTEM */
18597 /* Save some values that must not be changed. */
18598 int saved_x
= it
->current_x
;
18599 struct text_pos saved_pos
;
18600 Lisp_Object saved_object
;
18601 enum display_element_type saved_what
= it
->what
;
18602 int saved_face_id
= it
->face_id
;
18604 saved_object
= it
->object
;
18605 saved_pos
= it
->position
;
18607 it
->what
= IT_CHARACTER
;
18608 memset (&it
->position
, 0, sizeof it
->position
);
18609 it
->object
= make_number (0);
18610 it
->c
= it
->char_to_display
= ' ';
18612 /* The last row's blank glyphs should get the default face, to
18613 avoid painting the rest of the window with the region face,
18614 if the region ends at ZV. */
18615 if (it
->glyph_row
->ends_at_zv_p
)
18616 it
->face_id
= default_face
->id
;
18618 it
->face_id
= face
->id
;
18620 PRODUCE_GLYPHS (it
);
18622 while (it
->current_x
<= it
->last_visible_x
)
18623 PRODUCE_GLYPHS (it
);
18625 /* Don't count these blanks really. It would let us insert a left
18626 truncation glyph below and make us set the cursor on them, maybe. */
18627 it
->current_x
= saved_x
;
18628 it
->object
= saved_object
;
18629 it
->position
= saved_pos
;
18630 it
->what
= saved_what
;
18631 it
->face_id
= saved_face_id
;
18636 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18637 trailing whitespace. */
18640 trailing_whitespace_p (ptrdiff_t charpos
)
18642 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18645 while (bytepos
< ZV_BYTE
18646 && (c
= FETCH_CHAR (bytepos
),
18647 c
== ' ' || c
== '\t'))
18650 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18652 if (bytepos
!= PT_BYTE
)
18659 /* Highlight trailing whitespace, if any, in ROW. */
18662 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18664 int used
= row
->used
[TEXT_AREA
];
18668 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18669 struct glyph
*glyph
= start
+ used
- 1;
18671 if (row
->reversed_p
)
18673 /* Right-to-left rows need to be processed in the opposite
18674 direction, so swap the edge pointers. */
18676 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18679 /* Skip over glyphs inserted to display the cursor at the
18680 end of a line, for extending the face of the last glyph
18681 to the end of the line on terminals, and for truncation
18682 and continuation glyphs. */
18683 if (!row
->reversed_p
)
18685 while (glyph
>= start
18686 && glyph
->type
== CHAR_GLYPH
18687 && INTEGERP (glyph
->object
))
18692 while (glyph
<= start
18693 && glyph
->type
== CHAR_GLYPH
18694 && INTEGERP (glyph
->object
))
18698 /* If last glyph is a space or stretch, and it's trailing
18699 whitespace, set the face of all trailing whitespace glyphs in
18700 IT->glyph_row to `trailing-whitespace'. */
18701 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18702 && BUFFERP (glyph
->object
)
18703 && (glyph
->type
== STRETCH_GLYPH
18704 || (glyph
->type
== CHAR_GLYPH
18705 && glyph
->u
.ch
== ' '))
18706 && trailing_whitespace_p (glyph
->charpos
))
18708 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18712 if (!row
->reversed_p
)
18714 while (glyph
>= start
18715 && BUFFERP (glyph
->object
)
18716 && (glyph
->type
== STRETCH_GLYPH
18717 || (glyph
->type
== CHAR_GLYPH
18718 && glyph
->u
.ch
== ' ')))
18719 (glyph
--)->face_id
= face_id
;
18723 while (glyph
<= start
18724 && BUFFERP (glyph
->object
)
18725 && (glyph
->type
== STRETCH_GLYPH
18726 || (glyph
->type
== CHAR_GLYPH
18727 && glyph
->u
.ch
== ' ')))
18728 (glyph
++)->face_id
= face_id
;
18735 /* Value is non-zero if glyph row ROW should be
18736 considered to hold the buffer position CHARPOS. */
18739 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18743 if (charpos
== CHARPOS (row
->end
.pos
)
18744 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18746 /* Suppose the row ends on a string.
18747 Unless the row is continued, that means it ends on a newline
18748 in the string. If it's anything other than a display string
18749 (e.g., a before-string from an overlay), we don't want the
18750 cursor there. (This heuristic seems to give the optimal
18751 behavior for the various types of multi-line strings.)
18752 One exception: if the string has `cursor' property on one of
18753 its characters, we _do_ want the cursor there. */
18754 if (CHARPOS (row
->end
.string_pos
) >= 0)
18756 if (row
->continued_p
)
18760 /* Check for `display' property. */
18761 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18762 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18763 struct glyph
*glyph
;
18766 for (glyph
= end
; glyph
>= beg
; --glyph
)
18767 if (STRINGP (glyph
->object
))
18770 = Fget_char_property (make_number (charpos
),
18774 && display_prop_string_p (prop
, glyph
->object
));
18775 /* If there's a `cursor' property on one of the
18776 string's characters, this row is a cursor row,
18777 even though this is not a display string. */
18780 Lisp_Object s
= glyph
->object
;
18782 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18784 ptrdiff_t gpos
= glyph
->charpos
;
18786 if (!NILP (Fget_char_property (make_number (gpos
),
18798 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18800 /* If the row ends in middle of a real character,
18801 and the line is continued, we want the cursor here.
18802 That's because CHARPOS (ROW->end.pos) would equal
18803 PT if PT is before the character. */
18804 if (!row
->ends_in_ellipsis_p
)
18805 result
= row
->continued_p
;
18807 /* If the row ends in an ellipsis, then
18808 CHARPOS (ROW->end.pos) will equal point after the
18809 invisible text. We want that position to be displayed
18810 after the ellipsis. */
18813 /* If the row ends at ZV, display the cursor at the end of that
18814 row instead of at the start of the row below. */
18815 else if (row
->ends_at_zv_p
)
18824 /* Value is non-zero if glyph row ROW should be
18825 used to hold the cursor. */
18828 cursor_row_p (struct glyph_row
*row
)
18830 return row_for_charpos_p (row
, PT
);
18835 /* Push the property PROP so that it will be rendered at the current
18836 position in IT. Return 1 if PROP was successfully pushed, 0
18837 otherwise. Called from handle_line_prefix to handle the
18838 `line-prefix' and `wrap-prefix' properties. */
18841 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18843 struct text_pos pos
=
18844 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18846 eassert (it
->method
== GET_FROM_BUFFER
18847 || it
->method
== GET_FROM_DISPLAY_VECTOR
18848 || it
->method
== GET_FROM_STRING
);
18850 /* We need to save the current buffer/string position, so it will be
18851 restored by pop_it, because iterate_out_of_display_property
18852 depends on that being set correctly, but some situations leave
18853 it->position not yet set when this function is called. */
18854 push_it (it
, &pos
);
18856 if (STRINGP (prop
))
18858 if (SCHARS (prop
) == 0)
18865 it
->string_from_prefix_prop_p
= 1;
18866 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18867 it
->current
.overlay_string_index
= -1;
18868 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18869 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18870 it
->method
= GET_FROM_STRING
;
18871 it
->stop_charpos
= 0;
18873 it
->base_level_stop
= 0;
18875 /* Force paragraph direction to be that of the parent
18877 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18878 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18880 it
->paragraph_embedding
= L2R
;
18882 /* Set up the bidi iterator for this display string. */
18885 it
->bidi_it
.string
.lstring
= it
->string
;
18886 it
->bidi_it
.string
.s
= NULL
;
18887 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18888 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18889 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18890 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18891 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18894 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18896 it
->method
= GET_FROM_STRETCH
;
18899 #ifdef HAVE_WINDOW_SYSTEM
18900 else if (IMAGEP (prop
))
18902 it
->what
= IT_IMAGE
;
18903 it
->image_id
= lookup_image (it
->f
, prop
);
18904 it
->method
= GET_FROM_IMAGE
;
18906 #endif /* HAVE_WINDOW_SYSTEM */
18909 pop_it (it
); /* bogus display property, give up */
18916 /* Return the character-property PROP at the current position in IT. */
18919 get_it_property (struct it
*it
, Lisp_Object prop
)
18921 Lisp_Object position
;
18923 if (STRINGP (it
->object
))
18924 position
= make_number (IT_STRING_CHARPOS (*it
));
18925 else if (BUFFERP (it
->object
))
18926 position
= make_number (IT_CHARPOS (*it
));
18930 return Fget_char_property (position
, prop
, it
->object
);
18933 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18936 handle_line_prefix (struct it
*it
)
18938 Lisp_Object prefix
;
18940 if (it
->continuation_lines_width
> 0)
18942 prefix
= get_it_property (it
, Qwrap_prefix
);
18944 prefix
= Vwrap_prefix
;
18948 prefix
= get_it_property (it
, Qline_prefix
);
18950 prefix
= Vline_prefix
;
18952 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18954 /* If the prefix is wider than the window, and we try to wrap
18955 it, it would acquire its own wrap prefix, and so on till the
18956 iterator stack overflows. So, don't wrap the prefix. */
18957 it
->line_wrap
= TRUNCATE
;
18958 it
->avoid_cursor_p
= 1;
18964 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18965 only for R2L lines from display_line and display_string, when they
18966 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18967 the line/string needs to be continued on the next glyph row. */
18969 unproduce_glyphs (struct it
*it
, int n
)
18971 struct glyph
*glyph
, *end
;
18973 eassert (it
->glyph_row
);
18974 eassert (it
->glyph_row
->reversed_p
);
18975 eassert (it
->area
== TEXT_AREA
);
18976 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18978 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18979 n
= it
->glyph_row
->used
[TEXT_AREA
];
18980 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18981 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18982 for ( ; glyph
< end
; glyph
++)
18983 glyph
[-n
] = *glyph
;
18986 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18987 and ROW->maxpos. */
18989 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18990 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18991 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18993 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18994 lines' rows is implemented for bidi-reordered rows. */
18996 /* ROW->minpos is the value of min_pos, the minimal buffer position
18997 we have in ROW, or ROW->start.pos if that is smaller. */
18998 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18999 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19001 /* We didn't find buffer positions smaller than ROW->start, or
19002 didn't find _any_ valid buffer positions in any of the glyphs,
19003 so we must trust the iterator's computed positions. */
19004 row
->minpos
= row
->start
.pos
;
19007 max_pos
= CHARPOS (it
->current
.pos
);
19008 max_bpos
= BYTEPOS (it
->current
.pos
);
19011 /* Here are the various use-cases for ending the row, and the
19012 corresponding values for ROW->maxpos:
19014 Line ends in a newline from buffer eol_pos + 1
19015 Line is continued from buffer max_pos + 1
19016 Line is truncated on right it->current.pos
19017 Line ends in a newline from string max_pos + 1(*)
19018 (*) + 1 only when line ends in a forward scan
19019 Line is continued from string max_pos
19020 Line is continued from display vector max_pos
19021 Line is entirely from a string min_pos == max_pos
19022 Line is entirely from a display vector min_pos == max_pos
19023 Line that ends at ZV ZV
19025 If you discover other use-cases, please add them here as
19027 if (row
->ends_at_zv_p
)
19028 row
->maxpos
= it
->current
.pos
;
19029 else if (row
->used
[TEXT_AREA
])
19031 int seen_this_string
= 0;
19032 struct glyph_row
*r1
= row
- 1;
19034 /* Did we see the same display string on the previous row? */
19035 if (STRINGP (it
->object
)
19036 /* this is not the first row */
19037 && row
> it
->w
->desired_matrix
->rows
19038 /* previous row is not the header line */
19039 && !r1
->mode_line_p
19040 /* previous row also ends in a newline from a string */
19041 && r1
->ends_in_newline_from_string_p
)
19043 struct glyph
*start
, *end
;
19045 /* Search for the last glyph of the previous row that came
19046 from buffer or string. Depending on whether the row is
19047 L2R or R2L, we need to process it front to back or the
19048 other way round. */
19049 if (!r1
->reversed_p
)
19051 start
= r1
->glyphs
[TEXT_AREA
];
19052 end
= start
+ r1
->used
[TEXT_AREA
];
19053 /* Glyphs inserted by redisplay have an integer (zero)
19054 as their object. */
19056 && INTEGERP ((end
- 1)->object
)
19057 && (end
- 1)->charpos
<= 0)
19061 if (EQ ((end
- 1)->object
, it
->object
))
19062 seen_this_string
= 1;
19065 /* If all the glyphs of the previous row were inserted
19066 by redisplay, it means the previous row was
19067 produced from a single newline, which is only
19068 possible if that newline came from the same string
19069 as the one which produced this ROW. */
19070 seen_this_string
= 1;
19074 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19075 start
= end
+ r1
->used
[TEXT_AREA
];
19077 && INTEGERP ((end
+ 1)->object
)
19078 && (end
+ 1)->charpos
<= 0)
19082 if (EQ ((end
+ 1)->object
, it
->object
))
19083 seen_this_string
= 1;
19086 seen_this_string
= 1;
19089 /* Take note of each display string that covers a newline only
19090 once, the first time we see it. This is for when a display
19091 string includes more than one newline in it. */
19092 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19094 /* If we were scanning the buffer forward when we displayed
19095 the string, we want to account for at least one buffer
19096 position that belongs to this row (position covered by
19097 the display string), so that cursor positioning will
19098 consider this row as a candidate when point is at the end
19099 of the visual line represented by this row. This is not
19100 required when scanning back, because max_pos will already
19101 have a much larger value. */
19102 if (CHARPOS (row
->end
.pos
) > max_pos
)
19103 INC_BOTH (max_pos
, max_bpos
);
19104 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19106 else if (CHARPOS (it
->eol_pos
) > 0)
19107 SET_TEXT_POS (row
->maxpos
,
19108 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19109 else if (row
->continued_p
)
19111 /* If max_pos is different from IT's current position, it
19112 means IT->method does not belong to the display element
19113 at max_pos. However, it also means that the display
19114 element at max_pos was displayed in its entirety on this
19115 line, which is equivalent to saying that the next line
19116 starts at the next buffer position. */
19117 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19118 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19121 INC_BOTH (max_pos
, max_bpos
);
19122 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19125 else if (row
->truncated_on_right_p
)
19126 /* display_line already called reseat_at_next_visible_line_start,
19127 which puts the iterator at the beginning of the next line, in
19128 the logical order. */
19129 row
->maxpos
= it
->current
.pos
;
19130 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19131 /* A line that is entirely from a string/image/stretch... */
19132 row
->maxpos
= row
->minpos
;
19137 row
->maxpos
= it
->current
.pos
;
19140 /* Construct the glyph row IT->glyph_row in the desired matrix of
19141 IT->w from text at the current position of IT. See dispextern.h
19142 for an overview of struct it. Value is non-zero if
19143 IT->glyph_row displays text, as opposed to a line displaying ZV
19147 display_line (struct it
*it
)
19149 struct glyph_row
*row
= it
->glyph_row
;
19150 Lisp_Object overlay_arrow_string
;
19152 void *wrap_data
= NULL
;
19153 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19154 int wrap_row_used
= -1;
19155 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19156 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19157 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19158 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19159 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19161 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19162 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19164 /* We always start displaying at hpos zero even if hscrolled. */
19165 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19167 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19168 >= it
->w
->desired_matrix
->nrows
)
19170 it
->w
->nrows_scale_factor
++;
19171 fonts_changed_p
= 1;
19175 /* Is IT->w showing the region? */
19176 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19178 /* Clear the result glyph row and enable it. */
19179 prepare_desired_row (row
);
19181 row
->y
= it
->current_y
;
19182 row
->start
= it
->start
;
19183 row
->continuation_lines_width
= it
->continuation_lines_width
;
19184 row
->displays_text_p
= 1;
19185 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19186 it
->starts_in_middle_of_char_p
= 0;
19188 /* Arrange the overlays nicely for our purposes. Usually, we call
19189 display_line on only one line at a time, in which case this
19190 can't really hurt too much, or we call it on lines which appear
19191 one after another in the buffer, in which case all calls to
19192 recenter_overlay_lists but the first will be pretty cheap. */
19193 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19195 /* Move over display elements that are not visible because we are
19196 hscrolled. This may stop at an x-position < IT->first_visible_x
19197 if the first glyph is partially visible or if we hit a line end. */
19198 if (it
->current_x
< it
->first_visible_x
)
19200 enum move_it_result move_result
;
19202 this_line_min_pos
= row
->start
.pos
;
19203 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19204 MOVE_TO_POS
| MOVE_TO_X
);
19205 /* If we are under a large hscroll, move_it_in_display_line_to
19206 could hit the end of the line without reaching
19207 it->first_visible_x. Pretend that we did reach it. This is
19208 especially important on a TTY, where we will call
19209 extend_face_to_end_of_line, which needs to know how many
19210 blank glyphs to produce. */
19211 if (it
->current_x
< it
->first_visible_x
19212 && (move_result
== MOVE_NEWLINE_OR_CR
19213 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19214 it
->current_x
= it
->first_visible_x
;
19216 /* Record the smallest positions seen while we moved over
19217 display elements that are not visible. This is needed by
19218 redisplay_internal for optimizing the case where the cursor
19219 stays inside the same line. The rest of this function only
19220 considers positions that are actually displayed, so
19221 RECORD_MAX_MIN_POS will not otherwise record positions that
19222 are hscrolled to the left of the left edge of the window. */
19223 min_pos
= CHARPOS (this_line_min_pos
);
19224 min_bpos
= BYTEPOS (this_line_min_pos
);
19228 /* We only do this when not calling `move_it_in_display_line_to'
19229 above, because move_it_in_display_line_to calls
19230 handle_line_prefix itself. */
19231 handle_line_prefix (it
);
19234 /* Get the initial row height. This is either the height of the
19235 text hscrolled, if there is any, or zero. */
19236 row
->ascent
= it
->max_ascent
;
19237 row
->height
= it
->max_ascent
+ it
->max_descent
;
19238 row
->phys_ascent
= it
->max_phys_ascent
;
19239 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19240 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19242 /* Utility macro to record max and min buffer positions seen until now. */
19243 #define RECORD_MAX_MIN_POS(IT) \
19246 int composition_p = !STRINGP ((IT)->string) \
19247 && ((IT)->what == IT_COMPOSITION); \
19248 ptrdiff_t current_pos = \
19249 composition_p ? (IT)->cmp_it.charpos \
19250 : IT_CHARPOS (*(IT)); \
19251 ptrdiff_t current_bpos = \
19252 composition_p ? CHAR_TO_BYTE (current_pos) \
19253 : IT_BYTEPOS (*(IT)); \
19254 if (current_pos < min_pos) \
19256 min_pos = current_pos; \
19257 min_bpos = current_bpos; \
19259 if (IT_CHARPOS (*it) > max_pos) \
19261 max_pos = IT_CHARPOS (*it); \
19262 max_bpos = IT_BYTEPOS (*it); \
19267 /* Loop generating characters. The loop is left with IT on the next
19268 character to display. */
19271 int n_glyphs_before
, hpos_before
, x_before
;
19273 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19275 /* Retrieve the next thing to display. Value is zero if end of
19277 if (!get_next_display_element (it
))
19279 /* Maybe add a space at the end of this line that is used to
19280 display the cursor there under X. Set the charpos of the
19281 first glyph of blank lines not corresponding to any text
19283 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19284 row
->exact_window_width_line_p
= 1;
19285 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19286 || row
->used
[TEXT_AREA
] == 0)
19288 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19289 row
->displays_text_p
= 0;
19291 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19292 && (!MINI_WINDOW_P (it
->w
)
19293 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19294 row
->indicate_empty_line_p
= 1;
19297 it
->continuation_lines_width
= 0;
19298 row
->ends_at_zv_p
= 1;
19299 /* A row that displays right-to-left text must always have
19300 its last face extended all the way to the end of line,
19301 even if this row ends in ZV, because we still write to
19302 the screen left to right. We also need to extend the
19303 last face if the default face is remapped to some
19304 different face, otherwise the functions that clear
19305 portions of the screen will clear with the default face's
19306 background color. */
19307 if (row
->reversed_p
19308 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19309 extend_face_to_end_of_line (it
);
19313 /* Now, get the metrics of what we want to display. This also
19314 generates glyphs in `row' (which is IT->glyph_row). */
19315 n_glyphs_before
= row
->used
[TEXT_AREA
];
19318 /* Remember the line height so far in case the next element doesn't
19319 fit on the line. */
19320 if (it
->line_wrap
!= TRUNCATE
)
19322 ascent
= it
->max_ascent
;
19323 descent
= it
->max_descent
;
19324 phys_ascent
= it
->max_phys_ascent
;
19325 phys_descent
= it
->max_phys_descent
;
19327 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19329 if (IT_DISPLAYING_WHITESPACE (it
))
19333 SAVE_IT (wrap_it
, *it
, wrap_data
);
19335 wrap_row_used
= row
->used
[TEXT_AREA
];
19336 wrap_row_ascent
= row
->ascent
;
19337 wrap_row_height
= row
->height
;
19338 wrap_row_phys_ascent
= row
->phys_ascent
;
19339 wrap_row_phys_height
= row
->phys_height
;
19340 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19341 wrap_row_min_pos
= min_pos
;
19342 wrap_row_min_bpos
= min_bpos
;
19343 wrap_row_max_pos
= max_pos
;
19344 wrap_row_max_bpos
= max_bpos
;
19350 PRODUCE_GLYPHS (it
);
19352 /* If this display element was in marginal areas, continue with
19354 if (it
->area
!= TEXT_AREA
)
19356 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19357 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19358 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19359 row
->phys_height
= max (row
->phys_height
,
19360 it
->max_phys_ascent
+ it
->max_phys_descent
);
19361 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19362 it
->max_extra_line_spacing
);
19363 set_iterator_to_next (it
, 1);
19367 /* Does the display element fit on the line? If we truncate
19368 lines, we should draw past the right edge of the window. If
19369 we don't truncate, we want to stop so that we can display the
19370 continuation glyph before the right margin. If lines are
19371 continued, there are two possible strategies for characters
19372 resulting in more than 1 glyph (e.g. tabs): Display as many
19373 glyphs as possible in this line and leave the rest for the
19374 continuation line, or display the whole element in the next
19375 line. Original redisplay did the former, so we do it also. */
19376 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19377 hpos_before
= it
->hpos
;
19380 if (/* Not a newline. */
19382 /* Glyphs produced fit entirely in the line. */
19383 && it
->current_x
< it
->last_visible_x
)
19385 it
->hpos
+= nglyphs
;
19386 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19387 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19388 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19389 row
->phys_height
= max (row
->phys_height
,
19390 it
->max_phys_ascent
+ it
->max_phys_descent
);
19391 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19392 it
->max_extra_line_spacing
);
19393 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19394 row
->x
= x
- it
->first_visible_x
;
19395 /* Record the maximum and minimum buffer positions seen so
19396 far in glyphs that will be displayed by this row. */
19398 RECORD_MAX_MIN_POS (it
);
19403 struct glyph
*glyph
;
19405 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19407 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19408 new_x
= x
+ glyph
->pixel_width
;
19410 if (/* Lines are continued. */
19411 it
->line_wrap
!= TRUNCATE
19412 && (/* Glyph doesn't fit on the line. */
19413 new_x
> it
->last_visible_x
19414 /* Or it fits exactly on a window system frame. */
19415 || (new_x
== it
->last_visible_x
19416 && FRAME_WINDOW_P (it
->f
)
19417 && (row
->reversed_p
19418 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19419 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19421 /* End of a continued line. */
19424 || (new_x
== it
->last_visible_x
19425 && FRAME_WINDOW_P (it
->f
)
19426 && (row
->reversed_p
19427 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19428 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19430 /* Current glyph is the only one on the line or
19431 fits exactly on the line. We must continue
19432 the line because we can't draw the cursor
19433 after the glyph. */
19434 row
->continued_p
= 1;
19435 it
->current_x
= new_x
;
19436 it
->continuation_lines_width
+= new_x
;
19438 if (i
== nglyphs
- 1)
19440 /* If line-wrap is on, check if a previous
19441 wrap point was found. */
19442 if (wrap_row_used
> 0
19443 /* Even if there is a previous wrap
19444 point, continue the line here as
19445 usual, if (i) the previous character
19446 was a space or tab AND (ii) the
19447 current character is not. */
19449 || IT_DISPLAYING_WHITESPACE (it
)))
19452 /* Record the maximum and minimum buffer
19453 positions seen so far in glyphs that will be
19454 displayed by this row. */
19456 RECORD_MAX_MIN_POS (it
);
19457 set_iterator_to_next (it
, 1);
19458 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19460 if (!get_next_display_element (it
))
19462 row
->exact_window_width_line_p
= 1;
19463 it
->continuation_lines_width
= 0;
19464 row
->continued_p
= 0;
19465 row
->ends_at_zv_p
= 1;
19467 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19469 row
->continued_p
= 0;
19470 row
->exact_window_width_line_p
= 1;
19474 else if (it
->bidi_p
)
19475 RECORD_MAX_MIN_POS (it
);
19477 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19478 && !FRAME_WINDOW_P (it
->f
))
19480 /* A padding glyph that doesn't fit on this line.
19481 This means the whole character doesn't fit
19483 if (row
->reversed_p
)
19484 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19485 - n_glyphs_before
);
19486 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19488 /* Fill the rest of the row with continuation
19489 glyphs like in 20.x. */
19490 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19491 < row
->glyphs
[1 + TEXT_AREA
])
19492 produce_special_glyphs (it
, IT_CONTINUATION
);
19494 row
->continued_p
= 1;
19495 it
->current_x
= x_before
;
19496 it
->continuation_lines_width
+= x_before
;
19498 /* Restore the height to what it was before the
19499 element not fitting on the line. */
19500 it
->max_ascent
= ascent
;
19501 it
->max_descent
= descent
;
19502 it
->max_phys_ascent
= phys_ascent
;
19503 it
->max_phys_descent
= phys_descent
;
19505 else if (wrap_row_used
> 0)
19508 if (row
->reversed_p
)
19509 unproduce_glyphs (it
,
19510 row
->used
[TEXT_AREA
] - wrap_row_used
);
19511 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19512 it
->continuation_lines_width
+= wrap_x
;
19513 row
->used
[TEXT_AREA
] = wrap_row_used
;
19514 row
->ascent
= wrap_row_ascent
;
19515 row
->height
= wrap_row_height
;
19516 row
->phys_ascent
= wrap_row_phys_ascent
;
19517 row
->phys_height
= wrap_row_phys_height
;
19518 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19519 min_pos
= wrap_row_min_pos
;
19520 min_bpos
= wrap_row_min_bpos
;
19521 max_pos
= wrap_row_max_pos
;
19522 max_bpos
= wrap_row_max_bpos
;
19523 row
->continued_p
= 1;
19524 row
->ends_at_zv_p
= 0;
19525 row
->exact_window_width_line_p
= 0;
19526 it
->continuation_lines_width
+= x
;
19528 /* Make sure that a non-default face is extended
19529 up to the right margin of the window. */
19530 extend_face_to_end_of_line (it
);
19532 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19534 /* A TAB that extends past the right edge of the
19535 window. This produces a single glyph on
19536 window system frames. We leave the glyph in
19537 this row and let it fill the row, but don't
19538 consume the TAB. */
19539 if ((row
->reversed_p
19540 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19541 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19542 produce_special_glyphs (it
, IT_CONTINUATION
);
19543 it
->continuation_lines_width
+= it
->last_visible_x
;
19544 row
->ends_in_middle_of_char_p
= 1;
19545 row
->continued_p
= 1;
19546 glyph
->pixel_width
= it
->last_visible_x
- x
;
19547 it
->starts_in_middle_of_char_p
= 1;
19551 /* Something other than a TAB that draws past
19552 the right edge of the window. Restore
19553 positions to values before the element. */
19554 if (row
->reversed_p
)
19555 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19556 - (n_glyphs_before
+ i
));
19557 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19559 /* Display continuation glyphs. */
19560 it
->current_x
= x_before
;
19561 it
->continuation_lines_width
+= x
;
19562 if (!FRAME_WINDOW_P (it
->f
)
19563 || (row
->reversed_p
19564 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19565 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19566 produce_special_glyphs (it
, IT_CONTINUATION
);
19567 row
->continued_p
= 1;
19569 extend_face_to_end_of_line (it
);
19571 if (nglyphs
> 1 && i
> 0)
19573 row
->ends_in_middle_of_char_p
= 1;
19574 it
->starts_in_middle_of_char_p
= 1;
19577 /* Restore the height to what it was before the
19578 element not fitting on the line. */
19579 it
->max_ascent
= ascent
;
19580 it
->max_descent
= descent
;
19581 it
->max_phys_ascent
= phys_ascent
;
19582 it
->max_phys_descent
= phys_descent
;
19587 else if (new_x
> it
->first_visible_x
)
19589 /* Increment number of glyphs actually displayed. */
19592 /* Record the maximum and minimum buffer positions
19593 seen so far in glyphs that will be displayed by
19596 RECORD_MAX_MIN_POS (it
);
19598 if (x
< it
->first_visible_x
)
19599 /* Glyph is partially visible, i.e. row starts at
19600 negative X position. */
19601 row
->x
= x
- it
->first_visible_x
;
19605 /* Glyph is completely off the left margin of the
19606 window. This should not happen because of the
19607 move_it_in_display_line at the start of this
19608 function, unless the text display area of the
19609 window is empty. */
19610 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19613 /* Even if this display element produced no glyphs at all,
19614 we want to record its position. */
19615 if (it
->bidi_p
&& nglyphs
== 0)
19616 RECORD_MAX_MIN_POS (it
);
19618 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19619 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19620 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19621 row
->phys_height
= max (row
->phys_height
,
19622 it
->max_phys_ascent
+ it
->max_phys_descent
);
19623 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19624 it
->max_extra_line_spacing
);
19626 /* End of this display line if row is continued. */
19627 if (row
->continued_p
|| row
->ends_at_zv_p
)
19632 /* Is this a line end? If yes, we're also done, after making
19633 sure that a non-default face is extended up to the right
19634 margin of the window. */
19635 if (ITERATOR_AT_END_OF_LINE_P (it
))
19637 int used_before
= row
->used
[TEXT_AREA
];
19639 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19641 /* Add a space at the end of the line that is used to
19642 display the cursor there. */
19643 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19644 append_space_for_newline (it
, 0);
19646 /* Extend the face to the end of the line. */
19647 extend_face_to_end_of_line (it
);
19649 /* Make sure we have the position. */
19650 if (used_before
== 0)
19651 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19653 /* Record the position of the newline, for use in
19655 it
->eol_pos
= it
->current
.pos
;
19657 /* Consume the line end. This skips over invisible lines. */
19658 set_iterator_to_next (it
, 1);
19659 it
->continuation_lines_width
= 0;
19663 /* Proceed with next display element. Note that this skips
19664 over lines invisible because of selective display. */
19665 set_iterator_to_next (it
, 1);
19667 /* If we truncate lines, we are done when the last displayed
19668 glyphs reach past the right margin of the window. */
19669 if (it
->line_wrap
== TRUNCATE
19670 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19671 ? (it
->current_x
>= it
->last_visible_x
)
19672 : (it
->current_x
> it
->last_visible_x
)))
19674 /* Maybe add truncation glyphs. */
19675 if (!FRAME_WINDOW_P (it
->f
)
19676 || (row
->reversed_p
19677 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19678 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19682 if (!row
->reversed_p
)
19684 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19685 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19690 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19691 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19693 /* Remove any padding glyphs at the front of ROW, to
19694 make room for the truncation glyphs we will be
19695 adding below. The loop below always inserts at
19696 least one truncation glyph, so also remove the
19697 last glyph added to ROW. */
19698 unproduce_glyphs (it
, i
+ 1);
19699 /* Adjust i for the loop below. */
19700 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19703 it
->current_x
= x_before
;
19704 if (!FRAME_WINDOW_P (it
->f
))
19706 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19708 row
->used
[TEXT_AREA
] = i
;
19709 produce_special_glyphs (it
, IT_TRUNCATION
);
19714 row
->used
[TEXT_AREA
] = i
;
19715 produce_special_glyphs (it
, IT_TRUNCATION
);
19718 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19720 /* Don't truncate if we can overflow newline into fringe. */
19721 if (!get_next_display_element (it
))
19723 it
->continuation_lines_width
= 0;
19724 row
->ends_at_zv_p
= 1;
19725 row
->exact_window_width_line_p
= 1;
19728 if (ITERATOR_AT_END_OF_LINE_P (it
))
19730 row
->exact_window_width_line_p
= 1;
19731 goto at_end_of_line
;
19733 it
->current_x
= x_before
;
19736 row
->truncated_on_right_p
= 1;
19737 it
->continuation_lines_width
= 0;
19738 reseat_at_next_visible_line_start (it
, 0);
19739 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19740 it
->hpos
= hpos_before
;
19746 bidi_unshelve_cache (wrap_data
, 1);
19748 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19749 at the left window margin. */
19750 if (it
->first_visible_x
19751 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19753 if (!FRAME_WINDOW_P (it
->f
)
19754 || (row
->reversed_p
19755 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19756 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19757 insert_left_trunc_glyphs (it
);
19758 row
->truncated_on_left_p
= 1;
19761 /* Remember the position at which this line ends.
19763 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19764 cannot be before the call to find_row_edges below, since that is
19765 where these positions are determined. */
19766 row
->end
= it
->current
;
19769 row
->minpos
= row
->start
.pos
;
19770 row
->maxpos
= row
->end
.pos
;
19774 /* ROW->minpos and ROW->maxpos must be the smallest and
19775 `1 + the largest' buffer positions in ROW. But if ROW was
19776 bidi-reordered, these two positions can be anywhere in the
19777 row, so we must determine them now. */
19778 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19781 /* If the start of this line is the overlay arrow-position, then
19782 mark this glyph row as the one containing the overlay arrow.
19783 This is clearly a mess with variable size fonts. It would be
19784 better to let it be displayed like cursors under X. */
19785 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19786 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19787 !NILP (overlay_arrow_string
)))
19789 /* Overlay arrow in window redisplay is a fringe bitmap. */
19790 if (STRINGP (overlay_arrow_string
))
19792 struct glyph_row
*arrow_row
19793 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19794 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19795 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19796 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19797 struct glyph
*p2
, *end
;
19799 /* Copy the arrow glyphs. */
19800 while (glyph
< arrow_end
)
19803 /* Throw away padding glyphs. */
19805 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19806 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19812 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19817 eassert (INTEGERP (overlay_arrow_string
));
19818 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19820 overlay_arrow_seen
= 1;
19823 /* Highlight trailing whitespace. */
19824 if (!NILP (Vshow_trailing_whitespace
))
19825 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19827 /* Compute pixel dimensions of this line. */
19828 compute_line_metrics (it
);
19830 /* Implementation note: No changes in the glyphs of ROW or in their
19831 faces can be done past this point, because compute_line_metrics
19832 computes ROW's hash value and stores it within the glyph_row
19835 /* Record whether this row ends inside an ellipsis. */
19836 row
->ends_in_ellipsis_p
19837 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19838 && it
->ellipsis_p
);
19840 /* Save fringe bitmaps in this row. */
19841 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19842 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19843 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19844 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19846 it
->left_user_fringe_bitmap
= 0;
19847 it
->left_user_fringe_face_id
= 0;
19848 it
->right_user_fringe_bitmap
= 0;
19849 it
->right_user_fringe_face_id
= 0;
19851 /* Maybe set the cursor. */
19852 cvpos
= it
->w
->cursor
.vpos
;
19854 /* In bidi-reordered rows, keep checking for proper cursor
19855 position even if one has been found already, because buffer
19856 positions in such rows change non-linearly with ROW->VPOS,
19857 when a line is continued. One exception: when we are at ZV,
19858 display cursor on the first suitable glyph row, since all
19859 the empty rows after that also have their position set to ZV. */
19860 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19861 lines' rows is implemented for bidi-reordered rows. */
19863 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19864 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19865 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19866 && cursor_row_p (row
))
19867 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19869 /* Prepare for the next line. This line starts horizontally at (X
19870 HPOS) = (0 0). Vertical positions are incremented. As a
19871 convenience for the caller, IT->glyph_row is set to the next
19873 it
->current_x
= it
->hpos
= 0;
19874 it
->current_y
+= row
->height
;
19875 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19878 /* The next row should by default use the same value of the
19879 reversed_p flag as this one. set_iterator_to_next decides when
19880 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19881 the flag accordingly. */
19882 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19883 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19884 it
->start
= row
->end
;
19885 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
19887 #undef RECORD_MAX_MIN_POS
19890 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19891 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19892 doc
: /* Return paragraph direction at point in BUFFER.
19893 Value is either `left-to-right' or `right-to-left'.
19894 If BUFFER is omitted or nil, it defaults to the current buffer.
19896 Paragraph direction determines how the text in the paragraph is displayed.
19897 In left-to-right paragraphs, text begins at the left margin of the window
19898 and the reading direction is generally left to right. In right-to-left
19899 paragraphs, text begins at the right margin and is read from right to left.
19901 See also `bidi-paragraph-direction'. */)
19902 (Lisp_Object buffer
)
19904 struct buffer
*buf
= current_buffer
;
19905 struct buffer
*old
= buf
;
19907 if (! NILP (buffer
))
19909 CHECK_BUFFER (buffer
);
19910 buf
= XBUFFER (buffer
);
19913 if (NILP (BVAR (buf
, bidi_display_reordering
))
19914 || NILP (BVAR (buf
, enable_multibyte_characters
))
19915 /* When we are loading loadup.el, the character property tables
19916 needed for bidi iteration are not yet available. */
19917 || !NILP (Vpurify_flag
))
19918 return Qleft_to_right
;
19919 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19920 return BVAR (buf
, bidi_paragraph_direction
);
19923 /* Determine the direction from buffer text. We could try to
19924 use current_matrix if it is up to date, but this seems fast
19925 enough as it is. */
19926 struct bidi_it itb
;
19927 ptrdiff_t pos
= BUF_PT (buf
);
19928 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19930 void *itb_data
= bidi_shelve_cache ();
19932 set_buffer_temp (buf
);
19933 /* bidi_paragraph_init finds the base direction of the paragraph
19934 by searching forward from paragraph start. We need the base
19935 direction of the current or _previous_ paragraph, so we need
19936 to make sure we are within that paragraph. To that end, find
19937 the previous non-empty line. */
19938 if (pos
>= ZV
&& pos
> BEGV
)
19939 DEC_BOTH (pos
, bytepos
);
19940 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19941 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19943 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19944 || c
== ' ' || c
== '\t' || c
== '\f')
19946 if (bytepos
<= BEGV_BYTE
)
19951 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19954 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19955 itb
.paragraph_dir
= NEUTRAL_DIR
;
19956 itb
.string
.s
= NULL
;
19957 itb
.string
.lstring
= Qnil
;
19958 itb
.string
.bufpos
= 0;
19959 itb
.string
.unibyte
= 0;
19960 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19961 bidi_unshelve_cache (itb_data
, 0);
19962 set_buffer_temp (old
);
19963 switch (itb
.paragraph_dir
)
19966 return Qleft_to_right
;
19969 return Qright_to_left
;
19979 /***********************************************************************
19981 ***********************************************************************/
19983 /* Redisplay the menu bar in the frame for window W.
19985 The menu bar of X frames that don't have X toolkit support is
19986 displayed in a special window W->frame->menu_bar_window.
19988 The menu bar of terminal frames is treated specially as far as
19989 glyph matrices are concerned. Menu bar lines are not part of
19990 windows, so the update is done directly on the frame matrix rows
19991 for the menu bar. */
19994 display_menu_bar (struct window
*w
)
19996 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20001 /* Don't do all this for graphical frames. */
20003 if (FRAME_W32_P (f
))
20006 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20012 if (FRAME_NS_P (f
))
20014 #endif /* HAVE_NS */
20016 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20017 eassert (!FRAME_WINDOW_P (f
));
20018 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20019 it
.first_visible_x
= 0;
20020 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20021 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20022 if (FRAME_WINDOW_P (f
))
20024 /* Menu bar lines are displayed in the desired matrix of the
20025 dummy window menu_bar_window. */
20026 struct window
*menu_w
;
20027 menu_w
= XWINDOW (f
->menu_bar_window
);
20028 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20030 it
.first_visible_x
= 0;
20031 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20034 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20036 /* This is a TTY frame, i.e. character hpos/vpos are used as
20038 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20040 it
.first_visible_x
= 0;
20041 it
.last_visible_x
= FRAME_COLS (f
);
20044 /* FIXME: This should be controlled by a user option. See the
20045 comments in redisplay_tool_bar and display_mode_line about
20047 it
.paragraph_embedding
= L2R
;
20049 /* Clear all rows of the menu bar. */
20050 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20052 struct glyph_row
*row
= it
.glyph_row
+ i
;
20053 clear_glyph_row (row
);
20054 row
->enabled_p
= 1;
20055 row
->full_width_p
= 1;
20058 /* Display all items of the menu bar. */
20059 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20060 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20062 Lisp_Object string
;
20064 /* Stop at nil string. */
20065 string
= AREF (items
, i
+ 1);
20069 /* Remember where item was displayed. */
20070 ASET (items
, i
+ 3, make_number (it
.hpos
));
20072 /* Display the item, pad with one space. */
20073 if (it
.current_x
< it
.last_visible_x
)
20074 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20075 SCHARS (string
) + 1, 0, 0, -1);
20078 /* Fill out the line with spaces. */
20079 if (it
.current_x
< it
.last_visible_x
)
20080 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20082 /* Compute the total height of the lines. */
20083 compute_line_metrics (&it
);
20088 /***********************************************************************
20090 ***********************************************************************/
20092 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20093 FORCE is non-zero, redisplay mode lines unconditionally.
20094 Otherwise, redisplay only mode lines that are garbaged. Value is
20095 the number of windows whose mode lines were redisplayed. */
20098 redisplay_mode_lines (Lisp_Object window
, int force
)
20102 while (!NILP (window
))
20104 struct window
*w
= XWINDOW (window
);
20106 if (WINDOWP (w
->contents
))
20107 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20109 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20110 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20112 struct text_pos lpoint
;
20113 struct buffer
*old
= current_buffer
;
20115 /* Set the window's buffer for the mode line display. */
20116 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20117 set_buffer_internal_1 (XBUFFER (w
->contents
));
20119 /* Point refers normally to the selected window. For any
20120 other window, set up appropriate value. */
20121 if (!EQ (window
, selected_window
))
20123 struct text_pos pt
;
20125 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20126 if (CHARPOS (pt
) < BEGV
)
20127 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20128 else if (CHARPOS (pt
) > (ZV
- 1))
20129 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20131 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20134 /* Display mode lines. */
20135 clear_glyph_matrix (w
->desired_matrix
);
20136 if (display_mode_lines (w
))
20139 w
->must_be_updated_p
= 1;
20142 /* Restore old settings. */
20143 set_buffer_internal_1 (old
);
20144 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20154 /* Display the mode and/or header line of window W. Value is the
20155 sum number of mode lines and header lines displayed. */
20158 display_mode_lines (struct window
*w
)
20160 Lisp_Object old_selected_window
= selected_window
;
20161 Lisp_Object old_selected_frame
= selected_frame
;
20162 Lisp_Object new_frame
= w
->frame
;
20163 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20166 selected_frame
= new_frame
;
20167 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20168 or window's point, then we'd need select_window_1 here as well. */
20169 XSETWINDOW (selected_window
, w
);
20170 XFRAME (new_frame
)->selected_window
= selected_window
;
20172 /* These will be set while the mode line specs are processed. */
20173 line_number_displayed
= 0;
20174 w
->column_number_displayed
= -1;
20176 if (WINDOW_WANTS_MODELINE_P (w
))
20178 struct window
*sel_w
= XWINDOW (old_selected_window
);
20180 /* Select mode line face based on the real selected window. */
20181 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20182 BVAR (current_buffer
, mode_line_format
));
20186 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20188 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20189 BVAR (current_buffer
, header_line_format
));
20193 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20194 selected_frame
= old_selected_frame
;
20195 selected_window
= old_selected_window
;
20200 /* Display mode or header line of window W. FACE_ID specifies which
20201 line to display; it is either MODE_LINE_FACE_ID or
20202 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20203 display. Value is the pixel height of the mode/header line
20207 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20211 ptrdiff_t count
= SPECPDL_INDEX ();
20213 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20214 /* Don't extend on a previously drawn mode-line.
20215 This may happen if called from pos_visible_p. */
20216 it
.glyph_row
->enabled_p
= 0;
20217 prepare_desired_row (it
.glyph_row
);
20219 it
.glyph_row
->mode_line_p
= 1;
20221 /* FIXME: This should be controlled by a user option. But
20222 supporting such an option is not trivial, since the mode line is
20223 made up of many separate strings. */
20224 it
.paragraph_embedding
= L2R
;
20226 record_unwind_protect (unwind_format_mode_line
,
20227 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20229 mode_line_target
= MODE_LINE_DISPLAY
;
20231 /* Temporarily make frame's keyboard the current kboard so that
20232 kboard-local variables in the mode_line_format will get the right
20234 push_kboard (FRAME_KBOARD (it
.f
));
20235 record_unwind_save_match_data ();
20236 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20239 unbind_to (count
, Qnil
);
20241 /* Fill up with spaces. */
20242 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20244 compute_line_metrics (&it
);
20245 it
.glyph_row
->full_width_p
= 1;
20246 it
.glyph_row
->continued_p
= 0;
20247 it
.glyph_row
->truncated_on_left_p
= 0;
20248 it
.glyph_row
->truncated_on_right_p
= 0;
20250 /* Make a 3D mode-line have a shadow at its right end. */
20251 face
= FACE_FROM_ID (it
.f
, face_id
);
20252 extend_face_to_end_of_line (&it
);
20253 if (face
->box
!= FACE_NO_BOX
)
20255 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20256 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20257 last
->right_box_line_p
= 1;
20260 return it
.glyph_row
->height
;
20263 /* Move element ELT in LIST to the front of LIST.
20264 Return the updated list. */
20267 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20269 register Lisp_Object tail
, prev
;
20270 register Lisp_Object tem
;
20274 while (CONSP (tail
))
20280 /* Splice out the link TAIL. */
20282 list
= XCDR (tail
);
20284 Fsetcdr (prev
, XCDR (tail
));
20286 /* Now make it the first. */
20287 Fsetcdr (tail
, list
);
20292 tail
= XCDR (tail
);
20296 /* Not found--return unchanged LIST. */
20300 /* Contribute ELT to the mode line for window IT->w. How it
20301 translates into text depends on its data type.
20303 IT describes the display environment in which we display, as usual.
20305 DEPTH is the depth in recursion. It is used to prevent
20306 infinite recursion here.
20308 FIELD_WIDTH is the number of characters the display of ELT should
20309 occupy in the mode line, and PRECISION is the maximum number of
20310 characters to display from ELT's representation. See
20311 display_string for details.
20313 Returns the hpos of the end of the text generated by ELT.
20315 PROPS is a property list to add to any string we encounter.
20317 If RISKY is nonzero, remove (disregard) any properties in any string
20318 we encounter, and ignore :eval and :propertize.
20320 The global variable `mode_line_target' determines whether the
20321 output is passed to `store_mode_line_noprop',
20322 `store_mode_line_string', or `display_string'. */
20325 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20326 Lisp_Object elt
, Lisp_Object props
, int risky
)
20328 int n
= 0, field
, prec
;
20333 elt
= build_string ("*too-deep*");
20337 switch (XTYPE (elt
))
20341 /* A string: output it and check for %-constructs within it. */
20343 ptrdiff_t offset
= 0;
20345 if (SCHARS (elt
) > 0
20346 && (!NILP (props
) || risky
))
20348 Lisp_Object oprops
, aelt
;
20349 oprops
= Ftext_properties_at (make_number (0), elt
);
20351 /* If the starting string's properties are not what
20352 we want, translate the string. Also, if the string
20353 is risky, do that anyway. */
20355 if (NILP (Fequal (props
, oprops
)) || risky
)
20357 /* If the starting string has properties,
20358 merge the specified ones onto the existing ones. */
20359 if (! NILP (oprops
) && !risky
)
20363 oprops
= Fcopy_sequence (oprops
);
20365 while (CONSP (tem
))
20367 oprops
= Fplist_put (oprops
, XCAR (tem
),
20368 XCAR (XCDR (tem
)));
20369 tem
= XCDR (XCDR (tem
));
20374 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20375 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20377 /* AELT is what we want. Move it to the front
20378 without consing. */
20380 mode_line_proptrans_alist
20381 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20387 /* If AELT has the wrong props, it is useless.
20388 so get rid of it. */
20390 mode_line_proptrans_alist
20391 = Fdelq (aelt
, mode_line_proptrans_alist
);
20393 elt
= Fcopy_sequence (elt
);
20394 Fset_text_properties (make_number (0), Flength (elt
),
20396 /* Add this item to mode_line_proptrans_alist. */
20397 mode_line_proptrans_alist
20398 = Fcons (Fcons (elt
, props
),
20399 mode_line_proptrans_alist
);
20400 /* Truncate mode_line_proptrans_alist
20401 to at most 50 elements. */
20402 tem
= Fnthcdr (make_number (50),
20403 mode_line_proptrans_alist
);
20405 XSETCDR (tem
, Qnil
);
20414 prec
= precision
- n
;
20415 switch (mode_line_target
)
20417 case MODE_LINE_NOPROP
:
20418 case MODE_LINE_TITLE
:
20419 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20421 case MODE_LINE_STRING
:
20422 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20424 case MODE_LINE_DISPLAY
:
20425 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20426 0, prec
, 0, STRING_MULTIBYTE (elt
));
20433 /* Handle the non-literal case. */
20435 while ((precision
<= 0 || n
< precision
)
20436 && SREF (elt
, offset
) != 0
20437 && (mode_line_target
!= MODE_LINE_DISPLAY
20438 || it
->current_x
< it
->last_visible_x
))
20440 ptrdiff_t last_offset
= offset
;
20442 /* Advance to end of string or next format specifier. */
20443 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20446 if (offset
- 1 != last_offset
)
20448 ptrdiff_t nchars
, nbytes
;
20450 /* Output to end of string or up to '%'. Field width
20451 is length of string. Don't output more than
20452 PRECISION allows us. */
20455 prec
= c_string_width (SDATA (elt
) + last_offset
,
20456 offset
- last_offset
, precision
- n
,
20459 switch (mode_line_target
)
20461 case MODE_LINE_NOPROP
:
20462 case MODE_LINE_TITLE
:
20463 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20465 case MODE_LINE_STRING
:
20467 ptrdiff_t bytepos
= last_offset
;
20468 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20469 ptrdiff_t endpos
= (precision
<= 0
20470 ? string_byte_to_char (elt
, offset
)
20471 : charpos
+ nchars
);
20473 n
+= store_mode_line_string (NULL
,
20474 Fsubstring (elt
, make_number (charpos
),
20475 make_number (endpos
)),
20479 case MODE_LINE_DISPLAY
:
20481 ptrdiff_t bytepos
= last_offset
;
20482 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20484 if (precision
<= 0)
20485 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20486 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20488 STRING_MULTIBYTE (elt
));
20493 else /* c == '%' */
20495 ptrdiff_t percent_position
= offset
;
20497 /* Get the specified minimum width. Zero means
20500 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20501 field
= field
* 10 + c
- '0';
20503 /* Don't pad beyond the total padding allowed. */
20504 if (field_width
- n
> 0 && field
> field_width
- n
)
20505 field
= field_width
- n
;
20507 /* Note that either PRECISION <= 0 or N < PRECISION. */
20508 prec
= precision
- n
;
20511 n
+= display_mode_element (it
, depth
, field
, prec
,
20512 Vglobal_mode_string
, props
,
20517 ptrdiff_t bytepos
, charpos
;
20519 Lisp_Object string
;
20521 bytepos
= percent_position
;
20522 charpos
= (STRING_MULTIBYTE (elt
)
20523 ? string_byte_to_char (elt
, bytepos
)
20525 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20526 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20528 switch (mode_line_target
)
20530 case MODE_LINE_NOPROP
:
20531 case MODE_LINE_TITLE
:
20532 n
+= store_mode_line_noprop (spec
, field
, prec
);
20534 case MODE_LINE_STRING
:
20536 Lisp_Object tem
= build_string (spec
);
20537 props
= Ftext_properties_at (make_number (charpos
), elt
);
20538 /* Should only keep face property in props */
20539 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20542 case MODE_LINE_DISPLAY
:
20544 int nglyphs_before
, nwritten
;
20546 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20547 nwritten
= display_string (spec
, string
, elt
,
20552 /* Assign to the glyphs written above the
20553 string where the `%x' came from, position
20557 struct glyph
*glyph
20558 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20562 for (i
= 0; i
< nwritten
; ++i
)
20564 glyph
[i
].object
= elt
;
20565 glyph
[i
].charpos
= charpos
;
20582 /* A symbol: process the value of the symbol recursively
20583 as if it appeared here directly. Avoid error if symbol void.
20584 Special case: if value of symbol is a string, output the string
20587 register Lisp_Object tem
;
20589 /* If the variable is not marked as risky to set
20590 then its contents are risky to use. */
20591 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20594 tem
= Fboundp (elt
);
20597 tem
= Fsymbol_value (elt
);
20598 /* If value is a string, output that string literally:
20599 don't check for % within it. */
20603 if (!EQ (tem
, elt
))
20605 /* Give up right away for nil or t. */
20615 register Lisp_Object car
, tem
;
20617 /* A cons cell: five distinct cases.
20618 If first element is :eval or :propertize, do something special.
20619 If first element is a string or a cons, process all the elements
20620 and effectively concatenate them.
20621 If first element is a negative number, truncate displaying cdr to
20622 at most that many characters. If positive, pad (with spaces)
20623 to at least that many characters.
20624 If first element is a symbol, process the cadr or caddr recursively
20625 according to whether the symbol's value is non-nil or nil. */
20627 if (EQ (car
, QCeval
))
20629 /* An element of the form (:eval FORM) means evaluate FORM
20630 and use the result as mode line elements. */
20635 if (CONSP (XCDR (elt
)))
20638 spec
= safe_eval (XCAR (XCDR (elt
)));
20639 n
+= display_mode_element (it
, depth
, field_width
- n
,
20640 precision
- n
, spec
, props
,
20644 else if (EQ (car
, QCpropertize
))
20646 /* An element of the form (:propertize ELT PROPS...)
20647 means display ELT but applying properties PROPS. */
20652 if (CONSP (XCDR (elt
)))
20653 n
+= display_mode_element (it
, depth
, field_width
- n
,
20654 precision
- n
, XCAR (XCDR (elt
)),
20655 XCDR (XCDR (elt
)), risky
);
20657 else if (SYMBOLP (car
))
20659 tem
= Fboundp (car
);
20663 /* elt is now the cdr, and we know it is a cons cell.
20664 Use its car if CAR has a non-nil value. */
20667 tem
= Fsymbol_value (car
);
20674 /* Symbol's value is nil (or symbol is unbound)
20675 Get the cddr of the original list
20676 and if possible find the caddr and use that. */
20680 else if (!CONSP (elt
))
20685 else if (INTEGERP (car
))
20687 register int lim
= XINT (car
);
20691 /* Negative int means reduce maximum width. */
20692 if (precision
<= 0)
20695 precision
= min (precision
, -lim
);
20699 /* Padding specified. Don't let it be more than
20700 current maximum. */
20702 lim
= min (precision
, lim
);
20704 /* If that's more padding than already wanted, queue it.
20705 But don't reduce padding already specified even if
20706 that is beyond the current truncation point. */
20707 field_width
= max (lim
, field_width
);
20711 else if (STRINGP (car
) || CONSP (car
))
20713 Lisp_Object halftail
= elt
;
20717 && (precision
<= 0 || n
< precision
))
20719 n
+= display_mode_element (it
, depth
,
20720 /* Do padding only after the last
20721 element in the list. */
20722 (! CONSP (XCDR (elt
))
20725 precision
- n
, XCAR (elt
),
20729 if ((len
& 1) == 0)
20730 halftail
= XCDR (halftail
);
20731 /* Check for cycle. */
20732 if (EQ (halftail
, elt
))
20741 elt
= build_string ("*invalid*");
20745 /* Pad to FIELD_WIDTH. */
20746 if (field_width
> 0 && n
< field_width
)
20748 switch (mode_line_target
)
20750 case MODE_LINE_NOPROP
:
20751 case MODE_LINE_TITLE
:
20752 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20754 case MODE_LINE_STRING
:
20755 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20757 case MODE_LINE_DISPLAY
:
20758 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20767 /* Store a mode-line string element in mode_line_string_list.
20769 If STRING is non-null, display that C string. Otherwise, the Lisp
20770 string LISP_STRING is displayed.
20772 FIELD_WIDTH is the minimum number of output glyphs to produce.
20773 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20774 with spaces. FIELD_WIDTH <= 0 means don't pad.
20776 PRECISION is the maximum number of characters to output from
20777 STRING. PRECISION <= 0 means don't truncate the string.
20779 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20780 properties to the string.
20782 PROPS are the properties to add to the string.
20783 The mode_line_string_face face property is always added to the string.
20787 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20788 int field_width
, int precision
, Lisp_Object props
)
20793 if (string
!= NULL
)
20795 len
= strlen (string
);
20796 if (precision
> 0 && len
> precision
)
20798 lisp_string
= make_string (string
, len
);
20800 props
= mode_line_string_face_prop
;
20801 else if (!NILP (mode_line_string_face
))
20803 Lisp_Object face
= Fplist_get (props
, Qface
);
20804 props
= Fcopy_sequence (props
);
20806 face
= mode_line_string_face
;
20808 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20809 props
= Fplist_put (props
, Qface
, face
);
20811 Fadd_text_properties (make_number (0), make_number (len
),
20812 props
, lisp_string
);
20816 len
= XFASTINT (Flength (lisp_string
));
20817 if (precision
> 0 && len
> precision
)
20820 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20823 if (!NILP (mode_line_string_face
))
20827 props
= Ftext_properties_at (make_number (0), lisp_string
);
20828 face
= Fplist_get (props
, Qface
);
20830 face
= mode_line_string_face
;
20832 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20833 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20835 lisp_string
= Fcopy_sequence (lisp_string
);
20838 Fadd_text_properties (make_number (0), make_number (len
),
20839 props
, lisp_string
);
20844 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20848 if (field_width
> len
)
20850 field_width
-= len
;
20851 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20853 Fadd_text_properties (make_number (0), make_number (field_width
),
20854 props
, lisp_string
);
20855 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20863 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20865 doc
: /* Format a string out of a mode line format specification.
20866 First arg FORMAT specifies the mode line format (see `mode-line-format'
20867 for details) to use.
20869 By default, the format is evaluated for the currently selected window.
20871 Optional second arg FACE specifies the face property to put on all
20872 characters for which no face is specified. The value nil means the
20873 default face. The value t means whatever face the window's mode line
20874 currently uses (either `mode-line' or `mode-line-inactive',
20875 depending on whether the window is the selected window or not).
20876 An integer value means the value string has no text
20879 Optional third and fourth args WINDOW and BUFFER specify the window
20880 and buffer to use as the context for the formatting (defaults
20881 are the selected window and the WINDOW's buffer). */)
20882 (Lisp_Object format
, Lisp_Object face
,
20883 Lisp_Object window
, Lisp_Object buffer
)
20888 struct buffer
*old_buffer
= NULL
;
20890 int no_props
= INTEGERP (face
);
20891 ptrdiff_t count
= SPECPDL_INDEX ();
20893 int string_start
= 0;
20895 w
= decode_any_window (window
);
20896 XSETWINDOW (window
, w
);
20899 buffer
= w
->contents
;
20900 CHECK_BUFFER (buffer
);
20902 /* Make formatting the modeline a non-op when noninteractive, otherwise
20903 there will be problems later caused by a partially initialized frame. */
20904 if (NILP (format
) || noninteractive
)
20905 return empty_unibyte_string
;
20910 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20911 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20912 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20913 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20914 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20915 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20916 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20919 old_buffer
= current_buffer
;
20921 /* Save things including mode_line_proptrans_alist,
20922 and set that to nil so that we don't alter the outer value. */
20923 record_unwind_protect (unwind_format_mode_line
,
20924 format_mode_line_unwind_data
20925 (XFRAME (WINDOW_FRAME (w
)),
20926 old_buffer
, selected_window
, 1));
20927 mode_line_proptrans_alist
= Qnil
;
20929 Fselect_window (window
, Qt
);
20930 set_buffer_internal_1 (XBUFFER (buffer
));
20932 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20936 mode_line_target
= MODE_LINE_NOPROP
;
20937 mode_line_string_face_prop
= Qnil
;
20938 mode_line_string_list
= Qnil
;
20939 string_start
= MODE_LINE_NOPROP_LEN (0);
20943 mode_line_target
= MODE_LINE_STRING
;
20944 mode_line_string_list
= Qnil
;
20945 mode_line_string_face
= face
;
20946 mode_line_string_face_prop
20947 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20950 push_kboard (FRAME_KBOARD (it
.f
));
20951 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20956 len
= MODE_LINE_NOPROP_LEN (string_start
);
20957 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20961 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20962 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20963 empty_unibyte_string
);
20966 unbind_to (count
, Qnil
);
20970 /* Write a null-terminated, right justified decimal representation of
20971 the positive integer D to BUF using a minimal field width WIDTH. */
20974 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20976 register char *p
= buf
;
20984 *p
++ = d
% 10 + '0';
20989 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21000 /* Write a null-terminated, right justified decimal and "human
21001 readable" representation of the nonnegative integer D to BUF using
21002 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21004 static const char power_letter
[] =
21018 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21020 /* We aim to represent the nonnegative integer D as
21021 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21022 ptrdiff_t quotient
= d
;
21024 /* -1 means: do not use TENTHS. */
21028 /* Length of QUOTIENT.TENTHS as a string. */
21034 if (quotient
>= 1000)
21036 /* Scale to the appropriate EXPONENT. */
21039 remainder
= quotient
% 1000;
21043 while (quotient
>= 1000);
21045 /* Round to nearest and decide whether to use TENTHS or not. */
21048 tenths
= remainder
/ 100;
21049 if (remainder
% 100 >= 50)
21056 if (quotient
== 10)
21064 if (remainder
>= 500)
21066 if (quotient
< 999)
21077 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21078 if (tenths
== -1 && quotient
<= 99)
21085 p
= psuffix
= buf
+ max (width
, length
);
21087 /* Print EXPONENT. */
21088 *psuffix
++ = power_letter
[exponent
];
21091 /* Print TENTHS. */
21094 *--p
= '0' + tenths
;
21098 /* Print QUOTIENT. */
21101 int digit
= quotient
% 10;
21102 *--p
= '0' + digit
;
21104 while ((quotient
/= 10) != 0);
21106 /* Print leading spaces. */
21111 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21112 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21113 type of CODING_SYSTEM. Return updated pointer into BUF. */
21115 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21118 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21121 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21122 const unsigned char *eol_str
;
21124 /* The EOL conversion we are using. */
21125 Lisp_Object eoltype
;
21127 val
= CODING_SYSTEM_SPEC (coding_system
);
21130 if (!VECTORP (val
)) /* Not yet decided. */
21132 *buf
++ = multibyte
? '-' : ' ';
21134 eoltype
= eol_mnemonic_undecided
;
21135 /* Don't mention EOL conversion if it isn't decided. */
21140 Lisp_Object eolvalue
;
21142 attrs
= AREF (val
, 0);
21143 eolvalue
= AREF (val
, 2);
21146 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21151 /* The EOL conversion that is normal on this system. */
21153 if (NILP (eolvalue
)) /* Not yet decided. */
21154 eoltype
= eol_mnemonic_undecided
;
21155 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21156 eoltype
= eol_mnemonic_undecided
;
21157 else /* eolvalue is Qunix, Qdos, or Qmac. */
21158 eoltype
= (EQ (eolvalue
, Qunix
)
21159 ? eol_mnemonic_unix
21160 : (EQ (eolvalue
, Qdos
) == 1
21161 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21167 /* Mention the EOL conversion if it is not the usual one. */
21168 if (STRINGP (eoltype
))
21170 eol_str
= SDATA (eoltype
);
21171 eol_str_len
= SBYTES (eoltype
);
21173 else if (CHARACTERP (eoltype
))
21175 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21176 int c
= XFASTINT (eoltype
);
21177 eol_str_len
= CHAR_STRING (c
, tmp
);
21182 eol_str
= invalid_eol_type
;
21183 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21185 memcpy (buf
, eol_str
, eol_str_len
);
21186 buf
+= eol_str_len
;
21192 /* Return a string for the output of a mode line %-spec for window W,
21193 generated by character C. FIELD_WIDTH > 0 means pad the string
21194 returned with spaces to that value. Return a Lisp string in
21195 *STRING if the resulting string is taken from that Lisp string.
21197 Note we operate on the current buffer for most purposes. */
21199 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21201 static const char *
21202 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21203 Lisp_Object
*string
)
21206 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21207 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21208 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21209 produce strings from numerical values, so limit preposterously
21210 large values of FIELD_WIDTH to avoid overrunning the buffer's
21211 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21212 bytes plus the terminating null. */
21213 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21214 struct buffer
*b
= current_buffer
;
21222 if (!NILP (BVAR (b
, read_only
)))
21224 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21229 /* This differs from %* only for a modified read-only buffer. */
21230 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21232 if (!NILP (BVAR (b
, read_only
)))
21237 /* This differs from %* in ignoring read-only-ness. */
21238 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21250 if (command_loop_level
> 5)
21252 p
= decode_mode_spec_buf
;
21253 for (i
= 0; i
< command_loop_level
; i
++)
21256 return decode_mode_spec_buf
;
21264 if (command_loop_level
> 5)
21266 p
= decode_mode_spec_buf
;
21267 for (i
= 0; i
< command_loop_level
; i
++)
21270 return decode_mode_spec_buf
;
21277 /* Let lots_of_dashes be a string of infinite length. */
21278 if (mode_line_target
== MODE_LINE_NOPROP
21279 || mode_line_target
== MODE_LINE_STRING
)
21281 if (field_width
<= 0
21282 || field_width
> sizeof (lots_of_dashes
))
21284 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21285 decode_mode_spec_buf
[i
] = '-';
21286 decode_mode_spec_buf
[i
] = '\0';
21287 return decode_mode_spec_buf
;
21290 return lots_of_dashes
;
21294 obj
= BVAR (b
, name
);
21298 /* %c and %l are ignored in `frame-title-format'.
21299 (In redisplay_internal, the frame title is drawn _before_ the
21300 windows are updated, so the stuff which depends on actual
21301 window contents (such as %l) may fail to render properly, or
21302 even crash emacs.) */
21303 if (mode_line_target
== MODE_LINE_TITLE
)
21307 ptrdiff_t col
= current_column ();
21308 w
->column_number_displayed
= col
;
21309 pint2str (decode_mode_spec_buf
, width
, col
);
21310 return decode_mode_spec_buf
;
21314 #ifndef SYSTEM_MALLOC
21316 if (NILP (Vmemory_full
))
21319 return "!MEM FULL! ";
21326 /* %F displays the frame name. */
21327 if (!NILP (f
->title
))
21328 return SSDATA (f
->title
);
21329 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21330 return SSDATA (f
->name
);
21334 obj
= BVAR (b
, filename
);
21339 ptrdiff_t size
= ZV
- BEGV
;
21340 pint2str (decode_mode_spec_buf
, width
, size
);
21341 return decode_mode_spec_buf
;
21346 ptrdiff_t size
= ZV
- BEGV
;
21347 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21348 return decode_mode_spec_buf
;
21353 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21354 ptrdiff_t topline
, nlines
, height
;
21357 /* %c and %l are ignored in `frame-title-format'. */
21358 if (mode_line_target
== MODE_LINE_TITLE
)
21361 startpos
= marker_position (w
->start
);
21362 startpos_byte
= marker_byte_position (w
->start
);
21363 height
= WINDOW_TOTAL_LINES (w
);
21365 /* If we decided that this buffer isn't suitable for line numbers,
21366 don't forget that too fast. */
21367 if (w
->base_line_pos
== -1)
21370 /* If the buffer is very big, don't waste time. */
21371 if (INTEGERP (Vline_number_display_limit
)
21372 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21374 w
->base_line_pos
= 0;
21375 w
->base_line_number
= 0;
21379 if (w
->base_line_number
> 0
21380 && w
->base_line_pos
> 0
21381 && w
->base_line_pos
<= startpos
)
21383 line
= w
->base_line_number
;
21384 linepos
= w
->base_line_pos
;
21385 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21390 linepos
= BUF_BEGV (b
);
21391 linepos_byte
= BUF_BEGV_BYTE (b
);
21394 /* Count lines from base line to window start position. */
21395 nlines
= display_count_lines (linepos_byte
,
21399 topline
= nlines
+ line
;
21401 /* Determine a new base line, if the old one is too close
21402 or too far away, or if we did not have one.
21403 "Too close" means it's plausible a scroll-down would
21404 go back past it. */
21405 if (startpos
== BUF_BEGV (b
))
21407 w
->base_line_number
= topline
;
21408 w
->base_line_pos
= BUF_BEGV (b
);
21410 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21411 || linepos
== BUF_BEGV (b
))
21413 ptrdiff_t limit
= BUF_BEGV (b
);
21414 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21415 ptrdiff_t position
;
21416 ptrdiff_t distance
=
21417 (height
* 2 + 30) * line_number_display_limit_width
;
21419 if (startpos
- distance
> limit
)
21421 limit
= startpos
- distance
;
21422 limit_byte
= CHAR_TO_BYTE (limit
);
21425 nlines
= display_count_lines (startpos_byte
,
21427 - (height
* 2 + 30),
21429 /* If we couldn't find the lines we wanted within
21430 line_number_display_limit_width chars per line,
21431 give up on line numbers for this window. */
21432 if (position
== limit_byte
&& limit
== startpos
- distance
)
21434 w
->base_line_pos
= -1;
21435 w
->base_line_number
= 0;
21439 w
->base_line_number
= topline
- nlines
;
21440 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21443 /* Now count lines from the start pos to point. */
21444 nlines
= display_count_lines (startpos_byte
,
21445 PT_BYTE
, PT
, &junk
);
21447 /* Record that we did display the line number. */
21448 line_number_displayed
= 1;
21450 /* Make the string to show. */
21451 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21452 return decode_mode_spec_buf
;
21455 char* p
= decode_mode_spec_buf
;
21456 int pad
= width
- 2;
21462 return decode_mode_spec_buf
;
21468 obj
= BVAR (b
, mode_name
);
21472 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21478 ptrdiff_t pos
= marker_position (w
->start
);
21479 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21481 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21483 if (pos
<= BUF_BEGV (b
))
21488 else if (pos
<= BUF_BEGV (b
))
21492 if (total
> 1000000)
21493 /* Do it differently for a large value, to avoid overflow. */
21494 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21496 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21497 /* We can't normally display a 3-digit number,
21498 so get us a 2-digit number that is close. */
21501 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21502 return decode_mode_spec_buf
;
21506 /* Display percentage of size above the bottom of the screen. */
21509 ptrdiff_t toppos
= marker_position (w
->start
);
21510 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21511 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21513 if (botpos
>= BUF_ZV (b
))
21515 if (toppos
<= BUF_BEGV (b
))
21522 if (total
> 1000000)
21523 /* Do it differently for a large value, to avoid overflow. */
21524 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21526 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21527 /* We can't normally display a 3-digit number,
21528 so get us a 2-digit number that is close. */
21531 if (toppos
<= BUF_BEGV (b
))
21532 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21534 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21535 return decode_mode_spec_buf
;
21540 /* status of process */
21541 obj
= Fget_buffer_process (Fcurrent_buffer ());
21543 return "no process";
21545 obj
= Fsymbol_name (Fprocess_status (obj
));
21551 ptrdiff_t count
= inhibit_garbage_collection ();
21552 Lisp_Object val
= call1 (intern ("file-remote-p"),
21553 BVAR (current_buffer
, directory
));
21554 unbind_to (count
, Qnil
);
21563 /* coding-system (not including end-of-line format) */
21565 /* coding-system (including end-of-line type) */
21567 int eol_flag
= (c
== 'Z');
21568 char *p
= decode_mode_spec_buf
;
21570 if (! FRAME_WINDOW_P (f
))
21572 /* No need to mention EOL here--the terminal never needs
21573 to do EOL conversion. */
21574 p
= decode_mode_spec_coding (CODING_ID_NAME
21575 (FRAME_KEYBOARD_CODING (f
)->id
),
21577 p
= decode_mode_spec_coding (CODING_ID_NAME
21578 (FRAME_TERMINAL_CODING (f
)->id
),
21581 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21584 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21585 #ifdef subprocesses
21586 obj
= Fget_buffer_process (Fcurrent_buffer ());
21587 if (PROCESSP (obj
))
21589 p
= decode_mode_spec_coding
21590 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21591 p
= decode_mode_spec_coding
21592 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21594 #endif /* subprocesses */
21597 return decode_mode_spec_buf
;
21604 return SSDATA (obj
);
21611 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
21612 means count lines back from START_BYTE. But don't go beyond
21613 LIMIT_BYTE. Return the number of lines thus found (always
21616 Set *BYTE_POS_PTR to the byte position where we stopped. This is
21617 either the position COUNT lines after/before START_BYTE, if we
21618 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
21622 display_count_lines (ptrdiff_t start_byte
,
21623 ptrdiff_t limit_byte
, ptrdiff_t count
,
21624 ptrdiff_t *byte_pos_ptr
)
21626 register unsigned char *cursor
;
21627 unsigned char *base
;
21629 register ptrdiff_t ceiling
;
21630 register unsigned char *ceiling_addr
;
21631 ptrdiff_t orig_count
= count
;
21633 /* If we are not in selective display mode,
21634 check only for newlines. */
21635 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21636 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21640 while (start_byte
< limit_byte
)
21642 ceiling
= BUFFER_CEILING_OF (start_byte
);
21643 ceiling
= min (limit_byte
- 1, ceiling
);
21644 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21645 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21649 if (selective_display
)
21651 while (*cursor
!= '\n' && *cursor
!= 015
21652 && ++cursor
!= ceiling_addr
)
21654 if (cursor
== ceiling_addr
)
21659 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
21668 start_byte
+= cursor
- base
;
21669 *byte_pos_ptr
= start_byte
;
21673 while (cursor
< ceiling_addr
);
21675 start_byte
+= ceiling_addr
- base
;
21680 while (start_byte
> limit_byte
)
21682 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21683 ceiling
= max (limit_byte
, ceiling
);
21684 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
21685 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21688 if (selective_display
)
21690 while (--cursor
>= ceiling_addr
21691 && *cursor
!= '\n' && *cursor
!= 015)
21693 if (cursor
< ceiling_addr
)
21698 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
21705 start_byte
+= cursor
- base
+ 1;
21706 *byte_pos_ptr
= start_byte
;
21707 /* When scanning backwards, we should
21708 not count the newline posterior to which we stop. */
21709 return - orig_count
- 1;
21712 start_byte
+= ceiling_addr
- base
;
21716 *byte_pos_ptr
= limit_byte
;
21719 return - orig_count
+ count
;
21720 return orig_count
- count
;
21726 /***********************************************************************
21728 ***********************************************************************/
21730 /* Display a NUL-terminated string, starting with index START.
21732 If STRING is non-null, display that C string. Otherwise, the Lisp
21733 string LISP_STRING is displayed. There's a case that STRING is
21734 non-null and LISP_STRING is not nil. It means STRING is a string
21735 data of LISP_STRING. In that case, we display LISP_STRING while
21736 ignoring its text properties.
21738 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21739 FACE_STRING. Display STRING or LISP_STRING with the face at
21740 FACE_STRING_POS in FACE_STRING:
21742 Display the string in the environment given by IT, but use the
21743 standard display table, temporarily.
21745 FIELD_WIDTH is the minimum number of output glyphs to produce.
21746 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21747 with spaces. If STRING has more characters, more than FIELD_WIDTH
21748 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21750 PRECISION is the maximum number of characters to output from
21751 STRING. PRECISION < 0 means don't truncate the string.
21753 This is roughly equivalent to printf format specifiers:
21755 FIELD_WIDTH PRECISION PRINTF
21756 ----------------------------------------
21762 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21763 display them, and < 0 means obey the current buffer's value of
21764 enable_multibyte_characters.
21766 Value is the number of columns displayed. */
21769 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21770 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21771 int field_width
, int precision
, int max_x
, int multibyte
)
21773 int hpos_at_start
= it
->hpos
;
21774 int saved_face_id
= it
->face_id
;
21775 struct glyph_row
*row
= it
->glyph_row
;
21776 ptrdiff_t it_charpos
;
21778 /* Initialize the iterator IT for iteration over STRING beginning
21779 with index START. */
21780 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21781 precision
, field_width
, multibyte
);
21782 if (string
&& STRINGP (lisp_string
))
21783 /* LISP_STRING is the one returned by decode_mode_spec. We should
21784 ignore its text properties. */
21785 it
->stop_charpos
= it
->end_charpos
;
21787 /* If displaying STRING, set up the face of the iterator from
21788 FACE_STRING, if that's given. */
21789 if (STRINGP (face_string
))
21795 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21796 0, it
->region_beg_charpos
,
21797 it
->region_end_charpos
,
21798 &endptr
, it
->base_face_id
, 0);
21799 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21800 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21803 /* Set max_x to the maximum allowed X position. Don't let it go
21804 beyond the right edge of the window. */
21806 max_x
= it
->last_visible_x
;
21808 max_x
= min (max_x
, it
->last_visible_x
);
21810 /* Skip over display elements that are not visible. because IT->w is
21812 if (it
->current_x
< it
->first_visible_x
)
21813 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21814 MOVE_TO_POS
| MOVE_TO_X
);
21816 row
->ascent
= it
->max_ascent
;
21817 row
->height
= it
->max_ascent
+ it
->max_descent
;
21818 row
->phys_ascent
= it
->max_phys_ascent
;
21819 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21820 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21822 if (STRINGP (it
->string
))
21823 it_charpos
= IT_STRING_CHARPOS (*it
);
21825 it_charpos
= IT_CHARPOS (*it
);
21827 /* This condition is for the case that we are called with current_x
21828 past last_visible_x. */
21829 while (it
->current_x
< max_x
)
21831 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21833 /* Get the next display element. */
21834 if (!get_next_display_element (it
))
21837 /* Produce glyphs. */
21838 x_before
= it
->current_x
;
21839 n_glyphs_before
= row
->used
[TEXT_AREA
];
21840 PRODUCE_GLYPHS (it
);
21842 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21845 while (i
< nglyphs
)
21847 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21849 if (it
->line_wrap
!= TRUNCATE
21850 && x
+ glyph
->pixel_width
> max_x
)
21852 /* End of continued line or max_x reached. */
21853 if (CHAR_GLYPH_PADDING_P (*glyph
))
21855 /* A wide character is unbreakable. */
21856 if (row
->reversed_p
)
21857 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21858 - n_glyphs_before
);
21859 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21860 it
->current_x
= x_before
;
21864 if (row
->reversed_p
)
21865 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21866 - (n_glyphs_before
+ i
));
21867 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21872 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21874 /* Glyph is at least partially visible. */
21876 if (x
< it
->first_visible_x
)
21877 row
->x
= x
- it
->first_visible_x
;
21881 /* Glyph is off the left margin of the display area.
21882 Should not happen. */
21886 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21887 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21888 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21889 row
->phys_height
= max (row
->phys_height
,
21890 it
->max_phys_ascent
+ it
->max_phys_descent
);
21891 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21892 it
->max_extra_line_spacing
);
21893 x
+= glyph
->pixel_width
;
21897 /* Stop if max_x reached. */
21901 /* Stop at line ends. */
21902 if (ITERATOR_AT_END_OF_LINE_P (it
))
21904 it
->continuation_lines_width
= 0;
21908 set_iterator_to_next (it
, 1);
21909 if (STRINGP (it
->string
))
21910 it_charpos
= IT_STRING_CHARPOS (*it
);
21912 it_charpos
= IT_CHARPOS (*it
);
21914 /* Stop if truncating at the right edge. */
21915 if (it
->line_wrap
== TRUNCATE
21916 && it
->current_x
>= it
->last_visible_x
)
21918 /* Add truncation mark, but don't do it if the line is
21919 truncated at a padding space. */
21920 if (it_charpos
< it
->string_nchars
)
21922 if (!FRAME_WINDOW_P (it
->f
))
21926 if (it
->current_x
> it
->last_visible_x
)
21928 if (!row
->reversed_p
)
21930 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21931 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21936 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21937 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21939 unproduce_glyphs (it
, ii
+ 1);
21940 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21942 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21944 row
->used
[TEXT_AREA
] = ii
;
21945 produce_special_glyphs (it
, IT_TRUNCATION
);
21948 produce_special_glyphs (it
, IT_TRUNCATION
);
21950 row
->truncated_on_right_p
= 1;
21956 /* Maybe insert a truncation at the left. */
21957 if (it
->first_visible_x
21960 if (!FRAME_WINDOW_P (it
->f
)
21961 || (row
->reversed_p
21962 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21963 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21964 insert_left_trunc_glyphs (it
);
21965 row
->truncated_on_left_p
= 1;
21968 it
->face_id
= saved_face_id
;
21970 /* Value is number of columns displayed. */
21971 return it
->hpos
- hpos_at_start
;
21976 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21977 appears as an element of LIST or as the car of an element of LIST.
21978 If PROPVAL is a list, compare each element against LIST in that
21979 way, and return 1/2 if any element of PROPVAL is found in LIST.
21980 Otherwise return 0. This function cannot quit.
21981 The return value is 2 if the text is invisible but with an ellipsis
21982 and 1 if it's invisible and without an ellipsis. */
21985 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21987 register Lisp_Object tail
, proptail
;
21989 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21991 register Lisp_Object tem
;
21993 if (EQ (propval
, tem
))
21995 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21996 return NILP (XCDR (tem
)) ? 1 : 2;
21999 if (CONSP (propval
))
22001 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22003 Lisp_Object propelt
;
22004 propelt
= XCAR (proptail
);
22005 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22007 register Lisp_Object tem
;
22009 if (EQ (propelt
, tem
))
22011 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22012 return NILP (XCDR (tem
)) ? 1 : 2;
22020 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22021 doc
: /* Non-nil if the property makes the text invisible.
22022 POS-OR-PROP can be a marker or number, in which case it is taken to be
22023 a position in the current buffer and the value of the `invisible' property
22024 is checked; or it can be some other value, which is then presumed to be the
22025 value of the `invisible' property of the text of interest.
22026 The non-nil value returned can be t for truly invisible text or something
22027 else if the text is replaced by an ellipsis. */)
22028 (Lisp_Object pos_or_prop
)
22031 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22032 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22034 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22035 return (invis
== 0 ? Qnil
22037 : make_number (invis
));
22040 /* Calculate a width or height in pixels from a specification using
22041 the following elements:
22044 NUM - a (fractional) multiple of the default font width/height
22045 (NUM) - specifies exactly NUM pixels
22046 UNIT - a fixed number of pixels, see below.
22047 ELEMENT - size of a display element in pixels, see below.
22048 (NUM . SPEC) - equals NUM * SPEC
22049 (+ SPEC SPEC ...) - add pixel values
22050 (- SPEC SPEC ...) - subtract pixel values
22051 (- SPEC) - negate pixel value
22054 INT or FLOAT - a number constant
22055 SYMBOL - use symbol's (buffer local) variable binding.
22058 in - pixels per inch *)
22059 mm - pixels per 1/1000 meter *)
22060 cm - pixels per 1/100 meter *)
22061 width - width of current font in pixels.
22062 height - height of current font in pixels.
22064 *) using the ratio(s) defined in display-pixels-per-inch.
22068 left-fringe - left fringe width in pixels
22069 right-fringe - right fringe width in pixels
22071 left-margin - left margin width in pixels
22072 right-margin - right margin width in pixels
22074 scroll-bar - scroll-bar area width in pixels
22078 Pixels corresponding to 5 inches:
22081 Total width of non-text areas on left side of window (if scroll-bar is on left):
22082 '(space :width (+ left-fringe left-margin scroll-bar))
22084 Align to first text column (in header line):
22085 '(space :align-to 0)
22087 Align to middle of text area minus half the width of variable `my-image'
22088 containing a loaded image:
22089 '(space :align-to (0.5 . (- text my-image)))
22091 Width of left margin minus width of 1 character in the default font:
22092 '(space :width (- left-margin 1))
22094 Width of left margin minus width of 2 characters in the current font:
22095 '(space :width (- left-margin (2 . width)))
22097 Center 1 character over left-margin (in header line):
22098 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22100 Different ways to express width of left fringe plus left margin minus one pixel:
22101 '(space :width (- (+ left-fringe left-margin) (1)))
22102 '(space :width (+ left-fringe left-margin (- (1))))
22103 '(space :width (+ left-fringe left-margin (-1)))
22108 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22109 struct font
*font
, int width_p
, int *align_to
)
22113 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22114 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22117 return OK_PIXELS (0);
22119 eassert (FRAME_LIVE_P (it
->f
));
22121 if (SYMBOLP (prop
))
22123 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22125 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22127 if (unit
[0] == 'i' && unit
[1] == 'n')
22129 else if (unit
[0] == 'm' && unit
[1] == 'm')
22131 else if (unit
[0] == 'c' && unit
[1] == 'm')
22137 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22138 : FRAME_RES_Y (it
->f
));
22141 return OK_PIXELS (ppi
/ pixels
);
22146 #ifdef HAVE_WINDOW_SYSTEM
22147 if (EQ (prop
, Qheight
))
22148 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22149 if (EQ (prop
, Qwidth
))
22150 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22152 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22153 return OK_PIXELS (1);
22156 if (EQ (prop
, Qtext
))
22157 return OK_PIXELS (width_p
22158 ? window_box_width (it
->w
, TEXT_AREA
)
22159 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22161 if (align_to
&& *align_to
< 0)
22164 if (EQ (prop
, Qleft
))
22165 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22166 if (EQ (prop
, Qright
))
22167 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22168 if (EQ (prop
, Qcenter
))
22169 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22170 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22171 if (EQ (prop
, Qleft_fringe
))
22172 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22173 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22174 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22175 if (EQ (prop
, Qright_fringe
))
22176 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22177 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22178 : window_box_right_offset (it
->w
, TEXT_AREA
));
22179 if (EQ (prop
, Qleft_margin
))
22180 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22181 if (EQ (prop
, Qright_margin
))
22182 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22183 if (EQ (prop
, Qscroll_bar
))
22184 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22186 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22187 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22188 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22193 if (EQ (prop
, Qleft_fringe
))
22194 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22195 if (EQ (prop
, Qright_fringe
))
22196 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22197 if (EQ (prop
, Qleft_margin
))
22198 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22199 if (EQ (prop
, Qright_margin
))
22200 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22201 if (EQ (prop
, Qscroll_bar
))
22202 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22205 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22206 if (EQ (prop
, Qunbound
))
22210 if (INTEGERP (prop
) || FLOATP (prop
))
22212 int base_unit
= (width_p
22213 ? FRAME_COLUMN_WIDTH (it
->f
)
22214 : FRAME_LINE_HEIGHT (it
->f
));
22215 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22220 Lisp_Object car
= XCAR (prop
);
22221 Lisp_Object cdr
= XCDR (prop
);
22225 #ifdef HAVE_WINDOW_SYSTEM
22226 if (FRAME_WINDOW_P (it
->f
)
22227 && valid_image_p (prop
))
22229 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22230 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22232 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22235 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22241 while (CONSP (cdr
))
22243 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22244 font
, width_p
, align_to
))
22247 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22252 if (EQ (car
, Qminus
))
22254 return OK_PIXELS (pixels
);
22257 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22258 if (EQ (car
, Qunbound
))
22262 if (INTEGERP (car
) || FLOATP (car
))
22265 pixels
= XFLOATINT (car
);
22267 return OK_PIXELS (pixels
);
22268 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22269 font
, width_p
, align_to
))
22270 return OK_PIXELS (pixels
* fact
);
22281 /***********************************************************************
22283 ***********************************************************************/
22285 #ifdef HAVE_WINDOW_SYSTEM
22290 dump_glyph_string (struct glyph_string
*s
)
22292 fprintf (stderr
, "glyph string\n");
22293 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22294 s
->x
, s
->y
, s
->width
, s
->height
);
22295 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22296 fprintf (stderr
, " hl = %d\n", s
->hl
);
22297 fprintf (stderr
, " left overhang = %d, right = %d\n",
22298 s
->left_overhang
, s
->right_overhang
);
22299 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22300 fprintf (stderr
, " extends to end of line = %d\n",
22301 s
->extends_to_end_of_line_p
);
22302 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22303 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22306 #endif /* GLYPH_DEBUG */
22308 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22309 of XChar2b structures for S; it can't be allocated in
22310 init_glyph_string because it must be allocated via `alloca'. W
22311 is the window on which S is drawn. ROW and AREA are the glyph row
22312 and area within the row from which S is constructed. START is the
22313 index of the first glyph structure covered by S. HL is a
22314 face-override for drawing S. */
22317 #define OPTIONAL_HDC(hdc) HDC hdc,
22318 #define DECLARE_HDC(hdc) HDC hdc;
22319 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22320 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22323 #ifndef OPTIONAL_HDC
22324 #define OPTIONAL_HDC(hdc)
22325 #define DECLARE_HDC(hdc)
22326 #define ALLOCATE_HDC(hdc, f)
22327 #define RELEASE_HDC(hdc, f)
22331 init_glyph_string (struct glyph_string
*s
,
22333 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22334 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22336 memset (s
, 0, sizeof *s
);
22338 s
->f
= XFRAME (w
->frame
);
22342 s
->display
= FRAME_X_DISPLAY (s
->f
);
22343 s
->window
= FRAME_X_WINDOW (s
->f
);
22344 s
->char2b
= char2b
;
22348 s
->first_glyph
= row
->glyphs
[area
] + start
;
22349 s
->height
= row
->height
;
22350 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22351 s
->ybase
= s
->y
+ row
->ascent
;
22355 /* Append the list of glyph strings with head H and tail T to the list
22356 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22359 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22360 struct glyph_string
*h
, struct glyph_string
*t
)
22374 /* Prepend the list of glyph strings with head H and tail T to the
22375 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22379 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22380 struct glyph_string
*h
, struct glyph_string
*t
)
22394 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22395 Set *HEAD and *TAIL to the resulting list. */
22398 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22399 struct glyph_string
*s
)
22401 s
->next
= s
->prev
= NULL
;
22402 append_glyph_string_lists (head
, tail
, s
, s
);
22406 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22407 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22408 make sure that X resources for the face returned are allocated.
22409 Value is a pointer to a realized face that is ready for display if
22410 DISPLAY_P is non-zero. */
22412 static struct face
*
22413 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22414 XChar2b
*char2b
, int display_p
)
22416 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22421 code
= face
->font
->driver
->encode_char (face
->font
, c
);
22423 if (code
== FONT_INVALID_CODE
)
22426 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22428 /* Make sure X resources of the face are allocated. */
22429 #ifdef HAVE_X_WINDOWS
22433 eassert (face
!= NULL
);
22434 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22441 /* Get face and two-byte form of character glyph GLYPH on frame F.
22442 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22443 a pointer to a realized face that is ready for display. */
22445 static struct face
*
22446 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22447 XChar2b
*char2b
, int *two_byte_p
)
22452 eassert (glyph
->type
== CHAR_GLYPH
);
22453 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22455 /* Make sure X resources of the face are allocated. */
22456 eassert (face
!= NULL
);
22457 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22464 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22465 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22467 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22469 if (code
== FONT_INVALID_CODE
)
22473 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22478 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22479 Return 1 if FONT has a glyph for C, otherwise return 0. */
22482 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22486 if (CHAR_BYTE8_P (c
))
22487 code
= CHAR_TO_BYTE8 (c
);
22489 code
= font
->driver
->encode_char (font
, c
);
22491 if (code
== FONT_INVALID_CODE
)
22493 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22498 /* Fill glyph string S with composition components specified by S->cmp.
22500 BASE_FACE is the base face of the composition.
22501 S->cmp_from is the index of the first component for S.
22503 OVERLAPS non-zero means S should draw the foreground only, and use
22504 its physical height for clipping. See also draw_glyphs.
22506 Value is the index of a component not in S. */
22509 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22513 /* For all glyphs of this composition, starting at the offset
22514 S->cmp_from, until we reach the end of the definition or encounter a
22515 glyph that requires the different face, add it to S. */
22520 s
->for_overlaps
= overlaps
;
22523 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22525 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22527 /* TAB in a composition means display glyphs with padding space
22528 on the left or right. */
22531 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22534 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22541 s
->font
= s
->face
->font
;
22543 else if (s
->face
!= face
)
22551 if (s
->face
== NULL
)
22553 s
->face
= base_face
->ascii_face
;
22554 s
->font
= s
->face
->font
;
22557 /* All glyph strings for the same composition has the same width,
22558 i.e. the width set for the first component of the composition. */
22559 s
->width
= s
->first_glyph
->pixel_width
;
22561 /* If the specified font could not be loaded, use the frame's
22562 default font, but record the fact that we couldn't load it in
22563 the glyph string so that we can draw rectangles for the
22564 characters of the glyph string. */
22565 if (s
->font
== NULL
)
22567 s
->font_not_found_p
= 1;
22568 s
->font
= FRAME_FONT (s
->f
);
22571 /* Adjust base line for subscript/superscript text. */
22572 s
->ybase
+= s
->first_glyph
->voffset
;
22574 /* This glyph string must always be drawn with 16-bit functions. */
22581 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22582 int start
, int end
, int overlaps
)
22584 struct glyph
*glyph
, *last
;
22585 Lisp_Object lgstring
;
22588 s
->for_overlaps
= overlaps
;
22589 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22590 last
= s
->row
->glyphs
[s
->area
] + end
;
22591 s
->cmp_id
= glyph
->u
.cmp
.id
;
22592 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22593 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22594 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22595 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22596 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22598 while (glyph
< last
22599 && glyph
->u
.cmp
.automatic
22600 && glyph
->u
.cmp
.id
== s
->cmp_id
22601 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22602 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22604 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22606 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22607 unsigned code
= LGLYPH_CODE (lglyph
);
22609 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22611 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22612 return glyph
- s
->row
->glyphs
[s
->area
];
22616 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22617 See the comment of fill_glyph_string for arguments.
22618 Value is the index of the first glyph not in S. */
22622 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22623 int start
, int end
, int overlaps
)
22625 struct glyph
*glyph
, *last
;
22628 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22629 s
->for_overlaps
= overlaps
;
22630 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22631 last
= s
->row
->glyphs
[s
->area
] + end
;
22632 voffset
= glyph
->voffset
;
22633 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22634 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22636 s
->width
= glyph
->pixel_width
;
22638 while (glyph
< last
22639 && glyph
->type
== GLYPHLESS_GLYPH
22640 && glyph
->voffset
== voffset
22641 && glyph
->face_id
== face_id
)
22644 s
->width
+= glyph
->pixel_width
;
22647 s
->ybase
+= voffset
;
22648 return glyph
- s
->row
->glyphs
[s
->area
];
22652 /* Fill glyph string S from a sequence of character glyphs.
22654 FACE_ID is the face id of the string. START is the index of the
22655 first glyph to consider, END is the index of the last + 1.
22656 OVERLAPS non-zero means S should draw the foreground only, and use
22657 its physical height for clipping. See also draw_glyphs.
22659 Value is the index of the first glyph not in S. */
22662 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22663 int start
, int end
, int overlaps
)
22665 struct glyph
*glyph
, *last
;
22667 int glyph_not_available_p
;
22669 eassert (s
->f
== XFRAME (s
->w
->frame
));
22670 eassert (s
->nchars
== 0);
22671 eassert (start
>= 0 && end
> start
);
22673 s
->for_overlaps
= overlaps
;
22674 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22675 last
= s
->row
->glyphs
[s
->area
] + end
;
22676 voffset
= glyph
->voffset
;
22677 s
->padding_p
= glyph
->padding_p
;
22678 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22680 while (glyph
< last
22681 && glyph
->type
== CHAR_GLYPH
22682 && glyph
->voffset
== voffset
22683 /* Same face id implies same font, nowadays. */
22684 && glyph
->face_id
== face_id
22685 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22689 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22690 s
->char2b
+ s
->nchars
,
22692 s
->two_byte_p
= two_byte_p
;
22694 eassert (s
->nchars
<= end
- start
);
22695 s
->width
+= glyph
->pixel_width
;
22696 if (glyph
++->padding_p
!= s
->padding_p
)
22700 s
->font
= s
->face
->font
;
22702 /* If the specified font could not be loaded, use the frame's font,
22703 but record the fact that we couldn't load it in
22704 S->font_not_found_p so that we can draw rectangles for the
22705 characters of the glyph string. */
22706 if (s
->font
== NULL
|| glyph_not_available_p
)
22708 s
->font_not_found_p
= 1;
22709 s
->font
= FRAME_FONT (s
->f
);
22712 /* Adjust base line for subscript/superscript text. */
22713 s
->ybase
+= voffset
;
22715 eassert (s
->face
&& s
->face
->gc
);
22716 return glyph
- s
->row
->glyphs
[s
->area
];
22720 /* Fill glyph string S from image glyph S->first_glyph. */
22723 fill_image_glyph_string (struct glyph_string
*s
)
22725 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22726 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22728 s
->slice
= s
->first_glyph
->slice
.img
;
22729 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22730 s
->font
= s
->face
->font
;
22731 s
->width
= s
->first_glyph
->pixel_width
;
22733 /* Adjust base line for subscript/superscript text. */
22734 s
->ybase
+= s
->first_glyph
->voffset
;
22738 /* Fill glyph string S from a sequence of stretch glyphs.
22740 START is the index of the first glyph to consider,
22741 END is the index of the last + 1.
22743 Value is the index of the first glyph not in S. */
22746 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22748 struct glyph
*glyph
, *last
;
22749 int voffset
, face_id
;
22751 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22753 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22754 last
= s
->row
->glyphs
[s
->area
] + end
;
22755 face_id
= glyph
->face_id
;
22756 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22757 s
->font
= s
->face
->font
;
22758 s
->width
= glyph
->pixel_width
;
22760 voffset
= glyph
->voffset
;
22764 && glyph
->type
== STRETCH_GLYPH
22765 && glyph
->voffset
== voffset
22766 && glyph
->face_id
== face_id
);
22768 s
->width
+= glyph
->pixel_width
;
22770 /* Adjust base line for subscript/superscript text. */
22771 s
->ybase
+= voffset
;
22773 /* The case that face->gc == 0 is handled when drawing the glyph
22774 string by calling PREPARE_FACE_FOR_DISPLAY. */
22776 return glyph
- s
->row
->glyphs
[s
->area
];
22779 static struct font_metrics
*
22780 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22782 static struct font_metrics metrics
;
22787 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22788 if (code
== FONT_INVALID_CODE
)
22790 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22795 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22796 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22797 assumed to be zero. */
22800 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22802 *left
= *right
= 0;
22804 if (glyph
->type
== CHAR_GLYPH
)
22808 struct font_metrics
*pcm
;
22810 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22811 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22813 if (pcm
->rbearing
> pcm
->width
)
22814 *right
= pcm
->rbearing
- pcm
->width
;
22815 if (pcm
->lbearing
< 0)
22816 *left
= -pcm
->lbearing
;
22819 else if (glyph
->type
== COMPOSITE_GLYPH
)
22821 if (! glyph
->u
.cmp
.automatic
)
22823 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22825 if (cmp
->rbearing
> cmp
->pixel_width
)
22826 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22827 if (cmp
->lbearing
< 0)
22828 *left
= - cmp
->lbearing
;
22832 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22833 struct font_metrics metrics
;
22835 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22836 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22837 if (metrics
.rbearing
> metrics
.width
)
22838 *right
= metrics
.rbearing
- metrics
.width
;
22839 if (metrics
.lbearing
< 0)
22840 *left
= - metrics
.lbearing
;
22846 /* Return the index of the first glyph preceding glyph string S that
22847 is overwritten by S because of S's left overhang. Value is -1
22848 if no glyphs are overwritten. */
22851 left_overwritten (struct glyph_string
*s
)
22855 if (s
->left_overhang
)
22858 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22859 int first
= s
->first_glyph
- glyphs
;
22861 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22862 x
-= glyphs
[i
].pixel_width
;
22873 /* Return the index of the first glyph preceding glyph string S that
22874 is overwriting S because of its right overhang. Value is -1 if no
22875 glyph in front of S overwrites S. */
22878 left_overwriting (struct glyph_string
*s
)
22881 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22882 int first
= s
->first_glyph
- glyphs
;
22886 for (i
= first
- 1; i
>= 0; --i
)
22889 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22892 x
-= glyphs
[i
].pixel_width
;
22899 /* Return the index of the last glyph following glyph string S that is
22900 overwritten by S because of S's right overhang. Value is -1 if
22901 no such glyph is found. */
22904 right_overwritten (struct glyph_string
*s
)
22908 if (s
->right_overhang
)
22911 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22912 int first
= (s
->first_glyph
- glyphs
22913 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22914 int end
= s
->row
->used
[s
->area
];
22916 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22917 x
+= glyphs
[i
].pixel_width
;
22926 /* Return the index of the last glyph following glyph string S that
22927 overwrites S because of its left overhang. Value is negative
22928 if no such glyph is found. */
22931 right_overwriting (struct glyph_string
*s
)
22934 int end
= s
->row
->used
[s
->area
];
22935 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22936 int first
= (s
->first_glyph
- glyphs
22937 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22941 for (i
= first
; i
< end
; ++i
)
22944 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22947 x
+= glyphs
[i
].pixel_width
;
22954 /* Set background width of glyph string S. START is the index of the
22955 first glyph following S. LAST_X is the right-most x-position + 1
22956 in the drawing area. */
22959 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22961 /* If the face of this glyph string has to be drawn to the end of
22962 the drawing area, set S->extends_to_end_of_line_p. */
22964 if (start
== s
->row
->used
[s
->area
]
22965 && s
->area
== TEXT_AREA
22966 && ((s
->row
->fill_line_p
22967 && (s
->hl
== DRAW_NORMAL_TEXT
22968 || s
->hl
== DRAW_IMAGE_RAISED
22969 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22970 || s
->hl
== DRAW_MOUSE_FACE
))
22971 s
->extends_to_end_of_line_p
= 1;
22973 /* If S extends its face to the end of the line, set its
22974 background_width to the distance to the right edge of the drawing
22976 if (s
->extends_to_end_of_line_p
)
22977 s
->background_width
= last_x
- s
->x
+ 1;
22979 s
->background_width
= s
->width
;
22983 /* Compute overhangs and x-positions for glyph string S and its
22984 predecessors, or successors. X is the starting x-position for S.
22985 BACKWARD_P non-zero means process predecessors. */
22988 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22994 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22995 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23005 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23006 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23016 /* The following macros are only called from draw_glyphs below.
23017 They reference the following parameters of that function directly:
23018 `w', `row', `area', and `overlap_p'
23019 as well as the following local variables:
23020 `s', `f', and `hdc' (in W32) */
23023 /* On W32, silently add local `hdc' variable to argument list of
23024 init_glyph_string. */
23025 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23026 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23028 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23029 init_glyph_string (s, char2b, w, row, area, start, hl)
23032 /* Add a glyph string for a stretch glyph to the list of strings
23033 between HEAD and TAIL. START is the index of the stretch glyph in
23034 row area AREA of glyph row ROW. END is the index of the last glyph
23035 in that glyph row area. X is the current output position assigned
23036 to the new glyph string constructed. HL overrides that face of the
23037 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23038 is the right-most x-position of the drawing area. */
23040 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23041 and below -- keep them on one line. */
23042 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23045 s = alloca (sizeof *s); \
23046 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23047 START = fill_stretch_glyph_string (s, START, END); \
23048 append_glyph_string (&HEAD, &TAIL, s); \
23054 /* Add a glyph string for an image glyph to the list of strings
23055 between HEAD and TAIL. START is the index of the image glyph in
23056 row area AREA of glyph row ROW. END is the index of the last glyph
23057 in that glyph row area. X is the current output position assigned
23058 to the new glyph string constructed. HL overrides that face of the
23059 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23060 is the right-most x-position of the drawing area. */
23062 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23065 s = alloca (sizeof *s); \
23066 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23067 fill_image_glyph_string (s); \
23068 append_glyph_string (&HEAD, &TAIL, s); \
23075 /* Add a glyph string for a sequence of character glyphs to the list
23076 of strings between HEAD and TAIL. START is the index of the first
23077 glyph in row area AREA of glyph row ROW that is part of the new
23078 glyph string. END is the index of the last glyph in that glyph row
23079 area. X is the current output position assigned to the new glyph
23080 string constructed. HL overrides that face of the glyph; e.g. it
23081 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23082 right-most x-position of the drawing area. */
23084 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23090 face_id = (row)->glyphs[area][START].face_id; \
23092 s = alloca (sizeof *s); \
23093 char2b = alloca ((END - START) * sizeof *char2b); \
23094 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23095 append_glyph_string (&HEAD, &TAIL, s); \
23097 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23102 /* Add a glyph string for a composite sequence to the list of strings
23103 between HEAD and TAIL. START is the index of the first glyph in
23104 row area AREA of glyph row ROW that is part of the new glyph
23105 string. END is the index of the last glyph in that glyph row area.
23106 X is the current output position assigned to the new glyph string
23107 constructed. HL overrides that face of the glyph; e.g. it is
23108 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23109 x-position of the drawing area. */
23111 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23113 int face_id = (row)->glyphs[area][START].face_id; \
23114 struct face *base_face = FACE_FROM_ID (f, face_id); \
23115 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23116 struct composition *cmp = composition_table[cmp_id]; \
23118 struct glyph_string *first_s = NULL; \
23121 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23123 /* Make glyph_strings for each glyph sequence that is drawable by \
23124 the same face, and append them to HEAD/TAIL. */ \
23125 for (n = 0; n < cmp->glyph_len;) \
23127 s = alloca (sizeof *s); \
23128 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23129 append_glyph_string (&(HEAD), &(TAIL), s); \
23135 n = fill_composite_glyph_string (s, base_face, overlaps); \
23143 /* Add a glyph string for a glyph-string sequence to the list of strings
23144 between HEAD and TAIL. */
23146 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23150 Lisp_Object gstring; \
23152 face_id = (row)->glyphs[area][START].face_id; \
23153 gstring = (composition_gstring_from_id \
23154 ((row)->glyphs[area][START].u.cmp.id)); \
23155 s = alloca (sizeof *s); \
23156 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23157 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23158 append_glyph_string (&(HEAD), &(TAIL), s); \
23160 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23164 /* Add a glyph string for a sequence of glyphless character's glyphs
23165 to the list of strings between HEAD and TAIL. The meanings of
23166 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23168 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23173 face_id = (row)->glyphs[area][START].face_id; \
23175 s = alloca (sizeof *s); \
23176 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23177 append_glyph_string (&HEAD, &TAIL, s); \
23179 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23185 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23186 of AREA of glyph row ROW on window W between indices START and END.
23187 HL overrides the face for drawing glyph strings, e.g. it is
23188 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23189 x-positions of the drawing area.
23191 This is an ugly monster macro construct because we must use alloca
23192 to allocate glyph strings (because draw_glyphs can be called
23193 asynchronously). */
23195 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23198 HEAD = TAIL = NULL; \
23199 while (START < END) \
23201 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23202 switch (first_glyph->type) \
23205 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23209 case COMPOSITE_GLYPH: \
23210 if (first_glyph->u.cmp.automatic) \
23211 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23214 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23218 case STRETCH_GLYPH: \
23219 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23223 case IMAGE_GLYPH: \
23224 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23228 case GLYPHLESS_GLYPH: \
23229 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23239 set_glyph_string_background_width (s, START, LAST_X); \
23246 /* Draw glyphs between START and END in AREA of ROW on window W,
23247 starting at x-position X. X is relative to AREA in W. HL is a
23248 face-override with the following meaning:
23250 DRAW_NORMAL_TEXT draw normally
23251 DRAW_CURSOR draw in cursor face
23252 DRAW_MOUSE_FACE draw in mouse face.
23253 DRAW_INVERSE_VIDEO draw in mode line face
23254 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23255 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23257 If OVERLAPS is non-zero, draw only the foreground of characters and
23258 clip to the physical height of ROW. Non-zero value also defines
23259 the overlapping part to be drawn:
23261 OVERLAPS_PRED overlap with preceding rows
23262 OVERLAPS_SUCC overlap with succeeding rows
23263 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23264 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23266 Value is the x-position reached, relative to AREA of W. */
23269 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23270 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23271 enum draw_glyphs_face hl
, int overlaps
)
23273 struct glyph_string
*head
, *tail
;
23274 struct glyph_string
*s
;
23275 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23276 int i
, j
, x_reached
, last_x
, area_left
= 0;
23277 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23280 ALLOCATE_HDC (hdc
, f
);
23282 /* Let's rather be paranoid than getting a SEGV. */
23283 end
= min (end
, row
->used
[area
]);
23284 start
= clip_to_bounds (0, start
, end
);
23286 /* Translate X to frame coordinates. Set last_x to the right
23287 end of the drawing area. */
23288 if (row
->full_width_p
)
23290 /* X is relative to the left edge of W, without scroll bars
23292 area_left
= WINDOW_LEFT_EDGE_X (w
);
23293 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23297 area_left
= window_box_left (w
, area
);
23298 last_x
= area_left
+ window_box_width (w
, area
);
23302 /* Build a doubly-linked list of glyph_string structures between
23303 head and tail from what we have to draw. Note that the macro
23304 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23305 the reason we use a separate variable `i'. */
23307 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23309 x_reached
= tail
->x
+ tail
->background_width
;
23313 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23314 the row, redraw some glyphs in front or following the glyph
23315 strings built above. */
23316 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23318 struct glyph_string
*h
, *t
;
23319 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23320 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23321 int check_mouse_face
= 0;
23324 /* If mouse highlighting is on, we may need to draw adjacent
23325 glyphs using mouse-face highlighting. */
23326 if (area
== TEXT_AREA
&& row
->mouse_face_p
23327 && hlinfo
->mouse_face_beg_row
>= 0
23328 && hlinfo
->mouse_face_end_row
>= 0)
23330 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23332 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23333 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23335 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23337 check_mouse_face
= 1;
23338 mouse_beg_col
= (row
== mouse_beg_row
)
23339 ? hlinfo
->mouse_face_beg_col
: 0;
23340 mouse_end_col
= (row
== mouse_end_row
)
23341 ? hlinfo
->mouse_face_end_col
23342 : row
->used
[TEXT_AREA
];
23346 /* Compute overhangs for all glyph strings. */
23347 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23348 for (s
= head
; s
; s
= s
->next
)
23349 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23351 /* Prepend glyph strings for glyphs in front of the first glyph
23352 string that are overwritten because of the first glyph
23353 string's left overhang. The background of all strings
23354 prepended must be drawn because the first glyph string
23356 i
= left_overwritten (head
);
23359 enum draw_glyphs_face overlap_hl
;
23361 /* If this row contains mouse highlighting, attempt to draw
23362 the overlapped glyphs with the correct highlight. This
23363 code fails if the overlap encompasses more than one glyph
23364 and mouse-highlight spans only some of these glyphs.
23365 However, making it work perfectly involves a lot more
23366 code, and I don't know if the pathological case occurs in
23367 practice, so we'll stick to this for now. --- cyd */
23368 if (check_mouse_face
23369 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23370 overlap_hl
= DRAW_MOUSE_FACE
;
23372 overlap_hl
= DRAW_NORMAL_TEXT
;
23375 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23376 overlap_hl
, dummy_x
, last_x
);
23378 compute_overhangs_and_x (t
, head
->x
, 1);
23379 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23383 /* Prepend glyph strings for glyphs in front of the first glyph
23384 string that overwrite that glyph string because of their
23385 right overhang. For these strings, only the foreground must
23386 be drawn, because it draws over the glyph string at `head'.
23387 The background must not be drawn because this would overwrite
23388 right overhangs of preceding glyphs for which no glyph
23390 i
= left_overwriting (head
);
23393 enum draw_glyphs_face overlap_hl
;
23395 if (check_mouse_face
23396 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23397 overlap_hl
= DRAW_MOUSE_FACE
;
23399 overlap_hl
= DRAW_NORMAL_TEXT
;
23402 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23403 overlap_hl
, dummy_x
, last_x
);
23404 for (s
= h
; s
; s
= s
->next
)
23405 s
->background_filled_p
= 1;
23406 compute_overhangs_and_x (t
, head
->x
, 1);
23407 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23410 /* Append glyphs strings for glyphs following the last glyph
23411 string tail that are overwritten by tail. The background of
23412 these strings has to be drawn because tail's foreground draws
23414 i
= right_overwritten (tail
);
23417 enum draw_glyphs_face overlap_hl
;
23419 if (check_mouse_face
23420 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23421 overlap_hl
= DRAW_MOUSE_FACE
;
23423 overlap_hl
= DRAW_NORMAL_TEXT
;
23425 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23426 overlap_hl
, x
, last_x
);
23427 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23428 we don't have `end = i;' here. */
23429 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23430 append_glyph_string_lists (&head
, &tail
, h
, t
);
23434 /* Append glyph strings for glyphs following the last glyph
23435 string tail that overwrite tail. The foreground of such
23436 glyphs has to be drawn because it writes into the background
23437 of tail. The background must not be drawn because it could
23438 paint over the foreground of following glyphs. */
23439 i
= right_overwriting (tail
);
23442 enum draw_glyphs_face overlap_hl
;
23443 if (check_mouse_face
23444 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23445 overlap_hl
= DRAW_MOUSE_FACE
;
23447 overlap_hl
= DRAW_NORMAL_TEXT
;
23450 i
++; /* We must include the Ith glyph. */
23451 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23452 overlap_hl
, x
, last_x
);
23453 for (s
= h
; s
; s
= s
->next
)
23454 s
->background_filled_p
= 1;
23455 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23456 append_glyph_string_lists (&head
, &tail
, h
, t
);
23458 if (clip_head
|| clip_tail
)
23459 for (s
= head
; s
; s
= s
->next
)
23461 s
->clip_head
= clip_head
;
23462 s
->clip_tail
= clip_tail
;
23466 /* Draw all strings. */
23467 for (s
= head
; s
; s
= s
->next
)
23468 FRAME_RIF (f
)->draw_glyph_string (s
);
23471 /* When focus a sole frame and move horizontally, this sets on_p to 0
23472 causing a failure to erase prev cursor position. */
23473 if (area
== TEXT_AREA
23474 && !row
->full_width_p
23475 /* When drawing overlapping rows, only the glyph strings'
23476 foreground is drawn, which doesn't erase a cursor
23480 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23481 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23482 : (tail
? tail
->x
+ tail
->background_width
: x
));
23486 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23487 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23491 /* Value is the x-position up to which drawn, relative to AREA of W.
23492 This doesn't include parts drawn because of overhangs. */
23493 if (row
->full_width_p
)
23494 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23496 x_reached
-= area_left
;
23498 RELEASE_HDC (hdc
, f
);
23503 /* Expand row matrix if too narrow. Don't expand if area
23506 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23508 if (!fonts_changed_p \
23509 && (it->glyph_row->glyphs[area] \
23510 < it->glyph_row->glyphs[area + 1])) \
23512 it->w->ncols_scale_factor++; \
23513 fonts_changed_p = 1; \
23517 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23518 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23521 append_glyph (struct it
*it
)
23523 struct glyph
*glyph
;
23524 enum glyph_row_area area
= it
->area
;
23526 eassert (it
->glyph_row
);
23527 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23529 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23530 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23532 /* If the glyph row is reversed, we need to prepend the glyph
23533 rather than append it. */
23534 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23538 /* Make room for the additional glyph. */
23539 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23541 glyph
= it
->glyph_row
->glyphs
[area
];
23543 glyph
->charpos
= CHARPOS (it
->position
);
23544 glyph
->object
= it
->object
;
23545 if (it
->pixel_width
> 0)
23547 glyph
->pixel_width
= it
->pixel_width
;
23548 glyph
->padding_p
= 0;
23552 /* Assure at least 1-pixel width. Otherwise, cursor can't
23553 be displayed correctly. */
23554 glyph
->pixel_width
= 1;
23555 glyph
->padding_p
= 1;
23557 glyph
->ascent
= it
->ascent
;
23558 glyph
->descent
= it
->descent
;
23559 glyph
->voffset
= it
->voffset
;
23560 glyph
->type
= CHAR_GLYPH
;
23561 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23562 glyph
->multibyte_p
= it
->multibyte_p
;
23563 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23565 /* In R2L rows, the left and the right box edges need to be
23566 drawn in reverse direction. */
23567 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23568 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23572 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23573 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23575 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23576 || it
->phys_descent
> it
->descent
);
23577 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23578 glyph
->face_id
= it
->face_id
;
23579 glyph
->u
.ch
= it
->char_to_display
;
23580 glyph
->slice
.img
= null_glyph_slice
;
23581 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23584 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23585 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23587 glyph
->bidi_type
= it
->bidi_it
.type
;
23591 glyph
->resolved_level
= 0;
23592 glyph
->bidi_type
= UNKNOWN_BT
;
23594 ++it
->glyph_row
->used
[area
];
23597 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23600 /* Store one glyph for the composition IT->cmp_it.id in
23601 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23605 append_composite_glyph (struct it
*it
)
23607 struct glyph
*glyph
;
23608 enum glyph_row_area area
= it
->area
;
23610 eassert (it
->glyph_row
);
23612 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23613 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23615 /* If the glyph row is reversed, we need to prepend the glyph
23616 rather than append it. */
23617 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23621 /* Make room for the new glyph. */
23622 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23624 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23626 glyph
->charpos
= it
->cmp_it
.charpos
;
23627 glyph
->object
= it
->object
;
23628 glyph
->pixel_width
= it
->pixel_width
;
23629 glyph
->ascent
= it
->ascent
;
23630 glyph
->descent
= it
->descent
;
23631 glyph
->voffset
= it
->voffset
;
23632 glyph
->type
= COMPOSITE_GLYPH
;
23633 if (it
->cmp_it
.ch
< 0)
23635 glyph
->u
.cmp
.automatic
= 0;
23636 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23637 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23641 glyph
->u
.cmp
.automatic
= 1;
23642 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23643 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23644 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23646 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23647 glyph
->multibyte_p
= it
->multibyte_p
;
23648 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23650 /* In R2L rows, the left and the right box edges need to be
23651 drawn in reverse direction. */
23652 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23653 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23657 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23658 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23660 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23661 || it
->phys_descent
> it
->descent
);
23662 glyph
->padding_p
= 0;
23663 glyph
->glyph_not_available_p
= 0;
23664 glyph
->face_id
= it
->face_id
;
23665 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23668 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23669 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23671 glyph
->bidi_type
= it
->bidi_it
.type
;
23673 ++it
->glyph_row
->used
[area
];
23676 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23680 /* Change IT->ascent and IT->height according to the setting of
23684 take_vertical_position_into_account (struct it
*it
)
23688 if (it
->voffset
< 0)
23689 /* Increase the ascent so that we can display the text higher
23691 it
->ascent
-= it
->voffset
;
23693 /* Increase the descent so that we can display the text lower
23695 it
->descent
+= it
->voffset
;
23700 /* Produce glyphs/get display metrics for the image IT is loaded with.
23701 See the description of struct display_iterator in dispextern.h for
23702 an overview of struct display_iterator. */
23705 produce_image_glyph (struct it
*it
)
23709 int glyph_ascent
, crop
;
23710 struct glyph_slice slice
;
23712 eassert (it
->what
== IT_IMAGE
);
23714 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23716 /* Make sure X resources of the face is loaded. */
23717 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23719 if (it
->image_id
< 0)
23721 /* Fringe bitmap. */
23722 it
->ascent
= it
->phys_ascent
= 0;
23723 it
->descent
= it
->phys_descent
= 0;
23724 it
->pixel_width
= 0;
23729 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23731 /* Make sure X resources of the image is loaded. */
23732 prepare_image_for_display (it
->f
, img
);
23734 slice
.x
= slice
.y
= 0;
23735 slice
.width
= img
->width
;
23736 slice
.height
= img
->height
;
23738 if (INTEGERP (it
->slice
.x
))
23739 slice
.x
= XINT (it
->slice
.x
);
23740 else if (FLOATP (it
->slice
.x
))
23741 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23743 if (INTEGERP (it
->slice
.y
))
23744 slice
.y
= XINT (it
->slice
.y
);
23745 else if (FLOATP (it
->slice
.y
))
23746 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23748 if (INTEGERP (it
->slice
.width
))
23749 slice
.width
= XINT (it
->slice
.width
);
23750 else if (FLOATP (it
->slice
.width
))
23751 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23753 if (INTEGERP (it
->slice
.height
))
23754 slice
.height
= XINT (it
->slice
.height
);
23755 else if (FLOATP (it
->slice
.height
))
23756 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23758 if (slice
.x
>= img
->width
)
23759 slice
.x
= img
->width
;
23760 if (slice
.y
>= img
->height
)
23761 slice
.y
= img
->height
;
23762 if (slice
.x
+ slice
.width
>= img
->width
)
23763 slice
.width
= img
->width
- slice
.x
;
23764 if (slice
.y
+ slice
.height
> img
->height
)
23765 slice
.height
= img
->height
- slice
.y
;
23767 if (slice
.width
== 0 || slice
.height
== 0)
23770 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23772 it
->descent
= slice
.height
- glyph_ascent
;
23774 it
->descent
+= img
->vmargin
;
23775 if (slice
.y
+ slice
.height
== img
->height
)
23776 it
->descent
+= img
->vmargin
;
23777 it
->phys_descent
= it
->descent
;
23779 it
->pixel_width
= slice
.width
;
23781 it
->pixel_width
+= img
->hmargin
;
23782 if (slice
.x
+ slice
.width
== img
->width
)
23783 it
->pixel_width
+= img
->hmargin
;
23785 /* It's quite possible for images to have an ascent greater than
23786 their height, so don't get confused in that case. */
23787 if (it
->descent
< 0)
23792 if (face
->box
!= FACE_NO_BOX
)
23794 if (face
->box_line_width
> 0)
23797 it
->ascent
+= face
->box_line_width
;
23798 if (slice
.y
+ slice
.height
== img
->height
)
23799 it
->descent
+= face
->box_line_width
;
23802 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23803 it
->pixel_width
+= eabs (face
->box_line_width
);
23804 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23805 it
->pixel_width
+= eabs (face
->box_line_width
);
23808 take_vertical_position_into_account (it
);
23810 /* Automatically crop wide image glyphs at right edge so we can
23811 draw the cursor on same display row. */
23812 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23813 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23815 it
->pixel_width
-= crop
;
23816 slice
.width
-= crop
;
23821 struct glyph
*glyph
;
23822 enum glyph_row_area area
= it
->area
;
23824 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23825 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23827 glyph
->charpos
= CHARPOS (it
->position
);
23828 glyph
->object
= it
->object
;
23829 glyph
->pixel_width
= it
->pixel_width
;
23830 glyph
->ascent
= glyph_ascent
;
23831 glyph
->descent
= it
->descent
;
23832 glyph
->voffset
= it
->voffset
;
23833 glyph
->type
= IMAGE_GLYPH
;
23834 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23835 glyph
->multibyte_p
= it
->multibyte_p
;
23836 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23838 /* In R2L rows, the left and the right box edges need to be
23839 drawn in reverse direction. */
23840 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23841 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23845 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23846 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23848 glyph
->overlaps_vertically_p
= 0;
23849 glyph
->padding_p
= 0;
23850 glyph
->glyph_not_available_p
= 0;
23851 glyph
->face_id
= it
->face_id
;
23852 glyph
->u
.img_id
= img
->id
;
23853 glyph
->slice
.img
= slice
;
23854 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23857 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23858 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23860 glyph
->bidi_type
= it
->bidi_it
.type
;
23862 ++it
->glyph_row
->used
[area
];
23865 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23870 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23871 of the glyph, WIDTH and HEIGHT are the width and height of the
23872 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23875 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23876 int width
, int height
, int ascent
)
23878 struct glyph
*glyph
;
23879 enum glyph_row_area area
= it
->area
;
23881 eassert (ascent
>= 0 && ascent
<= height
);
23883 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23884 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23886 /* If the glyph row is reversed, we need to prepend the glyph
23887 rather than append it. */
23888 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23892 /* Make room for the additional glyph. */
23893 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23895 glyph
= it
->glyph_row
->glyphs
[area
];
23897 glyph
->charpos
= CHARPOS (it
->position
);
23898 glyph
->object
= object
;
23899 glyph
->pixel_width
= width
;
23900 glyph
->ascent
= ascent
;
23901 glyph
->descent
= height
- ascent
;
23902 glyph
->voffset
= it
->voffset
;
23903 glyph
->type
= STRETCH_GLYPH
;
23904 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23905 glyph
->multibyte_p
= it
->multibyte_p
;
23906 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23908 /* In R2L rows, the left and the right box edges need to be
23909 drawn in reverse direction. */
23910 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23911 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23915 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23916 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23918 glyph
->overlaps_vertically_p
= 0;
23919 glyph
->padding_p
= 0;
23920 glyph
->glyph_not_available_p
= 0;
23921 glyph
->face_id
= it
->face_id
;
23922 glyph
->u
.stretch
.ascent
= ascent
;
23923 glyph
->u
.stretch
.height
= height
;
23924 glyph
->slice
.img
= null_glyph_slice
;
23925 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23928 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23929 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23931 glyph
->bidi_type
= it
->bidi_it
.type
;
23935 glyph
->resolved_level
= 0;
23936 glyph
->bidi_type
= UNKNOWN_BT
;
23938 ++it
->glyph_row
->used
[area
];
23941 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23944 #endif /* HAVE_WINDOW_SYSTEM */
23946 /* Produce a stretch glyph for iterator IT. IT->object is the value
23947 of the glyph property displayed. The value must be a list
23948 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23951 1. `:width WIDTH' specifies that the space should be WIDTH *
23952 canonical char width wide. WIDTH may be an integer or floating
23955 2. `:relative-width FACTOR' specifies that the width of the stretch
23956 should be computed from the width of the first character having the
23957 `glyph' property, and should be FACTOR times that width.
23959 3. `:align-to HPOS' specifies that the space should be wide enough
23960 to reach HPOS, a value in canonical character units.
23962 Exactly one of the above pairs must be present.
23964 4. `:height HEIGHT' specifies that the height of the stretch produced
23965 should be HEIGHT, measured in canonical character units.
23967 5. `:relative-height FACTOR' specifies that the height of the
23968 stretch should be FACTOR times the height of the characters having
23969 the glyph property.
23971 Either none or exactly one of 4 or 5 must be present.
23973 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23974 of the stretch should be used for the ascent of the stretch.
23975 ASCENT must be in the range 0 <= ASCENT <= 100. */
23978 produce_stretch_glyph (struct it
*it
)
23980 /* (space :width WIDTH :height HEIGHT ...) */
23981 Lisp_Object prop
, plist
;
23982 int width
= 0, height
= 0, align_to
= -1;
23983 int zero_width_ok_p
= 0;
23985 struct font
*font
= NULL
;
23987 #ifdef HAVE_WINDOW_SYSTEM
23989 int zero_height_ok_p
= 0;
23991 if (FRAME_WINDOW_P (it
->f
))
23993 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23994 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23995 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23999 /* List should start with `space'. */
24000 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24001 plist
= XCDR (it
->object
);
24003 /* Compute the width of the stretch. */
24004 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24005 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24007 /* Absolute width `:width WIDTH' specified and valid. */
24008 zero_width_ok_p
= 1;
24011 #ifdef HAVE_WINDOW_SYSTEM
24012 else if (FRAME_WINDOW_P (it
->f
)
24013 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24015 /* Relative width `:relative-width FACTOR' specified and valid.
24016 Compute the width of the characters having the `glyph'
24019 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24022 if (it
->multibyte_p
)
24023 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24026 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24027 if (! ASCII_CHAR_P (it2
.c
))
24028 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24031 it2
.glyph_row
= NULL
;
24032 it2
.what
= IT_CHARACTER
;
24033 x_produce_glyphs (&it2
);
24034 width
= NUMVAL (prop
) * it2
.pixel_width
;
24036 #endif /* HAVE_WINDOW_SYSTEM */
24037 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24038 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24040 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24041 align_to
= (align_to
< 0
24043 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24044 else if (align_to
< 0)
24045 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24046 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24047 zero_width_ok_p
= 1;
24050 /* Nothing specified -> width defaults to canonical char width. */
24051 width
= FRAME_COLUMN_WIDTH (it
->f
);
24053 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24056 #ifdef HAVE_WINDOW_SYSTEM
24057 /* Compute height. */
24058 if (FRAME_WINDOW_P (it
->f
))
24060 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24061 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24064 zero_height_ok_p
= 1;
24066 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24068 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24070 height
= FONT_HEIGHT (font
);
24072 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24075 /* Compute percentage of height used for ascent. If
24076 `:ascent ASCENT' is present and valid, use that. Otherwise,
24077 derive the ascent from the font in use. */
24078 if (prop
= Fplist_get (plist
, QCascent
),
24079 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24080 ascent
= height
* NUMVAL (prop
) / 100.0;
24081 else if (!NILP (prop
)
24082 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24083 ascent
= min (max (0, (int)tem
), height
);
24085 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24088 #endif /* HAVE_WINDOW_SYSTEM */
24091 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24092 && it
->current_x
+ width
> it
->last_visible_x
)
24094 width
= it
->last_visible_x
- it
->current_x
;
24095 #ifdef HAVE_WINDOW_SYSTEM
24096 /* Subtract one more pixel from the stretch width, but only on
24097 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24098 width
-= FRAME_WINDOW_P (it
->f
);
24102 if (width
> 0 && height
> 0 && it
->glyph_row
)
24104 Lisp_Object o_object
= it
->object
;
24105 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24108 if (!STRINGP (object
))
24109 object
= it
->w
->contents
;
24110 #ifdef HAVE_WINDOW_SYSTEM
24111 if (FRAME_WINDOW_P (it
->f
))
24112 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24116 it
->object
= object
;
24117 it
->char_to_display
= ' ';
24118 it
->pixel_width
= it
->len
= 1;
24120 tty_append_glyph (it
);
24121 it
->object
= o_object
;
24125 it
->pixel_width
= width
;
24126 #ifdef HAVE_WINDOW_SYSTEM
24127 if (FRAME_WINDOW_P (it
->f
))
24129 it
->ascent
= it
->phys_ascent
= ascent
;
24130 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24131 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24132 take_vertical_position_into_account (it
);
24136 it
->nglyphs
= width
;
24139 /* Get information about special display element WHAT in an
24140 environment described by IT. WHAT is one of IT_TRUNCATION or
24141 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24142 non-null glyph_row member. This function ensures that fields like
24143 face_id, c, len of IT are left untouched. */
24146 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24153 temp_it
.object
= make_number (0);
24154 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24156 if (what
== IT_CONTINUATION
)
24158 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24159 if (it
->bidi_it
.paragraph_dir
== R2L
)
24160 SET_GLYPH_FROM_CHAR (glyph
, '/');
24162 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24164 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24166 /* FIXME: Should we mirror GC for R2L lines? */
24167 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24168 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24171 else if (what
== IT_TRUNCATION
)
24173 /* Truncation glyph. */
24174 SET_GLYPH_FROM_CHAR (glyph
, '$');
24176 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24178 /* FIXME: Should we mirror GC for R2L lines? */
24179 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24180 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24186 #ifdef HAVE_WINDOW_SYSTEM
24187 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24188 is turned off, we precede the truncation/continuation glyphs by a
24189 stretch glyph whose width is computed such that these special
24190 glyphs are aligned at the window margin, even when very different
24191 fonts are used in different glyph rows. */
24192 if (FRAME_WINDOW_P (temp_it
.f
)
24193 /* init_iterator calls this with it->glyph_row == NULL, and it
24194 wants only the pixel width of the truncation/continuation
24196 && temp_it
.glyph_row
24197 /* insert_left_trunc_glyphs calls us at the beginning of the
24198 row, and it has its own calculation of the stretch glyph
24200 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24201 && (temp_it
.glyph_row
->reversed_p
24202 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24203 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24205 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24207 if (stretch_width
> 0)
24209 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24210 struct font
*font
=
24211 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24212 int stretch_ascent
=
24213 (((temp_it
.ascent
+ temp_it
.descent
)
24214 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24216 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24217 temp_it
.ascent
+ temp_it
.descent
,
24224 temp_it
.what
= IT_CHARACTER
;
24226 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24227 temp_it
.face_id
= GLYPH_FACE (glyph
);
24228 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24230 PRODUCE_GLYPHS (&temp_it
);
24231 it
->pixel_width
= temp_it
.pixel_width
;
24232 it
->nglyphs
= temp_it
.pixel_width
;
24235 #ifdef HAVE_WINDOW_SYSTEM
24237 /* Calculate line-height and line-spacing properties.
24238 An integer value specifies explicit pixel value.
24239 A float value specifies relative value to current face height.
24240 A cons (float . face-name) specifies relative value to
24241 height of specified face font.
24243 Returns height in pixels, or nil. */
24247 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24248 int boff
, int override
)
24250 Lisp_Object face_name
= Qnil
;
24251 int ascent
, descent
, height
;
24253 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24258 face_name
= XCAR (val
);
24260 if (!NUMBERP (val
))
24261 val
= make_number (1);
24262 if (NILP (face_name
))
24264 height
= it
->ascent
+ it
->descent
;
24269 if (NILP (face_name
))
24271 font
= FRAME_FONT (it
->f
);
24272 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24274 else if (EQ (face_name
, Qt
))
24283 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24285 return make_number (-1);
24287 face
= FACE_FROM_ID (it
->f
, face_id
);
24290 return make_number (-1);
24291 boff
= font
->baseline_offset
;
24292 if (font
->vertical_centering
)
24293 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24296 ascent
= FONT_BASE (font
) + boff
;
24297 descent
= FONT_DESCENT (font
) - boff
;
24301 it
->override_ascent
= ascent
;
24302 it
->override_descent
= descent
;
24303 it
->override_boff
= boff
;
24306 height
= ascent
+ descent
;
24310 height
= (int)(XFLOAT_DATA (val
) * height
);
24311 else if (INTEGERP (val
))
24312 height
*= XINT (val
);
24314 return make_number (height
);
24318 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24319 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24320 and only if this is for a character for which no font was found.
24322 If the display method (it->glyphless_method) is
24323 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24324 length of the acronym or the hexadecimal string, UPPER_XOFF and
24325 UPPER_YOFF are pixel offsets for the upper part of the string,
24326 LOWER_XOFF and LOWER_YOFF are for the lower part.
24328 For the other display methods, LEN through LOWER_YOFF are zero. */
24331 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24332 short upper_xoff
, short upper_yoff
,
24333 short lower_xoff
, short lower_yoff
)
24335 struct glyph
*glyph
;
24336 enum glyph_row_area area
= it
->area
;
24338 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24339 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24341 /* If the glyph row is reversed, we need to prepend the glyph
24342 rather than append it. */
24343 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24347 /* Make room for the additional glyph. */
24348 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24350 glyph
= it
->glyph_row
->glyphs
[area
];
24352 glyph
->charpos
= CHARPOS (it
->position
);
24353 glyph
->object
= it
->object
;
24354 glyph
->pixel_width
= it
->pixel_width
;
24355 glyph
->ascent
= it
->ascent
;
24356 glyph
->descent
= it
->descent
;
24357 glyph
->voffset
= it
->voffset
;
24358 glyph
->type
= GLYPHLESS_GLYPH
;
24359 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24360 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24361 glyph
->u
.glyphless
.len
= len
;
24362 glyph
->u
.glyphless
.ch
= it
->c
;
24363 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24364 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24365 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24366 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24367 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24368 glyph
->multibyte_p
= it
->multibyte_p
;
24369 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24371 /* In R2L rows, the left and the right box edges need to be
24372 drawn in reverse direction. */
24373 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24374 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24378 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24379 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24381 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24382 || it
->phys_descent
> it
->descent
);
24383 glyph
->padding_p
= 0;
24384 glyph
->glyph_not_available_p
= 0;
24385 glyph
->face_id
= face_id
;
24386 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24389 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24390 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24392 glyph
->bidi_type
= it
->bidi_it
.type
;
24394 ++it
->glyph_row
->used
[area
];
24397 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24401 /* Produce a glyph for a glyphless character for iterator IT.
24402 IT->glyphless_method specifies which method to use for displaying
24403 the character. See the description of enum
24404 glyphless_display_method in dispextern.h for the detail.
24406 FOR_NO_FONT is nonzero if and only if this is for a character for
24407 which no font was found. ACRONYM, if non-nil, is an acronym string
24408 for the character. */
24411 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24416 int base_width
, base_height
, width
, height
;
24417 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24420 /* Get the metrics of the base font. We always refer to the current
24422 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24423 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24424 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24425 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24426 base_height
= it
->ascent
+ it
->descent
;
24427 base_width
= font
->average_width
;
24429 /* Get a face ID for the glyph by utilizing a cache (the same way as
24430 done for `escape-glyph' in get_next_display_element). */
24431 if (it
->f
== last_glyphless_glyph_frame
24432 && it
->face_id
== last_glyphless_glyph_face_id
)
24434 face_id
= last_glyphless_glyph_merged_face_id
;
24438 /* Merge the `glyphless-char' face into the current face. */
24439 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24440 last_glyphless_glyph_frame
= it
->f
;
24441 last_glyphless_glyph_face_id
= it
->face_id
;
24442 last_glyphless_glyph_merged_face_id
= face_id
;
24445 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24447 it
->pixel_width
= THIN_SPACE_WIDTH
;
24449 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24451 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24453 width
= CHAR_WIDTH (it
->c
);
24456 else if (width
> 4)
24458 it
->pixel_width
= base_width
* width
;
24460 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24466 unsigned int code
[6];
24468 int ascent
, descent
;
24469 struct font_metrics metrics_upper
, metrics_lower
;
24471 face
= FACE_FROM_ID (it
->f
, face_id
);
24472 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24473 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24475 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24477 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24478 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24479 if (CONSP (acronym
))
24480 acronym
= XCAR (acronym
);
24481 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24485 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24486 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24489 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24490 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24491 upper_len
= (len
+ 1) / 2;
24492 font
->driver
->text_extents (font
, code
, upper_len
,
24494 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24499 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24500 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24501 upper_xoff
= upper_yoff
= 2; /* the typical case */
24502 if (base_width
>= width
)
24504 /* Align the upper to the left, the lower to the right. */
24505 it
->pixel_width
= base_width
;
24506 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24510 /* Center the shorter one. */
24511 it
->pixel_width
= width
;
24512 if (metrics_upper
.width
>= metrics_lower
.width
)
24513 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24516 /* FIXME: This code doesn't look right. It formerly was
24517 missing the "lower_xoff = 0;", which couldn't have
24518 been right since it left lower_xoff uninitialized. */
24520 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24524 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24525 top, bottom, and between upper and lower strings. */
24526 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24527 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24528 /* Center vertically.
24529 H:base_height, D:base_descent
24530 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24532 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24533 descent = D - H/2 + h/2;
24534 lower_yoff = descent - 2 - ld;
24535 upper_yoff = lower_yoff - la - 1 - ud; */
24536 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24537 descent
= it
->descent
- (base_height
- height
) / 2;
24538 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24539 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24540 - metrics_upper
.descent
);
24541 /* Don't make the height shorter than the base height. */
24542 if (height
> base_height
)
24544 it
->ascent
= ascent
;
24545 it
->descent
= descent
;
24549 it
->phys_ascent
= it
->ascent
;
24550 it
->phys_descent
= it
->descent
;
24552 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24553 upper_xoff
, upper_yoff
,
24554 lower_xoff
, lower_yoff
);
24556 take_vertical_position_into_account (it
);
24561 Produce glyphs/get display metrics for the display element IT is
24562 loaded with. See the description of struct it in dispextern.h
24563 for an overview of struct it. */
24566 x_produce_glyphs (struct it
*it
)
24568 int extra_line_spacing
= it
->extra_line_spacing
;
24570 it
->glyph_not_available_p
= 0;
24572 if (it
->what
== IT_CHARACTER
)
24575 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24576 struct font
*font
= face
->font
;
24577 struct font_metrics
*pcm
= NULL
;
24578 int boff
; /* baseline offset */
24582 /* When no suitable font is found, display this character by
24583 the method specified in the first extra slot of
24584 Vglyphless_char_display. */
24585 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24587 eassert (it
->what
== IT_GLYPHLESS
);
24588 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24592 boff
= font
->baseline_offset
;
24593 if (font
->vertical_centering
)
24594 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24596 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24602 if (it
->override_ascent
>= 0)
24604 it
->ascent
= it
->override_ascent
;
24605 it
->descent
= it
->override_descent
;
24606 boff
= it
->override_boff
;
24610 it
->ascent
= FONT_BASE (font
) + boff
;
24611 it
->descent
= FONT_DESCENT (font
) - boff
;
24614 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24616 pcm
= get_per_char_metric (font
, &char2b
);
24617 if (pcm
->width
== 0
24618 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24624 it
->phys_ascent
= pcm
->ascent
+ boff
;
24625 it
->phys_descent
= pcm
->descent
- boff
;
24626 it
->pixel_width
= pcm
->width
;
24630 it
->glyph_not_available_p
= 1;
24631 it
->phys_ascent
= it
->ascent
;
24632 it
->phys_descent
= it
->descent
;
24633 it
->pixel_width
= font
->space_width
;
24636 if (it
->constrain_row_ascent_descent_p
)
24638 if (it
->descent
> it
->max_descent
)
24640 it
->ascent
+= it
->descent
- it
->max_descent
;
24641 it
->descent
= it
->max_descent
;
24643 if (it
->ascent
> it
->max_ascent
)
24645 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24646 it
->ascent
= it
->max_ascent
;
24648 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24649 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24650 extra_line_spacing
= 0;
24653 /* If this is a space inside a region of text with
24654 `space-width' property, change its width. */
24655 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24657 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24659 /* If face has a box, add the box thickness to the character
24660 height. If character has a box line to the left and/or
24661 right, add the box line width to the character's width. */
24662 if (face
->box
!= FACE_NO_BOX
)
24664 int thick
= face
->box_line_width
;
24668 it
->ascent
+= thick
;
24669 it
->descent
+= thick
;
24674 if (it
->start_of_box_run_p
)
24675 it
->pixel_width
+= thick
;
24676 if (it
->end_of_box_run_p
)
24677 it
->pixel_width
+= thick
;
24680 /* If face has an overline, add the height of the overline
24681 (1 pixel) and a 1 pixel margin to the character height. */
24682 if (face
->overline_p
)
24683 it
->ascent
+= overline_margin
;
24685 if (it
->constrain_row_ascent_descent_p
)
24687 if (it
->ascent
> it
->max_ascent
)
24688 it
->ascent
= it
->max_ascent
;
24689 if (it
->descent
> it
->max_descent
)
24690 it
->descent
= it
->max_descent
;
24693 take_vertical_position_into_account (it
);
24695 /* If we have to actually produce glyphs, do it. */
24700 /* Translate a space with a `space-width' property
24701 into a stretch glyph. */
24702 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24703 / FONT_HEIGHT (font
));
24704 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24705 it
->ascent
+ it
->descent
, ascent
);
24710 /* If characters with lbearing or rbearing are displayed
24711 in this line, record that fact in a flag of the
24712 glyph row. This is used to optimize X output code. */
24713 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24714 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24716 if (! stretched_p
&& it
->pixel_width
== 0)
24717 /* We assure that all visible glyphs have at least 1-pixel
24719 it
->pixel_width
= 1;
24721 else if (it
->char_to_display
== '\n')
24723 /* A newline has no width, but we need the height of the
24724 line. But if previous part of the line sets a height,
24725 don't increase that height */
24727 Lisp_Object height
;
24728 Lisp_Object total_height
= Qnil
;
24730 it
->override_ascent
= -1;
24731 it
->pixel_width
= 0;
24734 height
= get_it_property (it
, Qline_height
);
24735 /* Split (line-height total-height) list */
24737 && CONSP (XCDR (height
))
24738 && NILP (XCDR (XCDR (height
))))
24740 total_height
= XCAR (XCDR (height
));
24741 height
= XCAR (height
);
24743 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24745 if (it
->override_ascent
>= 0)
24747 it
->ascent
= it
->override_ascent
;
24748 it
->descent
= it
->override_descent
;
24749 boff
= it
->override_boff
;
24753 it
->ascent
= FONT_BASE (font
) + boff
;
24754 it
->descent
= FONT_DESCENT (font
) - boff
;
24757 if (EQ (height
, Qt
))
24759 if (it
->descent
> it
->max_descent
)
24761 it
->ascent
+= it
->descent
- it
->max_descent
;
24762 it
->descent
= it
->max_descent
;
24764 if (it
->ascent
> it
->max_ascent
)
24766 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24767 it
->ascent
= it
->max_ascent
;
24769 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24770 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24771 it
->constrain_row_ascent_descent_p
= 1;
24772 extra_line_spacing
= 0;
24776 Lisp_Object spacing
;
24778 it
->phys_ascent
= it
->ascent
;
24779 it
->phys_descent
= it
->descent
;
24781 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24782 && face
->box
!= FACE_NO_BOX
24783 && face
->box_line_width
> 0)
24785 it
->ascent
+= face
->box_line_width
;
24786 it
->descent
+= face
->box_line_width
;
24789 && XINT (height
) > it
->ascent
+ it
->descent
)
24790 it
->ascent
= XINT (height
) - it
->descent
;
24792 if (!NILP (total_height
))
24793 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24796 spacing
= get_it_property (it
, Qline_spacing
);
24797 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24799 if (INTEGERP (spacing
))
24801 extra_line_spacing
= XINT (spacing
);
24802 if (!NILP (total_height
))
24803 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24807 else /* i.e. (it->char_to_display == '\t') */
24809 if (font
->space_width
> 0)
24811 int tab_width
= it
->tab_width
* font
->space_width
;
24812 int x
= it
->current_x
+ it
->continuation_lines_width
;
24813 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24815 /* If the distance from the current position to the next tab
24816 stop is less than a space character width, use the
24817 tab stop after that. */
24818 if (next_tab_x
- x
< font
->space_width
)
24819 next_tab_x
+= tab_width
;
24821 it
->pixel_width
= next_tab_x
- x
;
24823 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24824 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24828 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24829 it
->ascent
+ it
->descent
, it
->ascent
);
24834 it
->pixel_width
= 0;
24839 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24841 /* A static composition.
24843 Note: A composition is represented as one glyph in the
24844 glyph matrix. There are no padding glyphs.
24846 Important note: pixel_width, ascent, and descent are the
24847 values of what is drawn by draw_glyphs (i.e. the values of
24848 the overall glyphs composed). */
24849 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24850 int boff
; /* baseline offset */
24851 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24852 int glyph_len
= cmp
->glyph_len
;
24853 struct font
*font
= face
->font
;
24857 /* If we have not yet calculated pixel size data of glyphs of
24858 the composition for the current face font, calculate them
24859 now. Theoretically, we have to check all fonts for the
24860 glyphs, but that requires much time and memory space. So,
24861 here we check only the font of the first glyph. This may
24862 lead to incorrect display, but it's very rare, and C-l
24863 (recenter-top-bottom) can correct the display anyway. */
24864 if (! cmp
->font
|| cmp
->font
!= font
)
24866 /* Ascent and descent of the font of the first character
24867 of this composition (adjusted by baseline offset).
24868 Ascent and descent of overall glyphs should not be less
24869 than these, respectively. */
24870 int font_ascent
, font_descent
, font_height
;
24871 /* Bounding box of the overall glyphs. */
24872 int leftmost
, rightmost
, lowest
, highest
;
24873 int lbearing
, rbearing
;
24874 int i
, width
, ascent
, descent
;
24875 int left_padded
= 0, right_padded
= 0;
24876 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24878 struct font_metrics
*pcm
;
24879 int font_not_found_p
;
24882 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24883 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24885 if (glyph_len
< cmp
->glyph_len
)
24887 for (i
= 0; i
< glyph_len
; i
++)
24889 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24891 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24896 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24897 : IT_CHARPOS (*it
));
24898 /* If no suitable font is found, use the default font. */
24899 font_not_found_p
= font
== NULL
;
24900 if (font_not_found_p
)
24902 face
= face
->ascii_face
;
24905 boff
= font
->baseline_offset
;
24906 if (font
->vertical_centering
)
24907 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24908 font_ascent
= FONT_BASE (font
) + boff
;
24909 font_descent
= FONT_DESCENT (font
) - boff
;
24910 font_height
= FONT_HEIGHT (font
);
24915 if (! font_not_found_p
)
24917 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24919 pcm
= get_per_char_metric (font
, &char2b
);
24922 /* Initialize the bounding box. */
24925 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24926 ascent
= pcm
->ascent
;
24927 descent
= pcm
->descent
;
24928 lbearing
= pcm
->lbearing
;
24929 rbearing
= pcm
->rbearing
;
24933 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24934 ascent
= FONT_BASE (font
);
24935 descent
= FONT_DESCENT (font
);
24942 lowest
= - descent
+ boff
;
24943 highest
= ascent
+ boff
;
24945 if (! font_not_found_p
24946 && font
->default_ascent
24947 && CHAR_TABLE_P (Vuse_default_ascent
)
24948 && !NILP (Faref (Vuse_default_ascent
,
24949 make_number (it
->char_to_display
))))
24950 highest
= font
->default_ascent
+ boff
;
24952 /* Draw the first glyph at the normal position. It may be
24953 shifted to right later if some other glyphs are drawn
24955 cmp
->offsets
[i
* 2] = 0;
24956 cmp
->offsets
[i
* 2 + 1] = boff
;
24957 cmp
->lbearing
= lbearing
;
24958 cmp
->rbearing
= rbearing
;
24960 /* Set cmp->offsets for the remaining glyphs. */
24961 for (i
++; i
< glyph_len
; i
++)
24963 int left
, right
, btm
, top
;
24964 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24966 struct face
*this_face
;
24970 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24971 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24972 font
= this_face
->font
;
24978 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24980 pcm
= get_per_char_metric (font
, &char2b
);
24983 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24986 width
= pcm
->width
;
24987 ascent
= pcm
->ascent
;
24988 descent
= pcm
->descent
;
24989 lbearing
= pcm
->lbearing
;
24990 rbearing
= pcm
->rbearing
;
24991 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24993 /* Relative composition with or without
24994 alternate chars. */
24995 left
= (leftmost
+ rightmost
- width
) / 2;
24996 btm
= - descent
+ boff
;
24997 if (font
->relative_compose
24998 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24999 || NILP (Faref (Vignore_relative_composition
,
25000 make_number (ch
)))))
25003 if (- descent
>= font
->relative_compose
)
25004 /* One extra pixel between two glyphs. */
25006 else if (ascent
<= 0)
25007 /* One extra pixel between two glyphs. */
25008 btm
= lowest
- 1 - ascent
- descent
;
25013 /* A composition rule is specified by an integer
25014 value that encodes global and new reference
25015 points (GREF and NREF). GREF and NREF are
25016 specified by numbers as below:
25018 0---1---2 -- ascent
25022 9--10--11 -- center
25024 ---3---4---5--- baseline
25026 6---7---8 -- descent
25028 int rule
= COMPOSITION_RULE (cmp
, i
);
25029 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25031 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25032 grefx
= gref
% 3, nrefx
= nref
% 3;
25033 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25035 xoff
= font_height
* (xoff
- 128) / 256;
25037 yoff
= font_height
* (yoff
- 128) / 256;
25040 + grefx
* (rightmost
- leftmost
) / 2
25041 - nrefx
* width
/ 2
25044 btm
= ((grefy
== 0 ? highest
25046 : grefy
== 2 ? lowest
25047 : (highest
+ lowest
) / 2)
25048 - (nrefy
== 0 ? ascent
+ descent
25049 : nrefy
== 1 ? descent
- boff
25051 : (ascent
+ descent
) / 2)
25055 cmp
->offsets
[i
* 2] = left
;
25056 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25058 /* Update the bounding box of the overall glyphs. */
25061 right
= left
+ width
;
25062 if (left
< leftmost
)
25064 if (right
> rightmost
)
25067 top
= btm
+ descent
+ ascent
;
25073 if (cmp
->lbearing
> left
+ lbearing
)
25074 cmp
->lbearing
= left
+ lbearing
;
25075 if (cmp
->rbearing
< left
+ rbearing
)
25076 cmp
->rbearing
= left
+ rbearing
;
25080 /* If there are glyphs whose x-offsets are negative,
25081 shift all glyphs to the right and make all x-offsets
25085 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25086 cmp
->offsets
[i
* 2] -= leftmost
;
25087 rightmost
-= leftmost
;
25088 cmp
->lbearing
-= leftmost
;
25089 cmp
->rbearing
-= leftmost
;
25092 if (left_padded
&& cmp
->lbearing
< 0)
25094 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25095 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25096 rightmost
-= cmp
->lbearing
;
25097 cmp
->rbearing
-= cmp
->lbearing
;
25100 if (right_padded
&& rightmost
< cmp
->rbearing
)
25102 rightmost
= cmp
->rbearing
;
25105 cmp
->pixel_width
= rightmost
;
25106 cmp
->ascent
= highest
;
25107 cmp
->descent
= - lowest
;
25108 if (cmp
->ascent
< font_ascent
)
25109 cmp
->ascent
= font_ascent
;
25110 if (cmp
->descent
< font_descent
)
25111 cmp
->descent
= font_descent
;
25115 && (cmp
->lbearing
< 0
25116 || cmp
->rbearing
> cmp
->pixel_width
))
25117 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25119 it
->pixel_width
= cmp
->pixel_width
;
25120 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25121 it
->descent
= it
->phys_descent
= cmp
->descent
;
25122 if (face
->box
!= FACE_NO_BOX
)
25124 int thick
= face
->box_line_width
;
25128 it
->ascent
+= thick
;
25129 it
->descent
+= thick
;
25134 if (it
->start_of_box_run_p
)
25135 it
->pixel_width
+= thick
;
25136 if (it
->end_of_box_run_p
)
25137 it
->pixel_width
+= thick
;
25140 /* If face has an overline, add the height of the overline
25141 (1 pixel) and a 1 pixel margin to the character height. */
25142 if (face
->overline_p
)
25143 it
->ascent
+= overline_margin
;
25145 take_vertical_position_into_account (it
);
25146 if (it
->ascent
< 0)
25148 if (it
->descent
< 0)
25151 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25152 append_composite_glyph (it
);
25154 else if (it
->what
== IT_COMPOSITION
)
25156 /* A dynamic (automatic) composition. */
25157 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25158 Lisp_Object gstring
;
25159 struct font_metrics metrics
;
25163 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25165 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25168 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25169 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25170 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25171 it
->descent
= it
->phys_descent
= metrics
.descent
;
25172 if (face
->box
!= FACE_NO_BOX
)
25174 int thick
= face
->box_line_width
;
25178 it
->ascent
+= thick
;
25179 it
->descent
+= thick
;
25184 if (it
->start_of_box_run_p
)
25185 it
->pixel_width
+= thick
;
25186 if (it
->end_of_box_run_p
)
25187 it
->pixel_width
+= thick
;
25189 /* If face has an overline, add the height of the overline
25190 (1 pixel) and a 1 pixel margin to the character height. */
25191 if (face
->overline_p
)
25192 it
->ascent
+= overline_margin
;
25193 take_vertical_position_into_account (it
);
25194 if (it
->ascent
< 0)
25196 if (it
->descent
< 0)
25200 append_composite_glyph (it
);
25202 else if (it
->what
== IT_GLYPHLESS
)
25203 produce_glyphless_glyph (it
, 0, Qnil
);
25204 else if (it
->what
== IT_IMAGE
)
25205 produce_image_glyph (it
);
25206 else if (it
->what
== IT_STRETCH
)
25207 produce_stretch_glyph (it
);
25210 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25211 because this isn't true for images with `:ascent 100'. */
25212 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25213 if (it
->area
== TEXT_AREA
)
25214 it
->current_x
+= it
->pixel_width
;
25216 if (extra_line_spacing
> 0)
25218 it
->descent
+= extra_line_spacing
;
25219 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25220 it
->max_extra_line_spacing
= extra_line_spacing
;
25223 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25224 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25225 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25226 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25230 Output LEN glyphs starting at START at the nominal cursor position.
25231 Advance the nominal cursor over the text. The global variable
25232 updated_window contains the window being updated, updated_row is
25233 the glyph row being updated, and updated_area is the area of that
25234 row being updated. */
25237 x_write_glyphs (struct glyph
*start
, int len
)
25239 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25241 eassert (updated_window
&& updated_row
);
25242 /* When the window is hscrolled, cursor hpos can legitimately be out
25243 of bounds, but we draw the cursor at the corresponding window
25244 margin in that case. */
25245 if (!updated_row
->reversed_p
&& chpos
< 0)
25247 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25248 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25252 /* Write glyphs. */
25254 hpos
= start
- updated_row
->glyphs
[updated_area
];
25255 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25256 updated_row
, updated_area
,
25258 DRAW_NORMAL_TEXT
, 0);
25260 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25261 if (updated_area
== TEXT_AREA
25262 && updated_window
->phys_cursor_on_p
25263 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25265 && chpos
< hpos
+ len
)
25266 updated_window
->phys_cursor_on_p
= 0;
25270 /* Advance the output cursor. */
25271 output_cursor
.hpos
+= len
;
25272 output_cursor
.x
= x
;
25277 Insert LEN glyphs from START at the nominal cursor position. */
25280 x_insert_glyphs (struct glyph
*start
, int len
)
25284 int line_height
, shift_by_width
, shifted_region_width
;
25285 struct glyph_row
*row
;
25286 struct glyph
*glyph
;
25287 int frame_x
, frame_y
;
25290 eassert (updated_window
&& updated_row
);
25292 w
= updated_window
;
25293 f
= XFRAME (WINDOW_FRAME (w
));
25295 /* Get the height of the line we are in. */
25297 line_height
= row
->height
;
25299 /* Get the width of the glyphs to insert. */
25300 shift_by_width
= 0;
25301 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25302 shift_by_width
+= glyph
->pixel_width
;
25304 /* Get the width of the region to shift right. */
25305 shifted_region_width
= (window_box_width (w
, updated_area
)
25310 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25311 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25313 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25314 line_height
, shift_by_width
);
25316 /* Write the glyphs. */
25317 hpos
= start
- row
->glyphs
[updated_area
];
25318 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25320 DRAW_NORMAL_TEXT
, 0);
25322 /* Advance the output cursor. */
25323 output_cursor
.hpos
+= len
;
25324 output_cursor
.x
+= shift_by_width
;
25330 Erase the current text line from the nominal cursor position
25331 (inclusive) to pixel column TO_X (exclusive). The idea is that
25332 everything from TO_X onward is already erased.
25334 TO_X is a pixel position relative to updated_area of
25335 updated_window. TO_X == -1 means clear to the end of this area. */
25338 x_clear_end_of_line (int to_x
)
25341 struct window
*w
= updated_window
;
25342 int max_x
, min_y
, max_y
;
25343 int from_x
, from_y
, to_y
;
25345 eassert (updated_window
&& updated_row
);
25346 f
= XFRAME (w
->frame
);
25348 if (updated_row
->full_width_p
)
25349 max_x
= WINDOW_TOTAL_WIDTH (w
);
25351 max_x
= window_box_width (w
, updated_area
);
25352 max_y
= window_text_bottom_y (w
);
25354 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25355 of window. For TO_X > 0, truncate to end of drawing area. */
25361 to_x
= min (to_x
, max_x
);
25363 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25365 /* Notice if the cursor will be cleared by this operation. */
25366 if (!updated_row
->full_width_p
)
25367 notice_overwritten_cursor (w
, updated_area
,
25368 output_cursor
.x
, -1,
25370 MATRIX_ROW_BOTTOM_Y (updated_row
));
25372 from_x
= output_cursor
.x
;
25374 /* Translate to frame coordinates. */
25375 if (updated_row
->full_width_p
)
25377 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25378 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25382 int area_left
= window_box_left (w
, updated_area
);
25383 from_x
+= area_left
;
25387 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25388 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25389 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25391 /* Prevent inadvertently clearing to end of the X window. */
25392 if (to_x
> from_x
&& to_y
> from_y
)
25395 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25396 to_x
- from_x
, to_y
- from_y
);
25401 #endif /* HAVE_WINDOW_SYSTEM */
25405 /***********************************************************************
25407 ***********************************************************************/
25409 /* Value is the internal representation of the specified cursor type
25410 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25411 of the bar cursor. */
25413 static enum text_cursor_kinds
25414 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25416 enum text_cursor_kinds type
;
25421 if (EQ (arg
, Qbox
))
25422 return FILLED_BOX_CURSOR
;
25424 if (EQ (arg
, Qhollow
))
25425 return HOLLOW_BOX_CURSOR
;
25427 if (EQ (arg
, Qbar
))
25434 && EQ (XCAR (arg
), Qbar
)
25435 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25437 *width
= XINT (XCDR (arg
));
25441 if (EQ (arg
, Qhbar
))
25444 return HBAR_CURSOR
;
25448 && EQ (XCAR (arg
), Qhbar
)
25449 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25451 *width
= XINT (XCDR (arg
));
25452 return HBAR_CURSOR
;
25455 /* Treat anything unknown as "hollow box cursor".
25456 It was bad to signal an error; people have trouble fixing
25457 .Xdefaults with Emacs, when it has something bad in it. */
25458 type
= HOLLOW_BOX_CURSOR
;
25463 /* Set the default cursor types for specified frame. */
25465 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25470 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25471 FRAME_CURSOR_WIDTH (f
) = width
;
25473 /* By default, set up the blink-off state depending on the on-state. */
25475 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25478 FRAME_BLINK_OFF_CURSOR (f
)
25479 = get_specified_cursor_type (XCDR (tem
), &width
);
25480 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25483 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25487 #ifdef HAVE_WINDOW_SYSTEM
25489 /* Return the cursor we want to be displayed in window W. Return
25490 width of bar/hbar cursor through WIDTH arg. Return with
25491 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25492 (i.e. if the `system caret' should track this cursor).
25494 In a mini-buffer window, we want the cursor only to appear if we
25495 are reading input from this window. For the selected window, we
25496 want the cursor type given by the frame parameter or buffer local
25497 setting of cursor-type. If explicitly marked off, draw no cursor.
25498 In all other cases, we want a hollow box cursor. */
25500 static enum text_cursor_kinds
25501 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25502 int *active_cursor
)
25504 struct frame
*f
= XFRAME (w
->frame
);
25505 struct buffer
*b
= XBUFFER (w
->contents
);
25506 int cursor_type
= DEFAULT_CURSOR
;
25507 Lisp_Object alt_cursor
;
25508 int non_selected
= 0;
25510 *active_cursor
= 1;
25513 if (cursor_in_echo_area
25514 && FRAME_HAS_MINIBUF_P (f
)
25515 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25517 if (w
== XWINDOW (echo_area_window
))
25519 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25521 *width
= FRAME_CURSOR_WIDTH (f
);
25522 return FRAME_DESIRED_CURSOR (f
);
25525 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25528 *active_cursor
= 0;
25532 /* Detect a nonselected window or nonselected frame. */
25533 else if (w
!= XWINDOW (f
->selected_window
)
25534 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25536 *active_cursor
= 0;
25538 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25544 /* Never display a cursor in a window in which cursor-type is nil. */
25545 if (NILP (BVAR (b
, cursor_type
)))
25548 /* Get the normal cursor type for this window. */
25549 if (EQ (BVAR (b
, cursor_type
), Qt
))
25551 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25552 *width
= FRAME_CURSOR_WIDTH (f
);
25555 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25557 /* Use cursor-in-non-selected-windows instead
25558 for non-selected window or frame. */
25561 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25562 if (!EQ (Qt
, alt_cursor
))
25563 return get_specified_cursor_type (alt_cursor
, width
);
25564 /* t means modify the normal cursor type. */
25565 if (cursor_type
== FILLED_BOX_CURSOR
)
25566 cursor_type
= HOLLOW_BOX_CURSOR
;
25567 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25569 return cursor_type
;
25572 /* Use normal cursor if not blinked off. */
25573 if (!w
->cursor_off_p
)
25575 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25577 if (cursor_type
== FILLED_BOX_CURSOR
)
25579 /* Using a block cursor on large images can be very annoying.
25580 So use a hollow cursor for "large" images.
25581 If image is not transparent (no mask), also use hollow cursor. */
25582 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25583 if (img
!= NULL
&& IMAGEP (img
->spec
))
25585 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25586 where N = size of default frame font size.
25587 This should cover most of the "tiny" icons people may use. */
25589 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25590 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25591 cursor_type
= HOLLOW_BOX_CURSOR
;
25594 else if (cursor_type
!= NO_CURSOR
)
25596 /* Display current only supports BOX and HOLLOW cursors for images.
25597 So for now, unconditionally use a HOLLOW cursor when cursor is
25598 not a solid box cursor. */
25599 cursor_type
= HOLLOW_BOX_CURSOR
;
25602 return cursor_type
;
25605 /* Cursor is blinked off, so determine how to "toggle" it. */
25607 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25608 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25609 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25611 /* Then see if frame has specified a specific blink off cursor type. */
25612 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25614 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25615 return FRAME_BLINK_OFF_CURSOR (f
);
25619 /* Some people liked having a permanently visible blinking cursor,
25620 while others had very strong opinions against it. So it was
25621 decided to remove it. KFS 2003-09-03 */
25623 /* Finally perform built-in cursor blinking:
25624 filled box <-> hollow box
25625 wide [h]bar <-> narrow [h]bar
25626 narrow [h]bar <-> no cursor
25627 other type <-> no cursor */
25629 if (cursor_type
== FILLED_BOX_CURSOR
)
25630 return HOLLOW_BOX_CURSOR
;
25632 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25635 return cursor_type
;
25643 /* Notice when the text cursor of window W has been completely
25644 overwritten by a drawing operation that outputs glyphs in AREA
25645 starting at X0 and ending at X1 in the line starting at Y0 and
25646 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25647 the rest of the line after X0 has been written. Y coordinates
25648 are window-relative. */
25651 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25652 int x0
, int x1
, int y0
, int y1
)
25654 int cx0
, cx1
, cy0
, cy1
;
25655 struct glyph_row
*row
;
25657 if (!w
->phys_cursor_on_p
)
25659 if (area
!= TEXT_AREA
)
25662 if (w
->phys_cursor
.vpos
< 0
25663 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25664 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25665 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
25668 if (row
->cursor_in_fringe_p
)
25670 row
->cursor_in_fringe_p
= 0;
25671 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25672 w
->phys_cursor_on_p
= 0;
25676 cx0
= w
->phys_cursor
.x
;
25677 cx1
= cx0
+ w
->phys_cursor_width
;
25678 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25681 /* The cursor image will be completely removed from the
25682 screen if the output area intersects the cursor area in
25683 y-direction. When we draw in [y0 y1[, and some part of
25684 the cursor is at y < y0, that part must have been drawn
25685 before. When scrolling, the cursor is erased before
25686 actually scrolling, so we don't come here. When not
25687 scrolling, the rows above the old cursor row must have
25688 changed, and in this case these rows must have written
25689 over the cursor image.
25691 Likewise if part of the cursor is below y1, with the
25692 exception of the cursor being in the first blank row at
25693 the buffer and window end because update_text_area
25694 doesn't draw that row. (Except when it does, but
25695 that's handled in update_text_area.) */
25697 cy0
= w
->phys_cursor
.y
;
25698 cy1
= cy0
+ w
->phys_cursor_height
;
25699 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25702 w
->phys_cursor_on_p
= 0;
25705 #endif /* HAVE_WINDOW_SYSTEM */
25708 /************************************************************************
25710 ************************************************************************/
25712 #ifdef HAVE_WINDOW_SYSTEM
25715 Fix the display of area AREA of overlapping row ROW in window W
25716 with respect to the overlapping part OVERLAPS. */
25719 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25720 enum glyph_row_area area
, int overlaps
)
25727 for (i
= 0; i
< row
->used
[area
];)
25729 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25731 int start
= i
, start_x
= x
;
25735 x
+= row
->glyphs
[area
][i
].pixel_width
;
25738 while (i
< row
->used
[area
]
25739 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25741 draw_glyphs (w
, start_x
, row
, area
,
25743 DRAW_NORMAL_TEXT
, overlaps
);
25747 x
+= row
->glyphs
[area
][i
].pixel_width
;
25757 Draw the cursor glyph of window W in glyph row ROW. See the
25758 comment of draw_glyphs for the meaning of HL. */
25761 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25762 enum draw_glyphs_face hl
)
25764 /* If cursor hpos is out of bounds, don't draw garbage. This can
25765 happen in mini-buffer windows when switching between echo area
25766 glyphs and mini-buffer. */
25767 if ((row
->reversed_p
25768 ? (w
->phys_cursor
.hpos
>= 0)
25769 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25771 int on_p
= w
->phys_cursor_on_p
;
25773 int hpos
= w
->phys_cursor
.hpos
;
25775 /* When the window is hscrolled, cursor hpos can legitimately be
25776 out of bounds, but we draw the cursor at the corresponding
25777 window margin in that case. */
25778 if (!row
->reversed_p
&& hpos
< 0)
25780 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25781 hpos
= row
->used
[TEXT_AREA
] - 1;
25783 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25785 w
->phys_cursor_on_p
= on_p
;
25787 if (hl
== DRAW_CURSOR
)
25788 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25789 /* When we erase the cursor, and ROW is overlapped by other
25790 rows, make sure that these overlapping parts of other rows
25792 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25794 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25796 if (row
> w
->current_matrix
->rows
25797 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25798 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25799 OVERLAPS_ERASED_CURSOR
);
25801 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25802 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25803 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25804 OVERLAPS_ERASED_CURSOR
);
25811 Erase the image of a cursor of window W from the screen. */
25814 erase_phys_cursor (struct window
*w
)
25816 struct frame
*f
= XFRAME (w
->frame
);
25817 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25818 int hpos
= w
->phys_cursor
.hpos
;
25819 int vpos
= w
->phys_cursor
.vpos
;
25820 int mouse_face_here_p
= 0;
25821 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25822 struct glyph_row
*cursor_row
;
25823 struct glyph
*cursor_glyph
;
25824 enum draw_glyphs_face hl
;
25826 /* No cursor displayed or row invalidated => nothing to do on the
25828 if (w
->phys_cursor_type
== NO_CURSOR
)
25829 goto mark_cursor_off
;
25831 /* VPOS >= active_glyphs->nrows means that window has been resized.
25832 Don't bother to erase the cursor. */
25833 if (vpos
>= active_glyphs
->nrows
)
25834 goto mark_cursor_off
;
25836 /* If row containing cursor is marked invalid, there is nothing we
25838 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25839 if (!cursor_row
->enabled_p
)
25840 goto mark_cursor_off
;
25842 /* If line spacing is > 0, old cursor may only be partially visible in
25843 window after split-window. So adjust visible height. */
25844 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25845 window_text_bottom_y (w
) - cursor_row
->y
);
25847 /* If row is completely invisible, don't attempt to delete a cursor which
25848 isn't there. This can happen if cursor is at top of a window, and
25849 we switch to a buffer with a header line in that window. */
25850 if (cursor_row
->visible_height
<= 0)
25851 goto mark_cursor_off
;
25853 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25854 if (cursor_row
->cursor_in_fringe_p
)
25856 cursor_row
->cursor_in_fringe_p
= 0;
25857 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25858 goto mark_cursor_off
;
25861 /* This can happen when the new row is shorter than the old one.
25862 In this case, either draw_glyphs or clear_end_of_line
25863 should have cleared the cursor. Note that we wouldn't be
25864 able to erase the cursor in this case because we don't have a
25865 cursor glyph at hand. */
25866 if ((cursor_row
->reversed_p
25867 ? (w
->phys_cursor
.hpos
< 0)
25868 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25869 goto mark_cursor_off
;
25871 /* When the window is hscrolled, cursor hpos can legitimately be out
25872 of bounds, but we draw the cursor at the corresponding window
25873 margin in that case. */
25874 if (!cursor_row
->reversed_p
&& hpos
< 0)
25876 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25877 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25879 /* If the cursor is in the mouse face area, redisplay that when
25880 we clear the cursor. */
25881 if (! NILP (hlinfo
->mouse_face_window
)
25882 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25883 /* Don't redraw the cursor's spot in mouse face if it is at the
25884 end of a line (on a newline). The cursor appears there, but
25885 mouse highlighting does not. */
25886 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25887 mouse_face_here_p
= 1;
25889 /* Maybe clear the display under the cursor. */
25890 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25893 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25896 cursor_glyph
= get_phys_cursor_glyph (w
);
25897 if (cursor_glyph
== NULL
)
25898 goto mark_cursor_off
;
25900 width
= cursor_glyph
->pixel_width
;
25901 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25902 x
= w
->phys_cursor
.x
;
25904 width
-= left_x
- x
;
25905 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25906 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25907 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25910 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25913 /* Erase the cursor by redrawing the character underneath it. */
25914 if (mouse_face_here_p
)
25915 hl
= DRAW_MOUSE_FACE
;
25917 hl
= DRAW_NORMAL_TEXT
;
25918 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25921 w
->phys_cursor_on_p
= 0;
25922 w
->phys_cursor_type
= NO_CURSOR
;
25927 Display or clear cursor of window W. If ON is zero, clear the
25928 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25929 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25932 display_and_set_cursor (struct window
*w
, int on
,
25933 int hpos
, int vpos
, int x
, int y
)
25935 struct frame
*f
= XFRAME (w
->frame
);
25936 int new_cursor_type
;
25937 int new_cursor_width
;
25939 struct glyph_row
*glyph_row
;
25940 struct glyph
*glyph
;
25942 /* This is pointless on invisible frames, and dangerous on garbaged
25943 windows and frames; in the latter case, the frame or window may
25944 be in the midst of changing its size, and x and y may be off the
25946 if (! FRAME_VISIBLE_P (f
)
25947 || FRAME_GARBAGED_P (f
)
25948 || vpos
>= w
->current_matrix
->nrows
25949 || hpos
>= w
->current_matrix
->matrix_w
)
25952 /* If cursor is off and we want it off, return quickly. */
25953 if (!on
&& !w
->phys_cursor_on_p
)
25956 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25957 /* If cursor row is not enabled, we don't really know where to
25958 display the cursor. */
25959 if (!glyph_row
->enabled_p
)
25961 w
->phys_cursor_on_p
= 0;
25966 if (!glyph_row
->exact_window_width_line_p
25967 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25968 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25970 eassert (input_blocked_p ());
25972 /* Set new_cursor_type to the cursor we want to be displayed. */
25973 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25974 &new_cursor_width
, &active_cursor
);
25976 /* If cursor is currently being shown and we don't want it to be or
25977 it is in the wrong place, or the cursor type is not what we want,
25979 if (w
->phys_cursor_on_p
25981 || w
->phys_cursor
.x
!= x
25982 || w
->phys_cursor
.y
!= y
25983 || new_cursor_type
!= w
->phys_cursor_type
25984 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25985 && new_cursor_width
!= w
->phys_cursor_width
)))
25986 erase_phys_cursor (w
);
25988 /* Don't check phys_cursor_on_p here because that flag is only set
25989 to zero in some cases where we know that the cursor has been
25990 completely erased, to avoid the extra work of erasing the cursor
25991 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25992 still not be visible, or it has only been partly erased. */
25995 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25996 w
->phys_cursor_height
= glyph_row
->height
;
25998 /* Set phys_cursor_.* before x_draw_.* is called because some
25999 of them may need the information. */
26000 w
->phys_cursor
.x
= x
;
26001 w
->phys_cursor
.y
= glyph_row
->y
;
26002 w
->phys_cursor
.hpos
= hpos
;
26003 w
->phys_cursor
.vpos
= vpos
;
26006 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26007 new_cursor_type
, new_cursor_width
,
26008 on
, active_cursor
);
26012 /* Switch the display of W's cursor on or off, according to the value
26016 update_window_cursor (struct window
*w
, int on
)
26018 /* Don't update cursor in windows whose frame is in the process
26019 of being deleted. */
26020 if (w
->current_matrix
)
26022 int hpos
= w
->phys_cursor
.hpos
;
26023 int vpos
= w
->phys_cursor
.vpos
;
26024 struct glyph_row
*row
;
26026 if (vpos
>= w
->current_matrix
->nrows
26027 || hpos
>= w
->current_matrix
->matrix_w
)
26030 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26032 /* When the window is hscrolled, cursor hpos can legitimately be
26033 out of bounds, but we draw the cursor at the corresponding
26034 window margin in that case. */
26035 if (!row
->reversed_p
&& hpos
< 0)
26037 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26038 hpos
= row
->used
[TEXT_AREA
] - 1;
26041 display_and_set_cursor (w
, on
, hpos
, vpos
,
26042 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26048 /* Call update_window_cursor with parameter ON_P on all leaf windows
26049 in the window tree rooted at W. */
26052 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26056 if (WINDOWP (w
->contents
))
26057 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26059 update_window_cursor (w
, on_p
);
26061 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26067 Display the cursor on window W, or clear it, according to ON_P.
26068 Don't change the cursor's position. */
26071 x_update_cursor (struct frame
*f
, int on_p
)
26073 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26078 Clear the cursor of window W to background color, and mark the
26079 cursor as not shown. This is used when the text where the cursor
26080 is about to be rewritten. */
26083 x_clear_cursor (struct window
*w
)
26085 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26086 update_window_cursor (w
, 0);
26089 #endif /* HAVE_WINDOW_SYSTEM */
26091 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26094 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26095 int start_hpos
, int end_hpos
,
26096 enum draw_glyphs_face draw
)
26098 #ifdef HAVE_WINDOW_SYSTEM
26099 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26101 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26105 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26106 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26110 /* Display the active region described by mouse_face_* according to DRAW. */
26113 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26115 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26116 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26118 if (/* If window is in the process of being destroyed, don't bother
26120 w
->current_matrix
!= NULL
26121 /* Don't update mouse highlight if hidden */
26122 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26123 /* Recognize when we are called to operate on rows that don't exist
26124 anymore. This can happen when a window is split. */
26125 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26127 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26128 struct glyph_row
*row
, *first
, *last
;
26130 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26131 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26133 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26135 int start_hpos
, end_hpos
, start_x
;
26137 /* For all but the first row, the highlight starts at column 0. */
26140 /* R2L rows have BEG and END in reversed order, but the
26141 screen drawing geometry is always left to right. So
26142 we need to mirror the beginning and end of the
26143 highlighted area in R2L rows. */
26144 if (!row
->reversed_p
)
26146 start_hpos
= hlinfo
->mouse_face_beg_col
;
26147 start_x
= hlinfo
->mouse_face_beg_x
;
26149 else if (row
== last
)
26151 start_hpos
= hlinfo
->mouse_face_end_col
;
26152 start_x
= hlinfo
->mouse_face_end_x
;
26160 else if (row
->reversed_p
&& row
== last
)
26162 start_hpos
= hlinfo
->mouse_face_end_col
;
26163 start_x
= hlinfo
->mouse_face_end_x
;
26173 if (!row
->reversed_p
)
26174 end_hpos
= hlinfo
->mouse_face_end_col
;
26175 else if (row
== first
)
26176 end_hpos
= hlinfo
->mouse_face_beg_col
;
26179 end_hpos
= row
->used
[TEXT_AREA
];
26180 if (draw
== DRAW_NORMAL_TEXT
)
26181 row
->fill_line_p
= 1; /* Clear to end of line */
26184 else if (row
->reversed_p
&& row
== first
)
26185 end_hpos
= hlinfo
->mouse_face_beg_col
;
26188 end_hpos
= row
->used
[TEXT_AREA
];
26189 if (draw
== DRAW_NORMAL_TEXT
)
26190 row
->fill_line_p
= 1; /* Clear to end of line */
26193 if (end_hpos
> start_hpos
)
26195 draw_row_with_mouse_face (w
, start_x
, row
,
26196 start_hpos
, end_hpos
, draw
);
26199 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26203 #ifdef HAVE_WINDOW_SYSTEM
26204 /* When we've written over the cursor, arrange for it to
26205 be displayed again. */
26206 if (FRAME_WINDOW_P (f
)
26207 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26209 int hpos
= w
->phys_cursor
.hpos
;
26211 /* When the window is hscrolled, cursor hpos can legitimately be
26212 out of bounds, but we draw the cursor at the corresponding
26213 window margin in that case. */
26214 if (!row
->reversed_p
&& hpos
< 0)
26216 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26217 hpos
= row
->used
[TEXT_AREA
] - 1;
26220 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26221 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26224 #endif /* HAVE_WINDOW_SYSTEM */
26227 #ifdef HAVE_WINDOW_SYSTEM
26228 /* Change the mouse cursor. */
26229 if (FRAME_WINDOW_P (f
))
26231 if (draw
== DRAW_NORMAL_TEXT
26232 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26233 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26234 else if (draw
== DRAW_MOUSE_FACE
)
26235 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26237 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26239 #endif /* HAVE_WINDOW_SYSTEM */
26243 Clear out the mouse-highlighted active region.
26244 Redraw it un-highlighted first. Value is non-zero if mouse
26245 face was actually drawn unhighlighted. */
26248 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26252 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26254 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26258 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26259 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26260 hlinfo
->mouse_face_window
= Qnil
;
26261 hlinfo
->mouse_face_overlay
= Qnil
;
26265 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26266 within the mouse face on that window. */
26268 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26270 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26272 /* Quickly resolve the easy cases. */
26273 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26274 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26276 if (vpos
< hlinfo
->mouse_face_beg_row
26277 || vpos
> hlinfo
->mouse_face_end_row
)
26279 if (vpos
> hlinfo
->mouse_face_beg_row
26280 && vpos
< hlinfo
->mouse_face_end_row
)
26283 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26285 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26287 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26290 else if ((vpos
== hlinfo
->mouse_face_beg_row
26291 && hpos
>= hlinfo
->mouse_face_beg_col
)
26292 || (vpos
== hlinfo
->mouse_face_end_row
26293 && hpos
< hlinfo
->mouse_face_end_col
))
26298 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26300 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26303 else if ((vpos
== hlinfo
->mouse_face_beg_row
26304 && hpos
<= hlinfo
->mouse_face_beg_col
)
26305 || (vpos
== hlinfo
->mouse_face_end_row
26306 && hpos
> hlinfo
->mouse_face_end_col
))
26314 Non-zero if physical cursor of window W is within mouse face. */
26317 cursor_in_mouse_face_p (struct window
*w
)
26319 int hpos
= w
->phys_cursor
.hpos
;
26320 int vpos
= w
->phys_cursor
.vpos
;
26321 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26323 /* When the window is hscrolled, cursor hpos can legitimately be out
26324 of bounds, but we draw the cursor at the corresponding window
26325 margin in that case. */
26326 if (!row
->reversed_p
&& hpos
< 0)
26328 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26329 hpos
= row
->used
[TEXT_AREA
] - 1;
26331 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26336 /* Find the glyph rows START_ROW and END_ROW of window W that display
26337 characters between buffer positions START_CHARPOS and END_CHARPOS
26338 (excluding END_CHARPOS). DISP_STRING is a display string that
26339 covers these buffer positions. This is similar to
26340 row_containing_pos, but is more accurate when bidi reordering makes
26341 buffer positions change non-linearly with glyph rows. */
26343 rows_from_pos_range (struct window
*w
,
26344 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26345 Lisp_Object disp_string
,
26346 struct glyph_row
**start
, struct glyph_row
**end
)
26348 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26349 int last_y
= window_text_bottom_y (w
);
26350 struct glyph_row
*row
;
26355 while (!first
->enabled_p
26356 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26359 /* Find the START row. */
26361 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26364 /* A row can potentially be the START row if the range of the
26365 characters it displays intersects the range
26366 [START_CHARPOS..END_CHARPOS). */
26367 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26368 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26369 /* See the commentary in row_containing_pos, for the
26370 explanation of the complicated way to check whether
26371 some position is beyond the end of the characters
26372 displayed by a row. */
26373 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26374 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26375 && !row
->ends_at_zv_p
26376 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26377 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26378 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26379 && !row
->ends_at_zv_p
26380 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26382 /* Found a candidate row. Now make sure at least one of the
26383 glyphs it displays has a charpos from the range
26384 [START_CHARPOS..END_CHARPOS).
26386 This is not obvious because bidi reordering could make
26387 buffer positions of a row be 1,2,3,102,101,100, and if we
26388 want to highlight characters in [50..60), we don't want
26389 this row, even though [50..60) does intersect [1..103),
26390 the range of character positions given by the row's start
26391 and end positions. */
26392 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26393 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26397 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26398 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26399 /* A glyph that comes from DISP_STRING is by
26400 definition to be highlighted. */
26401 || EQ (g
->object
, disp_string
))
26410 /* Find the END row. */
26412 /* If the last row is partially visible, start looking for END
26413 from that row, instead of starting from FIRST. */
26414 && !(row
->enabled_p
26415 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26417 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26419 struct glyph_row
*next
= row
+ 1;
26420 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26422 if (!next
->enabled_p
26423 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26424 /* The first row >= START whose range of displayed characters
26425 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26426 is the row END + 1. */
26427 || (start_charpos
< next_start
26428 && end_charpos
< next_start
)
26429 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26430 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26431 && !next
->ends_at_zv_p
26432 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26433 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26434 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26435 && !next
->ends_at_zv_p
26436 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26443 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26444 but none of the characters it displays are in the range, it is
26446 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26447 struct glyph
*s
= g
;
26448 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26452 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26453 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26454 /* If the buffer position of the first glyph in
26455 the row is equal to END_CHARPOS, it means
26456 the last character to be highlighted is the
26457 newline of ROW, and we must consider NEXT as
26459 || (((!next
->reversed_p
&& g
== s
)
26460 || (next
->reversed_p
&& g
== e
- 1))
26461 && (g
->charpos
== end_charpos
26462 /* Special case for when NEXT is an
26463 empty line at ZV. */
26464 || (g
->charpos
== -1
26465 && !row
->ends_at_zv_p
26466 && next_start
== end_charpos
)))))
26467 /* A glyph that comes from DISP_STRING is by
26468 definition to be highlighted. */
26469 || EQ (g
->object
, disp_string
))
26478 /* The first row that ends at ZV must be the last to be
26480 else if (next
->ends_at_zv_p
)
26489 /* This function sets the mouse_face_* elements of HLINFO, assuming
26490 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26491 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26492 for the overlay or run of text properties specifying the mouse
26493 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26494 before-string and after-string that must also be highlighted.
26495 DISP_STRING, if non-nil, is a display string that may cover some
26496 or all of the highlighted text. */
26499 mouse_face_from_buffer_pos (Lisp_Object window
,
26500 Mouse_HLInfo
*hlinfo
,
26501 ptrdiff_t mouse_charpos
,
26502 ptrdiff_t start_charpos
,
26503 ptrdiff_t end_charpos
,
26504 Lisp_Object before_string
,
26505 Lisp_Object after_string
,
26506 Lisp_Object disp_string
)
26508 struct window
*w
= XWINDOW (window
);
26509 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26510 struct glyph_row
*r1
, *r2
;
26511 struct glyph
*glyph
, *end
;
26512 ptrdiff_t ignore
, pos
;
26515 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26516 eassert (NILP (before_string
) || STRINGP (before_string
));
26517 eassert (NILP (after_string
) || STRINGP (after_string
));
26519 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26520 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26522 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26523 /* If the before-string or display-string contains newlines,
26524 rows_from_pos_range skips to its last row. Move back. */
26525 if (!NILP (before_string
) || !NILP (disp_string
))
26527 struct glyph_row
*prev
;
26528 while ((prev
= r1
- 1, prev
>= first
)
26529 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26530 && prev
->used
[TEXT_AREA
] > 0)
26532 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26533 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26534 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26536 || !(EQ (glyph
->object
, before_string
)
26537 || EQ (glyph
->object
, disp_string
)))
26544 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26545 hlinfo
->mouse_face_past_end
= 1;
26547 else if (!NILP (after_string
))
26549 /* If the after-string has newlines, advance to its last row. */
26550 struct glyph_row
*next
;
26551 struct glyph_row
*last
26552 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26554 for (next
= r2
+ 1;
26556 && next
->used
[TEXT_AREA
] > 0
26557 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26561 /* The rest of the display engine assumes that mouse_face_beg_row is
26562 either above mouse_face_end_row or identical to it. But with
26563 bidi-reordered continued lines, the row for START_CHARPOS could
26564 be below the row for END_CHARPOS. If so, swap the rows and store
26565 them in correct order. */
26568 struct glyph_row
*tem
= r2
;
26574 hlinfo
->mouse_face_beg_y
= r1
->y
;
26575 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26576 hlinfo
->mouse_face_end_y
= r2
->y
;
26577 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26579 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26580 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26581 could be anywhere in the row and in any order. The strategy
26582 below is to find the leftmost and the rightmost glyph that
26583 belongs to either of these 3 strings, or whose position is
26584 between START_CHARPOS and END_CHARPOS, and highlight all the
26585 glyphs between those two. This may cover more than just the text
26586 between START_CHARPOS and END_CHARPOS if the range of characters
26587 strides the bidi level boundary, e.g. if the beginning is in R2L
26588 text while the end is in L2R text or vice versa. */
26589 if (!r1
->reversed_p
)
26591 /* This row is in a left to right paragraph. Scan it left to
26593 glyph
= r1
->glyphs
[TEXT_AREA
];
26594 end
= glyph
+ r1
->used
[TEXT_AREA
];
26597 /* Skip truncation glyphs at the start of the glyph row. */
26598 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
26600 && INTEGERP (glyph
->object
)
26601 && glyph
->charpos
< 0;
26603 x
+= glyph
->pixel_width
;
26605 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26606 or DISP_STRING, and the first glyph from buffer whose
26607 position is between START_CHARPOS and END_CHARPOS. */
26609 && !INTEGERP (glyph
->object
)
26610 && !EQ (glyph
->object
, disp_string
)
26611 && !(BUFFERP (glyph
->object
)
26612 && (glyph
->charpos
>= start_charpos
26613 && glyph
->charpos
< end_charpos
));
26616 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26617 are present at buffer positions between START_CHARPOS and
26618 END_CHARPOS, or if they come from an overlay. */
26619 if (EQ (glyph
->object
, before_string
))
26621 pos
= string_buffer_position (before_string
,
26623 /* If pos == 0, it means before_string came from an
26624 overlay, not from a buffer position. */
26625 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26628 else if (EQ (glyph
->object
, after_string
))
26630 pos
= string_buffer_position (after_string
, end_charpos
);
26631 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26634 x
+= glyph
->pixel_width
;
26636 hlinfo
->mouse_face_beg_x
= x
;
26637 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26641 /* This row is in a right to left paragraph. Scan it right to
26645 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26646 glyph
= end
+ r1
->used
[TEXT_AREA
];
26648 /* Skip truncation glyphs at the start of the glyph row. */
26649 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
26651 && INTEGERP (glyph
->object
)
26652 && glyph
->charpos
< 0;
26656 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26657 or DISP_STRING, and the first glyph from buffer whose
26658 position is between START_CHARPOS and END_CHARPOS. */
26660 && !INTEGERP (glyph
->object
)
26661 && !EQ (glyph
->object
, disp_string
)
26662 && !(BUFFERP (glyph
->object
)
26663 && (glyph
->charpos
>= start_charpos
26664 && glyph
->charpos
< end_charpos
));
26667 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26668 are present at buffer positions between START_CHARPOS and
26669 END_CHARPOS, or if they come from an overlay. */
26670 if (EQ (glyph
->object
, before_string
))
26672 pos
= string_buffer_position (before_string
, start_charpos
);
26673 /* If pos == 0, it means before_string came from an
26674 overlay, not from a buffer position. */
26675 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26678 else if (EQ (glyph
->object
, after_string
))
26680 pos
= string_buffer_position (after_string
, end_charpos
);
26681 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26686 glyph
++; /* first glyph to the right of the highlighted area */
26687 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26688 x
+= g
->pixel_width
;
26689 hlinfo
->mouse_face_beg_x
= x
;
26690 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26693 /* If the highlight ends in a different row, compute GLYPH and END
26694 for the end row. Otherwise, reuse the values computed above for
26695 the row where the highlight begins. */
26698 if (!r2
->reversed_p
)
26700 glyph
= r2
->glyphs
[TEXT_AREA
];
26701 end
= glyph
+ r2
->used
[TEXT_AREA
];
26706 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26707 glyph
= end
+ r2
->used
[TEXT_AREA
];
26711 if (!r2
->reversed_p
)
26713 /* Skip truncation and continuation glyphs near the end of the
26714 row, and also blanks and stretch glyphs inserted by
26715 extend_face_to_end_of_line. */
26717 && INTEGERP ((end
- 1)->object
))
26719 /* Scan the rest of the glyph row from the end, looking for the
26720 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26721 DISP_STRING, or whose position is between START_CHARPOS
26725 && !INTEGERP (end
->object
)
26726 && !EQ (end
->object
, disp_string
)
26727 && !(BUFFERP (end
->object
)
26728 && (end
->charpos
>= start_charpos
26729 && end
->charpos
< end_charpos
));
26732 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26733 are present at buffer positions between START_CHARPOS and
26734 END_CHARPOS, or if they come from an overlay. */
26735 if (EQ (end
->object
, before_string
))
26737 pos
= string_buffer_position (before_string
, start_charpos
);
26738 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26741 else if (EQ (end
->object
, after_string
))
26743 pos
= string_buffer_position (after_string
, end_charpos
);
26744 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26748 /* Find the X coordinate of the last glyph to be highlighted. */
26749 for (; glyph
<= end
; ++glyph
)
26750 x
+= glyph
->pixel_width
;
26752 hlinfo
->mouse_face_end_x
= x
;
26753 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26757 /* Skip truncation and continuation glyphs near the end of the
26758 row, and also blanks and stretch glyphs inserted by
26759 extend_face_to_end_of_line. */
26763 && INTEGERP (end
->object
))
26765 x
+= end
->pixel_width
;
26768 /* Scan the rest of the glyph row from the end, looking for the
26769 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26770 DISP_STRING, or whose position is between START_CHARPOS
26774 && !INTEGERP (end
->object
)
26775 && !EQ (end
->object
, disp_string
)
26776 && !(BUFFERP (end
->object
)
26777 && (end
->charpos
>= start_charpos
26778 && end
->charpos
< end_charpos
));
26781 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26782 are present at buffer positions between START_CHARPOS and
26783 END_CHARPOS, or if they come from an overlay. */
26784 if (EQ (end
->object
, before_string
))
26786 pos
= string_buffer_position (before_string
, start_charpos
);
26787 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26790 else if (EQ (end
->object
, after_string
))
26792 pos
= string_buffer_position (after_string
, end_charpos
);
26793 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26796 x
+= end
->pixel_width
;
26798 /* If we exited the above loop because we arrived at the last
26799 glyph of the row, and its buffer position is still not in
26800 range, it means the last character in range is the preceding
26801 newline. Bump the end column and x values to get past the
26804 && BUFFERP (end
->object
)
26805 && (end
->charpos
< start_charpos
26806 || end
->charpos
>= end_charpos
))
26808 x
+= end
->pixel_width
;
26811 hlinfo
->mouse_face_end_x
= x
;
26812 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26815 hlinfo
->mouse_face_window
= window
;
26816 hlinfo
->mouse_face_face_id
26817 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26819 !hlinfo
->mouse_face_hidden
, -1);
26820 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26823 /* The following function is not used anymore (replaced with
26824 mouse_face_from_string_pos), but I leave it here for the time
26825 being, in case someone would. */
26827 #if 0 /* not used */
26829 /* Find the position of the glyph for position POS in OBJECT in
26830 window W's current matrix, and return in *X, *Y the pixel
26831 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26833 RIGHT_P non-zero means return the position of the right edge of the
26834 glyph, RIGHT_P zero means return the left edge position.
26836 If no glyph for POS exists in the matrix, return the position of
26837 the glyph with the next smaller position that is in the matrix, if
26838 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26839 exists in the matrix, return the position of the glyph with the
26840 next larger position in OBJECT.
26842 Value is non-zero if a glyph was found. */
26845 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26846 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26848 int yb
= window_text_bottom_y (w
);
26849 struct glyph_row
*r
;
26850 struct glyph
*best_glyph
= NULL
;
26851 struct glyph_row
*best_row
= NULL
;
26854 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26855 r
->enabled_p
&& r
->y
< yb
;
26858 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26859 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26862 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26863 if (EQ (g
->object
, object
))
26865 if (g
->charpos
== pos
)
26872 else if (best_glyph
== NULL
26873 || ((eabs (g
->charpos
- pos
)
26874 < eabs (best_glyph
->charpos
- pos
))
26877 : g
->charpos
> pos
)))
26891 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26895 *x
+= best_glyph
->pixel_width
;
26900 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
26903 return best_glyph
!= NULL
;
26905 #endif /* not used */
26907 /* Find the positions of the first and the last glyphs in window W's
26908 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26909 (assumed to be a string), and return in HLINFO's mouse_face_*
26910 members the pixel and column/row coordinates of those glyphs. */
26913 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26914 Lisp_Object object
,
26915 ptrdiff_t startpos
, ptrdiff_t endpos
)
26917 int yb
= window_text_bottom_y (w
);
26918 struct glyph_row
*r
;
26919 struct glyph
*g
, *e
;
26923 /* Find the glyph row with at least one position in the range
26924 [STARTPOS..ENDPOS], and the first glyph in that row whose
26925 position belongs to that range. */
26926 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26927 r
->enabled_p
&& r
->y
< yb
;
26930 if (!r
->reversed_p
)
26932 g
= r
->glyphs
[TEXT_AREA
];
26933 e
= g
+ r
->used
[TEXT_AREA
];
26934 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26935 if (EQ (g
->object
, object
)
26936 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26938 hlinfo
->mouse_face_beg_row
26939 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
26940 hlinfo
->mouse_face_beg_y
= r
->y
;
26941 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26942 hlinfo
->mouse_face_beg_x
= gx
;
26951 e
= r
->glyphs
[TEXT_AREA
];
26952 g
= e
+ r
->used
[TEXT_AREA
];
26953 for ( ; g
> e
; --g
)
26954 if (EQ ((g
-1)->object
, object
)
26955 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26957 hlinfo
->mouse_face_beg_row
26958 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
26959 hlinfo
->mouse_face_beg_y
= r
->y
;
26960 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26961 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26962 gx
+= g1
->pixel_width
;
26963 hlinfo
->mouse_face_beg_x
= gx
;
26975 /* Starting with the next row, look for the first row which does NOT
26976 include any glyphs whose positions are in the range. */
26977 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26979 g
= r
->glyphs
[TEXT_AREA
];
26980 e
= g
+ r
->used
[TEXT_AREA
];
26982 for ( ; g
< e
; ++g
)
26983 if (EQ (g
->object
, object
)
26984 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26993 /* The highlighted region ends on the previous row. */
26996 /* Set the end row and its vertical pixel coordinate. */
26997 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
26998 hlinfo
->mouse_face_end_y
= r
->y
;
27000 /* Compute and set the end column and the end column's horizontal
27001 pixel coordinate. */
27002 if (!r
->reversed_p
)
27004 g
= r
->glyphs
[TEXT_AREA
];
27005 e
= g
+ r
->used
[TEXT_AREA
];
27006 for ( ; e
> g
; --e
)
27007 if (EQ ((e
-1)->object
, object
)
27008 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27010 hlinfo
->mouse_face_end_col
= e
- g
;
27012 for (gx
= r
->x
; g
< e
; ++g
)
27013 gx
+= g
->pixel_width
;
27014 hlinfo
->mouse_face_end_x
= gx
;
27018 e
= r
->glyphs
[TEXT_AREA
];
27019 g
= e
+ r
->used
[TEXT_AREA
];
27020 for (gx
= r
->x
; e
< g
; ++e
)
27022 if (EQ (e
->object
, object
)
27023 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27025 gx
+= e
->pixel_width
;
27027 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27028 hlinfo
->mouse_face_end_x
= gx
;
27032 #ifdef HAVE_WINDOW_SYSTEM
27034 /* See if position X, Y is within a hot-spot of an image. */
27037 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27039 if (!CONSP (hot_spot
))
27042 if (EQ (XCAR (hot_spot
), Qrect
))
27044 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27045 Lisp_Object rect
= XCDR (hot_spot
);
27049 if (!CONSP (XCAR (rect
)))
27051 if (!CONSP (XCDR (rect
)))
27053 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27055 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27057 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27059 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27063 else if (EQ (XCAR (hot_spot
), Qcircle
))
27065 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27066 Lisp_Object circ
= XCDR (hot_spot
);
27067 Lisp_Object lr
, lx0
, ly0
;
27069 && CONSP (XCAR (circ
))
27070 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27071 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27072 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27074 double r
= XFLOATINT (lr
);
27075 double dx
= XINT (lx0
) - x
;
27076 double dy
= XINT (ly0
) - y
;
27077 return (dx
* dx
+ dy
* dy
<= r
* r
);
27080 else if (EQ (XCAR (hot_spot
), Qpoly
))
27082 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27083 if (VECTORP (XCDR (hot_spot
)))
27085 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27086 Lisp_Object
*poly
= v
->contents
;
27087 ptrdiff_t n
= v
->header
.size
;
27090 Lisp_Object lx
, ly
;
27093 /* Need an even number of coordinates, and at least 3 edges. */
27094 if (n
< 6 || n
& 1)
27097 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27098 If count is odd, we are inside polygon. Pixels on edges
27099 may or may not be included depending on actual geometry of the
27101 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27102 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27104 x0
= XINT (lx
), y0
= XINT (ly
);
27105 for (i
= 0; i
< n
; i
+= 2)
27107 int x1
= x0
, y1
= y0
;
27108 if ((lx
= poly
[i
], !INTEGERP (lx
))
27109 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27111 x0
= XINT (lx
), y0
= XINT (ly
);
27113 /* Does this segment cross the X line? */
27121 if (y
> y0
&& y
> y1
)
27123 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27133 find_hot_spot (Lisp_Object map
, int x
, int y
)
27135 while (CONSP (map
))
27137 if (CONSP (XCAR (map
))
27138 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27146 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27148 doc
: /* Lookup in image map MAP coordinates X and Y.
27149 An image map is an alist where each element has the format (AREA ID PLIST).
27150 An AREA is specified as either a rectangle, a circle, or a polygon:
27151 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27152 pixel coordinates of the upper left and bottom right corners.
27153 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27154 and the radius of the circle; r may be a float or integer.
27155 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27156 vector describes one corner in the polygon.
27157 Returns the alist element for the first matching AREA in MAP. */)
27158 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27166 return find_hot_spot (map
,
27167 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27168 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27172 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27174 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27176 /* Do not change cursor shape while dragging mouse. */
27177 if (!NILP (do_mouse_tracking
))
27180 if (!NILP (pointer
))
27182 if (EQ (pointer
, Qarrow
))
27183 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27184 else if (EQ (pointer
, Qhand
))
27185 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27186 else if (EQ (pointer
, Qtext
))
27187 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27188 else if (EQ (pointer
, intern ("hdrag")))
27189 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27190 #ifdef HAVE_X_WINDOWS
27191 else if (EQ (pointer
, intern ("vdrag")))
27192 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27194 else if (EQ (pointer
, intern ("hourglass")))
27195 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27196 else if (EQ (pointer
, Qmodeline
))
27197 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27199 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27202 if (cursor
!= No_Cursor
)
27203 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27206 #endif /* HAVE_WINDOW_SYSTEM */
27208 /* Take proper action when mouse has moved to the mode or header line
27209 or marginal area AREA of window W, x-position X and y-position Y.
27210 X is relative to the start of the text display area of W, so the
27211 width of bitmap areas and scroll bars must be subtracted to get a
27212 position relative to the start of the mode line. */
27215 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27216 enum window_part area
)
27218 struct window
*w
= XWINDOW (window
);
27219 struct frame
*f
= XFRAME (w
->frame
);
27220 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27221 #ifdef HAVE_WINDOW_SYSTEM
27222 Display_Info
*dpyinfo
;
27224 Cursor cursor
= No_Cursor
;
27225 Lisp_Object pointer
= Qnil
;
27226 int dx
, dy
, width
, height
;
27228 Lisp_Object string
, object
= Qnil
;
27229 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27231 Lisp_Object mouse_face
;
27232 int original_x_pixel
= x
;
27233 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27234 struct glyph_row
*row
IF_LINT (= 0);
27236 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27241 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27242 returns them in row/column units! */
27243 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27244 &object
, &dx
, &dy
, &width
, &height
);
27246 row
= (area
== ON_MODE_LINE
27247 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27248 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27250 /* Find the glyph under the mouse pointer. */
27251 if (row
->mode_line_p
&& row
->enabled_p
)
27253 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27254 end
= glyph
+ row
->used
[TEXT_AREA
];
27256 for (x0
= original_x_pixel
;
27257 glyph
< end
&& x0
>= glyph
->pixel_width
;
27259 x0
-= glyph
->pixel_width
;
27267 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27268 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27269 returns them in row/column units! */
27270 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27271 &object
, &dx
, &dy
, &width
, &height
);
27276 #ifdef HAVE_WINDOW_SYSTEM
27277 if (IMAGEP (object
))
27279 Lisp_Object image_map
, hotspot
;
27280 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27282 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27284 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27288 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27289 If so, we could look for mouse-enter, mouse-leave
27290 properties in PLIST (and do something...). */
27291 hotspot
= XCDR (hotspot
);
27292 if (CONSP (hotspot
)
27293 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27295 pointer
= Fplist_get (plist
, Qpointer
);
27296 if (NILP (pointer
))
27298 help
= Fplist_get (plist
, Qhelp_echo
);
27301 help_echo_string
= help
;
27302 XSETWINDOW (help_echo_window
, w
);
27303 help_echo_object
= w
->contents
;
27304 help_echo_pos
= charpos
;
27308 if (NILP (pointer
))
27309 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27311 #endif /* HAVE_WINDOW_SYSTEM */
27313 if (STRINGP (string
))
27314 pos
= make_number (charpos
);
27316 /* Set the help text and mouse pointer. If the mouse is on a part
27317 of the mode line without any text (e.g. past the right edge of
27318 the mode line text), use the default help text and pointer. */
27319 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27321 /* Arrange to display the help by setting the global variables
27322 help_echo_string, help_echo_object, and help_echo_pos. */
27325 if (STRINGP (string
))
27326 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27330 help_echo_string
= help
;
27331 XSETWINDOW (help_echo_window
, w
);
27332 help_echo_object
= string
;
27333 help_echo_pos
= charpos
;
27335 else if (area
== ON_MODE_LINE
)
27337 Lisp_Object default_help
27338 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27341 if (STRINGP (default_help
))
27343 help_echo_string
= default_help
;
27344 XSETWINDOW (help_echo_window
, w
);
27345 help_echo_object
= Qnil
;
27346 help_echo_pos
= -1;
27351 #ifdef HAVE_WINDOW_SYSTEM
27352 /* Change the mouse pointer according to what is under it. */
27353 if (FRAME_WINDOW_P (f
))
27355 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27356 if (STRINGP (string
))
27358 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27360 if (NILP (pointer
))
27361 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27363 /* Change the mouse pointer according to what is under X/Y. */
27365 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27368 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27369 if (!KEYMAPP (map
))
27370 map
= Fget_text_property (pos
, Qkeymap
, string
);
27371 if (!KEYMAPP (map
))
27372 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27376 /* Default mode-line pointer. */
27377 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27382 /* Change the mouse face according to what is under X/Y. */
27383 if (STRINGP (string
))
27385 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27386 if (!NILP (mouse_face
)
27387 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27392 struct glyph
* tmp_glyph
;
27396 int total_pixel_width
;
27397 ptrdiff_t begpos
, endpos
, ignore
;
27401 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27402 Qmouse_face
, string
, Qnil
);
27408 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27410 endpos
= SCHARS (string
);
27414 /* Calculate the glyph position GPOS of GLYPH in the
27415 displayed string, relative to the beginning of the
27416 highlighted part of the string.
27418 Note: GPOS is different from CHARPOS. CHARPOS is the
27419 position of GLYPH in the internal string object. A mode
27420 line string format has structures which are converted to
27421 a flattened string by the Emacs Lisp interpreter. The
27422 internal string is an element of those structures. The
27423 displayed string is the flattened string. */
27424 tmp_glyph
= row_start_glyph
;
27425 while (tmp_glyph
< glyph
27426 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27427 && begpos
<= tmp_glyph
->charpos
27428 && tmp_glyph
->charpos
< endpos
)))
27430 gpos
= glyph
- tmp_glyph
;
27432 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27433 the highlighted part of the displayed string to which
27434 GLYPH belongs. Note: GSEQ_LENGTH is different from
27435 SCHARS (STRING), because the latter returns the length of
27436 the internal string. */
27437 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27439 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27440 && begpos
<= tmp_glyph
->charpos
27441 && tmp_glyph
->charpos
< endpos
));
27444 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27446 /* Calculate the total pixel width of all the glyphs between
27447 the beginning of the highlighted area and GLYPH. */
27448 total_pixel_width
= 0;
27449 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27450 total_pixel_width
+= tmp_glyph
->pixel_width
;
27452 /* Pre calculation of re-rendering position. Note: X is in
27453 column units here, after the call to mode_line_string or
27454 marginal_area_string. */
27456 vpos
= (area
== ON_MODE_LINE
27457 ? (w
->current_matrix
)->nrows
- 1
27460 /* If GLYPH's position is included in the region that is
27461 already drawn in mouse face, we have nothing to do. */
27462 if ( EQ (window
, hlinfo
->mouse_face_window
)
27463 && (!row
->reversed_p
27464 ? (hlinfo
->mouse_face_beg_col
<= hpos
27465 && hpos
< hlinfo
->mouse_face_end_col
)
27466 /* In R2L rows we swap BEG and END, see below. */
27467 : (hlinfo
->mouse_face_end_col
<= hpos
27468 && hpos
< hlinfo
->mouse_face_beg_col
))
27469 && hlinfo
->mouse_face_beg_row
== vpos
)
27472 if (clear_mouse_face (hlinfo
))
27473 cursor
= No_Cursor
;
27475 if (!row
->reversed_p
)
27477 hlinfo
->mouse_face_beg_col
= hpos
;
27478 hlinfo
->mouse_face_beg_x
= original_x_pixel
27479 - (total_pixel_width
+ dx
);
27480 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27481 hlinfo
->mouse_face_end_x
= 0;
27485 /* In R2L rows, show_mouse_face expects BEG and END
27486 coordinates to be swapped. */
27487 hlinfo
->mouse_face_end_col
= hpos
;
27488 hlinfo
->mouse_face_end_x
= original_x_pixel
27489 - (total_pixel_width
+ dx
);
27490 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27491 hlinfo
->mouse_face_beg_x
= 0;
27494 hlinfo
->mouse_face_beg_row
= vpos
;
27495 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27496 hlinfo
->mouse_face_beg_y
= 0;
27497 hlinfo
->mouse_face_end_y
= 0;
27498 hlinfo
->mouse_face_past_end
= 0;
27499 hlinfo
->mouse_face_window
= window
;
27501 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27507 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27509 if (NILP (pointer
))
27512 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27513 clear_mouse_face (hlinfo
);
27515 #ifdef HAVE_WINDOW_SYSTEM
27516 if (FRAME_WINDOW_P (f
))
27517 define_frame_cursor1 (f
, cursor
, pointer
);
27523 Take proper action when the mouse has moved to position X, Y on
27524 frame F as regards highlighting characters that have mouse-face
27525 properties. Also de-highlighting chars where the mouse was before.
27526 X and Y can be negative or out of range. */
27529 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27531 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27532 enum window_part part
= ON_NOTHING
;
27533 Lisp_Object window
;
27535 Cursor cursor
= No_Cursor
;
27536 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27539 /* When a menu is active, don't highlight because this looks odd. */
27540 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27541 if (popup_activated ())
27545 if (NILP (Vmouse_highlight
)
27546 || !f
->glyphs_initialized_p
27547 || f
->pointer_invisible
)
27550 hlinfo
->mouse_face_mouse_x
= x
;
27551 hlinfo
->mouse_face_mouse_y
= y
;
27552 hlinfo
->mouse_face_mouse_frame
= f
;
27554 if (hlinfo
->mouse_face_defer
)
27557 /* Which window is that in? */
27558 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27560 /* If displaying active text in another window, clear that. */
27561 if (! EQ (window
, hlinfo
->mouse_face_window
)
27562 /* Also clear if we move out of text area in same window. */
27563 || (!NILP (hlinfo
->mouse_face_window
)
27566 && part
!= ON_MODE_LINE
27567 && part
!= ON_HEADER_LINE
))
27568 clear_mouse_face (hlinfo
);
27570 /* Not on a window -> return. */
27571 if (!WINDOWP (window
))
27574 /* Reset help_echo_string. It will get recomputed below. */
27575 help_echo_string
= Qnil
;
27577 /* Convert to window-relative pixel coordinates. */
27578 w
= XWINDOW (window
);
27579 frame_to_window_pixel_xy (w
, &x
, &y
);
27581 #ifdef HAVE_WINDOW_SYSTEM
27582 /* Handle tool-bar window differently since it doesn't display a
27584 if (EQ (window
, f
->tool_bar_window
))
27586 note_tool_bar_highlight (f
, x
, y
);
27591 /* Mouse is on the mode, header line or margin? */
27592 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27593 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27595 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27599 #ifdef HAVE_WINDOW_SYSTEM
27600 if (part
== ON_VERTICAL_BORDER
)
27602 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27603 help_echo_string
= build_string ("drag-mouse-1: resize");
27605 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27606 || part
== ON_SCROLL_BAR
)
27607 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27609 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27612 /* Are we in a window whose display is up to date?
27613 And verify the buffer's text has not changed. */
27614 b
= XBUFFER (w
->contents
);
27615 if (part
== ON_TEXT
27616 && w
->window_end_valid
27617 && w
->last_modified
== BUF_MODIFF (b
)
27618 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27620 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27622 struct glyph
*glyph
;
27623 Lisp_Object object
;
27624 Lisp_Object mouse_face
= Qnil
, position
;
27625 Lisp_Object
*overlay_vec
= NULL
;
27626 ptrdiff_t i
, noverlays
;
27627 struct buffer
*obuf
;
27628 ptrdiff_t obegv
, ozv
;
27631 /* Find the glyph under X/Y. */
27632 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27634 #ifdef HAVE_WINDOW_SYSTEM
27635 /* Look for :pointer property on image. */
27636 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27638 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27639 if (img
!= NULL
&& IMAGEP (img
->spec
))
27641 Lisp_Object image_map
, hotspot
;
27642 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27644 && (hotspot
= find_hot_spot (image_map
,
27645 glyph
->slice
.img
.x
+ dx
,
27646 glyph
->slice
.img
.y
+ dy
),
27648 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27652 /* Could check XCAR (hotspot) to see if we enter/leave
27654 If so, we could look for mouse-enter, mouse-leave
27655 properties in PLIST (and do something...). */
27656 hotspot
= XCDR (hotspot
);
27657 if (CONSP (hotspot
)
27658 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27660 pointer
= Fplist_get (plist
, Qpointer
);
27661 if (NILP (pointer
))
27663 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27664 if (!NILP (help_echo_string
))
27666 help_echo_window
= window
;
27667 help_echo_object
= glyph
->object
;
27668 help_echo_pos
= glyph
->charpos
;
27672 if (NILP (pointer
))
27673 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27676 #endif /* HAVE_WINDOW_SYSTEM */
27678 /* Clear mouse face if X/Y not over text. */
27680 || area
!= TEXT_AREA
27681 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
27682 /* Glyph's OBJECT is an integer for glyphs inserted by the
27683 display engine for its internal purposes, like truncation
27684 and continuation glyphs and blanks beyond the end of
27685 line's text on text terminals. If we are over such a
27686 glyph, we are not over any text. */
27687 || INTEGERP (glyph
->object
)
27688 /* R2L rows have a stretch glyph at their front, which
27689 stands for no text, whereas L2R rows have no glyphs at
27690 all beyond the end of text. Treat such stretch glyphs
27691 like we do with NULL glyphs in L2R rows. */
27692 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27693 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
27694 && glyph
->type
== STRETCH_GLYPH
27695 && glyph
->avoid_cursor_p
))
27697 if (clear_mouse_face (hlinfo
))
27698 cursor
= No_Cursor
;
27699 #ifdef HAVE_WINDOW_SYSTEM
27700 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27702 if (area
!= TEXT_AREA
)
27703 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27705 pointer
= Vvoid_text_area_pointer
;
27711 pos
= glyph
->charpos
;
27712 object
= glyph
->object
;
27713 if (!STRINGP (object
) && !BUFFERP (object
))
27716 /* If we get an out-of-range value, return now; avoid an error. */
27717 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27720 /* Make the window's buffer temporarily current for
27721 overlays_at and compute_char_face. */
27722 obuf
= current_buffer
;
27723 current_buffer
= b
;
27729 /* Is this char mouse-active or does it have help-echo? */
27730 position
= make_number (pos
);
27732 if (BUFFERP (object
))
27734 /* Put all the overlays we want in a vector in overlay_vec. */
27735 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27736 /* Sort overlays into increasing priority order. */
27737 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27742 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27745 cursor
= No_Cursor
;
27747 /* Check mouse-face highlighting. */
27749 /* If there exists an overlay with mouse-face overlapping
27750 the one we are currently highlighting, we have to
27751 check if we enter the overlapping overlay, and then
27752 highlight only that. */
27753 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27754 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27756 /* Find the highest priority overlay with a mouse-face. */
27757 Lisp_Object overlay
= Qnil
;
27758 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27760 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27761 if (!NILP (mouse_face
))
27762 overlay
= overlay_vec
[i
];
27765 /* If we're highlighting the same overlay as before, there's
27766 no need to do that again. */
27767 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27768 goto check_help_echo
;
27769 hlinfo
->mouse_face_overlay
= overlay
;
27771 /* Clear the display of the old active region, if any. */
27772 if (clear_mouse_face (hlinfo
))
27773 cursor
= No_Cursor
;
27775 /* If no overlay applies, get a text property. */
27776 if (NILP (overlay
))
27777 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27779 /* Next, compute the bounds of the mouse highlighting and
27781 if (!NILP (mouse_face
) && STRINGP (object
))
27783 /* The mouse-highlighting comes from a display string
27784 with a mouse-face. */
27788 s
= Fprevious_single_property_change
27789 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27790 e
= Fnext_single_property_change
27791 (position
, Qmouse_face
, object
, Qnil
);
27793 s
= make_number (0);
27795 e
= make_number (SCHARS (object
) - 1);
27796 mouse_face_from_string_pos (w
, hlinfo
, object
,
27797 XINT (s
), XINT (e
));
27798 hlinfo
->mouse_face_past_end
= 0;
27799 hlinfo
->mouse_face_window
= window
;
27800 hlinfo
->mouse_face_face_id
27801 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27802 glyph
->face_id
, 1);
27803 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27804 cursor
= No_Cursor
;
27808 /* The mouse-highlighting, if any, comes from an overlay
27809 or text property in the buffer. */
27810 Lisp_Object buffer
IF_LINT (= Qnil
);
27811 Lisp_Object disp_string
IF_LINT (= Qnil
);
27813 if (STRINGP (object
))
27815 /* If we are on a display string with no mouse-face,
27816 check if the text under it has one. */
27817 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27818 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27819 pos
= string_buffer_position (object
, start
);
27822 mouse_face
= get_char_property_and_overlay
27823 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
27824 buffer
= w
->contents
;
27825 disp_string
= object
;
27831 disp_string
= Qnil
;
27834 if (!NILP (mouse_face
))
27836 Lisp_Object before
, after
;
27837 Lisp_Object before_string
, after_string
;
27838 /* To correctly find the limits of mouse highlight
27839 in a bidi-reordered buffer, we must not use the
27840 optimization of limiting the search in
27841 previous-single-property-change and
27842 next-single-property-change, because
27843 rows_from_pos_range needs the real start and end
27844 positions to DTRT in this case. That's because
27845 the first row visible in a window does not
27846 necessarily display the character whose position
27847 is the smallest. */
27849 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27850 ? Fmarker_position (w
->start
)
27853 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27854 ? make_number (BUF_Z (XBUFFER (buffer
))
27855 - XFASTINT (w
->window_end_pos
))
27858 if (NILP (overlay
))
27860 /* Handle the text property case. */
27861 before
= Fprevious_single_property_change
27862 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27863 after
= Fnext_single_property_change
27864 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27865 before_string
= after_string
= Qnil
;
27869 /* Handle the overlay case. */
27870 before
= Foverlay_start (overlay
);
27871 after
= Foverlay_end (overlay
);
27872 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27873 after_string
= Foverlay_get (overlay
, Qafter_string
);
27875 if (!STRINGP (before_string
)) before_string
= Qnil
;
27876 if (!STRINGP (after_string
)) after_string
= Qnil
;
27879 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27882 : XFASTINT (before
),
27884 ? BUF_Z (XBUFFER (buffer
))
27885 : XFASTINT (after
),
27886 before_string
, after_string
,
27888 cursor
= No_Cursor
;
27895 /* Look for a `help-echo' property. */
27896 if (NILP (help_echo_string
)) {
27897 Lisp_Object help
, overlay
;
27899 /* Check overlays first. */
27900 help
= overlay
= Qnil
;
27901 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27903 overlay
= overlay_vec
[i
];
27904 help
= Foverlay_get (overlay
, Qhelp_echo
);
27909 help_echo_string
= help
;
27910 help_echo_window
= window
;
27911 help_echo_object
= overlay
;
27912 help_echo_pos
= pos
;
27916 Lisp_Object obj
= glyph
->object
;
27917 ptrdiff_t charpos
= glyph
->charpos
;
27919 /* Try text properties. */
27922 && charpos
< SCHARS (obj
))
27924 help
= Fget_text_property (make_number (charpos
),
27928 /* If the string itself doesn't specify a help-echo,
27929 see if the buffer text ``under'' it does. */
27930 struct glyph_row
*r
27931 = MATRIX_ROW (w
->current_matrix
, vpos
);
27932 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27933 ptrdiff_t p
= string_buffer_position (obj
, start
);
27936 help
= Fget_char_property (make_number (p
),
27937 Qhelp_echo
, w
->contents
);
27946 else if (BUFFERP (obj
)
27949 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27954 help_echo_string
= help
;
27955 help_echo_window
= window
;
27956 help_echo_object
= obj
;
27957 help_echo_pos
= charpos
;
27962 #ifdef HAVE_WINDOW_SYSTEM
27963 /* Look for a `pointer' property. */
27964 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27966 /* Check overlays first. */
27967 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27968 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27970 if (NILP (pointer
))
27972 Lisp_Object obj
= glyph
->object
;
27973 ptrdiff_t charpos
= glyph
->charpos
;
27975 /* Try text properties. */
27978 && charpos
< SCHARS (obj
))
27980 pointer
= Fget_text_property (make_number (charpos
),
27982 if (NILP (pointer
))
27984 /* If the string itself doesn't specify a pointer,
27985 see if the buffer text ``under'' it does. */
27986 struct glyph_row
*r
27987 = MATRIX_ROW (w
->current_matrix
, vpos
);
27988 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27989 ptrdiff_t p
= string_buffer_position (obj
, start
);
27991 pointer
= Fget_char_property (make_number (p
),
27992 Qpointer
, w
->contents
);
27995 else if (BUFFERP (obj
)
27998 pointer
= Fget_text_property (make_number (charpos
),
28002 #endif /* HAVE_WINDOW_SYSTEM */
28006 current_buffer
= obuf
;
28011 #ifdef HAVE_WINDOW_SYSTEM
28012 if (FRAME_WINDOW_P (f
))
28013 define_frame_cursor1 (f
, cursor
, pointer
);
28015 /* This is here to prevent a compiler error, about "label at end of
28016 compound statement". */
28023 Clear any mouse-face on window W. This function is part of the
28024 redisplay interface, and is called from try_window_id and similar
28025 functions to ensure the mouse-highlight is off. */
28028 x_clear_window_mouse_face (struct window
*w
)
28030 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28031 Lisp_Object window
;
28034 XSETWINDOW (window
, w
);
28035 if (EQ (window
, hlinfo
->mouse_face_window
))
28036 clear_mouse_face (hlinfo
);
28042 Just discard the mouse face information for frame F, if any.
28043 This is used when the size of F is changed. */
28046 cancel_mouse_face (struct frame
*f
)
28048 Lisp_Object window
;
28049 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28051 window
= hlinfo
->mouse_face_window
;
28052 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28054 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28055 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28056 hlinfo
->mouse_face_window
= Qnil
;
28062 /***********************************************************************
28064 ***********************************************************************/
28066 #ifdef HAVE_WINDOW_SYSTEM
28068 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28069 which intersects rectangle R. R is in window-relative coordinates. */
28072 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28073 enum glyph_row_area area
)
28075 struct glyph
*first
= row
->glyphs
[area
];
28076 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28077 struct glyph
*last
;
28078 int first_x
, start_x
, x
;
28080 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28081 /* If row extends face to end of line write the whole line. */
28082 draw_glyphs (w
, 0, row
, area
,
28083 0, row
->used
[area
],
28084 DRAW_NORMAL_TEXT
, 0);
28087 /* Set START_X to the window-relative start position for drawing glyphs of
28088 AREA. The first glyph of the text area can be partially visible.
28089 The first glyphs of other areas cannot. */
28090 start_x
= window_box_left_offset (w
, area
);
28092 if (area
== TEXT_AREA
)
28095 /* Find the first glyph that must be redrawn. */
28097 && x
+ first
->pixel_width
< r
->x
)
28099 x
+= first
->pixel_width
;
28103 /* Find the last one. */
28107 && x
< r
->x
+ r
->width
)
28109 x
+= last
->pixel_width
;
28115 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28116 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28117 DRAW_NORMAL_TEXT
, 0);
28122 /* Redraw the parts of the glyph row ROW on window W intersecting
28123 rectangle R. R is in window-relative coordinates. Value is
28124 non-zero if mouse-face was overwritten. */
28127 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28129 eassert (row
->enabled_p
);
28131 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28132 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28133 0, row
->used
[TEXT_AREA
],
28134 DRAW_NORMAL_TEXT
, 0);
28137 if (row
->used
[LEFT_MARGIN_AREA
])
28138 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28139 if (row
->used
[TEXT_AREA
])
28140 expose_area (w
, row
, r
, TEXT_AREA
);
28141 if (row
->used
[RIGHT_MARGIN_AREA
])
28142 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28143 draw_row_fringe_bitmaps (w
, row
);
28146 return row
->mouse_face_p
;
28150 /* Redraw those parts of glyphs rows during expose event handling that
28151 overlap other rows. Redrawing of an exposed line writes over parts
28152 of lines overlapping that exposed line; this function fixes that.
28154 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28155 row in W's current matrix that is exposed and overlaps other rows.
28156 LAST_OVERLAPPING_ROW is the last such row. */
28159 expose_overlaps (struct window
*w
,
28160 struct glyph_row
*first_overlapping_row
,
28161 struct glyph_row
*last_overlapping_row
,
28164 struct glyph_row
*row
;
28166 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28167 if (row
->overlapping_p
)
28169 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28172 if (row
->used
[LEFT_MARGIN_AREA
])
28173 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28175 if (row
->used
[TEXT_AREA
])
28176 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28178 if (row
->used
[RIGHT_MARGIN_AREA
])
28179 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28185 /* Return non-zero if W's cursor intersects rectangle R. */
28188 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28190 XRectangle cr
, result
;
28191 struct glyph
*cursor_glyph
;
28192 struct glyph_row
*row
;
28194 if (w
->phys_cursor
.vpos
>= 0
28195 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28196 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28198 && row
->cursor_in_fringe_p
)
28200 /* Cursor is in the fringe. */
28201 cr
.x
= window_box_right_offset (w
,
28202 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28203 ? RIGHT_MARGIN_AREA
28206 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28207 cr
.height
= row
->height
;
28208 return x_intersect_rectangles (&cr
, r
, &result
);
28211 cursor_glyph
= get_phys_cursor_glyph (w
);
28214 /* r is relative to W's box, but w->phys_cursor.x is relative
28215 to left edge of W's TEXT area. Adjust it. */
28216 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28217 cr
.y
= w
->phys_cursor
.y
;
28218 cr
.width
= cursor_glyph
->pixel_width
;
28219 cr
.height
= w
->phys_cursor_height
;
28220 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28221 I assume the effect is the same -- and this is portable. */
28222 return x_intersect_rectangles (&cr
, r
, &result
);
28224 /* If we don't understand the format, pretend we're not in the hot-spot. */
28230 Draw a vertical window border to the right of window W if W doesn't
28231 have vertical scroll bars. */
28234 x_draw_vertical_border (struct window
*w
)
28236 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28238 /* We could do better, if we knew what type of scroll-bar the adjacent
28239 windows (on either side) have... But we don't :-(
28240 However, I think this works ok. ++KFS 2003-04-25 */
28242 /* Redraw borders between horizontally adjacent windows. Don't
28243 do it for frames with vertical scroll bars because either the
28244 right scroll bar of a window, or the left scroll bar of its
28245 neighbor will suffice as a border. */
28246 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28249 /* Note: It is necessary to redraw both the left and the right
28250 borders, for when only this single window W is being
28252 if (!WINDOW_RIGHTMOST_P (w
)
28253 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28255 int x0
, x1
, y0
, y1
;
28257 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28260 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28263 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28265 if (!WINDOW_LEFTMOST_P (w
)
28266 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28268 int x0
, x1
, y0
, y1
;
28270 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28273 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28276 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28281 /* Redraw the part of window W intersection rectangle FR. Pixel
28282 coordinates in FR are frame-relative. Call this function with
28283 input blocked. Value is non-zero if the exposure overwrites
28287 expose_window (struct window
*w
, XRectangle
*fr
)
28289 struct frame
*f
= XFRAME (w
->frame
);
28291 int mouse_face_overwritten_p
= 0;
28293 /* If window is not yet fully initialized, do nothing. This can
28294 happen when toolkit scroll bars are used and a window is split.
28295 Reconfiguring the scroll bar will generate an expose for a newly
28297 if (w
->current_matrix
== NULL
)
28300 /* When we're currently updating the window, display and current
28301 matrix usually don't agree. Arrange for a thorough display
28303 if (w
== updated_window
)
28305 SET_FRAME_GARBAGED (f
);
28309 /* Frame-relative pixel rectangle of W. */
28310 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28311 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28312 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28313 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28315 if (x_intersect_rectangles (fr
, &wr
, &r
))
28317 int yb
= window_text_bottom_y (w
);
28318 struct glyph_row
*row
;
28319 int cursor_cleared_p
, phys_cursor_on_p
;
28320 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28322 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28323 r
.x
, r
.y
, r
.width
, r
.height
));
28325 /* Convert to window coordinates. */
28326 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28327 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28329 /* Turn off the cursor. */
28330 if (!w
->pseudo_window_p
28331 && phys_cursor_in_rect_p (w
, &r
))
28333 x_clear_cursor (w
);
28334 cursor_cleared_p
= 1;
28337 cursor_cleared_p
= 0;
28339 /* If the row containing the cursor extends face to end of line,
28340 then expose_area might overwrite the cursor outside the
28341 rectangle and thus notice_overwritten_cursor might clear
28342 w->phys_cursor_on_p. We remember the original value and
28343 check later if it is changed. */
28344 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28346 /* Update lines intersecting rectangle R. */
28347 first_overlapping_row
= last_overlapping_row
= NULL
;
28348 for (row
= w
->current_matrix
->rows
;
28353 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28355 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28356 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28357 || (r
.y
>= y0
&& r
.y
< y1
)
28358 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28360 /* A header line may be overlapping, but there is no need
28361 to fix overlapping areas for them. KFS 2005-02-12 */
28362 if (row
->overlapping_p
&& !row
->mode_line_p
)
28364 if (first_overlapping_row
== NULL
)
28365 first_overlapping_row
= row
;
28366 last_overlapping_row
= row
;
28370 if (expose_line (w
, row
, &r
))
28371 mouse_face_overwritten_p
= 1;
28374 else if (row
->overlapping_p
)
28376 /* We must redraw a row overlapping the exposed area. */
28378 ? y0
+ row
->phys_height
> r
.y
28379 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28381 if (first_overlapping_row
== NULL
)
28382 first_overlapping_row
= row
;
28383 last_overlapping_row
= row
;
28391 /* Display the mode line if there is one. */
28392 if (WINDOW_WANTS_MODELINE_P (w
)
28393 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28395 && row
->y
< r
.y
+ r
.height
)
28397 if (expose_line (w
, row
, &r
))
28398 mouse_face_overwritten_p
= 1;
28401 if (!w
->pseudo_window_p
)
28403 /* Fix the display of overlapping rows. */
28404 if (first_overlapping_row
)
28405 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28408 /* Draw border between windows. */
28409 x_draw_vertical_border (w
);
28411 /* Turn the cursor on again. */
28412 if (cursor_cleared_p
28413 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28414 update_window_cursor (w
, 1);
28418 return mouse_face_overwritten_p
;
28423 /* Redraw (parts) of all windows in the window tree rooted at W that
28424 intersect R. R contains frame pixel coordinates. Value is
28425 non-zero if the exposure overwrites mouse-face. */
28428 expose_window_tree (struct window
*w
, XRectangle
*r
)
28430 struct frame
*f
= XFRAME (w
->frame
);
28431 int mouse_face_overwritten_p
= 0;
28433 while (w
&& !FRAME_GARBAGED_P (f
))
28435 if (WINDOWP (w
->contents
))
28436 mouse_face_overwritten_p
28437 |= expose_window_tree (XWINDOW (w
->contents
), r
);
28439 mouse_face_overwritten_p
|= expose_window (w
, r
);
28441 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28444 return mouse_face_overwritten_p
;
28449 Redisplay an exposed area of frame F. X and Y are the upper-left
28450 corner of the exposed rectangle. W and H are width and height of
28451 the exposed area. All are pixel values. W or H zero means redraw
28452 the entire frame. */
28455 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28458 int mouse_face_overwritten_p
= 0;
28460 TRACE ((stderr
, "expose_frame "));
28462 /* No need to redraw if frame will be redrawn soon. */
28463 if (FRAME_GARBAGED_P (f
))
28465 TRACE ((stderr
, " garbaged\n"));
28469 /* If basic faces haven't been realized yet, there is no point in
28470 trying to redraw anything. This can happen when we get an expose
28471 event while Emacs is starting, e.g. by moving another window. */
28472 if (FRAME_FACE_CACHE (f
) == NULL
28473 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28475 TRACE ((stderr
, " no faces\n"));
28479 if (w
== 0 || h
== 0)
28482 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28483 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28493 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28494 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28496 if (WINDOWP (f
->tool_bar_window
))
28497 mouse_face_overwritten_p
28498 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28500 #ifdef HAVE_X_WINDOWS
28502 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
28503 if (WINDOWP (f
->menu_bar_window
))
28504 mouse_face_overwritten_p
28505 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28506 #endif /* not USE_X_TOOLKIT and not USE_GTK */
28510 /* Some window managers support a focus-follows-mouse style with
28511 delayed raising of frames. Imagine a partially obscured frame,
28512 and moving the mouse into partially obscured mouse-face on that
28513 frame. The visible part of the mouse-face will be highlighted,
28514 then the WM raises the obscured frame. With at least one WM, KDE
28515 2.1, Emacs is not getting any event for the raising of the frame
28516 (even tried with SubstructureRedirectMask), only Expose events.
28517 These expose events will draw text normally, i.e. not
28518 highlighted. Which means we must redo the highlight here.
28519 Subsume it under ``we love X''. --gerd 2001-08-15 */
28520 /* Included in Windows version because Windows most likely does not
28521 do the right thing if any third party tool offers
28522 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28523 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28525 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28526 if (f
== hlinfo
->mouse_face_mouse_frame
)
28528 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28529 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28530 clear_mouse_face (hlinfo
);
28531 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28538 Determine the intersection of two rectangles R1 and R2. Return
28539 the intersection in *RESULT. Value is non-zero if RESULT is not
28543 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28545 XRectangle
*left
, *right
;
28546 XRectangle
*upper
, *lower
;
28547 int intersection_p
= 0;
28549 /* Rearrange so that R1 is the left-most rectangle. */
28551 left
= r1
, right
= r2
;
28553 left
= r2
, right
= r1
;
28555 /* X0 of the intersection is right.x0, if this is inside R1,
28556 otherwise there is no intersection. */
28557 if (right
->x
<= left
->x
+ left
->width
)
28559 result
->x
= right
->x
;
28561 /* The right end of the intersection is the minimum of
28562 the right ends of left and right. */
28563 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28566 /* Same game for Y. */
28568 upper
= r1
, lower
= r2
;
28570 upper
= r2
, lower
= r1
;
28572 /* The upper end of the intersection is lower.y0, if this is inside
28573 of upper. Otherwise, there is no intersection. */
28574 if (lower
->y
<= upper
->y
+ upper
->height
)
28576 result
->y
= lower
->y
;
28578 /* The lower end of the intersection is the minimum of the lower
28579 ends of upper and lower. */
28580 result
->height
= (min (lower
->y
+ lower
->height
,
28581 upper
->y
+ upper
->height
)
28583 intersection_p
= 1;
28587 return intersection_p
;
28590 #endif /* HAVE_WINDOW_SYSTEM */
28593 /***********************************************************************
28595 ***********************************************************************/
28598 syms_of_xdisp (void)
28600 Vwith_echo_area_save_vector
= Qnil
;
28601 staticpro (&Vwith_echo_area_save_vector
);
28603 Vmessage_stack
= Qnil
;
28604 staticpro (&Vmessage_stack
);
28606 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28607 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28609 message_dolog_marker1
= Fmake_marker ();
28610 staticpro (&message_dolog_marker1
);
28611 message_dolog_marker2
= Fmake_marker ();
28612 staticpro (&message_dolog_marker2
);
28613 message_dolog_marker3
= Fmake_marker ();
28614 staticpro (&message_dolog_marker3
);
28617 defsubr (&Sdump_frame_glyph_matrix
);
28618 defsubr (&Sdump_glyph_matrix
);
28619 defsubr (&Sdump_glyph_row
);
28620 defsubr (&Sdump_tool_bar_row
);
28621 defsubr (&Strace_redisplay
);
28622 defsubr (&Strace_to_stderr
);
28624 #ifdef HAVE_WINDOW_SYSTEM
28625 defsubr (&Stool_bar_lines_needed
);
28626 defsubr (&Slookup_image_map
);
28628 defsubr (&Sformat_mode_line
);
28629 defsubr (&Sinvisible_p
);
28630 defsubr (&Scurrent_bidi_paragraph_direction
);
28632 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28633 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28634 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28635 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28636 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28637 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28638 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28639 DEFSYM (Qeval
, "eval");
28640 DEFSYM (QCdata
, ":data");
28641 DEFSYM (Qdisplay
, "display");
28642 DEFSYM (Qspace_width
, "space-width");
28643 DEFSYM (Qraise
, "raise");
28644 DEFSYM (Qslice
, "slice");
28645 DEFSYM (Qspace
, "space");
28646 DEFSYM (Qmargin
, "margin");
28647 DEFSYM (Qpointer
, "pointer");
28648 DEFSYM (Qleft_margin
, "left-margin");
28649 DEFSYM (Qright_margin
, "right-margin");
28650 DEFSYM (Qcenter
, "center");
28651 DEFSYM (Qline_height
, "line-height");
28652 DEFSYM (QCalign_to
, ":align-to");
28653 DEFSYM (QCrelative_width
, ":relative-width");
28654 DEFSYM (QCrelative_height
, ":relative-height");
28655 DEFSYM (QCeval
, ":eval");
28656 DEFSYM (QCpropertize
, ":propertize");
28657 DEFSYM (QCfile
, ":file");
28658 DEFSYM (Qfontified
, "fontified");
28659 DEFSYM (Qfontification_functions
, "fontification-functions");
28660 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28661 DEFSYM (Qescape_glyph
, "escape-glyph");
28662 DEFSYM (Qnobreak_space
, "nobreak-space");
28663 DEFSYM (Qimage
, "image");
28664 DEFSYM (Qtext
, "text");
28665 DEFSYM (Qboth
, "both");
28666 DEFSYM (Qboth_horiz
, "both-horiz");
28667 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28668 DEFSYM (QCmap
, ":map");
28669 DEFSYM (QCpointer
, ":pointer");
28670 DEFSYM (Qrect
, "rect");
28671 DEFSYM (Qcircle
, "circle");
28672 DEFSYM (Qpoly
, "poly");
28673 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28674 DEFSYM (Qgrow_only
, "grow-only");
28675 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28676 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28677 DEFSYM (Qposition
, "position");
28678 DEFSYM (Qbuffer_position
, "buffer-position");
28679 DEFSYM (Qobject
, "object");
28680 DEFSYM (Qbar
, "bar");
28681 DEFSYM (Qhbar
, "hbar");
28682 DEFSYM (Qbox
, "box");
28683 DEFSYM (Qhollow
, "hollow");
28684 DEFSYM (Qhand
, "hand");
28685 DEFSYM (Qarrow
, "arrow");
28686 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28688 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28689 Fcons (intern_c_string ("void-variable"), Qnil
)),
28691 staticpro (&list_of_error
);
28693 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28694 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28695 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28696 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28698 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28699 staticpro (&echo_buffer
[0]);
28700 staticpro (&echo_buffer
[1]);
28702 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28703 staticpro (&echo_area_buffer
[0]);
28704 staticpro (&echo_area_buffer
[1]);
28706 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28707 staticpro (&Vmessages_buffer_name
);
28709 mode_line_proptrans_alist
= Qnil
;
28710 staticpro (&mode_line_proptrans_alist
);
28711 mode_line_string_list
= Qnil
;
28712 staticpro (&mode_line_string_list
);
28713 mode_line_string_face
= Qnil
;
28714 staticpro (&mode_line_string_face
);
28715 mode_line_string_face_prop
= Qnil
;
28716 staticpro (&mode_line_string_face_prop
);
28717 Vmode_line_unwind_vector
= Qnil
;
28718 staticpro (&Vmode_line_unwind_vector
);
28720 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28722 help_echo_string
= Qnil
;
28723 staticpro (&help_echo_string
);
28724 help_echo_object
= Qnil
;
28725 staticpro (&help_echo_object
);
28726 help_echo_window
= Qnil
;
28727 staticpro (&help_echo_window
);
28728 previous_help_echo_string
= Qnil
;
28729 staticpro (&previous_help_echo_string
);
28730 help_echo_pos
= -1;
28732 DEFSYM (Qright_to_left
, "right-to-left");
28733 DEFSYM (Qleft_to_right
, "left-to-right");
28735 #ifdef HAVE_WINDOW_SYSTEM
28736 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28737 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28738 For example, if a block cursor is over a tab, it will be drawn as
28739 wide as that tab on the display. */);
28740 x_stretch_cursor_p
= 0;
28743 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28744 doc
: /* Non-nil means highlight trailing whitespace.
28745 The face used for trailing whitespace is `trailing-whitespace'. */);
28746 Vshow_trailing_whitespace
= Qnil
;
28748 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28749 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28750 If the value is t, Emacs highlights non-ASCII chars which have the
28751 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28752 or `escape-glyph' face respectively.
28754 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28755 U+2011 (non-breaking hyphen) are affected.
28757 Any other non-nil value means to display these characters as a escape
28758 glyph followed by an ordinary space or hyphen.
28760 A value of nil means no special handling of these characters. */);
28761 Vnobreak_char_display
= Qt
;
28763 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28764 doc
: /* The pointer shape to show in void text areas.
28765 A value of nil means to show the text pointer. Other options are `arrow',
28766 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28767 Vvoid_text_area_pointer
= Qarrow
;
28769 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28770 doc
: /* Non-nil means don't actually do any redisplay.
28771 This is used for internal purposes. */);
28772 Vinhibit_redisplay
= Qnil
;
28774 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28775 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28776 Vglobal_mode_string
= Qnil
;
28778 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28779 doc
: /* Marker for where to display an arrow on top of the buffer text.
28780 This must be the beginning of a line in order to work.
28781 See also `overlay-arrow-string'. */);
28782 Voverlay_arrow_position
= Qnil
;
28784 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28785 doc
: /* String to display as an arrow in non-window frames.
28786 See also `overlay-arrow-position'. */);
28787 Voverlay_arrow_string
= build_pure_c_string ("=>");
28789 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28790 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28791 The symbols on this list are examined during redisplay to determine
28792 where to display overlay arrows. */);
28793 Voverlay_arrow_variable_list
28794 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28796 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28797 doc
: /* The number of lines to try scrolling a window by when point moves out.
28798 If that fails to bring point back on frame, point is centered instead.
28799 If this is zero, point is always centered after it moves off frame.
28800 If you want scrolling to always be a line at a time, you should set
28801 `scroll-conservatively' to a large value rather than set this to 1. */);
28803 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28804 doc
: /* Scroll up to this many lines, to bring point back on screen.
28805 If point moves off-screen, redisplay will scroll by up to
28806 `scroll-conservatively' lines in order to bring point just barely
28807 onto the screen again. If that cannot be done, then redisplay
28808 recenters point as usual.
28810 If the value is greater than 100, redisplay will never recenter point,
28811 but will always scroll just enough text to bring point into view, even
28812 if you move far away.
28814 A value of zero means always recenter point if it moves off screen. */);
28815 scroll_conservatively
= 0;
28817 DEFVAR_INT ("scroll-margin", scroll_margin
,
28818 doc
: /* Number of lines of margin at the top and bottom of a window.
28819 Recenter the window whenever point gets within this many lines
28820 of the top or bottom of the window. */);
28823 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28824 doc
: /* Pixels per inch value for non-window system displays.
28825 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28826 Vdisplay_pixels_per_inch
= make_float (72.0);
28829 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28832 DEFVAR_LISP ("truncate-partial-width-windows",
28833 Vtruncate_partial_width_windows
,
28834 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28835 For an integer value, truncate lines in each window narrower than the
28836 full frame width, provided the window width is less than that integer;
28837 otherwise, respect the value of `truncate-lines'.
28839 For any other non-nil value, truncate lines in all windows that do
28840 not span the full frame width.
28842 A value of nil means to respect the value of `truncate-lines'.
28844 If `word-wrap' is enabled, you might want to reduce this. */);
28845 Vtruncate_partial_width_windows
= make_number (50);
28847 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28848 doc
: /* Maximum buffer size for which line number should be displayed.
28849 If the buffer is bigger than this, the line number does not appear
28850 in the mode line. A value of nil means no limit. */);
28851 Vline_number_display_limit
= Qnil
;
28853 DEFVAR_INT ("line-number-display-limit-width",
28854 line_number_display_limit_width
,
28855 doc
: /* Maximum line width (in characters) for line number display.
28856 If the average length of the lines near point is bigger than this, then the
28857 line number may be omitted from the mode line. */);
28858 line_number_display_limit_width
= 200;
28860 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28861 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28862 highlight_nonselected_windows
= 0;
28864 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28865 doc
: /* Non-nil if more than one frame is visible on this display.
28866 Minibuffer-only frames don't count, but iconified frames do.
28867 This variable is not guaranteed to be accurate except while processing
28868 `frame-title-format' and `icon-title-format'. */);
28870 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28871 doc
: /* Template for displaying the title bar of visible frames.
28872 \(Assuming the window manager supports this feature.)
28874 This variable has the same structure as `mode-line-format', except that
28875 the %c and %l constructs are ignored. It is used only on frames for
28876 which no explicit name has been set \(see `modify-frame-parameters'). */);
28878 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28879 doc
: /* Template for displaying the title bar of an iconified frame.
28880 \(Assuming the window manager supports this feature.)
28881 This variable has the same structure as `mode-line-format' (which see),
28882 and is used only on frames for which no explicit name has been set
28883 \(see `modify-frame-parameters'). */);
28885 = Vframe_title_format
28886 = listn (CONSTYPE_PURE
, 3,
28887 intern_c_string ("multiple-frames"),
28888 build_pure_c_string ("%b"),
28889 listn (CONSTYPE_PURE
, 4,
28890 empty_unibyte_string
,
28891 intern_c_string ("invocation-name"),
28892 build_pure_c_string ("@"),
28893 intern_c_string ("system-name")));
28895 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28896 doc
: /* Maximum number of lines to keep in the message log buffer.
28897 If nil, disable message logging. If t, log messages but don't truncate
28898 the buffer when it becomes large. */);
28899 Vmessage_log_max
= make_number (1000);
28901 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28902 doc
: /* Functions called before redisplay, if window sizes have changed.
28903 The value should be a list of functions that take one argument.
28904 Just before redisplay, for each frame, if any of its windows have changed
28905 size since the last redisplay, or have been split or deleted,
28906 all the functions in the list are called, with the frame as argument. */);
28907 Vwindow_size_change_functions
= Qnil
;
28909 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28910 doc
: /* List of functions to call before redisplaying a window with scrolling.
28911 Each function is called with two arguments, the window and its new
28912 display-start position. Note that these functions are also called by
28913 `set-window-buffer'. Also note that the value of `window-end' is not
28914 valid when these functions are called.
28916 Warning: Do not use this feature to alter the way the window
28917 is scrolled. It is not designed for that, and such use probably won't
28919 Vwindow_scroll_functions
= Qnil
;
28921 DEFVAR_LISP ("window-text-change-functions",
28922 Vwindow_text_change_functions
,
28923 doc
: /* Functions to call in redisplay when text in the window might change. */);
28924 Vwindow_text_change_functions
= Qnil
;
28926 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28927 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28928 Each function is called with two arguments, the window and the end trigger value.
28929 See `set-window-redisplay-end-trigger'. */);
28930 Vredisplay_end_trigger_functions
= Qnil
;
28932 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28933 doc
: /* Non-nil means autoselect window with mouse pointer.
28934 If nil, do not autoselect windows.
28935 A positive number means delay autoselection by that many seconds: a
28936 window is autoselected only after the mouse has remained in that
28937 window for the duration of the delay.
28938 A negative number has a similar effect, but causes windows to be
28939 autoselected only after the mouse has stopped moving. \(Because of
28940 the way Emacs compares mouse events, you will occasionally wait twice
28941 that time before the window gets selected.\)
28942 Any other value means to autoselect window instantaneously when the
28943 mouse pointer enters it.
28945 Autoselection selects the minibuffer only if it is active, and never
28946 unselects the minibuffer if it is active.
28948 When customizing this variable make sure that the actual value of
28949 `focus-follows-mouse' matches the behavior of your window manager. */);
28950 Vmouse_autoselect_window
= Qnil
;
28952 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28953 doc
: /* Non-nil means automatically resize tool-bars.
28954 This dynamically changes the tool-bar's height to the minimum height
28955 that is needed to make all tool-bar items visible.
28956 If value is `grow-only', the tool-bar's height is only increased
28957 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28958 Vauto_resize_tool_bars
= Qt
;
28960 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28961 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28962 auto_raise_tool_bar_buttons_p
= 1;
28964 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28965 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28966 make_cursor_line_fully_visible_p
= 1;
28968 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28969 doc
: /* Border below tool-bar in pixels.
28970 If an integer, use it as the height of the border.
28971 If it is one of `internal-border-width' or `border-width', use the
28972 value of the corresponding frame parameter.
28973 Otherwise, no border is added below the tool-bar. */);
28974 Vtool_bar_border
= Qinternal_border_width
;
28976 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28977 doc
: /* Margin around tool-bar buttons in pixels.
28978 If an integer, use that for both horizontal and vertical margins.
28979 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28980 HORZ specifying the horizontal margin, and VERT specifying the
28981 vertical margin. */);
28982 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28984 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28985 doc
: /* Relief thickness of tool-bar buttons. */);
28986 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28988 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28989 doc
: /* Tool bar style to use.
28991 image - show images only
28992 text - show text only
28993 both - show both, text below image
28994 both-horiz - show text to the right of the image
28995 text-image-horiz - show text to the left of the image
28996 any other - use system default or image if no system default.
28998 This variable only affects the GTK+ toolkit version of Emacs. */);
28999 Vtool_bar_style
= Qnil
;
29001 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29002 doc
: /* Maximum number of characters a label can have to be shown.
29003 The tool bar style must also show labels for this to have any effect, see
29004 `tool-bar-style'. */);
29005 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29007 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29008 doc
: /* List of functions to call to fontify regions of text.
29009 Each function is called with one argument POS. Functions must
29010 fontify a region starting at POS in the current buffer, and give
29011 fontified regions the property `fontified'. */);
29012 Vfontification_functions
= Qnil
;
29013 Fmake_variable_buffer_local (Qfontification_functions
);
29015 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29016 unibyte_display_via_language_environment
,
29017 doc
: /* Non-nil means display unibyte text according to language environment.
29018 Specifically, this means that raw bytes in the range 160-255 decimal
29019 are displayed by converting them to the equivalent multibyte characters
29020 according to the current language environment. As a result, they are
29021 displayed according to the current fontset.
29023 Note that this variable affects only how these bytes are displayed,
29024 but does not change the fact they are interpreted as raw bytes. */);
29025 unibyte_display_via_language_environment
= 0;
29027 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29028 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29029 If a float, it specifies a fraction of the mini-window frame's height.
29030 If an integer, it specifies a number of lines. */);
29031 Vmax_mini_window_height
= make_float (0.25);
29033 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29034 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29035 A value of nil means don't automatically resize mini-windows.
29036 A value of t means resize them to fit the text displayed in them.
29037 A value of `grow-only', the default, means let mini-windows grow only;
29038 they return to their normal size when the minibuffer is closed, or the
29039 echo area becomes empty. */);
29040 Vresize_mini_windows
= Qgrow_only
;
29042 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29043 doc
: /* Alist specifying how to blink the cursor off.
29044 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29045 `cursor-type' frame-parameter or variable equals ON-STATE,
29046 comparing using `equal', Emacs uses OFF-STATE to specify
29047 how to blink it off. ON-STATE and OFF-STATE are values for
29048 the `cursor-type' frame parameter.
29050 If a frame's ON-STATE has no entry in this list,
29051 the frame's other specifications determine how to blink the cursor off. */);
29052 Vblink_cursor_alist
= Qnil
;
29054 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29055 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29056 If non-nil, windows are automatically scrolled horizontally to make
29057 point visible. */);
29058 automatic_hscrolling_p
= 1;
29059 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29061 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29062 doc
: /* How many columns away from the window edge point is allowed to get
29063 before automatic hscrolling will horizontally scroll the window. */);
29064 hscroll_margin
= 5;
29066 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29067 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29068 When point is less than `hscroll-margin' columns from the window
29069 edge, automatic hscrolling will scroll the window by the amount of columns
29070 determined by this variable. If its value is a positive integer, scroll that
29071 many columns. If it's a positive floating-point number, it specifies the
29072 fraction of the window's width to scroll. If it's nil or zero, point will be
29073 centered horizontally after the scroll. Any other value, including negative
29074 numbers, are treated as if the value were zero.
29076 Automatic hscrolling always moves point outside the scroll margin, so if
29077 point was more than scroll step columns inside the margin, the window will
29078 scroll more than the value given by the scroll step.
29080 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29081 and `scroll-right' overrides this variable's effect. */);
29082 Vhscroll_step
= make_number (0);
29084 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29085 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29086 Bind this around calls to `message' to let it take effect. */);
29087 message_truncate_lines
= 0;
29089 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29090 doc
: /* Normal hook run to update the menu bar definitions.
29091 Redisplay runs this hook before it redisplays the menu bar.
29092 This is used to update submenus such as Buffers,
29093 whose contents depend on various data. */);
29094 Vmenu_bar_update_hook
= Qnil
;
29096 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29097 doc
: /* Frame for which we are updating a menu.
29098 The enable predicate for a menu binding should check this variable. */);
29099 Vmenu_updating_frame
= Qnil
;
29101 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29102 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29103 inhibit_menubar_update
= 0;
29105 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29106 doc
: /* Prefix prepended to all continuation lines at display time.
29107 The value may be a string, an image, or a stretch-glyph; it is
29108 interpreted in the same way as the value of a `display' text property.
29110 This variable is overridden by any `wrap-prefix' text or overlay
29113 To add a prefix to non-continuation lines, use `line-prefix'. */);
29114 Vwrap_prefix
= Qnil
;
29115 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29116 Fmake_variable_buffer_local (Qwrap_prefix
);
29118 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29119 doc
: /* Prefix prepended to all non-continuation lines at display time.
29120 The value may be a string, an image, or a stretch-glyph; it is
29121 interpreted in the same way as the value of a `display' text property.
29123 This variable is overridden by any `line-prefix' text or overlay
29126 To add a prefix to continuation lines, use `wrap-prefix'. */);
29127 Vline_prefix
= Qnil
;
29128 DEFSYM (Qline_prefix
, "line-prefix");
29129 Fmake_variable_buffer_local (Qline_prefix
);
29131 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29132 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29133 inhibit_eval_during_redisplay
= 0;
29135 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29136 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29137 inhibit_free_realized_faces
= 0;
29140 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29141 doc
: /* Inhibit try_window_id display optimization. */);
29142 inhibit_try_window_id
= 0;
29144 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29145 doc
: /* Inhibit try_window_reusing display optimization. */);
29146 inhibit_try_window_reusing
= 0;
29148 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29149 doc
: /* Inhibit try_cursor_movement display optimization. */);
29150 inhibit_try_cursor_movement
= 0;
29151 #endif /* GLYPH_DEBUG */
29153 DEFVAR_INT ("overline-margin", overline_margin
,
29154 doc
: /* Space between overline and text, in pixels.
29155 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29156 margin to the character height. */);
29157 overline_margin
= 2;
29159 DEFVAR_INT ("underline-minimum-offset",
29160 underline_minimum_offset
,
29161 doc
: /* Minimum distance between baseline and underline.
29162 This can improve legibility of underlined text at small font sizes,
29163 particularly when using variable `x-use-underline-position-properties'
29164 with fonts that specify an UNDERLINE_POSITION relatively close to the
29165 baseline. The default value is 1. */);
29166 underline_minimum_offset
= 1;
29168 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29169 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29170 This feature only works when on a window system that can change
29171 cursor shapes. */);
29172 display_hourglass_p
= 1;
29174 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29175 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29176 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29178 hourglass_atimer
= NULL
;
29179 hourglass_shown_p
= 0;
29181 DEFSYM (Qglyphless_char
, "glyphless-char");
29182 DEFSYM (Qhex_code
, "hex-code");
29183 DEFSYM (Qempty_box
, "empty-box");
29184 DEFSYM (Qthin_space
, "thin-space");
29185 DEFSYM (Qzero_width
, "zero-width");
29187 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29188 /* Intern this now in case it isn't already done.
29189 Setting this variable twice is harmless.
29190 But don't staticpro it here--that is done in alloc.c. */
29191 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29192 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29194 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29195 doc
: /* Char-table defining glyphless characters.
29196 Each element, if non-nil, should be one of the following:
29197 an ASCII acronym string: display this string in a box
29198 `hex-code': display the hexadecimal code of a character in a box
29199 `empty-box': display as an empty box
29200 `thin-space': display as 1-pixel width space
29201 `zero-width': don't display
29202 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29203 display method for graphical terminals and text terminals respectively.
29204 GRAPHICAL and TEXT should each have one of the values listed above.
29206 The char-table has one extra slot to control the display of a character for
29207 which no font is found. This slot only takes effect on graphical terminals.
29208 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29209 `thin-space'. The default is `empty-box'. */);
29210 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29211 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29214 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29215 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29216 Vdebug_on_message
= Qnil
;
29220 /* Initialize this module when Emacs starts. */
29225 current_header_line_height
= current_mode_line_height
= -1;
29227 CHARPOS (this_line_start_pos
) = 0;
29229 if (!noninteractive
)
29231 struct window
*m
= XWINDOW (minibuf_window
);
29232 Lisp_Object frame
= m
->frame
;
29233 struct frame
*f
= XFRAME (frame
);
29234 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29235 struct window
*r
= XWINDOW (root
);
29238 echo_area_window
= minibuf_window
;
29240 r
->top_line
= FRAME_TOP_MARGIN (f
);
29241 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29242 r
->total_cols
= FRAME_COLS (f
);
29244 m
->top_line
= FRAME_LINES (f
) - 1;
29245 m
->total_lines
= 1;
29246 m
->total_cols
= FRAME_COLS (f
);
29248 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29249 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29250 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29252 /* The default ellipsis glyphs `...'. */
29253 for (i
= 0; i
< 3; ++i
)
29254 default_invis_vector
[i
] = make_number ('.');
29258 /* Allocate the buffer for frame titles.
29259 Also used for `format-mode-line'. */
29261 mode_line_noprop_buf
= xmalloc (size
);
29262 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29263 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29264 mode_line_target
= MODE_LINE_DISPLAY
;
29267 help_echo_showing_p
= 0;
29270 /* Platform-independent portion of hourglass implementation. */
29272 /* Cancel a currently active hourglass timer, and start a new one. */
29274 start_hourglass (void)
29276 #if defined (HAVE_WINDOW_SYSTEM)
29279 cancel_hourglass ();
29281 if (INTEGERP (Vhourglass_delay
)
29282 && XINT (Vhourglass_delay
) > 0)
29283 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29284 TYPE_MAXIMUM (time_t)),
29286 else if (FLOATP (Vhourglass_delay
)
29287 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29288 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29290 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29294 extern void w32_note_current_window (void);
29295 w32_note_current_window ();
29297 #endif /* HAVE_NTGUI */
29299 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29300 show_hourglass
, NULL
);
29305 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29308 cancel_hourglass (void)
29310 #if defined (HAVE_WINDOW_SYSTEM)
29311 if (hourglass_atimer
)
29313 cancel_atimer (hourglass_atimer
);
29314 hourglass_atimer
= NULL
;
29317 if (hourglass_shown_p
)