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_max_ascent
, 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 cursor_row_p (struct glyph_row
*);
798 static int redisplay_mode_lines (Lisp_Object
, int);
799 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
801 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
803 static void handle_line_prefix (struct it
*);
805 static void pint2str (char *, int, ptrdiff_t);
806 static void pint2hrstr (char *, int, ptrdiff_t);
807 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
809 static void reconsider_clip_changes (struct window
*, struct buffer
*);
810 static int text_outside_line_unchanged_p (struct window
*,
811 ptrdiff_t, ptrdiff_t);
812 static void store_mode_line_noprop_char (char);
813 static int store_mode_line_noprop (const char *, int, int);
814 static void handle_stop (struct it
*);
815 static void handle_stop_backwards (struct it
*, ptrdiff_t);
816 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
817 static void ensure_echo_area_buffers (void);
818 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
819 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
820 static int with_echo_area_buffer (struct window
*, int,
821 int (*) (ptrdiff_t, Lisp_Object
),
822 ptrdiff_t, Lisp_Object
);
823 static void clear_garbaged_frames (void);
824 static int current_message_1 (ptrdiff_t, Lisp_Object
);
825 static void pop_message (void);
826 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
827 static void set_message (Lisp_Object
);
828 static int set_message_1 (ptrdiff_t, Lisp_Object
);
829 static int display_echo_area (struct window
*);
830 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
831 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
832 static Lisp_Object
unwind_redisplay (Lisp_Object
);
833 static int string_char_and_length (const unsigned char *, int *);
834 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
836 static int compute_window_start_on_continuation_line (struct window
*);
837 static void insert_left_trunc_glyphs (struct it
*);
838 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
840 static void extend_face_to_end_of_line (struct it
*);
841 static int append_space_for_newline (struct it
*, int);
842 static int cursor_row_fully_visible_p (struct window
*, int, int);
843 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
844 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
845 static int trailing_whitespace_p (ptrdiff_t);
846 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
847 static void push_it (struct it
*, struct text_pos
*);
848 static void iterate_out_of_display_property (struct it
*);
849 static void pop_it (struct it
*);
850 static void sync_frame_with_window_matrix_rows (struct window
*);
851 static void redisplay_internal (void);
852 static int echo_area_display (int);
853 static void redisplay_windows (Lisp_Object
);
854 static void redisplay_window (Lisp_Object
, int);
855 static Lisp_Object
redisplay_window_error (Lisp_Object
);
856 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
857 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
858 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
859 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
861 static int update_menu_bar (struct frame
*, int, int);
862 static int try_window_reusing_current_matrix (struct window
*);
863 static int try_window_id (struct window
*);
864 static int display_line (struct it
*);
865 static int display_mode_lines (struct window
*);
866 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
867 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
868 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
869 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
870 static void display_menu_bar (struct window
*);
871 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
873 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
874 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
875 static void compute_line_metrics (struct it
*);
876 static void run_redisplay_end_trigger_hook (struct it
*);
877 static int get_overlay_strings (struct it
*, ptrdiff_t);
878 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
879 static void next_overlay_string (struct it
*);
880 static void reseat (struct it
*, struct text_pos
, int);
881 static void reseat_1 (struct it
*, struct text_pos
, int);
882 static void back_to_previous_visible_line_start (struct it
*);
883 void reseat_at_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 void move_it_vertically_backward (struct it
*, int);
903 static void get_visually_first_element (struct it
*);
904 static void init_to_row_start (struct it
*, struct window
*,
906 static int init_to_row_end (struct it
*, struct window
*,
908 static void back_to_previous_line_start (struct it
*);
909 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
910 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
911 Lisp_Object
, ptrdiff_t);
912 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
913 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
914 static ptrdiff_t number_of_chars (const char *, int);
915 static void compute_stop_pos (struct it
*);
916 static void compute_string_pos (struct text_pos
*, struct text_pos
,
918 static int face_before_or_after_it_pos (struct it
*, int);
919 static ptrdiff_t next_overlay_change (ptrdiff_t);
920 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
921 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
922 static int handle_single_display_spec (struct it
*, Lisp_Object
,
923 Lisp_Object
, Lisp_Object
,
924 struct text_pos
*, ptrdiff_t, int, int);
925 static int underlying_face_id (struct it
*);
926 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
929 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
930 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
932 #ifdef HAVE_WINDOW_SYSTEM
934 static void x_consider_frame_title (Lisp_Object
);
935 static int tool_bar_lines_needed (struct frame
*, int *);
936 static void update_tool_bar (struct frame
*, int);
937 static void build_desired_tool_bar_string (struct frame
*f
);
938 static int redisplay_tool_bar (struct frame
*);
939 static void display_tool_bar_line (struct it
*, int);
940 static void notice_overwritten_cursor (struct window
*,
943 static void append_stretch_glyph (struct it
*, Lisp_Object
,
947 #endif /* HAVE_WINDOW_SYSTEM */
949 static void produce_special_glyphs (struct it
*, enum display_element_type
);
950 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
951 static int coords_in_mouse_face_p (struct window
*, int, int);
955 /***********************************************************************
956 Window display dimensions
957 ***********************************************************************/
959 /* Return the bottom boundary y-position for text lines in window W.
960 This is the first y position at which a line cannot start.
961 It is relative to the top of the window.
963 This is the height of W minus the height of a mode line, if any. */
966 window_text_bottom_y (struct window
*w
)
968 int height
= WINDOW_TOTAL_HEIGHT (w
);
970 if (WINDOW_WANTS_MODELINE_P (w
))
971 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
975 /* Return the pixel width of display area AREA of window W. AREA < 0
976 means return the total width of W, not including fringes to
977 the left and right of the window. */
980 window_box_width (struct window
*w
, int area
)
982 int cols
= XFASTINT (w
->total_cols
);
985 if (!w
->pseudo_window_p
)
987 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
989 if (area
== TEXT_AREA
)
991 if (INTEGERP (w
->left_margin_cols
))
992 cols
-= XFASTINT (w
->left_margin_cols
);
993 if (INTEGERP (w
->right_margin_cols
))
994 cols
-= XFASTINT (w
->right_margin_cols
);
995 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
997 else if (area
== LEFT_MARGIN_AREA
)
999 cols
= (INTEGERP (w
->left_margin_cols
)
1000 ? XFASTINT (w
->left_margin_cols
) : 0);
1003 else if (area
== RIGHT_MARGIN_AREA
)
1005 cols
= (INTEGERP (w
->right_margin_cols
)
1006 ? XFASTINT (w
->right_margin_cols
) : 0);
1011 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1015 /* Return the pixel height of the display area of window W, not
1016 including mode lines of W, if any. */
1019 window_box_height (struct window
*w
)
1021 struct frame
*f
= XFRAME (w
->frame
);
1022 int height
= WINDOW_TOTAL_HEIGHT (w
);
1024 eassert (height
>= 0);
1026 /* Note: the code below that determines the mode-line/header-line
1027 height is essentially the same as that contained in the macro
1028 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1029 the appropriate glyph row has its `mode_line_p' flag set,
1030 and if it doesn't, uses estimate_mode_line_height instead. */
1032 if (WINDOW_WANTS_MODELINE_P (w
))
1034 struct glyph_row
*ml_row
1035 = (w
->current_matrix
&& w
->current_matrix
->rows
1036 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1038 if (ml_row
&& ml_row
->mode_line_p
)
1039 height
-= ml_row
->height
;
1041 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1044 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1046 struct glyph_row
*hl_row
1047 = (w
->current_matrix
&& w
->current_matrix
->rows
1048 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1050 if (hl_row
&& hl_row
->mode_line_p
)
1051 height
-= hl_row
->height
;
1053 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1056 /* With a very small font and a mode-line that's taller than
1057 default, we might end up with a negative height. */
1058 return max (0, height
);
1061 /* Return the window-relative coordinate of the left edge of display
1062 area AREA of window W. AREA < 0 means return the left edge of the
1063 whole window, to the right of the left fringe of W. */
1066 window_box_left_offset (struct window
*w
, int area
)
1070 if (w
->pseudo_window_p
)
1073 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1075 if (area
== TEXT_AREA
)
1076 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1077 + window_box_width (w
, LEFT_MARGIN_AREA
));
1078 else if (area
== RIGHT_MARGIN_AREA
)
1079 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1080 + window_box_width (w
, LEFT_MARGIN_AREA
)
1081 + window_box_width (w
, TEXT_AREA
)
1082 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1084 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1085 else if (area
== LEFT_MARGIN_AREA
1086 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1087 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1093 /* Return the window-relative coordinate of the right edge of display
1094 area AREA of window W. AREA < 0 means return the right edge of the
1095 whole window, to the left of the right fringe of W. */
1098 window_box_right_offset (struct window
*w
, int area
)
1100 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1103 /* Return the frame-relative coordinate of the left edge of display
1104 area AREA of window W. AREA < 0 means return the left edge of the
1105 whole window, to the right of the left fringe of W. */
1108 window_box_left (struct window
*w
, int area
)
1110 struct frame
*f
= XFRAME (w
->frame
);
1113 if (w
->pseudo_window_p
)
1114 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1116 x
= (WINDOW_LEFT_EDGE_X (w
)
1117 + window_box_left_offset (w
, area
));
1123 /* Return the frame-relative coordinate of the right edge of display
1124 area AREA of window W. AREA < 0 means return the right edge of the
1125 whole window, to the left of the right fringe of W. */
1128 window_box_right (struct window
*w
, int area
)
1130 return window_box_left (w
, area
) + window_box_width (w
, area
);
1133 /* Get the bounding box of the display area AREA of window W, without
1134 mode lines, in frame-relative coordinates. AREA < 0 means the
1135 whole window, not including the left and right fringes of
1136 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1137 coordinates of the upper-left corner of the box. Return in
1138 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1141 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1142 int *box_width
, int *box_height
)
1145 *box_width
= window_box_width (w
, area
);
1147 *box_height
= window_box_height (w
);
1149 *box_x
= window_box_left (w
, area
);
1152 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1153 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1154 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1159 /* Get the bounding box of the display area AREA of window W, without
1160 mode lines. AREA < 0 means the whole window, not including the
1161 left and right fringe of the window. Return in *TOP_LEFT_X
1162 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1163 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1164 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1168 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1169 int *bottom_right_x
, int *bottom_right_y
)
1171 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1173 *bottom_right_x
+= *top_left_x
;
1174 *bottom_right_y
+= *top_left_y
;
1179 /***********************************************************************
1181 ***********************************************************************/
1183 /* Return the bottom y-position of the line the iterator IT is in.
1184 This can modify IT's settings. */
1187 line_bottom_y (struct it
*it
)
1189 int line_height
= it
->max_ascent
+ it
->max_descent
;
1190 int line_top_y
= it
->current_y
;
1192 if (line_height
== 0)
1195 line_height
= last_height
;
1196 else if (IT_CHARPOS (*it
) < ZV
)
1198 move_it_by_lines (it
, 1);
1199 line_height
= (it
->max_ascent
|| it
->max_descent
1200 ? it
->max_ascent
+ it
->max_descent
1205 struct glyph_row
*row
= it
->glyph_row
;
1207 /* Use the default character height. */
1208 it
->glyph_row
= NULL
;
1209 it
->what
= IT_CHARACTER
;
1212 PRODUCE_GLYPHS (it
);
1213 line_height
= it
->ascent
+ it
->descent
;
1214 it
->glyph_row
= row
;
1218 return line_top_y
+ line_height
;
1221 /* Subroutine of pos_visible_p below. Extracts a display string, if
1222 any, from the display spec given as its argument. */
1224 string_from_display_spec (Lisp_Object spec
)
1228 while (CONSP (spec
))
1230 if (STRINGP (XCAR (spec
)))
1235 else if (VECTORP (spec
))
1239 for (i
= 0; i
< ASIZE (spec
); i
++)
1241 if (STRINGP (AREF (spec
, i
)))
1242 return AREF (spec
, i
);
1251 /* Limit insanely large values of W->hscroll on frame F to the largest
1252 value that will still prevent first_visible_x and last_visible_x of
1253 'struct it' from overflowing an int. */
1255 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1257 ptrdiff_t window_hscroll
= w
->hscroll
;
1258 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1259 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1261 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1262 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1264 return window_hscroll
;
1267 /* Return 1 if position CHARPOS is visible in window W.
1268 CHARPOS < 0 means return info about WINDOW_END position.
1269 If visible, set *X and *Y to pixel coordinates of top left corner.
1270 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1271 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1274 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1275 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1278 void *itdata
= bidi_shelve_cache ();
1279 struct text_pos top
;
1281 struct buffer
*old_buffer
= NULL
;
1283 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1286 if (XBUFFER (w
->buffer
) != current_buffer
)
1288 old_buffer
= current_buffer
;
1289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1292 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1293 /* Scrolling a minibuffer window via scroll bar when the echo area
1294 shows long text sometimes resets the minibuffer contents behind
1296 if (CHARPOS (top
) > ZV
)
1297 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1299 /* Compute exact mode line heights. */
1300 if (WINDOW_WANTS_MODELINE_P (w
))
1301 current_mode_line_height
1302 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1303 BVAR (current_buffer
, mode_line_format
));
1305 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1306 current_header_line_height
1307 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1308 BVAR (current_buffer
, header_line_format
));
1310 start_display (&it
, w
, top
);
1311 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1312 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1315 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1316 && IT_CHARPOS (it
) >= charpos
)
1317 /* When scanning backwards under bidi iteration, move_it_to
1318 stops at or _before_ CHARPOS, because it stops at or to
1319 the _right_ of the character at CHARPOS. */
1320 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1321 && IT_CHARPOS (it
) <= charpos
)))
1323 /* We have reached CHARPOS, or passed it. How the call to
1324 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1325 or covered by a display property, move_it_to stops at the end
1326 of the invisible text, to the right of CHARPOS. (ii) If
1327 CHARPOS is in a display vector, move_it_to stops on its last
1329 int top_x
= it
.current_x
;
1330 int top_y
= it
.current_y
;
1331 /* Calling line_bottom_y may change it.method, it.position, etc. */
1332 enum it_method it_method
= it
.method
;
1333 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1334 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1336 if (top_y
< window_top_y
)
1337 visible_p
= bottom_y
> window_top_y
;
1338 else if (top_y
< it
.last_visible_y
)
1340 if (bottom_y
>= it
.last_visible_y
1341 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1342 && IT_CHARPOS (it
) < charpos
)
1344 /* When the last line of the window is scanned backwards
1345 under bidi iteration, we could be duped into thinking
1346 that we have passed CHARPOS, when in fact move_it_to
1347 simply stopped short of CHARPOS because it reached
1348 last_visible_y. To see if that's what happened, we call
1349 move_it_to again with a slightly larger vertical limit,
1350 and see if it actually moved vertically; if it did, we
1351 didn't really reach CHARPOS, which is beyond window end. */
1352 struct it save_it
= it
;
1353 /* Why 10? because we don't know how many canonical lines
1354 will the height of the next line(s) be. So we guess. */
1355 int ten_more_lines
=
1356 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1358 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1359 MOVE_TO_POS
| MOVE_TO_Y
);
1360 if (it
.current_y
> top_y
)
1367 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1369 /* We stopped on the last glyph of a display vector.
1370 Try and recompute. Hack alert! */
1371 if (charpos
< 2 || top
.charpos
>= charpos
)
1372 top_x
= it
.glyph_row
->x
;
1376 start_display (&it2
, w
, top
);
1377 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1378 get_next_display_element (&it2
);
1379 PRODUCE_GLYPHS (&it2
);
1380 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1381 || it2
.current_x
> it2
.last_visible_x
)
1382 top_x
= it
.glyph_row
->x
;
1385 top_x
= it2
.current_x
;
1386 top_y
= it2
.current_y
;
1390 else if (IT_CHARPOS (it
) != charpos
)
1392 Lisp_Object cpos
= make_number (charpos
);
1393 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1394 Lisp_Object string
= string_from_display_spec (spec
);
1395 int newline_in_string
= 0;
1397 if (STRINGP (string
))
1399 const char *s
= SSDATA (string
);
1400 const char *e
= s
+ SBYTES (string
);
1405 newline_in_string
= 1;
1410 /* The tricky code below is needed because there's a
1411 discrepancy between move_it_to and how we set cursor
1412 when the display line ends in a newline from a
1413 display string. move_it_to will stop _after_ such
1414 display strings, whereas set_cursor_from_row
1415 conspires with cursor_row_p to place the cursor on
1416 the first glyph produced from the display string. */
1418 /* We have overshoot PT because it is covered by a
1419 display property whose value is a string. If the
1420 string includes embedded newlines, we are also in the
1421 wrong display line. Backtrack to the correct line,
1422 where the display string begins. */
1423 if (newline_in_string
)
1425 Lisp_Object startpos
, endpos
;
1426 EMACS_INT start
, end
;
1430 /* Find the first and the last buffer positions
1431 covered by the display string. */
1433 Fnext_single_char_property_change (cpos
, Qdisplay
,
1436 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1438 start
= XFASTINT (startpos
);
1439 end
= XFASTINT (endpos
);
1440 /* Move to the last buffer position before the
1441 display property. */
1442 start_display (&it3
, w
, top
);
1443 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1444 /* Move forward one more line if the position before
1445 the display string is a newline or if it is the
1446 rightmost character on a line that is
1447 continued or word-wrapped. */
1448 if (it3
.method
== GET_FROM_BUFFER
1450 move_it_by_lines (&it3
, 1);
1451 else if (move_it_in_display_line_to (&it3
, -1,
1455 == MOVE_LINE_CONTINUED
)
1457 move_it_by_lines (&it3
, 1);
1458 /* When we are under word-wrap, the #$@%!
1459 move_it_by_lines moves 2 lines, so we need to
1461 if (it3
.line_wrap
== WORD_WRAP
)
1462 move_it_by_lines (&it3
, -1);
1465 /* Record the vertical coordinate of the display
1466 line where we wound up. */
1467 top_y
= it3
.current_y
;
1470 /* When characters are reordered for display,
1471 the character displayed to the left of the
1472 display string could be _after_ the display
1473 property in the logical order. Use the
1474 smallest vertical position of these two. */
1475 start_display (&it3
, w
, top
);
1476 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1477 if (it3
.current_y
< top_y
)
1478 top_y
= it3
.current_y
;
1480 /* Move from the top of the window to the beginning
1481 of the display line where the display string
1483 start_display (&it3
, w
, top
);
1484 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1485 /* If it3_moved stays zero after the 'while' loop
1486 below, that means we already were at a newline
1487 before the loop (e.g., the display string begins
1488 with a newline), so we don't need to (and cannot)
1489 inspect the glyphs of it3.glyph_row, because
1490 PRODUCE_GLYPHS will not produce anything for a
1491 newline, and thus it3.glyph_row stays at its
1492 stale content it got at top of the window. */
1494 /* Finally, advance the iterator until we hit the
1495 first display element whose character position is
1496 CHARPOS, or until the first newline from the
1497 display string, which signals the end of the
1499 while (get_next_display_element (&it3
))
1501 PRODUCE_GLYPHS (&it3
);
1502 if (IT_CHARPOS (it3
) == charpos
1503 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1506 set_iterator_to_next (&it3
, 0);
1508 top_x
= it3
.current_x
- it3
.pixel_width
;
1509 /* Normally, we would exit the above loop because we
1510 found the display element whose character
1511 position is CHARPOS. For the contingency that we
1512 didn't, and stopped at the first newline from the
1513 display string, move back over the glyphs
1514 produced from the string, until we find the
1515 rightmost glyph not from the 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
, int 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
, int 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
2565 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
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 IT_CHARPOS (*it
) = charpos
;
2845 /* We will rely on `reseat' to set this up properly, via
2846 handle_face_prop. */
2847 it
->face_id
= it
->base_face_id
;
2849 /* Compute byte position if not specified. */
2850 if (bytepos
< charpos
)
2851 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2853 IT_BYTEPOS (*it
) = bytepos
;
2855 it
->start
= it
->current
;
2856 /* Do we need to reorder bidirectional text? Not if this is a
2857 unibyte buffer: by definition, none of the single-byte
2858 characters are strong R2L, so no reordering is needed. And
2859 bidi.c doesn't support unibyte buffers anyway. Also, don't
2860 reorder while we are loading loadup.el, since the tables of
2861 character properties needed for reordering are not yet
2865 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2868 /* If we are to reorder bidirectional text, init the bidi
2872 /* Note the paragraph direction that this buffer wants to
2874 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2876 it
->paragraph_embedding
= L2R
;
2877 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2879 it
->paragraph_embedding
= R2L
;
2881 it
->paragraph_embedding
= NEUTRAL_DIR
;
2882 bidi_unshelve_cache (NULL
, 0);
2883 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2887 /* Compute faces etc. */
2888 reseat (it
, it
->current
.pos
, 1);
2895 /* Initialize IT for the display of window W with window start POS. */
2898 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2900 struct glyph_row
*row
;
2901 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2903 row
= w
->desired_matrix
->rows
+ first_vpos
;
2904 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2905 it
->first_vpos
= first_vpos
;
2907 /* Don't reseat to previous visible line start if current start
2908 position is in a string or image. */
2909 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2911 int start_at_line_beg_p
;
2912 int first_y
= it
->current_y
;
2914 /* If window start is not at a line start, skip forward to POS to
2915 get the correct continuation lines width. */
2916 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2917 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2918 if (!start_at_line_beg_p
)
2922 reseat_at_previous_visible_line_start (it
);
2923 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2925 new_x
= it
->current_x
+ it
->pixel_width
;
2927 /* If lines are continued, this line may end in the middle
2928 of a multi-glyph character (e.g. a control character
2929 displayed as \003, or in the middle of an overlay
2930 string). In this case move_it_to above will not have
2931 taken us to the start of the continuation line but to the
2932 end of the continued line. */
2933 if (it
->current_x
> 0
2934 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2935 && (/* And glyph doesn't fit on the line. */
2936 new_x
> it
->last_visible_x
2937 /* Or it fits exactly and we're on a window
2939 || (new_x
== it
->last_visible_x
2940 && FRAME_WINDOW_P (it
->f
)
2941 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2942 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2943 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2945 if ((it
->current
.dpvec_index
>= 0
2946 || it
->current
.overlay_string_index
>= 0)
2947 /* If we are on a newline from a display vector or
2948 overlay string, then we are already at the end of
2949 a screen line; no need to go to the next line in
2950 that case, as this line is not really continued.
2951 (If we do go to the next line, C-e will not DTRT.) */
2954 set_iterator_to_next (it
, 1);
2955 move_it_in_display_line_to (it
, -1, -1, 0);
2958 it
->continuation_lines_width
+= it
->current_x
;
2960 /* If the character at POS is displayed via a display
2961 vector, move_it_to above stops at the final glyph of
2962 IT->dpvec. To make the caller redisplay that character
2963 again (a.k.a. start at POS), we need to reset the
2964 dpvec_index to the beginning of IT->dpvec. */
2965 else if (it
->current
.dpvec_index
>= 0)
2966 it
->current
.dpvec_index
= 0;
2968 /* We're starting a new display line, not affected by the
2969 height of the continued line, so clear the appropriate
2970 fields in the iterator structure. */
2971 it
->max_ascent
= it
->max_descent
= 0;
2972 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2974 it
->current_y
= first_y
;
2976 it
->current_x
= it
->hpos
= 0;
2982 /* Return 1 if POS is a position in ellipses displayed for invisible
2983 text. W is the window we display, for text property lookup. */
2986 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2988 Lisp_Object prop
, window
;
2990 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2992 /* If POS specifies a position in a display vector, this might
2993 be for an ellipsis displayed for invisible text. We won't
2994 get the iterator set up for delivering that ellipsis unless
2995 we make sure that it gets aware of the invisible text. */
2996 if (pos
->dpvec_index
>= 0
2997 && pos
->overlay_string_index
< 0
2998 && CHARPOS (pos
->string_pos
) < 0
3000 && (XSETWINDOW (window
, w
),
3001 prop
= Fget_char_property (make_number (charpos
),
3002 Qinvisible
, window
),
3003 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3005 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3007 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3014 /* Initialize IT for stepping through current_buffer in window W,
3015 starting at position POS that includes overlay string and display
3016 vector/ control character translation position information. Value
3017 is zero if there are overlay strings with newlines at POS. */
3020 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3022 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3023 int i
, overlay_strings_with_newlines
= 0;
3025 /* If POS specifies a position in a display vector, this might
3026 be for an ellipsis displayed for invisible text. We won't
3027 get the iterator set up for delivering that ellipsis unless
3028 we make sure that it gets aware of the invisible text. */
3029 if (in_ellipses_for_invisible_text_p (pos
, w
))
3035 /* Keep in mind: the call to reseat in init_iterator skips invisible
3036 text, so we might end up at a position different from POS. This
3037 is only a problem when POS is a row start after a newline and an
3038 overlay starts there with an after-string, and the overlay has an
3039 invisible property. Since we don't skip invisible text in
3040 display_line and elsewhere immediately after consuming the
3041 newline before the row start, such a POS will not be in a string,
3042 but the call to init_iterator below will move us to the
3044 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3046 /* This only scans the current chunk -- it should scan all chunks.
3047 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3048 to 16 in 22.1 to make this a lesser problem. */
3049 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3051 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3052 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3054 while (s
< e
&& *s
!= '\n')
3059 overlay_strings_with_newlines
= 1;
3064 /* If position is within an overlay string, set up IT to the right
3066 if (pos
->overlay_string_index
>= 0)
3070 /* If the first overlay string happens to have a `display'
3071 property for an image, the iterator will be set up for that
3072 image, and we have to undo that setup first before we can
3073 correct the overlay string index. */
3074 if (it
->method
== GET_FROM_IMAGE
)
3077 /* We already have the first chunk of overlay strings in
3078 IT->overlay_strings. Load more until the one for
3079 pos->overlay_string_index is in IT->overlay_strings. */
3080 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3082 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3083 it
->current
.overlay_string_index
= 0;
3086 load_overlay_strings (it
, 0);
3087 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3091 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3092 relative_index
= (it
->current
.overlay_string_index
3093 % OVERLAY_STRING_CHUNK_SIZE
);
3094 it
->string
= it
->overlay_strings
[relative_index
];
3095 eassert (STRINGP (it
->string
));
3096 it
->current
.string_pos
= pos
->string_pos
;
3097 it
->method
= GET_FROM_STRING
;
3098 it
->end_charpos
= SCHARS (it
->string
);
3099 /* Set up the bidi iterator for this overlay string. */
3102 it
->bidi_it
.string
.lstring
= it
->string
;
3103 it
->bidi_it
.string
.s
= NULL
;
3104 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3105 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3106 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3107 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3108 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3109 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3111 /* Synchronize the state of the bidi iterator with
3112 pos->string_pos. For any string position other than
3113 zero, this will be done automagically when we resume
3114 iteration over the string and get_visually_first_element
3115 is called. But if string_pos is zero, and the string is
3116 to be reordered for display, we need to resync manually,
3117 since it could be that the iteration state recorded in
3118 pos ended at string_pos of 0 moving backwards in string. */
3119 if (CHARPOS (pos
->string_pos
) == 0)
3121 get_visually_first_element (it
);
3122 if (IT_STRING_CHARPOS (*it
) != 0)
3125 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3126 bidi_move_to_visually_next (&it
->bidi_it
);
3127 } while (it
->bidi_it
.charpos
!= 0);
3129 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3130 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3134 if (CHARPOS (pos
->string_pos
) >= 0)
3136 /* Recorded position is not in an overlay string, but in another
3137 string. This can only be a string from a `display' property.
3138 IT should already be filled with that string. */
3139 it
->current
.string_pos
= pos
->string_pos
;
3140 eassert (STRINGP (it
->string
));
3142 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3143 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3146 /* Restore position in display vector translations, control
3147 character translations or ellipses. */
3148 if (pos
->dpvec_index
>= 0)
3150 if (it
->dpvec
== NULL
)
3151 get_next_display_element (it
);
3152 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3153 it
->current
.dpvec_index
= pos
->dpvec_index
;
3157 return !overlay_strings_with_newlines
;
3161 /* Initialize IT for stepping through current_buffer in window W
3162 starting at ROW->start. */
3165 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3167 init_from_display_pos (it
, w
, &row
->start
);
3168 it
->start
= row
->start
;
3169 it
->continuation_lines_width
= row
->continuation_lines_width
;
3174 /* Initialize IT for stepping through current_buffer in window W
3175 starting in the line following ROW, i.e. starting at ROW->end.
3176 Value is zero if there are overlay strings with newlines at ROW's
3180 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3184 if (init_from_display_pos (it
, w
, &row
->end
))
3186 if (row
->continued_p
)
3187 it
->continuation_lines_width
3188 = row
->continuation_lines_width
+ row
->pixel_width
;
3199 /***********************************************************************
3201 ***********************************************************************/
3203 /* Called when IT reaches IT->stop_charpos. Handle text property and
3204 overlay changes. Set IT->stop_charpos to the next position where
3208 handle_stop (struct it
*it
)
3210 enum prop_handled handled
;
3211 int handle_overlay_change_p
;
3215 it
->current
.dpvec_index
= -1;
3216 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3217 it
->ignore_overlay_strings_at_pos_p
= 0;
3220 /* Use face of preceding text for ellipsis (if invisible) */
3221 if (it
->selective_display_ellipsis_p
)
3222 it
->saved_face_id
= it
->face_id
;
3226 handled
= HANDLED_NORMALLY
;
3228 /* Call text property handlers. */
3229 for (p
= it_props
; p
->handler
; ++p
)
3231 handled
= p
->handler (it
);
3233 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3235 else if (handled
== HANDLED_RETURN
)
3237 /* We still want to show before and after strings from
3238 overlays even if the actual buffer text is replaced. */
3239 if (!handle_overlay_change_p
3241 /* Don't call get_overlay_strings_1 if we already
3242 have overlay strings loaded, because doing so
3243 will load them again and push the iterator state
3244 onto the stack one more time, which is not
3245 expected by the rest of the code that processes
3247 || (it
->current
.overlay_string_index
< 0
3248 ? !get_overlay_strings_1 (it
, 0, 0)
3252 setup_for_ellipsis (it
, 0);
3253 /* When handling a display spec, we might load an
3254 empty string. In that case, discard it here. We
3255 used to discard it in handle_single_display_spec,
3256 but that causes get_overlay_strings_1, above, to
3257 ignore overlay strings that we must check. */
3258 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3262 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3266 it
->ignore_overlay_strings_at_pos_p
= 1;
3267 it
->string_from_display_prop_p
= 0;
3268 it
->from_disp_prop_p
= 0;
3269 handle_overlay_change_p
= 0;
3271 handled
= HANDLED_RECOMPUTE_PROPS
;
3274 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3275 handle_overlay_change_p
= 0;
3278 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3280 /* Don't check for overlay strings below when set to deliver
3281 characters from a display vector. */
3282 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3283 handle_overlay_change_p
= 0;
3285 /* Handle overlay changes.
3286 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3287 if it finds overlays. */
3288 if (handle_overlay_change_p
)
3289 handled
= handle_overlay_change (it
);
3294 setup_for_ellipsis (it
, 0);
3298 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3300 /* Determine where to stop next. */
3301 if (handled
== HANDLED_NORMALLY
)
3302 compute_stop_pos (it
);
3306 /* Compute IT->stop_charpos from text property and overlay change
3307 information for IT's current position. */
3310 compute_stop_pos (struct it
*it
)
3312 register INTERVAL iv
, next_iv
;
3313 Lisp_Object object
, limit
, position
;
3314 ptrdiff_t charpos
, bytepos
;
3316 if (STRINGP (it
->string
))
3318 /* Strings are usually short, so don't limit the search for
3320 it
->stop_charpos
= it
->end_charpos
;
3321 object
= it
->string
;
3323 charpos
= IT_STRING_CHARPOS (*it
);
3324 bytepos
= IT_STRING_BYTEPOS (*it
);
3330 /* If end_charpos is out of range for some reason, such as a
3331 misbehaving display function, rationalize it (Bug#5984). */
3332 if (it
->end_charpos
> ZV
)
3333 it
->end_charpos
= ZV
;
3334 it
->stop_charpos
= it
->end_charpos
;
3336 /* If next overlay change is in front of the current stop pos
3337 (which is IT->end_charpos), stop there. Note: value of
3338 next_overlay_change is point-max if no overlay change
3340 charpos
= IT_CHARPOS (*it
);
3341 bytepos
= IT_BYTEPOS (*it
);
3342 pos
= next_overlay_change (charpos
);
3343 if (pos
< it
->stop_charpos
)
3344 it
->stop_charpos
= pos
;
3346 /* If showing the region, we have to stop at the region
3347 start or end because the face might change there. */
3348 if (it
->region_beg_charpos
> 0)
3350 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3351 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3352 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3353 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3356 /* Set up variables for computing the stop position from text
3357 property changes. */
3358 XSETBUFFER (object
, current_buffer
);
3359 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3362 /* Get the interval containing IT's position. Value is a null
3363 interval if there isn't such an interval. */
3364 position
= make_number (charpos
);
3365 iv
= validate_interval_range (object
, &position
, &position
, 0);
3368 Lisp_Object values_here
[LAST_PROP_IDX
];
3371 /* Get properties here. */
3372 for (p
= it_props
; p
->handler
; ++p
)
3373 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3375 /* Look for an interval following iv that has different
3377 for (next_iv
= next_interval (iv
);
3380 || XFASTINT (limit
) > next_iv
->position
));
3381 next_iv
= next_interval (next_iv
))
3383 for (p
= it_props
; p
->handler
; ++p
)
3385 Lisp_Object new_value
;
3387 new_value
= textget (next_iv
->plist
, *p
->name
);
3388 if (!EQ (values_here
[p
->idx
], new_value
))
3398 if (INTEGERP (limit
)
3399 && next_iv
->position
>= XFASTINT (limit
))
3400 /* No text property change up to limit. */
3401 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3403 /* Text properties change in next_iv. */
3404 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3408 if (it
->cmp_it
.id
< 0)
3410 ptrdiff_t stoppos
= it
->end_charpos
;
3412 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3414 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3415 stoppos
, it
->string
);
3418 eassert (STRINGP (it
->string
)
3419 || (it
->stop_charpos
>= BEGV
3420 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3424 /* Return the position of the next overlay change after POS in
3425 current_buffer. Value is point-max if no overlay change
3426 follows. This is like `next-overlay-change' but doesn't use
3430 next_overlay_change (ptrdiff_t pos
)
3432 ptrdiff_t i
, noverlays
;
3434 Lisp_Object
*overlays
;
3436 /* Get all overlays at the given position. */
3437 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3439 /* If any of these overlays ends before endpos,
3440 use its ending point instead. */
3441 for (i
= 0; i
< noverlays
; ++i
)
3446 oend
= OVERLAY_END (overlays
[i
]);
3447 oendpos
= OVERLAY_POSITION (oend
);
3448 endpos
= min (endpos
, oendpos
);
3454 /* How many characters forward to search for a display property or
3455 display string. Searching too far forward makes the bidi display
3456 sluggish, especially in small windows. */
3457 #define MAX_DISP_SCAN 250
3459 /* Return the character position of a display string at or after
3460 position specified by POSITION. If no display string exists at or
3461 after POSITION, return ZV. A display string is either an overlay
3462 with `display' property whose value is a string, or a `display'
3463 text property whose value is a string. STRING is data about the
3464 string to iterate; if STRING->lstring is nil, we are iterating a
3465 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3466 on a GUI frame. DISP_PROP is set to zero if we searched
3467 MAX_DISP_SCAN characters forward without finding any display
3468 strings, non-zero otherwise. It is set to 2 if the display string
3469 uses any kind of `(space ...)' spec that will produce a stretch of
3470 white space in the text area. */
3472 compute_display_string_pos (struct text_pos
*position
,
3473 struct bidi_string_data
*string
,
3474 int frame_window_p
, int *disp_prop
)
3476 /* OBJECT = nil means current buffer. */
3477 Lisp_Object object
=
3478 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3479 Lisp_Object pos
, spec
, limpos
;
3480 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3481 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3482 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3483 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3485 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3486 struct text_pos tpos
;
3492 /* We don't support display properties whose values are strings
3493 that have display string properties. */
3494 || string
->from_disp_str
3495 /* C strings cannot have display properties. */
3496 || (string
->s
&& !STRINGP (object
)))
3502 /* If the character at CHARPOS is where the display string begins,
3504 pos
= make_number (charpos
);
3505 if (STRINGP (object
))
3506 bufpos
= string
->bufpos
;
3510 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3512 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3515 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3523 /* Look forward for the first character with a `display' property
3524 that will replace the underlying text when displayed. */
3525 limpos
= make_number (lim
);
3527 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3528 CHARPOS (tpos
) = XFASTINT (pos
);
3529 if (CHARPOS (tpos
) >= lim
)
3534 if (STRINGP (object
))
3535 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3537 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3538 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3539 if (!STRINGP (object
))
3540 bufpos
= CHARPOS (tpos
);
3541 } while (NILP (spec
)
3542 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3543 bufpos
, frame_window_p
)));
3547 return CHARPOS (tpos
);
3550 /* Return the character position of the end of the display string that
3551 started at CHARPOS. If there's no display string at CHARPOS,
3552 return -1. A display string is either an overlay with `display'
3553 property whose value is a string or a `display' text property whose
3554 value is a string. */
3556 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3558 /* OBJECT = nil means current buffer. */
3559 Lisp_Object object
=
3560 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3561 Lisp_Object pos
= make_number (charpos
);
3563 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3565 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3568 /* It could happen that the display property or overlay was removed
3569 since we found it in compute_display_string_pos above. One way
3570 this can happen is if JIT font-lock was called (through
3571 handle_fontified_prop), and jit-lock-functions remove text
3572 properties or overlays from the portion of buffer that includes
3573 CHARPOS. Muse mode is known to do that, for example. In this
3574 case, we return -1 to the caller, to signal that no display
3575 string is actually present at CHARPOS. See bidi_fetch_char for
3576 how this is handled.
3578 An alternative would be to never look for display properties past
3579 it->stop_charpos. But neither compute_display_string_pos nor
3580 bidi_fetch_char that calls it know or care where the next
3582 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3585 /* Look forward for the first character where the `display' property
3587 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3589 return XFASTINT (pos
);
3594 /***********************************************************************
3596 ***********************************************************************/
3598 /* Handle changes in the `fontified' property of the current buffer by
3599 calling hook functions from Qfontification_functions to fontify
3602 static enum prop_handled
3603 handle_fontified_prop (struct it
*it
)
3605 Lisp_Object prop
, pos
;
3606 enum prop_handled handled
= HANDLED_NORMALLY
;
3608 if (!NILP (Vmemory_full
))
3611 /* Get the value of the `fontified' property at IT's current buffer
3612 position. (The `fontified' property doesn't have a special
3613 meaning in strings.) If the value is nil, call functions from
3614 Qfontification_functions. */
3615 if (!STRINGP (it
->string
)
3617 && !NILP (Vfontification_functions
)
3618 && !NILP (Vrun_hooks
)
3619 && (pos
= make_number (IT_CHARPOS (*it
)),
3620 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3621 /* Ignore the special cased nil value always present at EOB since
3622 no amount of fontifying will be able to change it. */
3623 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3625 ptrdiff_t count
= SPECPDL_INDEX ();
3627 struct buffer
*obuf
= current_buffer
;
3628 int begv
= BEGV
, zv
= ZV
;
3629 int old_clip_changed
= current_buffer
->clip_changed
;
3631 val
= Vfontification_functions
;
3632 specbind (Qfontification_functions
, Qnil
);
3634 eassert (it
->end_charpos
== ZV
);
3636 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3637 safe_call1 (val
, pos
);
3640 Lisp_Object fns
, fn
;
3641 struct gcpro gcpro1
, gcpro2
;
3646 for (; CONSP (val
); val
= XCDR (val
))
3652 /* A value of t indicates this hook has a local
3653 binding; it means to run the global binding too.
3654 In a global value, t should not occur. If it
3655 does, we must ignore it to avoid an endless
3657 for (fns
= Fdefault_value (Qfontification_functions
);
3663 safe_call1 (fn
, pos
);
3667 safe_call1 (fn
, pos
);
3673 unbind_to (count
, Qnil
);
3675 /* Fontification functions routinely call `save-restriction'.
3676 Normally, this tags clip_changed, which can confuse redisplay
3677 (see discussion in Bug#6671). Since we don't perform any
3678 special handling of fontification changes in the case where
3679 `save-restriction' isn't called, there's no point doing so in
3680 this case either. So, if the buffer's restrictions are
3681 actually left unchanged, reset clip_changed. */
3682 if (obuf
== current_buffer
)
3684 if (begv
== BEGV
&& zv
== ZV
)
3685 current_buffer
->clip_changed
= old_clip_changed
;
3687 /* There isn't much we can reasonably do to protect against
3688 misbehaving fontification, but here's a fig leaf. */
3689 else if (BUFFER_LIVE_P (obuf
))
3690 set_buffer_internal_1 (obuf
);
3692 /* The fontification code may have added/removed text.
3693 It could do even a lot worse, but let's at least protect against
3694 the most obvious case where only the text past `pos' gets changed',
3695 as is/was done in grep.el where some escapes sequences are turned
3696 into face properties (bug#7876). */
3697 it
->end_charpos
= ZV
;
3699 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3700 something. This avoids an endless loop if they failed to
3701 fontify the text for which reason ever. */
3702 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3703 handled
= HANDLED_RECOMPUTE_PROPS
;
3711 /***********************************************************************
3713 ***********************************************************************/
3715 /* Set up iterator IT from face properties at its current position.
3716 Called from handle_stop. */
3718 static enum prop_handled
3719 handle_face_prop (struct it
*it
)
3722 ptrdiff_t next_stop
;
3724 if (!STRINGP (it
->string
))
3727 = face_at_buffer_position (it
->w
,
3729 it
->region_beg_charpos
,
3730 it
->region_end_charpos
,
3733 + TEXT_PROP_DISTANCE_LIMIT
),
3734 0, it
->base_face_id
);
3736 /* Is this a start of a run of characters with box face?
3737 Caveat: this can be called for a freshly initialized
3738 iterator; face_id is -1 in this case. We know that the new
3739 face will not change until limit, i.e. if the new face has a
3740 box, all characters up to limit will have one. But, as
3741 usual, we don't know whether limit is really the end. */
3742 if (new_face_id
!= it
->face_id
)
3744 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3745 /* If it->face_id is -1, old_face below will be NULL, see
3746 the definition of FACE_FROM_ID. This will happen if this
3747 is the initial call that gets the face. */
3748 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3750 /* If the value of face_id of the iterator is -1, we have to
3751 look in front of IT's position and see whether there is a
3752 face there that's different from new_face_id. */
3753 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3755 int prev_face_id
= face_before_it_pos (it
);
3757 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3760 /* If the new face has a box, but the old face does not,
3761 this is the start of a run of characters with box face,
3762 i.e. this character has a shadow on the left side. */
3763 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3764 && (old_face
== NULL
|| !old_face
->box
));
3765 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3773 Lisp_Object from_overlay
3774 = (it
->current
.overlay_string_index
>= 0
3775 ? it
->string_overlays
[it
->current
.overlay_string_index
3776 % OVERLAY_STRING_CHUNK_SIZE
]
3779 /* See if we got to this string directly or indirectly from
3780 an overlay property. That includes the before-string or
3781 after-string of an overlay, strings in display properties
3782 provided by an overlay, their text properties, etc.
3784 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3785 if (! NILP (from_overlay
))
3786 for (i
= it
->sp
- 1; i
>= 0; i
--)
3788 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3790 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3791 % OVERLAY_STRING_CHUNK_SIZE
];
3792 else if (! NILP (it
->stack
[i
].from_overlay
))
3793 from_overlay
= it
->stack
[i
].from_overlay
;
3795 if (!NILP (from_overlay
))
3799 if (! NILP (from_overlay
))
3801 bufpos
= IT_CHARPOS (*it
);
3802 /* For a string from an overlay, the base face depends
3803 only on text properties and ignores overlays. */
3805 = face_for_overlay_string (it
->w
,
3807 it
->region_beg_charpos
,
3808 it
->region_end_charpos
,
3811 + TEXT_PROP_DISTANCE_LIMIT
),
3819 /* For strings from a `display' property, use the face at
3820 IT's current buffer position as the base face to merge
3821 with, so that overlay strings appear in the same face as
3822 surrounding text, unless they specify their own
3824 base_face_id
= it
->string_from_prefix_prop_p
3826 : underlying_face_id (it
);
3829 new_face_id
= face_at_string_position (it
->w
,
3831 IT_STRING_CHARPOS (*it
),
3833 it
->region_beg_charpos
,
3834 it
->region_end_charpos
,
3838 /* Is this a start of a run of characters with box? Caveat:
3839 this can be called for a freshly allocated iterator; face_id
3840 is -1 is this case. We know that the new face will not
3841 change until the next check pos, i.e. if the new face has a
3842 box, all characters up to that position will have a
3843 box. But, as usual, we don't know whether that position
3844 is really the end. */
3845 if (new_face_id
!= it
->face_id
)
3847 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3848 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3850 /* If new face has a box but old face hasn't, this is the
3851 start of a run of characters with box, i.e. it has a
3852 shadow on the left side. */
3853 it
->start_of_box_run_p
3854 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3855 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3859 it
->face_id
= new_face_id
;
3860 return HANDLED_NORMALLY
;
3864 /* Return the ID of the face ``underlying'' IT's current position,
3865 which is in a string. If the iterator is associated with a
3866 buffer, return the face at IT's current buffer position.
3867 Otherwise, use the iterator's base_face_id. */
3870 underlying_face_id (struct it
*it
)
3872 int face_id
= it
->base_face_id
, i
;
3874 eassert (STRINGP (it
->string
));
3876 for (i
= it
->sp
- 1; i
>= 0; --i
)
3877 if (NILP (it
->stack
[i
].string
))
3878 face_id
= it
->stack
[i
].face_id
;
3884 /* Compute the face one character before or after the current position
3885 of IT, in the visual order. BEFORE_P non-zero means get the face
3886 in front (to the left in L2R paragraphs, to the right in R2L
3887 paragraphs) of IT's screen position. Value is the ID of the face. */
3890 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3893 ptrdiff_t next_check_charpos
;
3895 void *it_copy_data
= NULL
;
3897 eassert (it
->s
== NULL
);
3899 if (STRINGP (it
->string
))
3901 ptrdiff_t bufpos
, charpos
;
3904 /* No face change past the end of the string (for the case
3905 we are padding with spaces). No face change before the
3907 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3908 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3913 /* Set charpos to the position before or after IT's current
3914 position, in the logical order, which in the non-bidi
3915 case is the same as the visual order. */
3917 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3918 else if (it
->what
== IT_COMPOSITION
)
3919 /* For composition, we must check the character after the
3921 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3923 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3929 /* With bidi iteration, the character before the current
3930 in the visual order cannot be found by simple
3931 iteration, because "reverse" reordering is not
3932 supported. Instead, we need to use the move_it_*
3933 family of functions. */
3934 /* Ignore face changes before the first visible
3935 character on this display line. */
3936 if (it
->current_x
<= it
->first_visible_x
)
3938 SAVE_IT (it_copy
, *it
, it_copy_data
);
3939 /* Implementation note: Since move_it_in_display_line
3940 works in the iterator geometry, and thinks the first
3941 character is always the leftmost, even in R2L lines,
3942 we don't need to distinguish between the R2L and L2R
3944 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3945 it_copy
.current_x
- 1, MOVE_TO_X
);
3946 charpos
= IT_STRING_CHARPOS (it_copy
);
3947 RESTORE_IT (it
, it
, it_copy_data
);
3951 /* Set charpos to the string position of the character
3952 that comes after IT's current position in the visual
3954 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3958 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3960 charpos
= it_copy
.bidi_it
.charpos
;
3963 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3965 if (it
->current
.overlay_string_index
>= 0)
3966 bufpos
= IT_CHARPOS (*it
);
3970 base_face_id
= underlying_face_id (it
);
3972 /* Get the face for ASCII, or unibyte. */
3973 face_id
= face_at_string_position (it
->w
,
3977 it
->region_beg_charpos
,
3978 it
->region_end_charpos
,
3979 &next_check_charpos
,
3982 /* Correct the face for charsets different from ASCII. Do it
3983 for the multibyte case only. The face returned above is
3984 suitable for unibyte text if IT->string is unibyte. */
3985 if (STRING_MULTIBYTE (it
->string
))
3987 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3988 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3990 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3992 c
= string_char_and_length (p
, &len
);
3993 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3998 struct text_pos pos
;
4000 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4001 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4004 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4005 pos
= it
->current
.pos
;
4010 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4013 if (it
->what
== IT_COMPOSITION
)
4015 /* For composition, we must check the position after
4017 pos
.charpos
+= it
->cmp_it
.nchars
;
4018 pos
.bytepos
+= it
->len
;
4021 INC_TEXT_POS (pos
, it
->multibyte_p
);
4028 /* With bidi iteration, the character before the current
4029 in the visual order cannot be found by simple
4030 iteration, because "reverse" reordering is not
4031 supported. Instead, we need to use the move_it_*
4032 family of functions. */
4033 /* Ignore face changes before the first visible
4034 character on this display line. */
4035 if (it
->current_x
<= it
->first_visible_x
)
4037 SAVE_IT (it_copy
, *it
, it_copy_data
);
4038 /* Implementation note: Since move_it_in_display_line
4039 works in the iterator geometry, and thinks the first
4040 character is always the leftmost, even in R2L lines,
4041 we don't need to distinguish between the R2L and L2R
4043 move_it_in_display_line (&it_copy
, ZV
,
4044 it_copy
.current_x
- 1, MOVE_TO_X
);
4045 pos
= it_copy
.current
.pos
;
4046 RESTORE_IT (it
, it
, it_copy_data
);
4050 /* Set charpos to the buffer position of the character
4051 that comes after IT's current position in the visual
4053 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4057 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4060 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4063 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4065 /* Determine face for CHARSET_ASCII, or unibyte. */
4066 face_id
= face_at_buffer_position (it
->w
,
4068 it
->region_beg_charpos
,
4069 it
->region_end_charpos
,
4070 &next_check_charpos
,
4073 /* Correct the face for charsets different from ASCII. Do it
4074 for the multibyte case only. The face returned above is
4075 suitable for unibyte text if current_buffer is unibyte. */
4076 if (it
->multibyte_p
)
4078 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4079 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4080 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4089 /***********************************************************************
4091 ***********************************************************************/
4093 /* Set up iterator IT from invisible properties at its current
4094 position. Called from handle_stop. */
4096 static enum prop_handled
4097 handle_invisible_prop (struct it
*it
)
4099 enum prop_handled handled
= HANDLED_NORMALLY
;
4103 if (STRINGP (it
->string
))
4105 Lisp_Object end_charpos
, limit
, charpos
;
4107 /* Get the value of the invisible text property at the
4108 current position. Value will be nil if there is no such
4110 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4111 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4112 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4114 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4116 /* Record whether we have to display an ellipsis for the
4118 int display_ellipsis_p
= (invis_p
== 2);
4119 ptrdiff_t len
, endpos
;
4121 handled
= HANDLED_RECOMPUTE_PROPS
;
4123 /* Get the position at which the next visible text can be
4124 found in IT->string, if any. */
4125 endpos
= len
= SCHARS (it
->string
);
4126 XSETINT (limit
, len
);
4129 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4131 if (INTEGERP (end_charpos
))
4133 endpos
= XFASTINT (end_charpos
);
4134 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4135 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4137 display_ellipsis_p
= 1;
4140 while (invis_p
&& endpos
< len
);
4142 if (display_ellipsis_p
)
4147 /* Text at END_CHARPOS is visible. Move IT there. */
4148 struct text_pos old
;
4151 old
= it
->current
.string_pos
;
4152 oldpos
= CHARPOS (old
);
4155 if (it
->bidi_it
.first_elt
4156 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4157 bidi_paragraph_init (it
->paragraph_embedding
,
4159 /* Bidi-iterate out of the invisible text. */
4162 bidi_move_to_visually_next (&it
->bidi_it
);
4164 while (oldpos
<= it
->bidi_it
.charpos
4165 && it
->bidi_it
.charpos
< endpos
);
4167 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4168 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4169 if (IT_CHARPOS (*it
) >= endpos
)
4170 it
->prev_stop
= endpos
;
4174 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4175 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4180 /* The rest of the string is invisible. If this is an
4181 overlay string, proceed with the next overlay string
4182 or whatever comes and return a character from there. */
4183 if (it
->current
.overlay_string_index
>= 0
4184 && !display_ellipsis_p
)
4186 next_overlay_string (it
);
4187 /* Don't check for overlay strings when we just
4188 finished processing them. */
4189 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4193 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4194 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4201 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4202 Lisp_Object pos
, overlay
;
4204 /* First of all, is there invisible text at this position? */
4205 tem
= start_charpos
= IT_CHARPOS (*it
);
4206 pos
= make_number (tem
);
4207 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4209 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4211 /* If we are on invisible text, skip over it. */
4212 if (invis_p
&& start_charpos
< it
->end_charpos
)
4214 /* Record whether we have to display an ellipsis for the
4216 int display_ellipsis_p
= invis_p
== 2;
4218 handled
= HANDLED_RECOMPUTE_PROPS
;
4220 /* Loop skipping over invisible text. The loop is left at
4221 ZV or with IT on the first char being visible again. */
4224 /* Try to skip some invisible text. Return value is the
4225 position reached which can be equal to where we start
4226 if there is nothing invisible there. This skips both
4227 over invisible text properties and overlays with
4228 invisible property. */
4229 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4231 /* If we skipped nothing at all we weren't at invisible
4232 text in the first place. If everything to the end of
4233 the buffer was skipped, end the loop. */
4234 if (newpos
== tem
|| newpos
>= ZV
)
4238 /* We skipped some characters but not necessarily
4239 all there are. Check if we ended up on visible
4240 text. Fget_char_property returns the property of
4241 the char before the given position, i.e. if we
4242 get invis_p = 0, this means that the char at
4243 newpos is visible. */
4244 pos
= make_number (newpos
);
4245 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4246 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4249 /* If we ended up on invisible text, proceed to
4250 skip starting with next_stop. */
4254 /* If there are adjacent invisible texts, don't lose the
4255 second one's ellipsis. */
4257 display_ellipsis_p
= 1;
4261 /* The position newpos is now either ZV or on visible text. */
4264 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4266 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4268 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4270 /* If the invisible text ends on a newline or on a
4271 character after a newline, we can avoid the costly,
4272 character by character, bidi iteration to NEWPOS, and
4273 instead simply reseat the iterator there. That's
4274 because all bidi reordering information is tossed at
4275 the newline. This is a big win for modes that hide
4276 complete lines, like Outline, Org, etc. */
4277 if (on_newline
|| after_newline
)
4279 struct text_pos tpos
;
4280 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4282 SET_TEXT_POS (tpos
, newpos
, bpos
);
4283 reseat_1 (it
, tpos
, 0);
4284 /* If we reseat on a newline/ZV, we need to prep the
4285 bidi iterator for advancing to the next character
4286 after the newline/EOB, keeping the current paragraph
4287 direction (so that PRODUCE_GLYPHS does TRT wrt
4288 prepending/appending glyphs to a glyph row). */
4291 it
->bidi_it
.first_elt
= 0;
4292 it
->bidi_it
.paragraph_dir
= pdir
;
4293 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4294 it
->bidi_it
.nchars
= 1;
4295 it
->bidi_it
.ch_len
= 1;
4298 else /* Must use the slow method. */
4300 /* With bidi iteration, the region of invisible text
4301 could start and/or end in the middle of a
4302 non-base embedding level. Therefore, we need to
4303 skip invisible text using the bidi iterator,
4304 starting at IT's current position, until we find
4305 ourselves outside of the invisible text.
4306 Skipping invisible text _after_ bidi iteration
4307 avoids affecting the visual order of the
4308 displayed text when invisible properties are
4309 added or removed. */
4310 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4312 /* If we were `reseat'ed to a new paragraph,
4313 determine the paragraph base direction. We
4314 need to do it now because
4315 next_element_from_buffer may not have a
4316 chance to do it, if we are going to skip any
4317 text at the beginning, which resets the
4319 bidi_paragraph_init (it
->paragraph_embedding
,
4324 bidi_move_to_visually_next (&it
->bidi_it
);
4326 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4327 && it
->bidi_it
.charpos
< newpos
);
4328 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4329 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4330 /* If we overstepped NEWPOS, record its position in
4331 the iterator, so that we skip invisible text if
4332 later the bidi iteration lands us in the
4333 invisible region again. */
4334 if (IT_CHARPOS (*it
) >= newpos
)
4335 it
->prev_stop
= newpos
;
4340 IT_CHARPOS (*it
) = newpos
;
4341 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4344 /* If there are before-strings at the start of invisible
4345 text, and the text is invisible because of a text
4346 property, arrange to show before-strings because 20.x did
4347 it that way. (If the text is invisible because of an
4348 overlay property instead of a text property, this is
4349 already handled in the overlay code.) */
4351 && get_overlay_strings (it
, it
->stop_charpos
))
4353 handled
= HANDLED_RECOMPUTE_PROPS
;
4354 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4356 else if (display_ellipsis_p
)
4358 /* Make sure that the glyphs of the ellipsis will get
4359 correct `charpos' values. If we would not update
4360 it->position here, the glyphs would belong to the
4361 last visible character _before_ the invisible
4362 text, which confuses `set_cursor_from_row'.
4364 We use the last invisible position instead of the
4365 first because this way the cursor is always drawn on
4366 the first "." of the ellipsis, whenever PT is inside
4367 the invisible text. Otherwise the cursor would be
4368 placed _after_ the ellipsis when the point is after the
4369 first invisible character. */
4370 if (!STRINGP (it
->object
))
4372 it
->position
.charpos
= newpos
- 1;
4373 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4376 /* Let the ellipsis display before
4377 considering any properties of the following char.
4378 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4379 handled
= HANDLED_RETURN
;
4388 /* Make iterator IT return `...' next.
4389 Replaces LEN characters from buffer. */
4392 setup_for_ellipsis (struct it
*it
, int len
)
4394 /* Use the display table definition for `...'. Invalid glyphs
4395 will be handled by the method returning elements from dpvec. */
4396 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4398 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4399 it
->dpvec
= v
->contents
;
4400 it
->dpend
= v
->contents
+ v
->header
.size
;
4404 /* Default `...'. */
4405 it
->dpvec
= default_invis_vector
;
4406 it
->dpend
= default_invis_vector
+ 3;
4409 it
->dpvec_char_len
= len
;
4410 it
->current
.dpvec_index
= 0;
4411 it
->dpvec_face_id
= -1;
4413 /* Remember the current face id in case glyphs specify faces.
4414 IT's face is restored in set_iterator_to_next.
4415 saved_face_id was set to preceding char's face in handle_stop. */
4416 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4417 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4419 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4425 /***********************************************************************
4427 ***********************************************************************/
4429 /* Set up iterator IT from `display' property at its current position.
4430 Called from handle_stop.
4431 We return HANDLED_RETURN if some part of the display property
4432 overrides the display of the buffer text itself.
4433 Otherwise we return HANDLED_NORMALLY. */
4435 static enum prop_handled
4436 handle_display_prop (struct it
*it
)
4438 Lisp_Object propval
, object
, overlay
;
4439 struct text_pos
*position
;
4441 /* Nonzero if some property replaces the display of the text itself. */
4442 int display_replaced_p
= 0;
4444 if (STRINGP (it
->string
))
4446 object
= it
->string
;
4447 position
= &it
->current
.string_pos
;
4448 bufpos
= CHARPOS (it
->current
.pos
);
4452 XSETWINDOW (object
, it
->w
);
4453 position
= &it
->current
.pos
;
4454 bufpos
= CHARPOS (*position
);
4457 /* Reset those iterator values set from display property values. */
4458 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4459 it
->space_width
= Qnil
;
4460 it
->font_height
= Qnil
;
4463 /* We don't support recursive `display' properties, i.e. string
4464 values that have a string `display' property, that have a string
4465 `display' property etc. */
4466 if (!it
->string_from_display_prop_p
)
4467 it
->area
= TEXT_AREA
;
4469 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4470 Qdisplay
, object
, &overlay
);
4472 return HANDLED_NORMALLY
;
4473 /* Now OVERLAY is the overlay that gave us this property, or nil
4474 if it was a text property. */
4476 if (!STRINGP (it
->string
))
4477 object
= it
->w
->buffer
;
4479 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4481 FRAME_WINDOW_P (it
->f
));
4483 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4486 /* Subroutine of handle_display_prop. Returns non-zero if the display
4487 specification in SPEC is a replacing specification, i.e. it would
4488 replace the text covered by `display' property with something else,
4489 such as an image or a display string. If SPEC includes any kind or
4490 `(space ...) specification, the value is 2; this is used by
4491 compute_display_string_pos, which see.
4493 See handle_single_display_spec for documentation of arguments.
4494 frame_window_p is non-zero if the window being redisplayed is on a
4495 GUI frame; this argument is used only if IT is NULL, see below.
4497 IT can be NULL, if this is called by the bidi reordering code
4498 through compute_display_string_pos, which see. In that case, this
4499 function only examines SPEC, but does not otherwise "handle" it, in
4500 the sense that it doesn't set up members of IT from the display
4503 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4504 Lisp_Object overlay
, struct text_pos
*position
,
4505 ptrdiff_t bufpos
, int frame_window_p
)
4507 int replacing_p
= 0;
4511 /* Simple specifications. */
4512 && !EQ (XCAR (spec
), Qimage
)
4513 && !EQ (XCAR (spec
), Qspace
)
4514 && !EQ (XCAR (spec
), Qwhen
)
4515 && !EQ (XCAR (spec
), Qslice
)
4516 && !EQ (XCAR (spec
), Qspace_width
)
4517 && !EQ (XCAR (spec
), Qheight
)
4518 && !EQ (XCAR (spec
), Qraise
)
4519 /* Marginal area specifications. */
4520 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4521 && !EQ (XCAR (spec
), Qleft_fringe
)
4522 && !EQ (XCAR (spec
), Qright_fringe
)
4523 && !NILP (XCAR (spec
)))
4525 for (; CONSP (spec
); spec
= XCDR (spec
))
4527 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4528 overlay
, position
, bufpos
,
4529 replacing_p
, frame_window_p
)))
4532 /* If some text in a string is replaced, `position' no
4533 longer points to the position of `object'. */
4534 if (!it
|| STRINGP (object
))
4539 else if (VECTORP (spec
))
4542 for (i
= 0; i
< ASIZE (spec
); ++i
)
4543 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4544 overlay
, position
, bufpos
,
4545 replacing_p
, frame_window_p
)))
4548 /* If some text in a string is replaced, `position' no
4549 longer points to the position of `object'. */
4550 if (!it
|| STRINGP (object
))
4556 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4557 position
, bufpos
, 0,
4565 /* Value is the position of the end of the `display' property starting
4566 at START_POS in OBJECT. */
4568 static struct text_pos
4569 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4572 struct text_pos end_pos
;
4574 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4575 Qdisplay
, object
, Qnil
);
4576 CHARPOS (end_pos
) = XFASTINT (end
);
4577 if (STRINGP (object
))
4578 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4580 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4586 /* Set up IT from a single `display' property specification SPEC. OBJECT
4587 is the object in which the `display' property was found. *POSITION
4588 is the position in OBJECT at which the `display' property was found.
4589 BUFPOS is the buffer position of OBJECT (different from POSITION if
4590 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4591 previously saw a display specification which already replaced text
4592 display with something else, for example an image; we ignore such
4593 properties after the first one has been processed.
4595 OVERLAY is the overlay this `display' property came from,
4596 or nil if it was a text property.
4598 If SPEC is a `space' or `image' specification, and in some other
4599 cases too, set *POSITION to the position where the `display'
4602 If IT is NULL, only examine the property specification in SPEC, but
4603 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4604 is intended to be displayed in a window on a GUI frame.
4606 Value is non-zero if something was found which replaces the display
4607 of buffer or string text. */
4610 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4611 Lisp_Object overlay
, struct text_pos
*position
,
4612 ptrdiff_t bufpos
, int display_replaced_p
,
4616 Lisp_Object location
, value
;
4617 struct text_pos start_pos
= *position
;
4620 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4621 If the result is non-nil, use VALUE instead of SPEC. */
4623 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4632 if (!NILP (form
) && !EQ (form
, Qt
))
4634 ptrdiff_t count
= SPECPDL_INDEX ();
4635 struct gcpro gcpro1
;
4637 /* Bind `object' to the object having the `display' property, a
4638 buffer or string. Bind `position' to the position in the
4639 object where the property was found, and `buffer-position'
4640 to the current position in the buffer. */
4643 XSETBUFFER (object
, current_buffer
);
4644 specbind (Qobject
, object
);
4645 specbind (Qposition
, make_number (CHARPOS (*position
)));
4646 specbind (Qbuffer_position
, make_number (bufpos
));
4648 form
= safe_eval (form
);
4650 unbind_to (count
, Qnil
);
4656 /* Handle `(height HEIGHT)' specifications. */
4658 && EQ (XCAR (spec
), Qheight
)
4659 && CONSP (XCDR (spec
)))
4663 if (!FRAME_WINDOW_P (it
->f
))
4666 it
->font_height
= XCAR (XCDR (spec
));
4667 if (!NILP (it
->font_height
))
4669 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4670 int new_height
= -1;
4672 if (CONSP (it
->font_height
)
4673 && (EQ (XCAR (it
->font_height
), Qplus
)
4674 || EQ (XCAR (it
->font_height
), Qminus
))
4675 && CONSP (XCDR (it
->font_height
))
4676 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4678 /* `(+ N)' or `(- N)' where N is an integer. */
4679 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4680 if (EQ (XCAR (it
->font_height
), Qplus
))
4682 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4684 else if (FUNCTIONP (it
->font_height
))
4686 /* Call function with current height as argument.
4687 Value is the new height. */
4689 height
= safe_call1 (it
->font_height
,
4690 face
->lface
[LFACE_HEIGHT_INDEX
]);
4691 if (NUMBERP (height
))
4692 new_height
= XFLOATINT (height
);
4694 else if (NUMBERP (it
->font_height
))
4696 /* Value is a multiple of the canonical char height. */
4699 f
= FACE_FROM_ID (it
->f
,
4700 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4701 new_height
= (XFLOATINT (it
->font_height
)
4702 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4706 /* Evaluate IT->font_height with `height' bound to the
4707 current specified height to get the new height. */
4708 ptrdiff_t count
= SPECPDL_INDEX ();
4710 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4711 value
= safe_eval (it
->font_height
);
4712 unbind_to (count
, Qnil
);
4714 if (NUMBERP (value
))
4715 new_height
= XFLOATINT (value
);
4719 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4726 /* Handle `(space-width WIDTH)'. */
4728 && EQ (XCAR (spec
), Qspace_width
)
4729 && CONSP (XCDR (spec
)))
4733 if (!FRAME_WINDOW_P (it
->f
))
4736 value
= XCAR (XCDR (spec
));
4737 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4738 it
->space_width
= value
;
4744 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4746 && EQ (XCAR (spec
), Qslice
))
4752 if (!FRAME_WINDOW_P (it
->f
))
4755 if (tem
= XCDR (spec
), CONSP (tem
))
4757 it
->slice
.x
= XCAR (tem
);
4758 if (tem
= XCDR (tem
), CONSP (tem
))
4760 it
->slice
.y
= XCAR (tem
);
4761 if (tem
= XCDR (tem
), CONSP (tem
))
4763 it
->slice
.width
= XCAR (tem
);
4764 if (tem
= XCDR (tem
), CONSP (tem
))
4765 it
->slice
.height
= XCAR (tem
);
4774 /* Handle `(raise FACTOR)'. */
4776 && EQ (XCAR (spec
), Qraise
)
4777 && CONSP (XCDR (spec
)))
4781 if (!FRAME_WINDOW_P (it
->f
))
4784 #ifdef HAVE_WINDOW_SYSTEM
4785 value
= XCAR (XCDR (spec
));
4786 if (NUMBERP (value
))
4788 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4789 it
->voffset
= - (XFLOATINT (value
)
4790 * (FONT_HEIGHT (face
->font
)));
4792 #endif /* HAVE_WINDOW_SYSTEM */
4798 /* Don't handle the other kinds of display specifications
4799 inside a string that we got from a `display' property. */
4800 if (it
&& it
->string_from_display_prop_p
)
4803 /* Characters having this form of property are not displayed, so
4804 we have to find the end of the property. */
4807 start_pos
= *position
;
4808 *position
= display_prop_end (it
, object
, start_pos
);
4812 /* Stop the scan at that end position--we assume that all
4813 text properties change there. */
4815 it
->stop_charpos
= position
->charpos
;
4817 /* Handle `(left-fringe BITMAP [FACE])'
4818 and `(right-fringe BITMAP [FACE])'. */
4820 && (EQ (XCAR (spec
), Qleft_fringe
)
4821 || EQ (XCAR (spec
), Qright_fringe
))
4822 && CONSP (XCDR (spec
)))
4828 if (!FRAME_WINDOW_P (it
->f
))
4829 /* If we return here, POSITION has been advanced
4830 across the text with this property. */
4832 /* Synchronize the bidi iterator with POSITION. This is
4833 needed because we are not going to push the iterator
4834 on behalf of this display property, so there will be
4835 no pop_it call to do this synchronization for us. */
4838 it
->position
= *position
;
4839 iterate_out_of_display_property (it
);
4840 *position
= it
->position
;
4845 else if (!frame_window_p
)
4848 #ifdef HAVE_WINDOW_SYSTEM
4849 value
= XCAR (XCDR (spec
));
4850 if (!SYMBOLP (value
)
4851 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4852 /* If we return here, POSITION has been advanced
4853 across the text with this property. */
4855 if (it
&& it
->bidi_p
)
4857 it
->position
= *position
;
4858 iterate_out_of_display_property (it
);
4859 *position
= it
->position
;
4866 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4868 if (CONSP (XCDR (XCDR (spec
))))
4870 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4871 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4877 /* Save current settings of IT so that we can restore them
4878 when we are finished with the glyph property value. */
4879 push_it (it
, position
);
4881 it
->area
= TEXT_AREA
;
4882 it
->what
= IT_IMAGE
;
4883 it
->image_id
= -1; /* no image */
4884 it
->position
= start_pos
;
4885 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4886 it
->method
= GET_FROM_IMAGE
;
4887 it
->from_overlay
= Qnil
;
4888 it
->face_id
= face_id
;
4889 it
->from_disp_prop_p
= 1;
4891 /* Say that we haven't consumed the characters with
4892 `display' property yet. The call to pop_it in
4893 set_iterator_to_next will clean this up. */
4894 *position
= start_pos
;
4896 if (EQ (XCAR (spec
), Qleft_fringe
))
4898 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4899 it
->left_user_fringe_face_id
= face_id
;
4903 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4904 it
->right_user_fringe_face_id
= face_id
;
4907 #endif /* HAVE_WINDOW_SYSTEM */
4911 /* Prepare to handle `((margin left-margin) ...)',
4912 `((margin right-margin) ...)' and `((margin nil) ...)'
4913 prefixes for display specifications. */
4914 location
= Qunbound
;
4915 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4919 value
= XCDR (spec
);
4921 value
= XCAR (value
);
4924 if (EQ (XCAR (tem
), Qmargin
)
4925 && (tem
= XCDR (tem
),
4926 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4928 || EQ (tem
, Qleft_margin
)
4929 || EQ (tem
, Qright_margin
))))
4933 if (EQ (location
, Qunbound
))
4939 /* After this point, VALUE is the property after any
4940 margin prefix has been stripped. It must be a string,
4941 an image specification, or `(space ...)'.
4943 LOCATION specifies where to display: `left-margin',
4944 `right-margin' or nil. */
4946 valid_p
= (STRINGP (value
)
4947 #ifdef HAVE_WINDOW_SYSTEM
4948 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4949 && valid_image_p (value
))
4950 #endif /* not HAVE_WINDOW_SYSTEM */
4951 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4953 if (valid_p
&& !display_replaced_p
)
4959 /* Callers need to know whether the display spec is any kind
4960 of `(space ...)' spec that is about to affect text-area
4962 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4967 /* Save current settings of IT so that we can restore them
4968 when we are finished with the glyph property value. */
4969 push_it (it
, position
);
4970 it
->from_overlay
= overlay
;
4971 it
->from_disp_prop_p
= 1;
4973 if (NILP (location
))
4974 it
->area
= TEXT_AREA
;
4975 else if (EQ (location
, Qleft_margin
))
4976 it
->area
= LEFT_MARGIN_AREA
;
4978 it
->area
= RIGHT_MARGIN_AREA
;
4980 if (STRINGP (value
))
4983 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4984 it
->current
.overlay_string_index
= -1;
4985 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4986 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4987 it
->method
= GET_FROM_STRING
;
4988 it
->stop_charpos
= 0;
4990 it
->base_level_stop
= 0;
4991 it
->string_from_display_prop_p
= 1;
4992 /* Say that we haven't consumed the characters with
4993 `display' property yet. The call to pop_it in
4994 set_iterator_to_next will clean this up. */
4995 if (BUFFERP (object
))
4996 *position
= start_pos
;
4998 /* Force paragraph direction to be that of the parent
4999 object. If the parent object's paragraph direction is
5000 not yet determined, default to L2R. */
5001 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5002 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5004 it
->paragraph_embedding
= L2R
;
5006 /* Set up the bidi iterator for this display string. */
5009 it
->bidi_it
.string
.lstring
= it
->string
;
5010 it
->bidi_it
.string
.s
= NULL
;
5011 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5012 it
->bidi_it
.string
.bufpos
= bufpos
;
5013 it
->bidi_it
.string
.from_disp_str
= 1;
5014 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5015 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5018 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5020 it
->method
= GET_FROM_STRETCH
;
5022 *position
= it
->position
= start_pos
;
5023 retval
= 1 + (it
->area
== TEXT_AREA
);
5025 #ifdef HAVE_WINDOW_SYSTEM
5028 it
->what
= IT_IMAGE
;
5029 it
->image_id
= lookup_image (it
->f
, value
);
5030 it
->position
= start_pos
;
5031 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5032 it
->method
= GET_FROM_IMAGE
;
5034 /* Say that we haven't consumed the characters with
5035 `display' property yet. The call to pop_it in
5036 set_iterator_to_next will clean this up. */
5037 *position
= start_pos
;
5039 #endif /* HAVE_WINDOW_SYSTEM */
5044 /* Invalid property or property not supported. Restore
5045 POSITION to what it was before. */
5046 *position
= start_pos
;
5050 /* Check if PROP is a display property value whose text should be
5051 treated as intangible. OVERLAY is the overlay from which PROP
5052 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5053 specify the buffer position covered by PROP. */
5056 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5057 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5059 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5060 struct text_pos position
;
5062 SET_TEXT_POS (position
, charpos
, bytepos
);
5063 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5064 &position
, charpos
, frame_window_p
);
5068 /* Return 1 if PROP is a display sub-property value containing STRING.
5070 Implementation note: this and the following function are really
5071 special cases of handle_display_spec and
5072 handle_single_display_spec, and should ideally use the same code.
5073 Until they do, these two pairs must be consistent and must be
5074 modified in sync. */
5077 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5079 if (EQ (string
, prop
))
5082 /* Skip over `when FORM'. */
5083 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5088 /* Actually, the condition following `when' should be eval'ed,
5089 like handle_single_display_spec does, and we should return
5090 zero if it evaluates to nil. However, this function is
5091 called only when the buffer was already displayed and some
5092 glyph in the glyph matrix was found to come from a display
5093 string. Therefore, the condition was already evaluated, and
5094 the result was non-nil, otherwise the display string wouldn't
5095 have been displayed and we would have never been called for
5096 this property. Thus, we can skip the evaluation and assume
5097 its result is non-nil. */
5102 /* Skip over `margin LOCATION'. */
5103 if (EQ (XCAR (prop
), Qmargin
))
5114 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5118 /* Return 1 if STRING appears in the `display' property PROP. */
5121 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5124 && !EQ (XCAR (prop
), Qwhen
)
5125 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5127 /* A list of sub-properties. */
5128 while (CONSP (prop
))
5130 if (single_display_spec_string_p (XCAR (prop
), string
))
5135 else if (VECTORP (prop
))
5137 /* A vector of sub-properties. */
5139 for (i
= 0; i
< ASIZE (prop
); ++i
)
5140 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5144 return single_display_spec_string_p (prop
, string
);
5149 /* Look for STRING in overlays and text properties in the current
5150 buffer, between character positions FROM and TO (excluding TO).
5151 BACK_P non-zero means look back (in this case, TO is supposed to be
5153 Value is the first character position where STRING was found, or
5154 zero if it wasn't found before hitting TO.
5156 This function may only use code that doesn't eval because it is
5157 called asynchronously from note_mouse_highlight. */
5160 string_buffer_position_lim (Lisp_Object string
,
5161 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5163 Lisp_Object limit
, prop
, pos
;
5166 pos
= make_number (max (from
, BEGV
));
5168 if (!back_p
) /* looking forward */
5170 limit
= make_number (min (to
, ZV
));
5171 while (!found
&& !EQ (pos
, limit
))
5173 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5174 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5177 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5181 else /* looking back */
5183 limit
= make_number (max (to
, BEGV
));
5184 while (!found
&& !EQ (pos
, limit
))
5186 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5187 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5190 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5195 return found
? XINT (pos
) : 0;
5198 /* Determine which buffer position in current buffer STRING comes from.
5199 AROUND_CHARPOS is an approximate position where it could come from.
5200 Value is the buffer position or 0 if it couldn't be determined.
5202 This function is necessary because we don't record buffer positions
5203 in glyphs generated from strings (to keep struct glyph small).
5204 This function may only use code that doesn't eval because it is
5205 called asynchronously from note_mouse_highlight. */
5208 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5210 const int MAX_DISTANCE
= 1000;
5211 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5212 around_charpos
+ MAX_DISTANCE
,
5216 found
= string_buffer_position_lim (string
, around_charpos
,
5217 around_charpos
- MAX_DISTANCE
, 1);
5223 /***********************************************************************
5224 `composition' property
5225 ***********************************************************************/
5227 /* Set up iterator IT from `composition' property at its current
5228 position. Called from handle_stop. */
5230 static enum prop_handled
5231 handle_composition_prop (struct it
*it
)
5233 Lisp_Object prop
, string
;
5234 ptrdiff_t pos
, pos_byte
, start
, end
;
5236 if (STRINGP (it
->string
))
5240 pos
= IT_STRING_CHARPOS (*it
);
5241 pos_byte
= IT_STRING_BYTEPOS (*it
);
5242 string
= it
->string
;
5243 s
= SDATA (string
) + pos_byte
;
5244 it
->c
= STRING_CHAR (s
);
5248 pos
= IT_CHARPOS (*it
);
5249 pos_byte
= IT_BYTEPOS (*it
);
5251 it
->c
= FETCH_CHAR (pos_byte
);
5254 /* If there's a valid composition and point is not inside of the
5255 composition (in the case that the composition is from the current
5256 buffer), draw a glyph composed from the composition components. */
5257 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5258 && COMPOSITION_VALID_P (start
, end
, prop
)
5259 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5262 /* As we can't handle this situation (perhaps font-lock added
5263 a new composition), we just return here hoping that next
5264 redisplay will detect this composition much earlier. */
5265 return HANDLED_NORMALLY
;
5268 if (STRINGP (it
->string
))
5269 pos_byte
= string_char_to_byte (it
->string
, start
);
5271 pos_byte
= CHAR_TO_BYTE (start
);
5273 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5276 if (it
->cmp_it
.id
>= 0)
5279 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5280 it
->cmp_it
.nglyphs
= -1;
5284 return HANDLED_NORMALLY
;
5289 /***********************************************************************
5291 ***********************************************************************/
5293 /* The following structure is used to record overlay strings for
5294 later sorting in load_overlay_strings. */
5296 struct overlay_entry
5298 Lisp_Object overlay
;
5305 /* Set up iterator IT from overlay strings at its current position.
5306 Called from handle_stop. */
5308 static enum prop_handled
5309 handle_overlay_change (struct it
*it
)
5311 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5312 return HANDLED_RECOMPUTE_PROPS
;
5314 return HANDLED_NORMALLY
;
5318 /* Set up the next overlay string for delivery by IT, if there is an
5319 overlay string to deliver. Called by set_iterator_to_next when the
5320 end of the current overlay string is reached. If there are more
5321 overlay strings to display, IT->string and
5322 IT->current.overlay_string_index are set appropriately here.
5323 Otherwise IT->string is set to nil. */
5326 next_overlay_string (struct it
*it
)
5328 ++it
->current
.overlay_string_index
;
5329 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5331 /* No more overlay strings. Restore IT's settings to what
5332 they were before overlay strings were processed, and
5333 continue to deliver from current_buffer. */
5335 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5338 || (NILP (it
->string
)
5339 && it
->method
== GET_FROM_BUFFER
5340 && it
->stop_charpos
>= BEGV
5341 && it
->stop_charpos
<= it
->end_charpos
));
5342 it
->current
.overlay_string_index
= -1;
5343 it
->n_overlay_strings
= 0;
5344 it
->overlay_strings_charpos
= -1;
5345 /* If there's an empty display string on the stack, pop the
5346 stack, to resync the bidi iterator with IT's position. Such
5347 empty strings are pushed onto the stack in
5348 get_overlay_strings_1. */
5349 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5352 /* If we're at the end of the buffer, record that we have
5353 processed the overlay strings there already, so that
5354 next_element_from_buffer doesn't try it again. */
5355 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5356 it
->overlay_strings_at_end_processed_p
= 1;
5360 /* There are more overlay strings to process. If
5361 IT->current.overlay_string_index has advanced to a position
5362 where we must load IT->overlay_strings with more strings, do
5363 it. We must load at the IT->overlay_strings_charpos where
5364 IT->n_overlay_strings was originally computed; when invisible
5365 text is present, this might not be IT_CHARPOS (Bug#7016). */
5366 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5368 if (it
->current
.overlay_string_index
&& i
== 0)
5369 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5371 /* Initialize IT to deliver display elements from the overlay
5373 it
->string
= it
->overlay_strings
[i
];
5374 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5375 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5376 it
->method
= GET_FROM_STRING
;
5377 it
->stop_charpos
= 0;
5378 it
->end_charpos
= SCHARS (it
->string
);
5379 if (it
->cmp_it
.stop_pos
>= 0)
5380 it
->cmp_it
.stop_pos
= 0;
5382 it
->base_level_stop
= 0;
5384 /* Set up the bidi iterator for this overlay string. */
5387 it
->bidi_it
.string
.lstring
= it
->string
;
5388 it
->bidi_it
.string
.s
= NULL
;
5389 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5390 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5391 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5392 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5393 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5401 /* Compare two overlay_entry structures E1 and E2. Used as a
5402 comparison function for qsort in load_overlay_strings. Overlay
5403 strings for the same position are sorted so that
5405 1. All after-strings come in front of before-strings, except
5406 when they come from the same overlay.
5408 2. Within after-strings, strings are sorted so that overlay strings
5409 from overlays with higher priorities come first.
5411 2. Within before-strings, strings are sorted so that overlay
5412 strings from overlays with higher priorities come last.
5414 Value is analogous to strcmp. */
5418 compare_overlay_entries (const void *e1
, const void *e2
)
5420 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5421 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5424 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5426 /* Let after-strings appear in front of before-strings if
5427 they come from different overlays. */
5428 if (EQ (entry1
->overlay
, entry2
->overlay
))
5429 result
= entry1
->after_string_p
? 1 : -1;
5431 result
= entry1
->after_string_p
? -1 : 1;
5433 else if (entry1
->priority
!= entry2
->priority
)
5435 if (entry1
->after_string_p
)
5436 /* After-strings sorted in order of decreasing priority. */
5437 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5439 /* Before-strings sorted in order of increasing priority. */
5440 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5449 /* Load the vector IT->overlay_strings with overlay strings from IT's
5450 current buffer position, or from CHARPOS if that is > 0. Set
5451 IT->n_overlays to the total number of overlay strings found.
5453 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5454 a time. On entry into load_overlay_strings,
5455 IT->current.overlay_string_index gives the number of overlay
5456 strings that have already been loaded by previous calls to this
5459 IT->add_overlay_start contains an additional overlay start
5460 position to consider for taking overlay strings from, if non-zero.
5461 This position comes into play when the overlay has an `invisible'
5462 property, and both before and after-strings. When we've skipped to
5463 the end of the overlay, because of its `invisible' property, we
5464 nevertheless want its before-string to appear.
5465 IT->add_overlay_start will contain the overlay start position
5468 Overlay strings are sorted so that after-string strings come in
5469 front of before-string strings. Within before and after-strings,
5470 strings are sorted by overlay priority. See also function
5471 compare_overlay_entries. */
5474 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5476 Lisp_Object overlay
, window
, str
, invisible
;
5477 struct Lisp_Overlay
*ov
;
5478 ptrdiff_t start
, end
;
5479 ptrdiff_t size
= 20;
5480 ptrdiff_t n
= 0, i
, j
;
5482 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5486 charpos
= IT_CHARPOS (*it
);
5488 /* Append the overlay string STRING of overlay OVERLAY to vector
5489 `entries' which has size `size' and currently contains `n'
5490 elements. AFTER_P non-zero means STRING is an after-string of
5492 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5495 Lisp_Object priority; \
5499 struct overlay_entry *old = entries; \
5500 SAFE_NALLOCA (entries, 2, size); \
5501 memcpy (entries, old, size * sizeof *entries); \
5505 entries[n].string = (STRING); \
5506 entries[n].overlay = (OVERLAY); \
5507 priority = Foverlay_get ((OVERLAY), Qpriority); \
5508 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5509 entries[n].after_string_p = (AFTER_P); \
5514 /* Process overlay before the overlay center. */
5515 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5517 XSETMISC (overlay
, ov
);
5518 eassert (OVERLAYP (overlay
));
5519 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5520 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5525 /* Skip this overlay if it doesn't start or end at IT's current
5527 if (end
!= charpos
&& start
!= charpos
)
5530 /* Skip this overlay if it doesn't apply to IT->w. */
5531 window
= Foverlay_get (overlay
, Qwindow
);
5532 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5535 /* If the text ``under'' the overlay is invisible, both before-
5536 and after-strings from this overlay are visible; start and
5537 end position are indistinguishable. */
5538 invisible
= Foverlay_get (overlay
, Qinvisible
);
5539 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5541 /* If overlay has a non-empty before-string, record it. */
5542 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5543 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5545 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5547 /* If overlay has a non-empty after-string, record it. */
5548 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5549 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5551 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5554 /* Process overlays after the overlay center. */
5555 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5557 XSETMISC (overlay
, ov
);
5558 eassert (OVERLAYP (overlay
));
5559 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5560 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5562 if (start
> charpos
)
5565 /* Skip this overlay if it doesn't start or end at IT's current
5567 if (end
!= charpos
&& start
!= charpos
)
5570 /* Skip this overlay if it doesn't apply to IT->w. */
5571 window
= Foverlay_get (overlay
, Qwindow
);
5572 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5575 /* If the text ``under'' the overlay is invisible, it has a zero
5576 dimension, and both before- and after-strings apply. */
5577 invisible
= Foverlay_get (overlay
, Qinvisible
);
5578 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5580 /* If overlay has a non-empty before-string, record it. */
5581 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5582 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5584 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5586 /* If overlay has a non-empty after-string, record it. */
5587 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5588 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5590 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5593 #undef RECORD_OVERLAY_STRING
5597 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5599 /* Record number of overlay strings, and where we computed it. */
5600 it
->n_overlay_strings
= n
;
5601 it
->overlay_strings_charpos
= charpos
;
5603 /* IT->current.overlay_string_index is the number of overlay strings
5604 that have already been consumed by IT. Copy some of the
5605 remaining overlay strings to IT->overlay_strings. */
5607 j
= it
->current
.overlay_string_index
;
5608 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5610 it
->overlay_strings
[i
] = entries
[j
].string
;
5611 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5619 /* Get the first chunk of overlay strings at IT's current buffer
5620 position, or at CHARPOS if that is > 0. Value is non-zero if at
5621 least one overlay string was found. */
5624 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5626 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5627 process. This fills IT->overlay_strings with strings, and sets
5628 IT->n_overlay_strings to the total number of strings to process.
5629 IT->pos.overlay_string_index has to be set temporarily to zero
5630 because load_overlay_strings needs this; it must be set to -1
5631 when no overlay strings are found because a zero value would
5632 indicate a position in the first overlay string. */
5633 it
->current
.overlay_string_index
= 0;
5634 load_overlay_strings (it
, charpos
);
5636 /* If we found overlay strings, set up IT to deliver display
5637 elements from the first one. Otherwise set up IT to deliver
5638 from current_buffer. */
5639 if (it
->n_overlay_strings
)
5641 /* Make sure we know settings in current_buffer, so that we can
5642 restore meaningful values when we're done with the overlay
5645 compute_stop_pos (it
);
5646 eassert (it
->face_id
>= 0);
5648 /* Save IT's settings. They are restored after all overlay
5649 strings have been processed. */
5650 eassert (!compute_stop_p
|| it
->sp
== 0);
5652 /* When called from handle_stop, there might be an empty display
5653 string loaded. In that case, don't bother saving it. But
5654 don't use this optimization with the bidi iterator, since we
5655 need the corresponding pop_it call to resync the bidi
5656 iterator's position with IT's position, after we are done
5657 with the overlay strings. (The corresponding call to pop_it
5658 in case of an empty display string is in
5659 next_overlay_string.) */
5661 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5664 /* Set up IT to deliver display elements from the first overlay
5666 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5667 it
->string
= it
->overlay_strings
[0];
5668 it
->from_overlay
= Qnil
;
5669 it
->stop_charpos
= 0;
5670 eassert (STRINGP (it
->string
));
5671 it
->end_charpos
= SCHARS (it
->string
);
5673 it
->base_level_stop
= 0;
5674 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5675 it
->method
= GET_FROM_STRING
;
5676 it
->from_disp_prop_p
= 0;
5678 /* Force paragraph direction to be that of the parent
5680 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5681 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5683 it
->paragraph_embedding
= L2R
;
5685 /* Set up the bidi iterator for this overlay string. */
5688 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5690 it
->bidi_it
.string
.lstring
= it
->string
;
5691 it
->bidi_it
.string
.s
= NULL
;
5692 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5693 it
->bidi_it
.string
.bufpos
= pos
;
5694 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5695 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5696 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5701 it
->current
.overlay_string_index
= -1;
5706 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5709 it
->method
= GET_FROM_BUFFER
;
5711 (void) get_overlay_strings_1 (it
, charpos
, 1);
5715 /* Value is non-zero if we found at least one overlay string. */
5716 return STRINGP (it
->string
);
5721 /***********************************************************************
5722 Saving and restoring state
5723 ***********************************************************************/
5725 /* Save current settings of IT on IT->stack. Called, for example,
5726 before setting up IT for an overlay string, to be able to restore
5727 IT's settings to what they were after the overlay string has been
5728 processed. If POSITION is non-NULL, it is the position to save on
5729 the stack instead of IT->position. */
5732 push_it (struct it
*it
, struct text_pos
*position
)
5734 struct iterator_stack_entry
*p
;
5736 eassert (it
->sp
< IT_STACK_SIZE
);
5737 p
= it
->stack
+ it
->sp
;
5739 p
->stop_charpos
= it
->stop_charpos
;
5740 p
->prev_stop
= it
->prev_stop
;
5741 p
->base_level_stop
= it
->base_level_stop
;
5742 p
->cmp_it
= it
->cmp_it
;
5743 eassert (it
->face_id
>= 0);
5744 p
->face_id
= it
->face_id
;
5745 p
->string
= it
->string
;
5746 p
->method
= it
->method
;
5747 p
->from_overlay
= it
->from_overlay
;
5750 case GET_FROM_IMAGE
:
5751 p
->u
.image
.object
= it
->object
;
5752 p
->u
.image
.image_id
= it
->image_id
;
5753 p
->u
.image
.slice
= it
->slice
;
5755 case GET_FROM_STRETCH
:
5756 p
->u
.stretch
.object
= it
->object
;
5759 p
->position
= position
? *position
: it
->position
;
5760 p
->current
= it
->current
;
5761 p
->end_charpos
= it
->end_charpos
;
5762 p
->string_nchars
= it
->string_nchars
;
5764 p
->multibyte_p
= it
->multibyte_p
;
5765 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5766 p
->space_width
= it
->space_width
;
5767 p
->font_height
= it
->font_height
;
5768 p
->voffset
= it
->voffset
;
5769 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5770 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5771 p
->display_ellipsis_p
= 0;
5772 p
->line_wrap
= it
->line_wrap
;
5773 p
->bidi_p
= it
->bidi_p
;
5774 p
->paragraph_embedding
= it
->paragraph_embedding
;
5775 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5778 /* Save the state of the bidi iterator as well. */
5780 bidi_push_it (&it
->bidi_it
);
5784 iterate_out_of_display_property (struct it
*it
)
5786 int buffer_p
= !STRINGP (it
->string
);
5787 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5788 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5790 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5792 /* Maybe initialize paragraph direction. If we are at the beginning
5793 of a new paragraph, next_element_from_buffer may not have a
5794 chance to do that. */
5795 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5796 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5797 /* prev_stop can be zero, so check against BEGV as well. */
5798 while (it
->bidi_it
.charpos
>= bob
5799 && it
->prev_stop
<= it
->bidi_it
.charpos
5800 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5801 && it
->bidi_it
.charpos
< eob
)
5802 bidi_move_to_visually_next (&it
->bidi_it
);
5803 /* Record the stop_pos we just crossed, for when we cross it
5805 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5806 it
->prev_stop
= CHARPOS (it
->position
);
5807 /* If we ended up not where pop_it put us, resync IT's
5808 positional members with the bidi iterator. */
5809 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5810 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5812 it
->current
.pos
= it
->position
;
5814 it
->current
.string_pos
= it
->position
;
5817 /* Restore IT's settings from IT->stack. Called, for example, when no
5818 more overlay strings must be processed, and we return to delivering
5819 display elements from a buffer, or when the end of a string from a
5820 `display' property is reached and we return to delivering display
5821 elements from an overlay string, or from a buffer. */
5824 pop_it (struct it
*it
)
5826 struct iterator_stack_entry
*p
;
5827 int from_display_prop
= it
->from_disp_prop_p
;
5829 eassert (it
->sp
> 0);
5831 p
= it
->stack
+ it
->sp
;
5832 it
->stop_charpos
= p
->stop_charpos
;
5833 it
->prev_stop
= p
->prev_stop
;
5834 it
->base_level_stop
= p
->base_level_stop
;
5835 it
->cmp_it
= p
->cmp_it
;
5836 it
->face_id
= p
->face_id
;
5837 it
->current
= p
->current
;
5838 it
->position
= p
->position
;
5839 it
->string
= p
->string
;
5840 it
->from_overlay
= p
->from_overlay
;
5841 if (NILP (it
->string
))
5842 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5843 it
->method
= p
->method
;
5846 case GET_FROM_IMAGE
:
5847 it
->image_id
= p
->u
.image
.image_id
;
5848 it
->object
= p
->u
.image
.object
;
5849 it
->slice
= p
->u
.image
.slice
;
5851 case GET_FROM_STRETCH
:
5852 it
->object
= p
->u
.stretch
.object
;
5854 case GET_FROM_BUFFER
:
5855 it
->object
= it
->w
->buffer
;
5857 case GET_FROM_STRING
:
5858 it
->object
= it
->string
;
5860 case GET_FROM_DISPLAY_VECTOR
:
5862 it
->method
= GET_FROM_C_STRING
;
5863 else if (STRINGP (it
->string
))
5864 it
->method
= GET_FROM_STRING
;
5867 it
->method
= GET_FROM_BUFFER
;
5868 it
->object
= it
->w
->buffer
;
5871 it
->end_charpos
= p
->end_charpos
;
5872 it
->string_nchars
= p
->string_nchars
;
5874 it
->multibyte_p
= p
->multibyte_p
;
5875 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5876 it
->space_width
= p
->space_width
;
5877 it
->font_height
= p
->font_height
;
5878 it
->voffset
= p
->voffset
;
5879 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5880 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5881 it
->line_wrap
= p
->line_wrap
;
5882 it
->bidi_p
= p
->bidi_p
;
5883 it
->paragraph_embedding
= p
->paragraph_embedding
;
5884 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5887 bidi_pop_it (&it
->bidi_it
);
5888 /* Bidi-iterate until we get out of the portion of text, if any,
5889 covered by a `display' text property or by an overlay with
5890 `display' property. (We cannot just jump there, because the
5891 internal coherency of the bidi iterator state can not be
5892 preserved across such jumps.) We also must determine the
5893 paragraph base direction if the overlay we just processed is
5894 at the beginning of a new paragraph. */
5895 if (from_display_prop
5896 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5897 iterate_out_of_display_property (it
);
5899 eassert ((BUFFERP (it
->object
)
5900 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5901 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5902 || (STRINGP (it
->object
)
5903 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5904 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5905 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5911 /***********************************************************************
5913 ***********************************************************************/
5915 /* Set IT's current position to the previous line start. */
5918 back_to_previous_line_start (struct it
*it
)
5920 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5921 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5925 /* Move IT to the next line start.
5927 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5928 we skipped over part of the text (as opposed to moving the iterator
5929 continuously over the text). Otherwise, don't change the value
5932 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5933 iterator on the newline, if it was found.
5935 Newlines may come from buffer text, overlay strings, or strings
5936 displayed via the `display' property. That's the reason we can't
5937 simply use find_next_newline_no_quit.
5939 Note that this function may not skip over invisible text that is so
5940 because of text properties and immediately follows a newline. If
5941 it would, function reseat_at_next_visible_line_start, when called
5942 from set_iterator_to_next, would effectively make invisible
5943 characters following a newline part of the wrong glyph row, which
5944 leads to wrong cursor motion. */
5947 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5948 struct bidi_it
*bidi_it_prev
)
5950 ptrdiff_t old_selective
;
5951 int newline_found_p
, n
;
5952 const int MAX_NEWLINE_DISTANCE
= 500;
5954 /* If already on a newline, just consume it to avoid unintended
5955 skipping over invisible text below. */
5956 if (it
->what
== IT_CHARACTER
5958 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5960 if (it
->bidi_p
&& bidi_it_prev
)
5961 *bidi_it_prev
= it
->bidi_it
;
5962 set_iterator_to_next (it
, 0);
5967 /* Don't handle selective display in the following. It's (a)
5968 unnecessary because it's done by the caller, and (b) leads to an
5969 infinite recursion because next_element_from_ellipsis indirectly
5970 calls this function. */
5971 old_selective
= it
->selective
;
5974 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5975 from buffer text. */
5976 for (n
= newline_found_p
= 0;
5977 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5978 n
+= STRINGP (it
->string
) ? 0 : 1)
5980 if (!get_next_display_element (it
))
5982 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5983 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5984 *bidi_it_prev
= it
->bidi_it
;
5985 set_iterator_to_next (it
, 0);
5988 /* If we didn't find a newline near enough, see if we can use a
5990 if (!newline_found_p
)
5992 ptrdiff_t start
= IT_CHARPOS (*it
);
5993 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5996 eassert (!STRINGP (it
->string
));
5998 /* If there isn't any `display' property in sight, and no
5999 overlays, we can just use the position of the newline in
6001 if (it
->stop_charpos
>= limit
6002 || ((pos
= Fnext_single_property_change (make_number (start
),
6004 make_number (limit
)),
6006 && next_overlay_change (start
) == ZV
))
6010 IT_CHARPOS (*it
) = limit
;
6011 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
6015 struct bidi_it bprev
;
6017 /* Help bidi.c avoid expensive searches for display
6018 properties and overlays, by telling it that there are
6019 none up to `limit'. */
6020 if (it
->bidi_it
.disp_pos
< limit
)
6022 it
->bidi_it
.disp_pos
= limit
;
6023 it
->bidi_it
.disp_prop
= 0;
6026 bprev
= it
->bidi_it
;
6027 bidi_move_to_visually_next (&it
->bidi_it
);
6028 } while (it
->bidi_it
.charpos
!= limit
);
6029 IT_CHARPOS (*it
) = limit
;
6030 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6032 *bidi_it_prev
= bprev
;
6034 *skipped_p
= newline_found_p
= 1;
6038 while (get_next_display_element (it
)
6039 && !newline_found_p
)
6041 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6042 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6043 *bidi_it_prev
= it
->bidi_it
;
6044 set_iterator_to_next (it
, 0);
6049 it
->selective
= old_selective
;
6050 return newline_found_p
;
6054 /* Set IT's current position to the previous visible line start. Skip
6055 invisible text that is so either due to text properties or due to
6056 selective display. Caution: this does not change IT->current_x and
6060 back_to_previous_visible_line_start (struct it
*it
)
6062 while (IT_CHARPOS (*it
) > BEGV
)
6064 back_to_previous_line_start (it
);
6066 if (IT_CHARPOS (*it
) <= BEGV
)
6069 /* If selective > 0, then lines indented more than its value are
6071 if (it
->selective
> 0
6072 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6076 /* Check the newline before point for invisibility. */
6079 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6080 Qinvisible
, it
->window
);
6081 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6085 if (IT_CHARPOS (*it
) <= BEGV
)
6090 void *it2data
= NULL
;
6093 Lisp_Object val
, overlay
;
6095 SAVE_IT (it2
, *it
, it2data
);
6097 /* If newline is part of a composition, continue from start of composition */
6098 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6099 && beg
< IT_CHARPOS (*it
))
6102 /* If newline is replaced by a display property, find start of overlay
6103 or interval and continue search from that point. */
6104 pos
= --IT_CHARPOS (it2
);
6107 bidi_unshelve_cache (NULL
, 0);
6108 it2
.string_from_display_prop_p
= 0;
6109 it2
.from_disp_prop_p
= 0;
6110 if (handle_display_prop (&it2
) == HANDLED_RETURN
6111 && !NILP (val
= get_char_property_and_overlay
6112 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6113 && (OVERLAYP (overlay
)
6114 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6115 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6117 RESTORE_IT (it
, it
, it2data
);
6121 /* Newline is not replaced by anything -- so we are done. */
6122 RESTORE_IT (it
, it
, it2data
);
6128 IT_CHARPOS (*it
) = beg
;
6129 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6133 it
->continuation_lines_width
= 0;
6135 eassert (IT_CHARPOS (*it
) >= BEGV
);
6136 eassert (IT_CHARPOS (*it
) == BEGV
6137 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6142 /* Reseat iterator IT at the previous visible line start. Skip
6143 invisible text that is so either due to text properties or due to
6144 selective display. At the end, update IT's overlay information,
6145 face information etc. */
6148 reseat_at_previous_visible_line_start (struct it
*it
)
6150 back_to_previous_visible_line_start (it
);
6151 reseat (it
, it
->current
.pos
, 1);
6156 /* Reseat iterator IT on the next visible line start in the current
6157 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6158 preceding the line start. Skip over invisible text that is so
6159 because of selective display. Compute faces, overlays etc at the
6160 new position. Note that this function does not skip over text that
6161 is invisible because of text properties. */
6164 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6166 int newline_found_p
, skipped_p
= 0;
6167 struct bidi_it bidi_it_prev
;
6169 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6171 /* Skip over lines that are invisible because they are indented
6172 more than the value of IT->selective. */
6173 if (it
->selective
> 0)
6174 while (IT_CHARPOS (*it
) < ZV
6175 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6178 eassert (IT_BYTEPOS (*it
) == BEGV
6179 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6181 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6184 /* Position on the newline if that's what's requested. */
6185 if (on_newline_p
&& newline_found_p
)
6187 if (STRINGP (it
->string
))
6189 if (IT_STRING_CHARPOS (*it
) > 0)
6193 --IT_STRING_CHARPOS (*it
);
6194 --IT_STRING_BYTEPOS (*it
);
6198 /* We need to restore the bidi iterator to the state
6199 it had on the newline, and resync the IT's
6200 position with that. */
6201 it
->bidi_it
= bidi_it_prev
;
6202 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6203 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6207 else if (IT_CHARPOS (*it
) > BEGV
)
6216 /* We need to restore the bidi iterator to the state it
6217 had on the newline and resync IT with that. */
6218 it
->bidi_it
= bidi_it_prev
;
6219 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6220 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6222 reseat (it
, it
->current
.pos
, 0);
6226 reseat (it
, it
->current
.pos
, 0);
6233 /***********************************************************************
6234 Changing an iterator's position
6235 ***********************************************************************/
6237 /* Change IT's current position to POS in current_buffer. If FORCE_P
6238 is non-zero, always check for text properties at the new position.
6239 Otherwise, text properties are only looked up if POS >=
6240 IT->check_charpos of a property. */
6243 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6245 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6247 reseat_1 (it
, pos
, 0);
6249 /* Determine where to check text properties. Avoid doing it
6250 where possible because text property lookup is very expensive. */
6252 || CHARPOS (pos
) > it
->stop_charpos
6253 || CHARPOS (pos
) < original_pos
)
6257 /* For bidi iteration, we need to prime prev_stop and
6258 base_level_stop with our best estimations. */
6259 /* Implementation note: Of course, POS is not necessarily a
6260 stop position, so assigning prev_pos to it is a lie; we
6261 should have called compute_stop_backwards. However, if
6262 the current buffer does not include any R2L characters,
6263 that call would be a waste of cycles, because the
6264 iterator will never move back, and thus never cross this
6265 "fake" stop position. So we delay that backward search
6266 until the time we really need it, in next_element_from_buffer. */
6267 if (CHARPOS (pos
) != it
->prev_stop
)
6268 it
->prev_stop
= CHARPOS (pos
);
6269 if (CHARPOS (pos
) < it
->base_level_stop
)
6270 it
->base_level_stop
= 0; /* meaning it's unknown */
6276 it
->prev_stop
= it
->base_level_stop
= 0;
6285 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6286 IT->stop_pos to POS, also. */
6289 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6291 /* Don't call this function when scanning a C string. */
6292 eassert (it
->s
== NULL
);
6294 /* POS must be a reasonable value. */
6295 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6297 it
->current
.pos
= it
->position
= pos
;
6298 it
->end_charpos
= ZV
;
6300 it
->current
.dpvec_index
= -1;
6301 it
->current
.overlay_string_index
= -1;
6302 IT_STRING_CHARPOS (*it
) = -1;
6303 IT_STRING_BYTEPOS (*it
) = -1;
6305 it
->method
= GET_FROM_BUFFER
;
6306 it
->object
= it
->w
->buffer
;
6307 it
->area
= TEXT_AREA
;
6308 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6310 it
->string_from_display_prop_p
= 0;
6311 it
->string_from_prefix_prop_p
= 0;
6313 it
->from_disp_prop_p
= 0;
6314 it
->face_before_selective_p
= 0;
6317 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6319 bidi_unshelve_cache (NULL
, 0);
6320 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6321 it
->bidi_it
.string
.s
= NULL
;
6322 it
->bidi_it
.string
.lstring
= Qnil
;
6323 it
->bidi_it
.string
.bufpos
= 0;
6324 it
->bidi_it
.string
.unibyte
= 0;
6329 it
->stop_charpos
= CHARPOS (pos
);
6330 it
->base_level_stop
= CHARPOS (pos
);
6332 /* This make the information stored in it->cmp_it invalidate. */
6337 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6338 If S is non-null, it is a C string to iterate over. Otherwise,
6339 STRING gives a Lisp string to iterate over.
6341 If PRECISION > 0, don't return more then PRECISION number of
6342 characters from the string.
6344 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6345 characters have been returned. FIELD_WIDTH < 0 means an infinite
6348 MULTIBYTE = 0 means disable processing of multibyte characters,
6349 MULTIBYTE > 0 means enable it,
6350 MULTIBYTE < 0 means use IT->multibyte_p.
6352 IT must be initialized via a prior call to init_iterator before
6353 calling this function. */
6356 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6357 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6360 /* No region in strings. */
6361 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6363 /* No text property checks performed by default, but see below. */
6364 it
->stop_charpos
= -1;
6366 /* Set iterator position and end position. */
6367 memset (&it
->current
, 0, sizeof it
->current
);
6368 it
->current
.overlay_string_index
= -1;
6369 it
->current
.dpvec_index
= -1;
6370 eassert (charpos
>= 0);
6372 /* If STRING is specified, use its multibyteness, otherwise use the
6373 setting of MULTIBYTE, if specified. */
6375 it
->multibyte_p
= multibyte
> 0;
6377 /* Bidirectional reordering of strings is controlled by the default
6378 value of bidi-display-reordering. Don't try to reorder while
6379 loading loadup.el, as the necessary character property tables are
6380 not yet available. */
6383 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6387 eassert (STRINGP (string
));
6388 it
->string
= string
;
6390 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6391 it
->method
= GET_FROM_STRING
;
6392 it
->current
.string_pos
= string_pos (charpos
, string
);
6396 it
->bidi_it
.string
.lstring
= string
;
6397 it
->bidi_it
.string
.s
= NULL
;
6398 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6399 it
->bidi_it
.string
.bufpos
= 0;
6400 it
->bidi_it
.string
.from_disp_str
= 0;
6401 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6402 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6403 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6408 it
->s
= (const unsigned char *) s
;
6411 /* Note that we use IT->current.pos, not it->current.string_pos,
6412 for displaying C strings. */
6413 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6414 if (it
->multibyte_p
)
6416 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6417 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6421 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6422 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6427 it
->bidi_it
.string
.lstring
= Qnil
;
6428 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6429 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6430 it
->bidi_it
.string
.bufpos
= 0;
6431 it
->bidi_it
.string
.from_disp_str
= 0;
6432 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6433 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6436 it
->method
= GET_FROM_C_STRING
;
6439 /* PRECISION > 0 means don't return more than PRECISION characters
6441 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6443 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6445 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6448 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6449 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6450 FIELD_WIDTH < 0 means infinite field width. This is useful for
6451 padding with `-' at the end of a mode line. */
6452 if (field_width
< 0)
6453 field_width
= INFINITY
;
6454 /* Implementation note: We deliberately don't enlarge
6455 it->bidi_it.string.schars here to fit it->end_charpos, because
6456 the bidi iterator cannot produce characters out of thin air. */
6457 if (field_width
> it
->end_charpos
- charpos
)
6458 it
->end_charpos
= charpos
+ field_width
;
6460 /* Use the standard display table for displaying strings. */
6461 if (DISP_TABLE_P (Vstandard_display_table
))
6462 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6464 it
->stop_charpos
= charpos
;
6465 it
->prev_stop
= charpos
;
6466 it
->base_level_stop
= 0;
6469 it
->bidi_it
.first_elt
= 1;
6470 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6471 it
->bidi_it
.disp_pos
= -1;
6473 if (s
== NULL
&& it
->multibyte_p
)
6475 ptrdiff_t endpos
= SCHARS (it
->string
);
6476 if (endpos
> it
->end_charpos
)
6477 endpos
= it
->end_charpos
;
6478 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6486 /***********************************************************************
6488 ***********************************************************************/
6490 /* Map enum it_method value to corresponding next_element_from_* function. */
6492 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6494 next_element_from_buffer
,
6495 next_element_from_display_vector
,
6496 next_element_from_string
,
6497 next_element_from_c_string
,
6498 next_element_from_image
,
6499 next_element_from_stretch
6502 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6505 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6506 (possibly with the following characters). */
6508 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6509 ((IT)->cmp_it.id >= 0 \
6510 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6511 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6512 END_CHARPOS, (IT)->w, \
6513 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6517 /* Lookup the char-table Vglyphless_char_display for character C (-1
6518 if we want information for no-font case), and return the display
6519 method symbol. By side-effect, update it->what and
6520 it->glyphless_method. This function is called from
6521 get_next_display_element for each character element, and from
6522 x_produce_glyphs when no suitable font was found. */
6525 lookup_glyphless_char_display (int c
, struct it
*it
)
6527 Lisp_Object glyphless_method
= Qnil
;
6529 if (CHAR_TABLE_P (Vglyphless_char_display
)
6530 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6534 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6535 if (CONSP (glyphless_method
))
6536 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6537 ? XCAR (glyphless_method
)
6538 : XCDR (glyphless_method
);
6541 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6545 if (NILP (glyphless_method
))
6548 /* The default is to display the character by a proper font. */
6550 /* The default for the no-font case is to display an empty box. */
6551 glyphless_method
= Qempty_box
;
6553 if (EQ (glyphless_method
, Qzero_width
))
6556 return glyphless_method
;
6557 /* This method can't be used for the no-font case. */
6558 glyphless_method
= Qempty_box
;
6560 if (EQ (glyphless_method
, Qthin_space
))
6561 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6562 else if (EQ (glyphless_method
, Qempty_box
))
6563 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6564 else if (EQ (glyphless_method
, Qhex_code
))
6565 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6566 else if (STRINGP (glyphless_method
))
6567 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6570 /* Invalid value. We use the default method. */
6571 glyphless_method
= Qnil
;
6574 it
->what
= IT_GLYPHLESS
;
6575 return glyphless_method
;
6578 /* Load IT's display element fields with information about the next
6579 display element from the current position of IT. Value is zero if
6580 end of buffer (or C string) is reached. */
6582 static struct frame
*last_escape_glyph_frame
= NULL
;
6583 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6584 static int last_escape_glyph_merged_face_id
= 0;
6586 struct frame
*last_glyphless_glyph_frame
= NULL
;
6587 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6588 int last_glyphless_glyph_merged_face_id
= 0;
6591 get_next_display_element (struct it
*it
)
6593 /* Non-zero means that we found a display element. Zero means that
6594 we hit the end of what we iterate over. Performance note: the
6595 function pointer `method' used here turns out to be faster than
6596 using a sequence of if-statements. */
6600 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6602 if (it
->what
== IT_CHARACTER
)
6604 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6605 and only if (a) the resolved directionality of that character
6607 /* FIXME: Do we need an exception for characters from display
6609 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6610 it
->c
= bidi_mirror_char (it
->c
);
6611 /* Map via display table or translate control characters.
6612 IT->c, IT->len etc. have been set to the next character by
6613 the function call above. If we have a display table, and it
6614 contains an entry for IT->c, translate it. Don't do this if
6615 IT->c itself comes from a display table, otherwise we could
6616 end up in an infinite recursion. (An alternative could be to
6617 count the recursion depth of this function and signal an
6618 error when a certain maximum depth is reached.) Is it worth
6620 if (success_p
&& it
->dpvec
== NULL
)
6623 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6624 int nonascii_space_p
= 0;
6625 int nonascii_hyphen_p
= 0;
6626 int c
= it
->c
; /* This is the character to display. */
6628 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6630 eassert (SINGLE_BYTE_CHAR_P (c
));
6631 if (unibyte_display_via_language_environment
)
6633 c
= DECODE_CHAR (unibyte
, c
);
6635 c
= BYTE8_TO_CHAR (it
->c
);
6638 c
= BYTE8_TO_CHAR (it
->c
);
6642 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6645 struct Lisp_Vector
*v
= XVECTOR (dv
);
6647 /* Return the first character from the display table
6648 entry, if not empty. If empty, don't display the
6649 current character. */
6652 it
->dpvec_char_len
= it
->len
;
6653 it
->dpvec
= v
->contents
;
6654 it
->dpend
= v
->contents
+ v
->header
.size
;
6655 it
->current
.dpvec_index
= 0;
6656 it
->dpvec_face_id
= -1;
6657 it
->saved_face_id
= it
->face_id
;
6658 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6663 set_iterator_to_next (it
, 0);
6668 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6670 if (it
->what
== IT_GLYPHLESS
)
6672 /* Don't display this character. */
6673 set_iterator_to_next (it
, 0);
6677 /* If `nobreak-char-display' is non-nil, we display
6678 non-ASCII spaces and hyphens specially. */
6679 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6682 nonascii_space_p
= 1;
6683 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6684 nonascii_hyphen_p
= 1;
6687 /* Translate control characters into `\003' or `^C' form.
6688 Control characters coming from a display table entry are
6689 currently not translated because we use IT->dpvec to hold
6690 the translation. This could easily be changed but I
6691 don't believe that it is worth doing.
6693 The characters handled by `nobreak-char-display' must be
6696 Non-printable characters and raw-byte characters are also
6697 translated to octal form. */
6698 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6699 ? (it
->area
!= TEXT_AREA
6700 /* In mode line, treat \n, \t like other crl chars. */
6703 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6704 || (c
!= '\n' && c
!= '\t'))
6706 || nonascii_hyphen_p
6708 || ! CHAR_PRINTABLE_P (c
))))
6710 /* C is a control character, non-ASCII space/hyphen,
6711 raw-byte, or a non-printable character which must be
6712 displayed either as '\003' or as `^C' where the '\\'
6713 and '^' can be defined in the display table. Fill
6714 IT->ctl_chars with glyphs for what we have to
6715 display. Then, set IT->dpvec to these glyphs. */
6722 /* Handle control characters with ^. */
6724 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6728 g
= '^'; /* default glyph for Control */
6729 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6731 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6733 g
= GLYPH_CODE_CHAR (gc
);
6734 lface_id
= GLYPH_CODE_FACE (gc
);
6738 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6740 else if (it
->f
== last_escape_glyph_frame
6741 && it
->face_id
== last_escape_glyph_face_id
)
6743 face_id
= last_escape_glyph_merged_face_id
;
6747 /* Merge the escape-glyph face into the current face. */
6748 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6750 last_escape_glyph_frame
= it
->f
;
6751 last_escape_glyph_face_id
= it
->face_id
;
6752 last_escape_glyph_merged_face_id
= face_id
;
6755 XSETINT (it
->ctl_chars
[0], g
);
6756 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6758 goto display_control
;
6761 /* Handle non-ascii space in the mode where it only gets
6764 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6766 /* Merge `nobreak-space' into the current face. */
6767 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6769 XSETINT (it
->ctl_chars
[0], ' ');
6771 goto display_control
;
6774 /* Handle sequences that start with the "escape glyph". */
6776 /* the default escape glyph is \. */
6777 escape_glyph
= '\\';
6780 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6782 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6783 lface_id
= GLYPH_CODE_FACE (gc
);
6787 /* The display table specified a face.
6788 Merge it into face_id and also into escape_glyph. */
6789 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6792 else if (it
->f
== last_escape_glyph_frame
6793 && it
->face_id
== last_escape_glyph_face_id
)
6795 face_id
= last_escape_glyph_merged_face_id
;
6799 /* Merge the escape-glyph face into the current face. */
6800 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6802 last_escape_glyph_frame
= it
->f
;
6803 last_escape_glyph_face_id
= it
->face_id
;
6804 last_escape_glyph_merged_face_id
= face_id
;
6807 /* Draw non-ASCII hyphen with just highlighting: */
6809 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6811 XSETINT (it
->ctl_chars
[0], '-');
6813 goto display_control
;
6816 /* Draw non-ASCII space/hyphen with escape glyph: */
6818 if (nonascii_space_p
|| nonascii_hyphen_p
)
6820 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6821 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6823 goto display_control
;
6830 if (CHAR_BYTE8_P (c
))
6831 /* Display \200 instead of \17777600. */
6832 c
= CHAR_TO_BYTE8 (c
);
6833 len
= sprintf (str
, "%03o", c
);
6835 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6836 for (i
= 0; i
< len
; i
++)
6837 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6842 /* Set up IT->dpvec and return first character from it. */
6843 it
->dpvec_char_len
= it
->len
;
6844 it
->dpvec
= it
->ctl_chars
;
6845 it
->dpend
= it
->dpvec
+ ctl_len
;
6846 it
->current
.dpvec_index
= 0;
6847 it
->dpvec_face_id
= face_id
;
6848 it
->saved_face_id
= it
->face_id
;
6849 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6853 it
->char_to_display
= c
;
6857 it
->char_to_display
= it
->c
;
6861 /* Adjust face id for a multibyte character. There are no multibyte
6862 character in unibyte text. */
6863 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6866 && FRAME_WINDOW_P (it
->f
))
6868 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6870 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6872 /* Automatic composition with glyph-string. */
6873 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6875 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6879 ptrdiff_t pos
= (it
->s
? -1
6880 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6881 : IT_CHARPOS (*it
));
6884 if (it
->what
== IT_CHARACTER
)
6885 c
= it
->char_to_display
;
6888 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6892 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6893 /* TAB in a composition means display glyphs with
6894 padding space on the left or right. */
6895 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6898 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6903 /* Is this character the last one of a run of characters with
6904 box? If yes, set IT->end_of_box_run_p to 1. */
6908 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6910 int face_id
= underlying_face_id (it
);
6911 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6915 if (face
->box
== FACE_NO_BOX
)
6917 /* If the box comes from face properties in a
6918 display string, check faces in that string. */
6919 int string_face_id
= face_after_it_pos (it
);
6920 it
->end_of_box_run_p
6921 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6924 /* Otherwise, the box comes from the underlying face.
6925 If this is the last string character displayed, check
6926 the next buffer location. */
6927 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6928 && (it
->current
.overlay_string_index
6929 == it
->n_overlay_strings
- 1))
6933 struct text_pos pos
= it
->current
.pos
;
6934 INC_TEXT_POS (pos
, it
->multibyte_p
);
6936 next_face_id
= face_at_buffer_position
6937 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6938 it
->region_end_charpos
, &ignore
,
6939 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6941 it
->end_of_box_run_p
6942 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6949 int face_id
= face_after_it_pos (it
);
6950 it
->end_of_box_run_p
6951 = (face_id
!= it
->face_id
6952 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6955 /* If we reached the end of the object we've been iterating (e.g., a
6956 display string or an overlay string), and there's something on
6957 IT->stack, proceed with what's on the stack. It doesn't make
6958 sense to return zero if there's unprocessed stuff on the stack,
6959 because otherwise that stuff will never be displayed. */
6960 if (!success_p
&& it
->sp
> 0)
6962 set_iterator_to_next (it
, 0);
6963 success_p
= get_next_display_element (it
);
6966 /* Value is 0 if end of buffer or string reached. */
6971 /* Move IT to the next display element.
6973 RESEAT_P non-zero means if called on a newline in buffer text,
6974 skip to the next visible line start.
6976 Functions get_next_display_element and set_iterator_to_next are
6977 separate because I find this arrangement easier to handle than a
6978 get_next_display_element function that also increments IT's
6979 position. The way it is we can first look at an iterator's current
6980 display element, decide whether it fits on a line, and if it does,
6981 increment the iterator position. The other way around we probably
6982 would either need a flag indicating whether the iterator has to be
6983 incremented the next time, or we would have to implement a
6984 decrement position function which would not be easy to write. */
6987 set_iterator_to_next (struct it
*it
, int reseat_p
)
6989 /* Reset flags indicating start and end of a sequence of characters
6990 with box. Reset them at the start of this function because
6991 moving the iterator to a new position might set them. */
6992 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6996 case GET_FROM_BUFFER
:
6997 /* The current display element of IT is a character from
6998 current_buffer. Advance in the buffer, and maybe skip over
6999 invisible lines that are so because of selective display. */
7000 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7001 reseat_at_next_visible_line_start (it
, 0);
7002 else if (it
->cmp_it
.id
>= 0)
7004 /* We are currently getting glyphs from a composition. */
7009 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7010 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7011 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7013 it
->cmp_it
.from
= it
->cmp_it
.to
;
7018 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7020 it
->end_charpos
, Qnil
);
7023 else if (! it
->cmp_it
.reversed_p
)
7025 /* Composition created while scanning forward. */
7026 /* Update IT's char/byte positions to point to the first
7027 character of the next grapheme cluster, or to the
7028 character visually after the current composition. */
7029 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7030 bidi_move_to_visually_next (&it
->bidi_it
);
7031 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7032 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7034 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7036 /* Proceed to the next grapheme cluster. */
7037 it
->cmp_it
.from
= it
->cmp_it
.to
;
7041 /* No more grapheme clusters in this composition.
7042 Find the next stop position. */
7043 ptrdiff_t stop
= it
->end_charpos
;
7044 if (it
->bidi_it
.scan_dir
< 0)
7045 /* Now we are scanning backward and don't know
7048 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7049 IT_BYTEPOS (*it
), stop
, Qnil
);
7054 /* Composition created while scanning backward. */
7055 /* Update IT's char/byte positions to point to the last
7056 character of the previous grapheme cluster, or the
7057 character visually after the current composition. */
7058 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7059 bidi_move_to_visually_next (&it
->bidi_it
);
7060 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7061 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7062 if (it
->cmp_it
.from
> 0)
7064 /* Proceed to the previous grapheme cluster. */
7065 it
->cmp_it
.to
= it
->cmp_it
.from
;
7069 /* No more grapheme clusters in this composition.
7070 Find the next stop position. */
7071 ptrdiff_t stop
= it
->end_charpos
;
7072 if (it
->bidi_it
.scan_dir
< 0)
7073 /* Now we are scanning backward and don't know
7076 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7077 IT_BYTEPOS (*it
), stop
, Qnil
);
7083 eassert (it
->len
!= 0);
7087 IT_BYTEPOS (*it
) += it
->len
;
7088 IT_CHARPOS (*it
) += 1;
7092 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7093 /* If this is a new paragraph, determine its base
7094 direction (a.k.a. its base embedding level). */
7095 if (it
->bidi_it
.new_paragraph
)
7096 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7097 bidi_move_to_visually_next (&it
->bidi_it
);
7098 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7099 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7100 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7102 /* As the scan direction was changed, we must
7103 re-compute the stop position for composition. */
7104 ptrdiff_t stop
= it
->end_charpos
;
7105 if (it
->bidi_it
.scan_dir
< 0)
7107 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7108 IT_BYTEPOS (*it
), stop
, Qnil
);
7111 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7115 case GET_FROM_C_STRING
:
7116 /* Current display element of IT is from a C string. */
7118 /* If the string position is beyond string's end, it means
7119 next_element_from_c_string is padding the string with
7120 blanks, in which case we bypass the bidi iterator,
7121 because it cannot deal with such virtual characters. */
7122 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7124 IT_BYTEPOS (*it
) += it
->len
;
7125 IT_CHARPOS (*it
) += 1;
7129 bidi_move_to_visually_next (&it
->bidi_it
);
7130 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7131 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7135 case GET_FROM_DISPLAY_VECTOR
:
7136 /* Current display element of IT is from a display table entry.
7137 Advance in the display table definition. Reset it to null if
7138 end reached, and continue with characters from buffers/
7140 ++it
->current
.dpvec_index
;
7142 /* Restore face of the iterator to what they were before the
7143 display vector entry (these entries may contain faces). */
7144 it
->face_id
= it
->saved_face_id
;
7146 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7148 int recheck_faces
= it
->ellipsis_p
;
7151 it
->method
= GET_FROM_C_STRING
;
7152 else if (STRINGP (it
->string
))
7153 it
->method
= GET_FROM_STRING
;
7156 it
->method
= GET_FROM_BUFFER
;
7157 it
->object
= it
->w
->buffer
;
7161 it
->current
.dpvec_index
= -1;
7163 /* Skip over characters which were displayed via IT->dpvec. */
7164 if (it
->dpvec_char_len
< 0)
7165 reseat_at_next_visible_line_start (it
, 1);
7166 else if (it
->dpvec_char_len
> 0)
7168 if (it
->method
== GET_FROM_STRING
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;
7448 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7450 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7452 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7455 /* Now return to buffer/string position where we were asked
7456 to get the next display element, and produce that. */
7457 bidi_move_to_visually_next (&it
->bidi_it
);
7459 while (it
->bidi_it
.bytepos
!= orig_bytepos
7460 && it
->bidi_it
.charpos
< eob
);
7463 /* Adjust IT's position information to where we ended up. */
7464 if (STRINGP (it
->string
))
7466 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7467 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7471 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7472 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7475 if (STRINGP (it
->string
) || !it
->s
)
7477 ptrdiff_t stop
, charpos
, bytepos
;
7479 if (STRINGP (it
->string
))
7482 stop
= SCHARS (it
->string
);
7483 if (stop
> it
->end_charpos
)
7484 stop
= it
->end_charpos
;
7485 charpos
= IT_STRING_CHARPOS (*it
);
7486 bytepos
= IT_STRING_BYTEPOS (*it
);
7490 stop
= it
->end_charpos
;
7491 charpos
= IT_CHARPOS (*it
);
7492 bytepos
= IT_BYTEPOS (*it
);
7494 if (it
->bidi_it
.scan_dir
< 0)
7496 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7501 /* Load IT with the next display element from Lisp string IT->string.
7502 IT->current.string_pos is the current position within the string.
7503 If IT->current.overlay_string_index >= 0, the Lisp string is an
7507 next_element_from_string (struct it
*it
)
7509 struct text_pos position
;
7511 eassert (STRINGP (it
->string
));
7512 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7513 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7514 position
= it
->current
.string_pos
;
7516 /* With bidi reordering, the character to display might not be the
7517 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7518 that we were reseat()ed to a new string, whose paragraph
7519 direction is not known. */
7520 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7522 get_visually_first_element (it
);
7523 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7526 /* Time to check for invisible text? */
7527 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7529 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7532 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7533 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7535 /* With bidi non-linear iteration, we could find
7536 ourselves far beyond the last computed stop_charpos,
7537 with several other stop positions in between that we
7538 missed. Scan them all now, in buffer's logical
7539 order, until we find and handle the last stop_charpos
7540 that precedes our current position. */
7541 handle_stop_backwards (it
, it
->stop_charpos
);
7542 return GET_NEXT_DISPLAY_ELEMENT (it
);
7548 /* Take note of the stop position we just moved
7549 across, for when we will move back across it. */
7550 it
->prev_stop
= it
->stop_charpos
;
7551 /* If we are at base paragraph embedding level, take
7552 note of the last stop position seen at this
7554 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7555 it
->base_level_stop
= it
->stop_charpos
;
7559 /* Since a handler may have changed IT->method, we must
7561 return GET_NEXT_DISPLAY_ELEMENT (it
);
7565 /* If we are before prev_stop, we may have overstepped
7566 on our way backwards a stop_pos, and if so, we need
7567 to handle that stop_pos. */
7568 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7569 /* We can sometimes back up for reasons that have nothing
7570 to do with bidi reordering. E.g., compositions. The
7571 code below is only needed when we are above the base
7572 embedding level, so test for that explicitly. */
7573 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7575 /* If we lost track of base_level_stop, we have no better
7576 place for handle_stop_backwards to start from than string
7577 beginning. This happens, e.g., when we were reseated to
7578 the previous screenful of text by vertical-motion. */
7579 if (it
->base_level_stop
<= 0
7580 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7581 it
->base_level_stop
= 0;
7582 handle_stop_backwards (it
, it
->base_level_stop
);
7583 return GET_NEXT_DISPLAY_ELEMENT (it
);
7587 if (it
->current
.overlay_string_index
>= 0)
7589 /* Get the next character from an overlay string. In overlay
7590 strings, there is no field width or padding with spaces to
7592 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7597 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7598 IT_STRING_BYTEPOS (*it
),
7599 it
->bidi_it
.scan_dir
< 0
7601 : SCHARS (it
->string
))
7602 && next_element_from_composition (it
))
7606 else if (STRING_MULTIBYTE (it
->string
))
7608 const unsigned char *s
= (SDATA (it
->string
)
7609 + IT_STRING_BYTEPOS (*it
));
7610 it
->c
= string_char_and_length (s
, &it
->len
);
7614 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7620 /* Get the next character from a Lisp string that is not an
7621 overlay string. Such strings come from the mode line, for
7622 example. We may have to pad with spaces, or truncate the
7623 string. See also next_element_from_c_string. */
7624 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7629 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7631 /* Pad with spaces. */
7632 it
->c
= ' ', it
->len
= 1;
7633 CHARPOS (position
) = BYTEPOS (position
) = -1;
7635 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7636 IT_STRING_BYTEPOS (*it
),
7637 it
->bidi_it
.scan_dir
< 0
7639 : it
->string_nchars
)
7640 && next_element_from_composition (it
))
7644 else if (STRING_MULTIBYTE (it
->string
))
7646 const unsigned char *s
= (SDATA (it
->string
)
7647 + IT_STRING_BYTEPOS (*it
));
7648 it
->c
= string_char_and_length (s
, &it
->len
);
7652 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7657 /* Record what we have and where it came from. */
7658 it
->what
= IT_CHARACTER
;
7659 it
->object
= it
->string
;
7660 it
->position
= position
;
7665 /* Load IT with next display element from C string IT->s.
7666 IT->string_nchars is the maximum number of characters to return
7667 from the string. IT->end_charpos may be greater than
7668 IT->string_nchars when this function is called, in which case we
7669 may have to return padding spaces. Value is zero if end of string
7670 reached, including padding spaces. */
7673 next_element_from_c_string (struct it
*it
)
7678 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7679 it
->what
= IT_CHARACTER
;
7680 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7683 /* With bidi reordering, the character to display might not be the
7684 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7685 we were reseated to a new string, whose paragraph direction is
7687 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7688 get_visually_first_element (it
);
7690 /* IT's position can be greater than IT->string_nchars in case a
7691 field width or precision has been specified when the iterator was
7693 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7695 /* End of the game. */
7699 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7701 /* Pad with spaces. */
7702 it
->c
= ' ', it
->len
= 1;
7703 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7705 else if (it
->multibyte_p
)
7706 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7708 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7714 /* Set up IT to return characters from an ellipsis, if appropriate.
7715 The definition of the ellipsis glyphs may come from a display table
7716 entry. This function fills IT with the first glyph from the
7717 ellipsis if an ellipsis is to be displayed. */
7720 next_element_from_ellipsis (struct it
*it
)
7722 if (it
->selective_display_ellipsis_p
)
7723 setup_for_ellipsis (it
, it
->len
);
7726 /* The face at the current position may be different from the
7727 face we find after the invisible text. Remember what it
7728 was in IT->saved_face_id, and signal that it's there by
7729 setting face_before_selective_p. */
7730 it
->saved_face_id
= it
->face_id
;
7731 it
->method
= GET_FROM_BUFFER
;
7732 it
->object
= it
->w
->buffer
;
7733 reseat_at_next_visible_line_start (it
, 1);
7734 it
->face_before_selective_p
= 1;
7737 return GET_NEXT_DISPLAY_ELEMENT (it
);
7741 /* Deliver an image display element. The iterator IT is already
7742 filled with image information (done in handle_display_prop). Value
7747 next_element_from_image (struct it
*it
)
7749 it
->what
= IT_IMAGE
;
7750 it
->ignore_overlay_strings_at_pos_p
= 0;
7755 /* Fill iterator IT with next display element from a stretch glyph
7756 property. IT->object is the value of the text property. Value is
7760 next_element_from_stretch (struct it
*it
)
7762 it
->what
= IT_STRETCH
;
7766 /* Scan backwards from IT's current position until we find a stop
7767 position, or until BEGV. This is called when we find ourself
7768 before both the last known prev_stop and base_level_stop while
7769 reordering bidirectional text. */
7772 compute_stop_pos_backwards (struct it
*it
)
7774 const int SCAN_BACK_LIMIT
= 1000;
7775 struct text_pos pos
;
7776 struct display_pos save_current
= it
->current
;
7777 struct text_pos save_position
= it
->position
;
7778 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7779 ptrdiff_t where_we_are
= charpos
;
7780 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7781 ptrdiff_t save_end_pos
= it
->end_charpos
;
7783 eassert (NILP (it
->string
) && !it
->s
);
7784 eassert (it
->bidi_p
);
7788 it
->end_charpos
= min (charpos
+ 1, ZV
);
7789 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7790 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7791 reseat_1 (it
, pos
, 0);
7792 compute_stop_pos (it
);
7793 /* We must advance forward, right? */
7794 if (it
->stop_charpos
<= charpos
)
7797 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7799 if (it
->stop_charpos
<= where_we_are
)
7800 it
->prev_stop
= it
->stop_charpos
;
7802 it
->prev_stop
= BEGV
;
7804 it
->current
= save_current
;
7805 it
->position
= save_position
;
7806 it
->stop_charpos
= save_stop_pos
;
7807 it
->end_charpos
= save_end_pos
;
7810 /* Scan forward from CHARPOS in the current buffer/string, until we
7811 find a stop position > current IT's position. Then handle the stop
7812 position before that. This is called when we bump into a stop
7813 position while reordering bidirectional text. CHARPOS should be
7814 the last previously processed stop_pos (or BEGV/0, if none were
7815 processed yet) whose position is less that IT's current
7819 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7821 int bufp
= !STRINGP (it
->string
);
7822 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7823 struct display_pos save_current
= it
->current
;
7824 struct text_pos save_position
= it
->position
;
7825 struct text_pos pos1
;
7826 ptrdiff_t next_stop
;
7828 /* Scan in strict logical order. */
7829 eassert (it
->bidi_p
);
7833 it
->prev_stop
= charpos
;
7836 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7837 reseat_1 (it
, pos1
, 0);
7840 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7841 compute_stop_pos (it
);
7842 /* We must advance forward, right? */
7843 if (it
->stop_charpos
<= it
->prev_stop
)
7845 charpos
= it
->stop_charpos
;
7847 while (charpos
<= where_we_are
);
7850 it
->current
= save_current
;
7851 it
->position
= save_position
;
7852 next_stop
= it
->stop_charpos
;
7853 it
->stop_charpos
= it
->prev_stop
;
7855 it
->stop_charpos
= next_stop
;
7858 /* Load IT with the next display element from current_buffer. Value
7859 is zero if end of buffer reached. IT->stop_charpos is the next
7860 position at which to stop and check for text properties or buffer
7864 next_element_from_buffer (struct it
*it
)
7868 eassert (IT_CHARPOS (*it
) >= BEGV
);
7869 eassert (NILP (it
->string
) && !it
->s
);
7870 eassert (!it
->bidi_p
7871 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7872 && it
->bidi_it
.string
.s
== NULL
));
7874 /* With bidi reordering, the character to display might not be the
7875 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7876 we were reseat()ed to a new buffer position, which is potentially
7877 a different paragraph. */
7878 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7880 get_visually_first_element (it
);
7881 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7884 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7886 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7888 int overlay_strings_follow_p
;
7890 /* End of the game, except when overlay strings follow that
7891 haven't been returned yet. */
7892 if (it
->overlay_strings_at_end_processed_p
)
7893 overlay_strings_follow_p
= 0;
7896 it
->overlay_strings_at_end_processed_p
= 1;
7897 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7900 if (overlay_strings_follow_p
)
7901 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7905 it
->position
= it
->current
.pos
;
7909 else if (!(!it
->bidi_p
7910 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7911 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7913 /* With bidi non-linear iteration, we could find ourselves
7914 far beyond the last computed stop_charpos, with several
7915 other stop positions in between that we missed. Scan
7916 them all now, in buffer's logical order, until we find
7917 and handle the last stop_charpos that precedes our
7918 current position. */
7919 handle_stop_backwards (it
, it
->stop_charpos
);
7920 return GET_NEXT_DISPLAY_ELEMENT (it
);
7926 /* Take note of the stop position we just moved across,
7927 for when we will move back across it. */
7928 it
->prev_stop
= it
->stop_charpos
;
7929 /* If we are at base paragraph embedding level, take
7930 note of the last stop position seen at this
7932 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7933 it
->base_level_stop
= it
->stop_charpos
;
7936 return GET_NEXT_DISPLAY_ELEMENT (it
);
7940 /* If we are before prev_stop, we may have overstepped on
7941 our way backwards a stop_pos, and if so, we need to
7942 handle that stop_pos. */
7943 && IT_CHARPOS (*it
) < it
->prev_stop
7944 /* We can sometimes back up for reasons that have nothing
7945 to do with bidi reordering. E.g., compositions. The
7946 code below is only needed when we are above the base
7947 embedding level, so test for that explicitly. */
7948 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7950 if (it
->base_level_stop
<= 0
7951 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7953 /* If we lost track of base_level_stop, we need to find
7954 prev_stop by looking backwards. This happens, e.g., when
7955 we were reseated to the previous screenful of text by
7957 it
->base_level_stop
= BEGV
;
7958 compute_stop_pos_backwards (it
);
7959 handle_stop_backwards (it
, it
->prev_stop
);
7962 handle_stop_backwards (it
, it
->base_level_stop
);
7963 return GET_NEXT_DISPLAY_ELEMENT (it
);
7967 /* No face changes, overlays etc. in sight, so just return a
7968 character from current_buffer. */
7972 /* Maybe run the redisplay end trigger hook. Performance note:
7973 This doesn't seem to cost measurable time. */
7974 if (it
->redisplay_end_trigger_charpos
7976 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7977 run_redisplay_end_trigger_hook (it
);
7979 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7980 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7982 && next_element_from_composition (it
))
7987 /* Get the next character, maybe multibyte. */
7988 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7989 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7990 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7992 it
->c
= *p
, it
->len
= 1;
7994 /* Record what we have and where it came from. */
7995 it
->what
= IT_CHARACTER
;
7996 it
->object
= it
->w
->buffer
;
7997 it
->position
= it
->current
.pos
;
7999 /* Normally we return the character found above, except when we
8000 really want to return an ellipsis for selective display. */
8005 /* A value of selective > 0 means hide lines indented more
8006 than that number of columns. */
8007 if (it
->selective
> 0
8008 && IT_CHARPOS (*it
) + 1 < ZV
8009 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8010 IT_BYTEPOS (*it
) + 1,
8013 success_p
= next_element_from_ellipsis (it
);
8014 it
->dpvec_char_len
= -1;
8017 else if (it
->c
== '\r' && it
->selective
== -1)
8019 /* A value of selective == -1 means that everything from the
8020 CR to the end of the line is invisible, with maybe an
8021 ellipsis displayed for it. */
8022 success_p
= next_element_from_ellipsis (it
);
8023 it
->dpvec_char_len
= -1;
8028 /* Value is zero if end of buffer reached. */
8029 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8034 /* Run the redisplay end trigger hook for IT. */
8037 run_redisplay_end_trigger_hook (struct it
*it
)
8039 Lisp_Object args
[3];
8041 /* IT->glyph_row should be non-null, i.e. we should be actually
8042 displaying something, or otherwise we should not run the hook. */
8043 eassert (it
->glyph_row
);
8045 /* Set up hook arguments. */
8046 args
[0] = Qredisplay_end_trigger_functions
;
8047 args
[1] = it
->window
;
8048 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8049 it
->redisplay_end_trigger_charpos
= 0;
8051 /* Since we are *trying* to run these functions, don't try to run
8052 them again, even if they get an error. */
8053 wset_redisplay_end_trigger (it
->w
, Qnil
);
8054 Frun_hook_with_args (3, args
);
8056 /* Notice if it changed the face of the character we are on. */
8057 handle_face_prop (it
);
8061 /* Deliver a composition display element. Unlike the other
8062 next_element_from_XXX, this function is not registered in the array
8063 get_next_element[]. It is called from next_element_from_buffer and
8064 next_element_from_string when necessary. */
8067 next_element_from_composition (struct it
*it
)
8069 it
->what
= IT_COMPOSITION
;
8070 it
->len
= it
->cmp_it
.nbytes
;
8071 if (STRINGP (it
->string
))
8075 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8076 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8079 it
->position
= it
->current
.string_pos
;
8080 it
->object
= it
->string
;
8081 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8082 IT_STRING_BYTEPOS (*it
), it
->string
);
8088 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8089 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8092 if (it
->bidi_it
.new_paragraph
)
8093 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8094 /* Resync the bidi iterator with IT's new position.
8095 FIXME: this doesn't support bidirectional text. */
8096 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8097 bidi_move_to_visually_next (&it
->bidi_it
);
8101 it
->position
= it
->current
.pos
;
8102 it
->object
= it
->w
->buffer
;
8103 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8104 IT_BYTEPOS (*it
), Qnil
);
8111 /***********************************************************************
8112 Moving an iterator without producing glyphs
8113 ***********************************************************************/
8115 /* Check if iterator is at a position corresponding to a valid buffer
8116 position after some move_it_ call. */
8118 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8119 ((it)->method == GET_FROM_STRING \
8120 ? IT_STRING_CHARPOS (*it) == 0 \
8124 /* Move iterator IT to a specified buffer or X position within one
8125 line on the display without producing glyphs.
8127 OP should be a bit mask including some or all of these bits:
8128 MOVE_TO_X: Stop upon reaching x-position TO_X.
8129 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8130 Regardless of OP's value, stop upon reaching the end of the display line.
8132 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8133 This means, in particular, that TO_X includes window's horizontal
8136 The return value has several possible values that
8137 say what condition caused the scan to stop:
8139 MOVE_POS_MATCH_OR_ZV
8140 - when TO_POS or ZV was reached.
8143 -when TO_X was reached before TO_POS or ZV were reached.
8146 - when we reached the end of the display area and the line must
8150 - when we reached the end of the display area and the line is
8154 - when we stopped at a line end, i.e. a newline or a CR and selective
8157 static enum move_it_result
8158 move_it_in_display_line_to (struct it
*it
,
8159 ptrdiff_t to_charpos
, int to_x
,
8160 enum move_operation_enum op
)
8162 enum move_it_result result
= MOVE_UNDEFINED
;
8163 struct glyph_row
*saved_glyph_row
;
8164 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8165 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8166 void *ppos_data
= NULL
;
8168 enum it_method prev_method
= it
->method
;
8169 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8170 int saw_smaller_pos
= prev_pos
< to_charpos
;
8172 /* Don't produce glyphs in produce_glyphs. */
8173 saved_glyph_row
= it
->glyph_row
;
8174 it
->glyph_row
= NULL
;
8176 /* Use wrap_it to save a copy of IT wherever a word wrap could
8177 occur. Use atpos_it to save a copy of IT at the desired buffer
8178 position, if found, so that we can scan ahead and check if the
8179 word later overshoots the window edge. Use atx_it similarly, for
8185 /* Use ppos_it under bidi reordering to save a copy of IT for the
8186 position > CHARPOS that is the closest to CHARPOS. We restore
8187 that position in IT when we have scanned the entire display line
8188 without finding a match for CHARPOS and all the character
8189 positions are greater than CHARPOS. */
8192 SAVE_IT (ppos_it
, *it
, ppos_data
);
8193 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8194 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8195 SAVE_IT (ppos_it
, *it
, ppos_data
);
8198 #define BUFFER_POS_REACHED_P() \
8199 ((op & MOVE_TO_POS) != 0 \
8200 && BUFFERP (it->object) \
8201 && (IT_CHARPOS (*it) == to_charpos \
8203 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8204 && IT_CHARPOS (*it) > to_charpos) \
8205 || (it->what == IT_COMPOSITION \
8206 && ((IT_CHARPOS (*it) > to_charpos \
8207 && to_charpos >= it->cmp_it.charpos) \
8208 || (IT_CHARPOS (*it) < to_charpos \
8209 && to_charpos <= it->cmp_it.charpos)))) \
8210 && (it->method == GET_FROM_BUFFER \
8211 || (it->method == GET_FROM_DISPLAY_VECTOR \
8212 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8214 /* If there's a line-/wrap-prefix, handle it. */
8215 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8216 && it
->current_y
< it
->last_visible_y
)
8217 handle_line_prefix (it
);
8219 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8220 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8224 int x
, i
, ascent
= 0, descent
= 0;
8226 /* Utility macro to reset an iterator with x, ascent, and descent. */
8227 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8228 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8229 (IT)->max_descent = descent)
8231 /* Stop if we move beyond TO_CHARPOS (after an image or a
8232 display string or stretch glyph). */
8233 if ((op
& MOVE_TO_POS
) != 0
8234 && BUFFERP (it
->object
)
8235 && it
->method
== GET_FROM_BUFFER
8237 /* When the iterator is at base embedding level, we
8238 are guaranteed that characters are delivered for
8239 display in strictly increasing order of their
8240 buffer positions. */
8241 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8242 && IT_CHARPOS (*it
) > to_charpos
)
8244 && (prev_method
== GET_FROM_IMAGE
8245 || prev_method
== GET_FROM_STRETCH
8246 || prev_method
== GET_FROM_STRING
)
8247 /* Passed TO_CHARPOS from left to right. */
8248 && ((prev_pos
< to_charpos
8249 && IT_CHARPOS (*it
) > to_charpos
)
8250 /* Passed TO_CHARPOS from right to left. */
8251 || (prev_pos
> to_charpos
8252 && IT_CHARPOS (*it
) < to_charpos
)))))
8254 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8256 result
= MOVE_POS_MATCH_OR_ZV
;
8259 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8260 /* If wrap_it is valid, the current position might be in a
8261 word that is wrapped. So, save the iterator in
8262 atpos_it and continue to see if wrapping happens. */
8263 SAVE_IT (atpos_it
, *it
, atpos_data
);
8266 /* Stop when ZV reached.
8267 We used to stop here when TO_CHARPOS reached as well, but that is
8268 too soon if this glyph does not fit on this line. So we handle it
8269 explicitly below. */
8270 if (!get_next_display_element (it
))
8272 result
= MOVE_POS_MATCH_OR_ZV
;
8276 if (it
->line_wrap
== TRUNCATE
)
8278 if (BUFFER_POS_REACHED_P ())
8280 result
= MOVE_POS_MATCH_OR_ZV
;
8286 if (it
->line_wrap
== WORD_WRAP
)
8288 if (IT_DISPLAYING_WHITESPACE (it
))
8292 /* We have reached a glyph that follows one or more
8293 whitespace characters. If the position is
8294 already found, we are done. */
8295 if (atpos_it
.sp
>= 0)
8297 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8298 result
= MOVE_POS_MATCH_OR_ZV
;
8303 RESTORE_IT (it
, &atx_it
, atx_data
);
8304 result
= MOVE_X_REACHED
;
8307 /* Otherwise, we can wrap here. */
8308 SAVE_IT (wrap_it
, *it
, wrap_data
);
8314 /* Remember the line height for the current line, in case
8315 the next element doesn't fit on the line. */
8316 ascent
= it
->max_ascent
;
8317 descent
= it
->max_descent
;
8319 /* The call to produce_glyphs will get the metrics of the
8320 display element IT is loaded with. Record the x-position
8321 before this display element, in case it doesn't fit on the
8325 PRODUCE_GLYPHS (it
);
8327 if (it
->area
!= TEXT_AREA
)
8329 prev_method
= it
->method
;
8330 if (it
->method
== GET_FROM_BUFFER
)
8331 prev_pos
= IT_CHARPOS (*it
);
8332 set_iterator_to_next (it
, 1);
8333 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8334 SET_TEXT_POS (this_line_min_pos
,
8335 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8337 && (op
& MOVE_TO_POS
)
8338 && IT_CHARPOS (*it
) > to_charpos
8339 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8340 SAVE_IT (ppos_it
, *it
, ppos_data
);
8344 /* The number of glyphs we get back in IT->nglyphs will normally
8345 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8346 character on a terminal frame, or (iii) a line end. For the
8347 second case, IT->nglyphs - 1 padding glyphs will be present.
8348 (On X frames, there is only one glyph produced for a
8349 composite character.)
8351 The behavior implemented below means, for continuation lines,
8352 that as many spaces of a TAB as fit on the current line are
8353 displayed there. For terminal frames, as many glyphs of a
8354 multi-glyph character are displayed in the current line, too.
8355 This is what the old redisplay code did, and we keep it that
8356 way. Under X, the whole shape of a complex character must
8357 fit on the line or it will be completely displayed in the
8360 Note that both for tabs and padding glyphs, all glyphs have
8364 /* More than one glyph or glyph doesn't fit on line. All
8365 glyphs have the same width. */
8366 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8368 int x_before_this_char
= x
;
8369 int hpos_before_this_char
= it
->hpos
;
8371 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8373 new_x
= x
+ single_glyph_width
;
8375 /* We want to leave anything reaching TO_X to the caller. */
8376 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8378 if (BUFFER_POS_REACHED_P ())
8380 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8381 goto buffer_pos_reached
;
8382 if (atpos_it
.sp
< 0)
8384 SAVE_IT (atpos_it
, *it
, atpos_data
);
8385 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8390 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8393 result
= MOVE_X_REACHED
;
8398 SAVE_IT (atx_it
, *it
, atx_data
);
8399 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8404 if (/* Lines are continued. */
8405 it
->line_wrap
!= TRUNCATE
8406 && (/* And glyph doesn't fit on the line. */
8407 new_x
> it
->last_visible_x
8408 /* Or it fits exactly and we're on a window
8410 || (new_x
== it
->last_visible_x
8411 && FRAME_WINDOW_P (it
->f
)
8412 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8413 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8414 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8416 if (/* IT->hpos == 0 means the very first glyph
8417 doesn't fit on the line, e.g. a wide image. */
8419 || (new_x
== it
->last_visible_x
8420 && FRAME_WINDOW_P (it
->f
)))
8423 it
->current_x
= new_x
;
8425 /* The character's last glyph just barely fits
8427 if (i
== it
->nglyphs
- 1)
8429 /* If this is the destination position,
8430 return a position *before* it in this row,
8431 now that we know it fits in this row. */
8432 if (BUFFER_POS_REACHED_P ())
8434 if (it
->line_wrap
!= WORD_WRAP
8437 it
->hpos
= hpos_before_this_char
;
8438 it
->current_x
= x_before_this_char
;
8439 result
= MOVE_POS_MATCH_OR_ZV
;
8442 if (it
->line_wrap
== WORD_WRAP
8445 SAVE_IT (atpos_it
, *it
, atpos_data
);
8446 atpos_it
.current_x
= x_before_this_char
;
8447 atpos_it
.hpos
= hpos_before_this_char
;
8451 prev_method
= it
->method
;
8452 if (it
->method
== GET_FROM_BUFFER
)
8453 prev_pos
= IT_CHARPOS (*it
);
8454 set_iterator_to_next (it
, 1);
8455 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8456 SET_TEXT_POS (this_line_min_pos
,
8457 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8458 /* On graphical terminals, newlines may
8459 "overflow" into the fringe if
8460 overflow-newline-into-fringe is non-nil.
8461 On text terminals, and on graphical
8462 terminals with no right margin, newlines
8463 may overflow into the last glyph on the
8465 if (!FRAME_WINDOW_P (it
->f
)
8467 && it
->bidi_it
.paragraph_dir
== R2L
)
8468 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8469 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8470 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8472 if (!get_next_display_element (it
))
8474 result
= MOVE_POS_MATCH_OR_ZV
;
8477 if (BUFFER_POS_REACHED_P ())
8479 if (ITERATOR_AT_END_OF_LINE_P (it
))
8480 result
= MOVE_POS_MATCH_OR_ZV
;
8482 result
= MOVE_LINE_CONTINUED
;
8485 if (ITERATOR_AT_END_OF_LINE_P (it
))
8487 result
= MOVE_NEWLINE_OR_CR
;
8494 IT_RESET_X_ASCENT_DESCENT (it
);
8496 if (wrap_it
.sp
>= 0)
8498 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8503 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8505 result
= MOVE_LINE_CONTINUED
;
8509 if (BUFFER_POS_REACHED_P ())
8511 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8512 goto buffer_pos_reached
;
8513 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8515 SAVE_IT (atpos_it
, *it
, atpos_data
);
8516 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8520 if (new_x
> it
->first_visible_x
)
8522 /* Glyph is visible. Increment number of glyphs that
8523 would be displayed. */
8528 if (result
!= MOVE_UNDEFINED
)
8531 else if (BUFFER_POS_REACHED_P ())
8534 IT_RESET_X_ASCENT_DESCENT (it
);
8535 result
= MOVE_POS_MATCH_OR_ZV
;
8538 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8540 /* Stop when TO_X specified and reached. This check is
8541 necessary here because of lines consisting of a line end,
8542 only. The line end will not produce any glyphs and we
8543 would never get MOVE_X_REACHED. */
8544 eassert (it
->nglyphs
== 0);
8545 result
= MOVE_X_REACHED
;
8549 /* Is this a line end? If yes, we're done. */
8550 if (ITERATOR_AT_END_OF_LINE_P (it
))
8552 /* If we are past TO_CHARPOS, but never saw any character
8553 positions smaller than TO_CHARPOS, return
8554 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8556 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8558 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8560 if (IT_CHARPOS (ppos_it
) < ZV
)
8562 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8563 result
= MOVE_POS_MATCH_OR_ZV
;
8566 goto buffer_pos_reached
;
8568 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8569 && IT_CHARPOS (*it
) > to_charpos
)
8570 goto buffer_pos_reached
;
8572 result
= MOVE_NEWLINE_OR_CR
;
8575 result
= MOVE_NEWLINE_OR_CR
;
8579 prev_method
= it
->method
;
8580 if (it
->method
== GET_FROM_BUFFER
)
8581 prev_pos
= IT_CHARPOS (*it
);
8582 /* The current display element has been consumed. Advance
8584 set_iterator_to_next (it
, 1);
8585 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8586 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8587 if (IT_CHARPOS (*it
) < to_charpos
)
8588 saw_smaller_pos
= 1;
8590 && (op
& MOVE_TO_POS
)
8591 && IT_CHARPOS (*it
) >= to_charpos
8592 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8593 SAVE_IT (ppos_it
, *it
, ppos_data
);
8595 /* Stop if lines are truncated and IT's current x-position is
8596 past the right edge of the window now. */
8597 if (it
->line_wrap
== TRUNCATE
8598 && it
->current_x
>= it
->last_visible_x
)
8600 if (!FRAME_WINDOW_P (it
->f
)
8601 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8602 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8603 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8604 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8608 if ((at_eob_p
= !get_next_display_element (it
))
8609 || BUFFER_POS_REACHED_P ()
8610 /* If we are past TO_CHARPOS, but never saw any
8611 character positions smaller than TO_CHARPOS,
8612 return MOVE_POS_MATCH_OR_ZV, like the
8613 unidirectional display did. */
8614 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8616 && IT_CHARPOS (*it
) > to_charpos
))
8619 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8620 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8621 result
= MOVE_POS_MATCH_OR_ZV
;
8624 if (ITERATOR_AT_END_OF_LINE_P (it
))
8626 result
= MOVE_NEWLINE_OR_CR
;
8630 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8632 && IT_CHARPOS (*it
) > to_charpos
)
8634 if (IT_CHARPOS (ppos_it
) < ZV
)
8635 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8636 result
= MOVE_POS_MATCH_OR_ZV
;
8639 result
= MOVE_LINE_TRUNCATED
;
8642 #undef IT_RESET_X_ASCENT_DESCENT
8645 #undef BUFFER_POS_REACHED_P
8647 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8648 restore the saved iterator. */
8649 if (atpos_it
.sp
>= 0)
8650 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8651 else if (atx_it
.sp
>= 0)
8652 RESTORE_IT (it
, &atx_it
, atx_data
);
8657 bidi_unshelve_cache (atpos_data
, 1);
8659 bidi_unshelve_cache (atx_data
, 1);
8661 bidi_unshelve_cache (wrap_data
, 1);
8663 bidi_unshelve_cache (ppos_data
, 1);
8665 /* Restore the iterator settings altered at the beginning of this
8667 it
->glyph_row
= saved_glyph_row
;
8671 /* For external use. */
8673 move_it_in_display_line (struct it
*it
,
8674 ptrdiff_t to_charpos
, int to_x
,
8675 enum move_operation_enum op
)
8677 if (it
->line_wrap
== WORD_WRAP
8678 && (op
& MOVE_TO_X
))
8681 void *save_data
= NULL
;
8684 SAVE_IT (save_it
, *it
, save_data
);
8685 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8686 /* When word-wrap is on, TO_X may lie past the end
8687 of a wrapped line. Then it->current is the
8688 character on the next line, so backtrack to the
8689 space before the wrap point. */
8690 if (skip
== MOVE_LINE_CONTINUED
)
8692 int prev_x
= max (it
->current_x
- 1, 0);
8693 RESTORE_IT (it
, &save_it
, save_data
);
8694 move_it_in_display_line_to
8695 (it
, -1, prev_x
, MOVE_TO_X
);
8698 bidi_unshelve_cache (save_data
, 1);
8701 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8705 /* Move IT forward until it satisfies one or more of the criteria in
8706 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8708 OP is a bit-mask that specifies where to stop, and in particular,
8709 which of those four position arguments makes a difference. See the
8710 description of enum move_operation_enum.
8712 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8713 screen line, this function will set IT to the next position that is
8714 displayed to the right of TO_CHARPOS on the screen. */
8717 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8719 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8720 int line_height
, line_start_x
= 0, reached
= 0;
8721 void *backup_data
= NULL
;
8725 if (op
& MOVE_TO_VPOS
)
8727 /* If no TO_CHARPOS and no TO_X specified, stop at the
8728 start of the line TO_VPOS. */
8729 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8731 if (it
->vpos
== to_vpos
)
8737 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8741 /* TO_VPOS >= 0 means stop at TO_X in the line at
8742 TO_VPOS, or at TO_POS, whichever comes first. */
8743 if (it
->vpos
== to_vpos
)
8749 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8751 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8756 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8758 /* We have reached TO_X but not in the line we want. */
8759 skip
= move_it_in_display_line_to (it
, to_charpos
,
8761 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8769 else if (op
& MOVE_TO_Y
)
8771 struct it it_backup
;
8773 if (it
->line_wrap
== WORD_WRAP
)
8774 SAVE_IT (it_backup
, *it
, backup_data
);
8776 /* TO_Y specified means stop at TO_X in the line containing
8777 TO_Y---or at TO_CHARPOS if this is reached first. The
8778 problem is that we can't really tell whether the line
8779 contains TO_Y before we have completely scanned it, and
8780 this may skip past TO_X. What we do is to first scan to
8783 If TO_X is not specified, use a TO_X of zero. The reason
8784 is to make the outcome of this function more predictable.
8785 If we didn't use TO_X == 0, we would stop at the end of
8786 the line which is probably not what a caller would expect
8788 skip
= move_it_in_display_line_to
8789 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8790 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8792 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8793 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8795 else if (skip
== MOVE_X_REACHED
)
8797 /* If TO_X was reached, we want to know whether TO_Y is
8798 in the line. We know this is the case if the already
8799 scanned glyphs make the line tall enough. Otherwise,
8800 we must check by scanning the rest of the line. */
8801 line_height
= it
->max_ascent
+ it
->max_descent
;
8802 if (to_y
>= it
->current_y
8803 && to_y
< it
->current_y
+ line_height
)
8808 SAVE_IT (it_backup
, *it
, backup_data
);
8809 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8810 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8812 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8813 line_height
= it
->max_ascent
+ it
->max_descent
;
8814 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8816 if (to_y
>= it
->current_y
8817 && to_y
< it
->current_y
+ line_height
)
8819 /* If TO_Y is in this line and TO_X was reached
8820 above, we scanned too far. We have to restore
8821 IT's settings to the ones before skipping. But
8822 keep the more accurate values of max_ascent and
8823 max_descent we've found while skipping the rest
8824 of the line, for the sake of callers, such as
8825 pos_visible_p, that need to know the line
8827 int max_ascent
= it
->max_ascent
;
8828 int max_descent
= it
->max_descent
;
8830 RESTORE_IT (it
, &it_backup
, backup_data
);
8831 it
->max_ascent
= max_ascent
;
8832 it
->max_descent
= max_descent
;
8838 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8844 /* Check whether TO_Y is in this line. */
8845 line_height
= it
->max_ascent
+ it
->max_descent
;
8846 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8848 if (to_y
>= it
->current_y
8849 && to_y
< it
->current_y
+ line_height
)
8851 /* When word-wrap is on, TO_X may lie past the end
8852 of a wrapped line. Then it->current is the
8853 character on the next line, so backtrack to the
8854 space before the wrap point. */
8855 if (skip
== MOVE_LINE_CONTINUED
8856 && it
->line_wrap
== WORD_WRAP
)
8858 int prev_x
= max (it
->current_x
- 1, 0);
8859 RESTORE_IT (it
, &it_backup
, backup_data
);
8860 skip
= move_it_in_display_line_to
8861 (it
, -1, prev_x
, MOVE_TO_X
);
8870 else if (BUFFERP (it
->object
)
8871 && (it
->method
== GET_FROM_BUFFER
8872 || it
->method
== GET_FROM_STRETCH
)
8873 && IT_CHARPOS (*it
) >= to_charpos
8874 /* Under bidi iteration, a call to set_iterator_to_next
8875 can scan far beyond to_charpos if the initial
8876 portion of the next line needs to be reordered. In
8877 that case, give move_it_in_display_line_to another
8880 && it
->bidi_it
.scan_dir
== -1))
8881 skip
= MOVE_POS_MATCH_OR_ZV
;
8883 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8887 case MOVE_POS_MATCH_OR_ZV
:
8891 case MOVE_NEWLINE_OR_CR
:
8892 set_iterator_to_next (it
, 1);
8893 it
->continuation_lines_width
= 0;
8896 case MOVE_LINE_TRUNCATED
:
8897 it
->continuation_lines_width
= 0;
8898 reseat_at_next_visible_line_start (it
, 0);
8899 if ((op
& MOVE_TO_POS
) != 0
8900 && IT_CHARPOS (*it
) > to_charpos
)
8907 case MOVE_LINE_CONTINUED
:
8908 /* For continued lines ending in a tab, some of the glyphs
8909 associated with the tab are displayed on the current
8910 line. Since it->current_x does not include these glyphs,
8911 we use it->last_visible_x instead. */
8914 it
->continuation_lines_width
+= it
->last_visible_x
;
8915 /* When moving by vpos, ensure that the iterator really
8916 advances to the next line (bug#847, bug#969). Fixme:
8917 do we need to do this in other circumstances? */
8918 if (it
->current_x
!= it
->last_visible_x
8919 && (op
& MOVE_TO_VPOS
)
8920 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8922 line_start_x
= it
->current_x
+ it
->pixel_width
8923 - it
->last_visible_x
;
8924 set_iterator_to_next (it
, 0);
8928 it
->continuation_lines_width
+= it
->current_x
;
8935 /* Reset/increment for the next run. */
8936 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8937 it
->current_x
= line_start_x
;
8940 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8942 last_height
= it
->max_ascent
+ it
->max_descent
;
8943 last_max_ascent
= it
->max_ascent
;
8944 it
->max_ascent
= it
->max_descent
= 0;
8949 /* On text terminals, we may stop at the end of a line in the middle
8950 of a multi-character glyph. If the glyph itself is continued,
8951 i.e. it is actually displayed on the next line, don't treat this
8952 stopping point as valid; move to the next line instead (unless
8953 that brings us offscreen). */
8954 if (!FRAME_WINDOW_P (it
->f
)
8956 && IT_CHARPOS (*it
) == to_charpos
8957 && it
->what
== IT_CHARACTER
8959 && it
->line_wrap
== WINDOW_WRAP
8960 && it
->current_x
== it
->last_visible_x
- 1
8963 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8965 it
->continuation_lines_width
+= it
->current_x
;
8966 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8967 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8969 last_height
= it
->max_ascent
+ it
->max_descent
;
8970 last_max_ascent
= it
->max_ascent
;
8974 bidi_unshelve_cache (backup_data
, 1);
8976 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8980 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8982 If DY > 0, move IT backward at least that many pixels. DY = 0
8983 means move IT backward to the preceding line start or BEGV. This
8984 function may move over more than DY pixels if IT->current_y - DY
8985 ends up in the middle of a line; in this case IT->current_y will be
8986 set to the top of the line moved to. */
8989 move_it_vertically_backward (struct it
*it
, int dy
)
8993 void *it2data
= NULL
, *it3data
= NULL
;
8994 ptrdiff_t start_pos
;
8996 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
8997 ptrdiff_t pos_limit
;
9002 start_pos
= IT_CHARPOS (*it
);
9004 /* Estimate how many newlines we must move back. */
9005 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9006 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9008 /* Set the iterator's position that many lines back. But don't go
9009 back more than NLINES full screen lines -- this wins a day with
9010 buffers which have very long lines. */
9011 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9012 back_to_previous_visible_line_start (it
);
9014 /* Reseat the iterator here. When moving backward, we don't want
9015 reseat to skip forward over invisible text, set up the iterator
9016 to deliver from overlay strings at the new position etc. So,
9017 use reseat_1 here. */
9018 reseat_1 (it
, it
->current
.pos
, 1);
9020 /* We are now surely at a line start. */
9021 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9022 reordering is in effect. */
9023 it
->continuation_lines_width
= 0;
9025 /* Move forward and see what y-distance we moved. First move to the
9026 start of the next line so that we get its height. We need this
9027 height to be able to tell whether we reached the specified
9029 SAVE_IT (it2
, *it
, it2data
);
9030 it2
.max_ascent
= it2
.max_descent
= 0;
9033 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9034 MOVE_TO_POS
| MOVE_TO_VPOS
);
9036 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9037 /* If we are in a display string which starts at START_POS,
9038 and that display string includes a newline, and we are
9039 right after that newline (i.e. at the beginning of a
9040 display line), exit the loop, because otherwise we will
9041 infloop, since move_it_to will see that it is already at
9042 START_POS and will not move. */
9043 || (it2
.method
== GET_FROM_STRING
9044 && IT_CHARPOS (it2
) == start_pos
9045 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9046 eassert (IT_CHARPOS (*it
) >= BEGV
);
9047 SAVE_IT (it3
, it2
, it3data
);
9049 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9050 eassert (IT_CHARPOS (*it
) >= BEGV
);
9051 /* H is the actual vertical distance from the position in *IT
9052 and the starting position. */
9053 h
= it2
.current_y
- it
->current_y
;
9054 /* NLINES is the distance in number of lines. */
9055 nlines
= it2
.vpos
- it
->vpos
;
9057 /* Correct IT's y and vpos position
9058 so that they are relative to the starting point. */
9064 /* DY == 0 means move to the start of the screen line. The
9065 value of nlines is > 0 if continuation lines were involved,
9066 or if the original IT position was at start of a line. */
9067 RESTORE_IT (it
, it
, it2data
);
9069 move_it_by_lines (it
, nlines
);
9070 /* The above code moves us to some position NLINES down,
9071 usually to its first glyph (leftmost in an L2R line), but
9072 that's not necessarily the start of the line, under bidi
9073 reordering. We want to get to the character position
9074 that is immediately after the newline of the previous
9077 && !it
->continuation_lines_width
9078 && !STRINGP (it
->string
)
9079 && IT_CHARPOS (*it
) > BEGV
9080 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9083 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9085 move_it_to (it
, nl_pos
, -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 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9257 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9258 back_to_previous_visible_line_start (it
);
9259 reseat (it
, it
->current
.pos
, 1);
9261 /* Move further back if we end up in a string or an image. */
9262 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9264 /* First try to move to start of display line. */
9266 move_it_vertically_backward (it
, 0);
9268 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9270 /* If start of line is still in string or image,
9271 move further back. */
9272 back_to_previous_visible_line_start (it
);
9273 reseat (it
, it
->current
.pos
, 1);
9277 it
->current_x
= it
->hpos
= 0;
9279 /* Above call may have moved too far if continuation lines
9280 are involved. Scan forward and see if it did. */
9281 SAVE_IT (it2
, *it
, it2data
);
9282 it2
.vpos
= it2
.current_y
= 0;
9283 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9284 it
->vpos
-= it2
.vpos
;
9285 it
->current_y
-= it2
.current_y
;
9286 it
->current_x
= it
->hpos
= 0;
9288 /* If we moved too far back, move IT some lines forward. */
9289 if (it2
.vpos
> -dvpos
)
9291 int delta
= it2
.vpos
+ dvpos
;
9293 RESTORE_IT (&it2
, &it2
, it2data
);
9294 SAVE_IT (it2
, *it
, it2data
);
9295 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9296 /* Move back again if we got too far ahead. */
9297 if (IT_CHARPOS (*it
) >= start_charpos
)
9298 RESTORE_IT (it
, &it2
, it2data
);
9300 bidi_unshelve_cache (it2data
, 1);
9303 RESTORE_IT (it
, it
, it2data
);
9307 /* Return 1 if IT points into the middle of a display vector. */
9310 in_display_vector_p (struct it
*it
)
9312 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9313 && it
->current
.dpvec_index
> 0
9314 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9318 /***********************************************************************
9320 ***********************************************************************/
9323 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9327 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9329 Lisp_Object args
[3];
9330 Lisp_Object msg
, fmt
;
9333 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9337 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9339 args
[0] = fmt
= build_string (format
);
9342 msg
= Fformat (3, args
);
9344 len
= SBYTES (msg
) + 1;
9345 buffer
= SAFE_ALLOCA (len
);
9346 memcpy (buffer
, SDATA (msg
), len
);
9348 message_dolog (buffer
, len
- 1, 1, 0);
9355 /* Output a newline in the *Messages* buffer if "needs" one. */
9358 message_log_maybe_newline (void)
9360 if (message_log_need_newline
)
9361 message_dolog ("", 0, 1, 0);
9365 /* Add a string M of length NBYTES to the message log, optionally
9366 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9367 nonzero, means interpret the contents of M as multibyte. This
9368 function calls low-level routines in order to bypass text property
9369 hooks, etc. which might not be safe to run.
9371 This may GC (insert may run before/after change hooks),
9372 so the buffer M must NOT point to a Lisp string. */
9375 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9377 const unsigned char *msg
= (const unsigned char *) m
;
9379 if (!NILP (Vmemory_full
))
9382 if (!NILP (Vmessage_log_max
))
9384 struct buffer
*oldbuf
;
9385 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9386 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9387 ptrdiff_t point_at_end
= 0;
9388 ptrdiff_t zv_at_end
= 0;
9389 Lisp_Object old_deactivate_mark
;
9391 struct gcpro gcpro1
;
9393 old_deactivate_mark
= Vdeactivate_mark
;
9394 oldbuf
= current_buffer
;
9395 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9396 bset_undo_list (current_buffer
, Qt
);
9398 oldpoint
= message_dolog_marker1
;
9399 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9400 oldbegv
= message_dolog_marker2
;
9401 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9402 oldzv
= message_dolog_marker3
;
9403 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9404 GCPRO1 (old_deactivate_mark
);
9412 BEGV_BYTE
= BEG_BYTE
;
9415 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9417 /* Insert the string--maybe converting multibyte to single byte
9418 or vice versa, so that all the text fits the buffer. */
9420 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9426 /* Convert a multibyte string to single-byte
9427 for the *Message* buffer. */
9428 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9430 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9431 work
[0] = (ASCII_CHAR_P (c
)
9433 : multibyte_char_to_unibyte (c
));
9434 insert_1_both (work
, 1, 1, 1, 0, 0);
9437 else if (! multibyte
9438 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9442 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9443 /* Convert a single-byte string to multibyte
9444 for the *Message* buffer. */
9445 for (i
= 0; i
< nbytes
; i
++)
9448 MAKE_CHAR_MULTIBYTE (c
);
9449 char_bytes
= CHAR_STRING (c
, str
);
9450 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9454 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9458 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9461 insert_1_both ("\n", 1, 1, 1, 0, 0);
9463 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9465 this_bol_byte
= PT_BYTE
;
9467 /* See if this line duplicates the previous one.
9468 If so, combine duplicates. */
9471 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9473 prev_bol_byte
= PT_BYTE
;
9475 dups
= message_log_check_duplicate (prev_bol_byte
,
9479 del_range_both (prev_bol
, prev_bol_byte
,
9480 this_bol
, this_bol_byte
, 0);
9483 char dupstr
[sizeof " [ times]"
9484 + INT_STRLEN_BOUND (printmax_t
)];
9486 /* If you change this format, don't forget to also
9487 change message_log_check_duplicate. */
9488 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9489 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9490 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9495 /* If we have more than the desired maximum number of lines
9496 in the *Messages* buffer now, delete the oldest ones.
9497 This is safe because we don't have undo in this buffer. */
9499 if (NATNUMP (Vmessage_log_max
))
9501 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9502 -XFASTINT (Vmessage_log_max
) - 1, 0);
9503 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9506 BEGV
= marker_position (oldbegv
);
9507 BEGV_BYTE
= marker_byte_position (oldbegv
);
9516 ZV
= marker_position (oldzv
);
9517 ZV_BYTE
= marker_byte_position (oldzv
);
9521 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9523 /* We can't do Fgoto_char (oldpoint) because it will run some
9525 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9526 marker_byte_position (oldpoint
));
9529 unchain_marker (XMARKER (oldpoint
));
9530 unchain_marker (XMARKER (oldbegv
));
9531 unchain_marker (XMARKER (oldzv
));
9533 shown
= buffer_window_count (current_buffer
) > 0;
9534 set_buffer_internal (oldbuf
);
9536 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9537 message_log_need_newline
= !nlflag
;
9538 Vdeactivate_mark
= old_deactivate_mark
;
9543 /* We are at the end of the buffer after just having inserted a newline.
9544 (Note: We depend on the fact we won't be crossing the gap.)
9545 Check to see if the most recent message looks a lot like the previous one.
9546 Return 0 if different, 1 if the new one should just replace it, or a
9547 value N > 1 if we should also append " [N times]". */
9550 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9553 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9555 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9556 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9558 for (i
= 0; i
< len
; i
++)
9560 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9568 if (*p1
++ == ' ' && *p1
++ == '[')
9571 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9572 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9579 /* Display an echo area message M with a specified length of NBYTES
9580 bytes. The string may include null characters. If M is not a
9581 string, clear out any existing message, and let the mini-buffer
9584 This function cancels echoing. */
9587 message3 (Lisp_Object m
)
9589 struct gcpro gcpro1
;
9592 clear_message (1,1);
9595 /* First flush out any partial line written with print. */
9596 message_log_maybe_newline ();
9599 ptrdiff_t nbytes
= SBYTES (m
);
9600 int multibyte
= STRING_MULTIBYTE (m
);
9602 char *buffer
= SAFE_ALLOCA (nbytes
);
9603 memcpy (buffer
, SDATA (m
), nbytes
);
9604 message_dolog (buffer
, nbytes
, 1, multibyte
);
9613 /* The non-logging version of message3.
9614 This does not cancel echoing, because it is used for echoing.
9615 Perhaps we need to make a separate function for echoing
9616 and make this cancel echoing. */
9619 message3_nolog (Lisp_Object m
)
9621 struct frame
*sf
= SELECTED_FRAME ();
9623 if (FRAME_INITIAL_P (sf
))
9625 if (noninteractive_need_newline
)
9626 putc ('\n', stderr
);
9627 noninteractive_need_newline
= 0;
9629 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9630 if (cursor_in_echo_area
== 0)
9631 fprintf (stderr
, "\n");
9634 /* Error messages get reported properly by cmd_error, so this must be just an
9635 informative message; if the frame hasn't really been initialized yet, just
9637 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9639 /* Get the frame containing the mini-buffer
9640 that the selected frame is using. */
9641 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9642 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9643 struct frame
*f
= XFRAME (frame
);
9645 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9646 Fmake_frame_visible (frame
);
9648 if (STRINGP (m
) && SCHARS (m
) > 0)
9651 if (minibuffer_auto_raise
)
9652 Fraise_frame (frame
);
9653 /* Assume we are not echoing.
9654 (If we are, echo_now will override this.) */
9655 echo_message_buffer
= Qnil
;
9658 clear_message (1, 1);
9660 do_pending_window_change (0);
9661 echo_area_display (1);
9662 do_pending_window_change (0);
9663 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9664 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9669 /* Display a null-terminated echo area message M. If M is 0, clear
9670 out any existing message, and let the mini-buffer text show through.
9672 The buffer M must continue to exist until after the echo area gets
9673 cleared or some other message gets displayed there. Do not pass
9674 text that is stored in a Lisp string. Do not pass text in a buffer
9675 that was alloca'd. */
9678 message1 (const char *m
)
9680 message3 (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9684 /* The non-logging counterpart of message1. */
9687 message1_nolog (const char *m
)
9689 message3_nolog (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9692 /* Display a message M which contains a single %s
9693 which gets replaced with STRING. */
9696 message_with_string (const char *m
, Lisp_Object string
, int log
)
9698 CHECK_STRING (string
);
9704 if (noninteractive_need_newline
)
9705 putc ('\n', stderr
);
9706 noninteractive_need_newline
= 0;
9707 fprintf (stderr
, m
, SDATA (string
));
9708 if (!cursor_in_echo_area
)
9709 fprintf (stderr
, "\n");
9713 else if (INTERACTIVE
)
9715 /* The frame whose minibuffer we're going to display the message on.
9716 It may be larger than the selected frame, so we need
9717 to use its buffer, not the selected frame's buffer. */
9718 Lisp_Object mini_window
;
9719 struct frame
*f
, *sf
= SELECTED_FRAME ();
9721 /* Get the frame containing the minibuffer
9722 that the selected frame is using. */
9723 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9724 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9726 /* Error messages get reported properly by cmd_error, so this must be
9727 just an informative message; if the frame hasn't really been
9728 initialized yet, just toss it. */
9729 if (f
->glyphs_initialized_p
)
9731 Lisp_Object args
[2], msg
;
9732 struct gcpro gcpro1
, gcpro2
;
9734 args
[0] = build_string (m
);
9735 args
[1] = msg
= string
;
9736 GCPRO2 (args
[0], msg
);
9739 msg
= Fformat (2, args
);
9744 message3_nolog (msg
);
9748 /* Print should start at the beginning of the message
9749 buffer next time. */
9750 message_buf_print
= 0;
9756 /* Dump an informative message to the minibuf. If M is 0, clear out
9757 any existing message, and let the mini-buffer text show through. */
9760 vmessage (const char *m
, va_list ap
)
9766 if (noninteractive_need_newline
)
9767 putc ('\n', stderr
);
9768 noninteractive_need_newline
= 0;
9769 vfprintf (stderr
, m
, ap
);
9770 if (cursor_in_echo_area
== 0)
9771 fprintf (stderr
, "\n");
9775 else if (INTERACTIVE
)
9777 /* The frame whose mini-buffer we're going to display the message
9778 on. It may be larger than the selected frame, so we need to
9779 use its buffer, not the selected frame's buffer. */
9780 Lisp_Object mini_window
;
9781 struct frame
*f
, *sf
= SELECTED_FRAME ();
9783 /* Get the frame containing the mini-buffer
9784 that the selected frame is using. */
9785 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9786 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9788 /* Error messages get reported properly by cmd_error, so this must be
9789 just an informative message; if the frame hasn't really been
9790 initialized yet, just toss it. */
9791 if (f
->glyphs_initialized_p
)
9796 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9797 char *message_buf
= alloca (maxsize
+ 1);
9799 len
= doprnt (message_buf
, maxsize
, m
, (char *)0, ap
);
9801 message3 (make_string (message_buf
, len
));
9806 /* Print should start at the beginning of the message
9807 buffer next time. */
9808 message_buf_print
= 0;
9814 message (const char *m
, ...)
9824 /* The non-logging version of message. */
9827 message_nolog (const char *m
, ...)
9829 Lisp_Object old_log_max
;
9832 old_log_max
= Vmessage_log_max
;
9833 Vmessage_log_max
= Qnil
;
9835 Vmessage_log_max
= old_log_max
;
9841 /* Display the current message in the current mini-buffer. This is
9842 only called from error handlers in process.c, and is not time
9846 update_echo_area (void)
9848 if (!NILP (echo_area_buffer
[0]))
9851 string
= Fcurrent_message ();
9857 /* Make sure echo area buffers in `echo_buffers' are live.
9858 If they aren't, make new ones. */
9861 ensure_echo_area_buffers (void)
9865 for (i
= 0; i
< 2; ++i
)
9866 if (!BUFFERP (echo_buffer
[i
])
9867 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9870 Lisp_Object old_buffer
;
9873 old_buffer
= echo_buffer
[i
];
9874 echo_buffer
[i
] = Fget_buffer_create
9875 (make_formatted_string (name
, " *Echo Area %d*", i
));
9876 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9877 /* to force word wrap in echo area -
9878 it was decided to postpone this*/
9879 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9881 for (j
= 0; j
< 2; ++j
)
9882 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9883 echo_area_buffer
[j
] = echo_buffer
[i
];
9888 /* Call FN with args A1..A2 with either the current or last displayed
9889 echo_area_buffer as current buffer.
9891 WHICH zero means use the current message buffer
9892 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9893 from echo_buffer[] and clear it.
9895 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9896 suitable buffer from echo_buffer[] and clear it.
9898 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9899 that the current message becomes the last displayed one, make
9900 choose a suitable buffer for echo_area_buffer[0], and clear it.
9902 Value is what FN returns. */
9905 with_echo_area_buffer (struct window
*w
, int which
,
9906 int (*fn
) (ptrdiff_t, Lisp_Object
),
9907 ptrdiff_t a1
, Lisp_Object a2
)
9910 int this_one
, the_other
, clear_buffer_p
, rc
;
9911 ptrdiff_t count
= SPECPDL_INDEX ();
9913 /* If buffers aren't live, make new ones. */
9914 ensure_echo_area_buffers ();
9919 this_one
= 0, the_other
= 1;
9921 this_one
= 1, the_other
= 0;
9924 this_one
= 0, the_other
= 1;
9927 /* We need a fresh one in case the current echo buffer equals
9928 the one containing the last displayed echo area message. */
9929 if (!NILP (echo_area_buffer
[this_one
])
9930 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9931 echo_area_buffer
[this_one
] = Qnil
;
9934 /* Choose a suitable buffer from echo_buffer[] is we don't
9936 if (NILP (echo_area_buffer
[this_one
]))
9938 echo_area_buffer
[this_one
]
9939 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9940 ? echo_buffer
[the_other
]
9941 : echo_buffer
[this_one
]);
9945 buffer
= echo_area_buffer
[this_one
];
9947 /* Don't get confused by reusing the buffer used for echoing
9948 for a different purpose. */
9949 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9952 record_unwind_protect (unwind_with_echo_area_buffer
,
9953 with_echo_area_buffer_unwind_data (w
));
9955 /* Make the echo area buffer current. Note that for display
9956 purposes, it is not necessary that the displayed window's buffer
9957 == current_buffer, except for text property lookup. So, let's
9958 only set that buffer temporarily here without doing a full
9959 Fset_window_buffer. We must also change w->pointm, though,
9960 because otherwise an assertions in unshow_buffer fails, and Emacs
9962 set_buffer_internal_1 (XBUFFER (buffer
));
9965 wset_buffer (w
, buffer
);
9966 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9969 bset_undo_list (current_buffer
, Qt
);
9970 bset_read_only (current_buffer
, Qnil
);
9971 specbind (Qinhibit_read_only
, Qt
);
9972 specbind (Qinhibit_modification_hooks
, Qt
);
9974 if (clear_buffer_p
&& Z
> BEG
)
9977 eassert (BEGV
>= BEG
);
9978 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9982 eassert (BEGV
>= BEG
);
9983 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9985 unbind_to (count
, Qnil
);
9990 /* Save state that should be preserved around the call to the function
9991 FN called in with_echo_area_buffer. */
9994 with_echo_area_buffer_unwind_data (struct window
*w
)
9997 Lisp_Object vector
, tmp
;
9999 /* Reduce consing by keeping one vector in
10000 Vwith_echo_area_save_vector. */
10001 vector
= Vwith_echo_area_save_vector
;
10002 Vwith_echo_area_save_vector
= Qnil
;
10005 vector
= Fmake_vector (make_number (7), Qnil
);
10007 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10008 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10009 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10013 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10014 ASET (vector
, i
, w
->buffer
); ++i
;
10015 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10016 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10021 for (; i
< end
; ++i
)
10022 ASET (vector
, i
, Qnil
);
10025 eassert (i
== ASIZE (vector
));
10030 /* Restore global state from VECTOR which was created by
10031 with_echo_area_buffer_unwind_data. */
10034 unwind_with_echo_area_buffer (Lisp_Object vector
)
10036 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10037 Vdeactivate_mark
= AREF (vector
, 1);
10038 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10040 if (WINDOWP (AREF (vector
, 3)))
10043 Lisp_Object buffer
, charpos
, bytepos
;
10045 w
= XWINDOW (AREF (vector
, 3));
10046 buffer
= AREF (vector
, 4);
10047 charpos
= AREF (vector
, 5);
10048 bytepos
= AREF (vector
, 6);
10050 wset_buffer (w
, buffer
);
10051 set_marker_both (w
->pointm
, buffer
,
10052 XFASTINT (charpos
), XFASTINT (bytepos
));
10055 Vwith_echo_area_save_vector
= vector
;
10060 /* Set up the echo area for use by print functions. MULTIBYTE_P
10061 non-zero means we will print multibyte. */
10064 setup_echo_area_for_printing (int multibyte_p
)
10066 /* If we can't find an echo area any more, exit. */
10067 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10068 Fkill_emacs (Qnil
);
10070 ensure_echo_area_buffers ();
10072 if (!message_buf_print
)
10074 /* A message has been output since the last time we printed.
10075 Choose a fresh echo area buffer. */
10076 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10077 echo_area_buffer
[0] = echo_buffer
[1];
10079 echo_area_buffer
[0] = echo_buffer
[0];
10081 /* Switch to that buffer and clear it. */
10082 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10083 bset_truncate_lines (current_buffer
, Qnil
);
10087 ptrdiff_t count
= SPECPDL_INDEX ();
10088 specbind (Qinhibit_read_only
, Qt
);
10089 /* Note that undo recording is always disabled. */
10090 del_range (BEG
, Z
);
10091 unbind_to (count
, Qnil
);
10093 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10095 /* Set up the buffer for the multibyteness we need. */
10097 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10098 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10100 /* Raise the frame containing the echo area. */
10101 if (minibuffer_auto_raise
)
10103 struct frame
*sf
= SELECTED_FRAME ();
10104 Lisp_Object mini_window
;
10105 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10106 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10109 message_log_maybe_newline ();
10110 message_buf_print
= 1;
10114 if (NILP (echo_area_buffer
[0]))
10116 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10117 echo_area_buffer
[0] = echo_buffer
[1];
10119 echo_area_buffer
[0] = echo_buffer
[0];
10122 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10124 /* Someone switched buffers between print requests. */
10125 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10126 bset_truncate_lines (current_buffer
, Qnil
);
10132 /* Display an echo area message in window W. Value is non-zero if W's
10133 height is changed. If display_last_displayed_message_p is
10134 non-zero, display the message that was last displayed, otherwise
10135 display the current message. */
10138 display_echo_area (struct window
*w
)
10140 int i
, no_message_p
, window_height_changed_p
;
10142 /* Temporarily disable garbage collections while displaying the echo
10143 area. This is done because a GC can print a message itself.
10144 That message would modify the echo area buffer's contents while a
10145 redisplay of the buffer is going on, and seriously confuse
10147 ptrdiff_t count
= inhibit_garbage_collection ();
10149 /* If there is no message, we must call display_echo_area_1
10150 nevertheless because it resizes the window. But we will have to
10151 reset the echo_area_buffer in question to nil at the end because
10152 with_echo_area_buffer will sets it to an empty buffer. */
10153 i
= display_last_displayed_message_p
? 1 : 0;
10154 no_message_p
= NILP (echo_area_buffer
[i
]);
10156 window_height_changed_p
10157 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10158 display_echo_area_1
,
10159 (intptr_t) w
, Qnil
);
10162 echo_area_buffer
[i
] = Qnil
;
10164 unbind_to (count
, Qnil
);
10165 return window_height_changed_p
;
10169 /* Helper for display_echo_area. Display the current buffer which
10170 contains the current echo area message in window W, a mini-window,
10171 a pointer to which is passed in A1. A2..A4 are currently not used.
10172 Change the height of W so that all of the message is displayed.
10173 Value is non-zero if height of W was changed. */
10176 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10179 struct window
*w
= (struct window
*) i1
;
10180 Lisp_Object window
;
10181 struct text_pos start
;
10182 int window_height_changed_p
= 0;
10184 /* Do this before displaying, so that we have a large enough glyph
10185 matrix for the display. If we can't get enough space for the
10186 whole text, display the last N lines. That works by setting w->start. */
10187 window_height_changed_p
= resize_mini_window (w
, 0);
10189 /* Use the starting position chosen by resize_mini_window. */
10190 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10193 clear_glyph_matrix (w
->desired_matrix
);
10194 XSETWINDOW (window
, w
);
10195 try_window (window
, start
, 0);
10197 return window_height_changed_p
;
10201 /* Resize the echo area window to exactly the size needed for the
10202 currently displayed message, if there is one. If a mini-buffer
10203 is active, don't shrink it. */
10206 resize_echo_area_exactly (void)
10208 if (BUFFERP (echo_area_buffer
[0])
10209 && WINDOWP (echo_area_window
))
10211 struct window
*w
= XWINDOW (echo_area_window
);
10213 Lisp_Object resize_exactly
;
10215 if (minibuf_level
== 0)
10216 resize_exactly
= Qt
;
10218 resize_exactly
= Qnil
;
10220 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10221 (intptr_t) w
, resize_exactly
);
10224 ++windows_or_buffers_changed
;
10225 ++update_mode_lines
;
10226 redisplay_internal ();
10232 /* Callback function for with_echo_area_buffer, when used from
10233 resize_echo_area_exactly. A1 contains a pointer to the window to
10234 resize, EXACTLY non-nil means resize the mini-window exactly to the
10235 size of the text displayed. A3 and A4 are not used. Value is what
10236 resize_mini_window returns. */
10239 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10242 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10246 /* Resize mini-window W to fit the size of its contents. EXACT_P
10247 means size the window exactly to the size needed. Otherwise, it's
10248 only enlarged until W's buffer is empty.
10250 Set W->start to the right place to begin display. If the whole
10251 contents fit, start at the beginning. Otherwise, start so as
10252 to make the end of the contents appear. This is particularly
10253 important for y-or-n-p, but seems desirable generally.
10255 Value is non-zero if the window height has been changed. */
10258 resize_mini_window (struct window
*w
, int exact_p
)
10260 struct frame
*f
= XFRAME (w
->frame
);
10261 int window_height_changed_p
= 0;
10263 eassert (MINI_WINDOW_P (w
));
10265 /* By default, start display at the beginning. */
10266 set_marker_both (w
->start
, w
->buffer
,
10267 BUF_BEGV (XBUFFER (w
->buffer
)),
10268 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10270 /* Don't resize windows while redisplaying a window; it would
10271 confuse redisplay functions when the size of the window they are
10272 displaying changes from under them. Such a resizing can happen,
10273 for instance, when which-func prints a long message while
10274 we are running fontification-functions. We're running these
10275 functions with safe_call which binds inhibit-redisplay to t. */
10276 if (!NILP (Vinhibit_redisplay
))
10279 /* Nil means don't try to resize. */
10280 if (NILP (Vresize_mini_windows
)
10281 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10284 if (!FRAME_MINIBUF_ONLY_P (f
))
10287 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10288 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10290 EMACS_INT max_height
;
10291 int unit
= FRAME_LINE_HEIGHT (f
);
10292 struct text_pos start
;
10293 struct buffer
*old_current_buffer
= NULL
;
10295 if (current_buffer
!= XBUFFER (w
->buffer
))
10297 old_current_buffer
= current_buffer
;
10298 set_buffer_internal (XBUFFER (w
->buffer
));
10301 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10303 /* Compute the max. number of lines specified by the user. */
10304 if (FLOATP (Vmax_mini_window_height
))
10305 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10306 else if (INTEGERP (Vmax_mini_window_height
))
10307 max_height
= XINT (Vmax_mini_window_height
);
10309 max_height
= total_height
/ 4;
10311 /* Correct that max. height if it's bogus. */
10312 max_height
= clip_to_bounds (1, max_height
, total_height
);
10314 /* Find out the height of the text in the window. */
10315 if (it
.line_wrap
== TRUNCATE
)
10320 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10321 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10322 height
= it
.current_y
+ last_height
;
10324 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10325 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10326 height
= (height
+ unit
- 1) / unit
;
10329 /* Compute a suitable window start. */
10330 if (height
> max_height
)
10332 height
= max_height
;
10333 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10334 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10335 start
= it
.current
.pos
;
10338 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10339 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10341 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10343 /* Let it grow only, until we display an empty message, in which
10344 case the window shrinks again. */
10345 if (height
> WINDOW_TOTAL_LINES (w
))
10347 int old_height
= WINDOW_TOTAL_LINES (w
);
10348 freeze_window_starts (f
, 1);
10349 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10350 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10352 else if (height
< WINDOW_TOTAL_LINES (w
)
10353 && (exact_p
|| BEGV
== ZV
))
10355 int old_height
= WINDOW_TOTAL_LINES (w
);
10356 freeze_window_starts (f
, 0);
10357 shrink_mini_window (w
);
10358 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10363 /* Always resize to exact size needed. */
10364 if (height
> WINDOW_TOTAL_LINES (w
))
10366 int old_height
= WINDOW_TOTAL_LINES (w
);
10367 freeze_window_starts (f
, 1);
10368 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10369 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10371 else if (height
< WINDOW_TOTAL_LINES (w
))
10373 int old_height
= WINDOW_TOTAL_LINES (w
);
10374 freeze_window_starts (f
, 0);
10375 shrink_mini_window (w
);
10379 freeze_window_starts (f
, 1);
10380 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10383 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10387 if (old_current_buffer
)
10388 set_buffer_internal (old_current_buffer
);
10391 return window_height_changed_p
;
10395 /* Value is the current message, a string, or nil if there is no
10396 current message. */
10399 current_message (void)
10403 if (!BUFFERP (echo_area_buffer
[0]))
10407 with_echo_area_buffer (0, 0, current_message_1
,
10408 (intptr_t) &msg
, Qnil
);
10410 echo_area_buffer
[0] = Qnil
;
10418 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10421 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10424 *msg
= make_buffer_string (BEG
, Z
, 1);
10431 /* Push the current message on Vmessage_stack for later restoration
10432 by restore_message. Value is non-zero if the current message isn't
10433 empty. This is a relatively infrequent operation, so it's not
10434 worth optimizing. */
10437 push_message (void)
10439 Lisp_Object msg
= current_message ();
10440 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10441 return STRINGP (msg
);
10445 /* Restore message display from the top of Vmessage_stack. */
10448 restore_message (void)
10450 eassert (CONSP (Vmessage_stack
));
10451 message3_nolog (XCAR (Vmessage_stack
));
10455 /* Handler for record_unwind_protect calling pop_message. */
10458 pop_message_unwind (Lisp_Object dummy
)
10464 /* Pop the top-most entry off Vmessage_stack. */
10469 eassert (CONSP (Vmessage_stack
));
10470 Vmessage_stack
= XCDR (Vmessage_stack
);
10474 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10475 exits. If the stack is not empty, we have a missing pop_message
10479 check_message_stack (void)
10481 if (!NILP (Vmessage_stack
))
10486 /* Truncate to NCHARS what will be displayed in the echo area the next
10487 time we display it---but don't redisplay it now. */
10490 truncate_echo_area (ptrdiff_t nchars
)
10493 echo_area_buffer
[0] = Qnil
;
10494 else if (!noninteractive
10496 && !NILP (echo_area_buffer
[0]))
10498 struct frame
*sf
= SELECTED_FRAME ();
10499 /* Error messages get reported properly by cmd_error, so this must be
10500 just an informative message; if the frame hasn't really been
10501 initialized yet, just toss it. */
10502 if (sf
->glyphs_initialized_p
)
10503 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10508 /* Helper function for truncate_echo_area. Truncate the current
10509 message to at most NCHARS characters. */
10512 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10514 if (BEG
+ nchars
< Z
)
10515 del_range (BEG
+ nchars
, Z
);
10517 echo_area_buffer
[0] = Qnil
;
10521 /* Set the current message to STRING. */
10524 set_message (Lisp_Object string
)
10526 eassert (STRINGP (string
));
10528 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10530 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10531 message_buf_print
= 0;
10532 help_echo_showing_p
= 0;
10534 if (STRINGP (Vdebug_on_message
)
10535 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10536 call_debugger (list2 (Qerror
, string
));
10540 /* Helper function for set_message. First argument is ignored and second
10541 argument has the same meaning as for set_message.
10542 This function is called with the echo area buffer being current. */
10545 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10547 eassert (STRINGP (string
));
10549 /* Change multibyteness of the echo buffer appropriately. */
10550 if (message_enable_multibyte
10551 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10552 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10554 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10555 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10556 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10558 /* Insert new message at BEG. */
10559 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10561 /* This function takes care of single/multibyte conversion.
10562 We just have to ensure that the echo area buffer has the right
10563 setting of enable_multibyte_characters. */
10564 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10570 /* Clear messages. CURRENT_P non-zero means clear the current
10571 message. LAST_DISPLAYED_P non-zero means clear the message
10575 clear_message (int current_p
, int last_displayed_p
)
10579 echo_area_buffer
[0] = Qnil
;
10580 message_cleared_p
= 1;
10583 if (last_displayed_p
)
10584 echo_area_buffer
[1] = Qnil
;
10586 message_buf_print
= 0;
10589 /* Clear garbaged frames.
10591 This function is used where the old redisplay called
10592 redraw_garbaged_frames which in turn called redraw_frame which in
10593 turn called clear_frame. The call to clear_frame was a source of
10594 flickering. I believe a clear_frame is not necessary. It should
10595 suffice in the new redisplay to invalidate all current matrices,
10596 and ensure a complete redisplay of all windows. */
10599 clear_garbaged_frames (void)
10601 if (frame_garbaged
)
10603 Lisp_Object tail
, frame
;
10604 int changed_count
= 0;
10606 FOR_EACH_FRAME (tail
, frame
)
10608 struct frame
*f
= XFRAME (frame
);
10610 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10615 f
->force_flush_display_p
= 1;
10617 clear_current_matrices (f
);
10624 frame_garbaged
= 0;
10626 ++windows_or_buffers_changed
;
10631 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10632 is non-zero update selected_frame. Value is non-zero if the
10633 mini-windows height has been changed. */
10636 echo_area_display (int update_frame_p
)
10638 Lisp_Object mini_window
;
10641 int window_height_changed_p
= 0;
10642 struct frame
*sf
= SELECTED_FRAME ();
10644 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10645 w
= XWINDOW (mini_window
);
10646 f
= XFRAME (WINDOW_FRAME (w
));
10648 /* Don't display if frame is invisible or not yet initialized. */
10649 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10652 #ifdef HAVE_WINDOW_SYSTEM
10653 /* When Emacs starts, selected_frame may be the initial terminal
10654 frame. If we let this through, a message would be displayed on
10656 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10658 #endif /* HAVE_WINDOW_SYSTEM */
10660 /* Redraw garbaged frames. */
10661 clear_garbaged_frames ();
10663 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10665 echo_area_window
= mini_window
;
10666 window_height_changed_p
= display_echo_area (w
);
10667 w
->must_be_updated_p
= 1;
10669 /* Update the display, unless called from redisplay_internal.
10670 Also don't update the screen during redisplay itself. The
10671 update will happen at the end of redisplay, and an update
10672 here could cause confusion. */
10673 if (update_frame_p
&& !redisplaying_p
)
10677 /* If the display update has been interrupted by pending
10678 input, update mode lines in the frame. Due to the
10679 pending input, it might have been that redisplay hasn't
10680 been called, so that mode lines above the echo area are
10681 garbaged. This looks odd, so we prevent it here. */
10682 if (!display_completed
)
10683 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10685 if (window_height_changed_p
10686 /* Don't do this if Emacs is shutting down. Redisplay
10687 needs to run hooks. */
10688 && !NILP (Vrun_hooks
))
10690 /* Must update other windows. Likewise as in other
10691 cases, don't let this update be interrupted by
10693 ptrdiff_t count
= SPECPDL_INDEX ();
10694 specbind (Qredisplay_dont_pause
, Qt
);
10695 windows_or_buffers_changed
= 1;
10696 redisplay_internal ();
10697 unbind_to (count
, Qnil
);
10699 else if (FRAME_WINDOW_P (f
) && n
== 0)
10701 /* Window configuration is the same as before.
10702 Can do with a display update of the echo area,
10703 unless we displayed some mode lines. */
10704 update_single_window (w
, 1);
10705 FRAME_RIF (f
)->flush_display (f
);
10708 update_frame (f
, 1, 1);
10710 /* If cursor is in the echo area, make sure that the next
10711 redisplay displays the minibuffer, so that the cursor will
10712 be replaced with what the minibuffer wants. */
10713 if (cursor_in_echo_area
)
10714 ++windows_or_buffers_changed
;
10717 else if (!EQ (mini_window
, selected_window
))
10718 windows_or_buffers_changed
++;
10720 /* Last displayed message is now the current message. */
10721 echo_area_buffer
[1] = echo_area_buffer
[0];
10722 /* Inform read_char that we're not echoing. */
10723 echo_message_buffer
= Qnil
;
10725 /* Prevent redisplay optimization in redisplay_internal by resetting
10726 this_line_start_pos. This is done because the mini-buffer now
10727 displays the message instead of its buffer text. */
10728 if (EQ (mini_window
, selected_window
))
10729 CHARPOS (this_line_start_pos
) = 0;
10731 return window_height_changed_p
;
10734 /* Nonzero if the current window's buffer is shown in more than one
10735 window and was modified since last redisplay. */
10738 buffer_shared_and_changed (void)
10740 return (buffer_window_count (current_buffer
) > 1
10741 && UNCHANGED_MODIFIED
< MODIFF
);
10744 /* Nonzero if W doesn't reflect the actual state of current buffer due
10745 to its text or overlays change. FIXME: this may be called when
10746 XBUFFER (w->buffer) != current_buffer, which looks suspicious. */
10749 window_outdated (struct window
*w
)
10751 return (w
->last_modified
< MODIFF
10752 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10755 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10756 is enabled and mark of W's buffer was changed since last W's update. */
10759 window_buffer_changed (struct window
*w
)
10761 struct buffer
*b
= XBUFFER (w
->buffer
);
10763 eassert (BUFFER_LIVE_P (b
));
10765 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10766 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10767 != (w
->region_showing
!= 0)));
10770 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10773 mode_line_update_needed (struct window
*w
)
10775 return (w
->column_number_displayed
!= -1
10776 && !(PT
== w
->last_point
&& !window_outdated (w
))
10777 && (w
->column_number_displayed
!= current_column ()));
10780 /***********************************************************************
10781 Mode Lines and Frame Titles
10782 ***********************************************************************/
10784 /* A buffer for constructing non-propertized mode-line strings and
10785 frame titles in it; allocated from the heap in init_xdisp and
10786 resized as needed in store_mode_line_noprop_char. */
10788 static char *mode_line_noprop_buf
;
10790 /* The buffer's end, and a current output position in it. */
10792 static char *mode_line_noprop_buf_end
;
10793 static char *mode_line_noprop_ptr
;
10795 #define MODE_LINE_NOPROP_LEN(start) \
10796 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10799 MODE_LINE_DISPLAY
= 0,
10803 } mode_line_target
;
10805 /* Alist that caches the results of :propertize.
10806 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10807 static Lisp_Object mode_line_proptrans_alist
;
10809 /* List of strings making up the mode-line. */
10810 static Lisp_Object mode_line_string_list
;
10812 /* Base face property when building propertized mode line string. */
10813 static Lisp_Object mode_line_string_face
;
10814 static Lisp_Object mode_line_string_face_prop
;
10817 /* Unwind data for mode line strings */
10819 static Lisp_Object Vmode_line_unwind_vector
;
10822 format_mode_line_unwind_data (struct frame
*target_frame
,
10823 struct buffer
*obuf
,
10825 int save_proptrans
)
10827 Lisp_Object vector
, tmp
;
10829 /* Reduce consing by keeping one vector in
10830 Vwith_echo_area_save_vector. */
10831 vector
= Vmode_line_unwind_vector
;
10832 Vmode_line_unwind_vector
= Qnil
;
10835 vector
= Fmake_vector (make_number (10), Qnil
);
10837 ASET (vector
, 0, make_number (mode_line_target
));
10838 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10839 ASET (vector
, 2, mode_line_string_list
);
10840 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10841 ASET (vector
, 4, mode_line_string_face
);
10842 ASET (vector
, 5, mode_line_string_face_prop
);
10845 XSETBUFFER (tmp
, obuf
);
10848 ASET (vector
, 6, tmp
);
10849 ASET (vector
, 7, owin
);
10852 /* Similarly to `with-selected-window', if the operation selects
10853 a window on another frame, we must restore that frame's
10854 selected window, and (for a tty) the top-frame. */
10855 ASET (vector
, 8, target_frame
->selected_window
);
10856 if (FRAME_TERMCAP_P (target_frame
))
10857 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10864 unwind_format_mode_line (Lisp_Object vector
)
10866 Lisp_Object old_window
= AREF (vector
, 7);
10867 Lisp_Object target_frame_window
= AREF (vector
, 8);
10868 Lisp_Object old_top_frame
= AREF (vector
, 9);
10870 mode_line_target
= XINT (AREF (vector
, 0));
10871 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10872 mode_line_string_list
= AREF (vector
, 2);
10873 if (! EQ (AREF (vector
, 3), Qt
))
10874 mode_line_proptrans_alist
= AREF (vector
, 3);
10875 mode_line_string_face
= AREF (vector
, 4);
10876 mode_line_string_face_prop
= AREF (vector
, 5);
10878 /* Select window before buffer, since it may change the buffer. */
10879 if (!NILP (old_window
))
10881 /* If the operation that we are unwinding had selected a window
10882 on a different frame, reset its frame-selected-window. For a
10883 text terminal, reset its top-frame if necessary. */
10884 if (!NILP (target_frame_window
))
10887 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10889 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10890 Fselect_window (target_frame_window
, Qt
);
10892 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10893 Fselect_frame (old_top_frame
, Qt
);
10896 Fselect_window (old_window
, Qt
);
10899 if (!NILP (AREF (vector
, 6)))
10901 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10902 ASET (vector
, 6, Qnil
);
10905 Vmode_line_unwind_vector
= vector
;
10910 /* Store a single character C for the frame title in mode_line_noprop_buf.
10911 Re-allocate mode_line_noprop_buf if necessary. */
10914 store_mode_line_noprop_char (char c
)
10916 /* If output position has reached the end of the allocated buffer,
10917 increase the buffer's size. */
10918 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10920 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10921 ptrdiff_t size
= len
;
10922 mode_line_noprop_buf
=
10923 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10924 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10925 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10928 *mode_line_noprop_ptr
++ = c
;
10932 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10933 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10934 characters that yield more columns than PRECISION; PRECISION <= 0
10935 means copy the whole string. Pad with spaces until FIELD_WIDTH
10936 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10937 pad. Called from display_mode_element when it is used to build a
10941 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10943 const unsigned char *str
= (const unsigned char *) string
;
10945 ptrdiff_t dummy
, nbytes
;
10947 /* Copy at most PRECISION chars from STR. */
10948 nbytes
= strlen (string
);
10949 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10951 store_mode_line_noprop_char (*str
++);
10953 /* Fill up with spaces until FIELD_WIDTH reached. */
10954 while (field_width
> 0
10955 && n
< field_width
)
10957 store_mode_line_noprop_char (' ');
10964 /***********************************************************************
10966 ***********************************************************************/
10968 #ifdef HAVE_WINDOW_SYSTEM
10970 /* Set the title of FRAME, if it has changed. The title format is
10971 Vicon_title_format if FRAME is iconified, otherwise it is
10972 frame_title_format. */
10975 x_consider_frame_title (Lisp_Object frame
)
10977 struct frame
*f
= XFRAME (frame
);
10979 if (FRAME_WINDOW_P (f
)
10980 || FRAME_MINIBUF_ONLY_P (f
)
10981 || f
->explicit_name
)
10983 /* Do we have more than one visible frame on this X display? */
10984 Lisp_Object tail
, other_frame
, fmt
;
10985 ptrdiff_t title_start
;
10989 ptrdiff_t count
= SPECPDL_INDEX ();
10991 FOR_EACH_FRAME (tail
, other_frame
)
10993 struct frame
*tf
= XFRAME (other_frame
);
10996 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10997 && !FRAME_MINIBUF_ONLY_P (tf
)
10998 && !EQ (other_frame
, tip_frame
)
10999 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11003 /* Set global variable indicating that multiple frames exist. */
11004 multiple_frames
= CONSP (tail
);
11006 /* Switch to the buffer of selected window of the frame. Set up
11007 mode_line_target so that display_mode_element will output into
11008 mode_line_noprop_buf; then display the title. */
11009 record_unwind_protect (unwind_format_mode_line
,
11010 format_mode_line_unwind_data
11011 (f
, current_buffer
, selected_window
, 0));
11013 Fselect_window (f
->selected_window
, Qt
);
11014 set_buffer_internal_1
11015 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11016 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11018 mode_line_target
= MODE_LINE_TITLE
;
11019 title_start
= MODE_LINE_NOPROP_LEN (0);
11020 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11021 NULL
, DEFAULT_FACE_ID
);
11022 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11023 len
= MODE_LINE_NOPROP_LEN (title_start
);
11024 title
= mode_line_noprop_buf
+ title_start
;
11025 unbind_to (count
, Qnil
);
11027 /* Set the title only if it's changed. This avoids consing in
11028 the common case where it hasn't. (If it turns out that we've
11029 already wasted too much time by walking through the list with
11030 display_mode_element, then we might need to optimize at a
11031 higher level than this.) */
11032 if (! STRINGP (f
->name
)
11033 || SBYTES (f
->name
) != len
11034 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11035 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11039 #endif /* not HAVE_WINDOW_SYSTEM */
11042 /***********************************************************************
11044 ***********************************************************************/
11047 /* Prepare for redisplay by updating menu-bar item lists when
11048 appropriate. This can call eval. */
11051 prepare_menu_bars (void)
11054 struct gcpro gcpro1
, gcpro2
;
11056 Lisp_Object tooltip_frame
;
11058 #ifdef HAVE_WINDOW_SYSTEM
11059 tooltip_frame
= tip_frame
;
11061 tooltip_frame
= Qnil
;
11064 /* Update all frame titles based on their buffer names, etc. We do
11065 this before the menu bars so that the buffer-menu will show the
11066 up-to-date frame titles. */
11067 #ifdef HAVE_WINDOW_SYSTEM
11068 if (windows_or_buffers_changed
|| update_mode_lines
)
11070 Lisp_Object tail
, frame
;
11072 FOR_EACH_FRAME (tail
, frame
)
11074 f
= XFRAME (frame
);
11075 if (!EQ (frame
, tooltip_frame
)
11076 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11077 x_consider_frame_title (frame
);
11080 #endif /* HAVE_WINDOW_SYSTEM */
11082 /* Update the menu bar item lists, if appropriate. This has to be
11083 done before any actual redisplay or generation of display lines. */
11084 all_windows
= (update_mode_lines
11085 || buffer_shared_and_changed ()
11086 || windows_or_buffers_changed
);
11089 Lisp_Object tail
, frame
;
11090 ptrdiff_t count
= SPECPDL_INDEX ();
11091 /* 1 means that update_menu_bar has run its hooks
11092 so any further calls to update_menu_bar shouldn't do so again. */
11093 int menu_bar_hooks_run
= 0;
11095 record_unwind_save_match_data ();
11097 FOR_EACH_FRAME (tail
, frame
)
11099 f
= XFRAME (frame
);
11101 /* Ignore tooltip frame. */
11102 if (EQ (frame
, tooltip_frame
))
11105 /* If a window on this frame changed size, report that to
11106 the user and clear the size-change flag. */
11107 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11109 Lisp_Object functions
;
11111 /* Clear flag first in case we get an error below. */
11112 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11113 functions
= Vwindow_size_change_functions
;
11114 GCPRO2 (tail
, functions
);
11116 while (CONSP (functions
))
11118 if (!EQ (XCAR (functions
), Qt
))
11119 call1 (XCAR (functions
), frame
);
11120 functions
= XCDR (functions
);
11126 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11127 #ifdef HAVE_WINDOW_SYSTEM
11128 update_tool_bar (f
, 0);
11131 if (windows_or_buffers_changed
11134 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11139 unbind_to (count
, Qnil
);
11143 struct frame
*sf
= SELECTED_FRAME ();
11144 update_menu_bar (sf
, 1, 0);
11145 #ifdef HAVE_WINDOW_SYSTEM
11146 update_tool_bar (sf
, 1);
11152 /* Update the menu bar item list for frame F. This has to be done
11153 before we start to fill in any display lines, because it can call
11156 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11158 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11159 already ran the menu bar hooks for this redisplay, so there
11160 is no need to run them again. The return value is the
11161 updated value of this flag, to pass to the next call. */
11164 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11166 Lisp_Object window
;
11167 register struct window
*w
;
11169 /* If called recursively during a menu update, do nothing. This can
11170 happen when, for instance, an activate-menubar-hook causes a
11172 if (inhibit_menubar_update
)
11175 window
= FRAME_SELECTED_WINDOW (f
);
11176 w
= XWINDOW (window
);
11178 if (FRAME_WINDOW_P (f
)
11180 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11181 || defined (HAVE_NS) || defined (USE_GTK)
11182 FRAME_EXTERNAL_MENU_BAR (f
)
11184 FRAME_MENU_BAR_LINES (f
) > 0
11186 : FRAME_MENU_BAR_LINES (f
) > 0)
11188 /* If the user has switched buffers or windows, we need to
11189 recompute to reflect the new bindings. But we'll
11190 recompute when update_mode_lines is set too; that means
11191 that people can use force-mode-line-update to request
11192 that the menu bar be recomputed. The adverse effect on
11193 the rest of the redisplay algorithm is about the same as
11194 windows_or_buffers_changed anyway. */
11195 if (windows_or_buffers_changed
11196 /* This used to test w->update_mode_line, but we believe
11197 there is no need to recompute the menu in that case. */
11198 || update_mode_lines
11199 || window_buffer_changed (w
))
11201 struct buffer
*prev
= current_buffer
;
11202 ptrdiff_t count
= SPECPDL_INDEX ();
11204 specbind (Qinhibit_menubar_update
, Qt
);
11206 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11207 if (save_match_data
)
11208 record_unwind_save_match_data ();
11209 if (NILP (Voverriding_local_map_menu_flag
))
11211 specbind (Qoverriding_terminal_local_map
, Qnil
);
11212 specbind (Qoverriding_local_map
, Qnil
);
11217 /* Run the Lucid hook. */
11218 safe_run_hooks (Qactivate_menubar_hook
);
11220 /* If it has changed current-menubar from previous value,
11221 really recompute the menu-bar from the value. */
11222 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11223 call0 (Qrecompute_lucid_menubar
);
11225 safe_run_hooks (Qmenu_bar_update_hook
);
11230 XSETFRAME (Vmenu_updating_frame
, f
);
11231 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11233 /* Redisplay the menu bar in case we changed it. */
11234 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11235 || defined (HAVE_NS) || defined (USE_GTK)
11236 if (FRAME_WINDOW_P (f
))
11238 #if defined (HAVE_NS)
11239 /* All frames on Mac OS share the same menubar. So only
11240 the selected frame should be allowed to set it. */
11241 if (f
== SELECTED_FRAME ())
11243 set_frame_menubar (f
, 0, 0);
11246 /* On a terminal screen, the menu bar is an ordinary screen
11247 line, and this makes it get updated. */
11248 w
->update_mode_line
= 1;
11249 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11250 /* In the non-toolkit version, the menu bar is an ordinary screen
11251 line, and this makes it get updated. */
11252 w
->update_mode_line
= 1;
11253 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11255 unbind_to (count
, Qnil
);
11256 set_buffer_internal_1 (prev
);
11265 /***********************************************************************
11267 ***********************************************************************/
11269 #ifdef HAVE_WINDOW_SYSTEM
11272 Nominal cursor position -- where to draw output.
11273 HPOS and VPOS are window relative glyph matrix coordinates.
11274 X and Y are window relative pixel coordinates. */
11276 struct cursor_pos output_cursor
;
11280 Set the global variable output_cursor to CURSOR. All cursor
11281 positions are relative to updated_window. */
11284 set_output_cursor (struct cursor_pos
*cursor
)
11286 output_cursor
.hpos
= cursor
->hpos
;
11287 output_cursor
.vpos
= cursor
->vpos
;
11288 output_cursor
.x
= cursor
->x
;
11289 output_cursor
.y
= cursor
->y
;
11294 Set a nominal cursor position.
11296 HPOS and VPOS are column/row positions in a window glyph matrix. X
11297 and Y are window text area relative pixel positions.
11299 If this is done during an update, updated_window will contain the
11300 window that is being updated and the position is the future output
11301 cursor position for that window. If updated_window is null, use
11302 selected_window and display the cursor at the given position. */
11305 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11309 /* If updated_window is not set, work on selected_window. */
11310 if (updated_window
)
11311 w
= updated_window
;
11313 w
= XWINDOW (selected_window
);
11315 /* Set the output cursor. */
11316 output_cursor
.hpos
= hpos
;
11317 output_cursor
.vpos
= vpos
;
11318 output_cursor
.x
= x
;
11319 output_cursor
.y
= y
;
11321 /* If not called as part of an update, really display the cursor.
11322 This will also set the cursor position of W. */
11323 if (updated_window
== NULL
)
11326 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11327 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11328 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11333 #endif /* HAVE_WINDOW_SYSTEM */
11336 /***********************************************************************
11338 ***********************************************************************/
11340 #ifdef HAVE_WINDOW_SYSTEM
11342 /* Where the mouse was last time we reported a mouse event. */
11344 FRAME_PTR last_mouse_frame
;
11346 /* Tool-bar item index of the item on which a mouse button was pressed
11349 int last_tool_bar_item
;
11351 /* Select `frame' temporarily without running all the code in
11353 FIXME: Maybe do_switch_frame should be trimmed down similarly
11354 when `norecord' is set. */
11356 fast_set_selected_frame (Lisp_Object frame
)
11358 if (!EQ (selected_frame
, frame
))
11360 selected_frame
= frame
;
11361 selected_window
= XFRAME (frame
)->selected_window
;
11366 /* Update the tool-bar item list for frame F. This has to be done
11367 before we start to fill in any display lines. Called from
11368 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11369 and restore it here. */
11372 update_tool_bar (struct frame
*f
, int save_match_data
)
11374 #if defined (USE_GTK) || defined (HAVE_NS)
11375 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11377 int do_update
= WINDOWP (f
->tool_bar_window
)
11378 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11383 Lisp_Object window
;
11386 window
= FRAME_SELECTED_WINDOW (f
);
11387 w
= XWINDOW (window
);
11389 /* If the user has switched buffers or windows, we need to
11390 recompute to reflect the new bindings. But we'll
11391 recompute when update_mode_lines is set too; that means
11392 that people can use force-mode-line-update to request
11393 that the menu bar be recomputed. The adverse effect on
11394 the rest of the redisplay algorithm is about the same as
11395 windows_or_buffers_changed anyway. */
11396 if (windows_or_buffers_changed
11397 || w
->update_mode_line
11398 || update_mode_lines
11399 || window_buffer_changed (w
))
11401 struct buffer
*prev
= current_buffer
;
11402 ptrdiff_t count
= SPECPDL_INDEX ();
11403 Lisp_Object frame
, new_tool_bar
;
11404 int new_n_tool_bar
;
11405 struct gcpro gcpro1
;
11407 /* Set current_buffer to the buffer of the selected
11408 window of the frame, so that we get the right local
11410 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11412 /* Save match data, if we must. */
11413 if (save_match_data
)
11414 record_unwind_save_match_data ();
11416 /* Make sure that we don't accidentally use bogus keymaps. */
11417 if (NILP (Voverriding_local_map_menu_flag
))
11419 specbind (Qoverriding_terminal_local_map
, Qnil
);
11420 specbind (Qoverriding_local_map
, Qnil
);
11423 GCPRO1 (new_tool_bar
);
11425 /* We must temporarily set the selected frame to this frame
11426 before calling tool_bar_items, because the calculation of
11427 the tool-bar keymap uses the selected frame (see
11428 `tool-bar-make-keymap' in tool-bar.el). */
11429 eassert (EQ (selected_window
,
11430 /* Since we only explicitly preserve selected_frame,
11431 check that selected_window would be redundant. */
11432 XFRAME (selected_frame
)->selected_window
));
11433 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11434 XSETFRAME (frame
, f
);
11435 fast_set_selected_frame (frame
);
11437 /* Build desired tool-bar items from keymaps. */
11439 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11442 /* Redisplay the tool-bar if we changed it. */
11443 if (new_n_tool_bar
!= f
->n_tool_bar_items
11444 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11446 /* Redisplay that happens asynchronously due to an expose event
11447 may access f->tool_bar_items. Make sure we update both
11448 variables within BLOCK_INPUT so no such event interrupts. */
11450 fset_tool_bar_items (f
, new_tool_bar
);
11451 f
->n_tool_bar_items
= new_n_tool_bar
;
11452 w
->update_mode_line
= 1;
11458 unbind_to (count
, Qnil
);
11459 set_buffer_internal_1 (prev
);
11465 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11466 F's desired tool-bar contents. F->tool_bar_items must have
11467 been set up previously by calling prepare_menu_bars. */
11470 build_desired_tool_bar_string (struct frame
*f
)
11472 int i
, size
, size_needed
;
11473 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11474 Lisp_Object image
, plist
, props
;
11476 image
= plist
= props
= Qnil
;
11477 GCPRO3 (image
, plist
, props
);
11479 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11480 Otherwise, make a new string. */
11482 /* The size of the string we might be able to reuse. */
11483 size
= (STRINGP (f
->desired_tool_bar_string
)
11484 ? SCHARS (f
->desired_tool_bar_string
)
11487 /* We need one space in the string for each image. */
11488 size_needed
= f
->n_tool_bar_items
;
11490 /* Reuse f->desired_tool_bar_string, if possible. */
11491 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11492 fset_desired_tool_bar_string
11493 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11496 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11497 Fremove_text_properties (make_number (0), make_number (size
),
11498 props
, f
->desired_tool_bar_string
);
11501 /* Put a `display' property on the string for the images to display,
11502 put a `menu_item' property on tool-bar items with a value that
11503 is the index of the item in F's tool-bar item vector. */
11504 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11506 #define PROP(IDX) \
11507 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11509 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11510 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11511 int hmargin
, vmargin
, relief
, idx
, end
;
11513 /* If image is a vector, choose the image according to the
11515 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11516 if (VECTORP (image
))
11520 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11521 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11524 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11525 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11527 eassert (ASIZE (image
) >= idx
);
11528 image
= AREF (image
, idx
);
11533 /* Ignore invalid image specifications. */
11534 if (!valid_image_p (image
))
11537 /* Display the tool-bar button pressed, or depressed. */
11538 plist
= Fcopy_sequence (XCDR (image
));
11540 /* Compute margin and relief to draw. */
11541 relief
= (tool_bar_button_relief
>= 0
11542 ? tool_bar_button_relief
11543 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11544 hmargin
= vmargin
= relief
;
11546 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11547 INT_MAX
- max (hmargin
, vmargin
)))
11549 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11550 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11552 else if (CONSP (Vtool_bar_button_margin
))
11554 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11555 INT_MAX
- hmargin
))
11556 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11558 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11559 INT_MAX
- vmargin
))
11560 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11563 if (auto_raise_tool_bar_buttons_p
)
11565 /* Add a `:relief' property to the image spec if the item is
11569 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11576 /* If image is selected, display it pressed, i.e. with a
11577 negative relief. If it's not selected, display it with a
11579 plist
= Fplist_put (plist
, QCrelief
,
11581 ? make_number (-relief
)
11582 : make_number (relief
)));
11587 /* Put a margin around the image. */
11588 if (hmargin
|| vmargin
)
11590 if (hmargin
== vmargin
)
11591 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11593 plist
= Fplist_put (plist
, QCmargin
,
11594 Fcons (make_number (hmargin
),
11595 make_number (vmargin
)));
11598 /* If button is not enabled, and we don't have special images
11599 for the disabled state, make the image appear disabled by
11600 applying an appropriate algorithm to it. */
11601 if (!enabled_p
&& idx
< 0)
11602 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11604 /* Put a `display' text property on the string for the image to
11605 display. Put a `menu-item' property on the string that gives
11606 the start of this item's properties in the tool-bar items
11608 image
= Fcons (Qimage
, plist
);
11609 props
= list4 (Qdisplay
, image
,
11610 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11612 /* Let the last image hide all remaining spaces in the tool bar
11613 string. The string can be longer than needed when we reuse a
11614 previous string. */
11615 if (i
+ 1 == f
->n_tool_bar_items
)
11616 end
= SCHARS (f
->desired_tool_bar_string
);
11619 Fadd_text_properties (make_number (i
), make_number (end
),
11620 props
, f
->desired_tool_bar_string
);
11628 /* Display one line of the tool-bar of frame IT->f.
11630 HEIGHT specifies the desired height of the tool-bar line.
11631 If the actual height of the glyph row is less than HEIGHT, the
11632 row's height is increased to HEIGHT, and the icons are centered
11633 vertically in the new height.
11635 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11636 count a final empty row in case the tool-bar width exactly matches
11641 display_tool_bar_line (struct it
*it
, int height
)
11643 struct glyph_row
*row
= it
->glyph_row
;
11644 int max_x
= it
->last_visible_x
;
11645 struct glyph
*last
;
11647 prepare_desired_row (row
);
11648 row
->y
= it
->current_y
;
11650 /* Note that this isn't made use of if the face hasn't a box,
11651 so there's no need to check the face here. */
11652 it
->start_of_box_run_p
= 1;
11654 while (it
->current_x
< max_x
)
11656 int x
, n_glyphs_before
, i
, nglyphs
;
11657 struct it it_before
;
11659 /* Get the next display element. */
11660 if (!get_next_display_element (it
))
11662 /* Don't count empty row if we are counting needed tool-bar lines. */
11663 if (height
< 0 && !it
->hpos
)
11668 /* Produce glyphs. */
11669 n_glyphs_before
= row
->used
[TEXT_AREA
];
11672 PRODUCE_GLYPHS (it
);
11674 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11676 x
= it_before
.current_x
;
11677 while (i
< nglyphs
)
11679 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11681 if (x
+ glyph
->pixel_width
> max_x
)
11683 /* Glyph doesn't fit on line. Backtrack. */
11684 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11686 /* If this is the only glyph on this line, it will never fit on the
11687 tool-bar, so skip it. But ensure there is at least one glyph,
11688 so we don't accidentally disable the tool-bar. */
11689 if (n_glyphs_before
== 0
11690 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11696 x
+= glyph
->pixel_width
;
11700 /* Stop at line end. */
11701 if (ITERATOR_AT_END_OF_LINE_P (it
))
11704 set_iterator_to_next (it
, 1);
11709 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11711 /* Use default face for the border below the tool bar.
11713 FIXME: When auto-resize-tool-bars is grow-only, there is
11714 no additional border below the possibly empty tool-bar lines.
11715 So to make the extra empty lines look "normal", we have to
11716 use the tool-bar face for the border too. */
11717 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11718 it
->face_id
= DEFAULT_FACE_ID
;
11720 extend_face_to_end_of_line (it
);
11721 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11722 last
->right_box_line_p
= 1;
11723 if (last
== row
->glyphs
[TEXT_AREA
])
11724 last
->left_box_line_p
= 1;
11726 /* Make line the desired height and center it vertically. */
11727 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11729 /* Don't add more than one line height. */
11730 height
%= FRAME_LINE_HEIGHT (it
->f
);
11731 it
->max_ascent
+= height
/ 2;
11732 it
->max_descent
+= (height
+ 1) / 2;
11735 compute_line_metrics (it
);
11737 /* If line is empty, make it occupy the rest of the tool-bar. */
11738 if (!row
->displays_text_p
)
11740 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11741 row
->visible_height
= row
->height
;
11742 row
->ascent
= row
->phys_ascent
= 0;
11743 row
->extra_line_spacing
= 0;
11746 row
->full_width_p
= 1;
11747 row
->continued_p
= 0;
11748 row
->truncated_on_left_p
= 0;
11749 row
->truncated_on_right_p
= 0;
11751 it
->current_x
= it
->hpos
= 0;
11752 it
->current_y
+= row
->height
;
11758 /* Max tool-bar height. */
11760 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11761 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11763 /* Value is the number of screen lines needed to make all tool-bar
11764 items of frame F visible. The number of actual rows needed is
11765 returned in *N_ROWS if non-NULL. */
11768 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11770 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11772 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11773 the desired matrix, so use (unused) mode-line row as temporary row to
11774 avoid destroying the first tool-bar row. */
11775 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11777 /* Initialize an iterator for iteration over
11778 F->desired_tool_bar_string in the tool-bar window of frame F. */
11779 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11780 it
.first_visible_x
= 0;
11781 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11782 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11783 it
.paragraph_embedding
= L2R
;
11785 while (!ITERATOR_AT_END_P (&it
))
11787 clear_glyph_row (temp_row
);
11788 it
.glyph_row
= temp_row
;
11789 display_tool_bar_line (&it
, -1);
11791 clear_glyph_row (temp_row
);
11793 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11795 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11797 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11801 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11803 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11804 If FRAME is nil or omitted, use the selected frame. */)
11805 (Lisp_Object frame
)
11807 struct frame
*f
= decode_any_frame (frame
);
11811 if (WINDOWP (f
->tool_bar_window
)
11812 && (w
= XWINDOW (f
->tool_bar_window
),
11813 WINDOW_TOTAL_LINES (w
) > 0))
11815 update_tool_bar (f
, 1);
11816 if (f
->n_tool_bar_items
)
11818 build_desired_tool_bar_string (f
);
11819 nlines
= tool_bar_lines_needed (f
, NULL
);
11823 return make_number (nlines
);
11827 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11828 height should be changed. */
11831 redisplay_tool_bar (struct frame
*f
)
11835 struct glyph_row
*row
;
11837 #if defined (USE_GTK) || defined (HAVE_NS)
11838 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11839 update_frame_tool_bar (f
);
11843 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11844 do anything. This means you must start with tool-bar-lines
11845 non-zero to get the auto-sizing effect. Or in other words, you
11846 can turn off tool-bars by specifying tool-bar-lines zero. */
11847 if (!WINDOWP (f
->tool_bar_window
)
11848 || (w
= XWINDOW (f
->tool_bar_window
),
11849 WINDOW_TOTAL_LINES (w
) == 0))
11852 /* Set up an iterator for the tool-bar window. */
11853 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11854 it
.first_visible_x
= 0;
11855 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11856 row
= it
.glyph_row
;
11858 /* Build a string that represents the contents of the tool-bar. */
11859 build_desired_tool_bar_string (f
);
11860 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11861 /* FIXME: This should be controlled by a user option. But it
11862 doesn't make sense to have an R2L tool bar if the menu bar cannot
11863 be drawn also R2L, and making the menu bar R2L is tricky due
11864 toolkit-specific code that implements it. If an R2L tool bar is
11865 ever supported, display_tool_bar_line should also be augmented to
11866 call unproduce_glyphs like display_line and display_string
11868 it
.paragraph_embedding
= L2R
;
11870 if (f
->n_tool_bar_rows
== 0)
11874 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11875 nlines
!= WINDOW_TOTAL_LINES (w
)))
11878 int old_height
= WINDOW_TOTAL_LINES (w
);
11880 XSETFRAME (frame
, f
);
11881 Fmodify_frame_parameters (frame
,
11882 Fcons (Fcons (Qtool_bar_lines
,
11883 make_number (nlines
)),
11885 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11887 clear_glyph_matrix (w
->desired_matrix
);
11888 fonts_changed_p
= 1;
11894 /* Display as many lines as needed to display all tool-bar items. */
11896 if (f
->n_tool_bar_rows
> 0)
11898 int border
, rows
, height
, extra
;
11900 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11901 border
= XINT (Vtool_bar_border
);
11902 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11903 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11904 else if (EQ (Vtool_bar_border
, Qborder_width
))
11905 border
= f
->border_width
;
11911 rows
= f
->n_tool_bar_rows
;
11912 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11913 extra
= it
.last_visible_y
- border
- height
* rows
;
11915 while (it
.current_y
< it
.last_visible_y
)
11918 if (extra
> 0 && rows
-- > 0)
11920 h
= (extra
+ rows
- 1) / rows
;
11923 display_tool_bar_line (&it
, height
+ h
);
11928 while (it
.current_y
< it
.last_visible_y
)
11929 display_tool_bar_line (&it
, 0);
11932 /* It doesn't make much sense to try scrolling in the tool-bar
11933 window, so don't do it. */
11934 w
->desired_matrix
->no_scrolling_p
= 1;
11935 w
->must_be_updated_p
= 1;
11937 if (!NILP (Vauto_resize_tool_bars
))
11939 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11940 int change_height_p
= 0;
11942 /* If we couldn't display everything, change the tool-bar's
11943 height if there is room for more. */
11944 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11945 && it
.current_y
< max_tool_bar_height
)
11946 change_height_p
= 1;
11948 row
= it
.glyph_row
- 1;
11950 /* If there are blank lines at the end, except for a partially
11951 visible blank line at the end that is smaller than
11952 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11953 if (!row
->displays_text_p
11954 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11955 change_height_p
= 1;
11957 /* If row displays tool-bar items, but is partially visible,
11958 change the tool-bar's height. */
11959 if (row
->displays_text_p
11960 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11961 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11962 change_height_p
= 1;
11964 /* Resize windows as needed by changing the `tool-bar-lines'
11965 frame parameter. */
11966 if (change_height_p
)
11969 int old_height
= WINDOW_TOTAL_LINES (w
);
11971 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11973 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11974 && !f
->minimize_tool_bar_window_p
)
11975 ? (nlines
> old_height
)
11976 : (nlines
!= old_height
));
11977 f
->minimize_tool_bar_window_p
= 0;
11979 if (change_height_p
)
11981 XSETFRAME (frame
, f
);
11982 Fmodify_frame_parameters (frame
,
11983 Fcons (Fcons (Qtool_bar_lines
,
11984 make_number (nlines
)),
11986 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11988 clear_glyph_matrix (w
->desired_matrix
);
11989 f
->n_tool_bar_rows
= nrows
;
11990 fonts_changed_p
= 1;
11997 f
->minimize_tool_bar_window_p
= 0;
12002 /* Get information about the tool-bar item which is displayed in GLYPH
12003 on frame F. Return in *PROP_IDX the index where tool-bar item
12004 properties start in F->tool_bar_items. Value is zero if
12005 GLYPH doesn't display a tool-bar item. */
12008 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12014 /* This function can be called asynchronously, which means we must
12015 exclude any possibility that Fget_text_property signals an
12017 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12018 charpos
= max (0, charpos
);
12020 /* Get the text property `menu-item' at pos. The value of that
12021 property is the start index of this item's properties in
12022 F->tool_bar_items. */
12023 prop
= Fget_text_property (make_number (charpos
),
12024 Qmenu_item
, f
->current_tool_bar_string
);
12025 if (INTEGERP (prop
))
12027 *prop_idx
= XINT (prop
);
12037 /* Get information about the tool-bar item at position X/Y on frame F.
12038 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12039 the current matrix of the tool-bar window of F, or NULL if not
12040 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12041 item in F->tool_bar_items. Value is
12043 -1 if X/Y is not on a tool-bar item
12044 0 if X/Y is on the same item that was highlighted before.
12048 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12049 int *hpos
, int *vpos
, int *prop_idx
)
12051 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12052 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12055 /* Find the glyph under X/Y. */
12056 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12057 if (*glyph
== NULL
)
12060 /* Get the start of this tool-bar item's properties in
12061 f->tool_bar_items. */
12062 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12065 /* Is mouse on the highlighted item? */
12066 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12067 && *vpos
>= hlinfo
->mouse_face_beg_row
12068 && *vpos
<= hlinfo
->mouse_face_end_row
12069 && (*vpos
> hlinfo
->mouse_face_beg_row
12070 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12071 && (*vpos
< hlinfo
->mouse_face_end_row
12072 || *hpos
< hlinfo
->mouse_face_end_col
12073 || hlinfo
->mouse_face_past_end
))
12081 Handle mouse button event on the tool-bar of frame F, at
12082 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12083 0 for button release. MODIFIERS is event modifiers for button
12087 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12090 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12091 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12092 int hpos
, vpos
, prop_idx
;
12093 struct glyph
*glyph
;
12094 Lisp_Object enabled_p
;
12096 /* If not on the highlighted tool-bar item, return. */
12097 frame_to_window_pixel_xy (w
, &x
, &y
);
12098 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12101 /* If item is disabled, do nothing. */
12102 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12103 if (NILP (enabled_p
))
12108 /* Show item in pressed state. */
12109 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12110 last_tool_bar_item
= prop_idx
;
12114 Lisp_Object key
, frame
;
12115 struct input_event event
;
12116 EVENT_INIT (event
);
12118 /* Show item in released state. */
12119 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12121 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12123 XSETFRAME (frame
, f
);
12124 event
.kind
= TOOL_BAR_EVENT
;
12125 event
.frame_or_window
= frame
;
12127 kbd_buffer_store_event (&event
);
12129 event
.kind
= TOOL_BAR_EVENT
;
12130 event
.frame_or_window
= frame
;
12132 event
.modifiers
= modifiers
;
12133 kbd_buffer_store_event (&event
);
12134 last_tool_bar_item
= -1;
12139 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12140 tool-bar window-relative coordinates X/Y. Called from
12141 note_mouse_highlight. */
12144 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12146 Lisp_Object window
= f
->tool_bar_window
;
12147 struct window
*w
= XWINDOW (window
);
12148 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12149 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12151 struct glyph
*glyph
;
12152 struct glyph_row
*row
;
12154 Lisp_Object enabled_p
;
12156 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12157 int mouse_down_p
, rc
;
12159 /* Function note_mouse_highlight is called with negative X/Y
12160 values when mouse moves outside of the frame. */
12161 if (x
<= 0 || y
<= 0)
12163 clear_mouse_face (hlinfo
);
12167 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12170 /* Not on tool-bar item. */
12171 clear_mouse_face (hlinfo
);
12175 /* On same tool-bar item as before. */
12176 goto set_help_echo
;
12178 clear_mouse_face (hlinfo
);
12180 /* Mouse is down, but on different tool-bar item? */
12181 mouse_down_p
= (dpyinfo
->grabbed
12182 && f
== last_mouse_frame
12183 && FRAME_LIVE_P (f
));
12185 && last_tool_bar_item
!= prop_idx
)
12188 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12190 /* If tool-bar item is not enabled, don't highlight it. */
12191 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12192 if (!NILP (enabled_p
))
12194 /* Compute the x-position of the glyph. In front and past the
12195 image is a space. We include this in the highlighted area. */
12196 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12197 for (i
= x
= 0; i
< hpos
; ++i
)
12198 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12200 /* Record this as the current active region. */
12201 hlinfo
->mouse_face_beg_col
= hpos
;
12202 hlinfo
->mouse_face_beg_row
= vpos
;
12203 hlinfo
->mouse_face_beg_x
= x
;
12204 hlinfo
->mouse_face_beg_y
= row
->y
;
12205 hlinfo
->mouse_face_past_end
= 0;
12207 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12208 hlinfo
->mouse_face_end_row
= vpos
;
12209 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12210 hlinfo
->mouse_face_end_y
= row
->y
;
12211 hlinfo
->mouse_face_window
= window
;
12212 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12214 /* Display it as active. */
12215 show_mouse_face (hlinfo
, draw
);
12220 /* Set help_echo_string to a help string to display for this tool-bar item.
12221 XTread_socket does the rest. */
12222 help_echo_object
= help_echo_window
= Qnil
;
12223 help_echo_pos
= -1;
12224 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12225 if (NILP (help_echo_string
))
12226 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12229 #endif /* HAVE_WINDOW_SYSTEM */
12233 /************************************************************************
12234 Horizontal scrolling
12235 ************************************************************************/
12237 static int hscroll_window_tree (Lisp_Object
);
12238 static int hscroll_windows (Lisp_Object
);
12240 /* For all leaf windows in the window tree rooted at WINDOW, set their
12241 hscroll value so that PT is (i) visible in the window, and (ii) so
12242 that it is not within a certain margin at the window's left and
12243 right border. Value is non-zero if any window's hscroll has been
12247 hscroll_window_tree (Lisp_Object window
)
12249 int hscrolled_p
= 0;
12250 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12251 int hscroll_step_abs
= 0;
12252 double hscroll_step_rel
= 0;
12254 if (hscroll_relative_p
)
12256 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12257 if (hscroll_step_rel
< 0)
12259 hscroll_relative_p
= 0;
12260 hscroll_step_abs
= 0;
12263 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12265 hscroll_step_abs
= XINT (Vhscroll_step
);
12266 if (hscroll_step_abs
< 0)
12267 hscroll_step_abs
= 0;
12270 hscroll_step_abs
= 0;
12272 while (WINDOWP (window
))
12274 struct window
*w
= XWINDOW (window
);
12276 if (WINDOWP (w
->hchild
))
12277 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12278 else if (WINDOWP (w
->vchild
))
12279 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12280 else if (w
->cursor
.vpos
>= 0)
12283 int text_area_width
;
12284 struct glyph_row
*current_cursor_row
12285 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12286 struct glyph_row
*desired_cursor_row
12287 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12288 struct glyph_row
*cursor_row
12289 = (desired_cursor_row
->enabled_p
12290 ? desired_cursor_row
12291 : current_cursor_row
);
12292 int row_r2l_p
= cursor_row
->reversed_p
;
12294 text_area_width
= window_box_width (w
, TEXT_AREA
);
12296 /* Scroll when cursor is inside this scroll margin. */
12297 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12299 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12300 /* For left-to-right rows, hscroll when cursor is either
12301 (i) inside the right hscroll margin, or (ii) if it is
12302 inside the left margin and the window is already
12306 && w
->cursor
.x
<= h_margin
)
12307 || (cursor_row
->enabled_p
12308 && cursor_row
->truncated_on_right_p
12309 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12310 /* For right-to-left rows, the logic is similar,
12311 except that rules for scrolling to left and right
12312 are reversed. E.g., if cursor.x <= h_margin, we
12313 need to hscroll "to the right" unconditionally,
12314 and that will scroll the screen to the left so as
12315 to reveal the next portion of the row. */
12317 && ((cursor_row
->enabled_p
12318 /* FIXME: It is confusing to set the
12319 truncated_on_right_p flag when R2L rows
12320 are actually truncated on the left. */
12321 && cursor_row
->truncated_on_right_p
12322 && w
->cursor
.x
<= h_margin
)
12324 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12328 struct buffer
*saved_current_buffer
;
12332 /* Find point in a display of infinite width. */
12333 saved_current_buffer
= current_buffer
;
12334 current_buffer
= XBUFFER (w
->buffer
);
12336 if (w
== XWINDOW (selected_window
))
12339 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12341 /* Move iterator to pt starting at cursor_row->start in
12342 a line with infinite width. */
12343 init_to_row_start (&it
, w
, cursor_row
);
12344 it
.last_visible_x
= INFINITY
;
12345 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12346 current_buffer
= saved_current_buffer
;
12348 /* Position cursor in window. */
12349 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12350 hscroll
= max (0, (it
.current_x
12351 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12352 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12353 : (text_area_width
/ 2))))
12354 / FRAME_COLUMN_WIDTH (it
.f
);
12355 else if ((!row_r2l_p
12356 && w
->cursor
.x
>= text_area_width
- h_margin
)
12357 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12359 if (hscroll_relative_p
)
12360 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12363 wanted_x
= text_area_width
12364 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12367 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12371 if (hscroll_relative_p
)
12372 wanted_x
= text_area_width
* hscroll_step_rel
12375 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12378 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12380 hscroll
= max (hscroll
, w
->min_hscroll
);
12382 /* Don't prevent redisplay optimizations if hscroll
12383 hasn't changed, as it will unnecessarily slow down
12385 if (w
->hscroll
!= hscroll
)
12387 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12388 w
->hscroll
= hscroll
;
12397 /* Value is non-zero if hscroll of any leaf window has been changed. */
12398 return hscrolled_p
;
12402 /* Set hscroll so that cursor is visible and not inside horizontal
12403 scroll margins for all windows in the tree rooted at WINDOW. See
12404 also hscroll_window_tree above. Value is non-zero if any window's
12405 hscroll has been changed. If it has, desired matrices on the frame
12406 of WINDOW are cleared. */
12409 hscroll_windows (Lisp_Object window
)
12411 int hscrolled_p
= hscroll_window_tree (window
);
12413 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12414 return hscrolled_p
;
12419 /************************************************************************
12421 ************************************************************************/
12423 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12424 to a non-zero value. This is sometimes handy to have in a debugger
12429 /* First and last unchanged row for try_window_id. */
12431 static int debug_first_unchanged_at_end_vpos
;
12432 static int debug_last_unchanged_at_beg_vpos
;
12434 /* Delta vpos and y. */
12436 static int debug_dvpos
, debug_dy
;
12438 /* Delta in characters and bytes for try_window_id. */
12440 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12442 /* Values of window_end_pos and window_end_vpos at the end of
12445 static ptrdiff_t debug_end_vpos
;
12447 /* Append a string to W->desired_matrix->method. FMT is a printf
12448 format string. If trace_redisplay_p is non-zero also printf the
12449 resulting string to stderr. */
12451 static void debug_method_add (struct window
*, char const *, ...)
12452 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12455 debug_method_add (struct window
*w
, char const *fmt
, ...)
12457 char *method
= w
->desired_matrix
->method
;
12458 int len
= strlen (method
);
12459 int size
= sizeof w
->desired_matrix
->method
;
12460 int remaining
= size
- len
- 1;
12463 if (len
&& remaining
)
12466 --remaining
, ++len
;
12469 va_start (ap
, fmt
);
12470 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12473 if (trace_redisplay_p
)
12474 fprintf (stderr
, "%p (%s): %s\n",
12476 ((BUFFERP (w
->buffer
)
12477 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12478 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12483 #endif /* GLYPH_DEBUG */
12486 /* Value is non-zero if all changes in window W, which displays
12487 current_buffer, are in the text between START and END. START is a
12488 buffer position, END is given as a distance from Z. Used in
12489 redisplay_internal for display optimization. */
12492 text_outside_line_unchanged_p (struct window
*w
,
12493 ptrdiff_t start
, ptrdiff_t end
)
12495 int unchanged_p
= 1;
12497 /* If text or overlays have changed, see where. */
12498 if (window_outdated (w
))
12500 /* Gap in the line? */
12501 if (GPT
< start
|| Z
- GPT
< end
)
12504 /* Changes start in front of the line, or end after it? */
12506 && (BEG_UNCHANGED
< start
- 1
12507 || END_UNCHANGED
< end
))
12510 /* If selective display, can't optimize if changes start at the
12511 beginning of the line. */
12513 && INTEGERP (BVAR (current_buffer
, selective_display
))
12514 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12515 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12518 /* If there are overlays at the start or end of the line, these
12519 may have overlay strings with newlines in them. A change at
12520 START, for instance, may actually concern the display of such
12521 overlay strings as well, and they are displayed on different
12522 lines. So, quickly rule out this case. (For the future, it
12523 might be desirable to implement something more telling than
12524 just BEG/END_UNCHANGED.) */
12527 if (BEG
+ BEG_UNCHANGED
== start
12528 && overlay_touches_p (start
))
12530 if (END_UNCHANGED
== end
12531 && overlay_touches_p (Z
- end
))
12535 /* Under bidi reordering, adding or deleting a character in the
12536 beginning of a paragraph, before the first strong directional
12537 character, can change the base direction of the paragraph (unless
12538 the buffer specifies a fixed paragraph direction), which will
12539 require to redisplay the whole paragraph. It might be worthwhile
12540 to find the paragraph limits and widen the range of redisplayed
12541 lines to that, but for now just give up this optimization. */
12542 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12543 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12547 return unchanged_p
;
12551 /* Do a frame update, taking possible shortcuts into account. This is
12552 the main external entry point for redisplay.
12554 If the last redisplay displayed an echo area message and that message
12555 is no longer requested, we clear the echo area or bring back the
12556 mini-buffer if that is in use. */
12561 redisplay_internal ();
12566 overlay_arrow_string_or_property (Lisp_Object var
)
12570 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12573 return Voverlay_arrow_string
;
12576 /* Return 1 if there are any overlay-arrows in current_buffer. */
12578 overlay_arrow_in_current_buffer_p (void)
12582 for (vlist
= Voverlay_arrow_variable_list
;
12584 vlist
= XCDR (vlist
))
12586 Lisp_Object var
= XCAR (vlist
);
12589 if (!SYMBOLP (var
))
12591 val
= find_symbol_value (var
);
12593 && current_buffer
== XMARKER (val
)->buffer
)
12600 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12604 overlay_arrows_changed_p (void)
12608 for (vlist
= Voverlay_arrow_variable_list
;
12610 vlist
= XCDR (vlist
))
12612 Lisp_Object var
= XCAR (vlist
);
12613 Lisp_Object val
, pstr
;
12615 if (!SYMBOLP (var
))
12617 val
= find_symbol_value (var
);
12618 if (!MARKERP (val
))
12620 if (! EQ (COERCE_MARKER (val
),
12621 Fget (var
, Qlast_arrow_position
))
12622 || ! (pstr
= overlay_arrow_string_or_property (var
),
12623 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12629 /* Mark overlay arrows to be updated on next redisplay. */
12632 update_overlay_arrows (int up_to_date
)
12636 for (vlist
= Voverlay_arrow_variable_list
;
12638 vlist
= XCDR (vlist
))
12640 Lisp_Object var
= XCAR (vlist
);
12642 if (!SYMBOLP (var
))
12645 if (up_to_date
> 0)
12647 Lisp_Object val
= find_symbol_value (var
);
12648 Fput (var
, Qlast_arrow_position
,
12649 COERCE_MARKER (val
));
12650 Fput (var
, Qlast_arrow_string
,
12651 overlay_arrow_string_or_property (var
));
12653 else if (up_to_date
< 0
12654 || !NILP (Fget (var
, Qlast_arrow_position
)))
12656 Fput (var
, Qlast_arrow_position
, Qt
);
12657 Fput (var
, Qlast_arrow_string
, Qt
);
12663 /* Return overlay arrow string to display at row.
12664 Return integer (bitmap number) for arrow bitmap in left fringe.
12665 Return nil if no overlay arrow. */
12668 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12672 for (vlist
= Voverlay_arrow_variable_list
;
12674 vlist
= XCDR (vlist
))
12676 Lisp_Object var
= XCAR (vlist
);
12679 if (!SYMBOLP (var
))
12682 val
= find_symbol_value (var
);
12685 && current_buffer
== XMARKER (val
)->buffer
12686 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12688 if (FRAME_WINDOW_P (it
->f
)
12689 /* FIXME: if ROW->reversed_p is set, this should test
12690 the right fringe, not the left one. */
12691 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12693 #ifdef HAVE_WINDOW_SYSTEM
12694 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12697 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12698 return make_number (fringe_bitmap
);
12701 return make_number (-1); /* Use default arrow bitmap. */
12703 return overlay_arrow_string_or_property (var
);
12710 /* Return 1 if point moved out of or into a composition. Otherwise
12711 return 0. PREV_BUF and PREV_PT are the last point buffer and
12712 position. BUF and PT are the current point buffer and position. */
12715 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12716 struct buffer
*buf
, ptrdiff_t pt
)
12718 ptrdiff_t start
, end
;
12720 Lisp_Object buffer
;
12722 XSETBUFFER (buffer
, buf
);
12723 /* Check a composition at the last point if point moved within the
12725 if (prev_buf
== buf
)
12728 /* Point didn't move. */
12731 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12732 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12733 && COMPOSITION_VALID_P (start
, end
, prop
)
12734 && start
< prev_pt
&& end
> prev_pt
)
12735 /* The last point was within the composition. Return 1 iff
12736 point moved out of the composition. */
12737 return (pt
<= start
|| pt
>= end
);
12740 /* Check a composition at the current point. */
12741 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12742 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12743 && COMPOSITION_VALID_P (start
, end
, prop
)
12744 && start
< pt
&& end
> pt
);
12748 /* Reconsider the setting of B->clip_changed which is displayed
12752 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12754 if (b
->clip_changed
12755 && w
->window_end_valid
12756 && w
->current_matrix
->buffer
== b
12757 && w
->current_matrix
->zv
== BUF_ZV (b
)
12758 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12759 b
->clip_changed
= 0;
12761 /* If display wasn't paused, and W is not a tool bar window, see if
12762 point has been moved into or out of a composition. In that case,
12763 we set b->clip_changed to 1 to force updating the screen. If
12764 b->clip_changed has already been set to 1, we can skip this
12766 if (!b
->clip_changed
&& BUFFERP (w
->buffer
) && w
->window_end_valid
)
12770 if (w
== XWINDOW (selected_window
))
12773 pt
= marker_position (w
->pointm
);
12775 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12776 || pt
!= w
->last_point
)
12777 && check_point_in_composition (w
->current_matrix
->buffer
,
12779 XBUFFER (w
->buffer
), pt
))
12780 b
->clip_changed
= 1;
12785 #define STOP_POLLING \
12786 do { if (! polling_stopped_here) stop_polling (); \
12787 polling_stopped_here = 1; } while (0)
12789 #define RESUME_POLLING \
12790 do { if (polling_stopped_here) start_polling (); \
12791 polling_stopped_here = 0; } while (0)
12794 /* Perhaps in the future avoid recentering windows if it
12795 is not necessary; currently that causes some problems. */
12798 redisplay_internal (void)
12800 struct window
*w
= XWINDOW (selected_window
);
12804 int must_finish
= 0;
12805 struct text_pos tlbufpos
, tlendpos
;
12806 int number_of_visible_frames
;
12807 ptrdiff_t count
, count1
;
12809 int polling_stopped_here
= 0;
12810 Lisp_Object tail
, frame
;
12811 struct backtrace backtrace
;
12813 /* Non-zero means redisplay has to consider all windows on all
12814 frames. Zero means, only selected_window is considered. */
12815 int consider_all_windows_p
;
12817 /* Non-zero means redisplay has to redisplay the miniwindow. */
12818 int update_miniwindow_p
= 0;
12820 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12822 /* No redisplay if running in batch mode or frame is not yet fully
12823 initialized, or redisplay is explicitly turned off by setting
12824 Vinhibit_redisplay. */
12825 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12826 || !NILP (Vinhibit_redisplay
))
12829 /* Don't examine these until after testing Vinhibit_redisplay.
12830 When Emacs is shutting down, perhaps because its connection to
12831 X has dropped, we should not look at them at all. */
12832 fr
= XFRAME (w
->frame
);
12833 sf
= SELECTED_FRAME ();
12835 if (!fr
->glyphs_initialized_p
)
12838 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12839 if (popup_activated ())
12843 /* I don't think this happens but let's be paranoid. */
12844 if (redisplaying_p
)
12847 /* Record a function that clears redisplaying_p
12848 when we leave this function. */
12849 count
= SPECPDL_INDEX ();
12850 record_unwind_protect (unwind_redisplay
, selected_frame
);
12851 redisplaying_p
= 1;
12852 specbind (Qinhibit_free_realized_faces
, Qnil
);
12854 /* Record this function, so it appears on the profiler's backtraces. */
12855 backtrace
.next
= backtrace_list
;
12856 backtrace
.function
= Qredisplay_internal
;
12857 backtrace
.args
= &Qnil
;
12858 backtrace
.nargs
= 0;
12859 backtrace
.debug_on_exit
= 0;
12860 backtrace_list
= &backtrace
;
12862 FOR_EACH_FRAME (tail
, frame
)
12863 XFRAME (frame
)->already_hscrolled_p
= 0;
12866 /* Remember the currently selected window. */
12870 reconsider_clip_changes (w
, current_buffer
);
12871 last_escape_glyph_frame
= NULL
;
12872 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12873 last_glyphless_glyph_frame
= NULL
;
12874 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12876 /* If new fonts have been loaded that make a glyph matrix adjustment
12877 necessary, do it. */
12878 if (fonts_changed_p
)
12880 adjust_glyphs (NULL
);
12881 ++windows_or_buffers_changed
;
12882 fonts_changed_p
= 0;
12885 /* If face_change_count is non-zero, init_iterator will free all
12886 realized faces, which includes the faces referenced from current
12887 matrices. So, we can't reuse current matrices in this case. */
12888 if (face_change_count
)
12889 ++windows_or_buffers_changed
;
12891 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12892 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12894 /* Since frames on a single ASCII terminal share the same
12895 display area, displaying a different frame means redisplay
12896 the whole thing. */
12897 windows_or_buffers_changed
++;
12898 SET_FRAME_GARBAGED (sf
);
12900 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12902 FRAME_TTY (sf
)->previous_frame
= sf
;
12905 /* Set the visible flags for all frames. Do this before checking for
12906 resized or garbaged frames; they want to know if their frames are
12907 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
12908 number_of_visible_frames
= 0;
12910 FOR_EACH_FRAME (tail
, frame
)
12912 struct frame
*f
= XFRAME (frame
);
12914 if (FRAME_VISIBLE_P (f
))
12915 ++number_of_visible_frames
;
12916 clear_desired_matrices (f
);
12919 /* Notice any pending interrupt request to change frame size. */
12920 do_pending_window_change (1);
12922 /* do_pending_window_change could change the selected_window due to
12923 frame resizing which makes the selected window too small. */
12924 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12927 reconsider_clip_changes (w
, current_buffer
);
12930 /* Clear frames marked as garbaged. */
12931 clear_garbaged_frames ();
12933 /* Build menubar and tool-bar items. */
12934 if (NILP (Vmemory_full
))
12935 prepare_menu_bars ();
12937 if (windows_or_buffers_changed
)
12938 update_mode_lines
++;
12940 /* Detect case that we need to write or remove a star in the mode line. */
12941 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
12943 w
->update_mode_line
= 1;
12944 if (buffer_shared_and_changed ())
12945 update_mode_lines
++;
12948 /* Avoid invocation of point motion hooks by `current_column' below. */
12949 count1
= SPECPDL_INDEX ();
12950 specbind (Qinhibit_point_motion_hooks
, Qt
);
12952 if (mode_line_update_needed (w
))
12953 w
->update_mode_line
= 1;
12955 unbind_to (count1
, Qnil
);
12957 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12959 consider_all_windows_p
= (update_mode_lines
12960 || buffer_shared_and_changed ()
12961 || cursor_type_changed
);
12963 /* If specs for an arrow have changed, do thorough redisplay
12964 to ensure we remove any arrow that should no longer exist. */
12965 if (overlay_arrows_changed_p ())
12966 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12968 /* Normally the message* functions will have already displayed and
12969 updated the echo area, but the frame may have been trashed, or
12970 the update may have been preempted, so display the echo area
12971 again here. Checking message_cleared_p captures the case that
12972 the echo area should be cleared. */
12973 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12974 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12975 || (message_cleared_p
12976 && minibuf_level
== 0
12977 /* If the mini-window is currently selected, this means the
12978 echo-area doesn't show through. */
12979 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12981 int window_height_changed_p
= echo_area_display (0);
12983 if (message_cleared_p
)
12984 update_miniwindow_p
= 1;
12988 /* If we don't display the current message, don't clear the
12989 message_cleared_p flag, because, if we did, we wouldn't clear
12990 the echo area in the next redisplay which doesn't preserve
12992 if (!display_last_displayed_message_p
)
12993 message_cleared_p
= 0;
12995 if (fonts_changed_p
)
12997 else if (window_height_changed_p
)
12999 consider_all_windows_p
= 1;
13000 ++update_mode_lines
;
13001 ++windows_or_buffers_changed
;
13003 /* If window configuration was changed, frames may have been
13004 marked garbaged. Clear them or we will experience
13005 surprises wrt scrolling. */
13006 clear_garbaged_frames ();
13009 else if (EQ (selected_window
, minibuf_window
)
13010 && (current_buffer
->clip_changed
|| window_outdated (w
))
13011 && resize_mini_window (w
, 0))
13013 /* Resized active mini-window to fit the size of what it is
13014 showing if its contents might have changed. */
13016 /* FIXME: this causes all frames to be updated, which seems unnecessary
13017 since only the current frame needs to be considered. This function
13018 needs to be rewritten with two variables, consider_all_windows and
13019 consider_all_frames. */
13020 consider_all_windows_p
= 1;
13021 ++windows_or_buffers_changed
;
13022 ++update_mode_lines
;
13024 /* If window configuration was changed, frames may have been
13025 marked garbaged. Clear them or we will experience
13026 surprises wrt scrolling. */
13027 clear_garbaged_frames ();
13030 /* If showing the region, and mark has changed, we must redisplay
13031 the whole window. The assignment to this_line_start_pos prevents
13032 the optimization directly below this if-statement. */
13033 if (((!NILP (Vtransient_mark_mode
)
13034 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13035 != (w
->region_showing
> 0))
13036 || (w
->region_showing
13037 && w
->region_showing
13038 != XINT (Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13039 CHARPOS (this_line_start_pos
) = 0;
13041 /* Optimize the case that only the line containing the cursor in the
13042 selected window has changed. Variables starting with this_ are
13043 set in display_line and record information about the line
13044 containing the cursor. */
13045 tlbufpos
= this_line_start_pos
;
13046 tlendpos
= this_line_end_pos
;
13047 if (!consider_all_windows_p
13048 && CHARPOS (tlbufpos
) > 0
13049 && !w
->update_mode_line
13050 && !current_buffer
->clip_changed
13051 && !current_buffer
->prevent_redisplay_optimizations_p
13052 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13053 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13054 /* Make sure recorded data applies to current buffer, etc. */
13055 && this_line_buffer
== current_buffer
13056 && current_buffer
== XBUFFER (w
->buffer
)
13058 && !w
->optional_new_start
13059 /* Point must be on the line that we have info recorded about. */
13060 && PT
>= CHARPOS (tlbufpos
)
13061 && PT
<= Z
- CHARPOS (tlendpos
)
13062 /* All text outside that line, including its final newline,
13063 must be unchanged. */
13064 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13065 CHARPOS (tlendpos
)))
13067 if (CHARPOS (tlbufpos
) > BEGV
13068 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13069 && (CHARPOS (tlbufpos
) == ZV
13070 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13071 /* Former continuation line has disappeared by becoming empty. */
13073 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13075 /* We have to handle the case of continuation around a
13076 wide-column character (see the comment in indent.c around
13079 For instance, in the following case:
13081 -------- Insert --------
13082 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13083 J_I_ ==> J_I_ `^^' are cursors.
13087 As we have to redraw the line above, we cannot use this
13091 int line_height_before
= this_line_pixel_height
;
13093 /* Note that start_display will handle the case that the
13094 line starting at tlbufpos is a continuation line. */
13095 start_display (&it
, w
, tlbufpos
);
13097 /* Implementation note: It this still necessary? */
13098 if (it
.current_x
!= this_line_start_x
)
13101 TRACE ((stderr
, "trying display optimization 1\n"));
13102 w
->cursor
.vpos
= -1;
13103 overlay_arrow_seen
= 0;
13104 it
.vpos
= this_line_vpos
;
13105 it
.current_y
= this_line_y
;
13106 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13107 display_line (&it
);
13109 /* If line contains point, is not continued,
13110 and ends at same distance from eob as before, we win. */
13111 if (w
->cursor
.vpos
>= 0
13112 /* Line is not continued, otherwise this_line_start_pos
13113 would have been set to 0 in display_line. */
13114 && CHARPOS (this_line_start_pos
)
13115 /* Line ends as before. */
13116 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13117 /* Line has same height as before. Otherwise other lines
13118 would have to be shifted up or down. */
13119 && this_line_pixel_height
== line_height_before
)
13121 /* If this is not the window's last line, we must adjust
13122 the charstarts of the lines below. */
13123 if (it
.current_y
< it
.last_visible_y
)
13125 struct glyph_row
*row
13126 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13127 ptrdiff_t delta
, delta_bytes
;
13129 /* We used to distinguish between two cases here,
13130 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13131 when the line ends in a newline or the end of the
13132 buffer's accessible portion. But both cases did
13133 the same, so they were collapsed. */
13135 - CHARPOS (tlendpos
)
13136 - MATRIX_ROW_START_CHARPOS (row
));
13137 delta_bytes
= (Z_BYTE
13138 - BYTEPOS (tlendpos
)
13139 - MATRIX_ROW_START_BYTEPOS (row
));
13141 increment_matrix_positions (w
->current_matrix
,
13142 this_line_vpos
+ 1,
13143 w
->current_matrix
->nrows
,
13144 delta
, delta_bytes
);
13147 /* If this row displays text now but previously didn't,
13148 or vice versa, w->window_end_vpos may have to be
13150 if ((it
.glyph_row
- 1)->displays_text_p
)
13152 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13153 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13155 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13156 && this_line_vpos
> 0)
13157 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13158 w
->window_end_valid
= 0;
13160 /* Update hint: No need to try to scroll in update_window. */
13161 w
->desired_matrix
->no_scrolling_p
= 1;
13164 *w
->desired_matrix
->method
= 0;
13165 debug_method_add (w
, "optimization 1");
13167 #ifdef HAVE_WINDOW_SYSTEM
13168 update_window_fringes (w
, 0);
13175 else if (/* Cursor position hasn't changed. */
13176 PT
== w
->last_point
13177 /* Make sure the cursor was last displayed
13178 in this window. Otherwise we have to reposition it. */
13179 && 0 <= w
->cursor
.vpos
13180 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13184 do_pending_window_change (1);
13185 /* If selected_window changed, redisplay again. */
13186 if (WINDOWP (selected_window
)
13187 && (w
= XWINDOW (selected_window
)) != sw
)
13190 /* We used to always goto end_of_redisplay here, but this
13191 isn't enough if we have a blinking cursor. */
13192 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13193 goto end_of_redisplay
;
13197 /* If highlighting the region, or if the cursor is in the echo area,
13198 then we can't just move the cursor. */
13199 else if (! (!NILP (Vtransient_mark_mode
)
13200 && !NILP (BVAR (current_buffer
, mark_active
)))
13201 && (EQ (selected_window
,
13202 BVAR (current_buffer
, last_selected_window
))
13203 || highlight_nonselected_windows
)
13204 && !w
->region_showing
13205 && NILP (Vshow_trailing_whitespace
)
13206 && !cursor_in_echo_area
)
13209 struct glyph_row
*row
;
13211 /* Skip from tlbufpos to PT and see where it is. Note that
13212 PT may be in invisible text. If so, we will end at the
13213 next visible position. */
13214 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13215 NULL
, DEFAULT_FACE_ID
);
13216 it
.current_x
= this_line_start_x
;
13217 it
.current_y
= this_line_y
;
13218 it
.vpos
= this_line_vpos
;
13220 /* The call to move_it_to stops in front of PT, but
13221 moves over before-strings. */
13222 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13224 if (it
.vpos
== this_line_vpos
13225 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13228 eassert (this_line_vpos
== it
.vpos
);
13229 eassert (this_line_y
== it
.current_y
);
13230 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13232 *w
->desired_matrix
->method
= 0;
13233 debug_method_add (w
, "optimization 3");
13242 /* Text changed drastically or point moved off of line. */
13243 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13246 CHARPOS (this_line_start_pos
) = 0;
13247 consider_all_windows_p
|= buffer_shared_and_changed ();
13248 ++clear_face_cache_count
;
13249 #ifdef HAVE_WINDOW_SYSTEM
13250 ++clear_image_cache_count
;
13253 w
->region_showing
= XINT (Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)));
13255 /* Build desired matrices, and update the display. If
13256 consider_all_windows_p is non-zero, do it for all windows on all
13257 frames. Otherwise do it for selected_window, only. */
13259 if (consider_all_windows_p
)
13261 FOR_EACH_FRAME (tail
, frame
)
13262 XFRAME (frame
)->updated_p
= 0;
13264 FOR_EACH_FRAME (tail
, frame
)
13266 struct frame
*f
= XFRAME (frame
);
13268 /* We don't have to do anything for unselected terminal
13270 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13271 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13274 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13276 /* Mark all the scroll bars to be removed; we'll redeem
13277 the ones we want when we redisplay their windows. */
13278 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13279 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13281 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13282 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13284 /* The X error handler may have deleted that frame. */
13285 if (!FRAME_LIVE_P (f
))
13288 /* Any scroll bars which redisplay_windows should have
13289 nuked should now go away. */
13290 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13291 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13293 /* If fonts changed, display again. */
13294 /* ??? rms: I suspect it is a mistake to jump all the way
13295 back to retry here. It should just retry this frame. */
13296 if (fonts_changed_p
)
13299 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13301 /* See if we have to hscroll. */
13302 if (!f
->already_hscrolled_p
)
13304 f
->already_hscrolled_p
= 1;
13305 if (hscroll_windows (f
->root_window
))
13309 /* Prevent various kinds of signals during display
13310 update. stdio is not robust about handling
13311 signals, which can cause an apparent I/O
13313 if (interrupt_input
)
13314 unrequest_sigio ();
13317 /* Update the display. */
13318 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13319 pending
|= update_frame (f
, 0, 0);
13325 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13329 /* Do the mark_window_display_accurate after all windows have
13330 been redisplayed because this call resets flags in buffers
13331 which are needed for proper redisplay. */
13332 FOR_EACH_FRAME (tail
, frame
)
13334 struct frame
*f
= XFRAME (frame
);
13337 mark_window_display_accurate (f
->root_window
, 1);
13338 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13339 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13344 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13346 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13347 struct frame
*mini_frame
;
13349 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13350 /* Use list_of_error, not Qerror, so that
13351 we catch only errors and don't run the debugger. */
13352 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13354 redisplay_window_error
);
13355 if (update_miniwindow_p
)
13356 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13358 redisplay_window_error
);
13360 /* Compare desired and current matrices, perform output. */
13363 /* If fonts changed, display again. */
13364 if (fonts_changed_p
)
13367 /* Prevent various kinds of signals during display update.
13368 stdio is not robust about handling signals,
13369 which can cause an apparent I/O error. */
13370 if (interrupt_input
)
13371 unrequest_sigio ();
13374 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13376 if (hscroll_windows (selected_window
))
13379 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13380 pending
= update_frame (sf
, 0, 0);
13383 /* We may have called echo_area_display at the top of this
13384 function. If the echo area is on another frame, that may
13385 have put text on a frame other than the selected one, so the
13386 above call to update_frame would not have caught it. Catch
13388 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13389 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13391 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13393 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13394 pending
|= update_frame (mini_frame
, 0, 0);
13395 if (!pending
&& hscroll_windows (mini_window
))
13400 /* If display was paused because of pending input, make sure we do a
13401 thorough update the next time. */
13404 /* Prevent the optimization at the beginning of
13405 redisplay_internal that tries a single-line update of the
13406 line containing the cursor in the selected window. */
13407 CHARPOS (this_line_start_pos
) = 0;
13409 /* Let the overlay arrow be updated the next time. */
13410 update_overlay_arrows (0);
13412 /* If we pause after scrolling, some rows in the current
13413 matrices of some windows are not valid. */
13414 if (!WINDOW_FULL_WIDTH_P (w
)
13415 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13416 update_mode_lines
= 1;
13420 if (!consider_all_windows_p
)
13422 /* This has already been done above if
13423 consider_all_windows_p is set. */
13424 mark_window_display_accurate_1 (w
, 1);
13426 /* Say overlay arrows are up to date. */
13427 update_overlay_arrows (1);
13429 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13430 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13433 update_mode_lines
= 0;
13434 windows_or_buffers_changed
= 0;
13435 cursor_type_changed
= 0;
13438 /* Start SIGIO interrupts coming again. Having them off during the
13439 code above makes it less likely one will discard output, but not
13440 impossible, since there might be stuff in the system buffer here.
13441 But it is much hairier to try to do anything about that. */
13442 if (interrupt_input
)
13446 /* If a frame has become visible which was not before, redisplay
13447 again, so that we display it. Expose events for such a frame
13448 (which it gets when becoming visible) don't call the parts of
13449 redisplay constructing glyphs, so simply exposing a frame won't
13450 display anything in this case. So, we have to display these
13451 frames here explicitly. */
13456 FOR_EACH_FRAME (tail
, frame
)
13458 int this_is_visible
= 0;
13460 if (XFRAME (frame
)->visible
)
13461 this_is_visible
= 1;
13463 if (this_is_visible
)
13467 if (new_count
!= number_of_visible_frames
)
13468 windows_or_buffers_changed
++;
13471 /* Change frame size now if a change is pending. */
13472 do_pending_window_change (1);
13474 /* If we just did a pending size change, or have additional
13475 visible frames, or selected_window changed, redisplay again. */
13476 if ((windows_or_buffers_changed
&& !pending
)
13477 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13480 /* Clear the face and image caches.
13482 We used to do this only if consider_all_windows_p. But the cache
13483 needs to be cleared if a timer creates images in the current
13484 buffer (e.g. the test case in Bug#6230). */
13486 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13488 clear_face_cache (0);
13489 clear_face_cache_count
= 0;
13492 #ifdef HAVE_WINDOW_SYSTEM
13493 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13495 clear_image_caches (Qnil
);
13496 clear_image_cache_count
= 0;
13498 #endif /* HAVE_WINDOW_SYSTEM */
13501 backtrace_list
= backtrace
.next
;
13502 unbind_to (count
, Qnil
);
13507 /* Redisplay, but leave alone any recent echo area message unless
13508 another message has been requested in its place.
13510 This is useful in situations where you need to redisplay but no
13511 user action has occurred, making it inappropriate for the message
13512 area to be cleared. See tracking_off and
13513 wait_reading_process_output for examples of these situations.
13515 FROM_WHERE is an integer saying from where this function was
13516 called. This is useful for debugging. */
13519 redisplay_preserve_echo_area (int from_where
)
13521 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13523 if (!NILP (echo_area_buffer
[1]))
13525 /* We have a previously displayed message, but no current
13526 message. Redisplay the previous message. */
13527 display_last_displayed_message_p
= 1;
13528 redisplay_internal ();
13529 display_last_displayed_message_p
= 0;
13532 redisplay_internal ();
13534 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13535 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13536 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13540 /* Function registered with record_unwind_protect in redisplay_internal.
13541 Clear redisplaying_p. Also select the previously selected frame. */
13544 unwind_redisplay (Lisp_Object old_frame
)
13546 redisplaying_p
= 0;
13551 /* Mark the display of leaf window W as accurate or inaccurate.
13552 If ACCURATE_P is non-zero mark display of W as accurate. If
13553 ACCURATE_P is zero, arrange for W to be redisplayed the next
13554 time redisplay_internal is called. */
13557 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13559 struct buffer
*b
= XBUFFER (w
->buffer
);
13561 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13562 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13563 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13567 b
->clip_changed
= 0;
13568 b
->prevent_redisplay_optimizations_p
= 0;
13570 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13571 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13572 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13573 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13575 w
->current_matrix
->buffer
= b
;
13576 w
->current_matrix
->begv
= BUF_BEGV (b
);
13577 w
->current_matrix
->zv
= BUF_ZV (b
);
13579 w
->last_cursor
= w
->cursor
;
13580 w
->last_cursor_off_p
= w
->cursor_off_p
;
13582 if (w
== XWINDOW (selected_window
))
13583 w
->last_point
= BUF_PT (b
);
13585 w
->last_point
= marker_position (w
->pointm
);
13587 w
->window_end_valid
= 1;
13588 w
->update_mode_line
= 0;
13593 /* Mark the display of windows in the window tree rooted at WINDOW as
13594 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13595 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13596 be redisplayed the next time redisplay_internal is called. */
13599 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13603 for (; !NILP (window
); window
= w
->next
)
13605 w
= XWINDOW (window
);
13606 if (!NILP (w
->vchild
))
13607 mark_window_display_accurate (w
->vchild
, accurate_p
);
13608 else if (!NILP (w
->hchild
))
13609 mark_window_display_accurate (w
->hchild
, accurate_p
);
13610 else if (BUFFERP (w
->buffer
))
13611 mark_window_display_accurate_1 (w
, accurate_p
);
13615 update_overlay_arrows (1);
13617 /* Force a thorough redisplay the next time by setting
13618 last_arrow_position and last_arrow_string to t, which is
13619 unequal to any useful value of Voverlay_arrow_... */
13620 update_overlay_arrows (-1);
13624 /* Return value in display table DP (Lisp_Char_Table *) for character
13625 C. Since a display table doesn't have any parent, we don't have to
13626 follow parent. Do not call this function directly but use the
13627 macro DISP_CHAR_VECTOR. */
13630 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13634 if (ASCII_CHAR_P (c
))
13637 if (SUB_CHAR_TABLE_P (val
))
13638 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13644 XSETCHAR_TABLE (table
, dp
);
13645 val
= char_table_ref (table
, c
);
13654 /***********************************************************************
13656 ***********************************************************************/
13658 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13661 redisplay_windows (Lisp_Object window
)
13663 while (!NILP (window
))
13665 struct window
*w
= XWINDOW (window
);
13667 if (!NILP (w
->hchild
))
13668 redisplay_windows (w
->hchild
);
13669 else if (!NILP (w
->vchild
))
13670 redisplay_windows (w
->vchild
);
13671 else if (!NILP (w
->buffer
))
13673 displayed_buffer
= XBUFFER (w
->buffer
);
13674 /* Use list_of_error, not Qerror, so that
13675 we catch only errors and don't run the debugger. */
13676 internal_condition_case_1 (redisplay_window_0
, window
,
13678 redisplay_window_error
);
13686 redisplay_window_error (Lisp_Object ignore
)
13688 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13693 redisplay_window_0 (Lisp_Object window
)
13695 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13696 redisplay_window (window
, 0);
13701 redisplay_window_1 (Lisp_Object window
)
13703 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13704 redisplay_window (window
, 1);
13709 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13710 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13711 which positions recorded in ROW differ from current buffer
13714 Return 0 if cursor is not on this row, 1 otherwise. */
13717 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13718 struct glyph_matrix
*matrix
,
13719 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13722 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13723 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13724 struct glyph
*cursor
= NULL
;
13725 /* The last known character position in row. */
13726 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13728 ptrdiff_t pt_old
= PT
- delta
;
13729 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13730 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13731 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13732 /* A glyph beyond the edge of TEXT_AREA which we should never
13734 struct glyph
*glyphs_end
= end
;
13735 /* Non-zero means we've found a match for cursor position, but that
13736 glyph has the avoid_cursor_p flag set. */
13737 int match_with_avoid_cursor
= 0;
13738 /* Non-zero means we've seen at least one glyph that came from a
13740 int string_seen
= 0;
13741 /* Largest and smallest buffer positions seen so far during scan of
13743 ptrdiff_t bpos_max
= pos_before
;
13744 ptrdiff_t bpos_min
= pos_after
;
13745 /* Last buffer position covered by an overlay string with an integer
13746 `cursor' property. */
13747 ptrdiff_t bpos_covered
= 0;
13748 /* Non-zero means the display string on which to display the cursor
13749 comes from a text property, not from an overlay. */
13750 int string_from_text_prop
= 0;
13752 /* Don't even try doing anything if called for a mode-line or
13753 header-line row, since the rest of the code isn't prepared to
13754 deal with such calamities. */
13755 eassert (!row
->mode_line_p
);
13756 if (row
->mode_line_p
)
13759 /* Skip over glyphs not having an object at the start and the end of
13760 the row. These are special glyphs like truncation marks on
13761 terminal frames. */
13762 if (row
->displays_text_p
)
13764 if (!row
->reversed_p
)
13767 && INTEGERP (glyph
->object
)
13768 && glyph
->charpos
< 0)
13770 x
+= glyph
->pixel_width
;
13774 && INTEGERP ((end
- 1)->object
)
13775 /* CHARPOS is zero for blanks and stretch glyphs
13776 inserted by extend_face_to_end_of_line. */
13777 && (end
- 1)->charpos
<= 0)
13779 glyph_before
= glyph
- 1;
13786 /* If the glyph row is reversed, we need to process it from back
13787 to front, so swap the edge pointers. */
13788 glyphs_end
= end
= glyph
- 1;
13789 glyph
+= row
->used
[TEXT_AREA
] - 1;
13791 while (glyph
> end
+ 1
13792 && INTEGERP (glyph
->object
)
13793 && glyph
->charpos
< 0)
13796 x
-= glyph
->pixel_width
;
13798 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13800 /* By default, in reversed rows we put the cursor on the
13801 rightmost (first in the reading order) glyph. */
13802 for (g
= end
+ 1; g
< glyph
; g
++)
13803 x
+= g
->pixel_width
;
13805 && INTEGERP ((end
+ 1)->object
)
13806 && (end
+ 1)->charpos
<= 0)
13808 glyph_before
= glyph
+ 1;
13812 else if (row
->reversed_p
)
13814 /* In R2L rows that don't display text, put the cursor on the
13815 rightmost glyph. Case in point: an empty last line that is
13816 part of an R2L paragraph. */
13818 /* Avoid placing the cursor on the last glyph of the row, where
13819 on terminal frames we hold the vertical border between
13820 adjacent windows. */
13821 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13822 && !WINDOW_RIGHTMOST_P (w
)
13823 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13825 x
= -1; /* will be computed below, at label compute_x */
13828 /* Step 1: Try to find the glyph whose character position
13829 corresponds to point. If that's not possible, find 2 glyphs
13830 whose character positions are the closest to point, one before
13831 point, the other after it. */
13832 if (!row
->reversed_p
)
13833 while (/* not marched to end of glyph row */
13835 /* glyph was not inserted by redisplay for internal purposes */
13836 && !INTEGERP (glyph
->object
))
13838 if (BUFFERP (glyph
->object
))
13840 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13842 if (glyph
->charpos
> bpos_max
)
13843 bpos_max
= glyph
->charpos
;
13844 if (glyph
->charpos
< bpos_min
)
13845 bpos_min
= glyph
->charpos
;
13846 if (!glyph
->avoid_cursor_p
)
13848 /* If we hit point, we've found the glyph on which to
13849 display the cursor. */
13852 match_with_avoid_cursor
= 0;
13855 /* See if we've found a better approximation to
13856 POS_BEFORE or to POS_AFTER. */
13857 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13859 pos_before
= glyph
->charpos
;
13860 glyph_before
= glyph
;
13862 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13864 pos_after
= glyph
->charpos
;
13865 glyph_after
= glyph
;
13868 else if (dpos
== 0)
13869 match_with_avoid_cursor
= 1;
13871 else if (STRINGP (glyph
->object
))
13873 Lisp_Object chprop
;
13874 ptrdiff_t glyph_pos
= glyph
->charpos
;
13876 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13878 if (!NILP (chprop
))
13880 /* If the string came from a `display' text property,
13881 look up the buffer position of that property and
13882 use that position to update bpos_max, as if we
13883 actually saw such a position in one of the row's
13884 glyphs. This helps with supporting integer values
13885 of `cursor' property on the display string in
13886 situations where most or all of the row's buffer
13887 text is completely covered by display properties,
13888 so that no glyph with valid buffer positions is
13889 ever seen in the row. */
13890 ptrdiff_t prop_pos
=
13891 string_buffer_position_lim (glyph
->object
, pos_before
,
13894 if (prop_pos
>= pos_before
)
13895 bpos_max
= prop_pos
- 1;
13897 if (INTEGERP (chprop
))
13899 bpos_covered
= bpos_max
+ XINT (chprop
);
13900 /* If the `cursor' property covers buffer positions up
13901 to and including point, we should display cursor on
13902 this glyph. Note that, if a `cursor' property on one
13903 of the string's characters has an integer value, we
13904 will break out of the loop below _before_ we get to
13905 the position match above. IOW, integer values of
13906 the `cursor' property override the "exact match for
13907 point" strategy of positioning the cursor. */
13908 /* Implementation note: bpos_max == pt_old when, e.g.,
13909 we are in an empty line, where bpos_max is set to
13910 MATRIX_ROW_START_CHARPOS, see above. */
13911 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13920 x
+= glyph
->pixel_width
;
13923 else if (glyph
> end
) /* row is reversed */
13924 while (!INTEGERP (glyph
->object
))
13926 if (BUFFERP (glyph
->object
))
13928 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13930 if (glyph
->charpos
> bpos_max
)
13931 bpos_max
= glyph
->charpos
;
13932 if (glyph
->charpos
< bpos_min
)
13933 bpos_min
= glyph
->charpos
;
13934 if (!glyph
->avoid_cursor_p
)
13938 match_with_avoid_cursor
= 0;
13941 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13943 pos_before
= glyph
->charpos
;
13944 glyph_before
= glyph
;
13946 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13948 pos_after
= glyph
->charpos
;
13949 glyph_after
= glyph
;
13952 else if (dpos
== 0)
13953 match_with_avoid_cursor
= 1;
13955 else if (STRINGP (glyph
->object
))
13957 Lisp_Object chprop
;
13958 ptrdiff_t glyph_pos
= glyph
->charpos
;
13960 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13962 if (!NILP (chprop
))
13964 ptrdiff_t prop_pos
=
13965 string_buffer_position_lim (glyph
->object
, pos_before
,
13968 if (prop_pos
>= pos_before
)
13969 bpos_max
= prop_pos
- 1;
13971 if (INTEGERP (chprop
))
13973 bpos_covered
= bpos_max
+ XINT (chprop
);
13974 /* If the `cursor' property covers buffer positions up
13975 to and including point, we should display cursor on
13977 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13986 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13988 x
--; /* can't use any pixel_width */
13991 x
-= glyph
->pixel_width
;
13994 /* Step 2: If we didn't find an exact match for point, we need to
13995 look for a proper place to put the cursor among glyphs between
13996 GLYPH_BEFORE and GLYPH_AFTER. */
13997 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13998 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13999 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14001 /* An empty line has a single glyph whose OBJECT is zero and
14002 whose CHARPOS is the position of a newline on that line.
14003 Note that on a TTY, there are more glyphs after that, which
14004 were produced by extend_face_to_end_of_line, but their
14005 CHARPOS is zero or negative. */
14007 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14008 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14009 /* On a TTY, continued and truncated rows also have a glyph at
14010 their end whose OBJECT is zero and whose CHARPOS is
14011 positive (the continuation and truncation glyphs), but such
14012 rows are obviously not "empty". */
14013 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14015 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14017 ptrdiff_t ellipsis_pos
;
14019 /* Scan back over the ellipsis glyphs. */
14020 if (!row
->reversed_p
)
14022 ellipsis_pos
= (glyph
- 1)->charpos
;
14023 while (glyph
> row
->glyphs
[TEXT_AREA
]
14024 && (glyph
- 1)->charpos
== ellipsis_pos
)
14025 glyph
--, x
-= glyph
->pixel_width
;
14026 /* That loop always goes one position too far, including
14027 the glyph before the ellipsis. So scan forward over
14029 x
+= glyph
->pixel_width
;
14032 else /* row is reversed */
14034 ellipsis_pos
= (glyph
+ 1)->charpos
;
14035 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14036 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14037 glyph
++, x
+= glyph
->pixel_width
;
14038 x
-= glyph
->pixel_width
;
14042 else if (match_with_avoid_cursor
)
14044 cursor
= glyph_after
;
14047 else if (string_seen
)
14049 int incr
= row
->reversed_p
? -1 : +1;
14051 /* Need to find the glyph that came out of a string which is
14052 present at point. That glyph is somewhere between
14053 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14054 positioned between POS_BEFORE and POS_AFTER in the
14056 struct glyph
*start
, *stop
;
14057 ptrdiff_t pos
= pos_before
;
14061 /* If the row ends in a newline from a display string,
14062 reordering could have moved the glyphs belonging to the
14063 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14064 in this case we extend the search to the last glyph in
14065 the row that was not inserted by redisplay. */
14066 if (row
->ends_in_newline_from_string_p
)
14069 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14072 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14073 correspond to POS_BEFORE and POS_AFTER, respectively. We
14074 need START and STOP in the order that corresponds to the
14075 row's direction as given by its reversed_p flag. If the
14076 directionality of characters between POS_BEFORE and
14077 POS_AFTER is the opposite of the row's base direction,
14078 these characters will have been reordered for display,
14079 and we need to reverse START and STOP. */
14080 if (!row
->reversed_p
)
14082 start
= min (glyph_before
, glyph_after
);
14083 stop
= max (glyph_before
, glyph_after
);
14087 start
= max (glyph_before
, glyph_after
);
14088 stop
= min (glyph_before
, glyph_after
);
14090 for (glyph
= start
+ incr
;
14091 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14094 /* Any glyphs that come from the buffer are here because
14095 of bidi reordering. Skip them, and only pay
14096 attention to glyphs that came from some string. */
14097 if (STRINGP (glyph
->object
))
14101 /* If the display property covers the newline, we
14102 need to search for it one position farther. */
14103 ptrdiff_t lim
= pos_after
14104 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14106 string_from_text_prop
= 0;
14107 str
= glyph
->object
;
14108 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14109 if (tem
== 0 /* from overlay */
14112 /* If the string from which this glyph came is
14113 found in the buffer at point, or at position
14114 that is closer to point than pos_after, then
14115 we've found the glyph we've been looking for.
14116 If it comes from an overlay (tem == 0), and
14117 it has the `cursor' property on one of its
14118 glyphs, record that glyph as a candidate for
14119 displaying the cursor. (As in the
14120 unidirectional version, we will display the
14121 cursor on the last candidate we find.) */
14124 || (tem
- pt_old
> 0 && tem
< pos_after
))
14126 /* The glyphs from this string could have
14127 been reordered. Find the one with the
14128 smallest string position. Or there could
14129 be a character in the string with the
14130 `cursor' property, which means display
14131 cursor on that character's glyph. */
14132 ptrdiff_t strpos
= glyph
->charpos
;
14137 string_from_text_prop
= 1;
14140 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14141 && EQ (glyph
->object
, str
);
14145 ptrdiff_t gpos
= glyph
->charpos
;
14147 cprop
= Fget_char_property (make_number (gpos
),
14155 if (tem
&& glyph
->charpos
< strpos
)
14157 strpos
= glyph
->charpos
;
14163 || (tem
- pt_old
> 0 && tem
< pos_after
))
14167 pos
= tem
+ 1; /* don't find previous instances */
14169 /* This string is not what we want; skip all of the
14170 glyphs that came from it. */
14171 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14172 && EQ (glyph
->object
, str
))
14179 /* If we reached the end of the line, and END was from a string,
14180 the cursor is not on this line. */
14182 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14183 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14184 && STRINGP (end
->object
)
14185 && row
->continued_p
)
14188 /* A truncated row may not include PT among its character positions.
14189 Setting the cursor inside the scroll margin will trigger
14190 recalculation of hscroll in hscroll_window_tree. But if a
14191 display string covers point, defer to the string-handling
14192 code below to figure this out. */
14193 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14195 cursor
= glyph_before
;
14198 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14199 /* Zero-width characters produce no glyphs. */
14201 && (row
->reversed_p
14202 ? glyph_after
> glyphs_end
14203 : glyph_after
< glyphs_end
)))
14205 cursor
= glyph_after
;
14211 if (cursor
!= NULL
)
14213 else if (glyph
== glyphs_end
14214 && pos_before
== pos_after
14215 && STRINGP ((row
->reversed_p
14216 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14217 : row
->glyphs
[TEXT_AREA
])->object
))
14219 /* If all the glyphs of this row came from strings, put the
14220 cursor on the first glyph of the row. This avoids having the
14221 cursor outside of the text area in this very rare and hard
14225 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14226 : row
->glyphs
[TEXT_AREA
];
14232 /* Need to compute x that corresponds to GLYPH. */
14233 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14235 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14237 x
+= g
->pixel_width
;
14241 /* ROW could be part of a continued line, which, under bidi
14242 reordering, might have other rows whose start and end charpos
14243 occlude point. Only set w->cursor if we found a better
14244 approximation to the cursor position than we have from previously
14245 examined candidate rows belonging to the same continued line. */
14246 if (/* we already have a candidate row */
14247 w
->cursor
.vpos
>= 0
14248 /* that candidate is not the row we are processing */
14249 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14250 /* Make sure cursor.vpos specifies a row whose start and end
14251 charpos occlude point, and it is valid candidate for being a
14252 cursor-row. This is because some callers of this function
14253 leave cursor.vpos at the row where the cursor was displayed
14254 during the last redisplay cycle. */
14255 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14256 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14257 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14260 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14262 /* Don't consider glyphs that are outside TEXT_AREA. */
14263 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14265 /* Keep the candidate whose buffer position is the closest to
14266 point or has the `cursor' property. */
14267 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14268 w
->cursor
.hpos
>= 0
14269 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14270 && ((BUFFERP (g1
->object
)
14271 && (g1
->charpos
== pt_old
/* an exact match always wins */
14272 || (BUFFERP (glyph
->object
)
14273 && eabs (g1
->charpos
- pt_old
)
14274 < eabs (glyph
->charpos
- pt_old
))))
14275 /* previous candidate is a glyph from a string that has
14276 a non-nil `cursor' property */
14277 || (STRINGP (g1
->object
)
14278 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14279 Qcursor
, g1
->object
))
14280 /* previous candidate is from the same display
14281 string as this one, and the display string
14282 came from a text property */
14283 || (EQ (g1
->object
, glyph
->object
)
14284 && string_from_text_prop
)
14285 /* this candidate is from newline and its
14286 position is not an exact match */
14287 || (INTEGERP (glyph
->object
)
14288 && glyph
->charpos
!= pt_old
)))))
14290 /* If this candidate gives an exact match, use that. */
14291 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14292 /* If this candidate is a glyph created for the
14293 terminating newline of a line, and point is on that
14294 newline, it wins because it's an exact match. */
14295 || (!row
->continued_p
14296 && INTEGERP (glyph
->object
)
14297 && glyph
->charpos
== 0
14298 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14299 /* Otherwise, keep the candidate that comes from a row
14300 spanning less buffer positions. This may win when one or
14301 both candidate positions are on glyphs that came from
14302 display strings, for which we cannot compare buffer
14304 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14305 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14306 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14309 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14311 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14312 w
->cursor
.y
= row
->y
+ dy
;
14314 if (w
== XWINDOW (selected_window
))
14316 if (!row
->continued_p
14317 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14320 this_line_buffer
= XBUFFER (w
->buffer
);
14322 CHARPOS (this_line_start_pos
)
14323 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14324 BYTEPOS (this_line_start_pos
)
14325 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14327 CHARPOS (this_line_end_pos
)
14328 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14329 BYTEPOS (this_line_end_pos
)
14330 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14332 this_line_y
= w
->cursor
.y
;
14333 this_line_pixel_height
= row
->height
;
14334 this_line_vpos
= w
->cursor
.vpos
;
14335 this_line_start_x
= row
->x
;
14338 CHARPOS (this_line_start_pos
) = 0;
14345 /* Run window scroll functions, if any, for WINDOW with new window
14346 start STARTP. Sets the window start of WINDOW to that position.
14348 We assume that the window's buffer is really current. */
14350 static struct text_pos
14351 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14353 struct window
*w
= XWINDOW (window
);
14354 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14356 if (current_buffer
!= XBUFFER (w
->buffer
))
14359 if (!NILP (Vwindow_scroll_functions
))
14361 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14362 make_number (CHARPOS (startp
)));
14363 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14364 /* In case the hook functions switch buffers. */
14365 set_buffer_internal (XBUFFER (w
->buffer
));
14372 /* Make sure the line containing the cursor is fully visible.
14373 A value of 1 means there is nothing to be done.
14374 (Either the line is fully visible, or it cannot be made so,
14375 or we cannot tell.)
14377 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14378 is higher than window.
14380 A value of 0 means the caller should do scrolling
14381 as if point had gone off the screen. */
14384 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14386 struct glyph_matrix
*matrix
;
14387 struct glyph_row
*row
;
14390 if (!make_cursor_line_fully_visible_p
)
14393 /* It's not always possible to find the cursor, e.g, when a window
14394 is full of overlay strings. Don't do anything in that case. */
14395 if (w
->cursor
.vpos
< 0)
14398 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14399 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14401 /* If the cursor row is not partially visible, there's nothing to do. */
14402 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14405 /* If the row the cursor is in is taller than the window's height,
14406 it's not clear what to do, so do nothing. */
14407 window_height
= window_box_height (w
);
14408 if (row
->height
>= window_height
)
14410 if (!force_p
|| MINI_WINDOW_P (w
)
14411 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14418 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14419 non-zero means only WINDOW is redisplayed in redisplay_internal.
14420 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14421 in redisplay_window to bring a partially visible line into view in
14422 the case that only the cursor has moved.
14424 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14425 last screen line's vertical height extends past the end of the screen.
14429 1 if scrolling succeeded
14431 0 if scrolling didn't find point.
14433 -1 if new fonts have been loaded so that we must interrupt
14434 redisplay, adjust glyph matrices, and try again. */
14440 SCROLLING_NEED_LARGER_MATRICES
14443 /* If scroll-conservatively is more than this, never recenter.
14445 If you change this, don't forget to update the doc string of
14446 `scroll-conservatively' and the Emacs manual. */
14447 #define SCROLL_LIMIT 100
14450 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14451 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14452 int temp_scroll_step
, int last_line_misfit
)
14454 struct window
*w
= XWINDOW (window
);
14455 struct frame
*f
= XFRAME (w
->frame
);
14456 struct text_pos pos
, startp
;
14458 int this_scroll_margin
, scroll_max
, rc
, height
;
14459 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14460 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14461 Lisp_Object aggressive
;
14462 /* We will never try scrolling more than this number of lines. */
14463 int scroll_limit
= SCROLL_LIMIT
;
14466 debug_method_add (w
, "try_scrolling");
14469 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14471 /* Compute scroll margin height in pixels. We scroll when point is
14472 within this distance from the top or bottom of the window. */
14473 if (scroll_margin
> 0)
14474 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14475 * FRAME_LINE_HEIGHT (f
);
14477 this_scroll_margin
= 0;
14479 /* Force arg_scroll_conservatively to have a reasonable value, to
14480 avoid scrolling too far away with slow move_it_* functions. Note
14481 that the user can supply scroll-conservatively equal to
14482 `most-positive-fixnum', which can be larger than INT_MAX. */
14483 if (arg_scroll_conservatively
> scroll_limit
)
14485 arg_scroll_conservatively
= scroll_limit
+ 1;
14486 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14488 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14489 /* Compute how much we should try to scroll maximally to bring
14490 point into view. */
14491 scroll_max
= (max (scroll_step
,
14492 max (arg_scroll_conservatively
, temp_scroll_step
))
14493 * FRAME_LINE_HEIGHT (f
));
14494 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14495 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14496 /* We're trying to scroll because of aggressive scrolling but no
14497 scroll_step is set. Choose an arbitrary one. */
14498 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14504 /* Decide whether to scroll down. */
14505 if (PT
> CHARPOS (startp
))
14507 int scroll_margin_y
;
14509 /* Compute the pixel ypos of the scroll margin, then move IT to
14510 either that ypos or PT, whichever comes first. */
14511 start_display (&it
, w
, startp
);
14512 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14513 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14514 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14515 (MOVE_TO_POS
| MOVE_TO_Y
));
14517 if (PT
> CHARPOS (it
.current
.pos
))
14519 int y0
= line_bottom_y (&it
);
14520 /* Compute how many pixels below window bottom to stop searching
14521 for PT. This avoids costly search for PT that is far away if
14522 the user limited scrolling by a small number of lines, but
14523 always finds PT if scroll_conservatively is set to a large
14524 number, such as most-positive-fixnum. */
14525 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14526 int y_to_move
= it
.last_visible_y
+ slack
;
14528 /* Compute the distance from the scroll margin to PT or to
14529 the scroll limit, whichever comes first. This should
14530 include the height of the cursor line, to make that line
14532 move_it_to (&it
, PT
, -1, y_to_move
,
14533 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14534 dy
= line_bottom_y (&it
) - y0
;
14536 if (dy
> scroll_max
)
14537 return SCROLLING_FAILED
;
14546 /* Point is in or below the bottom scroll margin, so move the
14547 window start down. If scrolling conservatively, move it just
14548 enough down to make point visible. If scroll_step is set,
14549 move it down by scroll_step. */
14550 if (arg_scroll_conservatively
)
14552 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14553 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14554 else if (scroll_step
|| temp_scroll_step
)
14555 amount_to_scroll
= scroll_max
;
14558 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14559 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14560 if (NUMBERP (aggressive
))
14562 double float_amount
= XFLOATINT (aggressive
) * height
;
14563 int aggressive_scroll
= float_amount
;
14564 if (aggressive_scroll
== 0 && float_amount
> 0)
14565 aggressive_scroll
= 1;
14566 /* Don't let point enter the scroll margin near top of
14567 the window. This could happen if the value of
14568 scroll_up_aggressively is too large and there are
14569 non-zero margins, because scroll_up_aggressively
14570 means put point that fraction of window height
14571 _from_the_bottom_margin_. */
14572 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14573 aggressive_scroll
= height
- 2*this_scroll_margin
;
14574 amount_to_scroll
= dy
+ aggressive_scroll
;
14578 if (amount_to_scroll
<= 0)
14579 return SCROLLING_FAILED
;
14581 start_display (&it
, w
, startp
);
14582 if (arg_scroll_conservatively
<= scroll_limit
)
14583 move_it_vertically (&it
, amount_to_scroll
);
14586 /* Extra precision for users who set scroll-conservatively
14587 to a large number: make sure the amount we scroll
14588 the window start is never less than amount_to_scroll,
14589 which was computed as distance from window bottom to
14590 point. This matters when lines at window top and lines
14591 below window bottom have different height. */
14593 void *it1data
= NULL
;
14594 /* We use a temporary it1 because line_bottom_y can modify
14595 its argument, if it moves one line down; see there. */
14598 SAVE_IT (it1
, it
, it1data
);
14599 start_y
= line_bottom_y (&it1
);
14601 RESTORE_IT (&it
, &it
, it1data
);
14602 move_it_by_lines (&it
, 1);
14603 SAVE_IT (it1
, it
, it1data
);
14604 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14607 /* If STARTP is unchanged, move it down another screen line. */
14608 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14609 move_it_by_lines (&it
, 1);
14610 startp
= it
.current
.pos
;
14614 struct text_pos scroll_margin_pos
= startp
;
14616 /* See if point is inside the scroll margin at the top of the
14618 if (this_scroll_margin
)
14620 start_display (&it
, w
, startp
);
14621 move_it_vertically (&it
, this_scroll_margin
);
14622 scroll_margin_pos
= it
.current
.pos
;
14625 if (PT
< CHARPOS (scroll_margin_pos
))
14627 /* Point is in the scroll margin at the top of the window or
14628 above what is displayed in the window. */
14631 /* Compute the vertical distance from PT to the scroll
14632 margin position. Move as far as scroll_max allows, or
14633 one screenful, or 10 screen lines, whichever is largest.
14634 Give up if distance is greater than scroll_max or if we
14635 didn't reach the scroll margin position. */
14636 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14637 start_display (&it
, w
, pos
);
14639 y_to_move
= max (it
.last_visible_y
,
14640 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14641 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14643 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14644 dy
= it
.current_y
- y0
;
14645 if (dy
> scroll_max
14646 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14647 return SCROLLING_FAILED
;
14649 /* Compute new window start. */
14650 start_display (&it
, w
, startp
);
14652 if (arg_scroll_conservatively
)
14653 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14654 max (scroll_step
, temp_scroll_step
));
14655 else if (scroll_step
|| temp_scroll_step
)
14656 amount_to_scroll
= scroll_max
;
14659 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14660 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14661 if (NUMBERP (aggressive
))
14663 double float_amount
= XFLOATINT (aggressive
) * height
;
14664 int aggressive_scroll
= float_amount
;
14665 if (aggressive_scroll
== 0 && float_amount
> 0)
14666 aggressive_scroll
= 1;
14667 /* Don't let point enter the scroll margin near
14668 bottom of the window, if the value of
14669 scroll_down_aggressively happens to be too
14671 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14672 aggressive_scroll
= height
- 2*this_scroll_margin
;
14673 amount_to_scroll
= dy
+ aggressive_scroll
;
14677 if (amount_to_scroll
<= 0)
14678 return SCROLLING_FAILED
;
14680 move_it_vertically_backward (&it
, amount_to_scroll
);
14681 startp
= it
.current
.pos
;
14685 /* Run window scroll functions. */
14686 startp
= run_window_scroll_functions (window
, startp
);
14688 /* Display the window. Give up if new fonts are loaded, or if point
14690 if (!try_window (window
, startp
, 0))
14691 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14692 else if (w
->cursor
.vpos
< 0)
14694 clear_glyph_matrix (w
->desired_matrix
);
14695 rc
= SCROLLING_FAILED
;
14699 /* Maybe forget recorded base line for line number display. */
14700 if (!just_this_one_p
14701 || current_buffer
->clip_changed
14702 || BEG_UNCHANGED
< CHARPOS (startp
))
14703 w
->base_line_number
= 0;
14705 /* If cursor ends up on a partially visible line,
14706 treat that as being off the bottom of the screen. */
14707 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14708 /* It's possible that the cursor is on the first line of the
14709 buffer, which is partially obscured due to a vscroll
14710 (Bug#7537). In that case, avoid looping forever . */
14711 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14713 clear_glyph_matrix (w
->desired_matrix
);
14714 ++extra_scroll_margin_lines
;
14717 rc
= SCROLLING_SUCCESS
;
14724 /* Compute a suitable window start for window W if display of W starts
14725 on a continuation line. Value is non-zero if a new window start
14728 The new window start will be computed, based on W's width, starting
14729 from the start of the continued line. It is the start of the
14730 screen line with the minimum distance from the old start W->start. */
14733 compute_window_start_on_continuation_line (struct window
*w
)
14735 struct text_pos pos
, start_pos
;
14736 int window_start_changed_p
= 0;
14738 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14740 /* If window start is on a continuation line... Window start may be
14741 < BEGV in case there's invisible text at the start of the
14742 buffer (M-x rmail, for example). */
14743 if (CHARPOS (start_pos
) > BEGV
14744 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14747 struct glyph_row
*row
;
14749 /* Handle the case that the window start is out of range. */
14750 if (CHARPOS (start_pos
) < BEGV
)
14751 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14752 else if (CHARPOS (start_pos
) > ZV
)
14753 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14755 /* Find the start of the continued line. This should be fast
14756 because scan_buffer is fast (newline cache). */
14757 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14758 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14759 row
, DEFAULT_FACE_ID
);
14760 reseat_at_previous_visible_line_start (&it
);
14762 /* If the line start is "too far" away from the window start,
14763 say it takes too much time to compute a new window start. */
14764 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14765 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14767 int min_distance
, distance
;
14769 /* Move forward by display lines to find the new window
14770 start. If window width was enlarged, the new start can
14771 be expected to be > the old start. If window width was
14772 decreased, the new window start will be < the old start.
14773 So, we're looking for the display line start with the
14774 minimum distance from the old window start. */
14775 pos
= it
.current
.pos
;
14776 min_distance
= INFINITY
;
14777 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14778 distance
< min_distance
)
14780 min_distance
= distance
;
14781 pos
= it
.current
.pos
;
14782 move_it_by_lines (&it
, 1);
14785 /* Set the window start there. */
14786 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14787 window_start_changed_p
= 1;
14791 return window_start_changed_p
;
14795 /* Try cursor movement in case text has not changed in window WINDOW,
14796 with window start STARTP. Value is
14798 CURSOR_MOVEMENT_SUCCESS if successful
14800 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14802 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14803 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14804 we want to scroll as if scroll-step were set to 1. See the code.
14806 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14807 which case we have to abort this redisplay, and adjust matrices
14812 CURSOR_MOVEMENT_SUCCESS
,
14813 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14814 CURSOR_MOVEMENT_MUST_SCROLL
,
14815 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14819 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14821 struct window
*w
= XWINDOW (window
);
14822 struct frame
*f
= XFRAME (w
->frame
);
14823 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14826 if (inhibit_try_cursor_movement
)
14830 /* Previously, there was a check for Lisp integer in the
14831 if-statement below. Now, this field is converted to
14832 ptrdiff_t, thus zero means invalid position in a buffer. */
14833 eassert (w
->last_point
> 0);
14835 /* Handle case where text has not changed, only point, and it has
14836 not moved off the frame. */
14837 if (/* Point may be in this window. */
14838 PT
>= CHARPOS (startp
)
14839 /* Selective display hasn't changed. */
14840 && !current_buffer
->clip_changed
14841 /* Function force-mode-line-update is used to force a thorough
14842 redisplay. It sets either windows_or_buffers_changed or
14843 update_mode_lines. So don't take a shortcut here for these
14845 && !update_mode_lines
14846 && !windows_or_buffers_changed
14847 && !cursor_type_changed
14848 /* Can't use this case if highlighting a region. When a
14849 region exists, cursor movement has to do more than just
14851 && markpos_of_region () < 0
14852 && !w
->region_showing
14853 && NILP (Vshow_trailing_whitespace
)
14854 /* This code is not used for mini-buffer for the sake of the case
14855 of redisplaying to replace an echo area message; since in
14856 that case the mini-buffer contents per se are usually
14857 unchanged. This code is of no real use in the mini-buffer
14858 since the handling of this_line_start_pos, etc., in redisplay
14859 handles the same cases. */
14860 && !EQ (window
, minibuf_window
)
14861 /* When splitting windows or for new windows, it happens that
14862 redisplay is called with a nil window_end_vpos or one being
14863 larger than the window. This should really be fixed in
14864 window.c. I don't have this on my list, now, so we do
14865 approximately the same as the old redisplay code. --gerd. */
14866 && INTEGERP (w
->window_end_vpos
)
14867 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14868 && (FRAME_WINDOW_P (f
)
14869 || !overlay_arrow_in_current_buffer_p ()))
14871 int this_scroll_margin
, top_scroll_margin
;
14872 struct glyph_row
*row
= NULL
;
14875 debug_method_add (w
, "cursor movement");
14878 /* Scroll if point within this distance from the top or bottom
14879 of the window. This is a pixel value. */
14880 if (scroll_margin
> 0)
14882 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14883 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14886 this_scroll_margin
= 0;
14888 top_scroll_margin
= this_scroll_margin
;
14889 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14890 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14892 /* Start with the row the cursor was displayed during the last
14893 not paused redisplay. Give up if that row is not valid. */
14894 if (w
->last_cursor
.vpos
< 0
14895 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14896 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14899 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14900 if (row
->mode_line_p
)
14902 if (!row
->enabled_p
)
14903 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14906 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14908 int scroll_p
= 0, must_scroll
= 0;
14909 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14911 if (PT
> w
->last_point
)
14913 /* Point has moved forward. */
14914 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14915 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14917 eassert (row
->enabled_p
);
14921 /* If the end position of a row equals the start
14922 position of the next row, and PT is at that position,
14923 we would rather display cursor in the next line. */
14924 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14925 && MATRIX_ROW_END_CHARPOS (row
) == PT
14926 && row
< w
->current_matrix
->rows
14927 + w
->current_matrix
->nrows
- 1
14928 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14929 && !cursor_row_p (row
))
14932 /* If within the scroll margin, scroll. Note that
14933 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14934 the next line would be drawn, and that
14935 this_scroll_margin can be zero. */
14936 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14937 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14938 /* Line is completely visible last line in window
14939 and PT is to be set in the next line. */
14940 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14941 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14942 && !row
->ends_at_zv_p
14943 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14946 else if (PT
< w
->last_point
)
14948 /* Cursor has to be moved backward. Note that PT >=
14949 CHARPOS (startp) because of the outer if-statement. */
14950 while (!row
->mode_line_p
14951 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14952 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14953 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14954 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14955 row
> w
->current_matrix
->rows
14956 && (row
-1)->ends_in_newline_from_string_p
))))
14957 && (row
->y
> top_scroll_margin
14958 || CHARPOS (startp
) == BEGV
))
14960 eassert (row
->enabled_p
);
14964 /* Consider the following case: Window starts at BEGV,
14965 there is invisible, intangible text at BEGV, so that
14966 display starts at some point START > BEGV. It can
14967 happen that we are called with PT somewhere between
14968 BEGV and START. Try to handle that case. */
14969 if (row
< w
->current_matrix
->rows
14970 || row
->mode_line_p
)
14972 row
= w
->current_matrix
->rows
;
14973 if (row
->mode_line_p
)
14977 /* Due to newlines in overlay strings, we may have to
14978 skip forward over overlay strings. */
14979 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14980 && MATRIX_ROW_END_CHARPOS (row
) == PT
14981 && !cursor_row_p (row
))
14984 /* If within the scroll margin, scroll. */
14985 if (row
->y
< top_scroll_margin
14986 && CHARPOS (startp
) != BEGV
)
14991 /* Cursor did not move. So don't scroll even if cursor line
14992 is partially visible, as it was so before. */
14993 rc
= CURSOR_MOVEMENT_SUCCESS
;
14996 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14997 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14999 /* if PT is not in the glyph row, give up. */
15000 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15003 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15004 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15006 struct glyph_row
*row1
;
15008 /* If rows are bidi-reordered and point moved, back up
15009 until we find a row that does not belong to a
15010 continuation line. This is because we must consider
15011 all rows of a continued line as candidates for the
15012 new cursor positioning, since row start and end
15013 positions change non-linearly with vertical position
15015 /* FIXME: Revisit this when glyph ``spilling'' in
15016 continuation lines' rows is implemented for
15017 bidi-reordered rows. */
15018 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15019 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15022 /* If we hit the beginning of the displayed portion
15023 without finding the first row of a continued
15027 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15030 eassert (row
->enabled_p
);
15035 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15036 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15037 /* Make sure this isn't a header line by any chance, since
15038 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15039 && !row
->mode_line_p
15040 && make_cursor_line_fully_visible_p
)
15042 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15043 && !row
->ends_at_zv_p
15044 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15045 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15046 else if (row
->height
> window_box_height (w
))
15048 /* If we end up in a partially visible line, let's
15049 make it fully visible, except when it's taller
15050 than the window, in which case we can't do much
15053 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15057 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15058 if (!cursor_row_fully_visible_p (w
, 0, 1))
15059 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15061 rc
= CURSOR_MOVEMENT_SUCCESS
;
15065 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15066 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15067 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15069 /* With bidi-reordered rows, there could be more than
15070 one candidate row whose start and end positions
15071 occlude point. We need to let set_cursor_from_row
15072 find the best candidate. */
15073 /* FIXME: Revisit this when glyph ``spilling'' in
15074 continuation lines' rows is implemented for
15075 bidi-reordered rows. */
15080 int at_zv_p
= 0, exact_match_p
= 0;
15082 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15083 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15084 && cursor_row_p (row
))
15085 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15087 /* As soon as we've found the exact match for point,
15088 or the first suitable row whose ends_at_zv_p flag
15089 is set, we are done. */
15091 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15093 && w
->cursor
.hpos
>= 0
15094 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15097 struct glyph_row
*candidate
=
15098 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15100 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15101 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15104 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15105 || (INTEGERP (g
->object
)
15106 && (g
->charpos
== PT
15107 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15109 if (rv
&& (at_zv_p
|| exact_match_p
))
15111 rc
= CURSOR_MOVEMENT_SUCCESS
;
15114 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15118 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15119 || row
->continued_p
)
15120 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15121 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15122 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15123 /* If we didn't find any candidate rows, or exited the
15124 loop before all the candidates were examined, signal
15125 to the caller that this method failed. */
15126 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15128 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15129 && !row
->continued_p
))
15130 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15132 rc
= CURSOR_MOVEMENT_SUCCESS
;
15138 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15140 rc
= CURSOR_MOVEMENT_SUCCESS
;
15145 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15146 && MATRIX_ROW_START_CHARPOS (row
) == PT
15147 && cursor_row_p (row
));
15155 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15159 set_vertical_scroll_bar (struct window
*w
)
15161 ptrdiff_t start
, end
, whole
;
15163 /* Calculate the start and end positions for the current window.
15164 At some point, it would be nice to choose between scrollbars
15165 which reflect the whole buffer size, with special markers
15166 indicating narrowing, and scrollbars which reflect only the
15169 Note that mini-buffers sometimes aren't displaying any text. */
15170 if (!MINI_WINDOW_P (w
)
15171 || (w
== XWINDOW (minibuf_window
)
15172 && NILP (echo_area_buffer
[0])))
15174 struct buffer
*buf
= XBUFFER (w
->buffer
);
15175 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15176 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15177 /* I don't think this is guaranteed to be right. For the
15178 moment, we'll pretend it is. */
15179 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15183 if (whole
< (end
- start
))
15184 whole
= end
- start
;
15187 start
= end
= whole
= 0;
15189 /* Indicate what this scroll bar ought to be displaying now. */
15190 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15191 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15192 (w
, end
- start
, whole
, start
);
15196 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15197 selected_window is redisplayed.
15199 We can return without actually redisplaying the window if
15200 fonts_changed_p. In that case, redisplay_internal will
15204 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15206 struct window
*w
= XWINDOW (window
);
15207 struct frame
*f
= XFRAME (w
->frame
);
15208 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15209 struct buffer
*old
= current_buffer
;
15210 struct text_pos lpoint
, opoint
, startp
;
15211 int update_mode_line
;
15214 /* Record it now because it's overwritten. */
15215 int current_matrix_up_to_date_p
= 0;
15216 int used_current_matrix_p
= 0;
15217 /* This is less strict than current_matrix_up_to_date_p.
15218 It indicates that the buffer contents and narrowing are unchanged. */
15219 int buffer_unchanged_p
= 0;
15220 int temp_scroll_step
= 0;
15221 ptrdiff_t count
= SPECPDL_INDEX ();
15223 int centering_position
= -1;
15224 int last_line_misfit
= 0;
15225 ptrdiff_t beg_unchanged
, end_unchanged
;
15227 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15230 /* W must be a leaf window here. */
15231 eassert (!NILP (w
->buffer
));
15233 *w
->desired_matrix
->method
= 0;
15237 reconsider_clip_changes (w
, buffer
);
15239 /* Has the mode line to be updated? */
15240 update_mode_line
= (w
->update_mode_line
15241 || update_mode_lines
15242 || buffer
->clip_changed
15243 || buffer
->prevent_redisplay_optimizations_p
);
15245 if (MINI_WINDOW_P (w
))
15247 if (w
== XWINDOW (echo_area_window
)
15248 && !NILP (echo_area_buffer
[0]))
15250 if (update_mode_line
)
15251 /* We may have to update a tty frame's menu bar or a
15252 tool-bar. Example `M-x C-h C-h C-g'. */
15253 goto finish_menu_bars
;
15255 /* We've already displayed the echo area glyphs in this window. */
15256 goto finish_scroll_bars
;
15258 else if ((w
!= XWINDOW (minibuf_window
)
15259 || minibuf_level
== 0)
15260 /* When buffer is nonempty, redisplay window normally. */
15261 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15262 /* Quail displays non-mini buffers in minibuffer window.
15263 In that case, redisplay the window normally. */
15264 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15266 /* W is a mini-buffer window, but it's not active, so clear
15268 int yb
= window_text_bottom_y (w
);
15269 struct glyph_row
*row
;
15272 for (y
= 0, row
= w
->desired_matrix
->rows
;
15274 y
+= row
->height
, ++row
)
15275 blank_row (w
, row
, y
);
15276 goto finish_scroll_bars
;
15279 clear_glyph_matrix (w
->desired_matrix
);
15282 /* Otherwise set up data on this window; select its buffer and point
15284 /* Really select the buffer, for the sake of buffer-local
15286 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15288 current_matrix_up_to_date_p
15289 = (w
->window_end_valid
15290 && !current_buffer
->clip_changed
15291 && !current_buffer
->prevent_redisplay_optimizations_p
15292 && !window_outdated (w
));
15294 /* Run the window-bottom-change-functions
15295 if it is possible that the text on the screen has changed
15296 (either due to modification of the text, or any other reason). */
15297 if (!current_matrix_up_to_date_p
15298 && !NILP (Vwindow_text_change_functions
))
15300 safe_run_hooks (Qwindow_text_change_functions
);
15304 beg_unchanged
= BEG_UNCHANGED
;
15305 end_unchanged
= END_UNCHANGED
;
15307 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15309 specbind (Qinhibit_point_motion_hooks
, Qt
);
15312 = (w
->window_end_valid
15313 && !current_buffer
->clip_changed
15314 && !window_outdated (w
));
15316 /* When windows_or_buffers_changed is non-zero, we can't rely on
15317 the window end being valid, so set it to nil there. */
15318 if (windows_or_buffers_changed
)
15320 /* If window starts on a continuation line, maybe adjust the
15321 window start in case the window's width changed. */
15322 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15323 compute_window_start_on_continuation_line (w
);
15325 w
->window_end_valid
= 0;
15328 /* Some sanity checks. */
15329 CHECK_WINDOW_END (w
);
15330 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15332 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15335 if (mode_line_update_needed (w
))
15336 update_mode_line
= 1;
15338 /* Point refers normally to the selected window. For any other
15339 window, set up appropriate value. */
15340 if (!EQ (window
, selected_window
))
15342 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15343 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15347 new_pt_byte
= BEGV_BYTE
;
15348 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15350 else if (new_pt
> (ZV
- 1))
15353 new_pt_byte
= ZV_BYTE
;
15354 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15357 /* We don't use SET_PT so that the point-motion hooks don't run. */
15358 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15361 /* If any of the character widths specified in the display table
15362 have changed, invalidate the width run cache. It's true that
15363 this may be a bit late to catch such changes, but the rest of
15364 redisplay goes (non-fatally) haywire when the display table is
15365 changed, so why should we worry about doing any better? */
15366 if (current_buffer
->width_run_cache
)
15368 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15370 if (! disptab_matches_widthtab
15371 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15373 invalidate_region_cache (current_buffer
,
15374 current_buffer
->width_run_cache
,
15376 recompute_width_table (current_buffer
, disptab
);
15380 /* If window-start is screwed up, choose a new one. */
15381 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15384 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15386 /* If someone specified a new starting point but did not insist,
15387 check whether it can be used. */
15388 if (w
->optional_new_start
15389 && CHARPOS (startp
) >= BEGV
15390 && CHARPOS (startp
) <= ZV
)
15392 w
->optional_new_start
= 0;
15393 start_display (&it
, w
, startp
);
15394 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15395 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15396 if (IT_CHARPOS (it
) == PT
)
15397 w
->force_start
= 1;
15398 /* IT may overshoot PT if text at PT is invisible. */
15399 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15400 w
->force_start
= 1;
15405 /* Handle case where place to start displaying has been specified,
15406 unless the specified location is outside the accessible range. */
15407 if (w
->force_start
|| w
->frozen_window_start_p
)
15409 /* We set this later on if we have to adjust point. */
15412 w
->force_start
= 0;
15414 w
->window_end_valid
= 0;
15416 /* Forget any recorded base line for line number display. */
15417 if (!buffer_unchanged_p
)
15418 w
->base_line_number
= 0;
15420 /* Redisplay the mode line. Select the buffer properly for that.
15421 Also, run the hook window-scroll-functions
15422 because we have scrolled. */
15423 /* Note, we do this after clearing force_start because
15424 if there's an error, it is better to forget about force_start
15425 than to get into an infinite loop calling the hook functions
15426 and having them get more errors. */
15427 if (!update_mode_line
15428 || ! NILP (Vwindow_scroll_functions
))
15430 update_mode_line
= 1;
15431 w
->update_mode_line
= 1;
15432 startp
= run_window_scroll_functions (window
, startp
);
15435 w
->last_modified
= 0;
15436 w
->last_overlay_modified
= 0;
15437 if (CHARPOS (startp
) < BEGV
)
15438 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15439 else if (CHARPOS (startp
) > ZV
)
15440 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15442 /* Redisplay, then check if cursor has been set during the
15443 redisplay. Give up if new fonts were loaded. */
15444 /* We used to issue a CHECK_MARGINS argument to try_window here,
15445 but this causes scrolling to fail when point begins inside
15446 the scroll margin (bug#148) -- cyd */
15447 if (!try_window (window
, startp
, 0))
15449 w
->force_start
= 1;
15450 clear_glyph_matrix (w
->desired_matrix
);
15451 goto need_larger_matrices
;
15454 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15456 /* If point does not appear, try to move point so it does
15457 appear. The desired matrix has been built above, so we
15458 can use it here. */
15459 new_vpos
= window_box_height (w
) / 2;
15462 if (!cursor_row_fully_visible_p (w
, 0, 0))
15464 /* Point does appear, but on a line partly visible at end of window.
15465 Move it back to a fully-visible line. */
15466 new_vpos
= window_box_height (w
);
15468 else if (w
->cursor
.vpos
>=0)
15470 /* Some people insist on not letting point enter the scroll
15471 margin, even though this part handles windows that didn't
15473 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15474 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15475 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15477 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15478 below, which finds the row to move point to, advances by
15479 the Y coordinate of the _next_ row, see the definition of
15480 MATRIX_ROW_BOTTOM_Y. */
15481 if (w
->cursor
.vpos
< margin
+ header_line
)
15483 = pixel_margin
+ (header_line
15484 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15485 : 0) + FRAME_LINE_HEIGHT (f
);
15488 int window_height
= window_box_height (w
);
15491 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15492 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15493 new_vpos
= window_height
- pixel_margin
;
15497 /* If we need to move point for either of the above reasons,
15498 now actually do it. */
15501 struct glyph_row
*row
;
15503 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15504 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15507 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15508 MATRIX_ROW_START_BYTEPOS (row
));
15510 if (w
!= XWINDOW (selected_window
))
15511 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15512 else if (current_buffer
== old
)
15513 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15515 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15517 /* If we are highlighting the region, then we just changed
15518 the region, so redisplay to show it. */
15519 if (0 <= markpos_of_region ())
15521 clear_glyph_matrix (w
->desired_matrix
);
15522 if (!try_window (window
, startp
, 0))
15523 goto need_larger_matrices
;
15528 debug_method_add (w
, "forced window start");
15533 /* Handle case where text has not changed, only point, and it has
15534 not moved off the frame, and we are not retrying after hscroll.
15535 (current_matrix_up_to_date_p is nonzero when retrying.) */
15536 if (current_matrix_up_to_date_p
15537 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15538 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15542 case CURSOR_MOVEMENT_SUCCESS
:
15543 used_current_matrix_p
= 1;
15546 case CURSOR_MOVEMENT_MUST_SCROLL
:
15547 goto try_to_scroll
;
15553 /* If current starting point was originally the beginning of a line
15554 but no longer is, find a new starting point. */
15555 else if (w
->start_at_line_beg
15556 && !(CHARPOS (startp
) <= BEGV
15557 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15560 debug_method_add (w
, "recenter 1");
15565 /* Try scrolling with try_window_id. Value is > 0 if update has
15566 been done, it is -1 if we know that the same window start will
15567 not work. It is 0 if unsuccessful for some other reason. */
15568 else if ((tem
= try_window_id (w
)) != 0)
15571 debug_method_add (w
, "try_window_id %d", tem
);
15574 if (fonts_changed_p
)
15575 goto need_larger_matrices
;
15579 /* Otherwise try_window_id has returned -1 which means that we
15580 don't want the alternative below this comment to execute. */
15582 else if (CHARPOS (startp
) >= BEGV
15583 && CHARPOS (startp
) <= ZV
15584 && PT
>= CHARPOS (startp
)
15585 && (CHARPOS (startp
) < ZV
15586 /* Avoid starting at end of buffer. */
15587 || CHARPOS (startp
) == BEGV
15588 || !window_outdated (w
)))
15590 int d1
, d2
, d3
, d4
, d5
, d6
;
15592 /* If first window line is a continuation line, and window start
15593 is inside the modified region, but the first change is before
15594 current window start, we must select a new window start.
15596 However, if this is the result of a down-mouse event (e.g. by
15597 extending the mouse-drag-overlay), we don't want to select a
15598 new window start, since that would change the position under
15599 the mouse, resulting in an unwanted mouse-movement rather
15600 than a simple mouse-click. */
15601 if (!w
->start_at_line_beg
15602 && NILP (do_mouse_tracking
)
15603 && CHARPOS (startp
) > BEGV
15604 && CHARPOS (startp
) > BEG
+ beg_unchanged
15605 && CHARPOS (startp
) <= Z
- end_unchanged
15606 /* Even if w->start_at_line_beg is nil, a new window may
15607 start at a line_beg, since that's how set_buffer_window
15608 sets it. So, we need to check the return value of
15609 compute_window_start_on_continuation_line. (See also
15611 && XMARKER (w
->start
)->buffer
== current_buffer
15612 && compute_window_start_on_continuation_line (w
)
15613 /* It doesn't make sense to force the window start like we
15614 do at label force_start if it is already known that point
15615 will not be visible in the resulting window, because
15616 doing so will move point from its correct position
15617 instead of scrolling the window to bring point into view.
15619 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15621 w
->force_start
= 1;
15622 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15627 debug_method_add (w
, "same window start");
15630 /* Try to redisplay starting at same place as before.
15631 If point has not moved off frame, accept the results. */
15632 if (!current_matrix_up_to_date_p
15633 /* Don't use try_window_reusing_current_matrix in this case
15634 because a window scroll function can have changed the
15636 || !NILP (Vwindow_scroll_functions
)
15637 || MINI_WINDOW_P (w
)
15638 || !(used_current_matrix_p
15639 = try_window_reusing_current_matrix (w
)))
15641 IF_DEBUG (debug_method_add (w
, "1"));
15642 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15643 /* -1 means we need to scroll.
15644 0 means we need new matrices, but fonts_changed_p
15645 is set in that case, so we will detect it below. */
15646 goto try_to_scroll
;
15649 if (fonts_changed_p
)
15650 goto need_larger_matrices
;
15652 if (w
->cursor
.vpos
>= 0)
15654 if (!just_this_one_p
15655 || current_buffer
->clip_changed
15656 || BEG_UNCHANGED
< CHARPOS (startp
))
15657 /* Forget any recorded base line for line number display. */
15658 w
->base_line_number
= 0;
15660 if (!cursor_row_fully_visible_p (w
, 1, 0))
15662 clear_glyph_matrix (w
->desired_matrix
);
15663 last_line_misfit
= 1;
15665 /* Drop through and scroll. */
15670 clear_glyph_matrix (w
->desired_matrix
);
15675 w
->last_modified
= 0;
15676 w
->last_overlay_modified
= 0;
15678 /* Redisplay the mode line. Select the buffer properly for that. */
15679 if (!update_mode_line
)
15681 update_mode_line
= 1;
15682 w
->update_mode_line
= 1;
15685 /* Try to scroll by specified few lines. */
15686 if ((scroll_conservatively
15687 || emacs_scroll_step
15688 || temp_scroll_step
15689 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15690 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15691 && CHARPOS (startp
) >= BEGV
15692 && CHARPOS (startp
) <= ZV
)
15694 /* The function returns -1 if new fonts were loaded, 1 if
15695 successful, 0 if not successful. */
15696 int ss
= try_scrolling (window
, just_this_one_p
,
15697 scroll_conservatively
,
15699 temp_scroll_step
, last_line_misfit
);
15702 case SCROLLING_SUCCESS
:
15705 case SCROLLING_NEED_LARGER_MATRICES
:
15706 goto need_larger_matrices
;
15708 case SCROLLING_FAILED
:
15716 /* Finally, just choose a place to start which positions point
15717 according to user preferences. */
15722 debug_method_add (w
, "recenter");
15725 /* Forget any previously recorded base line for line number display. */
15726 if (!buffer_unchanged_p
)
15727 w
->base_line_number
= 0;
15729 /* Determine the window start relative to point. */
15730 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15731 it
.current_y
= it
.last_visible_y
;
15732 if (centering_position
< 0)
15736 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15738 ptrdiff_t margin_pos
= CHARPOS (startp
);
15739 Lisp_Object aggressive
;
15742 /* If there is a scroll margin at the top of the window, find
15743 its character position. */
15745 /* Cannot call start_display if startp is not in the
15746 accessible region of the buffer. This can happen when we
15747 have just switched to a different buffer and/or changed
15748 its restriction. In that case, startp is initialized to
15749 the character position 1 (BEGV) because we did not yet
15750 have chance to display the buffer even once. */
15751 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15754 void *it1data
= NULL
;
15756 SAVE_IT (it1
, it
, it1data
);
15757 start_display (&it1
, w
, startp
);
15758 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15759 margin_pos
= IT_CHARPOS (it1
);
15760 RESTORE_IT (&it
, &it
, it1data
);
15762 scrolling_up
= PT
> margin_pos
;
15765 ? BVAR (current_buffer
, scroll_up_aggressively
)
15766 : BVAR (current_buffer
, scroll_down_aggressively
);
15768 if (!MINI_WINDOW_P (w
)
15769 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15773 /* Setting scroll-conservatively overrides
15774 scroll-*-aggressively. */
15775 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15777 double float_amount
= XFLOATINT (aggressive
);
15779 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15780 if (pt_offset
== 0 && float_amount
> 0)
15782 if (pt_offset
&& margin
> 0)
15785 /* Compute how much to move the window start backward from
15786 point so that point will be displayed where the user
15790 centering_position
= it
.last_visible_y
;
15792 centering_position
-= pt_offset
;
15793 centering_position
-=
15794 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15795 + WINDOW_HEADER_LINE_HEIGHT (w
);
15796 /* Don't let point enter the scroll margin near top of
15798 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15799 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15802 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15805 /* Set the window start half the height of the window backward
15807 centering_position
= window_box_height (w
) / 2;
15809 move_it_vertically_backward (&it
, centering_position
);
15811 eassert (IT_CHARPOS (it
) >= BEGV
);
15813 /* The function move_it_vertically_backward may move over more
15814 than the specified y-distance. If it->w is small, e.g. a
15815 mini-buffer window, we may end up in front of the window's
15816 display area. Start displaying at the start of the line
15817 containing PT in this case. */
15818 if (it
.current_y
<= 0)
15820 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15821 move_it_vertically_backward (&it
, 0);
15825 it
.current_x
= it
.hpos
= 0;
15827 /* Set the window start position here explicitly, to avoid an
15828 infinite loop in case the functions in window-scroll-functions
15830 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15832 /* Run scroll hooks. */
15833 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15835 /* Redisplay the window. */
15836 if (!current_matrix_up_to_date_p
15837 || windows_or_buffers_changed
15838 || cursor_type_changed
15839 /* Don't use try_window_reusing_current_matrix in this case
15840 because it can have changed the buffer. */
15841 || !NILP (Vwindow_scroll_functions
)
15842 || !just_this_one_p
15843 || MINI_WINDOW_P (w
)
15844 || !(used_current_matrix_p
15845 = try_window_reusing_current_matrix (w
)))
15846 try_window (window
, startp
, 0);
15848 /* If new fonts have been loaded (due to fontsets), give up. We
15849 have to start a new redisplay since we need to re-adjust glyph
15851 if (fonts_changed_p
)
15852 goto need_larger_matrices
;
15854 /* If cursor did not appear assume that the middle of the window is
15855 in the first line of the window. Do it again with the next line.
15856 (Imagine a window of height 100, displaying two lines of height
15857 60. Moving back 50 from it->last_visible_y will end in the first
15859 if (w
->cursor
.vpos
< 0)
15861 if (w
->window_end_valid
&& PT
>= Z
- XFASTINT (w
->window_end_pos
))
15863 clear_glyph_matrix (w
->desired_matrix
);
15864 move_it_by_lines (&it
, 1);
15865 try_window (window
, it
.current
.pos
, 0);
15867 else if (PT
< IT_CHARPOS (it
))
15869 clear_glyph_matrix (w
->desired_matrix
);
15870 move_it_by_lines (&it
, -1);
15871 try_window (window
, it
.current
.pos
, 0);
15875 /* Not much we can do about it. */
15879 /* Consider the following case: Window starts at BEGV, there is
15880 invisible, intangible text at BEGV, so that display starts at
15881 some point START > BEGV. It can happen that we are called with
15882 PT somewhere between BEGV and START. Try to handle that case. */
15883 if (w
->cursor
.vpos
< 0)
15885 struct glyph_row
*row
= w
->current_matrix
->rows
;
15886 if (row
->mode_line_p
)
15888 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15891 if (!cursor_row_fully_visible_p (w
, 0, 0))
15893 /* If vscroll is enabled, disable it and try again. */
15897 clear_glyph_matrix (w
->desired_matrix
);
15901 /* Users who set scroll-conservatively to a large number want
15902 point just above/below the scroll margin. If we ended up
15903 with point's row partially visible, move the window start to
15904 make that row fully visible and out of the margin. */
15905 if (scroll_conservatively
> SCROLL_LIMIT
)
15909 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15911 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15913 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15914 clear_glyph_matrix (w
->desired_matrix
);
15915 if (1 == try_window (window
, it
.current
.pos
,
15916 TRY_WINDOW_CHECK_MARGINS
))
15920 /* If centering point failed to make the whole line visible,
15921 put point at the top instead. That has to make the whole line
15922 visible, if it can be done. */
15923 if (centering_position
== 0)
15926 clear_glyph_matrix (w
->desired_matrix
);
15927 centering_position
= 0;
15933 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15934 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
15935 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
15937 /* Display the mode line, if we must. */
15938 if ((update_mode_line
15939 /* If window not full width, must redo its mode line
15940 if (a) the window to its side is being redone and
15941 (b) we do a frame-based redisplay. This is a consequence
15942 of how inverted lines are drawn in frame-based redisplay. */
15943 || (!just_this_one_p
15944 && !FRAME_WINDOW_P (f
)
15945 && !WINDOW_FULL_WIDTH_P (w
))
15946 /* Line number to display. */
15947 || w
->base_line_pos
> 0
15948 /* Column number is displayed and different from the one displayed. */
15949 || (w
->column_number_displayed
!= -1
15950 && (w
->column_number_displayed
!= current_column ())))
15951 /* This means that the window has a mode line. */
15952 && (WINDOW_WANTS_MODELINE_P (w
)
15953 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15955 display_mode_lines (w
);
15957 /* If mode line height has changed, arrange for a thorough
15958 immediate redisplay using the correct mode line height. */
15959 if (WINDOW_WANTS_MODELINE_P (w
)
15960 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15962 fonts_changed_p
= 1;
15963 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15964 = DESIRED_MODE_LINE_HEIGHT (w
);
15967 /* If header line height has changed, arrange for a thorough
15968 immediate redisplay using the correct header line height. */
15969 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15970 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15972 fonts_changed_p
= 1;
15973 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15974 = DESIRED_HEADER_LINE_HEIGHT (w
);
15977 if (fonts_changed_p
)
15978 goto need_larger_matrices
;
15981 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
15983 w
->base_line_pos
= 0;
15984 w
->base_line_number
= 0;
15989 /* When we reach a frame's selected window, redo the frame's menu bar. */
15990 if (update_mode_line
15991 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15993 int redisplay_menu_p
= 0;
15995 if (FRAME_WINDOW_P (f
))
15997 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15998 || defined (HAVE_NS) || defined (USE_GTK)
15999 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16001 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16005 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16007 if (redisplay_menu_p
)
16008 display_menu_bar (w
);
16010 #ifdef HAVE_WINDOW_SYSTEM
16011 if (FRAME_WINDOW_P (f
))
16013 #if defined (USE_GTK) || defined (HAVE_NS)
16014 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16015 redisplay_tool_bar (f
);
16017 if (WINDOWP (f
->tool_bar_window
)
16018 && (FRAME_TOOL_BAR_LINES (f
) > 0
16019 || !NILP (Vauto_resize_tool_bars
))
16020 && redisplay_tool_bar (f
))
16021 ignore_mouse_drag_p
= 1;
16027 #ifdef HAVE_WINDOW_SYSTEM
16028 if (FRAME_WINDOW_P (f
)
16029 && update_window_fringes (w
, (just_this_one_p
16030 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16031 || w
->pseudo_window_p
)))
16035 if (draw_window_fringes (w
, 1))
16036 x_draw_vertical_border (w
);
16040 #endif /* HAVE_WINDOW_SYSTEM */
16042 /* We go to this label, with fonts_changed_p set,
16043 if it is necessary to try again using larger glyph matrices.
16044 We have to redeem the scroll bar even in this case,
16045 because the loop in redisplay_internal expects that. */
16046 need_larger_matrices
:
16048 finish_scroll_bars
:
16050 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16052 /* Set the thumb's position and size. */
16053 set_vertical_scroll_bar (w
);
16055 /* Note that we actually used the scroll bar attached to this
16056 window, so it shouldn't be deleted at the end of redisplay. */
16057 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16058 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16061 /* Restore current_buffer and value of point in it. The window
16062 update may have changed the buffer, so first make sure `opoint'
16063 is still valid (Bug#6177). */
16064 if (CHARPOS (opoint
) < BEGV
)
16065 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16066 else if (CHARPOS (opoint
) > ZV
)
16067 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16069 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16071 set_buffer_internal_1 (old
);
16072 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16073 shorter. This can be caused by log truncation in *Messages*. */
16074 if (CHARPOS (lpoint
) <= ZV
)
16075 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16077 unbind_to (count
, Qnil
);
16081 /* Build the complete desired matrix of WINDOW with a window start
16082 buffer position POS.
16084 Value is 1 if successful. It is zero if fonts were loaded during
16085 redisplay which makes re-adjusting glyph matrices necessary, and -1
16086 if point would appear in the scroll margins.
16087 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16088 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16092 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16094 struct window
*w
= XWINDOW (window
);
16096 struct glyph_row
*last_text_row
= NULL
;
16097 struct frame
*f
= XFRAME (w
->frame
);
16099 /* Make POS the new window start. */
16100 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16102 /* Mark cursor position as unknown. No overlay arrow seen. */
16103 w
->cursor
.vpos
= -1;
16104 overlay_arrow_seen
= 0;
16106 /* Initialize iterator and info to start at POS. */
16107 start_display (&it
, w
, pos
);
16109 /* Display all lines of W. */
16110 while (it
.current_y
< it
.last_visible_y
)
16112 if (display_line (&it
))
16113 last_text_row
= it
.glyph_row
- 1;
16114 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16118 /* Don't let the cursor end in the scroll margins. */
16119 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16120 && !MINI_WINDOW_P (w
))
16122 int this_scroll_margin
;
16124 if (scroll_margin
> 0)
16126 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16127 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16130 this_scroll_margin
= 0;
16132 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16133 && w
->cursor
.y
< this_scroll_margin
16134 && CHARPOS (pos
) > BEGV
16135 && IT_CHARPOS (it
) < ZV
)
16136 /* rms: considering make_cursor_line_fully_visible_p here
16137 seems to give wrong results. We don't want to recenter
16138 when the last line is partly visible, we want to allow
16139 that case to be handled in the usual way. */
16140 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16142 w
->cursor
.vpos
= -1;
16143 clear_glyph_matrix (w
->desired_matrix
);
16148 /* If bottom moved off end of frame, change mode line percentage. */
16149 if (XFASTINT (w
->window_end_pos
) <= 0
16150 && Z
!= IT_CHARPOS (it
))
16151 w
->update_mode_line
= 1;
16153 /* Set window_end_pos to the offset of the last character displayed
16154 on the window from the end of current_buffer. Set
16155 window_end_vpos to its row number. */
16158 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16159 w
->window_end_bytepos
16160 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16161 wset_window_end_pos
16162 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16163 wset_window_end_vpos
16164 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16166 (MATRIX_ROW (w
->desired_matrix
,
16167 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16171 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16172 wset_window_end_pos (w
, make_number (Z
- ZV
));
16173 wset_window_end_vpos (w
, make_number (0));
16176 /* But that is not valid info until redisplay finishes. */
16177 w
->window_end_valid
= 0;
16183 /************************************************************************
16184 Window redisplay reusing current matrix when buffer has not changed
16185 ************************************************************************/
16187 /* Try redisplay of window W showing an unchanged buffer with a
16188 different window start than the last time it was displayed by
16189 reusing its current matrix. Value is non-zero if successful.
16190 W->start is the new window start. */
16193 try_window_reusing_current_matrix (struct window
*w
)
16195 struct frame
*f
= XFRAME (w
->frame
);
16196 struct glyph_row
*bottom_row
;
16199 struct text_pos start
, new_start
;
16200 int nrows_scrolled
, i
;
16201 struct glyph_row
*last_text_row
;
16202 struct glyph_row
*last_reused_text_row
;
16203 struct glyph_row
*start_row
;
16204 int start_vpos
, min_y
, max_y
;
16207 if (inhibit_try_window_reusing
)
16211 if (/* This function doesn't handle terminal frames. */
16212 !FRAME_WINDOW_P (f
)
16213 /* Don't try to reuse the display if windows have been split
16215 || windows_or_buffers_changed
16216 || cursor_type_changed
)
16219 /* Can't do this if region may have changed. */
16220 if (0 <= markpos_of_region ()
16221 || w
->region_showing
16222 || !NILP (Vshow_trailing_whitespace
))
16225 /* If top-line visibility has changed, give up. */
16226 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16227 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16230 /* Give up if old or new display is scrolled vertically. We could
16231 make this function handle this, but right now it doesn't. */
16232 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16233 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16236 /* The variable new_start now holds the new window start. The old
16237 start `start' can be determined from the current matrix. */
16238 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16239 start
= start_row
->minpos
;
16240 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16242 /* Clear the desired matrix for the display below. */
16243 clear_glyph_matrix (w
->desired_matrix
);
16245 if (CHARPOS (new_start
) <= CHARPOS (start
))
16247 /* Don't use this method if the display starts with an ellipsis
16248 displayed for invisible text. It's not easy to handle that case
16249 below, and it's certainly not worth the effort since this is
16250 not a frequent case. */
16251 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16254 IF_DEBUG (debug_method_add (w
, "twu1"));
16256 /* Display up to a row that can be reused. The variable
16257 last_text_row is set to the last row displayed that displays
16258 text. Note that it.vpos == 0 if or if not there is a
16259 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16260 start_display (&it
, w
, new_start
);
16261 w
->cursor
.vpos
= -1;
16262 last_text_row
= last_reused_text_row
= NULL
;
16264 while (it
.current_y
< it
.last_visible_y
16265 && !fonts_changed_p
)
16267 /* If we have reached into the characters in the START row,
16268 that means the line boundaries have changed. So we
16269 can't start copying with the row START. Maybe it will
16270 work to start copying with the following row. */
16271 while (IT_CHARPOS (it
) > CHARPOS (start
))
16273 /* Advance to the next row as the "start". */
16275 start
= start_row
->minpos
;
16276 /* If there are no more rows to try, or just one, give up. */
16277 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16278 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16279 || CHARPOS (start
) == ZV
)
16281 clear_glyph_matrix (w
->desired_matrix
);
16285 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16287 /* If we have reached alignment, we can copy the rest of the
16289 if (IT_CHARPOS (it
) == CHARPOS (start
)
16290 /* Don't accept "alignment" inside a display vector,
16291 since start_row could have started in the middle of
16292 that same display vector (thus their character
16293 positions match), and we have no way of telling if
16294 that is the case. */
16295 && it
.current
.dpvec_index
< 0)
16298 if (display_line (&it
))
16299 last_text_row
= it
.glyph_row
- 1;
16303 /* A value of current_y < last_visible_y means that we stopped
16304 at the previous window start, which in turn means that we
16305 have at least one reusable row. */
16306 if (it
.current_y
< it
.last_visible_y
)
16308 struct glyph_row
*row
;
16310 /* IT.vpos always starts from 0; it counts text lines. */
16311 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16313 /* Find PT if not already found in the lines displayed. */
16314 if (w
->cursor
.vpos
< 0)
16316 int dy
= it
.current_y
- start_row
->y
;
16318 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16319 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16321 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16322 dy
, nrows_scrolled
);
16325 clear_glyph_matrix (w
->desired_matrix
);
16330 /* Scroll the display. Do it before the current matrix is
16331 changed. The problem here is that update has not yet
16332 run, i.e. part of the current matrix is not up to date.
16333 scroll_run_hook will clear the cursor, and use the
16334 current matrix to get the height of the row the cursor is
16336 run
.current_y
= start_row
->y
;
16337 run
.desired_y
= it
.current_y
;
16338 run
.height
= it
.last_visible_y
- it
.current_y
;
16340 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16343 FRAME_RIF (f
)->update_window_begin_hook (w
);
16344 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16345 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16346 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16350 /* Shift current matrix down by nrows_scrolled lines. */
16351 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16352 rotate_matrix (w
->current_matrix
,
16354 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16357 /* Disable lines that must be updated. */
16358 for (i
= 0; i
< nrows_scrolled
; ++i
)
16359 (start_row
+ i
)->enabled_p
= 0;
16361 /* Re-compute Y positions. */
16362 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16363 max_y
= it
.last_visible_y
;
16364 for (row
= start_row
+ nrows_scrolled
;
16368 row
->y
= it
.current_y
;
16369 row
->visible_height
= row
->height
;
16371 if (row
->y
< min_y
)
16372 row
->visible_height
-= min_y
- row
->y
;
16373 if (row
->y
+ row
->height
> max_y
)
16374 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16375 if (row
->fringe_bitmap_periodic_p
)
16376 row
->redraw_fringe_bitmaps_p
= 1;
16378 it
.current_y
+= row
->height
;
16380 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16381 last_reused_text_row
= row
;
16382 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16386 /* Disable lines in the current matrix which are now
16387 below the window. */
16388 for (++row
; row
< bottom_row
; ++row
)
16389 row
->enabled_p
= row
->mode_line_p
= 0;
16392 /* Update window_end_pos etc.; last_reused_text_row is the last
16393 reused row from the current matrix containing text, if any.
16394 The value of last_text_row is the last displayed line
16395 containing text. */
16396 if (last_reused_text_row
)
16398 w
->window_end_bytepos
16399 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16400 wset_window_end_pos
16402 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16403 wset_window_end_vpos
16404 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16405 w
->current_matrix
)));
16407 else if (last_text_row
)
16409 w
->window_end_bytepos
16410 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16411 wset_window_end_pos
16412 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16413 wset_window_end_vpos
16414 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16415 w
->desired_matrix
)));
16419 /* This window must be completely empty. */
16420 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16421 wset_window_end_pos (w
, make_number (Z
- ZV
));
16422 wset_window_end_vpos (w
, make_number (0));
16424 w
->window_end_valid
= 0;
16426 /* Update hint: don't try scrolling again in update_window. */
16427 w
->desired_matrix
->no_scrolling_p
= 1;
16430 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16434 else if (CHARPOS (new_start
) > CHARPOS (start
))
16436 struct glyph_row
*pt_row
, *row
;
16437 struct glyph_row
*first_reusable_row
;
16438 struct glyph_row
*first_row_to_display
;
16440 int yb
= window_text_bottom_y (w
);
16442 /* Find the row starting at new_start, if there is one. Don't
16443 reuse a partially visible line at the end. */
16444 first_reusable_row
= start_row
;
16445 while (first_reusable_row
->enabled_p
16446 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16447 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16448 < CHARPOS (new_start
)))
16449 ++first_reusable_row
;
16451 /* Give up if there is no row to reuse. */
16452 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16453 || !first_reusable_row
->enabled_p
16454 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16455 != CHARPOS (new_start
)))
16458 /* We can reuse fully visible rows beginning with
16459 first_reusable_row to the end of the window. Set
16460 first_row_to_display to the first row that cannot be reused.
16461 Set pt_row to the row containing point, if there is any. */
16463 for (first_row_to_display
= first_reusable_row
;
16464 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16465 ++first_row_to_display
)
16467 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16468 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16469 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16470 && first_row_to_display
->ends_at_zv_p
16471 && pt_row
== NULL
)))
16472 pt_row
= first_row_to_display
;
16475 /* Start displaying at the start of first_row_to_display. */
16476 eassert (first_row_to_display
->y
< yb
);
16477 init_to_row_start (&it
, w
, first_row_to_display
);
16479 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16481 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16483 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16484 + WINDOW_HEADER_LINE_HEIGHT (w
));
16486 /* Display lines beginning with first_row_to_display in the
16487 desired matrix. Set last_text_row to the last row displayed
16488 that displays text. */
16489 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16490 if (pt_row
== NULL
)
16491 w
->cursor
.vpos
= -1;
16492 last_text_row
= NULL
;
16493 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16494 if (display_line (&it
))
16495 last_text_row
= it
.glyph_row
- 1;
16497 /* If point is in a reused row, adjust y and vpos of the cursor
16501 w
->cursor
.vpos
-= nrows_scrolled
;
16502 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16505 /* Give up if point isn't in a row displayed or reused. (This
16506 also handles the case where w->cursor.vpos < nrows_scrolled
16507 after the calls to display_line, which can happen with scroll
16508 margins. See bug#1295.) */
16509 if (w
->cursor
.vpos
< 0)
16511 clear_glyph_matrix (w
->desired_matrix
);
16515 /* Scroll the display. */
16516 run
.current_y
= first_reusable_row
->y
;
16517 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16518 run
.height
= it
.last_visible_y
- run
.current_y
;
16519 dy
= run
.current_y
- run
.desired_y
;
16524 FRAME_RIF (f
)->update_window_begin_hook (w
);
16525 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16526 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16527 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16531 /* Adjust Y positions of reused rows. */
16532 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16533 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16534 max_y
= it
.last_visible_y
;
16535 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16538 row
->visible_height
= row
->height
;
16539 if (row
->y
< min_y
)
16540 row
->visible_height
-= min_y
- row
->y
;
16541 if (row
->y
+ row
->height
> max_y
)
16542 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16543 if (row
->fringe_bitmap_periodic_p
)
16544 row
->redraw_fringe_bitmaps_p
= 1;
16547 /* Scroll the current matrix. */
16548 eassert (nrows_scrolled
> 0);
16549 rotate_matrix (w
->current_matrix
,
16551 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16554 /* Disable rows not reused. */
16555 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16556 row
->enabled_p
= 0;
16558 /* Point may have moved to a different line, so we cannot assume that
16559 the previous cursor position is valid; locate the correct row. */
16562 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16564 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16565 && !row
->ends_at_zv_p
;
16569 w
->cursor
.y
= row
->y
;
16571 if (row
< bottom_row
)
16573 /* Can't simply scan the row for point with
16574 bidi-reordered glyph rows. Let set_cursor_from_row
16575 figure out where to put the cursor, and if it fails,
16577 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16579 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16582 clear_glyph_matrix (w
->desired_matrix
);
16588 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16589 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16592 && (!BUFFERP (glyph
->object
)
16593 || glyph
->charpos
< PT
);
16597 w
->cursor
.x
+= glyph
->pixel_width
;
16603 /* Adjust window end. A null value of last_text_row means that
16604 the window end is in reused rows which in turn means that
16605 only its vpos can have changed. */
16608 w
->window_end_bytepos
16609 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16610 wset_window_end_pos
16611 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16612 wset_window_end_vpos
16613 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16614 w
->desired_matrix
)));
16618 wset_window_end_vpos
16619 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16622 w
->window_end_valid
= 0;
16623 w
->desired_matrix
->no_scrolling_p
= 1;
16626 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16636 /************************************************************************
16637 Window redisplay reusing current matrix when buffer has changed
16638 ************************************************************************/
16640 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16641 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16642 ptrdiff_t *, ptrdiff_t *);
16643 static struct glyph_row
*
16644 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16645 struct glyph_row
*);
16648 /* Return the last row in MATRIX displaying text. If row START is
16649 non-null, start searching with that row. IT gives the dimensions
16650 of the display. Value is null if matrix is empty; otherwise it is
16651 a pointer to the row found. */
16653 static struct glyph_row
*
16654 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16655 struct glyph_row
*start
)
16657 struct glyph_row
*row
, *row_found
;
16659 /* Set row_found to the last row in IT->w's current matrix
16660 displaying text. The loop looks funny but think of partially
16663 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16664 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16666 eassert (row
->enabled_p
);
16668 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16677 /* Return the last row in the current matrix of W that is not affected
16678 by changes at the start of current_buffer that occurred since W's
16679 current matrix was built. Value is null if no such row exists.
16681 BEG_UNCHANGED us the number of characters unchanged at the start of
16682 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16683 first changed character in current_buffer. Characters at positions <
16684 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16685 when the current matrix was built. */
16687 static struct glyph_row
*
16688 find_last_unchanged_at_beg_row (struct window
*w
)
16690 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16691 struct glyph_row
*row
;
16692 struct glyph_row
*row_found
= NULL
;
16693 int yb
= window_text_bottom_y (w
);
16695 /* Find the last row displaying unchanged text. */
16696 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16697 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16698 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16701 if (/* If row ends before first_changed_pos, it is unchanged,
16702 except in some case. */
16703 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16704 /* When row ends in ZV and we write at ZV it is not
16706 && !row
->ends_at_zv_p
16707 /* When first_changed_pos is the end of a continued line,
16708 row is not unchanged because it may be no longer
16710 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16711 && (row
->continued_p
16712 || row
->exact_window_width_line_p
))
16713 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16714 needs to be recomputed, so don't consider this row as
16715 unchanged. This happens when the last line was
16716 bidi-reordered and was killed immediately before this
16717 redisplay cycle. In that case, ROW->end stores the
16718 buffer position of the first visual-order character of
16719 the killed text, which is now beyond ZV. */
16720 && CHARPOS (row
->end
.pos
) <= ZV
)
16723 /* Stop if last visible row. */
16724 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16732 /* Find the first glyph row in the current matrix of W that is not
16733 affected by changes at the end of current_buffer since the
16734 time W's current matrix was built.
16736 Return in *DELTA the number of chars by which buffer positions in
16737 unchanged text at the end of current_buffer must be adjusted.
16739 Return in *DELTA_BYTES the corresponding number of bytes.
16741 Value is null if no such row exists, i.e. all rows are affected by
16744 static struct glyph_row
*
16745 find_first_unchanged_at_end_row (struct window
*w
,
16746 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16748 struct glyph_row
*row
;
16749 struct glyph_row
*row_found
= NULL
;
16751 *delta
= *delta_bytes
= 0;
16753 /* Display must not have been paused, otherwise the current matrix
16754 is not up to date. */
16755 eassert (w
->window_end_valid
);
16757 /* A value of window_end_pos >= END_UNCHANGED means that the window
16758 end is in the range of changed text. If so, there is no
16759 unchanged row at the end of W's current matrix. */
16760 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16763 /* Set row to the last row in W's current matrix displaying text. */
16764 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16766 /* If matrix is entirely empty, no unchanged row exists. */
16767 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16769 /* The value of row is the last glyph row in the matrix having a
16770 meaningful buffer position in it. The end position of row
16771 corresponds to window_end_pos. This allows us to translate
16772 buffer positions in the current matrix to current buffer
16773 positions for characters not in changed text. */
16775 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16776 ptrdiff_t Z_BYTE_old
=
16777 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16778 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16779 struct glyph_row
*first_text_row
16780 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16782 *delta
= Z
- Z_old
;
16783 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16785 /* Set last_unchanged_pos to the buffer position of the last
16786 character in the buffer that has not been changed. Z is the
16787 index + 1 of the last character in current_buffer, i.e. by
16788 subtracting END_UNCHANGED we get the index of the last
16789 unchanged character, and we have to add BEG to get its buffer
16791 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16792 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16794 /* Search backward from ROW for a row displaying a line that
16795 starts at a minimum position >= last_unchanged_pos_old. */
16796 for (; row
> first_text_row
; --row
)
16798 /* This used to abort, but it can happen.
16799 It is ok to just stop the search instead here. KFS. */
16800 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16803 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16808 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16814 /* Make sure that glyph rows in the current matrix of window W
16815 reference the same glyph memory as corresponding rows in the
16816 frame's frame matrix. This function is called after scrolling W's
16817 current matrix on a terminal frame in try_window_id and
16818 try_window_reusing_current_matrix. */
16821 sync_frame_with_window_matrix_rows (struct window
*w
)
16823 struct frame
*f
= XFRAME (w
->frame
);
16824 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16826 /* Preconditions: W must be a leaf window and full-width. Its frame
16827 must have a frame matrix. */
16828 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16829 eassert (WINDOW_FULL_WIDTH_P (w
));
16830 eassert (!FRAME_WINDOW_P (f
));
16832 /* If W is a full-width window, glyph pointers in W's current matrix
16833 have, by definition, to be the same as glyph pointers in the
16834 corresponding frame matrix. Note that frame matrices have no
16835 marginal areas (see build_frame_matrix). */
16836 window_row
= w
->current_matrix
->rows
;
16837 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16838 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16839 while (window_row
< window_row_end
)
16841 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16842 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16844 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16845 frame_row
->glyphs
[TEXT_AREA
] = start
;
16846 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16847 frame_row
->glyphs
[LAST_AREA
] = end
;
16849 /* Disable frame rows whose corresponding window rows have
16850 been disabled in try_window_id. */
16851 if (!window_row
->enabled_p
)
16852 frame_row
->enabled_p
= 0;
16854 ++window_row
, ++frame_row
;
16859 /* Find the glyph row in window W containing CHARPOS. Consider all
16860 rows between START and END (not inclusive). END null means search
16861 all rows to the end of the display area of W. Value is the row
16862 containing CHARPOS or null. */
16865 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16866 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16868 struct glyph_row
*row
= start
;
16869 struct glyph_row
*best_row
= NULL
;
16870 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16873 /* If we happen to start on a header-line, skip that. */
16874 if (row
->mode_line_p
)
16877 if ((end
&& row
>= end
) || !row
->enabled_p
)
16880 last_y
= window_text_bottom_y (w
) - dy
;
16884 /* Give up if we have gone too far. */
16885 if (end
&& row
>= end
)
16887 /* This formerly returned if they were equal.
16888 I think that both quantities are of a "last plus one" type;
16889 if so, when they are equal, the row is within the screen. -- rms. */
16890 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16893 /* If it is in this row, return this row. */
16894 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16895 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16896 /* The end position of a row equals the start
16897 position of the next row. If CHARPOS is there, we
16898 would rather display it in the next line, except
16899 when this line ends in ZV. */
16900 && !row
->ends_at_zv_p
16901 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16902 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16906 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16907 || (!best_row
&& !row
->continued_p
))
16909 /* In bidi-reordered rows, there could be several rows
16910 occluding point, all of them belonging to the same
16911 continued line. We need to find the row which fits
16912 CHARPOS the best. */
16913 for (g
= row
->glyphs
[TEXT_AREA
];
16914 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16917 if (!STRINGP (g
->object
))
16919 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16921 mindif
= eabs (g
->charpos
- charpos
);
16923 /* Exact match always wins. */
16930 else if (best_row
&& !row
->continued_p
)
16937 /* Try to redisplay window W by reusing its existing display. W's
16938 current matrix must be up to date when this function is called,
16939 i.e. window_end_valid must be nonzero.
16943 1 if display has been updated
16944 0 if otherwise unsuccessful
16945 -1 if redisplay with same window start is known not to succeed
16947 The following steps are performed:
16949 1. Find the last row in the current matrix of W that is not
16950 affected by changes at the start of current_buffer. If no such row
16953 2. Find the first row in W's current matrix that is not affected by
16954 changes at the end of current_buffer. Maybe there is no such row.
16956 3. Display lines beginning with the row + 1 found in step 1 to the
16957 row found in step 2 or, if step 2 didn't find a row, to the end of
16960 4. If cursor is not known to appear on the window, give up.
16962 5. If display stopped at the row found in step 2, scroll the
16963 display and current matrix as needed.
16965 6. Maybe display some lines at the end of W, if we must. This can
16966 happen under various circumstances, like a partially visible line
16967 becoming fully visible, or because newly displayed lines are displayed
16968 in smaller font sizes.
16970 7. Update W's window end information. */
16973 try_window_id (struct window
*w
)
16975 struct frame
*f
= XFRAME (w
->frame
);
16976 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16977 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16978 struct glyph_row
*last_unchanged_at_beg_row
;
16979 struct glyph_row
*first_unchanged_at_end_row
;
16980 struct glyph_row
*row
;
16981 struct glyph_row
*bottom_row
;
16984 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
16986 struct text_pos start_pos
;
16988 int first_unchanged_at_end_vpos
= 0;
16989 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16990 struct text_pos start
;
16991 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
16994 if (inhibit_try_window_id
)
16998 /* This is handy for debugging. */
17000 #define GIVE_UP(X) \
17002 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17006 #define GIVE_UP(X) return 0
17009 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17011 /* Don't use this for mini-windows because these can show
17012 messages and mini-buffers, and we don't handle that here. */
17013 if (MINI_WINDOW_P (w
))
17016 /* This flag is used to prevent redisplay optimizations. */
17017 if (windows_or_buffers_changed
|| cursor_type_changed
)
17020 /* Verify that narrowing has not changed.
17021 Also verify that we were not told to prevent redisplay optimizations.
17022 It would be nice to further
17023 reduce the number of cases where this prevents try_window_id. */
17024 if (current_buffer
->clip_changed
17025 || current_buffer
->prevent_redisplay_optimizations_p
)
17028 /* Window must either use window-based redisplay or be full width. */
17029 if (!FRAME_WINDOW_P (f
)
17030 && (!FRAME_LINE_INS_DEL_OK (f
)
17031 || !WINDOW_FULL_WIDTH_P (w
)))
17034 /* Give up if point is known NOT to appear in W. */
17035 if (PT
< CHARPOS (start
))
17038 /* Another way to prevent redisplay optimizations. */
17039 if (w
->last_modified
== 0)
17042 /* Verify that window is not hscrolled. */
17043 if (w
->hscroll
!= 0)
17046 /* Verify that display wasn't paused. */
17047 if (!w
->window_end_valid
)
17050 /* Can't use this if highlighting a region because a cursor movement
17051 will do more than just set the cursor. */
17052 if (0 <= markpos_of_region ())
17055 /* Likewise if highlighting trailing whitespace. */
17056 if (!NILP (Vshow_trailing_whitespace
))
17059 /* Likewise if showing a region. */
17060 if (w
->region_showing
)
17063 /* Can't use this if overlay arrow position and/or string have
17065 if (overlay_arrows_changed_p ())
17068 /* When word-wrap is on, adding a space to the first word of a
17069 wrapped line can change the wrap position, altering the line
17070 above it. It might be worthwhile to handle this more
17071 intelligently, but for now just redisplay from scratch. */
17072 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17075 /* Under bidi reordering, adding or deleting a character in the
17076 beginning of a paragraph, before the first strong directional
17077 character, can change the base direction of the paragraph (unless
17078 the buffer specifies a fixed paragraph direction), which will
17079 require to redisplay the whole paragraph. It might be worthwhile
17080 to find the paragraph limits and widen the range of redisplayed
17081 lines to that, but for now just give up this optimization and
17082 redisplay from scratch. */
17083 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17084 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17087 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17088 only if buffer has really changed. The reason is that the gap is
17089 initially at Z for freshly visited files. The code below would
17090 set end_unchanged to 0 in that case. */
17091 if (MODIFF
> SAVE_MODIFF
17092 /* This seems to happen sometimes after saving a buffer. */
17093 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17095 if (GPT
- BEG
< BEG_UNCHANGED
)
17096 BEG_UNCHANGED
= GPT
- BEG
;
17097 if (Z
- GPT
< END_UNCHANGED
)
17098 END_UNCHANGED
= Z
- GPT
;
17101 /* The position of the first and last character that has been changed. */
17102 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17103 last_changed_charpos
= Z
- END_UNCHANGED
;
17105 /* If window starts after a line end, and the last change is in
17106 front of that newline, then changes don't affect the display.
17107 This case happens with stealth-fontification. Note that although
17108 the display is unchanged, glyph positions in the matrix have to
17109 be adjusted, of course. */
17110 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17111 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17112 && ((last_changed_charpos
< CHARPOS (start
)
17113 && CHARPOS (start
) == BEGV
)
17114 || (last_changed_charpos
< CHARPOS (start
) - 1
17115 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17117 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17118 struct glyph_row
*r0
;
17120 /* Compute how many chars/bytes have been added to or removed
17121 from the buffer. */
17122 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17123 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17124 Z_delta
= Z
- Z_old
;
17125 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17127 /* Give up if PT is not in the window. Note that it already has
17128 been checked at the start of try_window_id that PT is not in
17129 front of the window start. */
17130 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17133 /* If window start is unchanged, we can reuse the whole matrix
17134 as is, after adjusting glyph positions. No need to compute
17135 the window end again, since its offset from Z hasn't changed. */
17136 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17137 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17138 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17139 /* PT must not be in a partially visible line. */
17140 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17141 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17143 /* Adjust positions in the glyph matrix. */
17144 if (Z_delta
|| Z_delta_bytes
)
17146 struct glyph_row
*r1
17147 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17148 increment_matrix_positions (w
->current_matrix
,
17149 MATRIX_ROW_VPOS (r0
, current_matrix
),
17150 MATRIX_ROW_VPOS (r1
, current_matrix
),
17151 Z_delta
, Z_delta_bytes
);
17154 /* Set the cursor. */
17155 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17157 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17164 /* Handle the case that changes are all below what is displayed in
17165 the window, and that PT is in the window. This shortcut cannot
17166 be taken if ZV is visible in the window, and text has been added
17167 there that is visible in the window. */
17168 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17169 /* ZV is not visible in the window, or there are no
17170 changes at ZV, actually. */
17171 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17172 || first_changed_charpos
== last_changed_charpos
))
17174 struct glyph_row
*r0
;
17176 /* Give up if PT is not in the window. Note that it already has
17177 been checked at the start of try_window_id that PT is not in
17178 front of the window start. */
17179 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17182 /* If window start is unchanged, we can reuse the whole matrix
17183 as is, without changing glyph positions since no text has
17184 been added/removed in front of the window end. */
17185 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17186 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17187 /* PT must not be in a partially visible line. */
17188 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17189 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17191 /* We have to compute the window end anew since text
17192 could have been added/removed after it. */
17193 wset_window_end_pos
17194 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17195 w
->window_end_bytepos
17196 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17198 /* Set the cursor. */
17199 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17201 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17208 /* Give up if window start is in the changed area.
17210 The condition used to read
17212 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17214 but why that was tested escapes me at the moment. */
17215 if (CHARPOS (start
) >= first_changed_charpos
17216 && CHARPOS (start
) <= last_changed_charpos
)
17219 /* Check that window start agrees with the start of the first glyph
17220 row in its current matrix. Check this after we know the window
17221 start is not in changed text, otherwise positions would not be
17223 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17224 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17227 /* Give up if the window ends in strings. Overlay strings
17228 at the end are difficult to handle, so don't try. */
17229 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17230 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17233 /* Compute the position at which we have to start displaying new
17234 lines. Some of the lines at the top of the window might be
17235 reusable because they are not displaying changed text. Find the
17236 last row in W's current matrix not affected by changes at the
17237 start of current_buffer. Value is null if changes start in the
17238 first line of window. */
17239 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17240 if (last_unchanged_at_beg_row
)
17242 /* Avoid starting to display in the middle of a character, a TAB
17243 for instance. This is easier than to set up the iterator
17244 exactly, and it's not a frequent case, so the additional
17245 effort wouldn't really pay off. */
17246 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17247 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17248 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17249 --last_unchanged_at_beg_row
;
17251 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17254 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17256 start_pos
= it
.current
.pos
;
17258 /* Start displaying new lines in the desired matrix at the same
17259 vpos we would use in the current matrix, i.e. below
17260 last_unchanged_at_beg_row. */
17261 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17263 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17264 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17266 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17270 /* There are no reusable lines at the start of the window.
17271 Start displaying in the first text line. */
17272 start_display (&it
, w
, start
);
17273 it
.vpos
= it
.first_vpos
;
17274 start_pos
= it
.current
.pos
;
17277 /* Find the first row that is not affected by changes at the end of
17278 the buffer. Value will be null if there is no unchanged row, in
17279 which case we must redisplay to the end of the window. delta
17280 will be set to the value by which buffer positions beginning with
17281 first_unchanged_at_end_row have to be adjusted due to text
17283 first_unchanged_at_end_row
17284 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17285 IF_DEBUG (debug_delta
= delta
);
17286 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17288 /* Set stop_pos to the buffer position up to which we will have to
17289 display new lines. If first_unchanged_at_end_row != NULL, this
17290 is the buffer position of the start of the line displayed in that
17291 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17292 that we don't stop at a buffer position. */
17294 if (first_unchanged_at_end_row
)
17296 eassert (last_unchanged_at_beg_row
== NULL
17297 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17299 /* If this is a continuation line, move forward to the next one
17300 that isn't. Changes in lines above affect this line.
17301 Caution: this may move first_unchanged_at_end_row to a row
17302 not displaying text. */
17303 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17304 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17305 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17306 < it
.last_visible_y
))
17307 ++first_unchanged_at_end_row
;
17309 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17310 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17311 >= it
.last_visible_y
))
17312 first_unchanged_at_end_row
= NULL
;
17315 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17317 first_unchanged_at_end_vpos
17318 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17319 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17322 else if (last_unchanged_at_beg_row
== NULL
)
17328 /* Either there is no unchanged row at the end, or the one we have
17329 now displays text. This is a necessary condition for the window
17330 end pos calculation at the end of this function. */
17331 eassert (first_unchanged_at_end_row
== NULL
17332 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17334 debug_last_unchanged_at_beg_vpos
17335 = (last_unchanged_at_beg_row
17336 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17338 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17340 #endif /* GLYPH_DEBUG */
17343 /* Display new lines. Set last_text_row to the last new line
17344 displayed which has text on it, i.e. might end up as being the
17345 line where the window_end_vpos is. */
17346 w
->cursor
.vpos
= -1;
17347 last_text_row
= NULL
;
17348 overlay_arrow_seen
= 0;
17349 while (it
.current_y
< it
.last_visible_y
17350 && !fonts_changed_p
17351 && (first_unchanged_at_end_row
== NULL
17352 || IT_CHARPOS (it
) < stop_pos
))
17354 if (display_line (&it
))
17355 last_text_row
= it
.glyph_row
- 1;
17358 if (fonts_changed_p
)
17362 /* Compute differences in buffer positions, y-positions etc. for
17363 lines reused at the bottom of the window. Compute what we can
17365 if (first_unchanged_at_end_row
17366 /* No lines reused because we displayed everything up to the
17367 bottom of the window. */
17368 && it
.current_y
< it
.last_visible_y
)
17371 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17373 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17374 run
.current_y
= first_unchanged_at_end_row
->y
;
17375 run
.desired_y
= run
.current_y
+ dy
;
17376 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17380 delta
= delta_bytes
= dvpos
= dy
17381 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17382 first_unchanged_at_end_row
= NULL
;
17384 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17387 /* Find the cursor if not already found. We have to decide whether
17388 PT will appear on this window (it sometimes doesn't, but this is
17389 not a very frequent case.) This decision has to be made before
17390 the current matrix is altered. A value of cursor.vpos < 0 means
17391 that PT is either in one of the lines beginning at
17392 first_unchanged_at_end_row or below the window. Don't care for
17393 lines that might be displayed later at the window end; as
17394 mentioned, this is not a frequent case. */
17395 if (w
->cursor
.vpos
< 0)
17397 /* Cursor in unchanged rows at the top? */
17398 if (PT
< CHARPOS (start_pos
)
17399 && last_unchanged_at_beg_row
)
17401 row
= row_containing_pos (w
, PT
,
17402 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17403 last_unchanged_at_beg_row
+ 1, 0);
17405 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17408 /* Start from first_unchanged_at_end_row looking for PT. */
17409 else if (first_unchanged_at_end_row
)
17411 row
= row_containing_pos (w
, PT
- delta
,
17412 first_unchanged_at_end_row
, NULL
, 0);
17414 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17415 delta_bytes
, dy
, dvpos
);
17418 /* Give up if cursor was not found. */
17419 if (w
->cursor
.vpos
< 0)
17421 clear_glyph_matrix (w
->desired_matrix
);
17426 /* Don't let the cursor end in the scroll margins. */
17428 int this_scroll_margin
, cursor_height
;
17430 this_scroll_margin
=
17431 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17432 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17433 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17435 if ((w
->cursor
.y
< this_scroll_margin
17436 && CHARPOS (start
) > BEGV
)
17437 /* Old redisplay didn't take scroll margin into account at the bottom,
17438 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17439 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17440 ? cursor_height
+ this_scroll_margin
17441 : 1)) > it
.last_visible_y
)
17443 w
->cursor
.vpos
= -1;
17444 clear_glyph_matrix (w
->desired_matrix
);
17449 /* Scroll the display. Do it before changing the current matrix so
17450 that xterm.c doesn't get confused about where the cursor glyph is
17452 if (dy
&& run
.height
)
17456 if (FRAME_WINDOW_P (f
))
17458 FRAME_RIF (f
)->update_window_begin_hook (w
);
17459 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17460 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17461 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17465 /* Terminal frame. In this case, dvpos gives the number of
17466 lines to scroll by; dvpos < 0 means scroll up. */
17468 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17469 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17470 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17471 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17472 + window_internal_height (w
));
17474 #if defined (HAVE_GPM) || defined (MSDOS)
17475 x_clear_window_mouse_face (w
);
17477 /* Perform the operation on the screen. */
17480 /* Scroll last_unchanged_at_beg_row to the end of the
17481 window down dvpos lines. */
17482 set_terminal_window (f
, end
);
17484 /* On dumb terminals delete dvpos lines at the end
17485 before inserting dvpos empty lines. */
17486 if (!FRAME_SCROLL_REGION_OK (f
))
17487 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17489 /* Insert dvpos empty lines in front of
17490 last_unchanged_at_beg_row. */
17491 ins_del_lines (f
, from
, dvpos
);
17493 else if (dvpos
< 0)
17495 /* Scroll up last_unchanged_at_beg_vpos to the end of
17496 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17497 set_terminal_window (f
, end
);
17499 /* Delete dvpos lines in front of
17500 last_unchanged_at_beg_vpos. ins_del_lines will set
17501 the cursor to the given vpos and emit |dvpos| delete
17503 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17505 /* On a dumb terminal insert dvpos empty lines at the
17507 if (!FRAME_SCROLL_REGION_OK (f
))
17508 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17511 set_terminal_window (f
, 0);
17517 /* Shift reused rows of the current matrix to the right position.
17518 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17520 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17521 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17524 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17525 bottom_vpos
, dvpos
);
17526 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17529 else if (dvpos
> 0)
17531 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17532 bottom_vpos
, dvpos
);
17533 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17534 first_unchanged_at_end_vpos
+ dvpos
);
17537 /* For frame-based redisplay, make sure that current frame and window
17538 matrix are in sync with respect to glyph memory. */
17539 if (!FRAME_WINDOW_P (f
))
17540 sync_frame_with_window_matrix_rows (w
);
17542 /* Adjust buffer positions in reused rows. */
17543 if (delta
|| delta_bytes
)
17544 increment_matrix_positions (current_matrix
,
17545 first_unchanged_at_end_vpos
+ dvpos
,
17546 bottom_vpos
, delta
, delta_bytes
);
17548 /* Adjust Y positions. */
17550 shift_glyph_matrix (w
, current_matrix
,
17551 first_unchanged_at_end_vpos
+ dvpos
,
17554 if (first_unchanged_at_end_row
)
17556 first_unchanged_at_end_row
+= dvpos
;
17557 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17558 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17559 first_unchanged_at_end_row
= NULL
;
17562 /* If scrolling up, there may be some lines to display at the end of
17564 last_text_row_at_end
= NULL
;
17567 /* Scrolling up can leave for example a partially visible line
17568 at the end of the window to be redisplayed. */
17569 /* Set last_row to the glyph row in the current matrix where the
17570 window end line is found. It has been moved up or down in
17571 the matrix by dvpos. */
17572 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17573 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17575 /* If last_row is the window end line, it should display text. */
17576 eassert (last_row
->displays_text_p
);
17578 /* If window end line was partially visible before, begin
17579 displaying at that line. Otherwise begin displaying with the
17580 line following it. */
17581 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17583 init_to_row_start (&it
, w
, last_row
);
17584 it
.vpos
= last_vpos
;
17585 it
.current_y
= last_row
->y
;
17589 init_to_row_end (&it
, w
, last_row
);
17590 it
.vpos
= 1 + last_vpos
;
17591 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17595 /* We may start in a continuation line. If so, we have to
17596 get the right continuation_lines_width and current_x. */
17597 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17598 it
.hpos
= it
.current_x
= 0;
17600 /* Display the rest of the lines at the window end. */
17601 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17602 while (it
.current_y
< it
.last_visible_y
17603 && !fonts_changed_p
)
17605 /* Is it always sure that the display agrees with lines in
17606 the current matrix? I don't think so, so we mark rows
17607 displayed invalid in the current matrix by setting their
17608 enabled_p flag to zero. */
17609 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17610 if (display_line (&it
))
17611 last_text_row_at_end
= it
.glyph_row
- 1;
17615 /* Update window_end_pos and window_end_vpos. */
17616 if (first_unchanged_at_end_row
17617 && !last_text_row_at_end
)
17619 /* Window end line if one of the preserved rows from the current
17620 matrix. Set row to the last row displaying text in current
17621 matrix starting at first_unchanged_at_end_row, after
17623 eassert (first_unchanged_at_end_row
->displays_text_p
);
17624 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17625 first_unchanged_at_end_row
);
17626 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17628 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17629 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17630 wset_window_end_vpos
17631 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17632 eassert (w
->window_end_bytepos
>= 0);
17633 IF_DEBUG (debug_method_add (w
, "A"));
17635 else if (last_text_row_at_end
)
17637 wset_window_end_pos
17638 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17639 w
->window_end_bytepos
17640 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17641 wset_window_end_vpos
17642 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17644 eassert (w
->window_end_bytepos
>= 0);
17645 IF_DEBUG (debug_method_add (w
, "B"));
17647 else if (last_text_row
)
17649 /* We have displayed either to the end of the window or at the
17650 end of the window, i.e. the last row with text is to be found
17651 in the desired matrix. */
17652 wset_window_end_pos
17653 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17654 w
->window_end_bytepos
17655 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17656 wset_window_end_vpos
17657 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17658 eassert (w
->window_end_bytepos
>= 0);
17660 else if (first_unchanged_at_end_row
== NULL
17661 && last_text_row
== NULL
17662 && last_text_row_at_end
== NULL
)
17664 /* Displayed to end of window, but no line containing text was
17665 displayed. Lines were deleted at the end of the window. */
17666 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17667 int vpos
= XFASTINT (w
->window_end_vpos
);
17668 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17669 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17672 row
== NULL
&& vpos
>= first_vpos
;
17673 --vpos
, --current_row
, --desired_row
)
17675 if (desired_row
->enabled_p
)
17677 if (desired_row
->displays_text_p
)
17680 else if (current_row
->displays_text_p
)
17684 eassert (row
!= NULL
);
17685 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17686 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17687 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17688 eassert (w
->window_end_bytepos
>= 0);
17689 IF_DEBUG (debug_method_add (w
, "C"));
17694 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17695 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17697 /* Record that display has not been completed. */
17698 w
->window_end_valid
= 0;
17699 w
->desired_matrix
->no_scrolling_p
= 1;
17707 /***********************************************************************
17708 More debugging support
17709 ***********************************************************************/
17713 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17714 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17715 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17718 /* Dump the contents of glyph matrix MATRIX on stderr.
17720 GLYPHS 0 means don't show glyph contents.
17721 GLYPHS 1 means show glyphs in short form
17722 GLYPHS > 1 means show glyphs in long form. */
17725 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17728 for (i
= 0; i
< matrix
->nrows
; ++i
)
17729 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17733 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17734 the glyph row and area where the glyph comes from. */
17737 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17739 if (glyph
->type
== CHAR_GLYPH
17740 || glyph
->type
== GLYPHLESS_GLYPH
)
17743 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17744 glyph
- row
->glyphs
[TEXT_AREA
],
17745 (glyph
->type
== CHAR_GLYPH
17749 (BUFFERP (glyph
->object
)
17751 : (STRINGP (glyph
->object
)
17753 : (INTEGERP (glyph
->object
)
17756 glyph
->pixel_width
,
17758 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17762 glyph
->left_box_line_p
,
17763 glyph
->right_box_line_p
);
17765 else if (glyph
->type
== STRETCH_GLYPH
)
17768 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17769 glyph
- row
->glyphs
[TEXT_AREA
],
17772 (BUFFERP (glyph
->object
)
17774 : (STRINGP (glyph
->object
)
17776 : (INTEGERP (glyph
->object
)
17779 glyph
->pixel_width
,
17783 glyph
->left_box_line_p
,
17784 glyph
->right_box_line_p
);
17786 else if (glyph
->type
== IMAGE_GLYPH
)
17789 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17790 glyph
- row
->glyphs
[TEXT_AREA
],
17793 (BUFFERP (glyph
->object
)
17795 : (STRINGP (glyph
->object
)
17797 : (INTEGERP (glyph
->object
)
17800 glyph
->pixel_width
,
17804 glyph
->left_box_line_p
,
17805 glyph
->right_box_line_p
);
17807 else if (glyph
->type
== COMPOSITE_GLYPH
)
17810 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17811 glyph
- row
->glyphs
[TEXT_AREA
],
17814 (BUFFERP (glyph
->object
)
17816 : (STRINGP (glyph
->object
)
17818 : (INTEGERP (glyph
->object
)
17821 glyph
->pixel_width
,
17823 if (glyph
->u
.cmp
.automatic
)
17826 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17827 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17829 glyph
->left_box_line_p
,
17830 glyph
->right_box_line_p
);
17835 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17836 GLYPHS 0 means don't show glyph contents.
17837 GLYPHS 1 means show glyphs in short form
17838 GLYPHS > 1 means show glyphs in long form. */
17841 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17845 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17846 fprintf (stderr
, "==============================================================================\n");
17848 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17849 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17851 MATRIX_ROW_START_CHARPOS (row
),
17852 MATRIX_ROW_END_CHARPOS (row
),
17853 row
->used
[TEXT_AREA
],
17854 row
->contains_overlapping_glyphs_p
,
17856 row
->truncated_on_left_p
,
17857 row
->truncated_on_right_p
,
17859 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17860 row
->displays_text_p
,
17863 row
->ends_in_middle_of_char_p
,
17864 row
->starts_in_middle_of_char_p
,
17870 row
->visible_height
,
17873 /* The next 3 lines should align to "Start" in the header. */
17874 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17875 row
->end
.overlay_string_index
,
17876 row
->continuation_lines_width
);
17877 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17878 CHARPOS (row
->start
.string_pos
),
17879 CHARPOS (row
->end
.string_pos
));
17880 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17881 row
->end
.dpvec_index
);
17888 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17890 struct glyph
*glyph
= row
->glyphs
[area
];
17891 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17893 /* Glyph for a line end in text. */
17894 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17897 if (glyph
< glyph_end
)
17898 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
17900 for (; glyph
< glyph_end
; ++glyph
)
17901 dump_glyph (row
, glyph
, area
);
17904 else if (glyphs
== 1)
17908 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17910 char *s
= alloca (row
->used
[area
] + 4);
17913 for (i
= 0; i
< row
->used
[area
]; ++i
)
17915 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17916 if (i
== row
->used
[area
] - 1
17917 && area
== TEXT_AREA
17918 && INTEGERP (glyph
->object
)
17919 && glyph
->type
== CHAR_GLYPH
17920 && glyph
->u
.ch
== ' ')
17922 strcpy (&s
[i
], "[\\n]");
17925 else if (glyph
->type
== CHAR_GLYPH
17926 && glyph
->u
.ch
< 0x80
17927 && glyph
->u
.ch
>= ' ')
17928 s
[i
] = glyph
->u
.ch
;
17934 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17940 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17941 Sdump_glyph_matrix
, 0, 1, "p",
17942 doc
: /* Dump the current matrix of the selected window to stderr.
17943 Shows contents of glyph row structures. With non-nil
17944 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17945 glyphs in short form, otherwise show glyphs in long form. */)
17946 (Lisp_Object glyphs
)
17948 struct window
*w
= XWINDOW (selected_window
);
17949 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17951 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17952 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17953 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17954 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17955 fprintf (stderr
, "=============================================\n");
17956 dump_glyph_matrix (w
->current_matrix
,
17957 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17962 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17963 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17966 struct frame
*f
= XFRAME (selected_frame
);
17967 dump_glyph_matrix (f
->current_matrix
, 1);
17972 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17973 doc
: /* Dump glyph row ROW to stderr.
17974 GLYPH 0 means don't dump glyphs.
17975 GLYPH 1 means dump glyphs in short form.
17976 GLYPH > 1 or omitted means dump glyphs in long form. */)
17977 (Lisp_Object row
, Lisp_Object glyphs
)
17979 struct glyph_matrix
*matrix
;
17982 CHECK_NUMBER (row
);
17983 matrix
= XWINDOW (selected_window
)->current_matrix
;
17985 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17986 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17988 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17993 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17994 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17995 GLYPH 0 means don't dump glyphs.
17996 GLYPH 1 means dump glyphs in short form.
17997 GLYPH > 1 or omitted means dump glyphs in long form. */)
17998 (Lisp_Object row
, Lisp_Object glyphs
)
18000 struct frame
*sf
= SELECTED_FRAME ();
18001 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18004 CHECK_NUMBER (row
);
18006 if (vpos
>= 0 && vpos
< m
->nrows
)
18007 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18008 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18013 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18014 doc
: /* Toggle tracing of redisplay.
18015 With ARG, turn tracing on if and only if ARG is positive. */)
18019 trace_redisplay_p
= !trace_redisplay_p
;
18022 arg
= Fprefix_numeric_value (arg
);
18023 trace_redisplay_p
= XINT (arg
) > 0;
18030 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18031 doc
: /* Like `format', but print result to stderr.
18032 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18033 (ptrdiff_t nargs
, Lisp_Object
*args
)
18035 Lisp_Object s
= Fformat (nargs
, args
);
18036 fprintf (stderr
, "%s", SDATA (s
));
18040 #endif /* GLYPH_DEBUG */
18044 /***********************************************************************
18045 Building Desired Matrix Rows
18046 ***********************************************************************/
18048 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18049 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18051 static struct glyph_row
*
18052 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18054 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18055 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18056 struct buffer
*old
= current_buffer
;
18057 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18058 int arrow_len
= SCHARS (overlay_arrow_string
);
18059 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18060 const unsigned char *p
;
18063 int n_glyphs_before
;
18065 set_buffer_temp (buffer
);
18066 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18067 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18068 SET_TEXT_POS (it
.position
, 0, 0);
18070 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18072 while (p
< arrow_end
)
18074 Lisp_Object face
, ilisp
;
18076 /* Get the next character. */
18078 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18081 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18082 if (! ASCII_CHAR_P (it
.c
))
18083 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18087 /* Get its face. */
18088 ilisp
= make_number (p
- arrow_string
);
18089 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18090 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18092 /* Compute its width, get its glyphs. */
18093 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18094 SET_TEXT_POS (it
.position
, -1, -1);
18095 PRODUCE_GLYPHS (&it
);
18097 /* If this character doesn't fit any more in the line, we have
18098 to remove some glyphs. */
18099 if (it
.current_x
> it
.last_visible_x
)
18101 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18106 set_buffer_temp (old
);
18107 return it
.glyph_row
;
18111 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18112 glyphs to insert is determined by produce_special_glyphs. */
18115 insert_left_trunc_glyphs (struct it
*it
)
18117 struct it truncate_it
;
18118 struct glyph
*from
, *end
, *to
, *toend
;
18120 eassert (!FRAME_WINDOW_P (it
->f
)
18121 || (!it
->glyph_row
->reversed_p
18122 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18123 || (it
->glyph_row
->reversed_p
18124 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18126 /* Get the truncation glyphs. */
18128 truncate_it
.current_x
= 0;
18129 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18130 truncate_it
.glyph_row
= &scratch_glyph_row
;
18131 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18132 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18133 truncate_it
.object
= make_number (0);
18134 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18136 /* Overwrite glyphs from IT with truncation glyphs. */
18137 if (!it
->glyph_row
->reversed_p
)
18139 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18141 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18142 end
= from
+ tused
;
18143 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18144 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18145 if (FRAME_WINDOW_P (it
->f
))
18147 /* On GUI frames, when variable-size fonts are displayed,
18148 the truncation glyphs may need more pixels than the row's
18149 glyphs they overwrite. We overwrite more glyphs to free
18150 enough screen real estate, and enlarge the stretch glyph
18151 on the right (see display_line), if there is one, to
18152 preserve the screen position of the truncation glyphs on
18155 struct glyph
*g
= to
;
18158 /* The first glyph could be partially visible, in which case
18159 it->glyph_row->x will be negative. But we want the left
18160 truncation glyphs to be aligned at the left margin of the
18161 window, so we override the x coordinate at which the row
18163 it
->glyph_row
->x
= 0;
18164 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18166 w
+= g
->pixel_width
;
18169 if (g
- to
- tused
> 0)
18171 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18172 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18174 used
= it
->glyph_row
->used
[TEXT_AREA
];
18175 if (it
->glyph_row
->truncated_on_right_p
18176 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18177 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18180 int extra
= w
- it
->truncation_pixel_width
;
18182 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18189 /* There may be padding glyphs left over. Overwrite them too. */
18190 if (!FRAME_WINDOW_P (it
->f
))
18192 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18194 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18201 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18205 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18207 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18208 that back to front. */
18209 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18210 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18211 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18212 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18213 if (FRAME_WINDOW_P (it
->f
))
18216 struct glyph
*g
= to
;
18218 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18220 w
+= g
->pixel_width
;
18223 if (to
- g
- tused
> 0)
18225 if (it
->glyph_row
->truncated_on_right_p
18226 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18227 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18229 int extra
= w
- it
->truncation_pixel_width
;
18231 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18235 while (from
>= end
&& to
>= toend
)
18237 if (!FRAME_WINDOW_P (it
->f
))
18239 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18242 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18243 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18244 while (from
>= end
&& to
>= toend
)
18250 /* Need to free some room before prepending additional
18252 int move_by
= from
- end
+ 1;
18253 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18254 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18256 for ( ; g
>= g0
; g
--)
18258 while (from
>= end
)
18260 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18265 /* Compute the hash code for ROW. */
18267 row_hash (struct glyph_row
*row
)
18270 unsigned hashval
= 0;
18272 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18273 for (k
= 0; k
< row
->used
[area
]; ++k
)
18274 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18275 + row
->glyphs
[area
][k
].u
.val
18276 + row
->glyphs
[area
][k
].face_id
18277 + row
->glyphs
[area
][k
].padding_p
18278 + (row
->glyphs
[area
][k
].type
<< 2));
18283 /* Compute the pixel height and width of IT->glyph_row.
18285 Most of the time, ascent and height of a display line will be equal
18286 to the max_ascent and max_height values of the display iterator
18287 structure. This is not the case if
18289 1. We hit ZV without displaying anything. In this case, max_ascent
18290 and max_height will be zero.
18292 2. We have some glyphs that don't contribute to the line height.
18293 (The glyph row flag contributes_to_line_height_p is for future
18294 pixmap extensions).
18296 The first case is easily covered by using default values because in
18297 these cases, the line height does not really matter, except that it
18298 must not be zero. */
18301 compute_line_metrics (struct it
*it
)
18303 struct glyph_row
*row
= it
->glyph_row
;
18305 if (FRAME_WINDOW_P (it
->f
))
18307 int i
, min_y
, max_y
;
18309 /* The line may consist of one space only, that was added to
18310 place the cursor on it. If so, the row's height hasn't been
18312 if (row
->height
== 0)
18314 if (it
->max_ascent
+ it
->max_descent
== 0)
18315 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18316 row
->ascent
= it
->max_ascent
;
18317 row
->height
= it
->max_ascent
+ it
->max_descent
;
18318 row
->phys_ascent
= it
->max_phys_ascent
;
18319 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18320 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18323 /* Compute the width of this line. */
18324 row
->pixel_width
= row
->x
;
18325 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18326 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18328 eassert (row
->pixel_width
>= 0);
18329 eassert (row
->ascent
>= 0 && row
->height
> 0);
18331 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18332 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18334 /* If first line's physical ascent is larger than its logical
18335 ascent, use the physical ascent, and make the row taller.
18336 This makes accented characters fully visible. */
18337 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18338 && row
->phys_ascent
> row
->ascent
)
18340 row
->height
+= row
->phys_ascent
- row
->ascent
;
18341 row
->ascent
= row
->phys_ascent
;
18344 /* Compute how much of the line is visible. */
18345 row
->visible_height
= row
->height
;
18347 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18348 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18350 if (row
->y
< min_y
)
18351 row
->visible_height
-= min_y
- row
->y
;
18352 if (row
->y
+ row
->height
> max_y
)
18353 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18357 row
->pixel_width
= row
->used
[TEXT_AREA
];
18358 if (row
->continued_p
)
18359 row
->pixel_width
-= it
->continuation_pixel_width
;
18360 else if (row
->truncated_on_right_p
)
18361 row
->pixel_width
-= it
->truncation_pixel_width
;
18362 row
->ascent
= row
->phys_ascent
= 0;
18363 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18364 row
->extra_line_spacing
= 0;
18367 /* Compute a hash code for this row. */
18368 row
->hash
= row_hash (row
);
18370 it
->max_ascent
= it
->max_descent
= 0;
18371 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18375 /* Append one space to the glyph row of iterator IT if doing a
18376 window-based redisplay. The space has the same face as
18377 IT->face_id. Value is non-zero if a space was added.
18379 This function is called to make sure that there is always one glyph
18380 at the end of a glyph row that the cursor can be set on under
18381 window-systems. (If there weren't such a glyph we would not know
18382 how wide and tall a box cursor should be displayed).
18384 At the same time this space let's a nicely handle clearing to the
18385 end of the line if the row ends in italic text. */
18388 append_space_for_newline (struct it
*it
, int default_face_p
)
18390 if (FRAME_WINDOW_P (it
->f
))
18392 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18394 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18395 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18397 /* Save some values that must not be changed.
18398 Must save IT->c and IT->len because otherwise
18399 ITERATOR_AT_END_P wouldn't work anymore after
18400 append_space_for_newline has been called. */
18401 enum display_element_type saved_what
= it
->what
;
18402 int saved_c
= it
->c
, saved_len
= it
->len
;
18403 int saved_char_to_display
= it
->char_to_display
;
18404 int saved_x
= it
->current_x
;
18405 int saved_face_id
= it
->face_id
;
18406 int saved_box_end
= it
->end_of_box_run_p
;
18407 struct text_pos saved_pos
;
18408 Lisp_Object saved_object
;
18411 saved_object
= it
->object
;
18412 saved_pos
= it
->position
;
18414 it
->what
= IT_CHARACTER
;
18415 memset (&it
->position
, 0, sizeof it
->position
);
18416 it
->object
= make_number (0);
18417 it
->c
= it
->char_to_display
= ' ';
18420 /* If the default face was remapped, be sure to use the
18421 remapped face for the appended newline. */
18422 if (default_face_p
)
18423 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18424 else if (it
->face_before_selective_p
)
18425 it
->face_id
= it
->saved_face_id
;
18426 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18427 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18428 /* In R2L rows, we will prepend a stretch glyph that will
18429 have the end_of_box_run_p flag set for it, so there's no
18430 need for the appended newline glyph to have that flag
18432 if (it
->glyph_row
->reversed_p
18433 /* But if the appended newline glyph goes all the way to
18434 the end of the row, there will be no stretch glyph,
18435 so leave the box flag set. */
18436 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18437 it
->end_of_box_run_p
= 0;
18439 PRODUCE_GLYPHS (it
);
18441 it
->override_ascent
= -1;
18442 it
->constrain_row_ascent_descent_p
= 0;
18443 it
->current_x
= saved_x
;
18444 it
->object
= saved_object
;
18445 it
->position
= saved_pos
;
18446 it
->what
= saved_what
;
18447 it
->face_id
= saved_face_id
;
18448 it
->len
= saved_len
;
18450 it
->char_to_display
= saved_char_to_display
;
18451 it
->end_of_box_run_p
= saved_box_end
;
18460 /* Extend the face of the last glyph in the text area of IT->glyph_row
18461 to the end of the display line. Called from display_line. If the
18462 glyph row is empty, add a space glyph to it so that we know the
18463 face to draw. Set the glyph row flag fill_line_p. If the glyph
18464 row is R2L, prepend a stretch glyph to cover the empty space to the
18465 left of the leftmost glyph. */
18468 extend_face_to_end_of_line (struct it
*it
)
18470 struct face
*face
, *default_face
;
18471 struct frame
*f
= it
->f
;
18473 /* If line is already filled, do nothing. Non window-system frames
18474 get a grace of one more ``pixel'' because their characters are
18475 1-``pixel'' wide, so they hit the equality too early. This grace
18476 is needed only for R2L rows that are not continued, to produce
18477 one extra blank where we could display the cursor. */
18478 if (it
->current_x
>= it
->last_visible_x
18479 + (!FRAME_WINDOW_P (f
)
18480 && it
->glyph_row
->reversed_p
18481 && !it
->glyph_row
->continued_p
))
18484 /* The default face, possibly remapped. */
18485 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18487 /* Face extension extends the background and box of IT->face_id
18488 to the end of the line. If the background equals the background
18489 of the frame, we don't have to do anything. */
18490 if (it
->face_before_selective_p
)
18491 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18493 face
= FACE_FROM_ID (f
, it
->face_id
);
18495 if (FRAME_WINDOW_P (f
)
18496 && it
->glyph_row
->displays_text_p
18497 && face
->box
== FACE_NO_BOX
18498 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18500 && !it
->glyph_row
->reversed_p
)
18503 /* Set the glyph row flag indicating that the face of the last glyph
18504 in the text area has to be drawn to the end of the text area. */
18505 it
->glyph_row
->fill_line_p
= 1;
18507 /* If current character of IT is not ASCII, make sure we have the
18508 ASCII face. This will be automatically undone the next time
18509 get_next_display_element returns a multibyte character. Note
18510 that the character will always be single byte in unibyte
18512 if (!ASCII_CHAR_P (it
->c
))
18514 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18517 if (FRAME_WINDOW_P (f
))
18519 /* If the row is empty, add a space with the current face of IT,
18520 so that we know which face to draw. */
18521 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18523 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18524 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18525 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18527 #ifdef HAVE_WINDOW_SYSTEM
18528 if (it
->glyph_row
->reversed_p
)
18530 /* Prepend a stretch glyph to the row, such that the
18531 rightmost glyph will be drawn flushed all the way to the
18532 right margin of the window. The stretch glyph that will
18533 occupy the empty space, if any, to the left of the
18535 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18536 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18537 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18539 int row_width
, stretch_ascent
, stretch_width
;
18540 struct text_pos saved_pos
;
18541 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18543 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18544 row_width
+= g
->pixel_width
;
18545 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18546 if (stretch_width
> 0)
18549 (((it
->ascent
+ it
->descent
)
18550 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18551 saved_pos
= it
->position
;
18552 memset (&it
->position
, 0, sizeof it
->position
);
18553 saved_avoid_cursor
= it
->avoid_cursor_p
;
18554 it
->avoid_cursor_p
= 1;
18555 saved_face_id
= it
->face_id
;
18556 saved_box_start
= it
->start_of_box_run_p
;
18557 /* The last row's stretch glyph should get the default
18558 face, to avoid painting the rest of the window with
18559 the region face, if the region ends at ZV. */
18560 if (it
->glyph_row
->ends_at_zv_p
)
18561 it
->face_id
= default_face
->id
;
18563 it
->face_id
= face
->id
;
18564 it
->start_of_box_run_p
= 0;
18565 append_stretch_glyph (it
, make_number (0), stretch_width
,
18566 it
->ascent
+ it
->descent
, stretch_ascent
);
18567 it
->position
= saved_pos
;
18568 it
->avoid_cursor_p
= saved_avoid_cursor
;
18569 it
->face_id
= saved_face_id
;
18570 it
->start_of_box_run_p
= saved_box_start
;
18573 #endif /* HAVE_WINDOW_SYSTEM */
18577 /* Save some values that must not be changed. */
18578 int saved_x
= it
->current_x
;
18579 struct text_pos saved_pos
;
18580 Lisp_Object saved_object
;
18581 enum display_element_type saved_what
= it
->what
;
18582 int saved_face_id
= it
->face_id
;
18584 saved_object
= it
->object
;
18585 saved_pos
= it
->position
;
18587 it
->what
= IT_CHARACTER
;
18588 memset (&it
->position
, 0, sizeof it
->position
);
18589 it
->object
= make_number (0);
18590 it
->c
= it
->char_to_display
= ' ';
18592 /* The last row's blank glyphs should get the default face, to
18593 avoid painting the rest of the window with the region face,
18594 if the region ends at ZV. */
18595 if (it
->glyph_row
->ends_at_zv_p
)
18596 it
->face_id
= default_face
->id
;
18598 it
->face_id
= face
->id
;
18600 PRODUCE_GLYPHS (it
);
18602 while (it
->current_x
<= it
->last_visible_x
)
18603 PRODUCE_GLYPHS (it
);
18605 /* Don't count these blanks really. It would let us insert a left
18606 truncation glyph below and make us set the cursor on them, maybe. */
18607 it
->current_x
= saved_x
;
18608 it
->object
= saved_object
;
18609 it
->position
= saved_pos
;
18610 it
->what
= saved_what
;
18611 it
->face_id
= saved_face_id
;
18616 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18617 trailing whitespace. */
18620 trailing_whitespace_p (ptrdiff_t charpos
)
18622 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18625 while (bytepos
< ZV_BYTE
18626 && (c
= FETCH_CHAR (bytepos
),
18627 c
== ' ' || c
== '\t'))
18630 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18632 if (bytepos
!= PT_BYTE
)
18639 /* Highlight trailing whitespace, if any, in ROW. */
18642 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18644 int used
= row
->used
[TEXT_AREA
];
18648 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18649 struct glyph
*glyph
= start
+ used
- 1;
18651 if (row
->reversed_p
)
18653 /* Right-to-left rows need to be processed in the opposite
18654 direction, so swap the edge pointers. */
18656 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18659 /* Skip over glyphs inserted to display the cursor at the
18660 end of a line, for extending the face of the last glyph
18661 to the end of the line on terminals, and for truncation
18662 and continuation glyphs. */
18663 if (!row
->reversed_p
)
18665 while (glyph
>= start
18666 && glyph
->type
== CHAR_GLYPH
18667 && INTEGERP (glyph
->object
))
18672 while (glyph
<= start
18673 && glyph
->type
== CHAR_GLYPH
18674 && INTEGERP (glyph
->object
))
18678 /* If last glyph is a space or stretch, and it's trailing
18679 whitespace, set the face of all trailing whitespace glyphs in
18680 IT->glyph_row to `trailing-whitespace'. */
18681 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18682 && BUFFERP (glyph
->object
)
18683 && (glyph
->type
== STRETCH_GLYPH
18684 || (glyph
->type
== CHAR_GLYPH
18685 && glyph
->u
.ch
== ' '))
18686 && trailing_whitespace_p (glyph
->charpos
))
18688 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18692 if (!row
->reversed_p
)
18694 while (glyph
>= start
18695 && BUFFERP (glyph
->object
)
18696 && (glyph
->type
== STRETCH_GLYPH
18697 || (glyph
->type
== CHAR_GLYPH
18698 && glyph
->u
.ch
== ' ')))
18699 (glyph
--)->face_id
= face_id
;
18703 while (glyph
<= start
18704 && BUFFERP (glyph
->object
)
18705 && (glyph
->type
== STRETCH_GLYPH
18706 || (glyph
->type
== CHAR_GLYPH
18707 && glyph
->u
.ch
== ' ')))
18708 (glyph
++)->face_id
= face_id
;
18715 /* Value is non-zero if glyph row ROW should be
18716 used to hold the cursor. */
18719 cursor_row_p (struct glyph_row
*row
)
18723 if (PT
== CHARPOS (row
->end
.pos
)
18724 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18726 /* Suppose the row ends on a string.
18727 Unless the row is continued, that means it ends on a newline
18728 in the string. If it's anything other than a display string
18729 (e.g., a before-string from an overlay), we don't want the
18730 cursor there. (This heuristic seems to give the optimal
18731 behavior for the various types of multi-line strings.)
18732 One exception: if the string has `cursor' property on one of
18733 its characters, we _do_ want the cursor there. */
18734 if (CHARPOS (row
->end
.string_pos
) >= 0)
18736 if (row
->continued_p
)
18740 /* Check for `display' property. */
18741 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18742 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18743 struct glyph
*glyph
;
18746 for (glyph
= end
; glyph
>= beg
; --glyph
)
18747 if (STRINGP (glyph
->object
))
18750 = Fget_char_property (make_number (PT
),
18754 && display_prop_string_p (prop
, glyph
->object
));
18755 /* If there's a `cursor' property on one of the
18756 string's characters, this row is a cursor row,
18757 even though this is not a display string. */
18760 Lisp_Object s
= glyph
->object
;
18762 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18764 ptrdiff_t gpos
= glyph
->charpos
;
18766 if (!NILP (Fget_char_property (make_number (gpos
),
18778 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18780 /* If the row ends in middle of a real character,
18781 and the line is continued, we want the cursor here.
18782 That's because CHARPOS (ROW->end.pos) would equal
18783 PT if PT is before the character. */
18784 if (!row
->ends_in_ellipsis_p
)
18785 result
= row
->continued_p
;
18787 /* If the row ends in an ellipsis, then
18788 CHARPOS (ROW->end.pos) will equal point after the
18789 invisible text. We want that position to be displayed
18790 after the ellipsis. */
18793 /* If the row ends at ZV, display the cursor at the end of that
18794 row instead of at the start of the row below. */
18795 else if (row
->ends_at_zv_p
)
18806 /* Push the property PROP so that it will be rendered at the current
18807 position in IT. Return 1 if PROP was successfully pushed, 0
18808 otherwise. Called from handle_line_prefix to handle the
18809 `line-prefix' and `wrap-prefix' properties. */
18812 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18814 struct text_pos pos
=
18815 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18817 eassert (it
->method
== GET_FROM_BUFFER
18818 || it
->method
== GET_FROM_DISPLAY_VECTOR
18819 || it
->method
== GET_FROM_STRING
);
18821 /* We need to save the current buffer/string position, so it will be
18822 restored by pop_it, because iterate_out_of_display_property
18823 depends on that being set correctly, but some situations leave
18824 it->position not yet set when this function is called. */
18825 push_it (it
, &pos
);
18827 if (STRINGP (prop
))
18829 if (SCHARS (prop
) == 0)
18836 it
->string_from_prefix_prop_p
= 1;
18837 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18838 it
->current
.overlay_string_index
= -1;
18839 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18840 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18841 it
->method
= GET_FROM_STRING
;
18842 it
->stop_charpos
= 0;
18844 it
->base_level_stop
= 0;
18846 /* Force paragraph direction to be that of the parent
18848 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18849 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18851 it
->paragraph_embedding
= L2R
;
18853 /* Set up the bidi iterator for this display string. */
18856 it
->bidi_it
.string
.lstring
= it
->string
;
18857 it
->bidi_it
.string
.s
= NULL
;
18858 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18859 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18860 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18861 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18862 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18865 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18867 it
->method
= GET_FROM_STRETCH
;
18870 #ifdef HAVE_WINDOW_SYSTEM
18871 else if (IMAGEP (prop
))
18873 it
->what
= IT_IMAGE
;
18874 it
->image_id
= lookup_image (it
->f
, prop
);
18875 it
->method
= GET_FROM_IMAGE
;
18877 #endif /* HAVE_WINDOW_SYSTEM */
18880 pop_it (it
); /* bogus display property, give up */
18887 /* Return the character-property PROP at the current position in IT. */
18890 get_it_property (struct it
*it
, Lisp_Object prop
)
18892 Lisp_Object position
;
18894 if (STRINGP (it
->object
))
18895 position
= make_number (IT_STRING_CHARPOS (*it
));
18896 else if (BUFFERP (it
->object
))
18897 position
= make_number (IT_CHARPOS (*it
));
18901 return Fget_char_property (position
, prop
, it
->object
);
18904 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18907 handle_line_prefix (struct it
*it
)
18909 Lisp_Object prefix
;
18911 if (it
->continuation_lines_width
> 0)
18913 prefix
= get_it_property (it
, Qwrap_prefix
);
18915 prefix
= Vwrap_prefix
;
18919 prefix
= get_it_property (it
, Qline_prefix
);
18921 prefix
= Vline_prefix
;
18923 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18925 /* If the prefix is wider than the window, and we try to wrap
18926 it, it would acquire its own wrap prefix, and so on till the
18927 iterator stack overflows. So, don't wrap the prefix. */
18928 it
->line_wrap
= TRUNCATE
;
18929 it
->avoid_cursor_p
= 1;
18935 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18936 only for R2L lines from display_line and display_string, when they
18937 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18938 the line/string needs to be continued on the next glyph row. */
18940 unproduce_glyphs (struct it
*it
, int n
)
18942 struct glyph
*glyph
, *end
;
18944 eassert (it
->glyph_row
);
18945 eassert (it
->glyph_row
->reversed_p
);
18946 eassert (it
->area
== TEXT_AREA
);
18947 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18949 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18950 n
= it
->glyph_row
->used
[TEXT_AREA
];
18951 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18952 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18953 for ( ; glyph
< end
; glyph
++)
18954 glyph
[-n
] = *glyph
;
18957 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18958 and ROW->maxpos. */
18960 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18961 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18962 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18964 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18965 lines' rows is implemented for bidi-reordered rows. */
18967 /* ROW->minpos is the value of min_pos, the minimal buffer position
18968 we have in ROW, or ROW->start.pos if that is smaller. */
18969 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18970 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18972 /* We didn't find buffer positions smaller than ROW->start, or
18973 didn't find _any_ valid buffer positions in any of the glyphs,
18974 so we must trust the iterator's computed positions. */
18975 row
->minpos
= row
->start
.pos
;
18978 max_pos
= CHARPOS (it
->current
.pos
);
18979 max_bpos
= BYTEPOS (it
->current
.pos
);
18982 /* Here are the various use-cases for ending the row, and the
18983 corresponding values for ROW->maxpos:
18985 Line ends in a newline from buffer eol_pos + 1
18986 Line is continued from buffer max_pos + 1
18987 Line is truncated on right it->current.pos
18988 Line ends in a newline from string max_pos + 1(*)
18989 (*) + 1 only when line ends in a forward scan
18990 Line is continued from string max_pos
18991 Line is continued from display vector max_pos
18992 Line is entirely from a string min_pos == max_pos
18993 Line is entirely from a display vector min_pos == max_pos
18994 Line that ends at ZV ZV
18996 If you discover other use-cases, please add them here as
18998 if (row
->ends_at_zv_p
)
18999 row
->maxpos
= it
->current
.pos
;
19000 else if (row
->used
[TEXT_AREA
])
19002 int seen_this_string
= 0;
19003 struct glyph_row
*r1
= row
- 1;
19005 /* Did we see the same display string on the previous row? */
19006 if (STRINGP (it
->object
)
19007 /* this is not the first row */
19008 && row
> it
->w
->desired_matrix
->rows
19009 /* previous row is not the header line */
19010 && !r1
->mode_line_p
19011 /* previous row also ends in a newline from a string */
19012 && r1
->ends_in_newline_from_string_p
)
19014 struct glyph
*start
, *end
;
19016 /* Search for the last glyph of the previous row that came
19017 from buffer or string. Depending on whether the row is
19018 L2R or R2L, we need to process it front to back or the
19019 other way round. */
19020 if (!r1
->reversed_p
)
19022 start
= r1
->glyphs
[TEXT_AREA
];
19023 end
= start
+ r1
->used
[TEXT_AREA
];
19024 /* Glyphs inserted by redisplay have an integer (zero)
19025 as their object. */
19027 && INTEGERP ((end
- 1)->object
)
19028 && (end
- 1)->charpos
<= 0)
19032 if (EQ ((end
- 1)->object
, it
->object
))
19033 seen_this_string
= 1;
19036 /* If all the glyphs of the previous row were inserted
19037 by redisplay, it means the previous row was
19038 produced from a single newline, which is only
19039 possible if that newline came from the same string
19040 as the one which produced this ROW. */
19041 seen_this_string
= 1;
19045 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19046 start
= end
+ r1
->used
[TEXT_AREA
];
19048 && INTEGERP ((end
+ 1)->object
)
19049 && (end
+ 1)->charpos
<= 0)
19053 if (EQ ((end
+ 1)->object
, it
->object
))
19054 seen_this_string
= 1;
19057 seen_this_string
= 1;
19060 /* Take note of each display string that covers a newline only
19061 once, the first time we see it. This is for when a display
19062 string includes more than one newline in it. */
19063 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19065 /* If we were scanning the buffer forward when we displayed
19066 the string, we want to account for at least one buffer
19067 position that belongs to this row (position covered by
19068 the display string), so that cursor positioning will
19069 consider this row as a candidate when point is at the end
19070 of the visual line represented by this row. This is not
19071 required when scanning back, because max_pos will already
19072 have a much larger value. */
19073 if (CHARPOS (row
->end
.pos
) > max_pos
)
19074 INC_BOTH (max_pos
, max_bpos
);
19075 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19077 else if (CHARPOS (it
->eol_pos
) > 0)
19078 SET_TEXT_POS (row
->maxpos
,
19079 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19080 else if (row
->continued_p
)
19082 /* If max_pos is different from IT's current position, it
19083 means IT->method does not belong to the display element
19084 at max_pos. However, it also means that the display
19085 element at max_pos was displayed in its entirety on this
19086 line, which is equivalent to saying that the next line
19087 starts at the next buffer position. */
19088 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19089 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19092 INC_BOTH (max_pos
, max_bpos
);
19093 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19096 else if (row
->truncated_on_right_p
)
19097 /* display_line already called reseat_at_next_visible_line_start,
19098 which puts the iterator at the beginning of the next line, in
19099 the logical order. */
19100 row
->maxpos
= it
->current
.pos
;
19101 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19102 /* A line that is entirely from a string/image/stretch... */
19103 row
->maxpos
= row
->minpos
;
19108 row
->maxpos
= it
->current
.pos
;
19111 /* Construct the glyph row IT->glyph_row in the desired matrix of
19112 IT->w from text at the current position of IT. See dispextern.h
19113 for an overview of struct it. Value is non-zero if
19114 IT->glyph_row displays text, as opposed to a line displaying ZV
19118 display_line (struct it
*it
)
19120 struct glyph_row
*row
= it
->glyph_row
;
19121 Lisp_Object overlay_arrow_string
;
19123 void *wrap_data
= NULL
;
19124 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19125 int wrap_row_used
= -1;
19126 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19127 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19128 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19129 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19130 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19132 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19133 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19135 /* We always start displaying at hpos zero even if hscrolled. */
19136 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19138 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19139 >= it
->w
->desired_matrix
->nrows
)
19141 it
->w
->nrows_scale_factor
++;
19142 fonts_changed_p
= 1;
19146 /* Is IT->w showing the region? */
19147 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? -1 : 0;
19149 /* Clear the result glyph row and enable it. */
19150 prepare_desired_row (row
);
19152 row
->y
= it
->current_y
;
19153 row
->start
= it
->start
;
19154 row
->continuation_lines_width
= it
->continuation_lines_width
;
19155 row
->displays_text_p
= 1;
19156 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19157 it
->starts_in_middle_of_char_p
= 0;
19159 /* Arrange the overlays nicely for our purposes. Usually, we call
19160 display_line on only one line at a time, in which case this
19161 can't really hurt too much, or we call it on lines which appear
19162 one after another in the buffer, in which case all calls to
19163 recenter_overlay_lists but the first will be pretty cheap. */
19164 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19166 /* Move over display elements that are not visible because we are
19167 hscrolled. This may stop at an x-position < IT->first_visible_x
19168 if the first glyph is partially visible or if we hit a line end. */
19169 if (it
->current_x
< it
->first_visible_x
)
19171 enum move_it_result move_result
;
19173 this_line_min_pos
= row
->start
.pos
;
19174 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19175 MOVE_TO_POS
| MOVE_TO_X
);
19176 /* If we are under a large hscroll, move_it_in_display_line_to
19177 could hit the end of the line without reaching
19178 it->first_visible_x. Pretend that we did reach it. This is
19179 especially important on a TTY, where we will call
19180 extend_face_to_end_of_line, which needs to know how many
19181 blank glyphs to produce. */
19182 if (it
->current_x
< it
->first_visible_x
19183 && (move_result
== MOVE_NEWLINE_OR_CR
19184 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19185 it
->current_x
= it
->first_visible_x
;
19187 /* Record the smallest positions seen while we moved over
19188 display elements that are not visible. This is needed by
19189 redisplay_internal for optimizing the case where the cursor
19190 stays inside the same line. The rest of this function only
19191 considers positions that are actually displayed, so
19192 RECORD_MAX_MIN_POS will not otherwise record positions that
19193 are hscrolled to the left of the left edge of the window. */
19194 min_pos
= CHARPOS (this_line_min_pos
);
19195 min_bpos
= BYTEPOS (this_line_min_pos
);
19199 /* We only do this when not calling `move_it_in_display_line_to'
19200 above, because move_it_in_display_line_to calls
19201 handle_line_prefix itself. */
19202 handle_line_prefix (it
);
19205 /* Get the initial row height. This is either the height of the
19206 text hscrolled, if there is any, or zero. */
19207 row
->ascent
= it
->max_ascent
;
19208 row
->height
= it
->max_ascent
+ it
->max_descent
;
19209 row
->phys_ascent
= it
->max_phys_ascent
;
19210 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19211 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19213 /* Utility macro to record max and min buffer positions seen until now. */
19214 #define RECORD_MAX_MIN_POS(IT) \
19217 int composition_p = !STRINGP ((IT)->string) \
19218 && ((IT)->what == IT_COMPOSITION); \
19219 ptrdiff_t current_pos = \
19220 composition_p ? (IT)->cmp_it.charpos \
19221 : IT_CHARPOS (*(IT)); \
19222 ptrdiff_t current_bpos = \
19223 composition_p ? CHAR_TO_BYTE (current_pos) \
19224 : IT_BYTEPOS (*(IT)); \
19225 if (current_pos < min_pos) \
19227 min_pos = current_pos; \
19228 min_bpos = current_bpos; \
19230 if (IT_CHARPOS (*it) > max_pos) \
19232 max_pos = IT_CHARPOS (*it); \
19233 max_bpos = IT_BYTEPOS (*it); \
19238 /* Loop generating characters. The loop is left with IT on the next
19239 character to display. */
19242 int n_glyphs_before
, hpos_before
, x_before
;
19244 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19246 /* Retrieve the next thing to display. Value is zero if end of
19248 if (!get_next_display_element (it
))
19250 /* Maybe add a space at the end of this line that is used to
19251 display the cursor there under X. Set the charpos of the
19252 first glyph of blank lines not corresponding to any text
19254 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19255 row
->exact_window_width_line_p
= 1;
19256 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19257 || row
->used
[TEXT_AREA
] == 0)
19259 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19260 row
->displays_text_p
= 0;
19262 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19263 && (!MINI_WINDOW_P (it
->w
)
19264 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19265 row
->indicate_empty_line_p
= 1;
19268 it
->continuation_lines_width
= 0;
19269 row
->ends_at_zv_p
= 1;
19270 /* A row that displays right-to-left text must always have
19271 its last face extended all the way to the end of line,
19272 even if this row ends in ZV, because we still write to
19273 the screen left to right. We also need to extend the
19274 last face if the default face is remapped to some
19275 different face, otherwise the functions that clear
19276 portions of the screen will clear with the default face's
19277 background color. */
19278 if (row
->reversed_p
19279 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19280 extend_face_to_end_of_line (it
);
19284 /* Now, get the metrics of what we want to display. This also
19285 generates glyphs in `row' (which is IT->glyph_row). */
19286 n_glyphs_before
= row
->used
[TEXT_AREA
];
19289 /* Remember the line height so far in case the next element doesn't
19290 fit on the line. */
19291 if (it
->line_wrap
!= TRUNCATE
)
19293 ascent
= it
->max_ascent
;
19294 descent
= it
->max_descent
;
19295 phys_ascent
= it
->max_phys_ascent
;
19296 phys_descent
= it
->max_phys_descent
;
19298 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19300 if (IT_DISPLAYING_WHITESPACE (it
))
19304 SAVE_IT (wrap_it
, *it
, wrap_data
);
19306 wrap_row_used
= row
->used
[TEXT_AREA
];
19307 wrap_row_ascent
= row
->ascent
;
19308 wrap_row_height
= row
->height
;
19309 wrap_row_phys_ascent
= row
->phys_ascent
;
19310 wrap_row_phys_height
= row
->phys_height
;
19311 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19312 wrap_row_min_pos
= min_pos
;
19313 wrap_row_min_bpos
= min_bpos
;
19314 wrap_row_max_pos
= max_pos
;
19315 wrap_row_max_bpos
= max_bpos
;
19321 PRODUCE_GLYPHS (it
);
19323 /* If this display element was in marginal areas, continue with
19325 if (it
->area
!= TEXT_AREA
)
19327 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19328 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19329 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19330 row
->phys_height
= max (row
->phys_height
,
19331 it
->max_phys_ascent
+ it
->max_phys_descent
);
19332 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19333 it
->max_extra_line_spacing
);
19334 set_iterator_to_next (it
, 1);
19338 /* Does the display element fit on the line? If we truncate
19339 lines, we should draw past the right edge of the window. If
19340 we don't truncate, we want to stop so that we can display the
19341 continuation glyph before the right margin. If lines are
19342 continued, there are two possible strategies for characters
19343 resulting in more than 1 glyph (e.g. tabs): Display as many
19344 glyphs as possible in this line and leave the rest for the
19345 continuation line, or display the whole element in the next
19346 line. Original redisplay did the former, so we do it also. */
19347 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19348 hpos_before
= it
->hpos
;
19351 if (/* Not a newline. */
19353 /* Glyphs produced fit entirely in the line. */
19354 && it
->current_x
< it
->last_visible_x
)
19356 it
->hpos
+= nglyphs
;
19357 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19358 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19359 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19360 row
->phys_height
= max (row
->phys_height
,
19361 it
->max_phys_ascent
+ it
->max_phys_descent
);
19362 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19363 it
->max_extra_line_spacing
);
19364 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19365 row
->x
= x
- it
->first_visible_x
;
19366 /* Record the maximum and minimum buffer positions seen so
19367 far in glyphs that will be displayed by this row. */
19369 RECORD_MAX_MIN_POS (it
);
19374 struct glyph
*glyph
;
19376 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19378 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19379 new_x
= x
+ glyph
->pixel_width
;
19381 if (/* Lines are continued. */
19382 it
->line_wrap
!= TRUNCATE
19383 && (/* Glyph doesn't fit on the line. */
19384 new_x
> it
->last_visible_x
19385 /* Or it fits exactly on a window system frame. */
19386 || (new_x
== it
->last_visible_x
19387 && FRAME_WINDOW_P (it
->f
)
19388 && (row
->reversed_p
19389 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19390 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19392 /* End of a continued line. */
19395 || (new_x
== it
->last_visible_x
19396 && FRAME_WINDOW_P (it
->f
)
19397 && (row
->reversed_p
19398 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19399 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19401 /* Current glyph is the only one on the line or
19402 fits exactly on the line. We must continue
19403 the line because we can't draw the cursor
19404 after the glyph. */
19405 row
->continued_p
= 1;
19406 it
->current_x
= new_x
;
19407 it
->continuation_lines_width
+= new_x
;
19409 if (i
== nglyphs
- 1)
19411 /* If line-wrap is on, check if a previous
19412 wrap point was found. */
19413 if (wrap_row_used
> 0
19414 /* Even if there is a previous wrap
19415 point, continue the line here as
19416 usual, if (i) the previous character
19417 was a space or tab AND (ii) the
19418 current character is not. */
19420 || IT_DISPLAYING_WHITESPACE (it
)))
19423 /* Record the maximum and minimum buffer
19424 positions seen so far in glyphs that will be
19425 displayed by this row. */
19427 RECORD_MAX_MIN_POS (it
);
19428 set_iterator_to_next (it
, 1);
19429 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19431 if (!get_next_display_element (it
))
19433 row
->exact_window_width_line_p
= 1;
19434 it
->continuation_lines_width
= 0;
19435 row
->continued_p
= 0;
19436 row
->ends_at_zv_p
= 1;
19438 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19440 row
->continued_p
= 0;
19441 row
->exact_window_width_line_p
= 1;
19445 else if (it
->bidi_p
)
19446 RECORD_MAX_MIN_POS (it
);
19448 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19449 && !FRAME_WINDOW_P (it
->f
))
19451 /* A padding glyph that doesn't fit on this line.
19452 This means the whole character doesn't fit
19454 if (row
->reversed_p
)
19455 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19456 - n_glyphs_before
);
19457 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19459 /* Fill the rest of the row with continuation
19460 glyphs like in 20.x. */
19461 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19462 < row
->glyphs
[1 + TEXT_AREA
])
19463 produce_special_glyphs (it
, IT_CONTINUATION
);
19465 row
->continued_p
= 1;
19466 it
->current_x
= x_before
;
19467 it
->continuation_lines_width
+= x_before
;
19469 /* Restore the height to what it was before the
19470 element not fitting on the line. */
19471 it
->max_ascent
= ascent
;
19472 it
->max_descent
= descent
;
19473 it
->max_phys_ascent
= phys_ascent
;
19474 it
->max_phys_descent
= phys_descent
;
19476 else if (wrap_row_used
> 0)
19479 if (row
->reversed_p
)
19480 unproduce_glyphs (it
,
19481 row
->used
[TEXT_AREA
] - wrap_row_used
);
19482 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19483 it
->continuation_lines_width
+= wrap_x
;
19484 row
->used
[TEXT_AREA
] = wrap_row_used
;
19485 row
->ascent
= wrap_row_ascent
;
19486 row
->height
= wrap_row_height
;
19487 row
->phys_ascent
= wrap_row_phys_ascent
;
19488 row
->phys_height
= wrap_row_phys_height
;
19489 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19490 min_pos
= wrap_row_min_pos
;
19491 min_bpos
= wrap_row_min_bpos
;
19492 max_pos
= wrap_row_max_pos
;
19493 max_bpos
= wrap_row_max_bpos
;
19494 row
->continued_p
= 1;
19495 row
->ends_at_zv_p
= 0;
19496 row
->exact_window_width_line_p
= 0;
19497 it
->continuation_lines_width
+= x
;
19499 /* Make sure that a non-default face is extended
19500 up to the right margin of the window. */
19501 extend_face_to_end_of_line (it
);
19503 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19505 /* A TAB that extends past the right edge of the
19506 window. This produces a single glyph on
19507 window system frames. We leave the glyph in
19508 this row and let it fill the row, but don't
19509 consume the TAB. */
19510 if ((row
->reversed_p
19511 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19512 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19513 produce_special_glyphs (it
, IT_CONTINUATION
);
19514 it
->continuation_lines_width
+= it
->last_visible_x
;
19515 row
->ends_in_middle_of_char_p
= 1;
19516 row
->continued_p
= 1;
19517 glyph
->pixel_width
= it
->last_visible_x
- x
;
19518 it
->starts_in_middle_of_char_p
= 1;
19522 /* Something other than a TAB that draws past
19523 the right edge of the window. Restore
19524 positions to values before the element. */
19525 if (row
->reversed_p
)
19526 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19527 - (n_glyphs_before
+ i
));
19528 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19530 /* Display continuation glyphs. */
19531 it
->current_x
= x_before
;
19532 it
->continuation_lines_width
+= x
;
19533 if (!FRAME_WINDOW_P (it
->f
)
19534 || (row
->reversed_p
19535 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19536 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19537 produce_special_glyphs (it
, IT_CONTINUATION
);
19538 row
->continued_p
= 1;
19540 extend_face_to_end_of_line (it
);
19542 if (nglyphs
> 1 && i
> 0)
19544 row
->ends_in_middle_of_char_p
= 1;
19545 it
->starts_in_middle_of_char_p
= 1;
19548 /* Restore the height to what it was before the
19549 element not fitting on the line. */
19550 it
->max_ascent
= ascent
;
19551 it
->max_descent
= descent
;
19552 it
->max_phys_ascent
= phys_ascent
;
19553 it
->max_phys_descent
= phys_descent
;
19558 else if (new_x
> it
->first_visible_x
)
19560 /* Increment number of glyphs actually displayed. */
19563 /* Record the maximum and minimum buffer positions
19564 seen so far in glyphs that will be displayed by
19567 RECORD_MAX_MIN_POS (it
);
19569 if (x
< it
->first_visible_x
)
19570 /* Glyph is partially visible, i.e. row starts at
19571 negative X position. */
19572 row
->x
= x
- it
->first_visible_x
;
19576 /* Glyph is completely off the left margin of the
19577 window. This should not happen because of the
19578 move_it_in_display_line at the start of this
19579 function, unless the text display area of the
19580 window is empty. */
19581 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19584 /* Even if this display element produced no glyphs at all,
19585 we want to record its position. */
19586 if (it
->bidi_p
&& nglyphs
== 0)
19587 RECORD_MAX_MIN_POS (it
);
19589 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19590 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19591 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19592 row
->phys_height
= max (row
->phys_height
,
19593 it
->max_phys_ascent
+ it
->max_phys_descent
);
19594 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19595 it
->max_extra_line_spacing
);
19597 /* End of this display line if row is continued. */
19598 if (row
->continued_p
|| row
->ends_at_zv_p
)
19603 /* Is this a line end? If yes, we're also done, after making
19604 sure that a non-default face is extended up to the right
19605 margin of the window. */
19606 if (ITERATOR_AT_END_OF_LINE_P (it
))
19608 int used_before
= row
->used
[TEXT_AREA
];
19610 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19612 /* Add a space at the end of the line that is used to
19613 display the cursor there. */
19614 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19615 append_space_for_newline (it
, 0);
19617 /* Extend the face to the end of the line. */
19618 extend_face_to_end_of_line (it
);
19620 /* Make sure we have the position. */
19621 if (used_before
== 0)
19622 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19624 /* Record the position of the newline, for use in
19626 it
->eol_pos
= it
->current
.pos
;
19628 /* Consume the line end. This skips over invisible lines. */
19629 set_iterator_to_next (it
, 1);
19630 it
->continuation_lines_width
= 0;
19634 /* Proceed with next display element. Note that this skips
19635 over lines invisible because of selective display. */
19636 set_iterator_to_next (it
, 1);
19638 /* If we truncate lines, we are done when the last displayed
19639 glyphs reach past the right margin of the window. */
19640 if (it
->line_wrap
== TRUNCATE
19641 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19642 ? (it
->current_x
>= it
->last_visible_x
)
19643 : (it
->current_x
> it
->last_visible_x
)))
19645 /* Maybe add truncation glyphs. */
19646 if (!FRAME_WINDOW_P (it
->f
)
19647 || (row
->reversed_p
19648 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19649 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19653 if (!row
->reversed_p
)
19655 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19656 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19661 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19662 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19664 /* Remove any padding glyphs at the front of ROW, to
19665 make room for the truncation glyphs we will be
19666 adding below. The loop below always inserts at
19667 least one truncation glyph, so also remove the
19668 last glyph added to ROW. */
19669 unproduce_glyphs (it
, i
+ 1);
19670 /* Adjust i for the loop below. */
19671 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19674 it
->current_x
= x_before
;
19675 if (!FRAME_WINDOW_P (it
->f
))
19677 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19679 row
->used
[TEXT_AREA
] = i
;
19680 produce_special_glyphs (it
, IT_TRUNCATION
);
19685 row
->used
[TEXT_AREA
] = i
;
19686 produce_special_glyphs (it
, IT_TRUNCATION
);
19689 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19691 /* Don't truncate if we can overflow newline into fringe. */
19692 if (!get_next_display_element (it
))
19694 it
->continuation_lines_width
= 0;
19695 row
->ends_at_zv_p
= 1;
19696 row
->exact_window_width_line_p
= 1;
19699 if (ITERATOR_AT_END_OF_LINE_P (it
))
19701 row
->exact_window_width_line_p
= 1;
19702 goto at_end_of_line
;
19704 it
->current_x
= x_before
;
19707 row
->truncated_on_right_p
= 1;
19708 it
->continuation_lines_width
= 0;
19709 reseat_at_next_visible_line_start (it
, 0);
19710 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19711 it
->hpos
= hpos_before
;
19717 bidi_unshelve_cache (wrap_data
, 1);
19719 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19720 at the left window margin. */
19721 if (it
->first_visible_x
19722 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19724 if (!FRAME_WINDOW_P (it
->f
)
19725 || (row
->reversed_p
19726 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19727 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19728 insert_left_trunc_glyphs (it
);
19729 row
->truncated_on_left_p
= 1;
19732 /* Remember the position at which this line ends.
19734 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19735 cannot be before the call to find_row_edges below, since that is
19736 where these positions are determined. */
19737 row
->end
= it
->current
;
19740 row
->minpos
= row
->start
.pos
;
19741 row
->maxpos
= row
->end
.pos
;
19745 /* ROW->minpos and ROW->maxpos must be the smallest and
19746 `1 + the largest' buffer positions in ROW. But if ROW was
19747 bidi-reordered, these two positions can be anywhere in the
19748 row, so we must determine them now. */
19749 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19752 /* If the start of this line is the overlay arrow-position, then
19753 mark this glyph row as the one containing the overlay arrow.
19754 This is clearly a mess with variable size fonts. It would be
19755 better to let it be displayed like cursors under X. */
19756 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19757 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19758 !NILP (overlay_arrow_string
)))
19760 /* Overlay arrow in window redisplay is a fringe bitmap. */
19761 if (STRINGP (overlay_arrow_string
))
19763 struct glyph_row
*arrow_row
19764 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19765 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19766 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19767 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19768 struct glyph
*p2
, *end
;
19770 /* Copy the arrow glyphs. */
19771 while (glyph
< arrow_end
)
19774 /* Throw away padding glyphs. */
19776 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19777 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19783 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19788 eassert (INTEGERP (overlay_arrow_string
));
19789 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19791 overlay_arrow_seen
= 1;
19794 /* Highlight trailing whitespace. */
19795 if (!NILP (Vshow_trailing_whitespace
))
19796 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19798 /* Compute pixel dimensions of this line. */
19799 compute_line_metrics (it
);
19801 /* Implementation note: No changes in the glyphs of ROW or in their
19802 faces can be done past this point, because compute_line_metrics
19803 computes ROW's hash value and stores it within the glyph_row
19806 /* Record whether this row ends inside an ellipsis. */
19807 row
->ends_in_ellipsis_p
19808 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19809 && it
->ellipsis_p
);
19811 /* Save fringe bitmaps in this row. */
19812 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19813 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19814 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19815 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19817 it
->left_user_fringe_bitmap
= 0;
19818 it
->left_user_fringe_face_id
= 0;
19819 it
->right_user_fringe_bitmap
= 0;
19820 it
->right_user_fringe_face_id
= 0;
19822 /* Maybe set the cursor. */
19823 cvpos
= it
->w
->cursor
.vpos
;
19825 /* In bidi-reordered rows, keep checking for proper cursor
19826 position even if one has been found already, because buffer
19827 positions in such rows change non-linearly with ROW->VPOS,
19828 when a line is continued. One exception: when we are at ZV,
19829 display cursor on the first suitable glyph row, since all
19830 the empty rows after that also have their position set to ZV. */
19831 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19832 lines' rows is implemented for bidi-reordered rows. */
19834 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19835 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19836 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19837 && cursor_row_p (row
))
19838 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19840 /* Prepare for the next line. This line starts horizontally at (X
19841 HPOS) = (0 0). Vertical positions are incremented. As a
19842 convenience for the caller, IT->glyph_row is set to the next
19844 it
->current_x
= it
->hpos
= 0;
19845 it
->current_y
+= row
->height
;
19846 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19849 /* The next row should by default use the same value of the
19850 reversed_p flag as this one. set_iterator_to_next decides when
19851 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19852 the flag accordingly. */
19853 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19854 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19855 it
->start
= row
->end
;
19856 return row
->displays_text_p
;
19858 #undef RECORD_MAX_MIN_POS
19861 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19862 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19863 doc
: /* Return paragraph direction at point in BUFFER.
19864 Value is either `left-to-right' or `right-to-left'.
19865 If BUFFER is omitted or nil, it defaults to the current buffer.
19867 Paragraph direction determines how the text in the paragraph is displayed.
19868 In left-to-right paragraphs, text begins at the left margin of the window
19869 and the reading direction is generally left to right. In right-to-left
19870 paragraphs, text begins at the right margin and is read from right to left.
19872 See also `bidi-paragraph-direction'. */)
19873 (Lisp_Object buffer
)
19875 struct buffer
*buf
= current_buffer
;
19876 struct buffer
*old
= buf
;
19878 if (! NILP (buffer
))
19880 CHECK_BUFFER (buffer
);
19881 buf
= XBUFFER (buffer
);
19884 if (NILP (BVAR (buf
, bidi_display_reordering
))
19885 || NILP (BVAR (buf
, enable_multibyte_characters
))
19886 /* When we are loading loadup.el, the character property tables
19887 needed for bidi iteration are not yet available. */
19888 || !NILP (Vpurify_flag
))
19889 return Qleft_to_right
;
19890 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19891 return BVAR (buf
, bidi_paragraph_direction
);
19894 /* Determine the direction from buffer text. We could try to
19895 use current_matrix if it is up to date, but this seems fast
19896 enough as it is. */
19897 struct bidi_it itb
;
19898 ptrdiff_t pos
= BUF_PT (buf
);
19899 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19901 void *itb_data
= bidi_shelve_cache ();
19903 set_buffer_temp (buf
);
19904 /* bidi_paragraph_init finds the base direction of the paragraph
19905 by searching forward from paragraph start. We need the base
19906 direction of the current or _previous_ paragraph, so we need
19907 to make sure we are within that paragraph. To that end, find
19908 the previous non-empty line. */
19909 if (pos
>= ZV
&& pos
> BEGV
)
19912 bytepos
= CHAR_TO_BYTE (pos
);
19914 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19915 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19917 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19918 || c
== ' ' || c
== '\t' || c
== '\f')
19920 if (bytepos
<= BEGV_BYTE
)
19925 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19928 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19929 itb
.paragraph_dir
= NEUTRAL_DIR
;
19930 itb
.string
.s
= NULL
;
19931 itb
.string
.lstring
= Qnil
;
19932 itb
.string
.bufpos
= 0;
19933 itb
.string
.unibyte
= 0;
19934 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19935 bidi_unshelve_cache (itb_data
, 0);
19936 set_buffer_temp (old
);
19937 switch (itb
.paragraph_dir
)
19940 return Qleft_to_right
;
19943 return Qright_to_left
;
19953 /***********************************************************************
19955 ***********************************************************************/
19957 /* Redisplay the menu bar in the frame for window W.
19959 The menu bar of X frames that don't have X toolkit support is
19960 displayed in a special window W->frame->menu_bar_window.
19962 The menu bar of terminal frames is treated specially as far as
19963 glyph matrices are concerned. Menu bar lines are not part of
19964 windows, so the update is done directly on the frame matrix rows
19965 for the menu bar. */
19968 display_menu_bar (struct window
*w
)
19970 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19975 /* Don't do all this for graphical frames. */
19977 if (FRAME_W32_P (f
))
19980 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19986 if (FRAME_NS_P (f
))
19988 #endif /* HAVE_NS */
19990 #ifdef USE_X_TOOLKIT
19991 eassert (!FRAME_WINDOW_P (f
));
19992 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19993 it
.first_visible_x
= 0;
19994 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19995 #else /* not USE_X_TOOLKIT */
19996 if (FRAME_WINDOW_P (f
))
19998 /* Menu bar lines are displayed in the desired matrix of the
19999 dummy window menu_bar_window. */
20000 struct window
*menu_w
;
20001 eassert (WINDOWP (f
->menu_bar_window
));
20002 menu_w
= XWINDOW (f
->menu_bar_window
);
20003 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20005 it
.first_visible_x
= 0;
20006 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20010 /* This is a TTY frame, i.e. character hpos/vpos are used as
20012 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20014 it
.first_visible_x
= 0;
20015 it
.last_visible_x
= FRAME_COLS (f
);
20017 #endif /* not USE_X_TOOLKIT */
20019 /* FIXME: This should be controlled by a user option. See the
20020 comments in redisplay_tool_bar and display_mode_line about
20022 it
.paragraph_embedding
= L2R
;
20024 /* Clear all rows of the menu bar. */
20025 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20027 struct glyph_row
*row
= it
.glyph_row
+ i
;
20028 clear_glyph_row (row
);
20029 row
->enabled_p
= 1;
20030 row
->full_width_p
= 1;
20033 /* Display all items of the menu bar. */
20034 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20035 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20037 Lisp_Object string
;
20039 /* Stop at nil string. */
20040 string
= AREF (items
, i
+ 1);
20044 /* Remember where item was displayed. */
20045 ASET (items
, i
+ 3, make_number (it
.hpos
));
20047 /* Display the item, pad with one space. */
20048 if (it
.current_x
< it
.last_visible_x
)
20049 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20050 SCHARS (string
) + 1, 0, 0, -1);
20053 /* Fill out the line with spaces. */
20054 if (it
.current_x
< it
.last_visible_x
)
20055 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20057 /* Compute the total height of the lines. */
20058 compute_line_metrics (&it
);
20063 /***********************************************************************
20065 ***********************************************************************/
20067 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20068 FORCE is non-zero, redisplay mode lines unconditionally.
20069 Otherwise, redisplay only mode lines that are garbaged. Value is
20070 the number of windows whose mode lines were redisplayed. */
20073 redisplay_mode_lines (Lisp_Object window
, int force
)
20077 while (!NILP (window
))
20079 struct window
*w
= XWINDOW (window
);
20081 if (WINDOWP (w
->hchild
))
20082 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20083 else if (WINDOWP (w
->vchild
))
20084 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20086 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20087 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20089 struct text_pos lpoint
;
20090 struct buffer
*old
= current_buffer
;
20092 /* Set the window's buffer for the mode line display. */
20093 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20094 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20096 /* Point refers normally to the selected window. For any
20097 other window, set up appropriate value. */
20098 if (!EQ (window
, selected_window
))
20100 struct text_pos pt
;
20102 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20103 if (CHARPOS (pt
) < BEGV
)
20104 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20105 else if (CHARPOS (pt
) > (ZV
- 1))
20106 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20108 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20111 /* Display mode lines. */
20112 clear_glyph_matrix (w
->desired_matrix
);
20113 if (display_mode_lines (w
))
20116 w
->must_be_updated_p
= 1;
20119 /* Restore old settings. */
20120 set_buffer_internal_1 (old
);
20121 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20131 /* Display the mode and/or header line of window W. Value is the
20132 sum number of mode lines and header lines displayed. */
20135 display_mode_lines (struct window
*w
)
20137 Lisp_Object old_selected_window
= selected_window
;
20138 Lisp_Object old_selected_frame
= selected_frame
;
20139 Lisp_Object new_frame
= w
->frame
;
20140 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20143 selected_frame
= new_frame
;
20144 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20145 or window's point, then we'd need select_window_1 here as well. */
20146 XSETWINDOW (selected_window
, w
);
20147 XFRAME (new_frame
)->selected_window
= selected_window
;
20149 /* These will be set while the mode line specs are processed. */
20150 line_number_displayed
= 0;
20151 w
->column_number_displayed
= -1;
20153 if (WINDOW_WANTS_MODELINE_P (w
))
20155 struct window
*sel_w
= XWINDOW (old_selected_window
);
20157 /* Select mode line face based on the real selected window. */
20158 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20159 BVAR (current_buffer
, mode_line_format
));
20163 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20165 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20166 BVAR (current_buffer
, header_line_format
));
20170 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20171 selected_frame
= old_selected_frame
;
20172 selected_window
= old_selected_window
;
20177 /* Display mode or header line of window W. FACE_ID specifies which
20178 line to display; it is either MODE_LINE_FACE_ID or
20179 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20180 display. Value is the pixel height of the mode/header line
20184 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20188 ptrdiff_t count
= SPECPDL_INDEX ();
20190 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20191 /* Don't extend on a previously drawn mode-line.
20192 This may happen if called from pos_visible_p. */
20193 it
.glyph_row
->enabled_p
= 0;
20194 prepare_desired_row (it
.glyph_row
);
20196 it
.glyph_row
->mode_line_p
= 1;
20198 /* FIXME: This should be controlled by a user option. But
20199 supporting such an option is not trivial, since the mode line is
20200 made up of many separate strings. */
20201 it
.paragraph_embedding
= L2R
;
20203 record_unwind_protect (unwind_format_mode_line
,
20204 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20206 mode_line_target
= MODE_LINE_DISPLAY
;
20208 /* Temporarily make frame's keyboard the current kboard so that
20209 kboard-local variables in the mode_line_format will get the right
20211 push_kboard (FRAME_KBOARD (it
.f
));
20212 record_unwind_save_match_data ();
20213 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20216 unbind_to (count
, Qnil
);
20218 /* Fill up with spaces. */
20219 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20221 compute_line_metrics (&it
);
20222 it
.glyph_row
->full_width_p
= 1;
20223 it
.glyph_row
->continued_p
= 0;
20224 it
.glyph_row
->truncated_on_left_p
= 0;
20225 it
.glyph_row
->truncated_on_right_p
= 0;
20227 /* Make a 3D mode-line have a shadow at its right end. */
20228 face
= FACE_FROM_ID (it
.f
, face_id
);
20229 extend_face_to_end_of_line (&it
);
20230 if (face
->box
!= FACE_NO_BOX
)
20232 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20233 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20234 last
->right_box_line_p
= 1;
20237 return it
.glyph_row
->height
;
20240 /* Move element ELT in LIST to the front of LIST.
20241 Return the updated list. */
20244 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20246 register Lisp_Object tail
, prev
;
20247 register Lisp_Object tem
;
20251 while (CONSP (tail
))
20257 /* Splice out the link TAIL. */
20259 list
= XCDR (tail
);
20261 Fsetcdr (prev
, XCDR (tail
));
20263 /* Now make it the first. */
20264 Fsetcdr (tail
, list
);
20269 tail
= XCDR (tail
);
20273 /* Not found--return unchanged LIST. */
20277 /* Contribute ELT to the mode line for window IT->w. How it
20278 translates into text depends on its data type.
20280 IT describes the display environment in which we display, as usual.
20282 DEPTH is the depth in recursion. It is used to prevent
20283 infinite recursion here.
20285 FIELD_WIDTH is the number of characters the display of ELT should
20286 occupy in the mode line, and PRECISION is the maximum number of
20287 characters to display from ELT's representation. See
20288 display_string for details.
20290 Returns the hpos of the end of the text generated by ELT.
20292 PROPS is a property list to add to any string we encounter.
20294 If RISKY is nonzero, remove (disregard) any properties in any string
20295 we encounter, and ignore :eval and :propertize.
20297 The global variable `mode_line_target' determines whether the
20298 output is passed to `store_mode_line_noprop',
20299 `store_mode_line_string', or `display_string'. */
20302 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20303 Lisp_Object elt
, Lisp_Object props
, int risky
)
20305 int n
= 0, field
, prec
;
20310 elt
= build_string ("*too-deep*");
20314 switch (XTYPE (elt
))
20318 /* A string: output it and check for %-constructs within it. */
20320 ptrdiff_t offset
= 0;
20322 if (SCHARS (elt
) > 0
20323 && (!NILP (props
) || risky
))
20325 Lisp_Object oprops
, aelt
;
20326 oprops
= Ftext_properties_at (make_number (0), elt
);
20328 /* If the starting string's properties are not what
20329 we want, translate the string. Also, if the string
20330 is risky, do that anyway. */
20332 if (NILP (Fequal (props
, oprops
)) || risky
)
20334 /* If the starting string has properties,
20335 merge the specified ones onto the existing ones. */
20336 if (! NILP (oprops
) && !risky
)
20340 oprops
= Fcopy_sequence (oprops
);
20342 while (CONSP (tem
))
20344 oprops
= Fplist_put (oprops
, XCAR (tem
),
20345 XCAR (XCDR (tem
)));
20346 tem
= XCDR (XCDR (tem
));
20351 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20352 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20354 /* AELT is what we want. Move it to the front
20355 without consing. */
20357 mode_line_proptrans_alist
20358 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20364 /* If AELT has the wrong props, it is useless.
20365 so get rid of it. */
20367 mode_line_proptrans_alist
20368 = Fdelq (aelt
, mode_line_proptrans_alist
);
20370 elt
= Fcopy_sequence (elt
);
20371 Fset_text_properties (make_number (0), Flength (elt
),
20373 /* Add this item to mode_line_proptrans_alist. */
20374 mode_line_proptrans_alist
20375 = Fcons (Fcons (elt
, props
),
20376 mode_line_proptrans_alist
);
20377 /* Truncate mode_line_proptrans_alist
20378 to at most 50 elements. */
20379 tem
= Fnthcdr (make_number (50),
20380 mode_line_proptrans_alist
);
20382 XSETCDR (tem
, Qnil
);
20391 prec
= precision
- n
;
20392 switch (mode_line_target
)
20394 case MODE_LINE_NOPROP
:
20395 case MODE_LINE_TITLE
:
20396 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20398 case MODE_LINE_STRING
:
20399 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20401 case MODE_LINE_DISPLAY
:
20402 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20403 0, prec
, 0, STRING_MULTIBYTE (elt
));
20410 /* Handle the non-literal case. */
20412 while ((precision
<= 0 || n
< precision
)
20413 && SREF (elt
, offset
) != 0
20414 && (mode_line_target
!= MODE_LINE_DISPLAY
20415 || it
->current_x
< it
->last_visible_x
))
20417 ptrdiff_t last_offset
= offset
;
20419 /* Advance to end of string or next format specifier. */
20420 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20423 if (offset
- 1 != last_offset
)
20425 ptrdiff_t nchars
, nbytes
;
20427 /* Output to end of string or up to '%'. Field width
20428 is length of string. Don't output more than
20429 PRECISION allows us. */
20432 prec
= c_string_width (SDATA (elt
) + last_offset
,
20433 offset
- last_offset
, precision
- n
,
20436 switch (mode_line_target
)
20438 case MODE_LINE_NOPROP
:
20439 case MODE_LINE_TITLE
:
20440 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20442 case MODE_LINE_STRING
:
20444 ptrdiff_t bytepos
= last_offset
;
20445 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20446 ptrdiff_t endpos
= (precision
<= 0
20447 ? string_byte_to_char (elt
, offset
)
20448 : charpos
+ nchars
);
20450 n
+= store_mode_line_string (NULL
,
20451 Fsubstring (elt
, make_number (charpos
),
20452 make_number (endpos
)),
20456 case MODE_LINE_DISPLAY
:
20458 ptrdiff_t bytepos
= last_offset
;
20459 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20461 if (precision
<= 0)
20462 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20463 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20465 STRING_MULTIBYTE (elt
));
20470 else /* c == '%' */
20472 ptrdiff_t percent_position
= offset
;
20474 /* Get the specified minimum width. Zero means
20477 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20478 field
= field
* 10 + c
- '0';
20480 /* Don't pad beyond the total padding allowed. */
20481 if (field_width
- n
> 0 && field
> field_width
- n
)
20482 field
= field_width
- n
;
20484 /* Note that either PRECISION <= 0 or N < PRECISION. */
20485 prec
= precision
- n
;
20488 n
+= display_mode_element (it
, depth
, field
, prec
,
20489 Vglobal_mode_string
, props
,
20494 ptrdiff_t bytepos
, charpos
;
20496 Lisp_Object string
;
20498 bytepos
= percent_position
;
20499 charpos
= (STRING_MULTIBYTE (elt
)
20500 ? string_byte_to_char (elt
, bytepos
)
20502 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20503 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20505 switch (mode_line_target
)
20507 case MODE_LINE_NOPROP
:
20508 case MODE_LINE_TITLE
:
20509 n
+= store_mode_line_noprop (spec
, field
, prec
);
20511 case MODE_LINE_STRING
:
20513 Lisp_Object tem
= build_string (spec
);
20514 props
= Ftext_properties_at (make_number (charpos
), elt
);
20515 /* Should only keep face property in props */
20516 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20519 case MODE_LINE_DISPLAY
:
20521 int nglyphs_before
, nwritten
;
20523 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20524 nwritten
= display_string (spec
, string
, elt
,
20529 /* Assign to the glyphs written above the
20530 string where the `%x' came from, position
20534 struct glyph
*glyph
20535 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20539 for (i
= 0; i
< nwritten
; ++i
)
20541 glyph
[i
].object
= elt
;
20542 glyph
[i
].charpos
= charpos
;
20559 /* A symbol: process the value of the symbol recursively
20560 as if it appeared here directly. Avoid error if symbol void.
20561 Special case: if value of symbol is a string, output the string
20564 register Lisp_Object tem
;
20566 /* If the variable is not marked as risky to set
20567 then its contents are risky to use. */
20568 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20571 tem
= Fboundp (elt
);
20574 tem
= Fsymbol_value (elt
);
20575 /* If value is a string, output that string literally:
20576 don't check for % within it. */
20580 if (!EQ (tem
, elt
))
20582 /* Give up right away for nil or t. */
20592 register Lisp_Object car
, tem
;
20594 /* A cons cell: five distinct cases.
20595 If first element is :eval or :propertize, do something special.
20596 If first element is a string or a cons, process all the elements
20597 and effectively concatenate them.
20598 If first element is a negative number, truncate displaying cdr to
20599 at most that many characters. If positive, pad (with spaces)
20600 to at least that many characters.
20601 If first element is a symbol, process the cadr or caddr recursively
20602 according to whether the symbol's value is non-nil or nil. */
20604 if (EQ (car
, QCeval
))
20606 /* An element of the form (:eval FORM) means evaluate FORM
20607 and use the result as mode line elements. */
20612 if (CONSP (XCDR (elt
)))
20615 spec
= safe_eval (XCAR (XCDR (elt
)));
20616 n
+= display_mode_element (it
, depth
, field_width
- n
,
20617 precision
- n
, spec
, props
,
20621 else if (EQ (car
, QCpropertize
))
20623 /* An element of the form (:propertize ELT PROPS...)
20624 means display ELT but applying properties PROPS. */
20629 if (CONSP (XCDR (elt
)))
20630 n
+= display_mode_element (it
, depth
, field_width
- n
,
20631 precision
- n
, XCAR (XCDR (elt
)),
20632 XCDR (XCDR (elt
)), risky
);
20634 else if (SYMBOLP (car
))
20636 tem
= Fboundp (car
);
20640 /* elt is now the cdr, and we know it is a cons cell.
20641 Use its car if CAR has a non-nil value. */
20644 tem
= Fsymbol_value (car
);
20651 /* Symbol's value is nil (or symbol is unbound)
20652 Get the cddr of the original list
20653 and if possible find the caddr and use that. */
20657 else if (!CONSP (elt
))
20662 else if (INTEGERP (car
))
20664 register int lim
= XINT (car
);
20668 /* Negative int means reduce maximum width. */
20669 if (precision
<= 0)
20672 precision
= min (precision
, -lim
);
20676 /* Padding specified. Don't let it be more than
20677 current maximum. */
20679 lim
= min (precision
, lim
);
20681 /* If that's more padding than already wanted, queue it.
20682 But don't reduce padding already specified even if
20683 that is beyond the current truncation point. */
20684 field_width
= max (lim
, field_width
);
20688 else if (STRINGP (car
) || CONSP (car
))
20690 Lisp_Object halftail
= elt
;
20694 && (precision
<= 0 || n
< precision
))
20696 n
+= display_mode_element (it
, depth
,
20697 /* Do padding only after the last
20698 element in the list. */
20699 (! CONSP (XCDR (elt
))
20702 precision
- n
, XCAR (elt
),
20706 if ((len
& 1) == 0)
20707 halftail
= XCDR (halftail
);
20708 /* Check for cycle. */
20709 if (EQ (halftail
, elt
))
20718 elt
= build_string ("*invalid*");
20722 /* Pad to FIELD_WIDTH. */
20723 if (field_width
> 0 && n
< field_width
)
20725 switch (mode_line_target
)
20727 case MODE_LINE_NOPROP
:
20728 case MODE_LINE_TITLE
:
20729 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20731 case MODE_LINE_STRING
:
20732 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20734 case MODE_LINE_DISPLAY
:
20735 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20744 /* Store a mode-line string element in mode_line_string_list.
20746 If STRING is non-null, display that C string. Otherwise, the Lisp
20747 string LISP_STRING is displayed.
20749 FIELD_WIDTH is the minimum number of output glyphs to produce.
20750 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20751 with spaces. FIELD_WIDTH <= 0 means don't pad.
20753 PRECISION is the maximum number of characters to output from
20754 STRING. PRECISION <= 0 means don't truncate the string.
20756 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20757 properties to the string.
20759 PROPS are the properties to add to the string.
20760 The mode_line_string_face face property is always added to the string.
20764 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20765 int field_width
, int precision
, Lisp_Object props
)
20770 if (string
!= NULL
)
20772 len
= strlen (string
);
20773 if (precision
> 0 && len
> precision
)
20775 lisp_string
= make_string (string
, len
);
20777 props
= mode_line_string_face_prop
;
20778 else if (!NILP (mode_line_string_face
))
20780 Lisp_Object face
= Fplist_get (props
, Qface
);
20781 props
= Fcopy_sequence (props
);
20783 face
= mode_line_string_face
;
20785 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20786 props
= Fplist_put (props
, Qface
, face
);
20788 Fadd_text_properties (make_number (0), make_number (len
),
20789 props
, lisp_string
);
20793 len
= XFASTINT (Flength (lisp_string
));
20794 if (precision
> 0 && len
> precision
)
20797 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20800 if (!NILP (mode_line_string_face
))
20804 props
= Ftext_properties_at (make_number (0), lisp_string
);
20805 face
= Fplist_get (props
, Qface
);
20807 face
= mode_line_string_face
;
20809 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20810 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20812 lisp_string
= Fcopy_sequence (lisp_string
);
20815 Fadd_text_properties (make_number (0), make_number (len
),
20816 props
, lisp_string
);
20821 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20825 if (field_width
> len
)
20827 field_width
-= len
;
20828 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20830 Fadd_text_properties (make_number (0), make_number (field_width
),
20831 props
, lisp_string
);
20832 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20840 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20842 doc
: /* Format a string out of a mode line format specification.
20843 First arg FORMAT specifies the mode line format (see `mode-line-format'
20844 for details) to use.
20846 By default, the format is evaluated for the currently selected window.
20848 Optional second arg FACE specifies the face property to put on all
20849 characters for which no face is specified. The value nil means the
20850 default face. The value t means whatever face the window's mode line
20851 currently uses (either `mode-line' or `mode-line-inactive',
20852 depending on whether the window is the selected window or not).
20853 An integer value means the value string has no text
20856 Optional third and fourth args WINDOW and BUFFER specify the window
20857 and buffer to use as the context for the formatting (defaults
20858 are the selected window and the WINDOW's buffer). */)
20859 (Lisp_Object format
, Lisp_Object face
,
20860 Lisp_Object window
, Lisp_Object buffer
)
20865 struct buffer
*old_buffer
= NULL
;
20867 int no_props
= INTEGERP (face
);
20868 ptrdiff_t count
= SPECPDL_INDEX ();
20870 int string_start
= 0;
20872 w
= decode_any_window (window
);
20873 XSETWINDOW (window
, w
);
20876 buffer
= w
->buffer
;
20877 CHECK_BUFFER (buffer
);
20879 /* Make formatting the modeline a non-op when noninteractive, otherwise
20880 there will be problems later caused by a partially initialized frame. */
20881 if (NILP (format
) || noninteractive
)
20882 return empty_unibyte_string
;
20887 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20888 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20889 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20890 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20891 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20892 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20893 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20896 old_buffer
= current_buffer
;
20898 /* Save things including mode_line_proptrans_alist,
20899 and set that to nil so that we don't alter the outer value. */
20900 record_unwind_protect (unwind_format_mode_line
,
20901 format_mode_line_unwind_data
20902 (XFRAME (WINDOW_FRAME (w
)),
20903 old_buffer
, selected_window
, 1));
20904 mode_line_proptrans_alist
= Qnil
;
20906 Fselect_window (window
, Qt
);
20907 set_buffer_internal_1 (XBUFFER (buffer
));
20909 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20913 mode_line_target
= MODE_LINE_NOPROP
;
20914 mode_line_string_face_prop
= Qnil
;
20915 mode_line_string_list
= Qnil
;
20916 string_start
= MODE_LINE_NOPROP_LEN (0);
20920 mode_line_target
= MODE_LINE_STRING
;
20921 mode_line_string_list
= Qnil
;
20922 mode_line_string_face
= face
;
20923 mode_line_string_face_prop
20924 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20927 push_kboard (FRAME_KBOARD (it
.f
));
20928 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20933 len
= MODE_LINE_NOPROP_LEN (string_start
);
20934 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20938 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20939 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20940 empty_unibyte_string
);
20943 unbind_to (count
, Qnil
);
20947 /* Write a null-terminated, right justified decimal representation of
20948 the positive integer D to BUF using a minimal field width WIDTH. */
20951 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20953 register char *p
= buf
;
20961 *p
++ = d
% 10 + '0';
20966 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20977 /* Write a null-terminated, right justified decimal and "human
20978 readable" representation of the nonnegative integer D to BUF using
20979 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20981 static const char power_letter
[] =
20995 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20997 /* We aim to represent the nonnegative integer D as
20998 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20999 ptrdiff_t quotient
= d
;
21001 /* -1 means: do not use TENTHS. */
21005 /* Length of QUOTIENT.TENTHS as a string. */
21011 if (1000 <= quotient
)
21013 /* Scale to the appropriate EXPONENT. */
21016 remainder
= quotient
% 1000;
21020 while (1000 <= quotient
);
21022 /* Round to nearest and decide whether to use TENTHS or not. */
21025 tenths
= remainder
/ 100;
21026 if (50 <= remainder
% 100)
21033 if (quotient
== 10)
21041 if (500 <= remainder
)
21043 if (quotient
< 999)
21054 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21055 if (tenths
== -1 && quotient
<= 99)
21062 p
= psuffix
= buf
+ max (width
, length
);
21064 /* Print EXPONENT. */
21065 *psuffix
++ = power_letter
[exponent
];
21068 /* Print TENTHS. */
21071 *--p
= '0' + tenths
;
21075 /* Print QUOTIENT. */
21078 int digit
= quotient
% 10;
21079 *--p
= '0' + digit
;
21081 while ((quotient
/= 10) != 0);
21083 /* Print leading spaces. */
21088 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21089 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21090 type of CODING_SYSTEM. Return updated pointer into BUF. */
21092 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21095 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21098 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21099 const unsigned char *eol_str
;
21101 /* The EOL conversion we are using. */
21102 Lisp_Object eoltype
;
21104 val
= CODING_SYSTEM_SPEC (coding_system
);
21107 if (!VECTORP (val
)) /* Not yet decided. */
21109 *buf
++ = multibyte
? '-' : ' ';
21111 eoltype
= eol_mnemonic_undecided
;
21112 /* Don't mention EOL conversion if it isn't decided. */
21117 Lisp_Object eolvalue
;
21119 attrs
= AREF (val
, 0);
21120 eolvalue
= AREF (val
, 2);
21123 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21128 /* The EOL conversion that is normal on this system. */
21130 if (NILP (eolvalue
)) /* Not yet decided. */
21131 eoltype
= eol_mnemonic_undecided
;
21132 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21133 eoltype
= eol_mnemonic_undecided
;
21134 else /* eolvalue is Qunix, Qdos, or Qmac. */
21135 eoltype
= (EQ (eolvalue
, Qunix
)
21136 ? eol_mnemonic_unix
21137 : (EQ (eolvalue
, Qdos
) == 1
21138 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21144 /* Mention the EOL conversion if it is not the usual one. */
21145 if (STRINGP (eoltype
))
21147 eol_str
= SDATA (eoltype
);
21148 eol_str_len
= SBYTES (eoltype
);
21150 else if (CHARACTERP (eoltype
))
21152 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21153 int c
= XFASTINT (eoltype
);
21154 eol_str_len
= CHAR_STRING (c
, tmp
);
21159 eol_str
= invalid_eol_type
;
21160 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21162 memcpy (buf
, eol_str
, eol_str_len
);
21163 buf
+= eol_str_len
;
21169 /* Return a string for the output of a mode line %-spec for window W,
21170 generated by character C. FIELD_WIDTH > 0 means pad the string
21171 returned with spaces to that value. Return a Lisp string in
21172 *STRING if the resulting string is taken from that Lisp string.
21174 Note we operate on the current buffer for most purposes. */
21176 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21178 static const char *
21179 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21180 Lisp_Object
*string
)
21183 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21184 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21185 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21186 produce strings from numerical values, so limit preposterously
21187 large values of FIELD_WIDTH to avoid overrunning the buffer's
21188 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21189 bytes plus the terminating null. */
21190 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21191 struct buffer
*b
= current_buffer
;
21199 if (!NILP (BVAR (b
, read_only
)))
21201 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21206 /* This differs from %* only for a modified read-only buffer. */
21207 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21209 if (!NILP (BVAR (b
, read_only
)))
21214 /* This differs from %* in ignoring read-only-ness. */
21215 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21227 if (command_loop_level
> 5)
21229 p
= decode_mode_spec_buf
;
21230 for (i
= 0; i
< command_loop_level
; i
++)
21233 return decode_mode_spec_buf
;
21241 if (command_loop_level
> 5)
21243 p
= decode_mode_spec_buf
;
21244 for (i
= 0; i
< command_loop_level
; i
++)
21247 return decode_mode_spec_buf
;
21254 /* Let lots_of_dashes be a string of infinite length. */
21255 if (mode_line_target
== MODE_LINE_NOPROP
21256 || mode_line_target
== MODE_LINE_STRING
)
21258 if (field_width
<= 0
21259 || field_width
> sizeof (lots_of_dashes
))
21261 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21262 decode_mode_spec_buf
[i
] = '-';
21263 decode_mode_spec_buf
[i
] = '\0';
21264 return decode_mode_spec_buf
;
21267 return lots_of_dashes
;
21271 obj
= BVAR (b
, name
);
21275 /* %c and %l are ignored in `frame-title-format'.
21276 (In redisplay_internal, the frame title is drawn _before_ the
21277 windows are updated, so the stuff which depends on actual
21278 window contents (such as %l) may fail to render properly, or
21279 even crash emacs.) */
21280 if (mode_line_target
== MODE_LINE_TITLE
)
21284 ptrdiff_t col
= current_column ();
21285 w
->column_number_displayed
= col
;
21286 pint2str (decode_mode_spec_buf
, width
, col
);
21287 return decode_mode_spec_buf
;
21291 #ifndef SYSTEM_MALLOC
21293 if (NILP (Vmemory_full
))
21296 return "!MEM FULL! ";
21303 /* %F displays the frame name. */
21304 if (!NILP (f
->title
))
21305 return SSDATA (f
->title
);
21306 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21307 return SSDATA (f
->name
);
21311 obj
= BVAR (b
, filename
);
21316 ptrdiff_t size
= ZV
- BEGV
;
21317 pint2str (decode_mode_spec_buf
, width
, size
);
21318 return decode_mode_spec_buf
;
21323 ptrdiff_t size
= ZV
- BEGV
;
21324 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21325 return decode_mode_spec_buf
;
21330 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21331 ptrdiff_t topline
, nlines
, height
;
21334 /* %c and %l are ignored in `frame-title-format'. */
21335 if (mode_line_target
== MODE_LINE_TITLE
)
21338 startpos
= marker_position (w
->start
);
21339 startpos_byte
= marker_byte_position (w
->start
);
21340 height
= WINDOW_TOTAL_LINES (w
);
21342 /* If we decided that this buffer isn't suitable for line numbers,
21343 don't forget that too fast. */
21344 if (w
->base_line_pos
== -1)
21347 /* If the buffer is very big, don't waste time. */
21348 if (INTEGERP (Vline_number_display_limit
)
21349 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21351 w
->base_line_pos
= 0;
21352 w
->base_line_number
= 0;
21356 if (w
->base_line_number
> 0
21357 && w
->base_line_pos
> 0
21358 && w
->base_line_pos
<= startpos
)
21360 line
= w
->base_line_number
;
21361 linepos
= w
->base_line_pos
;
21362 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21367 linepos
= BUF_BEGV (b
);
21368 linepos_byte
= BUF_BEGV_BYTE (b
);
21371 /* Count lines from base line to window start position. */
21372 nlines
= display_count_lines (linepos_byte
,
21376 topline
= nlines
+ line
;
21378 /* Determine a new base line, if the old one is too close
21379 or too far away, or if we did not have one.
21380 "Too close" means it's plausible a scroll-down would
21381 go back past it. */
21382 if (startpos
== BUF_BEGV (b
))
21384 w
->base_line_number
= topline
;
21385 w
->base_line_pos
= BUF_BEGV (b
);
21387 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21388 || linepos
== BUF_BEGV (b
))
21390 ptrdiff_t limit
= BUF_BEGV (b
);
21391 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21392 ptrdiff_t position
;
21393 ptrdiff_t distance
=
21394 (height
* 2 + 30) * line_number_display_limit_width
;
21396 if (startpos
- distance
> limit
)
21398 limit
= startpos
- distance
;
21399 limit_byte
= CHAR_TO_BYTE (limit
);
21402 nlines
= display_count_lines (startpos_byte
,
21404 - (height
* 2 + 30),
21406 /* If we couldn't find the lines we wanted within
21407 line_number_display_limit_width chars per line,
21408 give up on line numbers for this window. */
21409 if (position
== limit_byte
&& limit
== startpos
- distance
)
21411 w
->base_line_pos
= -1;
21412 w
->base_line_number
= 0;
21416 w
->base_line_number
= topline
- nlines
;
21417 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21420 /* Now count lines from the start pos to point. */
21421 nlines
= display_count_lines (startpos_byte
,
21422 PT_BYTE
, PT
, &junk
);
21424 /* Record that we did display the line number. */
21425 line_number_displayed
= 1;
21427 /* Make the string to show. */
21428 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21429 return decode_mode_spec_buf
;
21432 char* p
= decode_mode_spec_buf
;
21433 int pad
= width
- 2;
21439 return decode_mode_spec_buf
;
21445 obj
= BVAR (b
, mode_name
);
21449 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21455 ptrdiff_t pos
= marker_position (w
->start
);
21456 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21458 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21460 if (pos
<= BUF_BEGV (b
))
21465 else if (pos
<= BUF_BEGV (b
))
21469 if (total
> 1000000)
21470 /* Do it differently for a large value, to avoid overflow. */
21471 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21473 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21474 /* We can't normally display a 3-digit number,
21475 so get us a 2-digit number that is close. */
21478 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21479 return decode_mode_spec_buf
;
21483 /* Display percentage of size above the bottom of the screen. */
21486 ptrdiff_t toppos
= marker_position (w
->start
);
21487 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21488 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21490 if (botpos
>= BUF_ZV (b
))
21492 if (toppos
<= BUF_BEGV (b
))
21499 if (total
> 1000000)
21500 /* Do it differently for a large value, to avoid overflow. */
21501 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21503 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21504 /* We can't normally display a 3-digit number,
21505 so get us a 2-digit number that is close. */
21508 if (toppos
<= BUF_BEGV (b
))
21509 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21511 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21512 return decode_mode_spec_buf
;
21517 /* status of process */
21518 obj
= Fget_buffer_process (Fcurrent_buffer ());
21520 return "no process";
21522 obj
= Fsymbol_name (Fprocess_status (obj
));
21528 ptrdiff_t count
= inhibit_garbage_collection ();
21529 Lisp_Object val
= call1 (intern ("file-remote-p"),
21530 BVAR (current_buffer
, directory
));
21531 unbind_to (count
, Qnil
);
21540 /* coding-system (not including end-of-line format) */
21542 /* coding-system (including end-of-line type) */
21544 int eol_flag
= (c
== 'Z');
21545 char *p
= decode_mode_spec_buf
;
21547 if (! FRAME_WINDOW_P (f
))
21549 /* No need to mention EOL here--the terminal never needs
21550 to do EOL conversion. */
21551 p
= decode_mode_spec_coding (CODING_ID_NAME
21552 (FRAME_KEYBOARD_CODING (f
)->id
),
21554 p
= decode_mode_spec_coding (CODING_ID_NAME
21555 (FRAME_TERMINAL_CODING (f
)->id
),
21558 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21561 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21562 #ifdef subprocesses
21563 obj
= Fget_buffer_process (Fcurrent_buffer ());
21564 if (PROCESSP (obj
))
21566 p
= decode_mode_spec_coding
21567 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21568 p
= decode_mode_spec_coding
21569 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21571 #endif /* subprocesses */
21574 return decode_mode_spec_buf
;
21581 return SSDATA (obj
);
21588 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
21589 means count lines back from START_BYTE. But don't go beyond
21590 LIMIT_BYTE. Return the number of lines thus found (always
21593 Set *BYTE_POS_PTR to the byte position where we stopped. This is
21594 either the position COUNT lines after/before START_BYTE, if we
21595 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
21599 display_count_lines (ptrdiff_t start_byte
,
21600 ptrdiff_t limit_byte
, ptrdiff_t count
,
21601 ptrdiff_t *byte_pos_ptr
)
21603 register unsigned char *cursor
;
21604 unsigned char *base
;
21606 register ptrdiff_t ceiling
;
21607 register unsigned char *ceiling_addr
;
21608 ptrdiff_t orig_count
= count
;
21610 /* If we are not in selective display mode,
21611 check only for newlines. */
21612 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21613 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21617 while (start_byte
< limit_byte
)
21619 ceiling
= BUFFER_CEILING_OF (start_byte
);
21620 ceiling
= min (limit_byte
- 1, ceiling
);
21621 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21622 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21625 if (selective_display
)
21626 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21629 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21632 if (cursor
!= ceiling_addr
)
21636 start_byte
+= cursor
- base
+ 1;
21637 *byte_pos_ptr
= start_byte
;
21641 if (++cursor
== ceiling_addr
)
21647 start_byte
+= cursor
- base
;
21652 while (start_byte
> limit_byte
)
21654 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21655 ceiling
= max (limit_byte
, ceiling
);
21656 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21657 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21660 if (selective_display
)
21661 while (--cursor
!= ceiling_addr
21662 && *cursor
!= '\n' && *cursor
!= 015)
21665 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21668 if (cursor
!= ceiling_addr
)
21672 start_byte
+= cursor
- base
+ 1;
21673 *byte_pos_ptr
= start_byte
;
21674 /* When scanning backwards, we should
21675 not count the newline posterior to which we stop. */
21676 return - orig_count
- 1;
21682 /* Here we add 1 to compensate for the last decrement
21683 of CURSOR, which took it past the valid range. */
21684 start_byte
+= cursor
- base
+ 1;
21688 *byte_pos_ptr
= limit_byte
;
21691 return - orig_count
+ count
;
21692 return orig_count
- count
;
21698 /***********************************************************************
21700 ***********************************************************************/
21702 /* Display a NUL-terminated string, starting with index START.
21704 If STRING is non-null, display that C string. Otherwise, the Lisp
21705 string LISP_STRING is displayed. There's a case that STRING is
21706 non-null and LISP_STRING is not nil. It means STRING is a string
21707 data of LISP_STRING. In that case, we display LISP_STRING while
21708 ignoring its text properties.
21710 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21711 FACE_STRING. Display STRING or LISP_STRING with the face at
21712 FACE_STRING_POS in FACE_STRING:
21714 Display the string in the environment given by IT, but use the
21715 standard display table, temporarily.
21717 FIELD_WIDTH is the minimum number of output glyphs to produce.
21718 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21719 with spaces. If STRING has more characters, more than FIELD_WIDTH
21720 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21722 PRECISION is the maximum number of characters to output from
21723 STRING. PRECISION < 0 means don't truncate the string.
21725 This is roughly equivalent to printf format specifiers:
21727 FIELD_WIDTH PRECISION PRINTF
21728 ----------------------------------------
21734 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21735 display them, and < 0 means obey the current buffer's value of
21736 enable_multibyte_characters.
21738 Value is the number of columns displayed. */
21741 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21742 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21743 int field_width
, int precision
, int max_x
, int multibyte
)
21745 int hpos_at_start
= it
->hpos
;
21746 int saved_face_id
= it
->face_id
;
21747 struct glyph_row
*row
= it
->glyph_row
;
21748 ptrdiff_t it_charpos
;
21750 /* Initialize the iterator IT for iteration over STRING beginning
21751 with index START. */
21752 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21753 precision
, field_width
, multibyte
);
21754 if (string
&& STRINGP (lisp_string
))
21755 /* LISP_STRING is the one returned by decode_mode_spec. We should
21756 ignore its text properties. */
21757 it
->stop_charpos
= it
->end_charpos
;
21759 /* If displaying STRING, set up the face of the iterator from
21760 FACE_STRING, if that's given. */
21761 if (STRINGP (face_string
))
21767 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21768 0, it
->region_beg_charpos
,
21769 it
->region_end_charpos
,
21770 &endptr
, it
->base_face_id
, 0);
21771 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21772 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21775 /* Set max_x to the maximum allowed X position. Don't let it go
21776 beyond the right edge of the window. */
21778 max_x
= it
->last_visible_x
;
21780 max_x
= min (max_x
, it
->last_visible_x
);
21782 /* Skip over display elements that are not visible. because IT->w is
21784 if (it
->current_x
< it
->first_visible_x
)
21785 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21786 MOVE_TO_POS
| MOVE_TO_X
);
21788 row
->ascent
= it
->max_ascent
;
21789 row
->height
= it
->max_ascent
+ it
->max_descent
;
21790 row
->phys_ascent
= it
->max_phys_ascent
;
21791 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21792 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21794 if (STRINGP (it
->string
))
21795 it_charpos
= IT_STRING_CHARPOS (*it
);
21797 it_charpos
= IT_CHARPOS (*it
);
21799 /* This condition is for the case that we are called with current_x
21800 past last_visible_x. */
21801 while (it
->current_x
< max_x
)
21803 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21805 /* Get the next display element. */
21806 if (!get_next_display_element (it
))
21809 /* Produce glyphs. */
21810 x_before
= it
->current_x
;
21811 n_glyphs_before
= row
->used
[TEXT_AREA
];
21812 PRODUCE_GLYPHS (it
);
21814 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21817 while (i
< nglyphs
)
21819 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21821 if (it
->line_wrap
!= TRUNCATE
21822 && x
+ glyph
->pixel_width
> max_x
)
21824 /* End of continued line or max_x reached. */
21825 if (CHAR_GLYPH_PADDING_P (*glyph
))
21827 /* A wide character is unbreakable. */
21828 if (row
->reversed_p
)
21829 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21830 - n_glyphs_before
);
21831 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21832 it
->current_x
= x_before
;
21836 if (row
->reversed_p
)
21837 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21838 - (n_glyphs_before
+ i
));
21839 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21844 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21846 /* Glyph is at least partially visible. */
21848 if (x
< it
->first_visible_x
)
21849 row
->x
= x
- it
->first_visible_x
;
21853 /* Glyph is off the left margin of the display area.
21854 Should not happen. */
21858 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21859 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21860 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21861 row
->phys_height
= max (row
->phys_height
,
21862 it
->max_phys_ascent
+ it
->max_phys_descent
);
21863 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21864 it
->max_extra_line_spacing
);
21865 x
+= glyph
->pixel_width
;
21869 /* Stop if max_x reached. */
21873 /* Stop at line ends. */
21874 if (ITERATOR_AT_END_OF_LINE_P (it
))
21876 it
->continuation_lines_width
= 0;
21880 set_iterator_to_next (it
, 1);
21881 if (STRINGP (it
->string
))
21882 it_charpos
= IT_STRING_CHARPOS (*it
);
21884 it_charpos
= IT_CHARPOS (*it
);
21886 /* Stop if truncating at the right edge. */
21887 if (it
->line_wrap
== TRUNCATE
21888 && it
->current_x
>= it
->last_visible_x
)
21890 /* Add truncation mark, but don't do it if the line is
21891 truncated at a padding space. */
21892 if (it_charpos
< it
->string_nchars
)
21894 if (!FRAME_WINDOW_P (it
->f
))
21898 if (it
->current_x
> it
->last_visible_x
)
21900 if (!row
->reversed_p
)
21902 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21903 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21908 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21909 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21911 unproduce_glyphs (it
, ii
+ 1);
21912 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21914 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21916 row
->used
[TEXT_AREA
] = ii
;
21917 produce_special_glyphs (it
, IT_TRUNCATION
);
21920 produce_special_glyphs (it
, IT_TRUNCATION
);
21922 row
->truncated_on_right_p
= 1;
21928 /* Maybe insert a truncation at the left. */
21929 if (it
->first_visible_x
21932 if (!FRAME_WINDOW_P (it
->f
)
21933 || (row
->reversed_p
21934 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21935 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21936 insert_left_trunc_glyphs (it
);
21937 row
->truncated_on_left_p
= 1;
21940 it
->face_id
= saved_face_id
;
21942 /* Value is number of columns displayed. */
21943 return it
->hpos
- hpos_at_start
;
21948 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21949 appears as an element of LIST or as the car of an element of LIST.
21950 If PROPVAL is a list, compare each element against LIST in that
21951 way, and return 1/2 if any element of PROPVAL is found in LIST.
21952 Otherwise return 0. This function cannot quit.
21953 The return value is 2 if the text is invisible but with an ellipsis
21954 and 1 if it's invisible and without an ellipsis. */
21957 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21959 register Lisp_Object tail
, proptail
;
21961 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21963 register Lisp_Object tem
;
21965 if (EQ (propval
, tem
))
21967 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21968 return NILP (XCDR (tem
)) ? 1 : 2;
21971 if (CONSP (propval
))
21973 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21975 Lisp_Object propelt
;
21976 propelt
= XCAR (proptail
);
21977 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21979 register Lisp_Object tem
;
21981 if (EQ (propelt
, tem
))
21983 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21984 return NILP (XCDR (tem
)) ? 1 : 2;
21992 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21993 doc
: /* Non-nil if the property makes the text invisible.
21994 POS-OR-PROP can be a marker or number, in which case it is taken to be
21995 a position in the current buffer and the value of the `invisible' property
21996 is checked; or it can be some other value, which is then presumed to be the
21997 value of the `invisible' property of the text of interest.
21998 The non-nil value returned can be t for truly invisible text or something
21999 else if the text is replaced by an ellipsis. */)
22000 (Lisp_Object pos_or_prop
)
22003 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22004 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22006 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22007 return (invis
== 0 ? Qnil
22009 : make_number (invis
));
22012 /* Calculate a width or height in pixels from a specification using
22013 the following elements:
22016 NUM - a (fractional) multiple of the default font width/height
22017 (NUM) - specifies exactly NUM pixels
22018 UNIT - a fixed number of pixels, see below.
22019 ELEMENT - size of a display element in pixels, see below.
22020 (NUM . SPEC) - equals NUM * SPEC
22021 (+ SPEC SPEC ...) - add pixel values
22022 (- SPEC SPEC ...) - subtract pixel values
22023 (- SPEC) - negate pixel value
22026 INT or FLOAT - a number constant
22027 SYMBOL - use symbol's (buffer local) variable binding.
22030 in - pixels per inch *)
22031 mm - pixels per 1/1000 meter *)
22032 cm - pixels per 1/100 meter *)
22033 width - width of current font in pixels.
22034 height - height of current font in pixels.
22036 *) using the ratio(s) defined in display-pixels-per-inch.
22040 left-fringe - left fringe width in pixels
22041 right-fringe - right fringe width in pixels
22043 left-margin - left margin width in pixels
22044 right-margin - right margin width in pixels
22046 scroll-bar - scroll-bar area width in pixels
22050 Pixels corresponding to 5 inches:
22053 Total width of non-text areas on left side of window (if scroll-bar is on left):
22054 '(space :width (+ left-fringe left-margin scroll-bar))
22056 Align to first text column (in header line):
22057 '(space :align-to 0)
22059 Align to middle of text area minus half the width of variable `my-image'
22060 containing a loaded image:
22061 '(space :align-to (0.5 . (- text my-image)))
22063 Width of left margin minus width of 1 character in the default font:
22064 '(space :width (- left-margin 1))
22066 Width of left margin minus width of 2 characters in the current font:
22067 '(space :width (- left-margin (2 . width)))
22069 Center 1 character over left-margin (in header line):
22070 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22072 Different ways to express width of left fringe plus left margin minus one pixel:
22073 '(space :width (- (+ left-fringe left-margin) (1)))
22074 '(space :width (+ left-fringe left-margin (- (1))))
22075 '(space :width (+ left-fringe left-margin (-1)))
22079 #define NUMVAL(X) \
22080 ((INTEGERP (X) || FLOATP (X)) \
22085 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22086 struct font
*font
, int width_p
, int *align_to
)
22090 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22091 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22094 return OK_PIXELS (0);
22096 eassert (FRAME_LIVE_P (it
->f
));
22098 if (SYMBOLP (prop
))
22100 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22102 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22104 if (unit
[0] == 'i' && unit
[1] == 'n')
22106 else if (unit
[0] == 'm' && unit
[1] == 'm')
22108 else if (unit
[0] == 'c' && unit
[1] == 'm')
22115 #ifdef HAVE_WINDOW_SYSTEM
22116 if (FRAME_WINDOW_P (it
->f
)
22118 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22119 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22121 return OK_PIXELS (ppi
/ pixels
);
22124 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22125 || (CONSP (Vdisplay_pixels_per_inch
)
22127 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22128 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22130 return OK_PIXELS (ppi
/ pixels
);
22136 #ifdef HAVE_WINDOW_SYSTEM
22137 if (EQ (prop
, Qheight
))
22138 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22139 if (EQ (prop
, Qwidth
))
22140 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22142 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22143 return OK_PIXELS (1);
22146 if (EQ (prop
, Qtext
))
22147 return OK_PIXELS (width_p
22148 ? window_box_width (it
->w
, TEXT_AREA
)
22149 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22151 if (align_to
&& *align_to
< 0)
22154 if (EQ (prop
, Qleft
))
22155 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22156 if (EQ (prop
, Qright
))
22157 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22158 if (EQ (prop
, Qcenter
))
22159 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22160 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22161 if (EQ (prop
, Qleft_fringe
))
22162 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22163 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22164 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22165 if (EQ (prop
, Qright_fringe
))
22166 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22167 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22168 : window_box_right_offset (it
->w
, TEXT_AREA
));
22169 if (EQ (prop
, Qleft_margin
))
22170 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22171 if (EQ (prop
, Qright_margin
))
22172 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22173 if (EQ (prop
, Qscroll_bar
))
22174 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22176 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22177 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22178 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22183 if (EQ (prop
, Qleft_fringe
))
22184 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22185 if (EQ (prop
, Qright_fringe
))
22186 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22187 if (EQ (prop
, Qleft_margin
))
22188 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22189 if (EQ (prop
, Qright_margin
))
22190 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22191 if (EQ (prop
, Qscroll_bar
))
22192 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22195 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22196 if (EQ (prop
, Qunbound
))
22200 if (INTEGERP (prop
) || FLOATP (prop
))
22202 int base_unit
= (width_p
22203 ? FRAME_COLUMN_WIDTH (it
->f
)
22204 : FRAME_LINE_HEIGHT (it
->f
));
22205 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22210 Lisp_Object car
= XCAR (prop
);
22211 Lisp_Object cdr
= XCDR (prop
);
22215 #ifdef HAVE_WINDOW_SYSTEM
22216 if (FRAME_WINDOW_P (it
->f
)
22217 && valid_image_p (prop
))
22219 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22220 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22222 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22225 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22231 while (CONSP (cdr
))
22233 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22234 font
, width_p
, align_to
))
22237 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22242 if (EQ (car
, Qminus
))
22244 return OK_PIXELS (pixels
);
22247 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22248 if (EQ (car
, Qunbound
))
22252 if (INTEGERP (car
) || FLOATP (car
))
22255 pixels
= XFLOATINT (car
);
22257 return OK_PIXELS (pixels
);
22258 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22259 font
, width_p
, align_to
))
22260 return OK_PIXELS (pixels
* fact
);
22271 /***********************************************************************
22273 ***********************************************************************/
22275 #ifdef HAVE_WINDOW_SYSTEM
22280 dump_glyph_string (struct glyph_string
*s
)
22282 fprintf (stderr
, "glyph string\n");
22283 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22284 s
->x
, s
->y
, s
->width
, s
->height
);
22285 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22286 fprintf (stderr
, " hl = %d\n", s
->hl
);
22287 fprintf (stderr
, " left overhang = %d, right = %d\n",
22288 s
->left_overhang
, s
->right_overhang
);
22289 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22290 fprintf (stderr
, " extends to end of line = %d\n",
22291 s
->extends_to_end_of_line_p
);
22292 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22293 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22296 #endif /* GLYPH_DEBUG */
22298 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22299 of XChar2b structures for S; it can't be allocated in
22300 init_glyph_string because it must be allocated via `alloca'. W
22301 is the window on which S is drawn. ROW and AREA are the glyph row
22302 and area within the row from which S is constructed. START is the
22303 index of the first glyph structure covered by S. HL is a
22304 face-override for drawing S. */
22307 #define OPTIONAL_HDC(hdc) HDC hdc,
22308 #define DECLARE_HDC(hdc) HDC hdc;
22309 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22310 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22313 #ifndef OPTIONAL_HDC
22314 #define OPTIONAL_HDC(hdc)
22315 #define DECLARE_HDC(hdc)
22316 #define ALLOCATE_HDC(hdc, f)
22317 #define RELEASE_HDC(hdc, f)
22321 init_glyph_string (struct glyph_string
*s
,
22323 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22324 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22326 memset (s
, 0, sizeof *s
);
22328 s
->f
= XFRAME (w
->frame
);
22332 s
->display
= FRAME_X_DISPLAY (s
->f
);
22333 s
->window
= FRAME_X_WINDOW (s
->f
);
22334 s
->char2b
= char2b
;
22338 s
->first_glyph
= row
->glyphs
[area
] + start
;
22339 s
->height
= row
->height
;
22340 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22341 s
->ybase
= s
->y
+ row
->ascent
;
22345 /* Append the list of glyph strings with head H and tail T to the list
22346 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22349 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22350 struct glyph_string
*h
, struct glyph_string
*t
)
22364 /* Prepend the list of glyph strings with head H and tail T to the
22365 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22369 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22370 struct glyph_string
*h
, struct glyph_string
*t
)
22384 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22385 Set *HEAD and *TAIL to the resulting list. */
22388 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22389 struct glyph_string
*s
)
22391 s
->next
= s
->prev
= NULL
;
22392 append_glyph_string_lists (head
, tail
, s
, s
);
22396 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22397 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22398 make sure that X resources for the face returned are allocated.
22399 Value is a pointer to a realized face that is ready for display if
22400 DISPLAY_P is non-zero. */
22402 static struct face
*
22403 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22404 XChar2b
*char2b
, int display_p
)
22406 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22410 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22412 if (code
!= FONT_INVALID_CODE
)
22413 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22415 STORE_XCHAR2B (char2b
, 0, 0);
22418 /* Make sure X resources of the face are allocated. */
22419 #ifdef HAVE_X_WINDOWS
22423 eassert (face
!= NULL
);
22424 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22431 /* Get face and two-byte form of character glyph GLYPH on frame F.
22432 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22433 a pointer to a realized face that is ready for display. */
22435 static struct face
*
22436 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22437 XChar2b
*char2b
, int *two_byte_p
)
22441 eassert (glyph
->type
== CHAR_GLYPH
);
22442 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22451 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22452 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22454 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22456 if (code
!= FONT_INVALID_CODE
)
22457 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22459 STORE_XCHAR2B (char2b
, 0, 0);
22462 /* Make sure X resources of the face are allocated. */
22463 eassert (face
!= NULL
);
22464 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22469 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22470 Return 1 if FONT has a glyph for C, otherwise return 0. */
22473 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22477 if (CHAR_BYTE8_P (c
))
22478 code
= CHAR_TO_BYTE8 (c
);
22480 code
= font
->driver
->encode_char (font
, c
);
22482 if (code
== FONT_INVALID_CODE
)
22484 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22489 /* Fill glyph string S with composition components specified by S->cmp.
22491 BASE_FACE is the base face of the composition.
22492 S->cmp_from is the index of the first component for S.
22494 OVERLAPS non-zero means S should draw the foreground only, and use
22495 its physical height for clipping. See also draw_glyphs.
22497 Value is the index of a component not in S. */
22500 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22504 /* For all glyphs of this composition, starting at the offset
22505 S->cmp_from, until we reach the end of the definition or encounter a
22506 glyph that requires the different face, add it to S. */
22511 s
->for_overlaps
= overlaps
;
22514 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22516 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22518 /* TAB in a composition means display glyphs with padding space
22519 on the left or right. */
22522 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22525 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22532 s
->font
= s
->face
->font
;
22534 else if (s
->face
!= face
)
22542 if (s
->face
== NULL
)
22544 s
->face
= base_face
->ascii_face
;
22545 s
->font
= s
->face
->font
;
22548 /* All glyph strings for the same composition has the same width,
22549 i.e. the width set for the first component of the composition. */
22550 s
->width
= s
->first_glyph
->pixel_width
;
22552 /* If the specified font could not be loaded, use the frame's
22553 default font, but record the fact that we couldn't load it in
22554 the glyph string so that we can draw rectangles for the
22555 characters of the glyph string. */
22556 if (s
->font
== NULL
)
22558 s
->font_not_found_p
= 1;
22559 s
->font
= FRAME_FONT (s
->f
);
22562 /* Adjust base line for subscript/superscript text. */
22563 s
->ybase
+= s
->first_glyph
->voffset
;
22565 /* This glyph string must always be drawn with 16-bit functions. */
22572 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22573 int start
, int end
, int overlaps
)
22575 struct glyph
*glyph
, *last
;
22576 Lisp_Object lgstring
;
22579 s
->for_overlaps
= overlaps
;
22580 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22581 last
= s
->row
->glyphs
[s
->area
] + end
;
22582 s
->cmp_id
= glyph
->u
.cmp
.id
;
22583 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22584 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22585 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22586 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22587 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22589 while (glyph
< last
22590 && glyph
->u
.cmp
.automatic
22591 && glyph
->u
.cmp
.id
== s
->cmp_id
22592 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22593 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22595 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22597 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22598 unsigned code
= LGLYPH_CODE (lglyph
);
22600 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22602 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22603 return glyph
- s
->row
->glyphs
[s
->area
];
22607 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22608 See the comment of fill_glyph_string for arguments.
22609 Value is the index of the first glyph not in S. */
22613 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22614 int start
, int end
, int overlaps
)
22616 struct glyph
*glyph
, *last
;
22619 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22620 s
->for_overlaps
= overlaps
;
22621 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22622 last
= s
->row
->glyphs
[s
->area
] + end
;
22623 voffset
= glyph
->voffset
;
22624 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22625 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22627 s
->width
= glyph
->pixel_width
;
22629 while (glyph
< last
22630 && glyph
->type
== GLYPHLESS_GLYPH
22631 && glyph
->voffset
== voffset
22632 && glyph
->face_id
== face_id
)
22635 s
->width
+= glyph
->pixel_width
;
22638 s
->ybase
+= voffset
;
22639 return glyph
- s
->row
->glyphs
[s
->area
];
22643 /* Fill glyph string S from a sequence of character glyphs.
22645 FACE_ID is the face id of the string. START is the index of the
22646 first glyph to consider, END is the index of the last + 1.
22647 OVERLAPS non-zero means S should draw the foreground only, and use
22648 its physical height for clipping. See also draw_glyphs.
22650 Value is the index of the first glyph not in S. */
22653 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22654 int start
, int end
, int overlaps
)
22656 struct glyph
*glyph
, *last
;
22658 int glyph_not_available_p
;
22660 eassert (s
->f
== XFRAME (s
->w
->frame
));
22661 eassert (s
->nchars
== 0);
22662 eassert (start
>= 0 && end
> start
);
22664 s
->for_overlaps
= overlaps
;
22665 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22666 last
= s
->row
->glyphs
[s
->area
] + end
;
22667 voffset
= glyph
->voffset
;
22668 s
->padding_p
= glyph
->padding_p
;
22669 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22671 while (glyph
< last
22672 && glyph
->type
== CHAR_GLYPH
22673 && glyph
->voffset
== voffset
22674 /* Same face id implies same font, nowadays. */
22675 && glyph
->face_id
== face_id
22676 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22680 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22681 s
->char2b
+ s
->nchars
,
22683 s
->two_byte_p
= two_byte_p
;
22685 eassert (s
->nchars
<= end
- start
);
22686 s
->width
+= glyph
->pixel_width
;
22687 if (glyph
++->padding_p
!= s
->padding_p
)
22691 s
->font
= s
->face
->font
;
22693 /* If the specified font could not be loaded, use the frame's font,
22694 but record the fact that we couldn't load it in
22695 S->font_not_found_p so that we can draw rectangles for the
22696 characters of the glyph string. */
22697 if (s
->font
== NULL
|| glyph_not_available_p
)
22699 s
->font_not_found_p
= 1;
22700 s
->font
= FRAME_FONT (s
->f
);
22703 /* Adjust base line for subscript/superscript text. */
22704 s
->ybase
+= voffset
;
22706 eassert (s
->face
&& s
->face
->gc
);
22707 return glyph
- s
->row
->glyphs
[s
->area
];
22711 /* Fill glyph string S from image glyph S->first_glyph. */
22714 fill_image_glyph_string (struct glyph_string
*s
)
22716 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22717 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22719 s
->slice
= s
->first_glyph
->slice
.img
;
22720 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22721 s
->font
= s
->face
->font
;
22722 s
->width
= s
->first_glyph
->pixel_width
;
22724 /* Adjust base line for subscript/superscript text. */
22725 s
->ybase
+= s
->first_glyph
->voffset
;
22729 /* Fill glyph string S from a sequence of stretch glyphs.
22731 START is the index of the first glyph to consider,
22732 END is the index of the last + 1.
22734 Value is the index of the first glyph not in S. */
22737 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22739 struct glyph
*glyph
, *last
;
22740 int voffset
, face_id
;
22742 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22744 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22745 last
= s
->row
->glyphs
[s
->area
] + end
;
22746 face_id
= glyph
->face_id
;
22747 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22748 s
->font
= s
->face
->font
;
22749 s
->width
= glyph
->pixel_width
;
22751 voffset
= glyph
->voffset
;
22755 && glyph
->type
== STRETCH_GLYPH
22756 && glyph
->voffset
== voffset
22757 && glyph
->face_id
== face_id
);
22759 s
->width
+= glyph
->pixel_width
;
22761 /* Adjust base line for subscript/superscript text. */
22762 s
->ybase
+= voffset
;
22764 /* The case that face->gc == 0 is handled when drawing the glyph
22765 string by calling PREPARE_FACE_FOR_DISPLAY. */
22767 return glyph
- s
->row
->glyphs
[s
->area
];
22770 static struct font_metrics
*
22771 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22773 static struct font_metrics metrics
;
22774 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22776 if (! font
|| code
== FONT_INVALID_CODE
)
22778 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22783 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22784 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22785 assumed to be zero. */
22788 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22790 *left
= *right
= 0;
22792 if (glyph
->type
== CHAR_GLYPH
)
22796 struct font_metrics
*pcm
;
22798 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22799 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22801 if (pcm
->rbearing
> pcm
->width
)
22802 *right
= pcm
->rbearing
- pcm
->width
;
22803 if (pcm
->lbearing
< 0)
22804 *left
= -pcm
->lbearing
;
22807 else if (glyph
->type
== COMPOSITE_GLYPH
)
22809 if (! glyph
->u
.cmp
.automatic
)
22811 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22813 if (cmp
->rbearing
> cmp
->pixel_width
)
22814 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22815 if (cmp
->lbearing
< 0)
22816 *left
= - cmp
->lbearing
;
22820 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22821 struct font_metrics metrics
;
22823 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22824 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22825 if (metrics
.rbearing
> metrics
.width
)
22826 *right
= metrics
.rbearing
- metrics
.width
;
22827 if (metrics
.lbearing
< 0)
22828 *left
= - metrics
.lbearing
;
22834 /* Return the index of the first glyph preceding glyph string S that
22835 is overwritten by S because of S's left overhang. Value is -1
22836 if no glyphs are overwritten. */
22839 left_overwritten (struct glyph_string
*s
)
22843 if (s
->left_overhang
)
22846 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22847 int first
= s
->first_glyph
- glyphs
;
22849 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22850 x
-= glyphs
[i
].pixel_width
;
22861 /* Return the index of the first glyph preceding glyph string S that
22862 is overwriting S because of its right overhang. Value is -1 if no
22863 glyph in front of S overwrites S. */
22866 left_overwriting (struct glyph_string
*s
)
22869 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22870 int first
= s
->first_glyph
- glyphs
;
22874 for (i
= first
- 1; i
>= 0; --i
)
22877 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22880 x
-= glyphs
[i
].pixel_width
;
22887 /* Return the index of the last glyph following glyph string S that is
22888 overwritten by S because of S's right overhang. Value is -1 if
22889 no such glyph is found. */
22892 right_overwritten (struct glyph_string
*s
)
22896 if (s
->right_overhang
)
22899 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22900 int first
= (s
->first_glyph
- glyphs
22901 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22902 int end
= s
->row
->used
[s
->area
];
22904 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22905 x
+= glyphs
[i
].pixel_width
;
22914 /* Return the index of the last glyph following glyph string S that
22915 overwrites S because of its left overhang. Value is negative
22916 if no such glyph is found. */
22919 right_overwriting (struct glyph_string
*s
)
22922 int end
= s
->row
->used
[s
->area
];
22923 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22924 int first
= (s
->first_glyph
- glyphs
22925 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22929 for (i
= first
; i
< end
; ++i
)
22932 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22935 x
+= glyphs
[i
].pixel_width
;
22942 /* Set background width of glyph string S. START is the index of the
22943 first glyph following S. LAST_X is the right-most x-position + 1
22944 in the drawing area. */
22947 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22949 /* If the face of this glyph string has to be drawn to the end of
22950 the drawing area, set S->extends_to_end_of_line_p. */
22952 if (start
== s
->row
->used
[s
->area
]
22953 && s
->area
== TEXT_AREA
22954 && ((s
->row
->fill_line_p
22955 && (s
->hl
== DRAW_NORMAL_TEXT
22956 || s
->hl
== DRAW_IMAGE_RAISED
22957 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22958 || s
->hl
== DRAW_MOUSE_FACE
))
22959 s
->extends_to_end_of_line_p
= 1;
22961 /* If S extends its face to the end of the line, set its
22962 background_width to the distance to the right edge of the drawing
22964 if (s
->extends_to_end_of_line_p
)
22965 s
->background_width
= last_x
- s
->x
+ 1;
22967 s
->background_width
= s
->width
;
22971 /* Compute overhangs and x-positions for glyph string S and its
22972 predecessors, or successors. X is the starting x-position for S.
22973 BACKWARD_P non-zero means process predecessors. */
22976 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22982 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22983 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22993 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22994 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23004 /* The following macros are only called from draw_glyphs below.
23005 They reference the following parameters of that function directly:
23006 `w', `row', `area', and `overlap_p'
23007 as well as the following local variables:
23008 `s', `f', and `hdc' (in W32) */
23011 /* On W32, silently add local `hdc' variable to argument list of
23012 init_glyph_string. */
23013 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23014 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23016 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23017 init_glyph_string (s, char2b, w, row, area, start, hl)
23020 /* Add a glyph string for a stretch glyph to the list of strings
23021 between HEAD and TAIL. START is the index of the stretch glyph in
23022 row area AREA of glyph row ROW. END is the index of the last glyph
23023 in that glyph row area. X is the current output position assigned
23024 to the new glyph string constructed. HL overrides that face of the
23025 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23026 is the right-most x-position of the drawing area. */
23028 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23029 and below -- keep them on one line. */
23030 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23033 s = alloca (sizeof *s); \
23034 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23035 START = fill_stretch_glyph_string (s, START, END); \
23036 append_glyph_string (&HEAD, &TAIL, s); \
23042 /* Add a glyph string for an image glyph to the list of strings
23043 between HEAD and TAIL. START is the index of the image glyph in
23044 row area AREA of glyph row ROW. END is the index of the last glyph
23045 in that glyph row area. X is the current output position assigned
23046 to the new glyph string constructed. HL overrides that face of the
23047 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23048 is the right-most x-position of the drawing area. */
23050 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23053 s = alloca (sizeof *s); \
23054 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23055 fill_image_glyph_string (s); \
23056 append_glyph_string (&HEAD, &TAIL, s); \
23063 /* Add a glyph string for a sequence of character glyphs to the list
23064 of strings between HEAD and TAIL. START is the index of the first
23065 glyph in row area AREA of glyph row ROW that is part of the new
23066 glyph string. END is the index of the last glyph in that glyph row
23067 area. X is the current output position assigned to the new glyph
23068 string constructed. HL overrides that face of the glyph; e.g. it
23069 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23070 right-most x-position of the drawing area. */
23072 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23078 face_id = (row)->glyphs[area][START].face_id; \
23080 s = alloca (sizeof *s); \
23081 char2b = alloca ((END - START) * sizeof *char2b); \
23082 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23083 append_glyph_string (&HEAD, &TAIL, s); \
23085 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23090 /* Add a glyph string for a composite sequence to the list of strings
23091 between HEAD and TAIL. START is the index of the first glyph in
23092 row area AREA of glyph row ROW that is part of the new glyph
23093 string. END is the index of the last glyph in that glyph row area.
23094 X is the current output position assigned to the new glyph string
23095 constructed. HL overrides that face of the glyph; e.g. it is
23096 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23097 x-position of the drawing area. */
23099 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23101 int face_id = (row)->glyphs[area][START].face_id; \
23102 struct face *base_face = FACE_FROM_ID (f, face_id); \
23103 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23104 struct composition *cmp = composition_table[cmp_id]; \
23106 struct glyph_string *first_s = NULL; \
23109 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23111 /* Make glyph_strings for each glyph sequence that is drawable by \
23112 the same face, and append them to HEAD/TAIL. */ \
23113 for (n = 0; n < cmp->glyph_len;) \
23115 s = alloca (sizeof *s); \
23116 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23117 append_glyph_string (&(HEAD), &(TAIL), s); \
23123 n = fill_composite_glyph_string (s, base_face, overlaps); \
23131 /* Add a glyph string for a glyph-string sequence to the list of strings
23132 between HEAD and TAIL. */
23134 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23138 Lisp_Object gstring; \
23140 face_id = (row)->glyphs[area][START].face_id; \
23141 gstring = (composition_gstring_from_id \
23142 ((row)->glyphs[area][START].u.cmp.id)); \
23143 s = alloca (sizeof *s); \
23144 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23145 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23146 append_glyph_string (&(HEAD), &(TAIL), s); \
23148 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23152 /* Add a glyph string for a sequence of glyphless character's glyphs
23153 to the list of strings between HEAD and TAIL. The meanings of
23154 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23156 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23161 face_id = (row)->glyphs[area][START].face_id; \
23163 s = alloca (sizeof *s); \
23164 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23165 append_glyph_string (&HEAD, &TAIL, s); \
23167 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23173 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23174 of AREA of glyph row ROW on window W between indices START and END.
23175 HL overrides the face for drawing glyph strings, e.g. it is
23176 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23177 x-positions of the drawing area.
23179 This is an ugly monster macro construct because we must use alloca
23180 to allocate glyph strings (because draw_glyphs can be called
23181 asynchronously). */
23183 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23186 HEAD = TAIL = NULL; \
23187 while (START < END) \
23189 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23190 switch (first_glyph->type) \
23193 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23197 case COMPOSITE_GLYPH: \
23198 if (first_glyph->u.cmp.automatic) \
23199 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23202 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23206 case STRETCH_GLYPH: \
23207 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23211 case IMAGE_GLYPH: \
23212 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23216 case GLYPHLESS_GLYPH: \
23217 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23227 set_glyph_string_background_width (s, START, LAST_X); \
23234 /* Draw glyphs between START and END in AREA of ROW on window W,
23235 starting at x-position X. X is relative to AREA in W. HL is a
23236 face-override with the following meaning:
23238 DRAW_NORMAL_TEXT draw normally
23239 DRAW_CURSOR draw in cursor face
23240 DRAW_MOUSE_FACE draw in mouse face.
23241 DRAW_INVERSE_VIDEO draw in mode line face
23242 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23243 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23245 If OVERLAPS is non-zero, draw only the foreground of characters and
23246 clip to the physical height of ROW. Non-zero value also defines
23247 the overlapping part to be drawn:
23249 OVERLAPS_PRED overlap with preceding rows
23250 OVERLAPS_SUCC overlap with succeeding rows
23251 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23252 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23254 Value is the x-position reached, relative to AREA of W. */
23257 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23258 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23259 enum draw_glyphs_face hl
, int overlaps
)
23261 struct glyph_string
*head
, *tail
;
23262 struct glyph_string
*s
;
23263 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23264 int i
, j
, x_reached
, last_x
, area_left
= 0;
23265 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23268 ALLOCATE_HDC (hdc
, f
);
23270 /* Let's rather be paranoid than getting a SEGV. */
23271 end
= min (end
, row
->used
[area
]);
23272 start
= clip_to_bounds (0, start
, end
);
23274 /* Translate X to frame coordinates. Set last_x to the right
23275 end of the drawing area. */
23276 if (row
->full_width_p
)
23278 /* X is relative to the left edge of W, without scroll bars
23280 area_left
= WINDOW_LEFT_EDGE_X (w
);
23281 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23285 area_left
= window_box_left (w
, area
);
23286 last_x
= area_left
+ window_box_width (w
, area
);
23290 /* Build a doubly-linked list of glyph_string structures between
23291 head and tail from what we have to draw. Note that the macro
23292 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23293 the reason we use a separate variable `i'. */
23295 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23297 x_reached
= tail
->x
+ tail
->background_width
;
23301 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23302 the row, redraw some glyphs in front or following the glyph
23303 strings built above. */
23304 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23306 struct glyph_string
*h
, *t
;
23307 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23308 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23309 int check_mouse_face
= 0;
23312 /* If mouse highlighting is on, we may need to draw adjacent
23313 glyphs using mouse-face highlighting. */
23314 if (area
== TEXT_AREA
&& row
->mouse_face_p
23315 && hlinfo
->mouse_face_beg_row
>= 0
23316 && hlinfo
->mouse_face_end_row
>= 0)
23318 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23320 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23321 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23323 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23325 check_mouse_face
= 1;
23326 mouse_beg_col
= (row
== mouse_beg_row
)
23327 ? hlinfo
->mouse_face_beg_col
: 0;
23328 mouse_end_col
= (row
== mouse_end_row
)
23329 ? hlinfo
->mouse_face_end_col
23330 : row
->used
[TEXT_AREA
];
23334 /* Compute overhangs for all glyph strings. */
23335 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23336 for (s
= head
; s
; s
= s
->next
)
23337 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23339 /* Prepend glyph strings for glyphs in front of the first glyph
23340 string that are overwritten because of the first glyph
23341 string's left overhang. The background of all strings
23342 prepended must be drawn because the first glyph string
23344 i
= left_overwritten (head
);
23347 enum draw_glyphs_face overlap_hl
;
23349 /* If this row contains mouse highlighting, attempt to draw
23350 the overlapped glyphs with the correct highlight. This
23351 code fails if the overlap encompasses more than one glyph
23352 and mouse-highlight spans only some of these glyphs.
23353 However, making it work perfectly involves a lot more
23354 code, and I don't know if the pathological case occurs in
23355 practice, so we'll stick to this for now. --- cyd */
23356 if (check_mouse_face
23357 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23358 overlap_hl
= DRAW_MOUSE_FACE
;
23360 overlap_hl
= DRAW_NORMAL_TEXT
;
23363 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23364 overlap_hl
, dummy_x
, last_x
);
23366 compute_overhangs_and_x (t
, head
->x
, 1);
23367 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23371 /* Prepend glyph strings for glyphs in front of the first glyph
23372 string that overwrite that glyph string because of their
23373 right overhang. For these strings, only the foreground must
23374 be drawn, because it draws over the glyph string at `head'.
23375 The background must not be drawn because this would overwrite
23376 right overhangs of preceding glyphs for which no glyph
23378 i
= left_overwriting (head
);
23381 enum draw_glyphs_face overlap_hl
;
23383 if (check_mouse_face
23384 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23385 overlap_hl
= DRAW_MOUSE_FACE
;
23387 overlap_hl
= DRAW_NORMAL_TEXT
;
23390 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23391 overlap_hl
, dummy_x
, last_x
);
23392 for (s
= h
; s
; s
= s
->next
)
23393 s
->background_filled_p
= 1;
23394 compute_overhangs_and_x (t
, head
->x
, 1);
23395 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23398 /* Append glyphs strings for glyphs following the last glyph
23399 string tail that are overwritten by tail. The background of
23400 these strings has to be drawn because tail's foreground draws
23402 i
= right_overwritten (tail
);
23405 enum draw_glyphs_face overlap_hl
;
23407 if (check_mouse_face
23408 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23409 overlap_hl
= DRAW_MOUSE_FACE
;
23411 overlap_hl
= DRAW_NORMAL_TEXT
;
23413 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23414 overlap_hl
, x
, last_x
);
23415 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23416 we don't have `end = i;' here. */
23417 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23418 append_glyph_string_lists (&head
, &tail
, h
, t
);
23422 /* Append glyph strings for glyphs following the last glyph
23423 string tail that overwrite tail. The foreground of such
23424 glyphs has to be drawn because it writes into the background
23425 of tail. The background must not be drawn because it could
23426 paint over the foreground of following glyphs. */
23427 i
= right_overwriting (tail
);
23430 enum draw_glyphs_face overlap_hl
;
23431 if (check_mouse_face
23432 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23433 overlap_hl
= DRAW_MOUSE_FACE
;
23435 overlap_hl
= DRAW_NORMAL_TEXT
;
23438 i
++; /* We must include the Ith glyph. */
23439 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23440 overlap_hl
, x
, last_x
);
23441 for (s
= h
; s
; s
= s
->next
)
23442 s
->background_filled_p
= 1;
23443 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23444 append_glyph_string_lists (&head
, &tail
, h
, t
);
23446 if (clip_head
|| clip_tail
)
23447 for (s
= head
; s
; s
= s
->next
)
23449 s
->clip_head
= clip_head
;
23450 s
->clip_tail
= clip_tail
;
23454 /* Draw all strings. */
23455 for (s
= head
; s
; s
= s
->next
)
23456 FRAME_RIF (f
)->draw_glyph_string (s
);
23459 /* When focus a sole frame and move horizontally, this sets on_p to 0
23460 causing a failure to erase prev cursor position. */
23461 if (area
== TEXT_AREA
23462 && !row
->full_width_p
23463 /* When drawing overlapping rows, only the glyph strings'
23464 foreground is drawn, which doesn't erase a cursor
23468 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23469 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23470 : (tail
? tail
->x
+ tail
->background_width
: x
));
23474 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23475 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23479 /* Value is the x-position up to which drawn, relative to AREA of W.
23480 This doesn't include parts drawn because of overhangs. */
23481 if (row
->full_width_p
)
23482 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23484 x_reached
-= area_left
;
23486 RELEASE_HDC (hdc
, f
);
23491 /* Expand row matrix if too narrow. Don't expand if area
23494 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23496 if (!fonts_changed_p \
23497 && (it->glyph_row->glyphs[area] \
23498 < it->glyph_row->glyphs[area + 1])) \
23500 it->w->ncols_scale_factor++; \
23501 fonts_changed_p = 1; \
23505 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23506 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23509 append_glyph (struct it
*it
)
23511 struct glyph
*glyph
;
23512 enum glyph_row_area area
= it
->area
;
23514 eassert (it
->glyph_row
);
23515 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23517 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23518 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23520 /* If the glyph row is reversed, we need to prepend the glyph
23521 rather than append it. */
23522 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23526 /* Make room for the additional glyph. */
23527 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23529 glyph
= it
->glyph_row
->glyphs
[area
];
23531 glyph
->charpos
= CHARPOS (it
->position
);
23532 glyph
->object
= it
->object
;
23533 if (it
->pixel_width
> 0)
23535 glyph
->pixel_width
= it
->pixel_width
;
23536 glyph
->padding_p
= 0;
23540 /* Assure at least 1-pixel width. Otherwise, cursor can't
23541 be displayed correctly. */
23542 glyph
->pixel_width
= 1;
23543 glyph
->padding_p
= 1;
23545 glyph
->ascent
= it
->ascent
;
23546 glyph
->descent
= it
->descent
;
23547 glyph
->voffset
= it
->voffset
;
23548 glyph
->type
= CHAR_GLYPH
;
23549 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23550 glyph
->multibyte_p
= it
->multibyte_p
;
23551 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23553 /* In R2L rows, the left and the right box edges need to be
23554 drawn in reverse direction. */
23555 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23556 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23560 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23561 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23563 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23564 || it
->phys_descent
> it
->descent
);
23565 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23566 glyph
->face_id
= it
->face_id
;
23567 glyph
->u
.ch
= it
->char_to_display
;
23568 glyph
->slice
.img
= null_glyph_slice
;
23569 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23572 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23573 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23575 glyph
->bidi_type
= it
->bidi_it
.type
;
23579 glyph
->resolved_level
= 0;
23580 glyph
->bidi_type
= UNKNOWN_BT
;
23582 ++it
->glyph_row
->used
[area
];
23585 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23588 /* Store one glyph for the composition IT->cmp_it.id in
23589 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23593 append_composite_glyph (struct it
*it
)
23595 struct glyph
*glyph
;
23596 enum glyph_row_area area
= it
->area
;
23598 eassert (it
->glyph_row
);
23600 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23601 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23603 /* If the glyph row is reversed, we need to prepend the glyph
23604 rather than append it. */
23605 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23609 /* Make room for the new glyph. */
23610 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23612 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23614 glyph
->charpos
= it
->cmp_it
.charpos
;
23615 glyph
->object
= it
->object
;
23616 glyph
->pixel_width
= it
->pixel_width
;
23617 glyph
->ascent
= it
->ascent
;
23618 glyph
->descent
= it
->descent
;
23619 glyph
->voffset
= it
->voffset
;
23620 glyph
->type
= COMPOSITE_GLYPH
;
23621 if (it
->cmp_it
.ch
< 0)
23623 glyph
->u
.cmp
.automatic
= 0;
23624 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23625 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23629 glyph
->u
.cmp
.automatic
= 1;
23630 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23631 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23632 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23634 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23635 glyph
->multibyte_p
= it
->multibyte_p
;
23636 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23638 /* In R2L rows, the left and the right box edges need to be
23639 drawn in reverse direction. */
23640 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23641 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23645 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23646 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23648 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23649 || it
->phys_descent
> it
->descent
);
23650 glyph
->padding_p
= 0;
23651 glyph
->glyph_not_available_p
= 0;
23652 glyph
->face_id
= it
->face_id
;
23653 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23656 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23657 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23659 glyph
->bidi_type
= it
->bidi_it
.type
;
23661 ++it
->glyph_row
->used
[area
];
23664 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23668 /* Change IT->ascent and IT->height according to the setting of
23672 take_vertical_position_into_account (struct it
*it
)
23676 if (it
->voffset
< 0)
23677 /* Increase the ascent so that we can display the text higher
23679 it
->ascent
-= it
->voffset
;
23681 /* Increase the descent so that we can display the text lower
23683 it
->descent
+= it
->voffset
;
23688 /* Produce glyphs/get display metrics for the image IT is loaded with.
23689 See the description of struct display_iterator in dispextern.h for
23690 an overview of struct display_iterator. */
23693 produce_image_glyph (struct it
*it
)
23697 int glyph_ascent
, crop
;
23698 struct glyph_slice slice
;
23700 eassert (it
->what
== IT_IMAGE
);
23702 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23704 /* Make sure X resources of the face is loaded. */
23705 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23707 if (it
->image_id
< 0)
23709 /* Fringe bitmap. */
23710 it
->ascent
= it
->phys_ascent
= 0;
23711 it
->descent
= it
->phys_descent
= 0;
23712 it
->pixel_width
= 0;
23717 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23719 /* Make sure X resources of the image is loaded. */
23720 prepare_image_for_display (it
->f
, img
);
23722 slice
.x
= slice
.y
= 0;
23723 slice
.width
= img
->width
;
23724 slice
.height
= img
->height
;
23726 if (INTEGERP (it
->slice
.x
))
23727 slice
.x
= XINT (it
->slice
.x
);
23728 else if (FLOATP (it
->slice
.x
))
23729 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23731 if (INTEGERP (it
->slice
.y
))
23732 slice
.y
= XINT (it
->slice
.y
);
23733 else if (FLOATP (it
->slice
.y
))
23734 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23736 if (INTEGERP (it
->slice
.width
))
23737 slice
.width
= XINT (it
->slice
.width
);
23738 else if (FLOATP (it
->slice
.width
))
23739 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23741 if (INTEGERP (it
->slice
.height
))
23742 slice
.height
= XINT (it
->slice
.height
);
23743 else if (FLOATP (it
->slice
.height
))
23744 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23746 if (slice
.x
>= img
->width
)
23747 slice
.x
= img
->width
;
23748 if (slice
.y
>= img
->height
)
23749 slice
.y
= img
->height
;
23750 if (slice
.x
+ slice
.width
>= img
->width
)
23751 slice
.width
= img
->width
- slice
.x
;
23752 if (slice
.y
+ slice
.height
> img
->height
)
23753 slice
.height
= img
->height
- slice
.y
;
23755 if (slice
.width
== 0 || slice
.height
== 0)
23758 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23760 it
->descent
= slice
.height
- glyph_ascent
;
23762 it
->descent
+= img
->vmargin
;
23763 if (slice
.y
+ slice
.height
== img
->height
)
23764 it
->descent
+= img
->vmargin
;
23765 it
->phys_descent
= it
->descent
;
23767 it
->pixel_width
= slice
.width
;
23769 it
->pixel_width
+= img
->hmargin
;
23770 if (slice
.x
+ slice
.width
== img
->width
)
23771 it
->pixel_width
+= img
->hmargin
;
23773 /* It's quite possible for images to have an ascent greater than
23774 their height, so don't get confused in that case. */
23775 if (it
->descent
< 0)
23780 if (face
->box
!= FACE_NO_BOX
)
23782 if (face
->box_line_width
> 0)
23785 it
->ascent
+= face
->box_line_width
;
23786 if (slice
.y
+ slice
.height
== img
->height
)
23787 it
->descent
+= face
->box_line_width
;
23790 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23791 it
->pixel_width
+= eabs (face
->box_line_width
);
23792 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23793 it
->pixel_width
+= eabs (face
->box_line_width
);
23796 take_vertical_position_into_account (it
);
23798 /* Automatically crop wide image glyphs at right edge so we can
23799 draw the cursor on same display row. */
23800 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23801 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23803 it
->pixel_width
-= crop
;
23804 slice
.width
-= crop
;
23809 struct glyph
*glyph
;
23810 enum glyph_row_area area
= it
->area
;
23812 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23813 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23815 glyph
->charpos
= CHARPOS (it
->position
);
23816 glyph
->object
= it
->object
;
23817 glyph
->pixel_width
= it
->pixel_width
;
23818 glyph
->ascent
= glyph_ascent
;
23819 glyph
->descent
= it
->descent
;
23820 glyph
->voffset
= it
->voffset
;
23821 glyph
->type
= IMAGE_GLYPH
;
23822 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23823 glyph
->multibyte_p
= it
->multibyte_p
;
23824 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23826 /* In R2L rows, the left and the right box edges need to be
23827 drawn in reverse direction. */
23828 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23829 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23833 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23834 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23836 glyph
->overlaps_vertically_p
= 0;
23837 glyph
->padding_p
= 0;
23838 glyph
->glyph_not_available_p
= 0;
23839 glyph
->face_id
= it
->face_id
;
23840 glyph
->u
.img_id
= img
->id
;
23841 glyph
->slice
.img
= slice
;
23842 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23845 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23846 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23848 glyph
->bidi_type
= it
->bidi_it
.type
;
23850 ++it
->glyph_row
->used
[area
];
23853 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23858 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23859 of the glyph, WIDTH and HEIGHT are the width and height of the
23860 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23863 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23864 int width
, int height
, int ascent
)
23866 struct glyph
*glyph
;
23867 enum glyph_row_area area
= it
->area
;
23869 eassert (ascent
>= 0 && ascent
<= height
);
23871 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23872 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23874 /* If the glyph row is reversed, we need to prepend the glyph
23875 rather than append it. */
23876 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23880 /* Make room for the additional glyph. */
23881 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23883 glyph
= it
->glyph_row
->glyphs
[area
];
23885 glyph
->charpos
= CHARPOS (it
->position
);
23886 glyph
->object
= object
;
23887 glyph
->pixel_width
= width
;
23888 glyph
->ascent
= ascent
;
23889 glyph
->descent
= height
- ascent
;
23890 glyph
->voffset
= it
->voffset
;
23891 glyph
->type
= STRETCH_GLYPH
;
23892 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23893 glyph
->multibyte_p
= it
->multibyte_p
;
23894 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23896 /* In R2L rows, the left and the right box edges need to be
23897 drawn in reverse direction. */
23898 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23899 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23903 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23904 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23906 glyph
->overlaps_vertically_p
= 0;
23907 glyph
->padding_p
= 0;
23908 glyph
->glyph_not_available_p
= 0;
23909 glyph
->face_id
= it
->face_id
;
23910 glyph
->u
.stretch
.ascent
= ascent
;
23911 glyph
->u
.stretch
.height
= height
;
23912 glyph
->slice
.img
= null_glyph_slice
;
23913 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23916 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23917 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23919 glyph
->bidi_type
= it
->bidi_it
.type
;
23923 glyph
->resolved_level
= 0;
23924 glyph
->bidi_type
= UNKNOWN_BT
;
23926 ++it
->glyph_row
->used
[area
];
23929 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23932 #endif /* HAVE_WINDOW_SYSTEM */
23934 /* Produce a stretch glyph for iterator IT. IT->object is the value
23935 of the glyph property displayed. The value must be a list
23936 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23939 1. `:width WIDTH' specifies that the space should be WIDTH *
23940 canonical char width wide. WIDTH may be an integer or floating
23943 2. `:relative-width FACTOR' specifies that the width of the stretch
23944 should be computed from the width of the first character having the
23945 `glyph' property, and should be FACTOR times that width.
23947 3. `:align-to HPOS' specifies that the space should be wide enough
23948 to reach HPOS, a value in canonical character units.
23950 Exactly one of the above pairs must be present.
23952 4. `:height HEIGHT' specifies that the height of the stretch produced
23953 should be HEIGHT, measured in canonical character units.
23955 5. `:relative-height FACTOR' specifies that the height of the
23956 stretch should be FACTOR times the height of the characters having
23957 the glyph property.
23959 Either none or exactly one of 4 or 5 must be present.
23961 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23962 of the stretch should be used for the ascent of the stretch.
23963 ASCENT must be in the range 0 <= ASCENT <= 100. */
23966 produce_stretch_glyph (struct it
*it
)
23968 /* (space :width WIDTH :height HEIGHT ...) */
23969 Lisp_Object prop
, plist
;
23970 int width
= 0, height
= 0, align_to
= -1;
23971 int zero_width_ok_p
= 0;
23973 struct font
*font
= NULL
;
23975 #ifdef HAVE_WINDOW_SYSTEM
23977 int zero_height_ok_p
= 0;
23979 if (FRAME_WINDOW_P (it
->f
))
23981 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23982 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23983 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23987 /* List should start with `space'. */
23988 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23989 plist
= XCDR (it
->object
);
23991 /* Compute the width of the stretch. */
23992 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23993 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23995 /* Absolute width `:width WIDTH' specified and valid. */
23996 zero_width_ok_p
= 1;
23999 #ifdef HAVE_WINDOW_SYSTEM
24000 else if (FRAME_WINDOW_P (it
->f
)
24001 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24003 /* Relative width `:relative-width FACTOR' specified and valid.
24004 Compute the width of the characters having the `glyph'
24007 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24010 if (it
->multibyte_p
)
24011 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24014 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24015 if (! ASCII_CHAR_P (it2
.c
))
24016 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24019 it2
.glyph_row
= NULL
;
24020 it2
.what
= IT_CHARACTER
;
24021 x_produce_glyphs (&it2
);
24022 width
= NUMVAL (prop
) * it2
.pixel_width
;
24024 #endif /* HAVE_WINDOW_SYSTEM */
24025 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24026 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24028 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24029 align_to
= (align_to
< 0
24031 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24032 else if (align_to
< 0)
24033 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24034 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24035 zero_width_ok_p
= 1;
24038 /* Nothing specified -> width defaults to canonical char width. */
24039 width
= FRAME_COLUMN_WIDTH (it
->f
);
24041 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24044 #ifdef HAVE_WINDOW_SYSTEM
24045 /* Compute height. */
24046 if (FRAME_WINDOW_P (it
->f
))
24048 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24049 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24052 zero_height_ok_p
= 1;
24054 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24056 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24058 height
= FONT_HEIGHT (font
);
24060 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24063 /* Compute percentage of height used for ascent. If
24064 `:ascent ASCENT' is present and valid, use that. Otherwise,
24065 derive the ascent from the font in use. */
24066 if (prop
= Fplist_get (plist
, QCascent
),
24067 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24068 ascent
= height
* NUMVAL (prop
) / 100.0;
24069 else if (!NILP (prop
)
24070 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24071 ascent
= min (max (0, (int)tem
), height
);
24073 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24076 #endif /* HAVE_WINDOW_SYSTEM */
24079 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24080 && it
->current_x
+ width
> it
->last_visible_x
)
24082 width
= it
->last_visible_x
- it
->current_x
;
24083 #ifdef HAVE_WINDOW_SYSTEM
24084 /* Subtract one more pixel from the stretch width, but only on
24085 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24086 width
-= FRAME_WINDOW_P (it
->f
);
24090 if (width
> 0 && height
> 0 && it
->glyph_row
)
24092 Lisp_Object o_object
= it
->object
;
24093 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24096 if (!STRINGP (object
))
24097 object
= it
->w
->buffer
;
24098 #ifdef HAVE_WINDOW_SYSTEM
24099 if (FRAME_WINDOW_P (it
->f
))
24100 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24104 it
->object
= object
;
24105 it
->char_to_display
= ' ';
24106 it
->pixel_width
= it
->len
= 1;
24108 tty_append_glyph (it
);
24109 it
->object
= o_object
;
24113 it
->pixel_width
= width
;
24114 #ifdef HAVE_WINDOW_SYSTEM
24115 if (FRAME_WINDOW_P (it
->f
))
24117 it
->ascent
= it
->phys_ascent
= ascent
;
24118 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24119 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24120 take_vertical_position_into_account (it
);
24124 it
->nglyphs
= width
;
24127 /* Get information about special display element WHAT in an
24128 environment described by IT. WHAT is one of IT_TRUNCATION or
24129 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24130 non-null glyph_row member. This function ensures that fields like
24131 face_id, c, len of IT are left untouched. */
24134 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24141 temp_it
.object
= make_number (0);
24142 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24144 if (what
== IT_CONTINUATION
)
24146 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24147 if (it
->bidi_it
.paragraph_dir
== R2L
)
24148 SET_GLYPH_FROM_CHAR (glyph
, '/');
24150 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24152 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24154 /* FIXME: Should we mirror GC for R2L lines? */
24155 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24156 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24159 else if (what
== IT_TRUNCATION
)
24161 /* Truncation glyph. */
24162 SET_GLYPH_FROM_CHAR (glyph
, '$');
24164 && (gc
= DISP_TRUNC_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
);
24174 #ifdef HAVE_WINDOW_SYSTEM
24175 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24176 is turned off, we precede the truncation/continuation glyphs by a
24177 stretch glyph whose width is computed such that these special
24178 glyphs are aligned at the window margin, even when very different
24179 fonts are used in different glyph rows. */
24180 if (FRAME_WINDOW_P (temp_it
.f
)
24181 /* init_iterator calls this with it->glyph_row == NULL, and it
24182 wants only the pixel width of the truncation/continuation
24184 && temp_it
.glyph_row
24185 /* insert_left_trunc_glyphs calls us at the beginning of the
24186 row, and it has its own calculation of the stretch glyph
24188 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24189 && (temp_it
.glyph_row
->reversed_p
24190 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24191 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24193 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24195 if (stretch_width
> 0)
24197 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24198 struct font
*font
=
24199 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24200 int stretch_ascent
=
24201 (((temp_it
.ascent
+ temp_it
.descent
)
24202 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24204 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24205 temp_it
.ascent
+ temp_it
.descent
,
24212 temp_it
.what
= IT_CHARACTER
;
24214 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24215 temp_it
.face_id
= GLYPH_FACE (glyph
);
24216 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24218 PRODUCE_GLYPHS (&temp_it
);
24219 it
->pixel_width
= temp_it
.pixel_width
;
24220 it
->nglyphs
= temp_it
.pixel_width
;
24223 #ifdef HAVE_WINDOW_SYSTEM
24225 /* Calculate line-height and line-spacing properties.
24226 An integer value specifies explicit pixel value.
24227 A float value specifies relative value to current face height.
24228 A cons (float . face-name) specifies relative value to
24229 height of specified face font.
24231 Returns height in pixels, or nil. */
24235 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24236 int boff
, int override
)
24238 Lisp_Object face_name
= Qnil
;
24239 int ascent
, descent
, height
;
24241 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24246 face_name
= XCAR (val
);
24248 if (!NUMBERP (val
))
24249 val
= make_number (1);
24250 if (NILP (face_name
))
24252 height
= it
->ascent
+ it
->descent
;
24257 if (NILP (face_name
))
24259 font
= FRAME_FONT (it
->f
);
24260 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24262 else if (EQ (face_name
, Qt
))
24271 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24273 return make_number (-1);
24275 face
= FACE_FROM_ID (it
->f
, face_id
);
24278 return make_number (-1);
24279 boff
= font
->baseline_offset
;
24280 if (font
->vertical_centering
)
24281 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24284 ascent
= FONT_BASE (font
) + boff
;
24285 descent
= FONT_DESCENT (font
) - boff
;
24289 it
->override_ascent
= ascent
;
24290 it
->override_descent
= descent
;
24291 it
->override_boff
= boff
;
24294 height
= ascent
+ descent
;
24298 height
= (int)(XFLOAT_DATA (val
) * height
);
24299 else if (INTEGERP (val
))
24300 height
*= XINT (val
);
24302 return make_number (height
);
24306 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24307 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24308 and only if this is for a character for which no font was found.
24310 If the display method (it->glyphless_method) is
24311 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24312 length of the acronym or the hexadecimal string, UPPER_XOFF and
24313 UPPER_YOFF are pixel offsets for the upper part of the string,
24314 LOWER_XOFF and LOWER_YOFF are for the lower part.
24316 For the other display methods, LEN through LOWER_YOFF are zero. */
24319 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24320 short upper_xoff
, short upper_yoff
,
24321 short lower_xoff
, short lower_yoff
)
24323 struct glyph
*glyph
;
24324 enum glyph_row_area area
= it
->area
;
24326 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24327 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24329 /* If the glyph row is reversed, we need to prepend the glyph
24330 rather than append it. */
24331 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24335 /* Make room for the additional glyph. */
24336 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24338 glyph
= it
->glyph_row
->glyphs
[area
];
24340 glyph
->charpos
= CHARPOS (it
->position
);
24341 glyph
->object
= it
->object
;
24342 glyph
->pixel_width
= it
->pixel_width
;
24343 glyph
->ascent
= it
->ascent
;
24344 glyph
->descent
= it
->descent
;
24345 glyph
->voffset
= it
->voffset
;
24346 glyph
->type
= GLYPHLESS_GLYPH
;
24347 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24348 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24349 glyph
->u
.glyphless
.len
= len
;
24350 glyph
->u
.glyphless
.ch
= it
->c
;
24351 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24352 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24353 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24354 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24355 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24356 glyph
->multibyte_p
= it
->multibyte_p
;
24357 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24359 /* In R2L rows, the left and the right box edges need to be
24360 drawn in reverse direction. */
24361 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24362 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24366 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24367 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24369 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24370 || it
->phys_descent
> it
->descent
);
24371 glyph
->padding_p
= 0;
24372 glyph
->glyph_not_available_p
= 0;
24373 glyph
->face_id
= face_id
;
24374 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24377 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24378 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24380 glyph
->bidi_type
= it
->bidi_it
.type
;
24382 ++it
->glyph_row
->used
[area
];
24385 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24389 /* Produce a glyph for a glyphless character for iterator IT.
24390 IT->glyphless_method specifies which method to use for displaying
24391 the character. See the description of enum
24392 glyphless_display_method in dispextern.h for the detail.
24394 FOR_NO_FONT is nonzero if and only if this is for a character for
24395 which no font was found. ACRONYM, if non-nil, is an acronym string
24396 for the character. */
24399 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24404 int base_width
, base_height
, width
, height
;
24405 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24408 /* Get the metrics of the base font. We always refer to the current
24410 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24411 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24412 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24413 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24414 base_height
= it
->ascent
+ it
->descent
;
24415 base_width
= font
->average_width
;
24417 /* Get a face ID for the glyph by utilizing a cache (the same way as
24418 done for `escape-glyph' in get_next_display_element). */
24419 if (it
->f
== last_glyphless_glyph_frame
24420 && it
->face_id
== last_glyphless_glyph_face_id
)
24422 face_id
= last_glyphless_glyph_merged_face_id
;
24426 /* Merge the `glyphless-char' face into the current face. */
24427 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24428 last_glyphless_glyph_frame
= it
->f
;
24429 last_glyphless_glyph_face_id
= it
->face_id
;
24430 last_glyphless_glyph_merged_face_id
= face_id
;
24433 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24435 it
->pixel_width
= THIN_SPACE_WIDTH
;
24437 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24439 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24441 width
= CHAR_WIDTH (it
->c
);
24444 else if (width
> 4)
24446 it
->pixel_width
= base_width
* width
;
24448 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24454 unsigned int code
[6];
24456 int ascent
, descent
;
24457 struct font_metrics metrics_upper
, metrics_lower
;
24459 face
= FACE_FROM_ID (it
->f
, face_id
);
24460 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24461 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24463 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24465 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24466 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24467 if (CONSP (acronym
))
24468 acronym
= XCAR (acronym
);
24469 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24473 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24474 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24477 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24478 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24479 upper_len
= (len
+ 1) / 2;
24480 font
->driver
->text_extents (font
, code
, upper_len
,
24482 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24487 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24488 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24489 upper_xoff
= upper_yoff
= 2; /* the typical case */
24490 if (base_width
>= width
)
24492 /* Align the upper to the left, the lower to the right. */
24493 it
->pixel_width
= base_width
;
24494 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24498 /* Center the shorter one. */
24499 it
->pixel_width
= width
;
24500 if (metrics_upper
.width
>= metrics_lower
.width
)
24501 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24504 /* FIXME: This code doesn't look right. It formerly was
24505 missing the "lower_xoff = 0;", which couldn't have
24506 been right since it left lower_xoff uninitialized. */
24508 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24512 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24513 top, bottom, and between upper and lower strings. */
24514 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24515 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24516 /* Center vertically.
24517 H:base_height, D:base_descent
24518 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24520 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24521 descent = D - H/2 + h/2;
24522 lower_yoff = descent - 2 - ld;
24523 upper_yoff = lower_yoff - la - 1 - ud; */
24524 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24525 descent
= it
->descent
- (base_height
- height
) / 2;
24526 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24527 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24528 - metrics_upper
.descent
);
24529 /* Don't make the height shorter than the base height. */
24530 if (height
> base_height
)
24532 it
->ascent
= ascent
;
24533 it
->descent
= descent
;
24537 it
->phys_ascent
= it
->ascent
;
24538 it
->phys_descent
= it
->descent
;
24540 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24541 upper_xoff
, upper_yoff
,
24542 lower_xoff
, lower_yoff
);
24544 take_vertical_position_into_account (it
);
24549 Produce glyphs/get display metrics for the display element IT is
24550 loaded with. See the description of struct it in dispextern.h
24551 for an overview of struct it. */
24554 x_produce_glyphs (struct it
*it
)
24556 int extra_line_spacing
= it
->extra_line_spacing
;
24558 it
->glyph_not_available_p
= 0;
24560 if (it
->what
== IT_CHARACTER
)
24563 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24564 struct font
*font
= face
->font
;
24565 struct font_metrics
*pcm
= NULL
;
24566 int boff
; /* baseline offset */
24570 /* When no suitable font is found, display this character by
24571 the method specified in the first extra slot of
24572 Vglyphless_char_display. */
24573 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24575 eassert (it
->what
== IT_GLYPHLESS
);
24576 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24580 boff
= font
->baseline_offset
;
24581 if (font
->vertical_centering
)
24582 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24584 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24590 if (it
->override_ascent
>= 0)
24592 it
->ascent
= it
->override_ascent
;
24593 it
->descent
= it
->override_descent
;
24594 boff
= it
->override_boff
;
24598 it
->ascent
= FONT_BASE (font
) + boff
;
24599 it
->descent
= FONT_DESCENT (font
) - boff
;
24602 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24604 pcm
= get_per_char_metric (font
, &char2b
);
24605 if (pcm
->width
== 0
24606 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24612 it
->phys_ascent
= pcm
->ascent
+ boff
;
24613 it
->phys_descent
= pcm
->descent
- boff
;
24614 it
->pixel_width
= pcm
->width
;
24618 it
->glyph_not_available_p
= 1;
24619 it
->phys_ascent
= it
->ascent
;
24620 it
->phys_descent
= it
->descent
;
24621 it
->pixel_width
= font
->space_width
;
24624 if (it
->constrain_row_ascent_descent_p
)
24626 if (it
->descent
> it
->max_descent
)
24628 it
->ascent
+= it
->descent
- it
->max_descent
;
24629 it
->descent
= it
->max_descent
;
24631 if (it
->ascent
> it
->max_ascent
)
24633 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24634 it
->ascent
= it
->max_ascent
;
24636 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24637 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24638 extra_line_spacing
= 0;
24641 /* If this is a space inside a region of text with
24642 `space-width' property, change its width. */
24643 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24645 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24647 /* If face has a box, add the box thickness to the character
24648 height. If character has a box line to the left and/or
24649 right, add the box line width to the character's width. */
24650 if (face
->box
!= FACE_NO_BOX
)
24652 int thick
= face
->box_line_width
;
24656 it
->ascent
+= thick
;
24657 it
->descent
+= thick
;
24662 if (it
->start_of_box_run_p
)
24663 it
->pixel_width
+= thick
;
24664 if (it
->end_of_box_run_p
)
24665 it
->pixel_width
+= thick
;
24668 /* If face has an overline, add the height of the overline
24669 (1 pixel) and a 1 pixel margin to the character height. */
24670 if (face
->overline_p
)
24671 it
->ascent
+= overline_margin
;
24673 if (it
->constrain_row_ascent_descent_p
)
24675 if (it
->ascent
> it
->max_ascent
)
24676 it
->ascent
= it
->max_ascent
;
24677 if (it
->descent
> it
->max_descent
)
24678 it
->descent
= it
->max_descent
;
24681 take_vertical_position_into_account (it
);
24683 /* If we have to actually produce glyphs, do it. */
24688 /* Translate a space with a `space-width' property
24689 into a stretch glyph. */
24690 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24691 / FONT_HEIGHT (font
));
24692 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24693 it
->ascent
+ it
->descent
, ascent
);
24698 /* If characters with lbearing or rbearing are displayed
24699 in this line, record that fact in a flag of the
24700 glyph row. This is used to optimize X output code. */
24701 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24702 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24704 if (! stretched_p
&& it
->pixel_width
== 0)
24705 /* We assure that all visible glyphs have at least 1-pixel
24707 it
->pixel_width
= 1;
24709 else if (it
->char_to_display
== '\n')
24711 /* A newline has no width, but we need the height of the
24712 line. But if previous part of the line sets a height,
24713 don't increase that height */
24715 Lisp_Object height
;
24716 Lisp_Object total_height
= Qnil
;
24718 it
->override_ascent
= -1;
24719 it
->pixel_width
= 0;
24722 height
= get_it_property (it
, Qline_height
);
24723 /* Split (line-height total-height) list */
24725 && CONSP (XCDR (height
))
24726 && NILP (XCDR (XCDR (height
))))
24728 total_height
= XCAR (XCDR (height
));
24729 height
= XCAR (height
);
24731 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24733 if (it
->override_ascent
>= 0)
24735 it
->ascent
= it
->override_ascent
;
24736 it
->descent
= it
->override_descent
;
24737 boff
= it
->override_boff
;
24741 it
->ascent
= FONT_BASE (font
) + boff
;
24742 it
->descent
= FONT_DESCENT (font
) - boff
;
24745 if (EQ (height
, Qt
))
24747 if (it
->descent
> it
->max_descent
)
24749 it
->ascent
+= it
->descent
- it
->max_descent
;
24750 it
->descent
= it
->max_descent
;
24752 if (it
->ascent
> it
->max_ascent
)
24754 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24755 it
->ascent
= it
->max_ascent
;
24757 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24758 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24759 it
->constrain_row_ascent_descent_p
= 1;
24760 extra_line_spacing
= 0;
24764 Lisp_Object spacing
;
24766 it
->phys_ascent
= it
->ascent
;
24767 it
->phys_descent
= it
->descent
;
24769 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24770 && face
->box
!= FACE_NO_BOX
24771 && face
->box_line_width
> 0)
24773 it
->ascent
+= face
->box_line_width
;
24774 it
->descent
+= face
->box_line_width
;
24777 && XINT (height
) > it
->ascent
+ it
->descent
)
24778 it
->ascent
= XINT (height
) - it
->descent
;
24780 if (!NILP (total_height
))
24781 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24784 spacing
= get_it_property (it
, Qline_spacing
);
24785 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24787 if (INTEGERP (spacing
))
24789 extra_line_spacing
= XINT (spacing
);
24790 if (!NILP (total_height
))
24791 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24795 else /* i.e. (it->char_to_display == '\t') */
24797 if (font
->space_width
> 0)
24799 int tab_width
= it
->tab_width
* font
->space_width
;
24800 int x
= it
->current_x
+ it
->continuation_lines_width
;
24801 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24803 /* If the distance from the current position to the next tab
24804 stop is less than a space character width, use the
24805 tab stop after that. */
24806 if (next_tab_x
- x
< font
->space_width
)
24807 next_tab_x
+= tab_width
;
24809 it
->pixel_width
= next_tab_x
- x
;
24811 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24812 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24816 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24817 it
->ascent
+ it
->descent
, it
->ascent
);
24822 it
->pixel_width
= 0;
24827 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24829 /* A static composition.
24831 Note: A composition is represented as one glyph in the
24832 glyph matrix. There are no padding glyphs.
24834 Important note: pixel_width, ascent, and descent are the
24835 values of what is drawn by draw_glyphs (i.e. the values of
24836 the overall glyphs composed). */
24837 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24838 int boff
; /* baseline offset */
24839 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24840 int glyph_len
= cmp
->glyph_len
;
24841 struct font
*font
= face
->font
;
24845 /* If we have not yet calculated pixel size data of glyphs of
24846 the composition for the current face font, calculate them
24847 now. Theoretically, we have to check all fonts for the
24848 glyphs, but that requires much time and memory space. So,
24849 here we check only the font of the first glyph. This may
24850 lead to incorrect display, but it's very rare, and C-l
24851 (recenter-top-bottom) can correct the display anyway. */
24852 if (! cmp
->font
|| cmp
->font
!= font
)
24854 /* Ascent and descent of the font of the first character
24855 of this composition (adjusted by baseline offset).
24856 Ascent and descent of overall glyphs should not be less
24857 than these, respectively. */
24858 int font_ascent
, font_descent
, font_height
;
24859 /* Bounding box of the overall glyphs. */
24860 int leftmost
, rightmost
, lowest
, highest
;
24861 int lbearing
, rbearing
;
24862 int i
, width
, ascent
, descent
;
24863 int left_padded
= 0, right_padded
= 0;
24864 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24866 struct font_metrics
*pcm
;
24867 int font_not_found_p
;
24870 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24871 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24873 if (glyph_len
< cmp
->glyph_len
)
24875 for (i
= 0; i
< glyph_len
; i
++)
24877 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24879 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24884 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24885 : IT_CHARPOS (*it
));
24886 /* If no suitable font is found, use the default font. */
24887 font_not_found_p
= font
== NULL
;
24888 if (font_not_found_p
)
24890 face
= face
->ascii_face
;
24893 boff
= font
->baseline_offset
;
24894 if (font
->vertical_centering
)
24895 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24896 font_ascent
= FONT_BASE (font
) + boff
;
24897 font_descent
= FONT_DESCENT (font
) - boff
;
24898 font_height
= FONT_HEIGHT (font
);
24903 if (! font_not_found_p
)
24905 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24907 pcm
= get_per_char_metric (font
, &char2b
);
24910 /* Initialize the bounding box. */
24913 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24914 ascent
= pcm
->ascent
;
24915 descent
= pcm
->descent
;
24916 lbearing
= pcm
->lbearing
;
24917 rbearing
= pcm
->rbearing
;
24921 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24922 ascent
= FONT_BASE (font
);
24923 descent
= FONT_DESCENT (font
);
24930 lowest
= - descent
+ boff
;
24931 highest
= ascent
+ boff
;
24933 if (! font_not_found_p
24934 && font
->default_ascent
24935 && CHAR_TABLE_P (Vuse_default_ascent
)
24936 && !NILP (Faref (Vuse_default_ascent
,
24937 make_number (it
->char_to_display
))))
24938 highest
= font
->default_ascent
+ boff
;
24940 /* Draw the first glyph at the normal position. It may be
24941 shifted to right later if some other glyphs are drawn
24943 cmp
->offsets
[i
* 2] = 0;
24944 cmp
->offsets
[i
* 2 + 1] = boff
;
24945 cmp
->lbearing
= lbearing
;
24946 cmp
->rbearing
= rbearing
;
24948 /* Set cmp->offsets for the remaining glyphs. */
24949 for (i
++; i
< glyph_len
; i
++)
24951 int left
, right
, btm
, top
;
24952 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24954 struct face
*this_face
;
24958 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24959 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24960 font
= this_face
->font
;
24966 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24968 pcm
= get_per_char_metric (font
, &char2b
);
24971 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24974 width
= pcm
->width
;
24975 ascent
= pcm
->ascent
;
24976 descent
= pcm
->descent
;
24977 lbearing
= pcm
->lbearing
;
24978 rbearing
= pcm
->rbearing
;
24979 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24981 /* Relative composition with or without
24982 alternate chars. */
24983 left
= (leftmost
+ rightmost
- width
) / 2;
24984 btm
= - descent
+ boff
;
24985 if (font
->relative_compose
24986 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24987 || NILP (Faref (Vignore_relative_composition
,
24988 make_number (ch
)))))
24991 if (- descent
>= font
->relative_compose
)
24992 /* One extra pixel between two glyphs. */
24994 else if (ascent
<= 0)
24995 /* One extra pixel between two glyphs. */
24996 btm
= lowest
- 1 - ascent
- descent
;
25001 /* A composition rule is specified by an integer
25002 value that encodes global and new reference
25003 points (GREF and NREF). GREF and NREF are
25004 specified by numbers as below:
25006 0---1---2 -- ascent
25010 9--10--11 -- center
25012 ---3---4---5--- baseline
25014 6---7---8 -- descent
25016 int rule
= COMPOSITION_RULE (cmp
, i
);
25017 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25019 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25020 grefx
= gref
% 3, nrefx
= nref
% 3;
25021 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25023 xoff
= font_height
* (xoff
- 128) / 256;
25025 yoff
= font_height
* (yoff
- 128) / 256;
25028 + grefx
* (rightmost
- leftmost
) / 2
25029 - nrefx
* width
/ 2
25032 btm
= ((grefy
== 0 ? highest
25034 : grefy
== 2 ? lowest
25035 : (highest
+ lowest
) / 2)
25036 - (nrefy
== 0 ? ascent
+ descent
25037 : nrefy
== 1 ? descent
- boff
25039 : (ascent
+ descent
) / 2)
25043 cmp
->offsets
[i
* 2] = left
;
25044 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25046 /* Update the bounding box of the overall glyphs. */
25049 right
= left
+ width
;
25050 if (left
< leftmost
)
25052 if (right
> rightmost
)
25055 top
= btm
+ descent
+ ascent
;
25061 if (cmp
->lbearing
> left
+ lbearing
)
25062 cmp
->lbearing
= left
+ lbearing
;
25063 if (cmp
->rbearing
< left
+ rbearing
)
25064 cmp
->rbearing
= left
+ rbearing
;
25068 /* If there are glyphs whose x-offsets are negative,
25069 shift all glyphs to the right and make all x-offsets
25073 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25074 cmp
->offsets
[i
* 2] -= leftmost
;
25075 rightmost
-= leftmost
;
25076 cmp
->lbearing
-= leftmost
;
25077 cmp
->rbearing
-= leftmost
;
25080 if (left_padded
&& cmp
->lbearing
< 0)
25082 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25083 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25084 rightmost
-= cmp
->lbearing
;
25085 cmp
->rbearing
-= cmp
->lbearing
;
25088 if (right_padded
&& rightmost
< cmp
->rbearing
)
25090 rightmost
= cmp
->rbearing
;
25093 cmp
->pixel_width
= rightmost
;
25094 cmp
->ascent
= highest
;
25095 cmp
->descent
= - lowest
;
25096 if (cmp
->ascent
< font_ascent
)
25097 cmp
->ascent
= font_ascent
;
25098 if (cmp
->descent
< font_descent
)
25099 cmp
->descent
= font_descent
;
25103 && (cmp
->lbearing
< 0
25104 || cmp
->rbearing
> cmp
->pixel_width
))
25105 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25107 it
->pixel_width
= cmp
->pixel_width
;
25108 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25109 it
->descent
= it
->phys_descent
= cmp
->descent
;
25110 if (face
->box
!= FACE_NO_BOX
)
25112 int thick
= face
->box_line_width
;
25116 it
->ascent
+= thick
;
25117 it
->descent
+= thick
;
25122 if (it
->start_of_box_run_p
)
25123 it
->pixel_width
+= thick
;
25124 if (it
->end_of_box_run_p
)
25125 it
->pixel_width
+= thick
;
25128 /* If face has an overline, add the height of the overline
25129 (1 pixel) and a 1 pixel margin to the character height. */
25130 if (face
->overline_p
)
25131 it
->ascent
+= overline_margin
;
25133 take_vertical_position_into_account (it
);
25134 if (it
->ascent
< 0)
25136 if (it
->descent
< 0)
25139 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25140 append_composite_glyph (it
);
25142 else if (it
->what
== IT_COMPOSITION
)
25144 /* A dynamic (automatic) composition. */
25145 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25146 Lisp_Object gstring
;
25147 struct font_metrics metrics
;
25151 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25153 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25156 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25157 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25158 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25159 it
->descent
= it
->phys_descent
= metrics
.descent
;
25160 if (face
->box
!= FACE_NO_BOX
)
25162 int thick
= face
->box_line_width
;
25166 it
->ascent
+= thick
;
25167 it
->descent
+= thick
;
25172 if (it
->start_of_box_run_p
)
25173 it
->pixel_width
+= thick
;
25174 if (it
->end_of_box_run_p
)
25175 it
->pixel_width
+= thick
;
25177 /* If face has an overline, add the height of the overline
25178 (1 pixel) and a 1 pixel margin to the character height. */
25179 if (face
->overline_p
)
25180 it
->ascent
+= overline_margin
;
25181 take_vertical_position_into_account (it
);
25182 if (it
->ascent
< 0)
25184 if (it
->descent
< 0)
25188 append_composite_glyph (it
);
25190 else if (it
->what
== IT_GLYPHLESS
)
25191 produce_glyphless_glyph (it
, 0, Qnil
);
25192 else if (it
->what
== IT_IMAGE
)
25193 produce_image_glyph (it
);
25194 else if (it
->what
== IT_STRETCH
)
25195 produce_stretch_glyph (it
);
25198 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25199 because this isn't true for images with `:ascent 100'. */
25200 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25201 if (it
->area
== TEXT_AREA
)
25202 it
->current_x
+= it
->pixel_width
;
25204 if (extra_line_spacing
> 0)
25206 it
->descent
+= extra_line_spacing
;
25207 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25208 it
->max_extra_line_spacing
= extra_line_spacing
;
25211 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25212 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25213 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25214 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25218 Output LEN glyphs starting at START at the nominal cursor position.
25219 Advance the nominal cursor over the text. The global variable
25220 updated_window contains the window being updated, updated_row is
25221 the glyph row being updated, and updated_area is the area of that
25222 row being updated. */
25225 x_write_glyphs (struct glyph
*start
, int len
)
25227 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25229 eassert (updated_window
&& updated_row
);
25230 /* When the window is hscrolled, cursor hpos can legitimately be out
25231 of bounds, but we draw the cursor at the corresponding window
25232 margin in that case. */
25233 if (!updated_row
->reversed_p
&& chpos
< 0)
25235 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25236 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25240 /* Write glyphs. */
25242 hpos
= start
- updated_row
->glyphs
[updated_area
];
25243 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25244 updated_row
, updated_area
,
25246 DRAW_NORMAL_TEXT
, 0);
25248 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25249 if (updated_area
== TEXT_AREA
25250 && updated_window
->phys_cursor_on_p
25251 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25253 && chpos
< hpos
+ len
)
25254 updated_window
->phys_cursor_on_p
= 0;
25258 /* Advance the output cursor. */
25259 output_cursor
.hpos
+= len
;
25260 output_cursor
.x
= x
;
25265 Insert LEN glyphs from START at the nominal cursor position. */
25268 x_insert_glyphs (struct glyph
*start
, int len
)
25272 int line_height
, shift_by_width
, shifted_region_width
;
25273 struct glyph_row
*row
;
25274 struct glyph
*glyph
;
25275 int frame_x
, frame_y
;
25278 eassert (updated_window
&& updated_row
);
25280 w
= updated_window
;
25281 f
= XFRAME (WINDOW_FRAME (w
));
25283 /* Get the height of the line we are in. */
25285 line_height
= row
->height
;
25287 /* Get the width of the glyphs to insert. */
25288 shift_by_width
= 0;
25289 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25290 shift_by_width
+= glyph
->pixel_width
;
25292 /* Get the width of the region to shift right. */
25293 shifted_region_width
= (window_box_width (w
, updated_area
)
25298 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25299 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25301 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25302 line_height
, shift_by_width
);
25304 /* Write the glyphs. */
25305 hpos
= start
- row
->glyphs
[updated_area
];
25306 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25308 DRAW_NORMAL_TEXT
, 0);
25310 /* Advance the output cursor. */
25311 output_cursor
.hpos
+= len
;
25312 output_cursor
.x
+= shift_by_width
;
25318 Erase the current text line from the nominal cursor position
25319 (inclusive) to pixel column TO_X (exclusive). The idea is that
25320 everything from TO_X onward is already erased.
25322 TO_X is a pixel position relative to updated_area of
25323 updated_window. TO_X == -1 means clear to the end of this area. */
25326 x_clear_end_of_line (int to_x
)
25329 struct window
*w
= updated_window
;
25330 int max_x
, min_y
, max_y
;
25331 int from_x
, from_y
, to_y
;
25333 eassert (updated_window
&& updated_row
);
25334 f
= XFRAME (w
->frame
);
25336 if (updated_row
->full_width_p
)
25337 max_x
= WINDOW_TOTAL_WIDTH (w
);
25339 max_x
= window_box_width (w
, updated_area
);
25340 max_y
= window_text_bottom_y (w
);
25342 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25343 of window. For TO_X > 0, truncate to end of drawing area. */
25349 to_x
= min (to_x
, max_x
);
25351 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25353 /* Notice if the cursor will be cleared by this operation. */
25354 if (!updated_row
->full_width_p
)
25355 notice_overwritten_cursor (w
, updated_area
,
25356 output_cursor
.x
, -1,
25358 MATRIX_ROW_BOTTOM_Y (updated_row
));
25360 from_x
= output_cursor
.x
;
25362 /* Translate to frame coordinates. */
25363 if (updated_row
->full_width_p
)
25365 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25366 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25370 int area_left
= window_box_left (w
, updated_area
);
25371 from_x
+= area_left
;
25375 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25376 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25377 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25379 /* Prevent inadvertently clearing to end of the X window. */
25380 if (to_x
> from_x
&& to_y
> from_y
)
25383 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25384 to_x
- from_x
, to_y
- from_y
);
25389 #endif /* HAVE_WINDOW_SYSTEM */
25393 /***********************************************************************
25395 ***********************************************************************/
25397 /* Value is the internal representation of the specified cursor type
25398 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25399 of the bar cursor. */
25401 static enum text_cursor_kinds
25402 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25404 enum text_cursor_kinds type
;
25409 if (EQ (arg
, Qbox
))
25410 return FILLED_BOX_CURSOR
;
25412 if (EQ (arg
, Qhollow
))
25413 return HOLLOW_BOX_CURSOR
;
25415 if (EQ (arg
, Qbar
))
25422 && EQ (XCAR (arg
), Qbar
)
25423 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25425 *width
= XINT (XCDR (arg
));
25429 if (EQ (arg
, Qhbar
))
25432 return HBAR_CURSOR
;
25436 && EQ (XCAR (arg
), Qhbar
)
25437 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25439 *width
= XINT (XCDR (arg
));
25440 return HBAR_CURSOR
;
25443 /* Treat anything unknown as "hollow box cursor".
25444 It was bad to signal an error; people have trouble fixing
25445 .Xdefaults with Emacs, when it has something bad in it. */
25446 type
= HOLLOW_BOX_CURSOR
;
25451 /* Set the default cursor types for specified frame. */
25453 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25458 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25459 FRAME_CURSOR_WIDTH (f
) = width
;
25461 /* By default, set up the blink-off state depending on the on-state. */
25463 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25466 FRAME_BLINK_OFF_CURSOR (f
)
25467 = get_specified_cursor_type (XCDR (tem
), &width
);
25468 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25471 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25475 #ifdef HAVE_WINDOW_SYSTEM
25477 /* Return the cursor we want to be displayed in window W. Return
25478 width of bar/hbar cursor through WIDTH arg. Return with
25479 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25480 (i.e. if the `system caret' should track this cursor).
25482 In a mini-buffer window, we want the cursor only to appear if we
25483 are reading input from this window. For the selected window, we
25484 want the cursor type given by the frame parameter or buffer local
25485 setting of cursor-type. If explicitly marked off, draw no cursor.
25486 In all other cases, we want a hollow box cursor. */
25488 static enum text_cursor_kinds
25489 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25490 int *active_cursor
)
25492 struct frame
*f
= XFRAME (w
->frame
);
25493 struct buffer
*b
= XBUFFER (w
->buffer
);
25494 int cursor_type
= DEFAULT_CURSOR
;
25495 Lisp_Object alt_cursor
;
25496 int non_selected
= 0;
25498 *active_cursor
= 1;
25501 if (cursor_in_echo_area
25502 && FRAME_HAS_MINIBUF_P (f
)
25503 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25505 if (w
== XWINDOW (echo_area_window
))
25507 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25509 *width
= FRAME_CURSOR_WIDTH (f
);
25510 return FRAME_DESIRED_CURSOR (f
);
25513 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25516 *active_cursor
= 0;
25520 /* Detect a nonselected window or nonselected frame. */
25521 else if (w
!= XWINDOW (f
->selected_window
)
25522 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25524 *active_cursor
= 0;
25526 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25532 /* Never display a cursor in a window in which cursor-type is nil. */
25533 if (NILP (BVAR (b
, cursor_type
)))
25536 /* Get the normal cursor type for this window. */
25537 if (EQ (BVAR (b
, cursor_type
), Qt
))
25539 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25540 *width
= FRAME_CURSOR_WIDTH (f
);
25543 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25545 /* Use cursor-in-non-selected-windows instead
25546 for non-selected window or frame. */
25549 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25550 if (!EQ (Qt
, alt_cursor
))
25551 return get_specified_cursor_type (alt_cursor
, width
);
25552 /* t means modify the normal cursor type. */
25553 if (cursor_type
== FILLED_BOX_CURSOR
)
25554 cursor_type
= HOLLOW_BOX_CURSOR
;
25555 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25557 return cursor_type
;
25560 /* Use normal cursor if not blinked off. */
25561 if (!w
->cursor_off_p
)
25563 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25565 if (cursor_type
== FILLED_BOX_CURSOR
)
25567 /* Using a block cursor on large images can be very annoying.
25568 So use a hollow cursor for "large" images.
25569 If image is not transparent (no mask), also use hollow cursor. */
25570 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25571 if (img
!= NULL
&& IMAGEP (img
->spec
))
25573 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25574 where N = size of default frame font size.
25575 This should cover most of the "tiny" icons people may use. */
25577 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25578 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25579 cursor_type
= HOLLOW_BOX_CURSOR
;
25582 else if (cursor_type
!= NO_CURSOR
)
25584 /* Display current only supports BOX and HOLLOW cursors for images.
25585 So for now, unconditionally use a HOLLOW cursor when cursor is
25586 not a solid box cursor. */
25587 cursor_type
= HOLLOW_BOX_CURSOR
;
25590 return cursor_type
;
25593 /* Cursor is blinked off, so determine how to "toggle" it. */
25595 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25596 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25597 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25599 /* Then see if frame has specified a specific blink off cursor type. */
25600 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25602 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25603 return FRAME_BLINK_OFF_CURSOR (f
);
25607 /* Some people liked having a permanently visible blinking cursor,
25608 while others had very strong opinions against it. So it was
25609 decided to remove it. KFS 2003-09-03 */
25611 /* Finally perform built-in cursor blinking:
25612 filled box <-> hollow box
25613 wide [h]bar <-> narrow [h]bar
25614 narrow [h]bar <-> no cursor
25615 other type <-> no cursor */
25617 if (cursor_type
== FILLED_BOX_CURSOR
)
25618 return HOLLOW_BOX_CURSOR
;
25620 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25623 return cursor_type
;
25631 /* Notice when the text cursor of window W has been completely
25632 overwritten by a drawing operation that outputs glyphs in AREA
25633 starting at X0 and ending at X1 in the line starting at Y0 and
25634 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25635 the rest of the line after X0 has been written. Y coordinates
25636 are window-relative. */
25639 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25640 int x0
, int x1
, int y0
, int y1
)
25642 int cx0
, cx1
, cy0
, cy1
;
25643 struct glyph_row
*row
;
25645 if (!w
->phys_cursor_on_p
)
25647 if (area
!= TEXT_AREA
)
25650 if (w
->phys_cursor
.vpos
< 0
25651 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25652 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25653 !(row
->enabled_p
&& row
->displays_text_p
)))
25656 if (row
->cursor_in_fringe_p
)
25658 row
->cursor_in_fringe_p
= 0;
25659 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25660 w
->phys_cursor_on_p
= 0;
25664 cx0
= w
->phys_cursor
.x
;
25665 cx1
= cx0
+ w
->phys_cursor_width
;
25666 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25669 /* The cursor image will be completely removed from the
25670 screen if the output area intersects the cursor area in
25671 y-direction. When we draw in [y0 y1[, and some part of
25672 the cursor is at y < y0, that part must have been drawn
25673 before. When scrolling, the cursor is erased before
25674 actually scrolling, so we don't come here. When not
25675 scrolling, the rows above the old cursor row must have
25676 changed, and in this case these rows must have written
25677 over the cursor image.
25679 Likewise if part of the cursor is below y1, with the
25680 exception of the cursor being in the first blank row at
25681 the buffer and window end because update_text_area
25682 doesn't draw that row. (Except when it does, but
25683 that's handled in update_text_area.) */
25685 cy0
= w
->phys_cursor
.y
;
25686 cy1
= cy0
+ w
->phys_cursor_height
;
25687 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25690 w
->phys_cursor_on_p
= 0;
25693 #endif /* HAVE_WINDOW_SYSTEM */
25696 /************************************************************************
25698 ************************************************************************/
25700 #ifdef HAVE_WINDOW_SYSTEM
25703 Fix the display of area AREA of overlapping row ROW in window W
25704 with respect to the overlapping part OVERLAPS. */
25707 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25708 enum glyph_row_area area
, int overlaps
)
25715 for (i
= 0; i
< row
->used
[area
];)
25717 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25719 int start
= i
, start_x
= x
;
25723 x
+= row
->glyphs
[area
][i
].pixel_width
;
25726 while (i
< row
->used
[area
]
25727 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25729 draw_glyphs (w
, start_x
, row
, area
,
25731 DRAW_NORMAL_TEXT
, overlaps
);
25735 x
+= row
->glyphs
[area
][i
].pixel_width
;
25745 Draw the cursor glyph of window W in glyph row ROW. See the
25746 comment of draw_glyphs for the meaning of HL. */
25749 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25750 enum draw_glyphs_face hl
)
25752 /* If cursor hpos is out of bounds, don't draw garbage. This can
25753 happen in mini-buffer windows when switching between echo area
25754 glyphs and mini-buffer. */
25755 if ((row
->reversed_p
25756 ? (w
->phys_cursor
.hpos
>= 0)
25757 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25759 int on_p
= w
->phys_cursor_on_p
;
25761 int hpos
= w
->phys_cursor
.hpos
;
25763 /* When the window is hscrolled, cursor hpos can legitimately be
25764 out of bounds, but we draw the cursor at the corresponding
25765 window margin in that case. */
25766 if (!row
->reversed_p
&& hpos
< 0)
25768 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25769 hpos
= row
->used
[TEXT_AREA
] - 1;
25771 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25773 w
->phys_cursor_on_p
= on_p
;
25775 if (hl
== DRAW_CURSOR
)
25776 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25777 /* When we erase the cursor, and ROW is overlapped by other
25778 rows, make sure that these overlapping parts of other rows
25780 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25782 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25784 if (row
> w
->current_matrix
->rows
25785 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25786 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25787 OVERLAPS_ERASED_CURSOR
);
25789 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25790 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25791 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25792 OVERLAPS_ERASED_CURSOR
);
25799 Erase the image of a cursor of window W from the screen. */
25802 erase_phys_cursor (struct window
*w
)
25804 struct frame
*f
= XFRAME (w
->frame
);
25805 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25806 int hpos
= w
->phys_cursor
.hpos
;
25807 int vpos
= w
->phys_cursor
.vpos
;
25808 int mouse_face_here_p
= 0;
25809 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25810 struct glyph_row
*cursor_row
;
25811 struct glyph
*cursor_glyph
;
25812 enum draw_glyphs_face hl
;
25814 /* No cursor displayed or row invalidated => nothing to do on the
25816 if (w
->phys_cursor_type
== NO_CURSOR
)
25817 goto mark_cursor_off
;
25819 /* VPOS >= active_glyphs->nrows means that window has been resized.
25820 Don't bother to erase the cursor. */
25821 if (vpos
>= active_glyphs
->nrows
)
25822 goto mark_cursor_off
;
25824 /* If row containing cursor is marked invalid, there is nothing we
25826 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25827 if (!cursor_row
->enabled_p
)
25828 goto mark_cursor_off
;
25830 /* If line spacing is > 0, old cursor may only be partially visible in
25831 window after split-window. So adjust visible height. */
25832 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25833 window_text_bottom_y (w
) - cursor_row
->y
);
25835 /* If row is completely invisible, don't attempt to delete a cursor which
25836 isn't there. This can happen if cursor is at top of a window, and
25837 we switch to a buffer with a header line in that window. */
25838 if (cursor_row
->visible_height
<= 0)
25839 goto mark_cursor_off
;
25841 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25842 if (cursor_row
->cursor_in_fringe_p
)
25844 cursor_row
->cursor_in_fringe_p
= 0;
25845 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25846 goto mark_cursor_off
;
25849 /* This can happen when the new row is shorter than the old one.
25850 In this case, either draw_glyphs or clear_end_of_line
25851 should have cleared the cursor. Note that we wouldn't be
25852 able to erase the cursor in this case because we don't have a
25853 cursor glyph at hand. */
25854 if ((cursor_row
->reversed_p
25855 ? (w
->phys_cursor
.hpos
< 0)
25856 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25857 goto mark_cursor_off
;
25859 /* When the window is hscrolled, cursor hpos can legitimately be out
25860 of bounds, but we draw the cursor at the corresponding window
25861 margin in that case. */
25862 if (!cursor_row
->reversed_p
&& hpos
< 0)
25864 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25865 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25867 /* If the cursor is in the mouse face area, redisplay that when
25868 we clear the cursor. */
25869 if (! NILP (hlinfo
->mouse_face_window
)
25870 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25871 /* Don't redraw the cursor's spot in mouse face if it is at the
25872 end of a line (on a newline). The cursor appears there, but
25873 mouse highlighting does not. */
25874 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25875 mouse_face_here_p
= 1;
25877 /* Maybe clear the display under the cursor. */
25878 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25881 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25884 cursor_glyph
= get_phys_cursor_glyph (w
);
25885 if (cursor_glyph
== NULL
)
25886 goto mark_cursor_off
;
25888 width
= cursor_glyph
->pixel_width
;
25889 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25890 x
= w
->phys_cursor
.x
;
25892 width
-= left_x
- x
;
25893 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25894 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25895 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25898 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25901 /* Erase the cursor by redrawing the character underneath it. */
25902 if (mouse_face_here_p
)
25903 hl
= DRAW_MOUSE_FACE
;
25905 hl
= DRAW_NORMAL_TEXT
;
25906 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25909 w
->phys_cursor_on_p
= 0;
25910 w
->phys_cursor_type
= NO_CURSOR
;
25915 Display or clear cursor of window W. If ON is zero, clear the
25916 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25917 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25920 display_and_set_cursor (struct window
*w
, int on
,
25921 int hpos
, int vpos
, int x
, int y
)
25923 struct frame
*f
= XFRAME (w
->frame
);
25924 int new_cursor_type
;
25925 int new_cursor_width
;
25927 struct glyph_row
*glyph_row
;
25928 struct glyph
*glyph
;
25930 /* This is pointless on invisible frames, and dangerous on garbaged
25931 windows and frames; in the latter case, the frame or window may
25932 be in the midst of changing its size, and x and y may be off the
25934 if (! FRAME_VISIBLE_P (f
)
25935 || FRAME_GARBAGED_P (f
)
25936 || vpos
>= w
->current_matrix
->nrows
25937 || hpos
>= w
->current_matrix
->matrix_w
)
25940 /* If cursor is off and we want it off, return quickly. */
25941 if (!on
&& !w
->phys_cursor_on_p
)
25944 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25945 /* If cursor row is not enabled, we don't really know where to
25946 display the cursor. */
25947 if (!glyph_row
->enabled_p
)
25949 w
->phys_cursor_on_p
= 0;
25954 if (!glyph_row
->exact_window_width_line_p
25955 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25956 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25958 eassert (input_blocked_p ());
25960 /* Set new_cursor_type to the cursor we want to be displayed. */
25961 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25962 &new_cursor_width
, &active_cursor
);
25964 /* If cursor is currently being shown and we don't want it to be or
25965 it is in the wrong place, or the cursor type is not what we want,
25967 if (w
->phys_cursor_on_p
25969 || w
->phys_cursor
.x
!= x
25970 || w
->phys_cursor
.y
!= y
25971 || new_cursor_type
!= w
->phys_cursor_type
25972 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25973 && new_cursor_width
!= w
->phys_cursor_width
)))
25974 erase_phys_cursor (w
);
25976 /* Don't check phys_cursor_on_p here because that flag is only set
25977 to zero in some cases where we know that the cursor has been
25978 completely erased, to avoid the extra work of erasing the cursor
25979 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25980 still not be visible, or it has only been partly erased. */
25983 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25984 w
->phys_cursor_height
= glyph_row
->height
;
25986 /* Set phys_cursor_.* before x_draw_.* is called because some
25987 of them may need the information. */
25988 w
->phys_cursor
.x
= x
;
25989 w
->phys_cursor
.y
= glyph_row
->y
;
25990 w
->phys_cursor
.hpos
= hpos
;
25991 w
->phys_cursor
.vpos
= vpos
;
25994 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25995 new_cursor_type
, new_cursor_width
,
25996 on
, active_cursor
);
26000 /* Switch the display of W's cursor on or off, according to the value
26004 update_window_cursor (struct window
*w
, int on
)
26006 /* Don't update cursor in windows whose frame is in the process
26007 of being deleted. */
26008 if (w
->current_matrix
)
26010 int hpos
= w
->phys_cursor
.hpos
;
26011 int vpos
= w
->phys_cursor
.vpos
;
26012 struct glyph_row
*row
;
26014 if (vpos
>= w
->current_matrix
->nrows
26015 || hpos
>= w
->current_matrix
->matrix_w
)
26018 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26020 /* When the window is hscrolled, cursor hpos can legitimately be
26021 out of bounds, but we draw the cursor at the corresponding
26022 window margin in that case. */
26023 if (!row
->reversed_p
&& hpos
< 0)
26025 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26026 hpos
= row
->used
[TEXT_AREA
] - 1;
26029 display_and_set_cursor (w
, on
, hpos
, vpos
,
26030 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26036 /* Call update_window_cursor with parameter ON_P on all leaf windows
26037 in the window tree rooted at W. */
26040 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26044 if (!NILP (w
->hchild
))
26045 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26046 else if (!NILP (w
->vchild
))
26047 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26049 update_window_cursor (w
, on_p
);
26051 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26057 Display the cursor on window W, or clear it, according to ON_P.
26058 Don't change the cursor's position. */
26061 x_update_cursor (struct frame
*f
, int on_p
)
26063 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26068 Clear the cursor of window W to background color, and mark the
26069 cursor as not shown. This is used when the text where the cursor
26070 is about to be rewritten. */
26073 x_clear_cursor (struct window
*w
)
26075 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26076 update_window_cursor (w
, 0);
26079 #endif /* HAVE_WINDOW_SYSTEM */
26081 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26084 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26085 int start_hpos
, int end_hpos
,
26086 enum draw_glyphs_face draw
)
26088 #ifdef HAVE_WINDOW_SYSTEM
26089 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26091 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26095 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26096 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26100 /* Display the active region described by mouse_face_* according to DRAW. */
26103 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26105 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26106 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26108 if (/* If window is in the process of being destroyed, don't bother
26110 w
->current_matrix
!= NULL
26111 /* Don't update mouse highlight if hidden */
26112 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26113 /* Recognize when we are called to operate on rows that don't exist
26114 anymore. This can happen when a window is split. */
26115 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26117 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26118 struct glyph_row
*row
, *first
, *last
;
26120 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26121 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26123 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26125 int start_hpos
, end_hpos
, start_x
;
26127 /* For all but the first row, the highlight starts at column 0. */
26130 /* R2L rows have BEG and END in reversed order, but the
26131 screen drawing geometry is always left to right. So
26132 we need to mirror the beginning and end of the
26133 highlighted area in R2L rows. */
26134 if (!row
->reversed_p
)
26136 start_hpos
= hlinfo
->mouse_face_beg_col
;
26137 start_x
= hlinfo
->mouse_face_beg_x
;
26139 else if (row
== last
)
26141 start_hpos
= hlinfo
->mouse_face_end_col
;
26142 start_x
= hlinfo
->mouse_face_end_x
;
26150 else if (row
->reversed_p
&& row
== last
)
26152 start_hpos
= hlinfo
->mouse_face_end_col
;
26153 start_x
= hlinfo
->mouse_face_end_x
;
26163 if (!row
->reversed_p
)
26164 end_hpos
= hlinfo
->mouse_face_end_col
;
26165 else if (row
== first
)
26166 end_hpos
= hlinfo
->mouse_face_beg_col
;
26169 end_hpos
= row
->used
[TEXT_AREA
];
26170 if (draw
== DRAW_NORMAL_TEXT
)
26171 row
->fill_line_p
= 1; /* Clear to end of line */
26174 else if (row
->reversed_p
&& row
== first
)
26175 end_hpos
= hlinfo
->mouse_face_beg_col
;
26178 end_hpos
= row
->used
[TEXT_AREA
];
26179 if (draw
== DRAW_NORMAL_TEXT
)
26180 row
->fill_line_p
= 1; /* Clear to end of line */
26183 if (end_hpos
> start_hpos
)
26185 draw_row_with_mouse_face (w
, start_x
, row
,
26186 start_hpos
, end_hpos
, draw
);
26189 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26193 #ifdef HAVE_WINDOW_SYSTEM
26194 /* When we've written over the cursor, arrange for it to
26195 be displayed again. */
26196 if (FRAME_WINDOW_P (f
)
26197 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26199 int hpos
= w
->phys_cursor
.hpos
;
26201 /* When the window is hscrolled, cursor hpos can legitimately be
26202 out of bounds, but we draw the cursor at the corresponding
26203 window margin in that case. */
26204 if (!row
->reversed_p
&& hpos
< 0)
26206 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26207 hpos
= row
->used
[TEXT_AREA
] - 1;
26210 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26211 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26214 #endif /* HAVE_WINDOW_SYSTEM */
26217 #ifdef HAVE_WINDOW_SYSTEM
26218 /* Change the mouse cursor. */
26219 if (FRAME_WINDOW_P (f
))
26221 if (draw
== DRAW_NORMAL_TEXT
26222 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26223 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26224 else if (draw
== DRAW_MOUSE_FACE
)
26225 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26227 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26229 #endif /* HAVE_WINDOW_SYSTEM */
26233 Clear out the mouse-highlighted active region.
26234 Redraw it un-highlighted first. Value is non-zero if mouse
26235 face was actually drawn unhighlighted. */
26238 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26242 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26244 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26248 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26249 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26250 hlinfo
->mouse_face_window
= Qnil
;
26251 hlinfo
->mouse_face_overlay
= Qnil
;
26255 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26256 within the mouse face on that window. */
26258 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26260 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26262 /* Quickly resolve the easy cases. */
26263 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26264 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26266 if (vpos
< hlinfo
->mouse_face_beg_row
26267 || vpos
> hlinfo
->mouse_face_end_row
)
26269 if (vpos
> hlinfo
->mouse_face_beg_row
26270 && vpos
< hlinfo
->mouse_face_end_row
)
26273 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26275 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26277 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26280 else if ((vpos
== hlinfo
->mouse_face_beg_row
26281 && hpos
>= hlinfo
->mouse_face_beg_col
)
26282 || (vpos
== hlinfo
->mouse_face_end_row
26283 && hpos
< hlinfo
->mouse_face_end_col
))
26288 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26290 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26293 else if ((vpos
== hlinfo
->mouse_face_beg_row
26294 && hpos
<= hlinfo
->mouse_face_beg_col
)
26295 || (vpos
== hlinfo
->mouse_face_end_row
26296 && hpos
> hlinfo
->mouse_face_end_col
))
26304 Non-zero if physical cursor of window W is within mouse face. */
26307 cursor_in_mouse_face_p (struct window
*w
)
26309 int hpos
= w
->phys_cursor
.hpos
;
26310 int vpos
= w
->phys_cursor
.vpos
;
26311 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26313 /* When the window is hscrolled, cursor hpos can legitimately be out
26314 of bounds, but we draw the cursor at the corresponding window
26315 margin in that case. */
26316 if (!row
->reversed_p
&& hpos
< 0)
26318 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26319 hpos
= row
->used
[TEXT_AREA
] - 1;
26321 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26326 /* Find the glyph rows START_ROW and END_ROW of window W that display
26327 characters between buffer positions START_CHARPOS and END_CHARPOS
26328 (excluding END_CHARPOS). DISP_STRING is a display string that
26329 covers these buffer positions. This is similar to
26330 row_containing_pos, but is more accurate when bidi reordering makes
26331 buffer positions change non-linearly with glyph rows. */
26333 rows_from_pos_range (struct window
*w
,
26334 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26335 Lisp_Object disp_string
,
26336 struct glyph_row
**start
, struct glyph_row
**end
)
26338 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26339 int last_y
= window_text_bottom_y (w
);
26340 struct glyph_row
*row
;
26345 while (!first
->enabled_p
26346 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26349 /* Find the START row. */
26351 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26354 /* A row can potentially be the START row if the range of the
26355 characters it displays intersects the range
26356 [START_CHARPOS..END_CHARPOS). */
26357 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26358 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26359 /* See the commentary in row_containing_pos, for the
26360 explanation of the complicated way to check whether
26361 some position is beyond the end of the characters
26362 displayed by a row. */
26363 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26364 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26365 && !row
->ends_at_zv_p
26366 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26367 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26368 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26369 && !row
->ends_at_zv_p
26370 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26372 /* Found a candidate row. Now make sure at least one of the
26373 glyphs it displays has a charpos from the range
26374 [START_CHARPOS..END_CHARPOS).
26376 This is not obvious because bidi reordering could make
26377 buffer positions of a row be 1,2,3,102,101,100, and if we
26378 want to highlight characters in [50..60), we don't want
26379 this row, even though [50..60) does intersect [1..103),
26380 the range of character positions given by the row's start
26381 and end positions. */
26382 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26383 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26387 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26388 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26389 /* A glyph that comes from DISP_STRING is by
26390 definition to be highlighted. */
26391 || EQ (g
->object
, disp_string
))
26400 /* Find the END row. */
26402 /* If the last row is partially visible, start looking for END
26403 from that row, instead of starting from FIRST. */
26404 && !(row
->enabled_p
26405 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26407 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26409 struct glyph_row
*next
= row
+ 1;
26410 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26412 if (!next
->enabled_p
26413 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26414 /* The first row >= START whose range of displayed characters
26415 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26416 is the row END + 1. */
26417 || (start_charpos
< next_start
26418 && end_charpos
< next_start
)
26419 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26420 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26421 && !next
->ends_at_zv_p
26422 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26423 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26424 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26425 && !next
->ends_at_zv_p
26426 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26433 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26434 but none of the characters it displays are in the range, it is
26436 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26437 struct glyph
*s
= g
;
26438 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26442 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26443 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26444 /* If the buffer position of the first glyph in
26445 the row is equal to END_CHARPOS, it means
26446 the last character to be highlighted is the
26447 newline of ROW, and we must consider NEXT as
26449 || (((!next
->reversed_p
&& g
== s
)
26450 || (next
->reversed_p
&& g
== e
- 1))
26451 && (g
->charpos
== end_charpos
26452 /* Special case for when NEXT is an
26453 empty line at ZV. */
26454 || (g
->charpos
== -1
26455 && !row
->ends_at_zv_p
26456 && next_start
== end_charpos
)))))
26457 /* A glyph that comes from DISP_STRING is by
26458 definition to be highlighted. */
26459 || EQ (g
->object
, disp_string
))
26468 /* The first row that ends at ZV must be the last to be
26470 else if (next
->ends_at_zv_p
)
26479 /* This function sets the mouse_face_* elements of HLINFO, assuming
26480 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26481 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26482 for the overlay or run of text properties specifying the mouse
26483 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26484 before-string and after-string that must also be highlighted.
26485 DISP_STRING, if non-nil, is a display string that may cover some
26486 or all of the highlighted text. */
26489 mouse_face_from_buffer_pos (Lisp_Object window
,
26490 Mouse_HLInfo
*hlinfo
,
26491 ptrdiff_t mouse_charpos
,
26492 ptrdiff_t start_charpos
,
26493 ptrdiff_t end_charpos
,
26494 Lisp_Object before_string
,
26495 Lisp_Object after_string
,
26496 Lisp_Object disp_string
)
26498 struct window
*w
= XWINDOW (window
);
26499 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26500 struct glyph_row
*r1
, *r2
;
26501 struct glyph
*glyph
, *end
;
26502 ptrdiff_t ignore
, pos
;
26505 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26506 eassert (NILP (before_string
) || STRINGP (before_string
));
26507 eassert (NILP (after_string
) || STRINGP (after_string
));
26509 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26510 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26512 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26513 /* If the before-string or display-string contains newlines,
26514 rows_from_pos_range skips to its last row. Move back. */
26515 if (!NILP (before_string
) || !NILP (disp_string
))
26517 struct glyph_row
*prev
;
26518 while ((prev
= r1
- 1, prev
>= first
)
26519 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26520 && prev
->used
[TEXT_AREA
] > 0)
26522 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26523 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26524 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26526 || !(EQ (glyph
->object
, before_string
)
26527 || EQ (glyph
->object
, disp_string
)))
26534 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26535 hlinfo
->mouse_face_past_end
= 1;
26537 else if (!NILP (after_string
))
26539 /* If the after-string has newlines, advance to its last row. */
26540 struct glyph_row
*next
;
26541 struct glyph_row
*last
26542 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26544 for (next
= r2
+ 1;
26546 && next
->used
[TEXT_AREA
] > 0
26547 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26551 /* The rest of the display engine assumes that mouse_face_beg_row is
26552 either above mouse_face_end_row or identical to it. But with
26553 bidi-reordered continued lines, the row for START_CHARPOS could
26554 be below the row for END_CHARPOS. If so, swap the rows and store
26555 them in correct order. */
26558 struct glyph_row
*tem
= r2
;
26564 hlinfo
->mouse_face_beg_y
= r1
->y
;
26565 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26566 hlinfo
->mouse_face_end_y
= r2
->y
;
26567 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26569 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26570 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26571 could be anywhere in the row and in any order. The strategy
26572 below is to find the leftmost and the rightmost glyph that
26573 belongs to either of these 3 strings, or whose position is
26574 between START_CHARPOS and END_CHARPOS, and highlight all the
26575 glyphs between those two. This may cover more than just the text
26576 between START_CHARPOS and END_CHARPOS if the range of characters
26577 strides the bidi level boundary, e.g. if the beginning is in R2L
26578 text while the end is in L2R text or vice versa. */
26579 if (!r1
->reversed_p
)
26581 /* This row is in a left to right paragraph. Scan it left to
26583 glyph
= r1
->glyphs
[TEXT_AREA
];
26584 end
= glyph
+ r1
->used
[TEXT_AREA
];
26587 /* Skip truncation glyphs at the start of the glyph row. */
26588 if (r1
->displays_text_p
)
26590 && INTEGERP (glyph
->object
)
26591 && glyph
->charpos
< 0;
26593 x
+= glyph
->pixel_width
;
26595 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26596 or DISP_STRING, and the first glyph from buffer whose
26597 position is between START_CHARPOS and END_CHARPOS. */
26599 && !INTEGERP (glyph
->object
)
26600 && !EQ (glyph
->object
, disp_string
)
26601 && !(BUFFERP (glyph
->object
)
26602 && (glyph
->charpos
>= start_charpos
26603 && glyph
->charpos
< end_charpos
));
26606 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26607 are present at buffer positions between START_CHARPOS and
26608 END_CHARPOS, or if they come from an overlay. */
26609 if (EQ (glyph
->object
, before_string
))
26611 pos
= string_buffer_position (before_string
,
26613 /* If pos == 0, it means before_string came from an
26614 overlay, not from a buffer position. */
26615 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26618 else if (EQ (glyph
->object
, after_string
))
26620 pos
= string_buffer_position (after_string
, end_charpos
);
26621 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26624 x
+= glyph
->pixel_width
;
26626 hlinfo
->mouse_face_beg_x
= x
;
26627 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26631 /* This row is in a right to left paragraph. Scan it right to
26635 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26636 glyph
= end
+ r1
->used
[TEXT_AREA
];
26638 /* Skip truncation glyphs at the start of the glyph row. */
26639 if (r1
->displays_text_p
)
26641 && INTEGERP (glyph
->object
)
26642 && glyph
->charpos
< 0;
26646 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26647 or DISP_STRING, and the first glyph from buffer whose
26648 position is between START_CHARPOS and END_CHARPOS. */
26650 && !INTEGERP (glyph
->object
)
26651 && !EQ (glyph
->object
, disp_string
)
26652 && !(BUFFERP (glyph
->object
)
26653 && (glyph
->charpos
>= start_charpos
26654 && glyph
->charpos
< end_charpos
));
26657 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26658 are present at buffer positions between START_CHARPOS and
26659 END_CHARPOS, or if they come from an overlay. */
26660 if (EQ (glyph
->object
, before_string
))
26662 pos
= string_buffer_position (before_string
, start_charpos
);
26663 /* If pos == 0, it means before_string came from an
26664 overlay, not from a buffer position. */
26665 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26668 else if (EQ (glyph
->object
, after_string
))
26670 pos
= string_buffer_position (after_string
, end_charpos
);
26671 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26676 glyph
++; /* first glyph to the right of the highlighted area */
26677 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26678 x
+= g
->pixel_width
;
26679 hlinfo
->mouse_face_beg_x
= x
;
26680 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26683 /* If the highlight ends in a different row, compute GLYPH and END
26684 for the end row. Otherwise, reuse the values computed above for
26685 the row where the highlight begins. */
26688 if (!r2
->reversed_p
)
26690 glyph
= r2
->glyphs
[TEXT_AREA
];
26691 end
= glyph
+ r2
->used
[TEXT_AREA
];
26696 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26697 glyph
= end
+ r2
->used
[TEXT_AREA
];
26701 if (!r2
->reversed_p
)
26703 /* Skip truncation and continuation glyphs near the end of the
26704 row, and also blanks and stretch glyphs inserted by
26705 extend_face_to_end_of_line. */
26707 && INTEGERP ((end
- 1)->object
))
26709 /* Scan the rest of the glyph row from the end, looking for the
26710 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26711 DISP_STRING, or whose position is between START_CHARPOS
26715 && !INTEGERP (end
->object
)
26716 && !EQ (end
->object
, disp_string
)
26717 && !(BUFFERP (end
->object
)
26718 && (end
->charpos
>= start_charpos
26719 && end
->charpos
< end_charpos
));
26722 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26723 are present at buffer positions between START_CHARPOS and
26724 END_CHARPOS, or if they come from an overlay. */
26725 if (EQ (end
->object
, before_string
))
26727 pos
= string_buffer_position (before_string
, start_charpos
);
26728 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26731 else if (EQ (end
->object
, after_string
))
26733 pos
= string_buffer_position (after_string
, end_charpos
);
26734 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26738 /* Find the X coordinate of the last glyph to be highlighted. */
26739 for (; glyph
<= end
; ++glyph
)
26740 x
+= glyph
->pixel_width
;
26742 hlinfo
->mouse_face_end_x
= x
;
26743 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26747 /* Skip truncation and continuation glyphs near the end of the
26748 row, and also blanks and stretch glyphs inserted by
26749 extend_face_to_end_of_line. */
26753 && INTEGERP (end
->object
))
26755 x
+= end
->pixel_width
;
26758 /* Scan the rest of the glyph row from the end, looking for the
26759 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26760 DISP_STRING, or whose position is between START_CHARPOS
26764 && !INTEGERP (end
->object
)
26765 && !EQ (end
->object
, disp_string
)
26766 && !(BUFFERP (end
->object
)
26767 && (end
->charpos
>= start_charpos
26768 && end
->charpos
< end_charpos
));
26771 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26772 are present at buffer positions between START_CHARPOS and
26773 END_CHARPOS, or if they come from an overlay. */
26774 if (EQ (end
->object
, before_string
))
26776 pos
= string_buffer_position (before_string
, start_charpos
);
26777 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26780 else if (EQ (end
->object
, after_string
))
26782 pos
= string_buffer_position (after_string
, end_charpos
);
26783 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26786 x
+= end
->pixel_width
;
26788 /* If we exited the above loop because we arrived at the last
26789 glyph of the row, and its buffer position is still not in
26790 range, it means the last character in range is the preceding
26791 newline. Bump the end column and x values to get past the
26794 && BUFFERP (end
->object
)
26795 && (end
->charpos
< start_charpos
26796 || end
->charpos
>= end_charpos
))
26798 x
+= end
->pixel_width
;
26801 hlinfo
->mouse_face_end_x
= x
;
26802 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26805 hlinfo
->mouse_face_window
= window
;
26806 hlinfo
->mouse_face_face_id
26807 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26809 !hlinfo
->mouse_face_hidden
, -1);
26810 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26813 /* The following function is not used anymore (replaced with
26814 mouse_face_from_string_pos), but I leave it here for the time
26815 being, in case someone would. */
26817 #if 0 /* not used */
26819 /* Find the position of the glyph for position POS in OBJECT in
26820 window W's current matrix, and return in *X, *Y the pixel
26821 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26823 RIGHT_P non-zero means return the position of the right edge of the
26824 glyph, RIGHT_P zero means return the left edge position.
26826 If no glyph for POS exists in the matrix, return the position of
26827 the glyph with the next smaller position that is in the matrix, if
26828 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26829 exists in the matrix, return the position of the glyph with the
26830 next larger position in OBJECT.
26832 Value is non-zero if a glyph was found. */
26835 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26836 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26838 int yb
= window_text_bottom_y (w
);
26839 struct glyph_row
*r
;
26840 struct glyph
*best_glyph
= NULL
;
26841 struct glyph_row
*best_row
= NULL
;
26844 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26845 r
->enabled_p
&& r
->y
< yb
;
26848 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26849 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26852 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26853 if (EQ (g
->object
, object
))
26855 if (g
->charpos
== pos
)
26862 else if (best_glyph
== NULL
26863 || ((eabs (g
->charpos
- pos
)
26864 < eabs (best_glyph
->charpos
- pos
))
26867 : g
->charpos
> pos
)))
26881 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26885 *x
+= best_glyph
->pixel_width
;
26890 *vpos
= best_row
- w
->current_matrix
->rows
;
26893 return best_glyph
!= NULL
;
26895 #endif /* not used */
26897 /* Find the positions of the first and the last glyphs in window W's
26898 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26899 (assumed to be a string), and return in HLINFO's mouse_face_*
26900 members the pixel and column/row coordinates of those glyphs. */
26903 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26904 Lisp_Object object
,
26905 ptrdiff_t startpos
, ptrdiff_t endpos
)
26907 int yb
= window_text_bottom_y (w
);
26908 struct glyph_row
*r
;
26909 struct glyph
*g
, *e
;
26913 /* Find the glyph row with at least one position in the range
26914 [STARTPOS..ENDPOS], and the first glyph in that row whose
26915 position belongs to that range. */
26916 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26917 r
->enabled_p
&& r
->y
< yb
;
26920 if (!r
->reversed_p
)
26922 g
= r
->glyphs
[TEXT_AREA
];
26923 e
= g
+ r
->used
[TEXT_AREA
];
26924 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26925 if (EQ (g
->object
, object
)
26926 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26928 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26929 hlinfo
->mouse_face_beg_y
= r
->y
;
26930 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26931 hlinfo
->mouse_face_beg_x
= gx
;
26940 e
= r
->glyphs
[TEXT_AREA
];
26941 g
= e
+ r
->used
[TEXT_AREA
];
26942 for ( ; g
> e
; --g
)
26943 if (EQ ((g
-1)->object
, object
)
26944 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26946 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26947 hlinfo
->mouse_face_beg_y
= r
->y
;
26948 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26949 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26950 gx
+= g1
->pixel_width
;
26951 hlinfo
->mouse_face_beg_x
= gx
;
26963 /* Starting with the next row, look for the first row which does NOT
26964 include any glyphs whose positions are in the range. */
26965 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26967 g
= r
->glyphs
[TEXT_AREA
];
26968 e
= g
+ r
->used
[TEXT_AREA
];
26970 for ( ; g
< e
; ++g
)
26971 if (EQ (g
->object
, object
)
26972 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26981 /* The highlighted region ends on the previous row. */
26984 /* Set the end row and its vertical pixel coordinate. */
26985 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26986 hlinfo
->mouse_face_end_y
= r
->y
;
26988 /* Compute and set the end column and the end column's horizontal
26989 pixel coordinate. */
26990 if (!r
->reversed_p
)
26992 g
= r
->glyphs
[TEXT_AREA
];
26993 e
= g
+ r
->used
[TEXT_AREA
];
26994 for ( ; e
> g
; --e
)
26995 if (EQ ((e
-1)->object
, object
)
26996 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26998 hlinfo
->mouse_face_end_col
= e
- g
;
27000 for (gx
= r
->x
; g
< e
; ++g
)
27001 gx
+= g
->pixel_width
;
27002 hlinfo
->mouse_face_end_x
= gx
;
27006 e
= r
->glyphs
[TEXT_AREA
];
27007 g
= e
+ r
->used
[TEXT_AREA
];
27008 for (gx
= r
->x
; e
< g
; ++e
)
27010 if (EQ (e
->object
, object
)
27011 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27013 gx
+= e
->pixel_width
;
27015 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27016 hlinfo
->mouse_face_end_x
= gx
;
27020 #ifdef HAVE_WINDOW_SYSTEM
27022 /* See if position X, Y is within a hot-spot of an image. */
27025 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27027 if (!CONSP (hot_spot
))
27030 if (EQ (XCAR (hot_spot
), Qrect
))
27032 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27033 Lisp_Object rect
= XCDR (hot_spot
);
27037 if (!CONSP (XCAR (rect
)))
27039 if (!CONSP (XCDR (rect
)))
27041 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27043 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27045 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27047 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27051 else if (EQ (XCAR (hot_spot
), Qcircle
))
27053 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27054 Lisp_Object circ
= XCDR (hot_spot
);
27055 Lisp_Object lr
, lx0
, ly0
;
27057 && CONSP (XCAR (circ
))
27058 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27059 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27060 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27062 double r
= XFLOATINT (lr
);
27063 double dx
= XINT (lx0
) - x
;
27064 double dy
= XINT (ly0
) - y
;
27065 return (dx
* dx
+ dy
* dy
<= r
* r
);
27068 else if (EQ (XCAR (hot_spot
), Qpoly
))
27070 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27071 if (VECTORP (XCDR (hot_spot
)))
27073 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27074 Lisp_Object
*poly
= v
->contents
;
27075 ptrdiff_t n
= v
->header
.size
;
27078 Lisp_Object lx
, ly
;
27081 /* Need an even number of coordinates, and at least 3 edges. */
27082 if (n
< 6 || n
& 1)
27085 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27086 If count is odd, we are inside polygon. Pixels on edges
27087 may or may not be included depending on actual geometry of the
27089 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27090 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27092 x0
= XINT (lx
), y0
= XINT (ly
);
27093 for (i
= 0; i
< n
; i
+= 2)
27095 int x1
= x0
, y1
= y0
;
27096 if ((lx
= poly
[i
], !INTEGERP (lx
))
27097 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27099 x0
= XINT (lx
), y0
= XINT (ly
);
27101 /* Does this segment cross the X line? */
27109 if (y
> y0
&& y
> y1
)
27111 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27121 find_hot_spot (Lisp_Object map
, int x
, int y
)
27123 while (CONSP (map
))
27125 if (CONSP (XCAR (map
))
27126 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27134 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27136 doc
: /* Lookup in image map MAP coordinates X and Y.
27137 An image map is an alist where each element has the format (AREA ID PLIST).
27138 An AREA is specified as either a rectangle, a circle, or a polygon:
27139 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27140 pixel coordinates of the upper left and bottom right corners.
27141 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27142 and the radius of the circle; r may be a float or integer.
27143 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27144 vector describes one corner in the polygon.
27145 Returns the alist element for the first matching AREA in MAP. */)
27146 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27154 return find_hot_spot (map
,
27155 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27156 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27160 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27162 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27164 /* Do not change cursor shape while dragging mouse. */
27165 if (!NILP (do_mouse_tracking
))
27168 if (!NILP (pointer
))
27170 if (EQ (pointer
, Qarrow
))
27171 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27172 else if (EQ (pointer
, Qhand
))
27173 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27174 else if (EQ (pointer
, Qtext
))
27175 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27176 else if (EQ (pointer
, intern ("hdrag")))
27177 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27178 #ifdef HAVE_X_WINDOWS
27179 else if (EQ (pointer
, intern ("vdrag")))
27180 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27182 else if (EQ (pointer
, intern ("hourglass")))
27183 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27184 else if (EQ (pointer
, Qmodeline
))
27185 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27187 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27190 if (cursor
!= No_Cursor
)
27191 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27194 #endif /* HAVE_WINDOW_SYSTEM */
27196 /* Take proper action when mouse has moved to the mode or header line
27197 or marginal area AREA of window W, x-position X and y-position Y.
27198 X is relative to the start of the text display area of W, so the
27199 width of bitmap areas and scroll bars must be subtracted to get a
27200 position relative to the start of the mode line. */
27203 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27204 enum window_part area
)
27206 struct window
*w
= XWINDOW (window
);
27207 struct frame
*f
= XFRAME (w
->frame
);
27208 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27209 #ifdef HAVE_WINDOW_SYSTEM
27210 Display_Info
*dpyinfo
;
27212 Cursor cursor
= No_Cursor
;
27213 Lisp_Object pointer
= Qnil
;
27214 int dx
, dy
, width
, height
;
27216 Lisp_Object string
, object
= Qnil
;
27217 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27219 Lisp_Object mouse_face
;
27220 int original_x_pixel
= x
;
27221 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27222 struct glyph_row
*row
IF_LINT (= 0);
27224 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27229 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27230 returns them in row/column units! */
27231 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27232 &object
, &dx
, &dy
, &width
, &height
);
27234 row
= (area
== ON_MODE_LINE
27235 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27236 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27238 /* Find the glyph under the mouse pointer. */
27239 if (row
->mode_line_p
&& row
->enabled_p
)
27241 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27242 end
= glyph
+ row
->used
[TEXT_AREA
];
27244 for (x0
= original_x_pixel
;
27245 glyph
< end
&& x0
>= glyph
->pixel_width
;
27247 x0
-= glyph
->pixel_width
;
27255 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27256 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27257 returns them in row/column units! */
27258 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27259 &object
, &dx
, &dy
, &width
, &height
);
27264 #ifdef HAVE_WINDOW_SYSTEM
27265 if (IMAGEP (object
))
27267 Lisp_Object image_map
, hotspot
;
27268 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27270 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27272 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27276 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27277 If so, we could look for mouse-enter, mouse-leave
27278 properties in PLIST (and do something...). */
27279 hotspot
= XCDR (hotspot
);
27280 if (CONSP (hotspot
)
27281 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27283 pointer
= Fplist_get (plist
, Qpointer
);
27284 if (NILP (pointer
))
27286 help
= Fplist_get (plist
, Qhelp_echo
);
27289 help_echo_string
= help
;
27290 XSETWINDOW (help_echo_window
, w
);
27291 help_echo_object
= w
->buffer
;
27292 help_echo_pos
= charpos
;
27296 if (NILP (pointer
))
27297 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27299 #endif /* HAVE_WINDOW_SYSTEM */
27301 if (STRINGP (string
))
27302 pos
= make_number (charpos
);
27304 /* Set the help text and mouse pointer. If the mouse is on a part
27305 of the mode line without any text (e.g. past the right edge of
27306 the mode line text), use the default help text and pointer. */
27307 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27309 /* Arrange to display the help by setting the global variables
27310 help_echo_string, help_echo_object, and help_echo_pos. */
27313 if (STRINGP (string
))
27314 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27318 help_echo_string
= help
;
27319 XSETWINDOW (help_echo_window
, w
);
27320 help_echo_object
= string
;
27321 help_echo_pos
= charpos
;
27323 else if (area
== ON_MODE_LINE
)
27325 Lisp_Object default_help
27326 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27329 if (STRINGP (default_help
))
27331 help_echo_string
= default_help
;
27332 XSETWINDOW (help_echo_window
, w
);
27333 help_echo_object
= Qnil
;
27334 help_echo_pos
= -1;
27339 #ifdef HAVE_WINDOW_SYSTEM
27340 /* Change the mouse pointer according to what is under it. */
27341 if (FRAME_WINDOW_P (f
))
27343 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27344 if (STRINGP (string
))
27346 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27348 if (NILP (pointer
))
27349 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27351 /* Change the mouse pointer according to what is under X/Y. */
27353 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27356 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27357 if (!KEYMAPP (map
))
27358 map
= Fget_text_property (pos
, Qkeymap
, string
);
27359 if (!KEYMAPP (map
))
27360 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27364 /* Default mode-line pointer. */
27365 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27370 /* Change the mouse face according to what is under X/Y. */
27371 if (STRINGP (string
))
27373 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27374 if (!NILP (mouse_face
)
27375 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27380 struct glyph
* tmp_glyph
;
27384 int total_pixel_width
;
27385 ptrdiff_t begpos
, endpos
, ignore
;
27389 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27390 Qmouse_face
, string
, Qnil
);
27396 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27398 endpos
= SCHARS (string
);
27402 /* Calculate the glyph position GPOS of GLYPH in the
27403 displayed string, relative to the beginning of the
27404 highlighted part of the string.
27406 Note: GPOS is different from CHARPOS. CHARPOS is the
27407 position of GLYPH in the internal string object. A mode
27408 line string format has structures which are converted to
27409 a flattened string by the Emacs Lisp interpreter. The
27410 internal string is an element of those structures. The
27411 displayed string is the flattened string. */
27412 tmp_glyph
= row_start_glyph
;
27413 while (tmp_glyph
< glyph
27414 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27415 && begpos
<= tmp_glyph
->charpos
27416 && tmp_glyph
->charpos
< endpos
)))
27418 gpos
= glyph
- tmp_glyph
;
27420 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27421 the highlighted part of the displayed string to which
27422 GLYPH belongs. Note: GSEQ_LENGTH is different from
27423 SCHARS (STRING), because the latter returns the length of
27424 the internal string. */
27425 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27427 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27428 && begpos
<= tmp_glyph
->charpos
27429 && tmp_glyph
->charpos
< endpos
));
27432 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27434 /* Calculate the total pixel width of all the glyphs between
27435 the beginning of the highlighted area and GLYPH. */
27436 total_pixel_width
= 0;
27437 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27438 total_pixel_width
+= tmp_glyph
->pixel_width
;
27440 /* Pre calculation of re-rendering position. Note: X is in
27441 column units here, after the call to mode_line_string or
27442 marginal_area_string. */
27444 vpos
= (area
== ON_MODE_LINE
27445 ? (w
->current_matrix
)->nrows
- 1
27448 /* If GLYPH's position is included in the region that is
27449 already drawn in mouse face, we have nothing to do. */
27450 if ( EQ (window
, hlinfo
->mouse_face_window
)
27451 && (!row
->reversed_p
27452 ? (hlinfo
->mouse_face_beg_col
<= hpos
27453 && hpos
< hlinfo
->mouse_face_end_col
)
27454 /* In R2L rows we swap BEG and END, see below. */
27455 : (hlinfo
->mouse_face_end_col
<= hpos
27456 && hpos
< hlinfo
->mouse_face_beg_col
))
27457 && hlinfo
->mouse_face_beg_row
== vpos
)
27460 if (clear_mouse_face (hlinfo
))
27461 cursor
= No_Cursor
;
27463 if (!row
->reversed_p
)
27465 hlinfo
->mouse_face_beg_col
= hpos
;
27466 hlinfo
->mouse_face_beg_x
= original_x_pixel
27467 - (total_pixel_width
+ dx
);
27468 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27469 hlinfo
->mouse_face_end_x
= 0;
27473 /* In R2L rows, show_mouse_face expects BEG and END
27474 coordinates to be swapped. */
27475 hlinfo
->mouse_face_end_col
= hpos
;
27476 hlinfo
->mouse_face_end_x
= original_x_pixel
27477 - (total_pixel_width
+ dx
);
27478 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27479 hlinfo
->mouse_face_beg_x
= 0;
27482 hlinfo
->mouse_face_beg_row
= vpos
;
27483 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27484 hlinfo
->mouse_face_beg_y
= 0;
27485 hlinfo
->mouse_face_end_y
= 0;
27486 hlinfo
->mouse_face_past_end
= 0;
27487 hlinfo
->mouse_face_window
= window
;
27489 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27495 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27497 if (NILP (pointer
))
27500 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27501 clear_mouse_face (hlinfo
);
27503 #ifdef HAVE_WINDOW_SYSTEM
27504 if (FRAME_WINDOW_P (f
))
27505 define_frame_cursor1 (f
, cursor
, pointer
);
27511 Take proper action when the mouse has moved to position X, Y on
27512 frame F as regards highlighting characters that have mouse-face
27513 properties. Also de-highlighting chars where the mouse was before.
27514 X and Y can be negative or out of range. */
27517 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27519 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27520 enum window_part part
= ON_NOTHING
;
27521 Lisp_Object window
;
27523 Cursor cursor
= No_Cursor
;
27524 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27527 /* When a menu is active, don't highlight because this looks odd. */
27528 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27529 if (popup_activated ())
27533 if (NILP (Vmouse_highlight
)
27534 || !f
->glyphs_initialized_p
27535 || f
->pointer_invisible
)
27538 hlinfo
->mouse_face_mouse_x
= x
;
27539 hlinfo
->mouse_face_mouse_y
= y
;
27540 hlinfo
->mouse_face_mouse_frame
= f
;
27542 if (hlinfo
->mouse_face_defer
)
27545 /* Which window is that in? */
27546 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27548 /* If displaying active text in another window, clear that. */
27549 if (! EQ (window
, hlinfo
->mouse_face_window
)
27550 /* Also clear if we move out of text area in same window. */
27551 || (!NILP (hlinfo
->mouse_face_window
)
27554 && part
!= ON_MODE_LINE
27555 && part
!= ON_HEADER_LINE
))
27556 clear_mouse_face (hlinfo
);
27558 /* Not on a window -> return. */
27559 if (!WINDOWP (window
))
27562 /* Reset help_echo_string. It will get recomputed below. */
27563 help_echo_string
= Qnil
;
27565 /* Convert to window-relative pixel coordinates. */
27566 w
= XWINDOW (window
);
27567 frame_to_window_pixel_xy (w
, &x
, &y
);
27569 #ifdef HAVE_WINDOW_SYSTEM
27570 /* Handle tool-bar window differently since it doesn't display a
27572 if (EQ (window
, f
->tool_bar_window
))
27574 note_tool_bar_highlight (f
, x
, y
);
27579 /* Mouse is on the mode, header line or margin? */
27580 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27581 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27583 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27587 #ifdef HAVE_WINDOW_SYSTEM
27588 if (part
== ON_VERTICAL_BORDER
)
27590 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27591 help_echo_string
= build_string ("drag-mouse-1: resize");
27593 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27594 || part
== ON_SCROLL_BAR
)
27595 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27597 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27600 /* Are we in a window whose display is up to date?
27601 And verify the buffer's text has not changed. */
27602 b
= XBUFFER (w
->buffer
);
27603 if (part
== ON_TEXT
27604 && w
->window_end_valid
27605 && w
->last_modified
== BUF_MODIFF (b
)
27606 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27608 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27610 struct glyph
*glyph
;
27611 Lisp_Object object
;
27612 Lisp_Object mouse_face
= Qnil
, position
;
27613 Lisp_Object
*overlay_vec
= NULL
;
27614 ptrdiff_t i
, noverlays
;
27615 struct buffer
*obuf
;
27616 ptrdiff_t obegv
, ozv
;
27619 /* Find the glyph under X/Y. */
27620 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27622 #ifdef HAVE_WINDOW_SYSTEM
27623 /* Look for :pointer property on image. */
27624 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27626 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27627 if (img
!= NULL
&& IMAGEP (img
->spec
))
27629 Lisp_Object image_map
, hotspot
;
27630 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27632 && (hotspot
= find_hot_spot (image_map
,
27633 glyph
->slice
.img
.x
+ dx
,
27634 glyph
->slice
.img
.y
+ dy
),
27636 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27640 /* Could check XCAR (hotspot) to see if we enter/leave
27642 If so, we could look for mouse-enter, mouse-leave
27643 properties in PLIST (and do something...). */
27644 hotspot
= XCDR (hotspot
);
27645 if (CONSP (hotspot
)
27646 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27648 pointer
= Fplist_get (plist
, Qpointer
);
27649 if (NILP (pointer
))
27651 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27652 if (!NILP (help_echo_string
))
27654 help_echo_window
= window
;
27655 help_echo_object
= glyph
->object
;
27656 help_echo_pos
= glyph
->charpos
;
27660 if (NILP (pointer
))
27661 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27664 #endif /* HAVE_WINDOW_SYSTEM */
27666 /* Clear mouse face if X/Y not over text. */
27668 || area
!= TEXT_AREA
27669 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27670 /* Glyph's OBJECT is an integer for glyphs inserted by the
27671 display engine for its internal purposes, like truncation
27672 and continuation glyphs and blanks beyond the end of
27673 line's text on text terminals. If we are over such a
27674 glyph, we are not over any text. */
27675 || INTEGERP (glyph
->object
)
27676 /* R2L rows have a stretch glyph at their front, which
27677 stands for no text, whereas L2R rows have no glyphs at
27678 all beyond the end of text. Treat such stretch glyphs
27679 like we do with NULL glyphs in L2R rows. */
27680 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27681 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27682 && glyph
->type
== STRETCH_GLYPH
27683 && glyph
->avoid_cursor_p
))
27685 if (clear_mouse_face (hlinfo
))
27686 cursor
= No_Cursor
;
27687 #ifdef HAVE_WINDOW_SYSTEM
27688 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27690 if (area
!= TEXT_AREA
)
27691 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27693 pointer
= Vvoid_text_area_pointer
;
27699 pos
= glyph
->charpos
;
27700 object
= glyph
->object
;
27701 if (!STRINGP (object
) && !BUFFERP (object
))
27704 /* If we get an out-of-range value, return now; avoid an error. */
27705 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27708 /* Make the window's buffer temporarily current for
27709 overlays_at and compute_char_face. */
27710 obuf
= current_buffer
;
27711 current_buffer
= b
;
27717 /* Is this char mouse-active or does it have help-echo? */
27718 position
= make_number (pos
);
27720 if (BUFFERP (object
))
27722 /* Put all the overlays we want in a vector in overlay_vec. */
27723 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27724 /* Sort overlays into increasing priority order. */
27725 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27730 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27733 cursor
= No_Cursor
;
27735 /* Check mouse-face highlighting. */
27737 /* If there exists an overlay with mouse-face overlapping
27738 the one we are currently highlighting, we have to
27739 check if we enter the overlapping overlay, and then
27740 highlight only that. */
27741 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27742 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27744 /* Find the highest priority overlay with a mouse-face. */
27745 Lisp_Object overlay
= Qnil
;
27746 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27748 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27749 if (!NILP (mouse_face
))
27750 overlay
= overlay_vec
[i
];
27753 /* If we're highlighting the same overlay as before, there's
27754 no need to do that again. */
27755 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27756 goto check_help_echo
;
27757 hlinfo
->mouse_face_overlay
= overlay
;
27759 /* Clear the display of the old active region, if any. */
27760 if (clear_mouse_face (hlinfo
))
27761 cursor
= No_Cursor
;
27763 /* If no overlay applies, get a text property. */
27764 if (NILP (overlay
))
27765 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27767 /* Next, compute the bounds of the mouse highlighting and
27769 if (!NILP (mouse_face
) && STRINGP (object
))
27771 /* The mouse-highlighting comes from a display string
27772 with a mouse-face. */
27776 s
= Fprevious_single_property_change
27777 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27778 e
= Fnext_single_property_change
27779 (position
, Qmouse_face
, object
, Qnil
);
27781 s
= make_number (0);
27783 e
= make_number (SCHARS (object
) - 1);
27784 mouse_face_from_string_pos (w
, hlinfo
, object
,
27785 XINT (s
), XINT (e
));
27786 hlinfo
->mouse_face_past_end
= 0;
27787 hlinfo
->mouse_face_window
= window
;
27788 hlinfo
->mouse_face_face_id
27789 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27790 glyph
->face_id
, 1);
27791 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27792 cursor
= No_Cursor
;
27796 /* The mouse-highlighting, if any, comes from an overlay
27797 or text property in the buffer. */
27798 Lisp_Object buffer
IF_LINT (= Qnil
);
27799 Lisp_Object disp_string
IF_LINT (= Qnil
);
27801 if (STRINGP (object
))
27803 /* If we are on a display string with no mouse-face,
27804 check if the text under it has one. */
27805 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27806 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27807 pos
= string_buffer_position (object
, start
);
27810 mouse_face
= get_char_property_and_overlay
27811 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27812 buffer
= w
->buffer
;
27813 disp_string
= object
;
27819 disp_string
= Qnil
;
27822 if (!NILP (mouse_face
))
27824 Lisp_Object before
, after
;
27825 Lisp_Object before_string
, after_string
;
27826 /* To correctly find the limits of mouse highlight
27827 in a bidi-reordered buffer, we must not use the
27828 optimization of limiting the search in
27829 previous-single-property-change and
27830 next-single-property-change, because
27831 rows_from_pos_range needs the real start and end
27832 positions to DTRT in this case. That's because
27833 the first row visible in a window does not
27834 necessarily display the character whose position
27835 is the smallest. */
27837 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27838 ? Fmarker_position (w
->start
)
27841 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27842 ? make_number (BUF_Z (XBUFFER (buffer
))
27843 - XFASTINT (w
->window_end_pos
))
27846 if (NILP (overlay
))
27848 /* Handle the text property case. */
27849 before
= Fprevious_single_property_change
27850 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27851 after
= Fnext_single_property_change
27852 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27853 before_string
= after_string
= Qnil
;
27857 /* Handle the overlay case. */
27858 before
= Foverlay_start (overlay
);
27859 after
= Foverlay_end (overlay
);
27860 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27861 after_string
= Foverlay_get (overlay
, Qafter_string
);
27863 if (!STRINGP (before_string
)) before_string
= Qnil
;
27864 if (!STRINGP (after_string
)) after_string
= Qnil
;
27867 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27870 : XFASTINT (before
),
27872 ? BUF_Z (XBUFFER (buffer
))
27873 : XFASTINT (after
),
27874 before_string
, after_string
,
27876 cursor
= No_Cursor
;
27883 /* Look for a `help-echo' property. */
27884 if (NILP (help_echo_string
)) {
27885 Lisp_Object help
, overlay
;
27887 /* Check overlays first. */
27888 help
= overlay
= Qnil
;
27889 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27891 overlay
= overlay_vec
[i
];
27892 help
= Foverlay_get (overlay
, Qhelp_echo
);
27897 help_echo_string
= help
;
27898 help_echo_window
= window
;
27899 help_echo_object
= overlay
;
27900 help_echo_pos
= pos
;
27904 Lisp_Object obj
= glyph
->object
;
27905 ptrdiff_t charpos
= glyph
->charpos
;
27907 /* Try text properties. */
27910 && charpos
< SCHARS (obj
))
27912 help
= Fget_text_property (make_number (charpos
),
27916 /* If the string itself doesn't specify a help-echo,
27917 see if the buffer text ``under'' it does. */
27918 struct glyph_row
*r
27919 = MATRIX_ROW (w
->current_matrix
, vpos
);
27920 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27921 ptrdiff_t p
= string_buffer_position (obj
, start
);
27924 help
= Fget_char_property (make_number (p
),
27925 Qhelp_echo
, w
->buffer
);
27934 else if (BUFFERP (obj
)
27937 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27942 help_echo_string
= help
;
27943 help_echo_window
= window
;
27944 help_echo_object
= obj
;
27945 help_echo_pos
= charpos
;
27950 #ifdef HAVE_WINDOW_SYSTEM
27951 /* Look for a `pointer' property. */
27952 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27954 /* Check overlays first. */
27955 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27956 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27958 if (NILP (pointer
))
27960 Lisp_Object obj
= glyph
->object
;
27961 ptrdiff_t charpos
= glyph
->charpos
;
27963 /* Try text properties. */
27966 && charpos
< SCHARS (obj
))
27968 pointer
= Fget_text_property (make_number (charpos
),
27970 if (NILP (pointer
))
27972 /* If the string itself doesn't specify a pointer,
27973 see if the buffer text ``under'' it does. */
27974 struct glyph_row
*r
27975 = MATRIX_ROW (w
->current_matrix
, vpos
);
27976 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27977 ptrdiff_t p
= string_buffer_position (obj
, start
);
27979 pointer
= Fget_char_property (make_number (p
),
27980 Qpointer
, w
->buffer
);
27983 else if (BUFFERP (obj
)
27986 pointer
= Fget_text_property (make_number (charpos
),
27990 #endif /* HAVE_WINDOW_SYSTEM */
27994 current_buffer
= obuf
;
27999 #ifdef HAVE_WINDOW_SYSTEM
28000 if (FRAME_WINDOW_P (f
))
28001 define_frame_cursor1 (f
, cursor
, pointer
);
28003 /* This is here to prevent a compiler error, about "label at end of
28004 compound statement". */
28011 Clear any mouse-face on window W. This function is part of the
28012 redisplay interface, and is called from try_window_id and similar
28013 functions to ensure the mouse-highlight is off. */
28016 x_clear_window_mouse_face (struct window
*w
)
28018 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28019 Lisp_Object window
;
28022 XSETWINDOW (window
, w
);
28023 if (EQ (window
, hlinfo
->mouse_face_window
))
28024 clear_mouse_face (hlinfo
);
28030 Just discard the mouse face information for frame F, if any.
28031 This is used when the size of F is changed. */
28034 cancel_mouse_face (struct frame
*f
)
28036 Lisp_Object window
;
28037 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28039 window
= hlinfo
->mouse_face_window
;
28040 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28042 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28043 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28044 hlinfo
->mouse_face_window
= Qnil
;
28050 /***********************************************************************
28052 ***********************************************************************/
28054 #ifdef HAVE_WINDOW_SYSTEM
28056 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28057 which intersects rectangle R. R is in window-relative coordinates. */
28060 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28061 enum glyph_row_area area
)
28063 struct glyph
*first
= row
->glyphs
[area
];
28064 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28065 struct glyph
*last
;
28066 int first_x
, start_x
, x
;
28068 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28069 /* If row extends face to end of line write the whole line. */
28070 draw_glyphs (w
, 0, row
, area
,
28071 0, row
->used
[area
],
28072 DRAW_NORMAL_TEXT
, 0);
28075 /* Set START_X to the window-relative start position for drawing glyphs of
28076 AREA. The first glyph of the text area can be partially visible.
28077 The first glyphs of other areas cannot. */
28078 start_x
= window_box_left_offset (w
, area
);
28080 if (area
== TEXT_AREA
)
28083 /* Find the first glyph that must be redrawn. */
28085 && x
+ first
->pixel_width
< r
->x
)
28087 x
+= first
->pixel_width
;
28091 /* Find the last one. */
28095 && x
< r
->x
+ r
->width
)
28097 x
+= last
->pixel_width
;
28103 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28104 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28105 DRAW_NORMAL_TEXT
, 0);
28110 /* Redraw the parts of the glyph row ROW on window W intersecting
28111 rectangle R. R is in window-relative coordinates. Value is
28112 non-zero if mouse-face was overwritten. */
28115 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28117 eassert (row
->enabled_p
);
28119 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28120 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28121 0, row
->used
[TEXT_AREA
],
28122 DRAW_NORMAL_TEXT
, 0);
28125 if (row
->used
[LEFT_MARGIN_AREA
])
28126 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28127 if (row
->used
[TEXT_AREA
])
28128 expose_area (w
, row
, r
, TEXT_AREA
);
28129 if (row
->used
[RIGHT_MARGIN_AREA
])
28130 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28131 draw_row_fringe_bitmaps (w
, row
);
28134 return row
->mouse_face_p
;
28138 /* Redraw those parts of glyphs rows during expose event handling that
28139 overlap other rows. Redrawing of an exposed line writes over parts
28140 of lines overlapping that exposed line; this function fixes that.
28142 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28143 row in W's current matrix that is exposed and overlaps other rows.
28144 LAST_OVERLAPPING_ROW is the last such row. */
28147 expose_overlaps (struct window
*w
,
28148 struct glyph_row
*first_overlapping_row
,
28149 struct glyph_row
*last_overlapping_row
,
28152 struct glyph_row
*row
;
28154 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28155 if (row
->overlapping_p
)
28157 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28160 if (row
->used
[LEFT_MARGIN_AREA
])
28161 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28163 if (row
->used
[TEXT_AREA
])
28164 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28166 if (row
->used
[RIGHT_MARGIN_AREA
])
28167 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28173 /* Return non-zero if W's cursor intersects rectangle R. */
28176 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28178 XRectangle cr
, result
;
28179 struct glyph
*cursor_glyph
;
28180 struct glyph_row
*row
;
28182 if (w
->phys_cursor
.vpos
>= 0
28183 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28184 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28186 && row
->cursor_in_fringe_p
)
28188 /* Cursor is in the fringe. */
28189 cr
.x
= window_box_right_offset (w
,
28190 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28191 ? RIGHT_MARGIN_AREA
28194 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28195 cr
.height
= row
->height
;
28196 return x_intersect_rectangles (&cr
, r
, &result
);
28199 cursor_glyph
= get_phys_cursor_glyph (w
);
28202 /* r is relative to W's box, but w->phys_cursor.x is relative
28203 to left edge of W's TEXT area. Adjust it. */
28204 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28205 cr
.y
= w
->phys_cursor
.y
;
28206 cr
.width
= cursor_glyph
->pixel_width
;
28207 cr
.height
= w
->phys_cursor_height
;
28208 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28209 I assume the effect is the same -- and this is portable. */
28210 return x_intersect_rectangles (&cr
, r
, &result
);
28212 /* If we don't understand the format, pretend we're not in the hot-spot. */
28218 Draw a vertical window border to the right of window W if W doesn't
28219 have vertical scroll bars. */
28222 x_draw_vertical_border (struct window
*w
)
28224 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28226 /* We could do better, if we knew what type of scroll-bar the adjacent
28227 windows (on either side) have... But we don't :-(
28228 However, I think this works ok. ++KFS 2003-04-25 */
28230 /* Redraw borders between horizontally adjacent windows. Don't
28231 do it for frames with vertical scroll bars because either the
28232 right scroll bar of a window, or the left scroll bar of its
28233 neighbor will suffice as a border. */
28234 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28237 if (!WINDOW_RIGHTMOST_P (w
)
28238 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28240 int x0
, x1
, y0
, y1
;
28242 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28245 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28248 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28250 else if (!WINDOW_LEFTMOST_P (w
)
28251 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28253 int x0
, x1
, y0
, y1
;
28255 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28258 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28261 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28266 /* Redraw the part of window W intersection rectangle FR. Pixel
28267 coordinates in FR are frame-relative. Call this function with
28268 input blocked. Value is non-zero if the exposure overwrites
28272 expose_window (struct window
*w
, XRectangle
*fr
)
28274 struct frame
*f
= XFRAME (w
->frame
);
28276 int mouse_face_overwritten_p
= 0;
28278 /* If window is not yet fully initialized, do nothing. This can
28279 happen when toolkit scroll bars are used and a window is split.
28280 Reconfiguring the scroll bar will generate an expose for a newly
28282 if (w
->current_matrix
== NULL
)
28285 /* When we're currently updating the window, display and current
28286 matrix usually don't agree. Arrange for a thorough display
28288 if (w
== updated_window
)
28290 SET_FRAME_GARBAGED (f
);
28294 /* Frame-relative pixel rectangle of W. */
28295 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28296 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28297 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28298 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28300 if (x_intersect_rectangles (fr
, &wr
, &r
))
28302 int yb
= window_text_bottom_y (w
);
28303 struct glyph_row
*row
;
28304 int cursor_cleared_p
, phys_cursor_on_p
;
28305 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28307 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28308 r
.x
, r
.y
, r
.width
, r
.height
));
28310 /* Convert to window coordinates. */
28311 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28312 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28314 /* Turn off the cursor. */
28315 if (!w
->pseudo_window_p
28316 && phys_cursor_in_rect_p (w
, &r
))
28318 x_clear_cursor (w
);
28319 cursor_cleared_p
= 1;
28322 cursor_cleared_p
= 0;
28324 /* If the row containing the cursor extends face to end of line,
28325 then expose_area might overwrite the cursor outside the
28326 rectangle and thus notice_overwritten_cursor might clear
28327 w->phys_cursor_on_p. We remember the original value and
28328 check later if it is changed. */
28329 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28331 /* Update lines intersecting rectangle R. */
28332 first_overlapping_row
= last_overlapping_row
= NULL
;
28333 for (row
= w
->current_matrix
->rows
;
28338 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28340 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28341 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28342 || (r
.y
>= y0
&& r
.y
< y1
)
28343 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28345 /* A header line may be overlapping, but there is no need
28346 to fix overlapping areas for them. KFS 2005-02-12 */
28347 if (row
->overlapping_p
&& !row
->mode_line_p
)
28349 if (first_overlapping_row
== NULL
)
28350 first_overlapping_row
= row
;
28351 last_overlapping_row
= row
;
28355 if (expose_line (w
, row
, &r
))
28356 mouse_face_overwritten_p
= 1;
28359 else if (row
->overlapping_p
)
28361 /* We must redraw a row overlapping the exposed area. */
28363 ? y0
+ row
->phys_height
> r
.y
28364 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28366 if (first_overlapping_row
== NULL
)
28367 first_overlapping_row
= row
;
28368 last_overlapping_row
= row
;
28376 /* Display the mode line if there is one. */
28377 if (WINDOW_WANTS_MODELINE_P (w
)
28378 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28380 && row
->y
< r
.y
+ r
.height
)
28382 if (expose_line (w
, row
, &r
))
28383 mouse_face_overwritten_p
= 1;
28386 if (!w
->pseudo_window_p
)
28388 /* Fix the display of overlapping rows. */
28389 if (first_overlapping_row
)
28390 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28393 /* Draw border between windows. */
28394 x_draw_vertical_border (w
);
28396 /* Turn the cursor on again. */
28397 if (cursor_cleared_p
28398 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28399 update_window_cursor (w
, 1);
28403 return mouse_face_overwritten_p
;
28408 /* Redraw (parts) of all windows in the window tree rooted at W that
28409 intersect R. R contains frame pixel coordinates. Value is
28410 non-zero if the exposure overwrites mouse-face. */
28413 expose_window_tree (struct window
*w
, XRectangle
*r
)
28415 struct frame
*f
= XFRAME (w
->frame
);
28416 int mouse_face_overwritten_p
= 0;
28418 while (w
&& !FRAME_GARBAGED_P (f
))
28420 if (!NILP (w
->hchild
))
28421 mouse_face_overwritten_p
28422 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28423 else if (!NILP (w
->vchild
))
28424 mouse_face_overwritten_p
28425 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28427 mouse_face_overwritten_p
|= expose_window (w
, r
);
28429 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28432 return mouse_face_overwritten_p
;
28437 Redisplay an exposed area of frame F. X and Y are the upper-left
28438 corner of the exposed rectangle. W and H are width and height of
28439 the exposed area. All are pixel values. W or H zero means redraw
28440 the entire frame. */
28443 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28446 int mouse_face_overwritten_p
= 0;
28448 TRACE ((stderr
, "expose_frame "));
28450 /* No need to redraw if frame will be redrawn soon. */
28451 if (FRAME_GARBAGED_P (f
))
28453 TRACE ((stderr
, " garbaged\n"));
28457 /* If basic faces haven't been realized yet, there is no point in
28458 trying to redraw anything. This can happen when we get an expose
28459 event while Emacs is starting, e.g. by moving another window. */
28460 if (FRAME_FACE_CACHE (f
) == NULL
28461 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28463 TRACE ((stderr
, " no faces\n"));
28467 if (w
== 0 || h
== 0)
28470 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28471 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28481 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28482 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28484 if (WINDOWP (f
->tool_bar_window
))
28485 mouse_face_overwritten_p
28486 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28488 #ifdef HAVE_X_WINDOWS
28490 #ifndef USE_X_TOOLKIT
28491 if (WINDOWP (f
->menu_bar_window
))
28492 mouse_face_overwritten_p
28493 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28494 #endif /* not USE_X_TOOLKIT */
28498 /* Some window managers support a focus-follows-mouse style with
28499 delayed raising of frames. Imagine a partially obscured frame,
28500 and moving the mouse into partially obscured mouse-face on that
28501 frame. The visible part of the mouse-face will be highlighted,
28502 then the WM raises the obscured frame. With at least one WM, KDE
28503 2.1, Emacs is not getting any event for the raising of the frame
28504 (even tried with SubstructureRedirectMask), only Expose events.
28505 These expose events will draw text normally, i.e. not
28506 highlighted. Which means we must redo the highlight here.
28507 Subsume it under ``we love X''. --gerd 2001-08-15 */
28508 /* Included in Windows version because Windows most likely does not
28509 do the right thing if any third party tool offers
28510 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28511 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28513 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28514 if (f
== hlinfo
->mouse_face_mouse_frame
)
28516 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28517 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28518 clear_mouse_face (hlinfo
);
28519 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28526 Determine the intersection of two rectangles R1 and R2. Return
28527 the intersection in *RESULT. Value is non-zero if RESULT is not
28531 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28533 XRectangle
*left
, *right
;
28534 XRectangle
*upper
, *lower
;
28535 int intersection_p
= 0;
28537 /* Rearrange so that R1 is the left-most rectangle. */
28539 left
= r1
, right
= r2
;
28541 left
= r2
, right
= r1
;
28543 /* X0 of the intersection is right.x0, if this is inside R1,
28544 otherwise there is no intersection. */
28545 if (right
->x
<= left
->x
+ left
->width
)
28547 result
->x
= right
->x
;
28549 /* The right end of the intersection is the minimum of
28550 the right ends of left and right. */
28551 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28554 /* Same game for Y. */
28556 upper
= r1
, lower
= r2
;
28558 upper
= r2
, lower
= r1
;
28560 /* The upper end of the intersection is lower.y0, if this is inside
28561 of upper. Otherwise, there is no intersection. */
28562 if (lower
->y
<= upper
->y
+ upper
->height
)
28564 result
->y
= lower
->y
;
28566 /* The lower end of the intersection is the minimum of the lower
28567 ends of upper and lower. */
28568 result
->height
= (min (lower
->y
+ lower
->height
,
28569 upper
->y
+ upper
->height
)
28571 intersection_p
= 1;
28575 return intersection_p
;
28578 #endif /* HAVE_WINDOW_SYSTEM */
28581 /***********************************************************************
28583 ***********************************************************************/
28586 syms_of_xdisp (void)
28588 Vwith_echo_area_save_vector
= Qnil
;
28589 staticpro (&Vwith_echo_area_save_vector
);
28591 Vmessage_stack
= Qnil
;
28592 staticpro (&Vmessage_stack
);
28594 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28595 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28597 message_dolog_marker1
= Fmake_marker ();
28598 staticpro (&message_dolog_marker1
);
28599 message_dolog_marker2
= Fmake_marker ();
28600 staticpro (&message_dolog_marker2
);
28601 message_dolog_marker3
= Fmake_marker ();
28602 staticpro (&message_dolog_marker3
);
28605 defsubr (&Sdump_frame_glyph_matrix
);
28606 defsubr (&Sdump_glyph_matrix
);
28607 defsubr (&Sdump_glyph_row
);
28608 defsubr (&Sdump_tool_bar_row
);
28609 defsubr (&Strace_redisplay
);
28610 defsubr (&Strace_to_stderr
);
28612 #ifdef HAVE_WINDOW_SYSTEM
28613 defsubr (&Stool_bar_lines_needed
);
28614 defsubr (&Slookup_image_map
);
28616 defsubr (&Sformat_mode_line
);
28617 defsubr (&Sinvisible_p
);
28618 defsubr (&Scurrent_bidi_paragraph_direction
);
28620 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28621 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28622 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28623 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28624 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28625 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28626 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28627 DEFSYM (Qeval
, "eval");
28628 DEFSYM (QCdata
, ":data");
28629 DEFSYM (Qdisplay
, "display");
28630 DEFSYM (Qspace_width
, "space-width");
28631 DEFSYM (Qraise
, "raise");
28632 DEFSYM (Qslice
, "slice");
28633 DEFSYM (Qspace
, "space");
28634 DEFSYM (Qmargin
, "margin");
28635 DEFSYM (Qpointer
, "pointer");
28636 DEFSYM (Qleft_margin
, "left-margin");
28637 DEFSYM (Qright_margin
, "right-margin");
28638 DEFSYM (Qcenter
, "center");
28639 DEFSYM (Qline_height
, "line-height");
28640 DEFSYM (QCalign_to
, ":align-to");
28641 DEFSYM (QCrelative_width
, ":relative-width");
28642 DEFSYM (QCrelative_height
, ":relative-height");
28643 DEFSYM (QCeval
, ":eval");
28644 DEFSYM (QCpropertize
, ":propertize");
28645 DEFSYM (QCfile
, ":file");
28646 DEFSYM (Qfontified
, "fontified");
28647 DEFSYM (Qfontification_functions
, "fontification-functions");
28648 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28649 DEFSYM (Qescape_glyph
, "escape-glyph");
28650 DEFSYM (Qnobreak_space
, "nobreak-space");
28651 DEFSYM (Qimage
, "image");
28652 DEFSYM (Qtext
, "text");
28653 DEFSYM (Qboth
, "both");
28654 DEFSYM (Qboth_horiz
, "both-horiz");
28655 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28656 DEFSYM (QCmap
, ":map");
28657 DEFSYM (QCpointer
, ":pointer");
28658 DEFSYM (Qrect
, "rect");
28659 DEFSYM (Qcircle
, "circle");
28660 DEFSYM (Qpoly
, "poly");
28661 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28662 DEFSYM (Qgrow_only
, "grow-only");
28663 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28664 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28665 DEFSYM (Qposition
, "position");
28666 DEFSYM (Qbuffer_position
, "buffer-position");
28667 DEFSYM (Qobject
, "object");
28668 DEFSYM (Qbar
, "bar");
28669 DEFSYM (Qhbar
, "hbar");
28670 DEFSYM (Qbox
, "box");
28671 DEFSYM (Qhollow
, "hollow");
28672 DEFSYM (Qhand
, "hand");
28673 DEFSYM (Qarrow
, "arrow");
28674 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28676 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28677 Fcons (intern_c_string ("void-variable"), Qnil
)),
28679 staticpro (&list_of_error
);
28681 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28682 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28683 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28684 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28686 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28687 staticpro (&echo_buffer
[0]);
28688 staticpro (&echo_buffer
[1]);
28690 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28691 staticpro (&echo_area_buffer
[0]);
28692 staticpro (&echo_area_buffer
[1]);
28694 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28695 staticpro (&Vmessages_buffer_name
);
28697 mode_line_proptrans_alist
= Qnil
;
28698 staticpro (&mode_line_proptrans_alist
);
28699 mode_line_string_list
= Qnil
;
28700 staticpro (&mode_line_string_list
);
28701 mode_line_string_face
= Qnil
;
28702 staticpro (&mode_line_string_face
);
28703 mode_line_string_face_prop
= Qnil
;
28704 staticpro (&mode_line_string_face_prop
);
28705 Vmode_line_unwind_vector
= Qnil
;
28706 staticpro (&Vmode_line_unwind_vector
);
28708 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28710 help_echo_string
= Qnil
;
28711 staticpro (&help_echo_string
);
28712 help_echo_object
= Qnil
;
28713 staticpro (&help_echo_object
);
28714 help_echo_window
= Qnil
;
28715 staticpro (&help_echo_window
);
28716 previous_help_echo_string
= Qnil
;
28717 staticpro (&previous_help_echo_string
);
28718 help_echo_pos
= -1;
28720 DEFSYM (Qright_to_left
, "right-to-left");
28721 DEFSYM (Qleft_to_right
, "left-to-right");
28723 #ifdef HAVE_WINDOW_SYSTEM
28724 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28725 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28726 For example, if a block cursor is over a tab, it will be drawn as
28727 wide as that tab on the display. */);
28728 x_stretch_cursor_p
= 0;
28731 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28732 doc
: /* Non-nil means highlight trailing whitespace.
28733 The face used for trailing whitespace is `trailing-whitespace'. */);
28734 Vshow_trailing_whitespace
= Qnil
;
28736 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28737 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28738 If the value is t, Emacs highlights non-ASCII chars which have the
28739 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28740 or `escape-glyph' face respectively.
28742 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28743 U+2011 (non-breaking hyphen) are affected.
28745 Any other non-nil value means to display these characters as a escape
28746 glyph followed by an ordinary space or hyphen.
28748 A value of nil means no special handling of these characters. */);
28749 Vnobreak_char_display
= Qt
;
28751 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28752 doc
: /* The pointer shape to show in void text areas.
28753 A value of nil means to show the text pointer. Other options are `arrow',
28754 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28755 Vvoid_text_area_pointer
= Qarrow
;
28757 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28758 doc
: /* Non-nil means don't actually do any redisplay.
28759 This is used for internal purposes. */);
28760 Vinhibit_redisplay
= Qnil
;
28762 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28763 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28764 Vglobal_mode_string
= Qnil
;
28766 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28767 doc
: /* Marker for where to display an arrow on top of the buffer text.
28768 This must be the beginning of a line in order to work.
28769 See also `overlay-arrow-string'. */);
28770 Voverlay_arrow_position
= Qnil
;
28772 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28773 doc
: /* String to display as an arrow in non-window frames.
28774 See also `overlay-arrow-position'. */);
28775 Voverlay_arrow_string
= build_pure_c_string ("=>");
28777 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28778 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28779 The symbols on this list are examined during redisplay to determine
28780 where to display overlay arrows. */);
28781 Voverlay_arrow_variable_list
28782 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28784 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28785 doc
: /* The number of lines to try scrolling a window by when point moves out.
28786 If that fails to bring point back on frame, point is centered instead.
28787 If this is zero, point is always centered after it moves off frame.
28788 If you want scrolling to always be a line at a time, you should set
28789 `scroll-conservatively' to a large value rather than set this to 1. */);
28791 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28792 doc
: /* Scroll up to this many lines, to bring point back on screen.
28793 If point moves off-screen, redisplay will scroll by up to
28794 `scroll-conservatively' lines in order to bring point just barely
28795 onto the screen again. If that cannot be done, then redisplay
28796 recenters point as usual.
28798 If the value is greater than 100, redisplay will never recenter point,
28799 but will always scroll just enough text to bring point into view, even
28800 if you move far away.
28802 A value of zero means always recenter point if it moves off screen. */);
28803 scroll_conservatively
= 0;
28805 DEFVAR_INT ("scroll-margin", scroll_margin
,
28806 doc
: /* Number of lines of margin at the top and bottom of a window.
28807 Recenter the window whenever point gets within this many lines
28808 of the top or bottom of the window. */);
28811 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28812 doc
: /* Pixels per inch value for non-window system displays.
28813 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28814 Vdisplay_pixels_per_inch
= make_float (72.0);
28817 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28820 DEFVAR_LISP ("truncate-partial-width-windows",
28821 Vtruncate_partial_width_windows
,
28822 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28823 For an integer value, truncate lines in each window narrower than the
28824 full frame width, provided the window width is less than that integer;
28825 otherwise, respect the value of `truncate-lines'.
28827 For any other non-nil value, truncate lines in all windows that do
28828 not span the full frame width.
28830 A value of nil means to respect the value of `truncate-lines'.
28832 If `word-wrap' is enabled, you might want to reduce this. */);
28833 Vtruncate_partial_width_windows
= make_number (50);
28835 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28836 doc
: /* Maximum buffer size for which line number should be displayed.
28837 If the buffer is bigger than this, the line number does not appear
28838 in the mode line. A value of nil means no limit. */);
28839 Vline_number_display_limit
= Qnil
;
28841 DEFVAR_INT ("line-number-display-limit-width",
28842 line_number_display_limit_width
,
28843 doc
: /* Maximum line width (in characters) for line number display.
28844 If the average length of the lines near point is bigger than this, then the
28845 line number may be omitted from the mode line. */);
28846 line_number_display_limit_width
= 200;
28848 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28849 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28850 highlight_nonselected_windows
= 0;
28852 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28853 doc
: /* Non-nil if more than one frame is visible on this display.
28854 Minibuffer-only frames don't count, but iconified frames do.
28855 This variable is not guaranteed to be accurate except while processing
28856 `frame-title-format' and `icon-title-format'. */);
28858 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28859 doc
: /* Template for displaying the title bar of visible frames.
28860 \(Assuming the window manager supports this feature.)
28862 This variable has the same structure as `mode-line-format', except that
28863 the %c and %l constructs are ignored. It is used only on frames for
28864 which no explicit name has been set \(see `modify-frame-parameters'). */);
28866 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28867 doc
: /* Template for displaying the title bar of an iconified frame.
28868 \(Assuming the window manager supports this feature.)
28869 This variable has the same structure as `mode-line-format' (which see),
28870 and is used only on frames for which no explicit name has been set
28871 \(see `modify-frame-parameters'). */);
28873 = Vframe_title_format
28874 = listn (CONSTYPE_PURE
, 3,
28875 intern_c_string ("multiple-frames"),
28876 build_pure_c_string ("%b"),
28877 listn (CONSTYPE_PURE
, 4,
28878 empty_unibyte_string
,
28879 intern_c_string ("invocation-name"),
28880 build_pure_c_string ("@"),
28881 intern_c_string ("system-name")));
28883 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28884 doc
: /* Maximum number of lines to keep in the message log buffer.
28885 If nil, disable message logging. If t, log messages but don't truncate
28886 the buffer when it becomes large. */);
28887 Vmessage_log_max
= make_number (1000);
28889 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28890 doc
: /* Functions called before redisplay, if window sizes have changed.
28891 The value should be a list of functions that take one argument.
28892 Just before redisplay, for each frame, if any of its windows have changed
28893 size since the last redisplay, or have been split or deleted,
28894 all the functions in the list are called, with the frame as argument. */);
28895 Vwindow_size_change_functions
= Qnil
;
28897 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28898 doc
: /* List of functions to call before redisplaying a window with scrolling.
28899 Each function is called with two arguments, the window and its new
28900 display-start position. Note that these functions are also called by
28901 `set-window-buffer'. Also note that the value of `window-end' is not
28902 valid when these functions are called.
28904 Warning: Do not use this feature to alter the way the window
28905 is scrolled. It is not designed for that, and such use probably won't
28907 Vwindow_scroll_functions
= Qnil
;
28909 DEFVAR_LISP ("window-text-change-functions",
28910 Vwindow_text_change_functions
,
28911 doc
: /* Functions to call in redisplay when text in the window might change. */);
28912 Vwindow_text_change_functions
= Qnil
;
28914 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28915 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28916 Each function is called with two arguments, the window and the end trigger value.
28917 See `set-window-redisplay-end-trigger'. */);
28918 Vredisplay_end_trigger_functions
= Qnil
;
28920 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28921 doc
: /* Non-nil means autoselect window with mouse pointer.
28922 If nil, do not autoselect windows.
28923 A positive number means delay autoselection by that many seconds: a
28924 window is autoselected only after the mouse has remained in that
28925 window for the duration of the delay.
28926 A negative number has a similar effect, but causes windows to be
28927 autoselected only after the mouse has stopped moving. \(Because of
28928 the way Emacs compares mouse events, you will occasionally wait twice
28929 that time before the window gets selected.\)
28930 Any other value means to autoselect window instantaneously when the
28931 mouse pointer enters it.
28933 Autoselection selects the minibuffer only if it is active, and never
28934 unselects the minibuffer if it is active.
28936 When customizing this variable make sure that the actual value of
28937 `focus-follows-mouse' matches the behavior of your window manager. */);
28938 Vmouse_autoselect_window
= Qnil
;
28940 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28941 doc
: /* Non-nil means automatically resize tool-bars.
28942 This dynamically changes the tool-bar's height to the minimum height
28943 that is needed to make all tool-bar items visible.
28944 If value is `grow-only', the tool-bar's height is only increased
28945 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28946 Vauto_resize_tool_bars
= Qt
;
28948 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28949 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28950 auto_raise_tool_bar_buttons_p
= 1;
28952 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28953 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28954 make_cursor_line_fully_visible_p
= 1;
28956 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28957 doc
: /* Border below tool-bar in pixels.
28958 If an integer, use it as the height of the border.
28959 If it is one of `internal-border-width' or `border-width', use the
28960 value of the corresponding frame parameter.
28961 Otherwise, no border is added below the tool-bar. */);
28962 Vtool_bar_border
= Qinternal_border_width
;
28964 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28965 doc
: /* Margin around tool-bar buttons in pixels.
28966 If an integer, use that for both horizontal and vertical margins.
28967 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28968 HORZ specifying the horizontal margin, and VERT specifying the
28969 vertical margin. */);
28970 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28972 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28973 doc
: /* Relief thickness of tool-bar buttons. */);
28974 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28976 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28977 doc
: /* Tool bar style to use.
28979 image - show images only
28980 text - show text only
28981 both - show both, text below image
28982 both-horiz - show text to the right of the image
28983 text-image-horiz - show text to the left of the image
28984 any other - use system default or image if no system default.
28986 This variable only affects the GTK+ toolkit version of Emacs. */);
28987 Vtool_bar_style
= Qnil
;
28989 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28990 doc
: /* Maximum number of characters a label can have to be shown.
28991 The tool bar style must also show labels for this to have any effect, see
28992 `tool-bar-style'. */);
28993 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28995 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28996 doc
: /* List of functions to call to fontify regions of text.
28997 Each function is called with one argument POS. Functions must
28998 fontify a region starting at POS in the current buffer, and give
28999 fontified regions the property `fontified'. */);
29000 Vfontification_functions
= Qnil
;
29001 Fmake_variable_buffer_local (Qfontification_functions
);
29003 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29004 unibyte_display_via_language_environment
,
29005 doc
: /* Non-nil means display unibyte text according to language environment.
29006 Specifically, this means that raw bytes in the range 160-255 decimal
29007 are displayed by converting them to the equivalent multibyte characters
29008 according to the current language environment. As a result, they are
29009 displayed according to the current fontset.
29011 Note that this variable affects only how these bytes are displayed,
29012 but does not change the fact they are interpreted as raw bytes. */);
29013 unibyte_display_via_language_environment
= 0;
29015 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29016 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29017 If a float, it specifies a fraction of the mini-window frame's height.
29018 If an integer, it specifies a number of lines. */);
29019 Vmax_mini_window_height
= make_float (0.25);
29021 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29022 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29023 A value of nil means don't automatically resize mini-windows.
29024 A value of t means resize them to fit the text displayed in them.
29025 A value of `grow-only', the default, means let mini-windows grow only;
29026 they return to their normal size when the minibuffer is closed, or the
29027 echo area becomes empty. */);
29028 Vresize_mini_windows
= Qgrow_only
;
29030 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29031 doc
: /* Alist specifying how to blink the cursor off.
29032 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29033 `cursor-type' frame-parameter or variable equals ON-STATE,
29034 comparing using `equal', Emacs uses OFF-STATE to specify
29035 how to blink it off. ON-STATE and OFF-STATE are values for
29036 the `cursor-type' frame parameter.
29038 If a frame's ON-STATE has no entry in this list,
29039 the frame's other specifications determine how to blink the cursor off. */);
29040 Vblink_cursor_alist
= Qnil
;
29042 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29043 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29044 If non-nil, windows are automatically scrolled horizontally to make
29045 point visible. */);
29046 automatic_hscrolling_p
= 1;
29047 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29049 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29050 doc
: /* How many columns away from the window edge point is allowed to get
29051 before automatic hscrolling will horizontally scroll the window. */);
29052 hscroll_margin
= 5;
29054 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29055 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29056 When point is less than `hscroll-margin' columns from the window
29057 edge, automatic hscrolling will scroll the window by the amount of columns
29058 determined by this variable. If its value is a positive integer, scroll that
29059 many columns. If it's a positive floating-point number, it specifies the
29060 fraction of the window's width to scroll. If it's nil or zero, point will be
29061 centered horizontally after the scroll. Any other value, including negative
29062 numbers, are treated as if the value were zero.
29064 Automatic hscrolling always moves point outside the scroll margin, so if
29065 point was more than scroll step columns inside the margin, the window will
29066 scroll more than the value given by the scroll step.
29068 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29069 and `scroll-right' overrides this variable's effect. */);
29070 Vhscroll_step
= make_number (0);
29072 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29073 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29074 Bind this around calls to `message' to let it take effect. */);
29075 message_truncate_lines
= 0;
29077 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29078 doc
: /* Normal hook run to update the menu bar definitions.
29079 Redisplay runs this hook before it redisplays the menu bar.
29080 This is used to update submenus such as Buffers,
29081 whose contents depend on various data. */);
29082 Vmenu_bar_update_hook
= Qnil
;
29084 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29085 doc
: /* Frame for which we are updating a menu.
29086 The enable predicate for a menu binding should check this variable. */);
29087 Vmenu_updating_frame
= Qnil
;
29089 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29090 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29091 inhibit_menubar_update
= 0;
29093 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29094 doc
: /* Prefix prepended to all continuation lines at display time.
29095 The value may be a string, an image, or a stretch-glyph; it is
29096 interpreted in the same way as the value of a `display' text property.
29098 This variable is overridden by any `wrap-prefix' text or overlay
29101 To add a prefix to non-continuation lines, use `line-prefix'. */);
29102 Vwrap_prefix
= Qnil
;
29103 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29104 Fmake_variable_buffer_local (Qwrap_prefix
);
29106 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29107 doc
: /* Prefix prepended to all non-continuation lines at display time.
29108 The value may be a string, an image, or a stretch-glyph; it is
29109 interpreted in the same way as the value of a `display' text property.
29111 This variable is overridden by any `line-prefix' text or overlay
29114 To add a prefix to continuation lines, use `wrap-prefix'. */);
29115 Vline_prefix
= Qnil
;
29116 DEFSYM (Qline_prefix
, "line-prefix");
29117 Fmake_variable_buffer_local (Qline_prefix
);
29119 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29120 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29121 inhibit_eval_during_redisplay
= 0;
29123 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29124 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29125 inhibit_free_realized_faces
= 0;
29128 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29129 doc
: /* Inhibit try_window_id display optimization. */);
29130 inhibit_try_window_id
= 0;
29132 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29133 doc
: /* Inhibit try_window_reusing display optimization. */);
29134 inhibit_try_window_reusing
= 0;
29136 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29137 doc
: /* Inhibit try_cursor_movement display optimization. */);
29138 inhibit_try_cursor_movement
= 0;
29139 #endif /* GLYPH_DEBUG */
29141 DEFVAR_INT ("overline-margin", overline_margin
,
29142 doc
: /* Space between overline and text, in pixels.
29143 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29144 margin to the character height. */);
29145 overline_margin
= 2;
29147 DEFVAR_INT ("underline-minimum-offset",
29148 underline_minimum_offset
,
29149 doc
: /* Minimum distance between baseline and underline.
29150 This can improve legibility of underlined text at small font sizes,
29151 particularly when using variable `x-use-underline-position-properties'
29152 with fonts that specify an UNDERLINE_POSITION relatively close to the
29153 baseline. The default value is 1. */);
29154 underline_minimum_offset
= 1;
29156 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29157 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29158 This feature only works when on a window system that can change
29159 cursor shapes. */);
29160 display_hourglass_p
= 1;
29162 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29163 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29164 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29166 hourglass_atimer
= NULL
;
29167 hourglass_shown_p
= 0;
29169 DEFSYM (Qglyphless_char
, "glyphless-char");
29170 DEFSYM (Qhex_code
, "hex-code");
29171 DEFSYM (Qempty_box
, "empty-box");
29172 DEFSYM (Qthin_space
, "thin-space");
29173 DEFSYM (Qzero_width
, "zero-width");
29175 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29176 /* Intern this now in case it isn't already done.
29177 Setting this variable twice is harmless.
29178 But don't staticpro it here--that is done in alloc.c. */
29179 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29180 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29182 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29183 doc
: /* Char-table defining glyphless characters.
29184 Each element, if non-nil, should be one of the following:
29185 an ASCII acronym string: display this string in a box
29186 `hex-code': display the hexadecimal code of a character in a box
29187 `empty-box': display as an empty box
29188 `thin-space': display as 1-pixel width space
29189 `zero-width': don't display
29190 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29191 display method for graphical terminals and text terminals respectively.
29192 GRAPHICAL and TEXT should each have one of the values listed above.
29194 The char-table has one extra slot to control the display of a character for
29195 which no font is found. This slot only takes effect on graphical terminals.
29196 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29197 `thin-space'. The default is `empty-box'. */);
29198 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29199 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29202 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29203 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29204 Vdebug_on_message
= Qnil
;
29208 /* Initialize this module when Emacs starts. */
29213 current_header_line_height
= current_mode_line_height
= -1;
29215 CHARPOS (this_line_start_pos
) = 0;
29217 if (!noninteractive
)
29219 struct window
*m
= XWINDOW (minibuf_window
);
29220 Lisp_Object frame
= m
->frame
;
29221 struct frame
*f
= XFRAME (frame
);
29222 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29223 struct window
*r
= XWINDOW (root
);
29226 echo_area_window
= minibuf_window
;
29228 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29230 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29231 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29232 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29233 wset_total_lines (m
, make_number (1));
29234 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29236 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29237 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29238 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29240 /* The default ellipsis glyphs `...'. */
29241 for (i
= 0; i
< 3; ++i
)
29242 default_invis_vector
[i
] = make_number ('.');
29246 /* Allocate the buffer for frame titles.
29247 Also used for `format-mode-line'. */
29249 mode_line_noprop_buf
= xmalloc (size
);
29250 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29251 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29252 mode_line_target
= MODE_LINE_DISPLAY
;
29255 help_echo_showing_p
= 0;
29258 /* Platform-independent portion of hourglass implementation. */
29260 /* Cancel a currently active hourglass timer, and start a new one. */
29262 start_hourglass (void)
29264 #if defined (HAVE_WINDOW_SYSTEM)
29267 cancel_hourglass ();
29269 if (INTEGERP (Vhourglass_delay
)
29270 && XINT (Vhourglass_delay
) > 0)
29271 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29272 TYPE_MAXIMUM (time_t)),
29274 else if (FLOATP (Vhourglass_delay
)
29275 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29276 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29278 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29282 extern void w32_note_current_window (void);
29283 w32_note_current_window ();
29285 #endif /* HAVE_NTGUI */
29287 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29288 show_hourglass
, NULL
);
29293 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29296 cancel_hourglass (void)
29298 #if defined (HAVE_WINDOW_SYSTEM)
29299 if (hourglass_atimer
)
29301 cancel_atimer (hourglass_atimer
);
29302 hourglass_atimer
= NULL
;
29305 if (hourglass_shown_p
)