1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
284 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
301 #ifdef HAVE_WINDOW_SYSTEM
303 #endif /* HAVE_WINDOW_SYSTEM */
305 #ifndef FRAME_X_OUTPUT
306 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
309 #define INFINITY 10000000
311 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
312 Lisp_Object Qwindow_scroll_functions
;
313 static Lisp_Object Qwindow_text_change_functions
;
314 static Lisp_Object Qredisplay_end_trigger_functions
;
315 Lisp_Object Qinhibit_point_motion_hooks
;
316 static Lisp_Object QCeval
, QCpropertize
;
317 Lisp_Object QCfile
, QCdata
;
318 static Lisp_Object Qfontified
;
319 static Lisp_Object Qgrow_only
;
320 static Lisp_Object Qinhibit_eval_during_redisplay
;
321 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
322 static Lisp_Object Qright_to_left
, Qleft_to_right
;
325 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
327 /* Pointer shapes. */
328 static Lisp_Object Qarrow
, Qhand
;
331 /* Holds the list (error). */
332 static Lisp_Object list_of_error
;
334 static Lisp_Object Qfontification_functions
;
336 static Lisp_Object Qwrap_prefix
;
337 static Lisp_Object Qline_prefix
;
338 static Lisp_Object Qredisplay_internal
;
340 /* Non-nil means don't actually do any redisplay. */
342 Lisp_Object Qinhibit_redisplay
;
344 /* Names of text properties relevant for redisplay. */
346 Lisp_Object Qdisplay
;
348 Lisp_Object Qspace
, QCalign_to
;
349 static Lisp_Object QCrelative_width
, QCrelative_height
;
350 Lisp_Object Qleft_margin
, Qright_margin
;
351 static Lisp_Object Qspace_width
, Qraise
;
352 static Lisp_Object Qslice
;
354 static Lisp_Object Qmargin
, Qpointer
;
355 static Lisp_Object Qline_height
;
357 #ifdef HAVE_WINDOW_SYSTEM
359 /* Test if overflow newline into fringe. Called with iterator IT
360 at or past right window margin, and with IT->current_x set. */
362 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
363 (!NILP (Voverflow_newline_into_fringe) \
364 && FRAME_WINDOW_P ((IT)->f) \
365 && ((IT)->bidi_it.paragraph_dir == R2L \
366 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
367 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
368 && (IT)->current_x == (IT)->last_visible_x)
370 #else /* !HAVE_WINDOW_SYSTEM */
371 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
372 #endif /* HAVE_WINDOW_SYSTEM */
374 /* Test if the display element loaded in IT, or the underlying buffer
375 or string character, is a space or a TAB character. This is used
376 to determine where word wrapping can occur. */
378 #define IT_DISPLAYING_WHITESPACE(it) \
379 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
380 || ((STRINGP (it->string) \
381 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
382 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
384 && (it->s[IT_BYTEPOS (*it)] == ' ' \
385 || it->s[IT_BYTEPOS (*it)] == '\t')) \
386 || (IT_BYTEPOS (*it) < ZV_BYTE \
387 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
388 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
390 /* Name of the face used to highlight trailing whitespace. */
392 static Lisp_Object Qtrailing_whitespace
;
394 /* Name and number of the face used to highlight escape glyphs. */
396 static Lisp_Object Qescape_glyph
;
398 /* Name and number of the face used to highlight non-breaking spaces. */
400 static Lisp_Object Qnobreak_space
;
402 /* The symbol `image' which is the car of the lists used to represent
403 images in Lisp. Also a tool bar style. */
407 /* The image map types. */
409 static Lisp_Object QCpointer
;
410 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
412 /* Tool bar styles */
413 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
415 /* Non-zero means print newline to stdout before next mini-buffer
418 bool noninteractive_need_newline
;
420 /* Non-zero means print newline to message log before next message. */
422 static bool message_log_need_newline
;
424 /* Three markers that message_dolog uses.
425 It could allocate them itself, but that causes trouble
426 in handling memory-full errors. */
427 static Lisp_Object message_dolog_marker1
;
428 static Lisp_Object message_dolog_marker2
;
429 static Lisp_Object message_dolog_marker3
;
431 /* The buffer position of the first character appearing entirely or
432 partially on the line of the selected window which contains the
433 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
434 redisplay optimization in redisplay_internal. */
436 static struct text_pos this_line_start_pos
;
438 /* Number of characters past the end of the line above, including the
439 terminating newline. */
441 static struct text_pos this_line_end_pos
;
443 /* The vertical positions and the height of this line. */
445 static int this_line_vpos
;
446 static int this_line_y
;
447 static int this_line_pixel_height
;
449 /* X position at which this display line starts. Usually zero;
450 negative if first character is partially visible. */
452 static int this_line_start_x
;
454 /* The smallest character position seen by move_it_* functions as they
455 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
456 hscrolled lines, see display_line. */
458 static struct text_pos this_line_min_pos
;
460 /* Buffer that this_line_.* variables are referring to. */
462 static struct buffer
*this_line_buffer
;
465 /* Values of those variables at last redisplay are stored as
466 properties on `overlay-arrow-position' symbol. However, if
467 Voverlay_arrow_position is a marker, last-arrow-position is its
468 numerical position. */
470 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
472 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
473 properties on a symbol in overlay-arrow-variable-list. */
475 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
477 Lisp_Object Qmenu_bar_update_hook
;
479 /* Nonzero if an overlay arrow has been displayed in this window. */
481 static bool overlay_arrow_seen
;
483 /* Vector containing glyphs for an ellipsis `...'. */
485 static Lisp_Object default_invis_vector
[3];
487 /* This is the window where the echo area message was displayed. It
488 is always a mini-buffer window, but it may not be the same window
489 currently active as a mini-buffer. */
491 Lisp_Object echo_area_window
;
493 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
494 pushes the current message and the value of
495 message_enable_multibyte on the stack, the function restore_message
496 pops the stack and displays MESSAGE again. */
498 static Lisp_Object Vmessage_stack
;
500 /* Nonzero means multibyte characters were enabled when the echo area
501 message was specified. */
503 static bool message_enable_multibyte
;
505 /* Nonzero if we should redraw the mode lines on the next redisplay. */
507 int update_mode_lines
;
509 /* Nonzero if window sizes or contents have changed since last
510 redisplay that finished. */
512 int windows_or_buffers_changed
;
514 /* Nonzero after display_mode_line if %l was used and it displayed a
517 static bool line_number_displayed
;
519 /* The name of the *Messages* buffer, a string. */
521 static Lisp_Object Vmessages_buffer_name
;
523 /* Current, index 0, and last displayed echo area message. Either
524 buffers from echo_buffers, or nil to indicate no message. */
526 Lisp_Object echo_area_buffer
[2];
528 /* The buffers referenced from echo_area_buffer. */
530 static Lisp_Object echo_buffer
[2];
532 /* A vector saved used in with_area_buffer to reduce consing. */
534 static Lisp_Object Vwith_echo_area_save_vector
;
536 /* Non-zero means display_echo_area should display the last echo area
537 message again. Set by redisplay_preserve_echo_area. */
539 static bool display_last_displayed_message_p
;
541 /* Nonzero if echo area is being used by print; zero if being used by
544 static bool message_buf_print
;
546 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
548 static Lisp_Object Qinhibit_menubar_update
;
549 static Lisp_Object Qmessage_truncate_lines
;
551 /* Set to 1 in clear_message to make redisplay_internal aware
552 of an emptied echo area. */
554 static bool message_cleared_p
;
556 /* A scratch glyph row with contents used for generating truncation
557 glyphs. Also used in direct_output_for_insert. */
559 #define MAX_SCRATCH_GLYPHS 100
560 static struct glyph_row scratch_glyph_row
;
561 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
563 /* Ascent and height of the last line processed by move_it_to. */
565 static int last_height
;
567 /* Non-zero if there's a help-echo in the echo area. */
569 bool help_echo_showing_p
;
571 /* The maximum distance to look ahead for text properties. Values
572 that are too small let us call compute_char_face and similar
573 functions too often which is expensive. Values that are too large
574 let us call compute_char_face and alike too often because we
575 might not be interested in text properties that far away. */
577 #define TEXT_PROP_DISTANCE_LIMIT 100
579 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
580 iterator state and later restore it. This is needed because the
581 bidi iterator on bidi.c keeps a stacked cache of its states, which
582 is really a singleton. When we use scratch iterator objects to
583 move around the buffer, we can cause the bidi cache to be pushed or
584 popped, and therefore we need to restore the cache state when we
585 return to the original iterator. */
586 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
589 bidi_unshelve_cache (CACHE, 1); \
591 CACHE = bidi_shelve_cache (); \
594 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
596 if (pITORIG != pITCOPY) \
597 *(pITORIG) = *(pITCOPY); \
598 bidi_unshelve_cache (CACHE, 0); \
604 /* Non-zero means print traces of redisplay if compiled with
605 GLYPH_DEBUG defined. */
607 int trace_redisplay_p
;
609 #endif /* GLYPH_DEBUG */
611 #ifdef DEBUG_TRACE_MOVE
612 /* Non-zero means trace with TRACE_MOVE to stderr. */
615 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
617 #define TRACE_MOVE(x) (void) 0
620 static Lisp_Object Qauto_hscroll_mode
;
622 /* Buffer being redisplayed -- for redisplay_window_error. */
624 static struct buffer
*displayed_buffer
;
626 /* Value returned from text property handlers (see below). */
631 HANDLED_RECOMPUTE_PROPS
,
632 HANDLED_OVERLAY_STRING_CONSUMED
,
636 /* A description of text properties that redisplay is interested
641 /* The name of the property. */
644 /* A unique index for the property. */
647 /* A handler function called to set up iterator IT from the property
648 at IT's current position. Value is used to steer handle_stop. */
649 enum prop_handled (*handler
) (struct it
*it
);
652 static enum prop_handled
handle_face_prop (struct it
*);
653 static enum prop_handled
handle_invisible_prop (struct it
*);
654 static enum prop_handled
handle_display_prop (struct it
*);
655 static enum prop_handled
handle_composition_prop (struct it
*);
656 static enum prop_handled
handle_overlay_change (struct it
*);
657 static enum prop_handled
handle_fontified_prop (struct it
*);
659 /* Properties handled by iterators. */
661 static struct props it_props
[] =
663 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
664 /* Handle `face' before `display' because some sub-properties of
665 `display' need to know the face. */
666 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
667 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
668 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
669 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
673 /* Value is the position described by X. If X is a marker, value is
674 the marker_position of X. Otherwise, value is X. */
676 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
678 /* Enumeration returned by some move_it_.* functions internally. */
682 /* Not used. Undefined value. */
685 /* Move ended at the requested buffer position or ZV. */
686 MOVE_POS_MATCH_OR_ZV
,
688 /* Move ended at the requested X pixel position. */
691 /* Move within a line ended at the end of a line that must be
695 /* Move within a line ended at the end of a line that would
696 be displayed truncated. */
699 /* Move within a line ended at a line end. */
703 /* This counter is used to clear the face cache every once in a while
704 in redisplay_internal. It is incremented for each redisplay.
705 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
708 #define CLEAR_FACE_CACHE_COUNT 500
709 static int clear_face_cache_count
;
711 /* Similarly for the image cache. */
713 #ifdef HAVE_WINDOW_SYSTEM
714 #define CLEAR_IMAGE_CACHE_COUNT 101
715 static int clear_image_cache_count
;
717 /* Null glyph slice */
718 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
721 /* True while redisplay_internal is in progress. */
725 static Lisp_Object Qinhibit_free_realized_faces
;
726 static Lisp_Object Qmode_line_default_help_echo
;
728 /* If a string, XTread_socket generates an event to display that string.
729 (The display is done in read_char.) */
731 Lisp_Object help_echo_string
;
732 Lisp_Object help_echo_window
;
733 Lisp_Object help_echo_object
;
734 ptrdiff_t help_echo_pos
;
736 /* Temporary variable for XTread_socket. */
738 Lisp_Object previous_help_echo_string
;
740 /* Platform-independent portion of hourglass implementation. */
742 #ifdef HAVE_WINDOW_SYSTEM
744 /* Non-zero means an hourglass cursor is currently shown. */
745 bool hourglass_shown_p
;
747 /* If non-null, an asynchronous timer that, when it expires, displays
748 an hourglass cursor on all frames. */
749 struct atimer
*hourglass_atimer
;
751 #endif /* HAVE_WINDOW_SYSTEM */
753 /* Name of the face used to display glyphless characters. */
754 Lisp_Object Qglyphless_char
;
756 /* Symbol for the purpose of Vglyphless_char_display. */
757 static Lisp_Object Qglyphless_char_display
;
759 /* Method symbols for Vglyphless_char_display. */
760 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
762 /* Default number of seconds to wait before displaying an hourglass
764 #define DEFAULT_HOURGLASS_DELAY 1
766 #ifdef HAVE_WINDOW_SYSTEM
768 /* Default pixel width of `thin-space' display method. */
769 #define THIN_SPACE_WIDTH 1
771 #endif /* HAVE_WINDOW_SYSTEM */
773 /* Function prototypes. */
775 static void setup_for_ellipsis (struct it
*, int);
776 static void set_iterator_to_next (struct it
*, int);
777 static void mark_window_display_accurate_1 (struct window
*, int);
778 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
779 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
780 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
781 static int cursor_row_p (struct glyph_row
*);
782 static int redisplay_mode_lines (Lisp_Object
, int);
783 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
785 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
787 static void handle_line_prefix (struct it
*);
789 static void pint2str (char *, int, ptrdiff_t);
790 static void pint2hrstr (char *, int, ptrdiff_t);
791 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
793 static int text_outside_line_unchanged_p (struct window
*,
794 ptrdiff_t, ptrdiff_t);
795 static void store_mode_line_noprop_char (char);
796 static int store_mode_line_noprop (const char *, int, int);
797 static void handle_stop (struct it
*);
798 static void handle_stop_backwards (struct it
*, ptrdiff_t);
799 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
800 static void ensure_echo_area_buffers (void);
801 static void unwind_with_echo_area_buffer (Lisp_Object
);
802 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
803 static int with_echo_area_buffer (struct window
*, int,
804 int (*) (ptrdiff_t, Lisp_Object
),
805 ptrdiff_t, Lisp_Object
);
806 static void clear_garbaged_frames (void);
807 static int current_message_1 (ptrdiff_t, Lisp_Object
);
808 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
809 static void set_message (Lisp_Object
);
810 static int set_message_1 (ptrdiff_t, Lisp_Object
);
811 static int display_echo_area (struct window
*);
812 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
813 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
814 static void unwind_redisplay (void);
815 static int string_char_and_length (const unsigned char *, int *);
816 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
818 static int compute_window_start_on_continuation_line (struct window
*);
819 static void insert_left_trunc_glyphs (struct it
*);
820 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
822 static void extend_face_to_end_of_line (struct it
*);
823 static int append_space_for_newline (struct it
*, int);
824 static int cursor_row_fully_visible_p (struct window
*, int, int);
825 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
826 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
827 static int trailing_whitespace_p (ptrdiff_t);
828 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
829 static void push_it (struct it
*, struct text_pos
*);
830 static void iterate_out_of_display_property (struct it
*);
831 static void pop_it (struct it
*);
832 static void sync_frame_with_window_matrix_rows (struct window
*);
833 static void redisplay_internal (void);
834 static int echo_area_display (int);
835 static void redisplay_windows (Lisp_Object
);
836 static void redisplay_window (Lisp_Object
, int);
837 static Lisp_Object
redisplay_window_error (Lisp_Object
);
838 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
839 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
840 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
841 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
843 static int update_menu_bar (struct frame
*, int, int);
844 static int try_window_reusing_current_matrix (struct window
*);
845 static int try_window_id (struct window
*);
846 static int display_line (struct it
*);
847 static int display_mode_lines (struct window
*);
848 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
849 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
850 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
851 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
852 static void display_menu_bar (struct window
*);
853 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
855 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
856 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
857 static void compute_line_metrics (struct it
*);
858 static void run_redisplay_end_trigger_hook (struct it
*);
859 static int get_overlay_strings (struct it
*, ptrdiff_t);
860 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
861 static void next_overlay_string (struct it
*);
862 static void reseat (struct it
*, struct text_pos
, int);
863 static void reseat_1 (struct it
*, struct text_pos
, int);
864 static void back_to_previous_visible_line_start (struct it
*);
865 static void reseat_at_next_visible_line_start (struct it
*, int);
866 static int next_element_from_ellipsis (struct it
*);
867 static int next_element_from_display_vector (struct it
*);
868 static int next_element_from_string (struct it
*);
869 static int next_element_from_c_string (struct it
*);
870 static int next_element_from_buffer (struct it
*);
871 static int next_element_from_composition (struct it
*);
872 static int next_element_from_image (struct it
*);
873 static int next_element_from_stretch (struct it
*);
874 static void load_overlay_strings (struct it
*, ptrdiff_t);
875 static int init_from_display_pos (struct it
*, struct window
*,
876 struct display_pos
*);
877 static void reseat_to_string (struct it
*, const char *,
878 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
879 static int get_next_display_element (struct it
*);
880 static enum move_it_result
881 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
882 enum move_operation_enum
);
883 static void get_visually_first_element (struct it
*);
884 static void init_to_row_start (struct it
*, struct window
*,
886 static int init_to_row_end (struct it
*, struct window
*,
888 static void back_to_previous_line_start (struct it
*);
889 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
890 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
891 Lisp_Object
, ptrdiff_t);
892 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
893 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
894 static ptrdiff_t number_of_chars (const char *, bool);
895 static void compute_stop_pos (struct it
*);
896 static void compute_string_pos (struct text_pos
*, struct text_pos
,
898 static int face_before_or_after_it_pos (struct it
*, int);
899 static ptrdiff_t next_overlay_change (ptrdiff_t);
900 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
901 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
902 static int handle_single_display_spec (struct it
*, Lisp_Object
,
903 Lisp_Object
, Lisp_Object
,
904 struct text_pos
*, ptrdiff_t, int, int);
905 static int underlying_face_id (struct it
*);
906 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
909 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
910 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
912 #ifdef HAVE_WINDOW_SYSTEM
914 static void x_consider_frame_title (Lisp_Object
);
915 static void update_tool_bar (struct frame
*, int);
916 static int redisplay_tool_bar (struct frame
*);
917 static void notice_overwritten_cursor (struct window
*,
920 static void append_stretch_glyph (struct it
*, Lisp_Object
,
924 #endif /* HAVE_WINDOW_SYSTEM */
926 static void produce_special_glyphs (struct it
*, enum display_element_type
);
927 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
928 static int coords_in_mouse_face_p (struct window
*, int, int);
932 /***********************************************************************
933 Window display dimensions
934 ***********************************************************************/
936 /* Return the bottom boundary y-position for text lines in window W.
937 This is the first y position at which a line cannot start.
938 It is relative to the top of the window.
940 This is the height of W minus the height of a mode line, if any. */
943 window_text_bottom_y (struct window
*w
)
945 int height
= WINDOW_TOTAL_HEIGHT (w
);
947 if (WINDOW_WANTS_MODELINE_P (w
))
948 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
952 /* Return the pixel width of display area AREA of window W.
953 ANY_AREA means return the total width of W, not including
954 fringes to the left and right of the window. */
957 window_box_width (struct window
*w
, enum glyph_row_area area
)
959 int cols
= w
->total_cols
;
962 if (!w
->pseudo_window_p
)
964 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
966 if (area
== TEXT_AREA
)
968 cols
-= max (0, w
->left_margin_cols
);
969 cols
-= max (0, w
->right_margin_cols
);
970 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
972 else if (area
== LEFT_MARGIN_AREA
)
974 cols
= max (0, w
->left_margin_cols
);
977 else if (area
== RIGHT_MARGIN_AREA
)
979 cols
= max (0, w
->right_margin_cols
);
984 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
988 /* Return the pixel height of the display area of window W, not
989 including mode lines of W, if any. */
992 window_box_height (struct window
*w
)
994 struct frame
*f
= XFRAME (w
->frame
);
995 int height
= WINDOW_TOTAL_HEIGHT (w
);
997 eassert (height
>= 0);
999 /* Note: the code below that determines the mode-line/header-line
1000 height is essentially the same as that contained in the macro
1001 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1002 the appropriate glyph row has its `mode_line_p' flag set,
1003 and if it doesn't, uses estimate_mode_line_height instead. */
1005 if (WINDOW_WANTS_MODELINE_P (w
))
1007 struct glyph_row
*ml_row
1008 = (w
->current_matrix
&& w
->current_matrix
->rows
1009 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1011 if (ml_row
&& ml_row
->mode_line_p
)
1012 height
-= ml_row
->height
;
1014 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1017 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1019 struct glyph_row
*hl_row
1020 = (w
->current_matrix
&& w
->current_matrix
->rows
1021 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1023 if (hl_row
&& hl_row
->mode_line_p
)
1024 height
-= hl_row
->height
;
1026 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1029 /* With a very small font and a mode-line that's taller than
1030 default, we might end up with a negative height. */
1031 return max (0, height
);
1034 /* Return the window-relative coordinate of the left edge of display
1035 area AREA of window W. ANY_AREA means return the left edge of the
1036 whole window, to the right of the left fringe of W. */
1039 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1043 if (w
->pseudo_window_p
)
1046 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1048 if (area
== TEXT_AREA
)
1049 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1050 + window_box_width (w
, LEFT_MARGIN_AREA
));
1051 else if (area
== RIGHT_MARGIN_AREA
)
1052 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1053 + window_box_width (w
, LEFT_MARGIN_AREA
)
1054 + window_box_width (w
, TEXT_AREA
)
1055 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1057 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1058 else if (area
== LEFT_MARGIN_AREA
1059 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1060 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1066 /* Return the window-relative coordinate of the right edge of display
1067 area AREA of window W. ANY_AREA means return the right edge of the
1068 whole window, to the left of the right fringe of W. */
1071 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1073 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1076 /* Return the frame-relative coordinate of the left edge of display
1077 area AREA of window W. ANY_AREA means return the left edge of the
1078 whole window, to the right of the left fringe of W. */
1081 window_box_left (struct window
*w
, enum glyph_row_area area
)
1083 struct frame
*f
= XFRAME (w
->frame
);
1086 if (w
->pseudo_window_p
)
1087 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1089 x
= (WINDOW_LEFT_EDGE_X (w
)
1090 + window_box_left_offset (w
, area
));
1096 /* Return the frame-relative coordinate of the right edge of display
1097 area AREA of window W. ANY_AREA means return the right edge of the
1098 whole window, to the left of the right fringe of W. */
1101 window_box_right (struct window
*w
, enum glyph_row_area area
)
1103 return window_box_left (w
, area
) + window_box_width (w
, area
);
1106 /* Get the bounding box of the display area AREA of window W, without
1107 mode lines, in frame-relative coordinates. ANY_AREA means the
1108 whole window, not including the left and right fringes of
1109 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1110 coordinates of the upper-left corner of the box. Return in
1111 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1114 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1115 int *box_y
, int *box_width
, int *box_height
)
1118 *box_width
= window_box_width (w
, area
);
1120 *box_height
= window_box_height (w
);
1122 *box_x
= window_box_left (w
, area
);
1125 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1126 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1127 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1131 #ifdef HAVE_WINDOW_SYSTEM
1133 /* Get the bounding box of the display area AREA of window W, without
1134 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1135 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1136 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1137 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1141 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1142 int *bottom_right_x
, int *bottom_right_y
)
1144 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1145 bottom_right_x
, bottom_right_y
);
1146 *bottom_right_x
+= *top_left_x
;
1147 *bottom_right_y
+= *top_left_y
;
1150 #endif /* HAVE_WINDOW_SYSTEM */
1152 /***********************************************************************
1154 ***********************************************************************/
1156 /* Return the bottom y-position of the line the iterator IT is in.
1157 This can modify IT's settings. */
1160 line_bottom_y (struct it
*it
)
1162 int line_height
= it
->max_ascent
+ it
->max_descent
;
1163 int line_top_y
= it
->current_y
;
1165 if (line_height
== 0)
1168 line_height
= last_height
;
1169 else if (IT_CHARPOS (*it
) < ZV
)
1171 move_it_by_lines (it
, 1);
1172 line_height
= (it
->max_ascent
|| it
->max_descent
1173 ? it
->max_ascent
+ it
->max_descent
1178 struct glyph_row
*row
= it
->glyph_row
;
1180 /* Use the default character height. */
1181 it
->glyph_row
= NULL
;
1182 it
->what
= IT_CHARACTER
;
1185 PRODUCE_GLYPHS (it
);
1186 line_height
= it
->ascent
+ it
->descent
;
1187 it
->glyph_row
= row
;
1191 return line_top_y
+ line_height
;
1194 DEFUN ("line-pixel-height", Fline_pixel_height
,
1195 Sline_pixel_height
, 0, 0, 0,
1196 doc
: /* Return height in pixels of text line in the selected window.
1198 Value is the height in pixels of the line at point. */)
1203 struct window
*w
= XWINDOW (selected_window
);
1205 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1206 start_display (&it
, w
, pt
);
1207 it
.vpos
= it
.current_y
= 0;
1209 return make_number (line_bottom_y (&it
));
1212 /* Return the default pixel height of text lines in window W. The
1213 value is the canonical height of the W frame's default font, plus
1214 any extra space required by the line-spacing variable or frame
1217 Implementation note: this ignores any line-spacing text properties
1218 put on the newline characters. This is because those properties
1219 only affect the _screen_ line ending in the newline (i.e., in a
1220 continued line, only the last screen line will be affected), which
1221 means only a small number of lines in a buffer can ever use this
1222 feature. Since this function is used to compute the default pixel
1223 equivalent of text lines in a window, we can safely ignore those
1224 few lines. For the same reasons, we ignore the line-height
1227 default_line_pixel_height (struct window
*w
)
1229 struct frame
*f
= WINDOW_XFRAME (w
);
1230 int height
= FRAME_LINE_HEIGHT (f
);
1232 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1234 struct buffer
*b
= XBUFFER (w
->contents
);
1235 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1238 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1241 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1242 height
+= XFASTINT (val
);
1243 else if (FLOATP (val
))
1245 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1252 height
+= f
->extra_line_spacing
;
1258 /* Subroutine of pos_visible_p below. Extracts a display string, if
1259 any, from the display spec given as its argument. */
1261 string_from_display_spec (Lisp_Object spec
)
1265 while (CONSP (spec
))
1267 if (STRINGP (XCAR (spec
)))
1272 else if (VECTORP (spec
))
1276 for (i
= 0; i
< ASIZE (spec
); i
++)
1278 if (STRINGP (AREF (spec
, i
)))
1279 return AREF (spec
, i
);
1288 /* Limit insanely large values of W->hscroll on frame F to the largest
1289 value that will still prevent first_visible_x and last_visible_x of
1290 'struct it' from overflowing an int. */
1292 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1294 ptrdiff_t window_hscroll
= w
->hscroll
;
1295 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1296 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1298 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1299 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1301 return window_hscroll
;
1304 /* Return 1 if position CHARPOS is visible in window W.
1305 CHARPOS < 0 means return info about WINDOW_END position.
1306 If visible, set *X and *Y to pixel coordinates of top left corner.
1307 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1308 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1311 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1312 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1315 void *itdata
= bidi_shelve_cache ();
1316 struct text_pos top
;
1318 struct buffer
*old_buffer
= NULL
;
1320 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1323 if (XBUFFER (w
->contents
) != current_buffer
)
1325 old_buffer
= current_buffer
;
1326 set_buffer_internal_1 (XBUFFER (w
->contents
));
1329 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1330 /* Scrolling a minibuffer window via scroll bar when the echo area
1331 shows long text sometimes resets the minibuffer contents behind
1333 if (CHARPOS (top
) > ZV
)
1334 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1336 /* Compute exact mode line heights. */
1337 if (WINDOW_WANTS_MODELINE_P (w
))
1339 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1340 BVAR (current_buffer
, mode_line_format
));
1342 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1343 w
->header_line_height
1344 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1345 BVAR (current_buffer
, header_line_format
));
1347 start_display (&it
, w
, top
);
1348 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1349 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1352 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1353 && IT_CHARPOS (it
) >= charpos
)
1354 /* When scanning backwards under bidi iteration, move_it_to
1355 stops at or _before_ CHARPOS, because it stops at or to
1356 the _right_ of the character at CHARPOS. */
1357 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1358 && IT_CHARPOS (it
) <= charpos
)))
1360 /* We have reached CHARPOS, or passed it. How the call to
1361 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1362 or covered by a display property, move_it_to stops at the end
1363 of the invisible text, to the right of CHARPOS. (ii) If
1364 CHARPOS is in a display vector, move_it_to stops on its last
1366 int top_x
= it
.current_x
;
1367 int top_y
= it
.current_y
;
1368 /* Calling line_bottom_y may change it.method, it.position, etc. */
1369 enum it_method it_method
= it
.method
;
1370 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1371 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1373 if (top_y
< window_top_y
)
1374 visible_p
= bottom_y
> window_top_y
;
1375 else if (top_y
< it
.last_visible_y
)
1377 if (bottom_y
>= it
.last_visible_y
1378 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1379 && IT_CHARPOS (it
) < charpos
)
1381 /* When the last line of the window is scanned backwards
1382 under bidi iteration, we could be duped into thinking
1383 that we have passed CHARPOS, when in fact move_it_to
1384 simply stopped short of CHARPOS because it reached
1385 last_visible_y. To see if that's what happened, we call
1386 move_it_to again with a slightly larger vertical limit,
1387 and see if it actually moved vertically; if it did, we
1388 didn't really reach CHARPOS, which is beyond window end. */
1389 struct it save_it
= it
;
1390 /* Why 10? because we don't know how many canonical lines
1391 will the height of the next line(s) be. So we guess. */
1392 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1394 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1395 MOVE_TO_POS
| MOVE_TO_Y
);
1396 if (it
.current_y
> top_y
)
1403 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1405 /* We stopped on the last glyph of a display vector.
1406 Try and recompute. Hack alert! */
1407 if (charpos
< 2 || top
.charpos
>= charpos
)
1408 top_x
= it
.glyph_row
->x
;
1411 struct it it2
, it2_prev
;
1412 /* The idea is to get to the previous buffer
1413 position, consume the character there, and use
1414 the pixel coordinates we get after that. But if
1415 the previous buffer position is also displayed
1416 from a display vector, we need to consume all of
1417 the glyphs from that display vector. */
1418 start_display (&it2
, w
, top
);
1419 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1420 /* If we didn't get to CHARPOS - 1, there's some
1421 replacing display property at that position, and
1422 we stopped after it. That is exactly the place
1423 whose coordinates we want. */
1424 if (IT_CHARPOS (it2
) != charpos
- 1)
1428 /* Iterate until we get out of the display
1429 vector that displays the character at
1432 get_next_display_element (&it2
);
1433 PRODUCE_GLYPHS (&it2
);
1435 set_iterator_to_next (&it2
, 1);
1436 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1437 && IT_CHARPOS (it2
) < charpos
);
1439 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1440 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1441 top_x
= it
.glyph_row
->x
;
1444 top_x
= it2_prev
.current_x
;
1445 top_y
= it2_prev
.current_y
;
1449 else if (IT_CHARPOS (it
) != charpos
)
1451 Lisp_Object cpos
= make_number (charpos
);
1452 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1453 Lisp_Object string
= string_from_display_spec (spec
);
1454 struct text_pos tpos
;
1455 int replacing_spec_p
;
1456 bool newline_in_string
1458 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1460 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1463 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1464 charpos
, FRAME_WINDOW_P (it
.f
)));
1465 /* The tricky code below is needed because there's a
1466 discrepancy between move_it_to and how we set cursor
1467 when PT is at the beginning of a portion of text
1468 covered by a display property or an overlay with a
1469 display property, or the display line ends in a
1470 newline from a display string. move_it_to will stop
1471 _after_ such display strings, whereas
1472 set_cursor_from_row conspires with cursor_row_p to
1473 place the cursor on the first glyph produced from the
1476 /* We have overshoot PT because it is covered by a
1477 display property that replaces the text it covers.
1478 If the string includes embedded newlines, we are also
1479 in the wrong display line. Backtrack to the correct
1480 line, where the display property begins. */
1481 if (replacing_spec_p
)
1483 Lisp_Object startpos
, endpos
;
1484 EMACS_INT start
, end
;
1488 /* Find the first and the last buffer positions
1489 covered by the display string. */
1491 Fnext_single_char_property_change (cpos
, Qdisplay
,
1494 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1496 start
= XFASTINT (startpos
);
1497 end
= XFASTINT (endpos
);
1498 /* Move to the last buffer position before the
1499 display property. */
1500 start_display (&it3
, w
, top
);
1501 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1502 /* Move forward one more line if the position before
1503 the display string is a newline or if it is the
1504 rightmost character on a line that is
1505 continued or word-wrapped. */
1506 if (it3
.method
== GET_FROM_BUFFER
1508 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1509 move_it_by_lines (&it3
, 1);
1510 else if (move_it_in_display_line_to (&it3
, -1,
1514 == MOVE_LINE_CONTINUED
)
1516 move_it_by_lines (&it3
, 1);
1517 /* When we are under word-wrap, the #$@%!
1518 move_it_by_lines moves 2 lines, so we need to
1520 if (it3
.line_wrap
== WORD_WRAP
)
1521 move_it_by_lines (&it3
, -1);
1524 /* Record the vertical coordinate of the display
1525 line where we wound up. */
1526 top_y
= it3
.current_y
;
1529 /* When characters are reordered for display,
1530 the character displayed to the left of the
1531 display string could be _after_ the display
1532 property in the logical order. Use the
1533 smallest vertical position of these two. */
1534 start_display (&it3
, w
, top
);
1535 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1536 if (it3
.current_y
< top_y
)
1537 top_y
= it3
.current_y
;
1539 /* Move from the top of the window to the beginning
1540 of the display line where the display string
1542 start_display (&it3
, w
, top
);
1543 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1544 /* If it3_moved stays zero after the 'while' loop
1545 below, that means we already were at a newline
1546 before the loop (e.g., the display string begins
1547 with a newline), so we don't need to (and cannot)
1548 inspect the glyphs of it3.glyph_row, because
1549 PRODUCE_GLYPHS will not produce anything for a
1550 newline, and thus it3.glyph_row stays at its
1551 stale content it got at top of the window. */
1553 /* Finally, advance the iterator until we hit the
1554 first display element whose character position is
1555 CHARPOS, or until the first newline from the
1556 display string, which signals the end of the
1558 while (get_next_display_element (&it3
))
1560 PRODUCE_GLYPHS (&it3
);
1561 if (IT_CHARPOS (it3
) == charpos
1562 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1565 set_iterator_to_next (&it3
, 0);
1567 top_x
= it3
.current_x
- it3
.pixel_width
;
1568 /* Normally, we would exit the above loop because we
1569 found the display element whose character
1570 position is CHARPOS. For the contingency that we
1571 didn't, and stopped at the first newline from the
1572 display string, move back over the glyphs
1573 produced from the string, until we find the
1574 rightmost glyph not from the string. */
1576 && newline_in_string
1577 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1579 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1580 + it3
.glyph_row
->used
[TEXT_AREA
];
1582 while (EQ ((g
- 1)->object
, string
))
1585 top_x
-= g
->pixel_width
;
1587 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1588 + it3
.glyph_row
->used
[TEXT_AREA
]);
1594 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1595 *rtop
= max (0, window_top_y
- top_y
);
1596 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1597 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1598 - max (top_y
, window_top_y
)));
1604 /* We were asked to provide info about WINDOW_END. */
1606 void *it2data
= NULL
;
1608 SAVE_IT (it2
, it
, it2data
);
1609 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1610 move_it_by_lines (&it
, 1);
1611 if (charpos
< IT_CHARPOS (it
)
1612 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1615 RESTORE_IT (&it2
, &it2
, it2data
);
1616 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1618 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1619 *rtop
= max (0, -it2
.current_y
);
1620 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1621 - it
.last_visible_y
));
1622 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1624 - max (it2
.current_y
,
1625 WINDOW_HEADER_LINE_HEIGHT (w
))));
1629 bidi_unshelve_cache (it2data
, 1);
1631 bidi_unshelve_cache (itdata
, 0);
1634 set_buffer_internal_1 (old_buffer
);
1636 if (visible_p
&& w
->hscroll
> 0)
1638 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1639 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1642 /* Debugging code. */
1644 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1645 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1647 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1654 /* Return the next character from STR. Return in *LEN the length of
1655 the character. This is like STRING_CHAR_AND_LENGTH but never
1656 returns an invalid character. If we find one, we return a `?', but
1657 with the length of the invalid character. */
1660 string_char_and_length (const unsigned char *str
, int *len
)
1664 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1665 if (!CHAR_VALID_P (c
))
1666 /* We may not change the length here because other places in Emacs
1667 don't use this function, i.e. they silently accept invalid
1676 /* Given a position POS containing a valid character and byte position
1677 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1679 static struct text_pos
1680 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1682 eassert (STRINGP (string
) && nchars
>= 0);
1684 if (STRING_MULTIBYTE (string
))
1686 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1691 string_char_and_length (p
, &len
);
1694 BYTEPOS (pos
) += len
;
1698 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1704 /* Value is the text position, i.e. character and byte position,
1705 for character position CHARPOS in STRING. */
1707 static struct text_pos
1708 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1710 struct text_pos pos
;
1711 eassert (STRINGP (string
));
1712 eassert (charpos
>= 0);
1713 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1718 /* Value is a text position, i.e. character and byte position, for
1719 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1720 means recognize multibyte characters. */
1722 static struct text_pos
1723 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1725 struct text_pos pos
;
1727 eassert (s
!= NULL
);
1728 eassert (charpos
>= 0);
1734 SET_TEXT_POS (pos
, 0, 0);
1737 string_char_and_length ((const unsigned char *) s
, &len
);
1740 BYTEPOS (pos
) += len
;
1744 SET_TEXT_POS (pos
, charpos
, charpos
);
1750 /* Value is the number of characters in C string S. MULTIBYTE_P
1751 non-zero means recognize multibyte characters. */
1754 number_of_chars (const char *s
, bool multibyte_p
)
1760 ptrdiff_t rest
= strlen (s
);
1762 const unsigned char *p
= (const unsigned char *) s
;
1764 for (nchars
= 0; rest
> 0; ++nchars
)
1766 string_char_and_length (p
, &len
);
1767 rest
-= len
, p
+= len
;
1771 nchars
= strlen (s
);
1777 /* Compute byte position NEWPOS->bytepos corresponding to
1778 NEWPOS->charpos. POS is a known position in string STRING.
1779 NEWPOS->charpos must be >= POS.charpos. */
1782 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1784 eassert (STRINGP (string
));
1785 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1787 if (STRING_MULTIBYTE (string
))
1788 *newpos
= string_pos_nchars_ahead (pos
, string
,
1789 CHARPOS (*newpos
) - CHARPOS (pos
));
1791 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1795 Return an estimation of the pixel height of mode or header lines on
1796 frame F. FACE_ID specifies what line's height to estimate. */
1799 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1801 #ifdef HAVE_WINDOW_SYSTEM
1802 if (FRAME_WINDOW_P (f
))
1804 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1806 /* This function is called so early when Emacs starts that the face
1807 cache and mode line face are not yet initialized. */
1808 if (FRAME_FACE_CACHE (f
))
1810 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1814 height
= FONT_HEIGHT (face
->font
);
1815 if (face
->box_line_width
> 0)
1816 height
+= 2 * face
->box_line_width
;
1827 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1828 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1829 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1830 not force the value into range. */
1833 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1834 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1837 #ifdef HAVE_WINDOW_SYSTEM
1838 if (FRAME_WINDOW_P (f
))
1840 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1841 even for negative values. */
1843 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1845 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1847 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1848 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1851 STORE_NATIVE_RECT (*bounds
,
1852 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1853 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1854 FRAME_COLUMN_WIDTH (f
) - 1,
1855 FRAME_LINE_HEIGHT (f
) - 1);
1861 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1862 pix_x
= FRAME_TOTAL_COLS (f
);
1866 else if (pix_y
> FRAME_LINES (f
))
1867 pix_y
= FRAME_LINES (f
);
1877 /* Find the glyph under window-relative coordinates X/Y in window W.
1878 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1879 strings. Return in *HPOS and *VPOS the row and column number of
1880 the glyph found. Return in *AREA the glyph area containing X.
1881 Value is a pointer to the glyph found or null if X/Y is not on
1882 text, or we can't tell because W's current matrix is not up to
1885 static struct glyph
*
1886 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1887 int *dx
, int *dy
, int *area
)
1889 struct glyph
*glyph
, *end
;
1890 struct glyph_row
*row
= NULL
;
1893 /* Find row containing Y. Give up if some row is not enabled. */
1894 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1896 row
= MATRIX_ROW (w
->current_matrix
, i
);
1897 if (!row
->enabled_p
)
1899 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1906 /* Give up if Y is not in the window. */
1907 if (i
== w
->current_matrix
->nrows
)
1910 /* Get the glyph area containing X. */
1911 if (w
->pseudo_window_p
)
1918 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1920 *area
= LEFT_MARGIN_AREA
;
1921 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1923 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1926 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1930 *area
= RIGHT_MARGIN_AREA
;
1931 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1935 /* Find glyph containing X. */
1936 glyph
= row
->glyphs
[*area
];
1937 end
= glyph
+ row
->used
[*area
];
1939 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1941 x
-= glyph
->pixel_width
;
1951 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1954 *hpos
= glyph
- row
->glyphs
[*area
];
1958 /* Convert frame-relative x/y to coordinates relative to window W.
1959 Takes pseudo-windows into account. */
1962 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1964 if (w
->pseudo_window_p
)
1966 /* A pseudo-window is always full-width, and starts at the
1967 left edge of the frame, plus a frame border. */
1968 struct frame
*f
= XFRAME (w
->frame
);
1969 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1970 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1974 *x
-= WINDOW_LEFT_EDGE_X (w
);
1975 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1979 #ifdef HAVE_WINDOW_SYSTEM
1982 Return in RECTS[] at most N clipping rectangles for glyph string S.
1983 Return the number of stored rectangles. */
1986 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1993 if (s
->row
->full_width_p
)
1995 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1996 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1997 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1999 /* Unless displaying a mode or menu bar line, which are always
2000 fully visible, clip to the visible part of the row. */
2001 if (s
->w
->pseudo_window_p
)
2002 r
.height
= s
->row
->visible_height
;
2004 r
.height
= s
->height
;
2008 /* This is a text line that may be partially visible. */
2009 r
.x
= window_box_left (s
->w
, s
->area
);
2010 r
.width
= window_box_width (s
->w
, s
->area
);
2011 r
.height
= s
->row
->visible_height
;
2015 if (r
.x
< s
->clip_head
->x
)
2017 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2018 r
.width
-= s
->clip_head
->x
- r
.x
;
2021 r
.x
= s
->clip_head
->x
;
2024 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2026 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2027 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2032 /* If S draws overlapping rows, it's sufficient to use the top and
2033 bottom of the window for clipping because this glyph string
2034 intentionally draws over other lines. */
2035 if (s
->for_overlaps
)
2037 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2038 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2040 /* Alas, the above simple strategy does not work for the
2041 environments with anti-aliased text: if the same text is
2042 drawn onto the same place multiple times, it gets thicker.
2043 If the overlap we are processing is for the erased cursor, we
2044 take the intersection with the rectangle of the cursor. */
2045 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2047 XRectangle rc
, r_save
= r
;
2049 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2050 rc
.y
= s
->w
->phys_cursor
.y
;
2051 rc
.width
= s
->w
->phys_cursor_width
;
2052 rc
.height
= s
->w
->phys_cursor_height
;
2054 x_intersect_rectangles (&r_save
, &rc
, &r
);
2059 /* Don't use S->y for clipping because it doesn't take partially
2060 visible lines into account. For example, it can be negative for
2061 partially visible lines at the top of a window. */
2062 if (!s
->row
->full_width_p
2063 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2064 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2066 r
.y
= max (0, s
->row
->y
);
2069 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2071 /* If drawing the cursor, don't let glyph draw outside its
2072 advertised boundaries. Cleartype does this under some circumstances. */
2073 if (s
->hl
== DRAW_CURSOR
)
2075 struct glyph
*glyph
= s
->first_glyph
;
2080 r
.width
-= s
->x
- r
.x
;
2083 r
.width
= min (r
.width
, glyph
->pixel_width
);
2085 /* If r.y is below window bottom, ensure that we still see a cursor. */
2086 height
= min (glyph
->ascent
+ glyph
->descent
,
2087 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2088 max_y
= window_text_bottom_y (s
->w
) - height
;
2089 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2090 if (s
->ybase
- glyph
->ascent
> max_y
)
2097 /* Don't draw cursor glyph taller than our actual glyph. */
2098 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2099 if (height
< r
.height
)
2101 max_y
= r
.y
+ r
.height
;
2102 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2103 r
.height
= min (max_y
- r
.y
, height
);
2110 XRectangle r_save
= r
;
2112 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2116 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2117 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2119 #ifdef CONVERT_FROM_XRECT
2120 CONVERT_FROM_XRECT (r
, *rects
);
2128 /* If we are processing overlapping and allowed to return
2129 multiple clipping rectangles, we exclude the row of the glyph
2130 string from the clipping rectangle. This is to avoid drawing
2131 the same text on the environment with anti-aliasing. */
2132 #ifdef CONVERT_FROM_XRECT
2135 XRectangle
*rs
= rects
;
2137 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2139 if (s
->for_overlaps
& OVERLAPS_PRED
)
2142 if (r
.y
+ r
.height
> row_y
)
2145 rs
[i
].height
= row_y
- r
.y
;
2151 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2154 if (r
.y
< row_y
+ s
->row
->visible_height
)
2156 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2158 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2159 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2168 #ifdef CONVERT_FROM_XRECT
2169 for (i
= 0; i
< n
; i
++)
2170 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2177 Return in *NR the clipping rectangle for glyph string S. */
2180 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2182 get_glyph_string_clip_rects (s
, nr
, 1);
2187 Return the position and height of the phys cursor in window W.
2188 Set w->phys_cursor_width to width of phys cursor.
2192 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2193 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2195 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2196 int x
, y
, wd
, h
, h0
, y0
;
2198 /* Compute the width of the rectangle to draw. If on a stretch
2199 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2200 rectangle as wide as the glyph, but use a canonical character
2202 wd
= glyph
->pixel_width
- 1;
2203 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2207 x
= w
->phys_cursor
.x
;
2214 if (glyph
->type
== STRETCH_GLYPH
2215 && !x_stretch_cursor_p
)
2216 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2217 w
->phys_cursor_width
= wd
;
2219 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2221 /* If y is below window bottom, ensure that we still see a cursor. */
2222 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2224 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2225 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2227 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2230 h
= max (h
- (y0
- y
) + 1, h0
);
2235 y0
= window_text_bottom_y (w
) - h0
;
2243 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2244 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2249 * Remember which glyph the mouse is over.
2253 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2257 struct glyph_row
*r
, *gr
, *end_row
;
2258 enum window_part part
;
2259 enum glyph_row_area area
;
2260 int x
, y
, width
, height
;
2262 /* Try to determine frame pixel position and size of the glyph under
2263 frame pixel coordinates X/Y on frame F. */
2265 if (!f
->glyphs_initialized_p
2266 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2269 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2270 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2274 w
= XWINDOW (window
);
2275 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2276 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2278 x
= window_relative_x_coord (w
, part
, gx
);
2279 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2281 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2282 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2284 if (w
->pseudo_window_p
)
2287 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2293 case ON_LEFT_MARGIN
:
2294 area
= LEFT_MARGIN_AREA
;
2297 case ON_RIGHT_MARGIN
:
2298 area
= RIGHT_MARGIN_AREA
;
2301 case ON_HEADER_LINE
:
2303 gr
= (part
== ON_HEADER_LINE
2304 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2305 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2308 goto text_glyph_row_found
;
2315 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2316 if (r
->y
+ r
->height
> y
)
2322 text_glyph_row_found
:
2325 struct glyph
*g
= gr
->glyphs
[area
];
2326 struct glyph
*end
= g
+ gr
->used
[area
];
2328 height
= gr
->height
;
2329 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2330 if (gx
+ g
->pixel_width
> x
)
2335 if (g
->type
== IMAGE_GLYPH
)
2337 /* Don't remember when mouse is over image, as
2338 image may have hot-spots. */
2339 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2342 width
= g
->pixel_width
;
2346 /* Use nominal char spacing at end of line. */
2348 gx
+= (x
/ width
) * width
;
2351 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2352 gx
+= window_box_left_offset (w
, area
);
2356 /* Use nominal line height at end of window. */
2357 gx
= (x
/ width
) * width
;
2359 gy
+= (y
/ height
) * height
;
2363 case ON_LEFT_FRINGE
:
2364 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2365 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2366 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2367 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2370 case ON_RIGHT_FRINGE
:
2371 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2372 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2373 : window_box_right_offset (w
, TEXT_AREA
));
2374 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2378 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2380 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2381 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2382 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2384 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2388 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2389 if (r
->y
+ r
->height
> y
)
2396 height
= gr
->height
;
2399 /* Use nominal line height at end of window. */
2401 gy
+= (y
/ height
) * height
;
2408 /* If there is no glyph under the mouse, then we divide the screen
2409 into a grid of the smallest glyph in the frame, and use that
2412 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2413 round down even for negative values. */
2419 gx
= (gx
/ width
) * width
;
2420 gy
= (gy
/ height
) * height
;
2425 gx
+= WINDOW_LEFT_EDGE_X (w
);
2426 gy
+= WINDOW_TOP_EDGE_Y (w
);
2429 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2431 /* Visible feedback for debugging. */
2434 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2435 f
->output_data
.x
->normal_gc
,
2436 gx
, gy
, width
, height
);
2442 #endif /* HAVE_WINDOW_SYSTEM */
2445 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2448 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2449 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2451 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2454 /***********************************************************************
2455 Lisp form evaluation
2456 ***********************************************************************/
2458 /* Error handler for safe_eval and safe_call. */
2461 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2463 add_to_log ("Error during redisplay: %S signaled %S",
2464 Flist (nargs
, args
), arg
);
2468 /* Call function FUNC with the rest of NARGS - 1 arguments
2469 following. Return the result, or nil if something went
2470 wrong. Prevent redisplay during the evaluation. */
2473 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2477 if (inhibit_eval_during_redisplay
)
2483 ptrdiff_t count
= SPECPDL_INDEX ();
2484 struct gcpro gcpro1
;
2485 Lisp_Object
*args
= alloca (nargs
* word_size
);
2488 va_start (ap
, func
);
2489 for (i
= 1; i
< nargs
; i
++)
2490 args
[i
] = va_arg (ap
, Lisp_Object
);
2494 gcpro1
.nvars
= nargs
;
2495 specbind (Qinhibit_redisplay
, Qt
);
2496 /* Use Qt to ensure debugger does not run,
2497 so there is no possibility of wanting to redisplay. */
2498 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2501 val
= unbind_to (count
, val
);
2508 /* Call function FN with one argument ARG.
2509 Return the result, or nil if something went wrong. */
2512 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2514 return safe_call (2, fn
, arg
);
2517 static Lisp_Object Qeval
;
2520 safe_eval (Lisp_Object sexpr
)
2522 return safe_call1 (Qeval
, sexpr
);
2525 /* Call function FN with two arguments ARG1 and ARG2.
2526 Return the result, or nil if something went wrong. */
2529 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2531 return safe_call (3, fn
, arg1
, arg2
);
2536 /***********************************************************************
2538 ***********************************************************************/
2542 /* Define CHECK_IT to perform sanity checks on iterators.
2543 This is for debugging. It is too slow to do unconditionally. */
2546 check_it (struct it
*it
)
2548 if (it
->method
== GET_FROM_STRING
)
2550 eassert (STRINGP (it
->string
));
2551 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2555 eassert (IT_STRING_CHARPOS (*it
) < 0);
2556 if (it
->method
== GET_FROM_BUFFER
)
2558 /* Check that character and byte positions agree. */
2559 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2564 eassert (it
->current
.dpvec_index
>= 0);
2566 eassert (it
->current
.dpvec_index
< 0);
2569 #define CHECK_IT(IT) check_it ((IT))
2573 #define CHECK_IT(IT) (void) 0
2578 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2580 /* Check that the window end of window W is what we expect it
2581 to be---the last row in the current matrix displaying text. */
2584 check_window_end (struct window
*w
)
2586 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2588 struct glyph_row
*row
;
2589 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2591 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2592 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2596 #define CHECK_WINDOW_END(W) check_window_end ((W))
2600 #define CHECK_WINDOW_END(W) (void) 0
2602 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2604 /* Return mark position if current buffer has the region of non-zero length,
2608 markpos_of_region (void)
2610 if (!NILP (Vtransient_mark_mode
)
2611 && !NILP (BVAR (current_buffer
, mark_active
))
2612 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2614 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2622 /***********************************************************************
2623 Iterator initialization
2624 ***********************************************************************/
2626 /* Initialize IT for displaying current_buffer in window W, starting
2627 at character position CHARPOS. CHARPOS < 0 means that no buffer
2628 position is specified which is useful when the iterator is assigned
2629 a position later. BYTEPOS is the byte position corresponding to
2632 If ROW is not null, calls to produce_glyphs with IT as parameter
2633 will produce glyphs in that row.
2635 BASE_FACE_ID is the id of a base face to use. It must be one of
2636 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2637 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2638 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2640 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2641 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2642 will be initialized to use the corresponding mode line glyph row of
2643 the desired matrix of W. */
2646 init_iterator (struct it
*it
, struct window
*w
,
2647 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2648 struct glyph_row
*row
, enum face_id base_face_id
)
2651 enum face_id remapped_base_face_id
= base_face_id
;
2653 /* Some precondition checks. */
2654 eassert (w
!= NULL
&& it
!= NULL
);
2655 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2658 /* If face attributes have been changed since the last redisplay,
2659 free realized faces now because they depend on face definitions
2660 that might have changed. Don't free faces while there might be
2661 desired matrices pending which reference these faces. */
2662 if (face_change_count
&& !inhibit_free_realized_faces
)
2664 face_change_count
= 0;
2665 free_all_realized_faces (Qnil
);
2668 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2669 if (! NILP (Vface_remapping_alist
))
2670 remapped_base_face_id
2671 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2673 /* Use one of the mode line rows of W's desired matrix if
2677 if (base_face_id
== MODE_LINE_FACE_ID
2678 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2679 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2680 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2681 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2685 memset (it
, 0, sizeof *it
);
2686 it
->current
.overlay_string_index
= -1;
2687 it
->current
.dpvec_index
= -1;
2688 it
->base_face_id
= remapped_base_face_id
;
2690 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2691 it
->paragraph_embedding
= L2R
;
2692 it
->bidi_it
.string
.lstring
= Qnil
;
2693 it
->bidi_it
.string
.s
= NULL
;
2694 it
->bidi_it
.string
.bufpos
= 0;
2697 /* The window in which we iterate over current_buffer: */
2698 XSETWINDOW (it
->window
, w
);
2700 it
->f
= XFRAME (w
->frame
);
2704 /* Extra space between lines (on window systems only). */
2705 if (base_face_id
== DEFAULT_FACE_ID
2706 && FRAME_WINDOW_P (it
->f
))
2708 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2709 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2710 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2711 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2712 * FRAME_LINE_HEIGHT (it
->f
));
2713 else if (it
->f
->extra_line_spacing
> 0)
2714 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2715 it
->max_extra_line_spacing
= 0;
2718 /* If realized faces have been removed, e.g. because of face
2719 attribute changes of named faces, recompute them. When running
2720 in batch mode, the face cache of the initial frame is null. If
2721 we happen to get called, make a dummy face cache. */
2722 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2723 init_frame_faces (it
->f
);
2724 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2725 recompute_basic_faces (it
->f
);
2727 /* Current value of the `slice', `space-width', and 'height' properties. */
2728 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2729 it
->space_width
= Qnil
;
2730 it
->font_height
= Qnil
;
2731 it
->override_ascent
= -1;
2733 /* Are control characters displayed as `^C'? */
2734 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2736 /* -1 means everything between a CR and the following line end
2737 is invisible. >0 means lines indented more than this value are
2739 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2741 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2743 : (!NILP (BVAR (current_buffer
, selective_display
))
2745 it
->selective_display_ellipsis_p
2746 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2748 /* Display table to use. */
2749 it
->dp
= window_display_table (w
);
2751 /* Are multibyte characters enabled in current_buffer? */
2752 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2754 /* If visible region is of non-zero length, set IT->region_beg_charpos
2755 and IT->region_end_charpos to the start and end of a visible region
2756 in window IT->w. Set both to -1 to indicate no region. */
2757 markpos
= markpos_of_region ();
2759 /* Maybe highlight only in selected window. */
2760 && (/* Either show region everywhere. */
2761 highlight_nonselected_windows
2762 /* Or show region in the selected window. */
2763 || w
== XWINDOW (selected_window
)
2764 /* Or show the region if we are in the mini-buffer and W is
2765 the window the mini-buffer refers to. */
2766 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2767 && WINDOWP (minibuf_selected_window
)
2768 && w
== XWINDOW (minibuf_selected_window
))))
2770 it
->region_beg_charpos
= min (PT
, markpos
);
2771 it
->region_end_charpos
= max (PT
, markpos
);
2774 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2776 /* Get the position at which the redisplay_end_trigger hook should
2777 be run, if it is to be run at all. */
2778 if (MARKERP (w
->redisplay_end_trigger
)
2779 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2780 it
->redisplay_end_trigger_charpos
2781 = marker_position (w
->redisplay_end_trigger
);
2782 else if (INTEGERP (w
->redisplay_end_trigger
))
2783 it
->redisplay_end_trigger_charpos
=
2784 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2786 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2788 /* Are lines in the display truncated? */
2789 if (base_face_id
!= DEFAULT_FACE_ID
2791 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2792 && ((!NILP (Vtruncate_partial_width_windows
)
2793 && !INTEGERP (Vtruncate_partial_width_windows
))
2794 || (INTEGERP (Vtruncate_partial_width_windows
)
2795 && (WINDOW_TOTAL_COLS (it
->w
)
2796 < XINT (Vtruncate_partial_width_windows
))))))
2797 it
->line_wrap
= TRUNCATE
;
2798 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2799 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2800 ? WINDOW_WRAP
: WORD_WRAP
;
2802 it
->line_wrap
= TRUNCATE
;
2804 /* Get dimensions of truncation and continuation glyphs. These are
2805 displayed as fringe bitmaps under X, but we need them for such
2806 frames when the fringes are turned off. But leave the dimensions
2807 zero for tooltip frames, as these glyphs look ugly there and also
2808 sabotage calculations of tooltip dimensions in x-show-tip. */
2809 #ifdef HAVE_WINDOW_SYSTEM
2810 if (!(FRAME_WINDOW_P (it
->f
)
2811 && FRAMEP (tip_frame
)
2812 && it
->f
== XFRAME (tip_frame
)))
2815 if (it
->line_wrap
== TRUNCATE
)
2817 /* We will need the truncation glyph. */
2818 eassert (it
->glyph_row
== NULL
);
2819 produce_special_glyphs (it
, IT_TRUNCATION
);
2820 it
->truncation_pixel_width
= it
->pixel_width
;
2824 /* We will need the continuation glyph. */
2825 eassert (it
->glyph_row
== NULL
);
2826 produce_special_glyphs (it
, IT_CONTINUATION
);
2827 it
->continuation_pixel_width
= it
->pixel_width
;
2831 /* Reset these values to zero because the produce_special_glyphs
2832 above has changed them. */
2833 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2834 it
->phys_ascent
= it
->phys_descent
= 0;
2836 /* Set this after getting the dimensions of truncation and
2837 continuation glyphs, so that we don't produce glyphs when calling
2838 produce_special_glyphs, above. */
2839 it
->glyph_row
= row
;
2840 it
->area
= TEXT_AREA
;
2842 /* Forget any previous info about this row being reversed. */
2844 it
->glyph_row
->reversed_p
= 0;
2846 /* Get the dimensions of the display area. The display area
2847 consists of the visible window area plus a horizontally scrolled
2848 part to the left of the window. All x-values are relative to the
2849 start of this total display area. */
2850 if (base_face_id
!= DEFAULT_FACE_ID
)
2852 /* Mode lines, menu bar in terminal frames. */
2853 it
->first_visible_x
= 0;
2854 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2858 it
->first_visible_x
=
2859 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2860 it
->last_visible_x
= (it
->first_visible_x
2861 + window_box_width (w
, TEXT_AREA
));
2863 /* If we truncate lines, leave room for the truncation glyph(s) at
2864 the right margin. Otherwise, leave room for the continuation
2865 glyph(s). Done only if the window has no fringes. Since we
2866 don't know at this point whether there will be any R2L lines in
2867 the window, we reserve space for truncation/continuation glyphs
2868 even if only one of the fringes is absent. */
2869 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2870 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2872 if (it
->line_wrap
== TRUNCATE
)
2873 it
->last_visible_x
-= it
->truncation_pixel_width
;
2875 it
->last_visible_x
-= it
->continuation_pixel_width
;
2878 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2879 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2882 /* Leave room for a border glyph. */
2883 if (!FRAME_WINDOW_P (it
->f
)
2884 && !WINDOW_RIGHTMOST_P (it
->w
))
2885 it
->last_visible_x
-= 1;
2887 it
->last_visible_y
= window_text_bottom_y (w
);
2889 /* For mode lines and alike, arrange for the first glyph having a
2890 left box line if the face specifies a box. */
2891 if (base_face_id
!= DEFAULT_FACE_ID
)
2895 it
->face_id
= remapped_base_face_id
;
2897 /* If we have a boxed mode line, make the first character appear
2898 with a left box line. */
2899 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2900 if (face
->box
!= FACE_NO_BOX
)
2901 it
->start_of_box_run_p
= 1;
2904 /* If a buffer position was specified, set the iterator there,
2905 getting overlays and face properties from that position. */
2906 if (charpos
>= BUF_BEG (current_buffer
))
2908 it
->end_charpos
= ZV
;
2909 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2910 IT_CHARPOS (*it
) = charpos
;
2911 IT_BYTEPOS (*it
) = bytepos
;
2913 /* We will rely on `reseat' to set this up properly, via
2914 handle_face_prop. */
2915 it
->face_id
= it
->base_face_id
;
2917 it
->start
= it
->current
;
2918 /* Do we need to reorder bidirectional text? Not if this is a
2919 unibyte buffer: by definition, none of the single-byte
2920 characters are strong R2L, so no reordering is needed. And
2921 bidi.c doesn't support unibyte buffers anyway. Also, don't
2922 reorder while we are loading loadup.el, since the tables of
2923 character properties needed for reordering are not yet
2927 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2930 /* If we are to reorder bidirectional text, init the bidi
2934 /* Note the paragraph direction that this buffer wants to
2936 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2938 it
->paragraph_embedding
= L2R
;
2939 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2941 it
->paragraph_embedding
= R2L
;
2943 it
->paragraph_embedding
= NEUTRAL_DIR
;
2944 bidi_unshelve_cache (NULL
, 0);
2945 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2949 /* Compute faces etc. */
2950 reseat (it
, it
->current
.pos
, 1);
2957 /* Initialize IT for the display of window W with window start POS. */
2960 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2962 struct glyph_row
*row
;
2963 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2965 row
= w
->desired_matrix
->rows
+ first_vpos
;
2966 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2967 it
->first_vpos
= first_vpos
;
2969 /* Don't reseat to previous visible line start if current start
2970 position is in a string or image. */
2971 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2973 int start_at_line_beg_p
;
2974 int first_y
= it
->current_y
;
2976 /* If window start is not at a line start, skip forward to POS to
2977 get the correct continuation lines width. */
2978 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2979 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2980 if (!start_at_line_beg_p
)
2984 reseat_at_previous_visible_line_start (it
);
2985 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2987 new_x
= it
->current_x
+ it
->pixel_width
;
2989 /* If lines are continued, this line may end in the middle
2990 of a multi-glyph character (e.g. a control character
2991 displayed as \003, or in the middle of an overlay
2992 string). In this case move_it_to above will not have
2993 taken us to the start of the continuation line but to the
2994 end of the continued line. */
2995 if (it
->current_x
> 0
2996 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2997 && (/* And glyph doesn't fit on the line. */
2998 new_x
> it
->last_visible_x
2999 /* Or it fits exactly and we're on a window
3001 || (new_x
== it
->last_visible_x
3002 && FRAME_WINDOW_P (it
->f
)
3003 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3004 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3005 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3007 if ((it
->current
.dpvec_index
>= 0
3008 || it
->current
.overlay_string_index
>= 0)
3009 /* If we are on a newline from a display vector or
3010 overlay string, then we are already at the end of
3011 a screen line; no need to go to the next line in
3012 that case, as this line is not really continued.
3013 (If we do go to the next line, C-e will not DTRT.) */
3016 set_iterator_to_next (it
, 1);
3017 move_it_in_display_line_to (it
, -1, -1, 0);
3020 it
->continuation_lines_width
+= it
->current_x
;
3022 /* If the character at POS is displayed via a display
3023 vector, move_it_to above stops at the final glyph of
3024 IT->dpvec. To make the caller redisplay that character
3025 again (a.k.a. start at POS), we need to reset the
3026 dpvec_index to the beginning of IT->dpvec. */
3027 else if (it
->current
.dpvec_index
>= 0)
3028 it
->current
.dpvec_index
= 0;
3030 /* We're starting a new display line, not affected by the
3031 height of the continued line, so clear the appropriate
3032 fields in the iterator structure. */
3033 it
->max_ascent
= it
->max_descent
= 0;
3034 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3036 it
->current_y
= first_y
;
3038 it
->current_x
= it
->hpos
= 0;
3044 /* Return 1 if POS is a position in ellipses displayed for invisible
3045 text. W is the window we display, for text property lookup. */
3048 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3050 Lisp_Object prop
, window
;
3052 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3054 /* If POS specifies a position in a display vector, this might
3055 be for an ellipsis displayed for invisible text. We won't
3056 get the iterator set up for delivering that ellipsis unless
3057 we make sure that it gets aware of the invisible text. */
3058 if (pos
->dpvec_index
>= 0
3059 && pos
->overlay_string_index
< 0
3060 && CHARPOS (pos
->string_pos
) < 0
3062 && (XSETWINDOW (window
, w
),
3063 prop
= Fget_char_property (make_number (charpos
),
3064 Qinvisible
, window
),
3065 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3067 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3069 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3076 /* Initialize IT for stepping through current_buffer in window W,
3077 starting at position POS that includes overlay string and display
3078 vector/ control character translation position information. Value
3079 is zero if there are overlay strings with newlines at POS. */
3082 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3084 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3085 int i
, overlay_strings_with_newlines
= 0;
3087 /* If POS specifies a position in a display vector, this might
3088 be for an ellipsis displayed for invisible text. We won't
3089 get the iterator set up for delivering that ellipsis unless
3090 we make sure that it gets aware of the invisible text. */
3091 if (in_ellipses_for_invisible_text_p (pos
, w
))
3097 /* Keep in mind: the call to reseat in init_iterator skips invisible
3098 text, so we might end up at a position different from POS. This
3099 is only a problem when POS is a row start after a newline and an
3100 overlay starts there with an after-string, and the overlay has an
3101 invisible property. Since we don't skip invisible text in
3102 display_line and elsewhere immediately after consuming the
3103 newline before the row start, such a POS will not be in a string,
3104 but the call to init_iterator below will move us to the
3106 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3108 /* This only scans the current chunk -- it should scan all chunks.
3109 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3110 to 16 in 22.1 to make this a lesser problem. */
3111 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3113 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3114 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3116 while (s
< e
&& *s
!= '\n')
3121 overlay_strings_with_newlines
= 1;
3126 /* If position is within an overlay string, set up IT to the right
3128 if (pos
->overlay_string_index
>= 0)
3132 /* If the first overlay string happens to have a `display'
3133 property for an image, the iterator will be set up for that
3134 image, and we have to undo that setup first before we can
3135 correct the overlay string index. */
3136 if (it
->method
== GET_FROM_IMAGE
)
3139 /* We already have the first chunk of overlay strings in
3140 IT->overlay_strings. Load more until the one for
3141 pos->overlay_string_index is in IT->overlay_strings. */
3142 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3144 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3145 it
->current
.overlay_string_index
= 0;
3148 load_overlay_strings (it
, 0);
3149 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3153 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3154 relative_index
= (it
->current
.overlay_string_index
3155 % OVERLAY_STRING_CHUNK_SIZE
);
3156 it
->string
= it
->overlay_strings
[relative_index
];
3157 eassert (STRINGP (it
->string
));
3158 it
->current
.string_pos
= pos
->string_pos
;
3159 it
->method
= GET_FROM_STRING
;
3160 it
->end_charpos
= SCHARS (it
->string
);
3161 /* Set up the bidi iterator for this overlay string. */
3164 it
->bidi_it
.string
.lstring
= it
->string
;
3165 it
->bidi_it
.string
.s
= NULL
;
3166 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3167 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3168 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3169 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3170 it
->bidi_it
.w
= it
->w
;
3171 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3172 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3174 /* Synchronize the state of the bidi iterator with
3175 pos->string_pos. For any string position other than
3176 zero, this will be done automagically when we resume
3177 iteration over the string and get_visually_first_element
3178 is called. But if string_pos is zero, and the string is
3179 to be reordered for display, we need to resync manually,
3180 since it could be that the iteration state recorded in
3181 pos ended at string_pos of 0 moving backwards in string. */
3182 if (CHARPOS (pos
->string_pos
) == 0)
3184 get_visually_first_element (it
);
3185 if (IT_STRING_CHARPOS (*it
) != 0)
3188 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3189 bidi_move_to_visually_next (&it
->bidi_it
);
3190 } while (it
->bidi_it
.charpos
!= 0);
3192 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3193 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3197 if (CHARPOS (pos
->string_pos
) >= 0)
3199 /* Recorded position is not in an overlay string, but in another
3200 string. This can only be a string from a `display' property.
3201 IT should already be filled with that string. */
3202 it
->current
.string_pos
= pos
->string_pos
;
3203 eassert (STRINGP (it
->string
));
3205 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3206 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3209 /* Restore position in display vector translations, control
3210 character translations or ellipses. */
3211 if (pos
->dpvec_index
>= 0)
3213 if (it
->dpvec
== NULL
)
3214 get_next_display_element (it
);
3215 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3216 it
->current
.dpvec_index
= pos
->dpvec_index
;
3220 return !overlay_strings_with_newlines
;
3224 /* Initialize IT for stepping through current_buffer in window W
3225 starting at ROW->start. */
3228 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3230 init_from_display_pos (it
, w
, &row
->start
);
3231 it
->start
= row
->start
;
3232 it
->continuation_lines_width
= row
->continuation_lines_width
;
3237 /* Initialize IT for stepping through current_buffer in window W
3238 starting in the line following ROW, i.e. starting at ROW->end.
3239 Value is zero if there are overlay strings with newlines at ROW's
3243 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3247 if (init_from_display_pos (it
, w
, &row
->end
))
3249 if (row
->continued_p
)
3250 it
->continuation_lines_width
3251 = row
->continuation_lines_width
+ row
->pixel_width
;
3262 /***********************************************************************
3264 ***********************************************************************/
3266 /* Called when IT reaches IT->stop_charpos. Handle text property and
3267 overlay changes. Set IT->stop_charpos to the next position where
3271 handle_stop (struct it
*it
)
3273 enum prop_handled handled
;
3274 int handle_overlay_change_p
;
3278 it
->current
.dpvec_index
= -1;
3279 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3280 it
->ignore_overlay_strings_at_pos_p
= 0;
3283 /* Use face of preceding text for ellipsis (if invisible) */
3284 if (it
->selective_display_ellipsis_p
)
3285 it
->saved_face_id
= it
->face_id
;
3289 handled
= HANDLED_NORMALLY
;
3291 /* Call text property handlers. */
3292 for (p
= it_props
; p
->handler
; ++p
)
3294 handled
= p
->handler (it
);
3296 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3298 else if (handled
== HANDLED_RETURN
)
3300 /* We still want to show before and after strings from
3301 overlays even if the actual buffer text is replaced. */
3302 if (!handle_overlay_change_p
3304 /* Don't call get_overlay_strings_1 if we already
3305 have overlay strings loaded, because doing so
3306 will load them again and push the iterator state
3307 onto the stack one more time, which is not
3308 expected by the rest of the code that processes
3310 || (it
->current
.overlay_string_index
< 0
3311 ? !get_overlay_strings_1 (it
, 0, 0)
3315 setup_for_ellipsis (it
, 0);
3316 /* When handling a display spec, we might load an
3317 empty string. In that case, discard it here. We
3318 used to discard it in handle_single_display_spec,
3319 but that causes get_overlay_strings_1, above, to
3320 ignore overlay strings that we must check. */
3321 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3325 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3329 it
->ignore_overlay_strings_at_pos_p
= 1;
3330 it
->string_from_display_prop_p
= 0;
3331 it
->from_disp_prop_p
= 0;
3332 handle_overlay_change_p
= 0;
3334 handled
= HANDLED_RECOMPUTE_PROPS
;
3337 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3338 handle_overlay_change_p
= 0;
3341 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3343 /* Don't check for overlay strings below when set to deliver
3344 characters from a display vector. */
3345 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3346 handle_overlay_change_p
= 0;
3348 /* Handle overlay changes.
3349 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3350 if it finds overlays. */
3351 if (handle_overlay_change_p
)
3352 handled
= handle_overlay_change (it
);
3357 setup_for_ellipsis (it
, 0);
3361 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3363 /* Determine where to stop next. */
3364 if (handled
== HANDLED_NORMALLY
)
3365 compute_stop_pos (it
);
3369 /* Compute IT->stop_charpos from text property and overlay change
3370 information for IT's current position. */
3373 compute_stop_pos (struct it
*it
)
3375 register INTERVAL iv
, next_iv
;
3376 Lisp_Object object
, limit
, position
;
3377 ptrdiff_t charpos
, bytepos
;
3379 if (STRINGP (it
->string
))
3381 /* Strings are usually short, so don't limit the search for
3383 it
->stop_charpos
= it
->end_charpos
;
3384 object
= it
->string
;
3386 charpos
= IT_STRING_CHARPOS (*it
);
3387 bytepos
= IT_STRING_BYTEPOS (*it
);
3393 /* If end_charpos is out of range for some reason, such as a
3394 misbehaving display function, rationalize it (Bug#5984). */
3395 if (it
->end_charpos
> ZV
)
3396 it
->end_charpos
= ZV
;
3397 it
->stop_charpos
= it
->end_charpos
;
3399 /* If next overlay change is in front of the current stop pos
3400 (which is IT->end_charpos), stop there. Note: value of
3401 next_overlay_change is point-max if no overlay change
3403 charpos
= IT_CHARPOS (*it
);
3404 bytepos
= IT_BYTEPOS (*it
);
3405 pos
= next_overlay_change (charpos
);
3406 if (pos
< it
->stop_charpos
)
3407 it
->stop_charpos
= pos
;
3409 /* If showing the region, we have to stop at the region
3410 start or end because the face might change there. */
3411 if (it
->region_beg_charpos
> 0)
3413 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3414 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3415 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3416 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3419 /* Set up variables for computing the stop position from text
3420 property changes. */
3421 XSETBUFFER (object
, current_buffer
);
3422 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3425 /* Get the interval containing IT's position. Value is a null
3426 interval if there isn't such an interval. */
3427 position
= make_number (charpos
);
3428 iv
= validate_interval_range (object
, &position
, &position
, 0);
3431 Lisp_Object values_here
[LAST_PROP_IDX
];
3434 /* Get properties here. */
3435 for (p
= it_props
; p
->handler
; ++p
)
3436 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3438 /* Look for an interval following iv that has different
3440 for (next_iv
= next_interval (iv
);
3443 || XFASTINT (limit
) > next_iv
->position
));
3444 next_iv
= next_interval (next_iv
))
3446 for (p
= it_props
; p
->handler
; ++p
)
3448 Lisp_Object new_value
;
3450 new_value
= textget (next_iv
->plist
, *p
->name
);
3451 if (!EQ (values_here
[p
->idx
], new_value
))
3461 if (INTEGERP (limit
)
3462 && next_iv
->position
>= XFASTINT (limit
))
3463 /* No text property change up to limit. */
3464 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3466 /* Text properties change in next_iv. */
3467 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3471 if (it
->cmp_it
.id
< 0)
3473 ptrdiff_t stoppos
= it
->end_charpos
;
3475 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3477 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3478 stoppos
, it
->string
);
3481 eassert (STRINGP (it
->string
)
3482 || (it
->stop_charpos
>= BEGV
3483 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3487 /* Return the position of the next overlay change after POS in
3488 current_buffer. Value is point-max if no overlay change
3489 follows. This is like `next-overlay-change' but doesn't use
3493 next_overlay_change (ptrdiff_t pos
)
3495 ptrdiff_t i
, noverlays
;
3497 Lisp_Object
*overlays
;
3499 /* Get all overlays at the given position. */
3500 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3502 /* If any of these overlays ends before endpos,
3503 use its ending point instead. */
3504 for (i
= 0; i
< noverlays
; ++i
)
3509 oend
= OVERLAY_END (overlays
[i
]);
3510 oendpos
= OVERLAY_POSITION (oend
);
3511 endpos
= min (endpos
, oendpos
);
3517 /* How many characters forward to search for a display property or
3518 display string. Searching too far forward makes the bidi display
3519 sluggish, especially in small windows. */
3520 #define MAX_DISP_SCAN 250
3522 /* Return the character position of a display string at or after
3523 position specified by POSITION. If no display string exists at or
3524 after POSITION, return ZV. A display string is either an overlay
3525 with `display' property whose value is a string, or a `display'
3526 text property whose value is a string. STRING is data about the
3527 string to iterate; if STRING->lstring is nil, we are iterating a
3528 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3529 on a GUI frame. DISP_PROP is set to zero if we searched
3530 MAX_DISP_SCAN characters forward without finding any display
3531 strings, non-zero otherwise. It is set to 2 if the display string
3532 uses any kind of `(space ...)' spec that will produce a stretch of
3533 white space in the text area. */
3535 compute_display_string_pos (struct text_pos
*position
,
3536 struct bidi_string_data
*string
,
3538 int frame_window_p
, int *disp_prop
)
3540 /* OBJECT = nil means current buffer. */
3541 Lisp_Object object
, object1
;
3542 Lisp_Object pos
, spec
, limpos
;
3543 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3544 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3545 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3546 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3548 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3549 struct text_pos tpos
;
3552 if (string
&& STRINGP (string
->lstring
))
3553 object1
= object
= string
->lstring
;
3554 else if (w
&& !string_p
)
3556 XSETWINDOW (object
, w
);
3560 object1
= object
= Qnil
;
3565 /* We don't support display properties whose values are strings
3566 that have display string properties. */
3567 || string
->from_disp_str
3568 /* C strings cannot have display properties. */
3569 || (string
->s
&& !STRINGP (object
)))
3575 /* If the character at CHARPOS is where the display string begins,
3577 pos
= make_number (charpos
);
3578 if (STRINGP (object
))
3579 bufpos
= string
->bufpos
;
3583 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3585 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3588 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3596 /* Look forward for the first character with a `display' property
3597 that will replace the underlying text when displayed. */
3598 limpos
= make_number (lim
);
3600 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3601 CHARPOS (tpos
) = XFASTINT (pos
);
3602 if (CHARPOS (tpos
) >= lim
)
3607 if (STRINGP (object
))
3608 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3610 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3611 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3612 if (!STRINGP (object
))
3613 bufpos
= CHARPOS (tpos
);
3614 } while (NILP (spec
)
3615 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3616 bufpos
, frame_window_p
)));
3620 return CHARPOS (tpos
);
3623 /* Return the character position of the end of the display string that
3624 started at CHARPOS. If there's no display string at CHARPOS,
3625 return -1. A display string is either an overlay with `display'
3626 property whose value is a string or a `display' text property whose
3627 value is a string. */
3629 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3631 /* OBJECT = nil means current buffer. */
3632 Lisp_Object object
=
3633 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3634 Lisp_Object pos
= make_number (charpos
);
3636 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3638 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3641 /* It could happen that the display property or overlay was removed
3642 since we found it in compute_display_string_pos above. One way
3643 this can happen is if JIT font-lock was called (through
3644 handle_fontified_prop), and jit-lock-functions remove text
3645 properties or overlays from the portion of buffer that includes
3646 CHARPOS. Muse mode is known to do that, for example. In this
3647 case, we return -1 to the caller, to signal that no display
3648 string is actually present at CHARPOS. See bidi_fetch_char for
3649 how this is handled.
3651 An alternative would be to never look for display properties past
3652 it->stop_charpos. But neither compute_display_string_pos nor
3653 bidi_fetch_char that calls it know or care where the next
3655 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3658 /* Look forward for the first character where the `display' property
3660 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3662 return XFASTINT (pos
);
3667 /***********************************************************************
3669 ***********************************************************************/
3671 /* Handle changes in the `fontified' property of the current buffer by
3672 calling hook functions from Qfontification_functions to fontify
3675 static enum prop_handled
3676 handle_fontified_prop (struct it
*it
)
3678 Lisp_Object prop
, pos
;
3679 enum prop_handled handled
= HANDLED_NORMALLY
;
3681 if (!NILP (Vmemory_full
))
3684 /* Get the value of the `fontified' property at IT's current buffer
3685 position. (The `fontified' property doesn't have a special
3686 meaning in strings.) If the value is nil, call functions from
3687 Qfontification_functions. */
3688 if (!STRINGP (it
->string
)
3690 && !NILP (Vfontification_functions
)
3691 && !NILP (Vrun_hooks
)
3692 && (pos
= make_number (IT_CHARPOS (*it
)),
3693 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3694 /* Ignore the special cased nil value always present at EOB since
3695 no amount of fontifying will be able to change it. */
3696 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3698 ptrdiff_t count
= SPECPDL_INDEX ();
3700 struct buffer
*obuf
= current_buffer
;
3701 int begv
= BEGV
, zv
= ZV
;
3702 int old_clip_changed
= current_buffer
->clip_changed
;
3704 val
= Vfontification_functions
;
3705 specbind (Qfontification_functions
, Qnil
);
3707 eassert (it
->end_charpos
== ZV
);
3709 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3710 safe_call1 (val
, pos
);
3713 Lisp_Object fns
, fn
;
3714 struct gcpro gcpro1
, gcpro2
;
3719 for (; CONSP (val
); val
= XCDR (val
))
3725 /* A value of t indicates this hook has a local
3726 binding; it means to run the global binding too.
3727 In a global value, t should not occur. If it
3728 does, we must ignore it to avoid an endless
3730 for (fns
= Fdefault_value (Qfontification_functions
);
3736 safe_call1 (fn
, pos
);
3740 safe_call1 (fn
, pos
);
3746 unbind_to (count
, Qnil
);
3748 /* Fontification functions routinely call `save-restriction'.
3749 Normally, this tags clip_changed, which can confuse redisplay
3750 (see discussion in Bug#6671). Since we don't perform any
3751 special handling of fontification changes in the case where
3752 `save-restriction' isn't called, there's no point doing so in
3753 this case either. So, if the buffer's restrictions are
3754 actually left unchanged, reset clip_changed. */
3755 if (obuf
== current_buffer
)
3757 if (begv
== BEGV
&& zv
== ZV
)
3758 current_buffer
->clip_changed
= old_clip_changed
;
3760 /* There isn't much we can reasonably do to protect against
3761 misbehaving fontification, but here's a fig leaf. */
3762 else if (BUFFER_LIVE_P (obuf
))
3763 set_buffer_internal_1 (obuf
);
3765 /* The fontification code may have added/removed text.
3766 It could do even a lot worse, but let's at least protect against
3767 the most obvious case where only the text past `pos' gets changed',
3768 as is/was done in grep.el where some escapes sequences are turned
3769 into face properties (bug#7876). */
3770 it
->end_charpos
= ZV
;
3772 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3773 something. This avoids an endless loop if they failed to
3774 fontify the text for which reason ever. */
3775 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3776 handled
= HANDLED_RECOMPUTE_PROPS
;
3784 /***********************************************************************
3786 ***********************************************************************/
3788 /* Set up iterator IT from face properties at its current position.
3789 Called from handle_stop. */
3791 static enum prop_handled
3792 handle_face_prop (struct it
*it
)
3795 ptrdiff_t next_stop
;
3797 if (!STRINGP (it
->string
))
3800 = face_at_buffer_position (it
->w
,
3802 it
->region_beg_charpos
,
3803 it
->region_end_charpos
,
3806 + TEXT_PROP_DISTANCE_LIMIT
),
3807 0, it
->base_face_id
);
3809 /* Is this a start of a run of characters with box face?
3810 Caveat: this can be called for a freshly initialized
3811 iterator; face_id is -1 in this case. We know that the new
3812 face will not change until limit, i.e. if the new face has a
3813 box, all characters up to limit will have one. But, as
3814 usual, we don't know whether limit is really the end. */
3815 if (new_face_id
!= it
->face_id
)
3817 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3818 /* If it->face_id is -1, old_face below will be NULL, see
3819 the definition of FACE_FROM_ID. This will happen if this
3820 is the initial call that gets the face. */
3821 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3823 /* If the value of face_id of the iterator is -1, we have to
3824 look in front of IT's position and see whether there is a
3825 face there that's different from new_face_id. */
3826 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3828 int prev_face_id
= face_before_it_pos (it
);
3830 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3833 /* If the new face has a box, but the old face does not,
3834 this is the start of a run of characters with box face,
3835 i.e. this character has a shadow on the left side. */
3836 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3837 && (old_face
== NULL
|| !old_face
->box
));
3838 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3846 Lisp_Object from_overlay
3847 = (it
->current
.overlay_string_index
>= 0
3848 ? it
->string_overlays
[it
->current
.overlay_string_index
3849 % OVERLAY_STRING_CHUNK_SIZE
]
3852 /* See if we got to this string directly or indirectly from
3853 an overlay property. That includes the before-string or
3854 after-string of an overlay, strings in display properties
3855 provided by an overlay, their text properties, etc.
3857 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3858 if (! NILP (from_overlay
))
3859 for (i
= it
->sp
- 1; i
>= 0; i
--)
3861 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3863 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3864 % OVERLAY_STRING_CHUNK_SIZE
];
3865 else if (! NILP (it
->stack
[i
].from_overlay
))
3866 from_overlay
= it
->stack
[i
].from_overlay
;
3868 if (!NILP (from_overlay
))
3872 if (! NILP (from_overlay
))
3874 bufpos
= IT_CHARPOS (*it
);
3875 /* For a string from an overlay, the base face depends
3876 only on text properties and ignores overlays. */
3878 = face_for_overlay_string (it
->w
,
3880 it
->region_beg_charpos
,
3881 it
->region_end_charpos
,
3884 + TEXT_PROP_DISTANCE_LIMIT
),
3892 /* For strings from a `display' property, use the face at
3893 IT's current buffer position as the base face to merge
3894 with, so that overlay strings appear in the same face as
3895 surrounding text, unless they specify their own faces.
3896 For strings from wrap-prefix and line-prefix properties,
3897 use the default face, possibly remapped via
3898 Vface_remapping_alist. */
3899 base_face_id
= it
->string_from_prefix_prop_p
3900 ? (!NILP (Vface_remapping_alist
)
3901 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3903 : underlying_face_id (it
);
3906 new_face_id
= face_at_string_position (it
->w
,
3908 IT_STRING_CHARPOS (*it
),
3910 it
->region_beg_charpos
,
3911 it
->region_end_charpos
,
3915 /* Is this a start of a run of characters with box? Caveat:
3916 this can be called for a freshly allocated iterator; face_id
3917 is -1 is this case. We know that the new face will not
3918 change until the next check pos, i.e. if the new face has a
3919 box, all characters up to that position will have a
3920 box. But, as usual, we don't know whether that position
3921 is really the end. */
3922 if (new_face_id
!= it
->face_id
)
3924 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3925 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3927 /* If new face has a box but old face hasn't, this is the
3928 start of a run of characters with box, i.e. it has a
3929 shadow on the left side. */
3930 it
->start_of_box_run_p
3931 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3932 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3936 it
->face_id
= new_face_id
;
3937 return HANDLED_NORMALLY
;
3941 /* Return the ID of the face ``underlying'' IT's current position,
3942 which is in a string. If the iterator is associated with a
3943 buffer, return the face at IT's current buffer position.
3944 Otherwise, use the iterator's base_face_id. */
3947 underlying_face_id (struct it
*it
)
3949 int face_id
= it
->base_face_id
, i
;
3951 eassert (STRINGP (it
->string
));
3953 for (i
= it
->sp
- 1; i
>= 0; --i
)
3954 if (NILP (it
->stack
[i
].string
))
3955 face_id
= it
->stack
[i
].face_id
;
3961 /* Compute the face one character before or after the current position
3962 of IT, in the visual order. BEFORE_P non-zero means get the face
3963 in front (to the left in L2R paragraphs, to the right in R2L
3964 paragraphs) of IT's screen position. Value is the ID of the face. */
3967 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3970 ptrdiff_t next_check_charpos
;
3972 void *it_copy_data
= NULL
;
3974 eassert (it
->s
== NULL
);
3976 if (STRINGP (it
->string
))
3978 ptrdiff_t bufpos
, charpos
;
3981 /* No face change past the end of the string (for the case
3982 we are padding with spaces). No face change before the
3984 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3985 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3990 /* Set charpos to the position before or after IT's current
3991 position, in the logical order, which in the non-bidi
3992 case is the same as the visual order. */
3994 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3995 else if (it
->what
== IT_COMPOSITION
)
3996 /* For composition, we must check the character after the
3998 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4000 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4006 /* With bidi iteration, the character before the current
4007 in the visual order cannot be found by simple
4008 iteration, because "reverse" reordering is not
4009 supported. Instead, we need to use the move_it_*
4010 family of functions. */
4011 /* Ignore face changes before the first visible
4012 character on this display line. */
4013 if (it
->current_x
<= it
->first_visible_x
)
4015 SAVE_IT (it_copy
, *it
, it_copy_data
);
4016 /* Implementation note: Since move_it_in_display_line
4017 works in the iterator geometry, and thinks the first
4018 character is always the leftmost, even in R2L lines,
4019 we don't need to distinguish between the R2L and L2R
4021 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4022 it_copy
.current_x
- 1, MOVE_TO_X
);
4023 charpos
= IT_STRING_CHARPOS (it_copy
);
4024 RESTORE_IT (it
, it
, it_copy_data
);
4028 /* Set charpos to the string position of the character
4029 that comes after IT's current position in the visual
4031 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4035 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4037 charpos
= it_copy
.bidi_it
.charpos
;
4040 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4042 if (it
->current
.overlay_string_index
>= 0)
4043 bufpos
= IT_CHARPOS (*it
);
4047 base_face_id
= underlying_face_id (it
);
4049 /* Get the face for ASCII, or unibyte. */
4050 face_id
= face_at_string_position (it
->w
,
4054 it
->region_beg_charpos
,
4055 it
->region_end_charpos
,
4056 &next_check_charpos
,
4059 /* Correct the face for charsets different from ASCII. Do it
4060 for the multibyte case only. The face returned above is
4061 suitable for unibyte text if IT->string is unibyte. */
4062 if (STRING_MULTIBYTE (it
->string
))
4064 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4065 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4067 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4069 c
= string_char_and_length (p
, &len
);
4070 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4075 struct text_pos pos
;
4077 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4078 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4081 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4082 pos
= it
->current
.pos
;
4087 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4090 if (it
->what
== IT_COMPOSITION
)
4092 /* For composition, we must check the position after
4094 pos
.charpos
+= it
->cmp_it
.nchars
;
4095 pos
.bytepos
+= it
->len
;
4098 INC_TEXT_POS (pos
, it
->multibyte_p
);
4105 /* With bidi iteration, the character before the current
4106 in the visual order cannot be found by simple
4107 iteration, because "reverse" reordering is not
4108 supported. Instead, we need to use the move_it_*
4109 family of functions. */
4110 /* Ignore face changes before the first visible
4111 character on this display line. */
4112 if (it
->current_x
<= it
->first_visible_x
)
4114 SAVE_IT (it_copy
, *it
, it_copy_data
);
4115 /* Implementation note: Since move_it_in_display_line
4116 works in the iterator geometry, and thinks the first
4117 character is always the leftmost, even in R2L lines,
4118 we don't need to distinguish between the R2L and L2R
4120 move_it_in_display_line (&it_copy
, ZV
,
4121 it_copy
.current_x
- 1, MOVE_TO_X
);
4122 pos
= it_copy
.current
.pos
;
4123 RESTORE_IT (it
, it
, it_copy_data
);
4127 /* Set charpos to the buffer position of the character
4128 that comes after IT's current position in the visual
4130 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4134 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4137 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4140 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4142 /* Determine face for CHARSET_ASCII, or unibyte. */
4143 face_id
= face_at_buffer_position (it
->w
,
4145 it
->region_beg_charpos
,
4146 it
->region_end_charpos
,
4147 &next_check_charpos
,
4150 /* Correct the face for charsets different from ASCII. Do it
4151 for the multibyte case only. The face returned above is
4152 suitable for unibyte text if current_buffer is unibyte. */
4153 if (it
->multibyte_p
)
4155 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4156 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4157 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4166 /***********************************************************************
4168 ***********************************************************************/
4170 /* Set up iterator IT from invisible properties at its current
4171 position. Called from handle_stop. */
4173 static enum prop_handled
4174 handle_invisible_prop (struct it
*it
)
4176 enum prop_handled handled
= HANDLED_NORMALLY
;
4180 if (STRINGP (it
->string
))
4182 Lisp_Object end_charpos
, limit
, charpos
;
4184 /* Get the value of the invisible text property at the
4185 current position. Value will be nil if there is no such
4187 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4188 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4189 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4191 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4193 /* Record whether we have to display an ellipsis for the
4195 int display_ellipsis_p
= (invis_p
== 2);
4196 ptrdiff_t len
, endpos
;
4198 handled
= HANDLED_RECOMPUTE_PROPS
;
4200 /* Get the position at which the next visible text can be
4201 found in IT->string, if any. */
4202 endpos
= len
= SCHARS (it
->string
);
4203 XSETINT (limit
, len
);
4206 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4208 if (INTEGERP (end_charpos
))
4210 endpos
= XFASTINT (end_charpos
);
4211 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4212 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4214 display_ellipsis_p
= 1;
4217 while (invis_p
&& endpos
< len
);
4219 if (display_ellipsis_p
)
4224 /* Text at END_CHARPOS is visible. Move IT there. */
4225 struct text_pos old
;
4228 old
= it
->current
.string_pos
;
4229 oldpos
= CHARPOS (old
);
4232 if (it
->bidi_it
.first_elt
4233 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4234 bidi_paragraph_init (it
->paragraph_embedding
,
4236 /* Bidi-iterate out of the invisible text. */
4239 bidi_move_to_visually_next (&it
->bidi_it
);
4241 while (oldpos
<= it
->bidi_it
.charpos
4242 && it
->bidi_it
.charpos
< endpos
);
4244 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4245 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4246 if (IT_CHARPOS (*it
) >= endpos
)
4247 it
->prev_stop
= endpos
;
4251 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4252 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4257 /* The rest of the string is invisible. If this is an
4258 overlay string, proceed with the next overlay string
4259 or whatever comes and return a character from there. */
4260 if (it
->current
.overlay_string_index
>= 0
4261 && !display_ellipsis_p
)
4263 next_overlay_string (it
);
4264 /* Don't check for overlay strings when we just
4265 finished processing them. */
4266 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4270 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4271 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4278 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4279 Lisp_Object pos
, overlay
;
4281 /* First of all, is there invisible text at this position? */
4282 tem
= start_charpos
= IT_CHARPOS (*it
);
4283 pos
= make_number (tem
);
4284 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4286 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4288 /* If we are on invisible text, skip over it. */
4289 if (invis_p
&& start_charpos
< it
->end_charpos
)
4291 /* Record whether we have to display an ellipsis for the
4293 int display_ellipsis_p
= invis_p
== 2;
4295 handled
= HANDLED_RECOMPUTE_PROPS
;
4297 /* Loop skipping over invisible text. The loop is left at
4298 ZV or with IT on the first char being visible again. */
4301 /* Try to skip some invisible text. Return value is the
4302 position reached which can be equal to where we start
4303 if there is nothing invisible there. This skips both
4304 over invisible text properties and overlays with
4305 invisible property. */
4306 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4308 /* If we skipped nothing at all we weren't at invisible
4309 text in the first place. If everything to the end of
4310 the buffer was skipped, end the loop. */
4311 if (newpos
== tem
|| newpos
>= ZV
)
4315 /* We skipped some characters but not necessarily
4316 all there are. Check if we ended up on visible
4317 text. Fget_char_property returns the property of
4318 the char before the given position, i.e. if we
4319 get invis_p = 0, this means that the char at
4320 newpos is visible. */
4321 pos
= make_number (newpos
);
4322 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4323 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4326 /* If we ended up on invisible text, proceed to
4327 skip starting with next_stop. */
4331 /* If there are adjacent invisible texts, don't lose the
4332 second one's ellipsis. */
4334 display_ellipsis_p
= 1;
4338 /* The position newpos is now either ZV or on visible text. */
4341 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4343 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4345 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4347 /* If the invisible text ends on a newline or on a
4348 character after a newline, we can avoid the costly,
4349 character by character, bidi iteration to NEWPOS, and
4350 instead simply reseat the iterator there. That's
4351 because all bidi reordering information is tossed at
4352 the newline. This is a big win for modes that hide
4353 complete lines, like Outline, Org, etc. */
4354 if (on_newline
|| after_newline
)
4356 struct text_pos tpos
;
4357 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4359 SET_TEXT_POS (tpos
, newpos
, bpos
);
4360 reseat_1 (it
, tpos
, 0);
4361 /* If we reseat on a newline/ZV, we need to prep the
4362 bidi iterator for advancing to the next character
4363 after the newline/EOB, keeping the current paragraph
4364 direction (so that PRODUCE_GLYPHS does TRT wrt
4365 prepending/appending glyphs to a glyph row). */
4368 it
->bidi_it
.first_elt
= 0;
4369 it
->bidi_it
.paragraph_dir
= pdir
;
4370 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4371 it
->bidi_it
.nchars
= 1;
4372 it
->bidi_it
.ch_len
= 1;
4375 else /* Must use the slow method. */
4377 /* With bidi iteration, the region of invisible text
4378 could start and/or end in the middle of a
4379 non-base embedding level. Therefore, we need to
4380 skip invisible text using the bidi iterator,
4381 starting at IT's current position, until we find
4382 ourselves outside of the invisible text.
4383 Skipping invisible text _after_ bidi iteration
4384 avoids affecting the visual order of the
4385 displayed text when invisible properties are
4386 added or removed. */
4387 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4389 /* If we were `reseat'ed to a new paragraph,
4390 determine the paragraph base direction. We
4391 need to do it now because
4392 next_element_from_buffer may not have a
4393 chance to do it, if we are going to skip any
4394 text at the beginning, which resets the
4396 bidi_paragraph_init (it
->paragraph_embedding
,
4401 bidi_move_to_visually_next (&it
->bidi_it
);
4403 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4404 && it
->bidi_it
.charpos
< newpos
);
4405 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4406 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4407 /* If we overstepped NEWPOS, record its position in
4408 the iterator, so that we skip invisible text if
4409 later the bidi iteration lands us in the
4410 invisible region again. */
4411 if (IT_CHARPOS (*it
) >= newpos
)
4412 it
->prev_stop
= newpos
;
4417 IT_CHARPOS (*it
) = newpos
;
4418 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4421 /* If there are before-strings at the start of invisible
4422 text, and the text is invisible because of a text
4423 property, arrange to show before-strings because 20.x did
4424 it that way. (If the text is invisible because of an
4425 overlay property instead of a text property, this is
4426 already handled in the overlay code.) */
4428 && get_overlay_strings (it
, it
->stop_charpos
))
4430 handled
= HANDLED_RECOMPUTE_PROPS
;
4431 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4433 else if (display_ellipsis_p
)
4435 /* Make sure that the glyphs of the ellipsis will get
4436 correct `charpos' values. If we would not update
4437 it->position here, the glyphs would belong to the
4438 last visible character _before_ the invisible
4439 text, which confuses `set_cursor_from_row'.
4441 We use the last invisible position instead of the
4442 first because this way the cursor is always drawn on
4443 the first "." of the ellipsis, whenever PT is inside
4444 the invisible text. Otherwise the cursor would be
4445 placed _after_ the ellipsis when the point is after the
4446 first invisible character. */
4447 if (!STRINGP (it
->object
))
4449 it
->position
.charpos
= newpos
- 1;
4450 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4453 /* Let the ellipsis display before
4454 considering any properties of the following char.
4455 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4456 handled
= HANDLED_RETURN
;
4465 /* Make iterator IT return `...' next.
4466 Replaces LEN characters from buffer. */
4469 setup_for_ellipsis (struct it
*it
, int len
)
4471 /* Use the display table definition for `...'. Invalid glyphs
4472 will be handled by the method returning elements from dpvec. */
4473 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4475 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4476 it
->dpvec
= v
->u
.contents
;
4477 it
->dpend
= v
->u
.contents
+ v
->header
.size
;
4481 /* Default `...'. */
4482 it
->dpvec
= default_invis_vector
;
4483 it
->dpend
= default_invis_vector
+ 3;
4486 it
->dpvec_char_len
= len
;
4487 it
->current
.dpvec_index
= 0;
4488 it
->dpvec_face_id
= -1;
4490 /* Remember the current face id in case glyphs specify faces.
4491 IT's face is restored in set_iterator_to_next.
4492 saved_face_id was set to preceding char's face in handle_stop. */
4493 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4494 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4496 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4502 /***********************************************************************
4504 ***********************************************************************/
4506 /* Set up iterator IT from `display' property at its current position.
4507 Called from handle_stop.
4508 We return HANDLED_RETURN if some part of the display property
4509 overrides the display of the buffer text itself.
4510 Otherwise we return HANDLED_NORMALLY. */
4512 static enum prop_handled
4513 handle_display_prop (struct it
*it
)
4515 Lisp_Object propval
, object
, overlay
;
4516 struct text_pos
*position
;
4518 /* Nonzero if some property replaces the display of the text itself. */
4519 int display_replaced_p
= 0;
4521 if (STRINGP (it
->string
))
4523 object
= it
->string
;
4524 position
= &it
->current
.string_pos
;
4525 bufpos
= CHARPOS (it
->current
.pos
);
4529 XSETWINDOW (object
, it
->w
);
4530 position
= &it
->current
.pos
;
4531 bufpos
= CHARPOS (*position
);
4534 /* Reset those iterator values set from display property values. */
4535 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4536 it
->space_width
= Qnil
;
4537 it
->font_height
= Qnil
;
4540 /* We don't support recursive `display' properties, i.e. string
4541 values that have a string `display' property, that have a string
4542 `display' property etc. */
4543 if (!it
->string_from_display_prop_p
)
4544 it
->area
= TEXT_AREA
;
4546 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4547 Qdisplay
, object
, &overlay
);
4549 return HANDLED_NORMALLY
;
4550 /* Now OVERLAY is the overlay that gave us this property, or nil
4551 if it was a text property. */
4553 if (!STRINGP (it
->string
))
4554 object
= it
->w
->contents
;
4556 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4558 FRAME_WINDOW_P (it
->f
));
4560 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4563 /* Subroutine of handle_display_prop. Returns non-zero if the display
4564 specification in SPEC is a replacing specification, i.e. it would
4565 replace the text covered by `display' property with something else,
4566 such as an image or a display string. If SPEC includes any kind or
4567 `(space ...) specification, the value is 2; this is used by
4568 compute_display_string_pos, which see.
4570 See handle_single_display_spec for documentation of arguments.
4571 frame_window_p is non-zero if the window being redisplayed is on a
4572 GUI frame; this argument is used only if IT is NULL, see below.
4574 IT can be NULL, if this is called by the bidi reordering code
4575 through compute_display_string_pos, which see. In that case, this
4576 function only examines SPEC, but does not otherwise "handle" it, in
4577 the sense that it doesn't set up members of IT from the display
4580 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4581 Lisp_Object overlay
, struct text_pos
*position
,
4582 ptrdiff_t bufpos
, int frame_window_p
)
4584 int replacing_p
= 0;
4588 /* Simple specifications. */
4589 && !EQ (XCAR (spec
), Qimage
)
4590 && !EQ (XCAR (spec
), Qspace
)
4591 && !EQ (XCAR (spec
), Qwhen
)
4592 && !EQ (XCAR (spec
), Qslice
)
4593 && !EQ (XCAR (spec
), Qspace_width
)
4594 && !EQ (XCAR (spec
), Qheight
)
4595 && !EQ (XCAR (spec
), Qraise
)
4596 /* Marginal area specifications. */
4597 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4598 && !EQ (XCAR (spec
), Qleft_fringe
)
4599 && !EQ (XCAR (spec
), Qright_fringe
)
4600 && !NILP (XCAR (spec
)))
4602 for (; CONSP (spec
); spec
= XCDR (spec
))
4604 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4605 overlay
, position
, bufpos
,
4606 replacing_p
, frame_window_p
)))
4609 /* If some text in a string is replaced, `position' no
4610 longer points to the position of `object'. */
4611 if (!it
|| STRINGP (object
))
4616 else if (VECTORP (spec
))
4619 for (i
= 0; i
< ASIZE (spec
); ++i
)
4620 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4621 overlay
, position
, bufpos
,
4622 replacing_p
, frame_window_p
)))
4625 /* If some text in a string is replaced, `position' no
4626 longer points to the position of `object'. */
4627 if (!it
|| STRINGP (object
))
4633 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4634 position
, bufpos
, 0,
4642 /* Value is the position of the end of the `display' property starting
4643 at START_POS in OBJECT. */
4645 static struct text_pos
4646 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4649 struct text_pos end_pos
;
4651 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4652 Qdisplay
, object
, Qnil
);
4653 CHARPOS (end_pos
) = XFASTINT (end
);
4654 if (STRINGP (object
))
4655 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4657 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4663 /* Set up IT from a single `display' property specification SPEC. OBJECT
4664 is the object in which the `display' property was found. *POSITION
4665 is the position in OBJECT at which the `display' property was found.
4666 BUFPOS is the buffer position of OBJECT (different from POSITION if
4667 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4668 previously saw a display specification which already replaced text
4669 display with something else, for example an image; we ignore such
4670 properties after the first one has been processed.
4672 OVERLAY is the overlay this `display' property came from,
4673 or nil if it was a text property.
4675 If SPEC is a `space' or `image' specification, and in some other
4676 cases too, set *POSITION to the position where the `display'
4679 If IT is NULL, only examine the property specification in SPEC, but
4680 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4681 is intended to be displayed in a window on a GUI frame.
4683 Value is non-zero if something was found which replaces the display
4684 of buffer or string text. */
4687 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4688 Lisp_Object overlay
, struct text_pos
*position
,
4689 ptrdiff_t bufpos
, int display_replaced_p
,
4693 Lisp_Object location
, value
;
4694 struct text_pos start_pos
= *position
;
4697 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4698 If the result is non-nil, use VALUE instead of SPEC. */
4700 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4709 if (!NILP (form
) && !EQ (form
, Qt
))
4711 ptrdiff_t count
= SPECPDL_INDEX ();
4712 struct gcpro gcpro1
;
4714 /* Bind `object' to the object having the `display' property, a
4715 buffer or string. Bind `position' to the position in the
4716 object where the property was found, and `buffer-position'
4717 to the current position in the buffer. */
4720 XSETBUFFER (object
, current_buffer
);
4721 specbind (Qobject
, object
);
4722 specbind (Qposition
, make_number (CHARPOS (*position
)));
4723 specbind (Qbuffer_position
, make_number (bufpos
));
4725 form
= safe_eval (form
);
4727 unbind_to (count
, Qnil
);
4733 /* Handle `(height HEIGHT)' specifications. */
4735 && EQ (XCAR (spec
), Qheight
)
4736 && CONSP (XCDR (spec
)))
4740 if (!FRAME_WINDOW_P (it
->f
))
4743 it
->font_height
= XCAR (XCDR (spec
));
4744 if (!NILP (it
->font_height
))
4746 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4747 int new_height
= -1;
4749 if (CONSP (it
->font_height
)
4750 && (EQ (XCAR (it
->font_height
), Qplus
)
4751 || EQ (XCAR (it
->font_height
), Qminus
))
4752 && CONSP (XCDR (it
->font_height
))
4753 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4755 /* `(+ N)' or `(- N)' where N is an integer. */
4756 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4757 if (EQ (XCAR (it
->font_height
), Qplus
))
4759 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4761 else if (FUNCTIONP (it
->font_height
))
4763 /* Call function with current height as argument.
4764 Value is the new height. */
4766 height
= safe_call1 (it
->font_height
,
4767 face
->lface
[LFACE_HEIGHT_INDEX
]);
4768 if (NUMBERP (height
))
4769 new_height
= XFLOATINT (height
);
4771 else if (NUMBERP (it
->font_height
))
4773 /* Value is a multiple of the canonical char height. */
4776 f
= FACE_FROM_ID (it
->f
,
4777 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4778 new_height
= (XFLOATINT (it
->font_height
)
4779 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4783 /* Evaluate IT->font_height with `height' bound to the
4784 current specified height to get the new height. */
4785 ptrdiff_t count
= SPECPDL_INDEX ();
4787 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4788 value
= safe_eval (it
->font_height
);
4789 unbind_to (count
, Qnil
);
4791 if (NUMBERP (value
))
4792 new_height
= XFLOATINT (value
);
4796 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4803 /* Handle `(space-width WIDTH)'. */
4805 && EQ (XCAR (spec
), Qspace_width
)
4806 && CONSP (XCDR (spec
)))
4810 if (!FRAME_WINDOW_P (it
->f
))
4813 value
= XCAR (XCDR (spec
));
4814 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4815 it
->space_width
= value
;
4821 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4823 && EQ (XCAR (spec
), Qslice
))
4829 if (!FRAME_WINDOW_P (it
->f
))
4832 if (tem
= XCDR (spec
), CONSP (tem
))
4834 it
->slice
.x
= XCAR (tem
);
4835 if (tem
= XCDR (tem
), CONSP (tem
))
4837 it
->slice
.y
= XCAR (tem
);
4838 if (tem
= XCDR (tem
), CONSP (tem
))
4840 it
->slice
.width
= XCAR (tem
);
4841 if (tem
= XCDR (tem
), CONSP (tem
))
4842 it
->slice
.height
= XCAR (tem
);
4851 /* Handle `(raise FACTOR)'. */
4853 && EQ (XCAR (spec
), Qraise
)
4854 && CONSP (XCDR (spec
)))
4858 if (!FRAME_WINDOW_P (it
->f
))
4861 #ifdef HAVE_WINDOW_SYSTEM
4862 value
= XCAR (XCDR (spec
));
4863 if (NUMBERP (value
))
4865 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4866 it
->voffset
= - (XFLOATINT (value
)
4867 * (FONT_HEIGHT (face
->font
)));
4869 #endif /* HAVE_WINDOW_SYSTEM */
4875 /* Don't handle the other kinds of display specifications
4876 inside a string that we got from a `display' property. */
4877 if (it
&& it
->string_from_display_prop_p
)
4880 /* Characters having this form of property are not displayed, so
4881 we have to find the end of the property. */
4884 start_pos
= *position
;
4885 *position
= display_prop_end (it
, object
, start_pos
);
4889 /* Stop the scan at that end position--we assume that all
4890 text properties change there. */
4892 it
->stop_charpos
= position
->charpos
;
4894 /* Handle `(left-fringe BITMAP [FACE])'
4895 and `(right-fringe BITMAP [FACE])'. */
4897 && (EQ (XCAR (spec
), Qleft_fringe
)
4898 || EQ (XCAR (spec
), Qright_fringe
))
4899 && CONSP (XCDR (spec
)))
4905 if (!FRAME_WINDOW_P (it
->f
))
4906 /* If we return here, POSITION has been advanced
4907 across the text with this property. */
4909 /* Synchronize the bidi iterator with POSITION. This is
4910 needed because we are not going to push the iterator
4911 on behalf of this display property, so there will be
4912 no pop_it call to do this synchronization for us. */
4915 it
->position
= *position
;
4916 iterate_out_of_display_property (it
);
4917 *position
= it
->position
;
4922 else if (!frame_window_p
)
4925 #ifdef HAVE_WINDOW_SYSTEM
4926 value
= XCAR (XCDR (spec
));
4927 if (!SYMBOLP (value
)
4928 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4929 /* If we return here, POSITION has been advanced
4930 across the text with this property. */
4932 if (it
&& it
->bidi_p
)
4934 it
->position
= *position
;
4935 iterate_out_of_display_property (it
);
4936 *position
= it
->position
;
4943 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4945 if (CONSP (XCDR (XCDR (spec
))))
4947 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4948 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4954 /* Save current settings of IT so that we can restore them
4955 when we are finished with the glyph property value. */
4956 push_it (it
, position
);
4958 it
->area
= TEXT_AREA
;
4959 it
->what
= IT_IMAGE
;
4960 it
->image_id
= -1; /* no image */
4961 it
->position
= start_pos
;
4962 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4963 it
->method
= GET_FROM_IMAGE
;
4964 it
->from_overlay
= Qnil
;
4965 it
->face_id
= face_id
;
4966 it
->from_disp_prop_p
= 1;
4968 /* Say that we haven't consumed the characters with
4969 `display' property yet. The call to pop_it in
4970 set_iterator_to_next will clean this up. */
4971 *position
= start_pos
;
4973 if (EQ (XCAR (spec
), Qleft_fringe
))
4975 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4976 it
->left_user_fringe_face_id
= face_id
;
4980 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4981 it
->right_user_fringe_face_id
= face_id
;
4984 #endif /* HAVE_WINDOW_SYSTEM */
4988 /* Prepare to handle `((margin left-margin) ...)',
4989 `((margin right-margin) ...)' and `((margin nil) ...)'
4990 prefixes for display specifications. */
4991 location
= Qunbound
;
4992 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4996 value
= XCDR (spec
);
4998 value
= XCAR (value
);
5001 if (EQ (XCAR (tem
), Qmargin
)
5002 && (tem
= XCDR (tem
),
5003 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5005 || EQ (tem
, Qleft_margin
)
5006 || EQ (tem
, Qright_margin
))))
5010 if (EQ (location
, Qunbound
))
5016 /* After this point, VALUE is the property after any
5017 margin prefix has been stripped. It must be a string,
5018 an image specification, or `(space ...)'.
5020 LOCATION specifies where to display: `left-margin',
5021 `right-margin' or nil. */
5023 valid_p
= (STRINGP (value
)
5024 #ifdef HAVE_WINDOW_SYSTEM
5025 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5026 && valid_image_p (value
))
5027 #endif /* not HAVE_WINDOW_SYSTEM */
5028 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5030 if (valid_p
&& !display_replaced_p
)
5036 /* Callers need to know whether the display spec is any kind
5037 of `(space ...)' spec that is about to affect text-area
5039 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5044 /* Save current settings of IT so that we can restore them
5045 when we are finished with the glyph property value. */
5046 push_it (it
, position
);
5047 it
->from_overlay
= overlay
;
5048 it
->from_disp_prop_p
= 1;
5050 if (NILP (location
))
5051 it
->area
= TEXT_AREA
;
5052 else if (EQ (location
, Qleft_margin
))
5053 it
->area
= LEFT_MARGIN_AREA
;
5055 it
->area
= RIGHT_MARGIN_AREA
;
5057 if (STRINGP (value
))
5060 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5061 it
->current
.overlay_string_index
= -1;
5062 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5063 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5064 it
->method
= GET_FROM_STRING
;
5065 it
->stop_charpos
= 0;
5067 it
->base_level_stop
= 0;
5068 it
->string_from_display_prop_p
= 1;
5069 /* Say that we haven't consumed the characters with
5070 `display' property yet. The call to pop_it in
5071 set_iterator_to_next will clean this up. */
5072 if (BUFFERP (object
))
5073 *position
= start_pos
;
5075 /* Force paragraph direction to be that of the parent
5076 object. If the parent object's paragraph direction is
5077 not yet determined, default to L2R. */
5078 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5079 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5081 it
->paragraph_embedding
= L2R
;
5083 /* Set up the bidi iterator for this display string. */
5086 it
->bidi_it
.string
.lstring
= it
->string
;
5087 it
->bidi_it
.string
.s
= NULL
;
5088 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5089 it
->bidi_it
.string
.bufpos
= bufpos
;
5090 it
->bidi_it
.string
.from_disp_str
= 1;
5091 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5092 it
->bidi_it
.w
= it
->w
;
5093 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5096 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5098 it
->method
= GET_FROM_STRETCH
;
5100 *position
= it
->position
= start_pos
;
5101 retval
= 1 + (it
->area
== TEXT_AREA
);
5103 #ifdef HAVE_WINDOW_SYSTEM
5106 it
->what
= IT_IMAGE
;
5107 it
->image_id
= lookup_image (it
->f
, value
);
5108 it
->position
= start_pos
;
5109 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5110 it
->method
= GET_FROM_IMAGE
;
5112 /* Say that we haven't consumed the characters with
5113 `display' property yet. The call to pop_it in
5114 set_iterator_to_next will clean this up. */
5115 *position
= start_pos
;
5117 #endif /* HAVE_WINDOW_SYSTEM */
5122 /* Invalid property or property not supported. Restore
5123 POSITION to what it was before. */
5124 *position
= start_pos
;
5128 /* Check if PROP is a display property value whose text should be
5129 treated as intangible. OVERLAY is the overlay from which PROP
5130 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5131 specify the buffer position covered by PROP. */
5134 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5135 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5137 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5138 struct text_pos position
;
5140 SET_TEXT_POS (position
, charpos
, bytepos
);
5141 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5142 &position
, charpos
, frame_window_p
);
5146 /* Return 1 if PROP is a display sub-property value containing STRING.
5148 Implementation note: this and the following function are really
5149 special cases of handle_display_spec and
5150 handle_single_display_spec, and should ideally use the same code.
5151 Until they do, these two pairs must be consistent and must be
5152 modified in sync. */
5155 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5157 if (EQ (string
, prop
))
5160 /* Skip over `when FORM'. */
5161 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5166 /* Actually, the condition following `when' should be eval'ed,
5167 like handle_single_display_spec does, and we should return
5168 zero if it evaluates to nil. However, this function is
5169 called only when the buffer was already displayed and some
5170 glyph in the glyph matrix was found to come from a display
5171 string. Therefore, the condition was already evaluated, and
5172 the result was non-nil, otherwise the display string wouldn't
5173 have been displayed and we would have never been called for
5174 this property. Thus, we can skip the evaluation and assume
5175 its result is non-nil. */
5180 /* Skip over `margin LOCATION'. */
5181 if (EQ (XCAR (prop
), Qmargin
))
5192 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5196 /* Return 1 if STRING appears in the `display' property PROP. */
5199 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5202 && !EQ (XCAR (prop
), Qwhen
)
5203 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5205 /* A list of sub-properties. */
5206 while (CONSP (prop
))
5208 if (single_display_spec_string_p (XCAR (prop
), string
))
5213 else if (VECTORP (prop
))
5215 /* A vector of sub-properties. */
5217 for (i
= 0; i
< ASIZE (prop
); ++i
)
5218 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5222 return single_display_spec_string_p (prop
, string
);
5227 /* Look for STRING in overlays and text properties in the current
5228 buffer, between character positions FROM and TO (excluding TO).
5229 BACK_P non-zero means look back (in this case, TO is supposed to be
5231 Value is the first character position where STRING was found, or
5232 zero if it wasn't found before hitting TO.
5234 This function may only use code that doesn't eval because it is
5235 called asynchronously from note_mouse_highlight. */
5238 string_buffer_position_lim (Lisp_Object string
,
5239 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5241 Lisp_Object limit
, prop
, pos
;
5244 pos
= make_number (max (from
, BEGV
));
5246 if (!back_p
) /* looking forward */
5248 limit
= make_number (min (to
, ZV
));
5249 while (!found
&& !EQ (pos
, limit
))
5251 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5252 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5255 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5259 else /* looking back */
5261 limit
= make_number (max (to
, BEGV
));
5262 while (!found
&& !EQ (pos
, limit
))
5264 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5265 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5268 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5273 return found
? XINT (pos
) : 0;
5276 /* Determine which buffer position in current buffer STRING comes from.
5277 AROUND_CHARPOS is an approximate position where it could come from.
5278 Value is the buffer position or 0 if it couldn't be determined.
5280 This function is necessary because we don't record buffer positions
5281 in glyphs generated from strings (to keep struct glyph small).
5282 This function may only use code that doesn't eval because it is
5283 called asynchronously from note_mouse_highlight. */
5286 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5288 const int MAX_DISTANCE
= 1000;
5289 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5290 around_charpos
+ MAX_DISTANCE
,
5294 found
= string_buffer_position_lim (string
, around_charpos
,
5295 around_charpos
- MAX_DISTANCE
, 1);
5301 /***********************************************************************
5302 `composition' property
5303 ***********************************************************************/
5305 /* Set up iterator IT from `composition' property at its current
5306 position. Called from handle_stop. */
5308 static enum prop_handled
5309 handle_composition_prop (struct it
*it
)
5311 Lisp_Object prop
, string
;
5312 ptrdiff_t pos
, pos_byte
, start
, end
;
5314 if (STRINGP (it
->string
))
5318 pos
= IT_STRING_CHARPOS (*it
);
5319 pos_byte
= IT_STRING_BYTEPOS (*it
);
5320 string
= it
->string
;
5321 s
= SDATA (string
) + pos_byte
;
5322 it
->c
= STRING_CHAR (s
);
5326 pos
= IT_CHARPOS (*it
);
5327 pos_byte
= IT_BYTEPOS (*it
);
5329 it
->c
= FETCH_CHAR (pos_byte
);
5332 /* If there's a valid composition and point is not inside of the
5333 composition (in the case that the composition is from the current
5334 buffer), draw a glyph composed from the composition components. */
5335 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5336 && composition_valid_p (start
, end
, prop
)
5337 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5340 /* As we can't handle this situation (perhaps font-lock added
5341 a new composition), we just return here hoping that next
5342 redisplay will detect this composition much earlier. */
5343 return HANDLED_NORMALLY
;
5346 if (STRINGP (it
->string
))
5347 pos_byte
= string_char_to_byte (it
->string
, start
);
5349 pos_byte
= CHAR_TO_BYTE (start
);
5351 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5354 if (it
->cmp_it
.id
>= 0)
5357 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5358 it
->cmp_it
.nglyphs
= -1;
5362 return HANDLED_NORMALLY
;
5367 /***********************************************************************
5369 ***********************************************************************/
5371 /* The following structure is used to record overlay strings for
5372 later sorting in load_overlay_strings. */
5374 struct overlay_entry
5376 Lisp_Object overlay
;
5383 /* Set up iterator IT from overlay strings at its current position.
5384 Called from handle_stop. */
5386 static enum prop_handled
5387 handle_overlay_change (struct it
*it
)
5389 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5390 return HANDLED_RECOMPUTE_PROPS
;
5392 return HANDLED_NORMALLY
;
5396 /* Set up the next overlay string for delivery by IT, if there is an
5397 overlay string to deliver. Called by set_iterator_to_next when the
5398 end of the current overlay string is reached. If there are more
5399 overlay strings to display, IT->string and
5400 IT->current.overlay_string_index are set appropriately here.
5401 Otherwise IT->string is set to nil. */
5404 next_overlay_string (struct it
*it
)
5406 ++it
->current
.overlay_string_index
;
5407 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5409 /* No more overlay strings. Restore IT's settings to what
5410 they were before overlay strings were processed, and
5411 continue to deliver from current_buffer. */
5413 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5416 || (NILP (it
->string
)
5417 && it
->method
== GET_FROM_BUFFER
5418 && it
->stop_charpos
>= BEGV
5419 && it
->stop_charpos
<= it
->end_charpos
));
5420 it
->current
.overlay_string_index
= -1;
5421 it
->n_overlay_strings
= 0;
5422 it
->overlay_strings_charpos
= -1;
5423 /* If there's an empty display string on the stack, pop the
5424 stack, to resync the bidi iterator with IT's position. Such
5425 empty strings are pushed onto the stack in
5426 get_overlay_strings_1. */
5427 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5430 /* If we're at the end of the buffer, record that we have
5431 processed the overlay strings there already, so that
5432 next_element_from_buffer doesn't try it again. */
5433 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5434 it
->overlay_strings_at_end_processed_p
= 1;
5438 /* There are more overlay strings to process. If
5439 IT->current.overlay_string_index has advanced to a position
5440 where we must load IT->overlay_strings with more strings, do
5441 it. We must load at the IT->overlay_strings_charpos where
5442 IT->n_overlay_strings was originally computed; when invisible
5443 text is present, this might not be IT_CHARPOS (Bug#7016). */
5444 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5446 if (it
->current
.overlay_string_index
&& i
== 0)
5447 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5449 /* Initialize IT to deliver display elements from the overlay
5451 it
->string
= it
->overlay_strings
[i
];
5452 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5453 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5454 it
->method
= GET_FROM_STRING
;
5455 it
->stop_charpos
= 0;
5456 it
->end_charpos
= SCHARS (it
->string
);
5457 if (it
->cmp_it
.stop_pos
>= 0)
5458 it
->cmp_it
.stop_pos
= 0;
5460 it
->base_level_stop
= 0;
5462 /* Set up the bidi iterator for this overlay string. */
5465 it
->bidi_it
.string
.lstring
= it
->string
;
5466 it
->bidi_it
.string
.s
= NULL
;
5467 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5468 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5469 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5470 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5471 it
->bidi_it
.w
= it
->w
;
5472 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5480 /* Compare two overlay_entry structures E1 and E2. Used as a
5481 comparison function for qsort in load_overlay_strings. Overlay
5482 strings for the same position are sorted so that
5484 1. All after-strings come in front of before-strings, except
5485 when they come from the same overlay.
5487 2. Within after-strings, strings are sorted so that overlay strings
5488 from overlays with higher priorities come first.
5490 2. Within before-strings, strings are sorted so that overlay
5491 strings from overlays with higher priorities come last.
5493 Value is analogous to strcmp. */
5497 compare_overlay_entries (const void *e1
, const void *e2
)
5499 struct overlay_entry
const *entry1
= e1
;
5500 struct overlay_entry
const *entry2
= e2
;
5503 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5505 /* Let after-strings appear in front of before-strings if
5506 they come from different overlays. */
5507 if (EQ (entry1
->overlay
, entry2
->overlay
))
5508 result
= entry1
->after_string_p
? 1 : -1;
5510 result
= entry1
->after_string_p
? -1 : 1;
5512 else if (entry1
->priority
!= entry2
->priority
)
5514 if (entry1
->after_string_p
)
5515 /* After-strings sorted in order of decreasing priority. */
5516 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5518 /* Before-strings sorted in order of increasing priority. */
5519 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5528 /* Load the vector IT->overlay_strings with overlay strings from IT's
5529 current buffer position, or from CHARPOS if that is > 0. Set
5530 IT->n_overlays to the total number of overlay strings found.
5532 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5533 a time. On entry into load_overlay_strings,
5534 IT->current.overlay_string_index gives the number of overlay
5535 strings that have already been loaded by previous calls to this
5538 IT->add_overlay_start contains an additional overlay start
5539 position to consider for taking overlay strings from, if non-zero.
5540 This position comes into play when the overlay has an `invisible'
5541 property, and both before and after-strings. When we've skipped to
5542 the end of the overlay, because of its `invisible' property, we
5543 nevertheless want its before-string to appear.
5544 IT->add_overlay_start will contain the overlay start position
5547 Overlay strings are sorted so that after-string strings come in
5548 front of before-string strings. Within before and after-strings,
5549 strings are sorted by overlay priority. See also function
5550 compare_overlay_entries. */
5553 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5555 Lisp_Object overlay
, window
, str
, invisible
;
5556 struct Lisp_Overlay
*ov
;
5557 ptrdiff_t start
, end
;
5558 ptrdiff_t size
= 20;
5559 ptrdiff_t n
= 0, i
, j
;
5561 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5565 charpos
= IT_CHARPOS (*it
);
5567 /* Append the overlay string STRING of overlay OVERLAY to vector
5568 `entries' which has size `size' and currently contains `n'
5569 elements. AFTER_P non-zero means STRING is an after-string of
5571 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5574 Lisp_Object priority; \
5578 struct overlay_entry *old = entries; \
5579 SAFE_NALLOCA (entries, 2, size); \
5580 memcpy (entries, old, size * sizeof *entries); \
5584 entries[n].string = (STRING); \
5585 entries[n].overlay = (OVERLAY); \
5586 priority = Foverlay_get ((OVERLAY), Qpriority); \
5587 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5588 entries[n].after_string_p = (AFTER_P); \
5593 /* Process overlay before the overlay center. */
5594 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5596 XSETMISC (overlay
, ov
);
5597 eassert (OVERLAYP (overlay
));
5598 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5599 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5604 /* Skip this overlay if it doesn't start or end at IT's current
5606 if (end
!= charpos
&& start
!= charpos
)
5609 /* Skip this overlay if it doesn't apply to IT->w. */
5610 window
= Foverlay_get (overlay
, Qwindow
);
5611 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5614 /* If the text ``under'' the overlay is invisible, both before-
5615 and after-strings from this overlay are visible; start and
5616 end position are indistinguishable. */
5617 invisible
= Foverlay_get (overlay
, Qinvisible
);
5618 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5620 /* If overlay has a non-empty before-string, record it. */
5621 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5622 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5624 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5626 /* If overlay has a non-empty after-string, record it. */
5627 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5628 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5630 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5633 /* Process overlays after the overlay center. */
5634 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5636 XSETMISC (overlay
, ov
);
5637 eassert (OVERLAYP (overlay
));
5638 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5639 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5641 if (start
> charpos
)
5644 /* Skip this overlay if it doesn't start or end at IT's current
5646 if (end
!= charpos
&& start
!= charpos
)
5649 /* Skip this overlay if it doesn't apply to IT->w. */
5650 window
= Foverlay_get (overlay
, Qwindow
);
5651 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5654 /* If the text ``under'' the overlay is invisible, it has a zero
5655 dimension, and both before- and after-strings apply. */
5656 invisible
= Foverlay_get (overlay
, Qinvisible
);
5657 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5659 /* If overlay has a non-empty before-string, record it. */
5660 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5661 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5663 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5665 /* If overlay has a non-empty after-string, record it. */
5666 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5667 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5669 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5672 #undef RECORD_OVERLAY_STRING
5676 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5678 /* Record number of overlay strings, and where we computed it. */
5679 it
->n_overlay_strings
= n
;
5680 it
->overlay_strings_charpos
= charpos
;
5682 /* IT->current.overlay_string_index is the number of overlay strings
5683 that have already been consumed by IT. Copy some of the
5684 remaining overlay strings to IT->overlay_strings. */
5686 j
= it
->current
.overlay_string_index
;
5687 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5689 it
->overlay_strings
[i
] = entries
[j
].string
;
5690 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5698 /* Get the first chunk of overlay strings at IT's current buffer
5699 position, or at CHARPOS if that is > 0. Value is non-zero if at
5700 least one overlay string was found. */
5703 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5705 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5706 process. This fills IT->overlay_strings with strings, and sets
5707 IT->n_overlay_strings to the total number of strings to process.
5708 IT->pos.overlay_string_index has to be set temporarily to zero
5709 because load_overlay_strings needs this; it must be set to -1
5710 when no overlay strings are found because a zero value would
5711 indicate a position in the first overlay string. */
5712 it
->current
.overlay_string_index
= 0;
5713 load_overlay_strings (it
, charpos
);
5715 /* If we found overlay strings, set up IT to deliver display
5716 elements from the first one. Otherwise set up IT to deliver
5717 from current_buffer. */
5718 if (it
->n_overlay_strings
)
5720 /* Make sure we know settings in current_buffer, so that we can
5721 restore meaningful values when we're done with the overlay
5724 compute_stop_pos (it
);
5725 eassert (it
->face_id
>= 0);
5727 /* Save IT's settings. They are restored after all overlay
5728 strings have been processed. */
5729 eassert (!compute_stop_p
|| it
->sp
== 0);
5731 /* When called from handle_stop, there might be an empty display
5732 string loaded. In that case, don't bother saving it. But
5733 don't use this optimization with the bidi iterator, since we
5734 need the corresponding pop_it call to resync the bidi
5735 iterator's position with IT's position, after we are done
5736 with the overlay strings. (The corresponding call to pop_it
5737 in case of an empty display string is in
5738 next_overlay_string.) */
5740 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5743 /* Set up IT to deliver display elements from the first overlay
5745 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5746 it
->string
= it
->overlay_strings
[0];
5747 it
->from_overlay
= Qnil
;
5748 it
->stop_charpos
= 0;
5749 eassert (STRINGP (it
->string
));
5750 it
->end_charpos
= SCHARS (it
->string
);
5752 it
->base_level_stop
= 0;
5753 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5754 it
->method
= GET_FROM_STRING
;
5755 it
->from_disp_prop_p
= 0;
5757 /* Force paragraph direction to be that of the parent
5759 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5760 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5762 it
->paragraph_embedding
= L2R
;
5764 /* Set up the bidi iterator for this overlay string. */
5767 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5769 it
->bidi_it
.string
.lstring
= it
->string
;
5770 it
->bidi_it
.string
.s
= NULL
;
5771 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5772 it
->bidi_it
.string
.bufpos
= pos
;
5773 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5774 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5775 it
->bidi_it
.w
= it
->w
;
5776 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5781 it
->current
.overlay_string_index
= -1;
5786 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5789 it
->method
= GET_FROM_BUFFER
;
5791 (void) get_overlay_strings_1 (it
, charpos
, 1);
5795 /* Value is non-zero if we found at least one overlay string. */
5796 return STRINGP (it
->string
);
5801 /***********************************************************************
5802 Saving and restoring state
5803 ***********************************************************************/
5805 /* Save current settings of IT on IT->stack. Called, for example,
5806 before setting up IT for an overlay string, to be able to restore
5807 IT's settings to what they were after the overlay string has been
5808 processed. If POSITION is non-NULL, it is the position to save on
5809 the stack instead of IT->position. */
5812 push_it (struct it
*it
, struct text_pos
*position
)
5814 struct iterator_stack_entry
*p
;
5816 eassert (it
->sp
< IT_STACK_SIZE
);
5817 p
= it
->stack
+ it
->sp
;
5819 p
->stop_charpos
= it
->stop_charpos
;
5820 p
->prev_stop
= it
->prev_stop
;
5821 p
->base_level_stop
= it
->base_level_stop
;
5822 p
->cmp_it
= it
->cmp_it
;
5823 eassert (it
->face_id
>= 0);
5824 p
->face_id
= it
->face_id
;
5825 p
->string
= it
->string
;
5826 p
->method
= it
->method
;
5827 p
->from_overlay
= it
->from_overlay
;
5830 case GET_FROM_IMAGE
:
5831 p
->u
.image
.object
= it
->object
;
5832 p
->u
.image
.image_id
= it
->image_id
;
5833 p
->u
.image
.slice
= it
->slice
;
5835 case GET_FROM_STRETCH
:
5836 p
->u
.stretch
.object
= it
->object
;
5839 p
->position
= position
? *position
: it
->position
;
5840 p
->current
= it
->current
;
5841 p
->end_charpos
= it
->end_charpos
;
5842 p
->string_nchars
= it
->string_nchars
;
5844 p
->multibyte_p
= it
->multibyte_p
;
5845 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5846 p
->space_width
= it
->space_width
;
5847 p
->font_height
= it
->font_height
;
5848 p
->voffset
= it
->voffset
;
5849 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5850 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5851 p
->display_ellipsis_p
= 0;
5852 p
->line_wrap
= it
->line_wrap
;
5853 p
->bidi_p
= it
->bidi_p
;
5854 p
->paragraph_embedding
= it
->paragraph_embedding
;
5855 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5858 /* Save the state of the bidi iterator as well. */
5860 bidi_push_it (&it
->bidi_it
);
5864 iterate_out_of_display_property (struct it
*it
)
5866 int buffer_p
= !STRINGP (it
->string
);
5867 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5868 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5870 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5872 /* Maybe initialize paragraph direction. If we are at the beginning
5873 of a new paragraph, next_element_from_buffer may not have a
5874 chance to do that. */
5875 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5876 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5877 /* prev_stop can be zero, so check against BEGV as well. */
5878 while (it
->bidi_it
.charpos
>= bob
5879 && it
->prev_stop
<= it
->bidi_it
.charpos
5880 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5881 && it
->bidi_it
.charpos
< eob
)
5882 bidi_move_to_visually_next (&it
->bidi_it
);
5883 /* Record the stop_pos we just crossed, for when we cross it
5885 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5886 it
->prev_stop
= CHARPOS (it
->position
);
5887 /* If we ended up not where pop_it put us, resync IT's
5888 positional members with the bidi iterator. */
5889 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5890 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5892 it
->current
.pos
= it
->position
;
5894 it
->current
.string_pos
= it
->position
;
5897 /* Restore IT's settings from IT->stack. Called, for example, when no
5898 more overlay strings must be processed, and we return to delivering
5899 display elements from a buffer, or when the end of a string from a
5900 `display' property is reached and we return to delivering display
5901 elements from an overlay string, or from a buffer. */
5904 pop_it (struct it
*it
)
5906 struct iterator_stack_entry
*p
;
5907 int from_display_prop
= it
->from_disp_prop_p
;
5909 eassert (it
->sp
> 0);
5911 p
= it
->stack
+ it
->sp
;
5912 it
->stop_charpos
= p
->stop_charpos
;
5913 it
->prev_stop
= p
->prev_stop
;
5914 it
->base_level_stop
= p
->base_level_stop
;
5915 it
->cmp_it
= p
->cmp_it
;
5916 it
->face_id
= p
->face_id
;
5917 it
->current
= p
->current
;
5918 it
->position
= p
->position
;
5919 it
->string
= p
->string
;
5920 it
->from_overlay
= p
->from_overlay
;
5921 if (NILP (it
->string
))
5922 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5923 it
->method
= p
->method
;
5926 case GET_FROM_IMAGE
:
5927 it
->image_id
= p
->u
.image
.image_id
;
5928 it
->object
= p
->u
.image
.object
;
5929 it
->slice
= p
->u
.image
.slice
;
5931 case GET_FROM_STRETCH
:
5932 it
->object
= p
->u
.stretch
.object
;
5934 case GET_FROM_BUFFER
:
5935 it
->object
= it
->w
->contents
;
5937 case GET_FROM_STRING
:
5938 it
->object
= it
->string
;
5940 case GET_FROM_DISPLAY_VECTOR
:
5942 it
->method
= GET_FROM_C_STRING
;
5943 else if (STRINGP (it
->string
))
5944 it
->method
= GET_FROM_STRING
;
5947 it
->method
= GET_FROM_BUFFER
;
5948 it
->object
= it
->w
->contents
;
5951 it
->end_charpos
= p
->end_charpos
;
5952 it
->string_nchars
= p
->string_nchars
;
5954 it
->multibyte_p
= p
->multibyte_p
;
5955 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5956 it
->space_width
= p
->space_width
;
5957 it
->font_height
= p
->font_height
;
5958 it
->voffset
= p
->voffset
;
5959 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5960 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5961 it
->line_wrap
= p
->line_wrap
;
5962 it
->bidi_p
= p
->bidi_p
;
5963 it
->paragraph_embedding
= p
->paragraph_embedding
;
5964 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5967 bidi_pop_it (&it
->bidi_it
);
5968 /* Bidi-iterate until we get out of the portion of text, if any,
5969 covered by a `display' text property or by an overlay with
5970 `display' property. (We cannot just jump there, because the
5971 internal coherency of the bidi iterator state can not be
5972 preserved across such jumps.) We also must determine the
5973 paragraph base direction if the overlay we just processed is
5974 at the beginning of a new paragraph. */
5975 if (from_display_prop
5976 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5977 iterate_out_of_display_property (it
);
5979 eassert ((BUFFERP (it
->object
)
5980 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5981 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5982 || (STRINGP (it
->object
)
5983 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5984 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5985 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5991 /***********************************************************************
5993 ***********************************************************************/
5995 /* Set IT's current position to the previous line start. */
5998 back_to_previous_line_start (struct it
*it
)
6000 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6003 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6007 /* Move IT to the next line start.
6009 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6010 we skipped over part of the text (as opposed to moving the iterator
6011 continuously over the text). Otherwise, don't change the value
6014 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6015 iterator on the newline, if it was found.
6017 Newlines may come from buffer text, overlay strings, or strings
6018 displayed via the `display' property. That's the reason we can't
6019 simply use find_newline_no_quit.
6021 Note that this function may not skip over invisible text that is so
6022 because of text properties and immediately follows a newline. If
6023 it would, function reseat_at_next_visible_line_start, when called
6024 from set_iterator_to_next, would effectively make invisible
6025 characters following a newline part of the wrong glyph row, which
6026 leads to wrong cursor motion. */
6029 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6030 struct bidi_it
*bidi_it_prev
)
6032 ptrdiff_t old_selective
;
6033 int newline_found_p
, n
;
6034 const int MAX_NEWLINE_DISTANCE
= 500;
6036 /* If already on a newline, just consume it to avoid unintended
6037 skipping over invisible text below. */
6038 if (it
->what
== IT_CHARACTER
6040 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6042 if (it
->bidi_p
&& bidi_it_prev
)
6043 *bidi_it_prev
= it
->bidi_it
;
6044 set_iterator_to_next (it
, 0);
6049 /* Don't handle selective display in the following. It's (a)
6050 unnecessary because it's done by the caller, and (b) leads to an
6051 infinite recursion because next_element_from_ellipsis indirectly
6052 calls this function. */
6053 old_selective
= it
->selective
;
6056 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6057 from buffer text. */
6058 for (n
= newline_found_p
= 0;
6059 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6060 n
+= STRINGP (it
->string
) ? 0 : 1)
6062 if (!get_next_display_element (it
))
6064 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6065 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6066 *bidi_it_prev
= it
->bidi_it
;
6067 set_iterator_to_next (it
, 0);
6070 /* If we didn't find a newline near enough, see if we can use a
6072 if (!newline_found_p
)
6074 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6075 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6079 eassert (!STRINGP (it
->string
));
6081 /* If there isn't any `display' property in sight, and no
6082 overlays, we can just use the position of the newline in
6084 if (it
->stop_charpos
>= limit
6085 || ((pos
= Fnext_single_property_change (make_number (start
),
6087 make_number (limit
)),
6089 && next_overlay_change (start
) == ZV
))
6093 IT_CHARPOS (*it
) = limit
;
6094 IT_BYTEPOS (*it
) = bytepos
;
6098 struct bidi_it bprev
;
6100 /* Help bidi.c avoid expensive searches for display
6101 properties and overlays, by telling it that there are
6102 none up to `limit'. */
6103 if (it
->bidi_it
.disp_pos
< limit
)
6105 it
->bidi_it
.disp_pos
= limit
;
6106 it
->bidi_it
.disp_prop
= 0;
6109 bprev
= it
->bidi_it
;
6110 bidi_move_to_visually_next (&it
->bidi_it
);
6111 } while (it
->bidi_it
.charpos
!= limit
);
6112 IT_CHARPOS (*it
) = limit
;
6113 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6115 *bidi_it_prev
= bprev
;
6117 *skipped_p
= newline_found_p
= 1;
6121 while (get_next_display_element (it
)
6122 && !newline_found_p
)
6124 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6125 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6126 *bidi_it_prev
= it
->bidi_it
;
6127 set_iterator_to_next (it
, 0);
6132 it
->selective
= old_selective
;
6133 return newline_found_p
;
6137 /* Set IT's current position to the previous visible line start. Skip
6138 invisible text that is so either due to text properties or due to
6139 selective display. Caution: this does not change IT->current_x and
6143 back_to_previous_visible_line_start (struct it
*it
)
6145 while (IT_CHARPOS (*it
) > BEGV
)
6147 back_to_previous_line_start (it
);
6149 if (IT_CHARPOS (*it
) <= BEGV
)
6152 /* If selective > 0, then lines indented more than its value are
6154 if (it
->selective
> 0
6155 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6159 /* Check the newline before point for invisibility. */
6162 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6163 Qinvisible
, it
->window
);
6164 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6168 if (IT_CHARPOS (*it
) <= BEGV
)
6173 void *it2data
= NULL
;
6176 Lisp_Object val
, overlay
;
6178 SAVE_IT (it2
, *it
, it2data
);
6180 /* If newline is part of a composition, continue from start of composition */
6181 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6182 && beg
< IT_CHARPOS (*it
))
6185 /* If newline is replaced by a display property, find start of overlay
6186 or interval and continue search from that point. */
6187 pos
= --IT_CHARPOS (it2
);
6190 bidi_unshelve_cache (NULL
, 0);
6191 it2
.string_from_display_prop_p
= 0;
6192 it2
.from_disp_prop_p
= 0;
6193 if (handle_display_prop (&it2
) == HANDLED_RETURN
6194 && !NILP (val
= get_char_property_and_overlay
6195 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6196 && (OVERLAYP (overlay
)
6197 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6198 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6200 RESTORE_IT (it
, it
, it2data
);
6204 /* Newline is not replaced by anything -- so we are done. */
6205 RESTORE_IT (it
, it
, it2data
);
6211 IT_CHARPOS (*it
) = beg
;
6212 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6216 it
->continuation_lines_width
= 0;
6218 eassert (IT_CHARPOS (*it
) >= BEGV
);
6219 eassert (IT_CHARPOS (*it
) == BEGV
6220 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6225 /* Reseat iterator IT at the previous visible line start. Skip
6226 invisible text that is so either due to text properties or due to
6227 selective display. At the end, update IT's overlay information,
6228 face information etc. */
6231 reseat_at_previous_visible_line_start (struct it
*it
)
6233 back_to_previous_visible_line_start (it
);
6234 reseat (it
, it
->current
.pos
, 1);
6239 /* Reseat iterator IT on the next visible line start in the current
6240 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6241 preceding the line start. Skip over invisible text that is so
6242 because of selective display. Compute faces, overlays etc at the
6243 new position. Note that this function does not skip over text that
6244 is invisible because of text properties. */
6247 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6249 int newline_found_p
, skipped_p
= 0;
6250 struct bidi_it bidi_it_prev
;
6252 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6254 /* Skip over lines that are invisible because they are indented
6255 more than the value of IT->selective. */
6256 if (it
->selective
> 0)
6257 while (IT_CHARPOS (*it
) < ZV
6258 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6261 eassert (IT_BYTEPOS (*it
) == BEGV
6262 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6264 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6267 /* Position on the newline if that's what's requested. */
6268 if (on_newline_p
&& newline_found_p
)
6270 if (STRINGP (it
->string
))
6272 if (IT_STRING_CHARPOS (*it
) > 0)
6276 --IT_STRING_CHARPOS (*it
);
6277 --IT_STRING_BYTEPOS (*it
);
6281 /* We need to restore the bidi iterator to the state
6282 it had on the newline, and resync the IT's
6283 position with that. */
6284 it
->bidi_it
= bidi_it_prev
;
6285 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6286 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6290 else if (IT_CHARPOS (*it
) > BEGV
)
6299 /* We need to restore the bidi iterator to the state it
6300 had on the newline and resync IT with that. */
6301 it
->bidi_it
= bidi_it_prev
;
6302 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6303 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6305 reseat (it
, it
->current
.pos
, 0);
6309 reseat (it
, it
->current
.pos
, 0);
6316 /***********************************************************************
6317 Changing an iterator's position
6318 ***********************************************************************/
6320 /* Change IT's current position to POS in current_buffer. If FORCE_P
6321 is non-zero, always check for text properties at the new position.
6322 Otherwise, text properties are only looked up if POS >=
6323 IT->check_charpos of a property. */
6326 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6328 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6330 reseat_1 (it
, pos
, 0);
6332 /* Determine where to check text properties. Avoid doing it
6333 where possible because text property lookup is very expensive. */
6335 || CHARPOS (pos
) > it
->stop_charpos
6336 || CHARPOS (pos
) < original_pos
)
6340 /* For bidi iteration, we need to prime prev_stop and
6341 base_level_stop with our best estimations. */
6342 /* Implementation note: Of course, POS is not necessarily a
6343 stop position, so assigning prev_pos to it is a lie; we
6344 should have called compute_stop_backwards. However, if
6345 the current buffer does not include any R2L characters,
6346 that call would be a waste of cycles, because the
6347 iterator will never move back, and thus never cross this
6348 "fake" stop position. So we delay that backward search
6349 until the time we really need it, in next_element_from_buffer. */
6350 if (CHARPOS (pos
) != it
->prev_stop
)
6351 it
->prev_stop
= CHARPOS (pos
);
6352 if (CHARPOS (pos
) < it
->base_level_stop
)
6353 it
->base_level_stop
= 0; /* meaning it's unknown */
6359 it
->prev_stop
= it
->base_level_stop
= 0;
6368 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6369 IT->stop_pos to POS, also. */
6372 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6374 /* Don't call this function when scanning a C string. */
6375 eassert (it
->s
== NULL
);
6377 /* POS must be a reasonable value. */
6378 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6380 it
->current
.pos
= it
->position
= pos
;
6381 it
->end_charpos
= ZV
;
6383 it
->current
.dpvec_index
= -1;
6384 it
->current
.overlay_string_index
= -1;
6385 IT_STRING_CHARPOS (*it
) = -1;
6386 IT_STRING_BYTEPOS (*it
) = -1;
6388 it
->method
= GET_FROM_BUFFER
;
6389 it
->object
= it
->w
->contents
;
6390 it
->area
= TEXT_AREA
;
6391 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6393 it
->string_from_display_prop_p
= 0;
6394 it
->string_from_prefix_prop_p
= 0;
6396 it
->from_disp_prop_p
= 0;
6397 it
->face_before_selective_p
= 0;
6400 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6402 bidi_unshelve_cache (NULL
, 0);
6403 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6404 it
->bidi_it
.string
.s
= NULL
;
6405 it
->bidi_it
.string
.lstring
= Qnil
;
6406 it
->bidi_it
.string
.bufpos
= 0;
6407 it
->bidi_it
.string
.unibyte
= 0;
6408 it
->bidi_it
.w
= it
->w
;
6413 it
->stop_charpos
= CHARPOS (pos
);
6414 it
->base_level_stop
= CHARPOS (pos
);
6416 /* This make the information stored in it->cmp_it invalidate. */
6421 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6422 If S is non-null, it is a C string to iterate over. Otherwise,
6423 STRING gives a Lisp string to iterate over.
6425 If PRECISION > 0, don't return more then PRECISION number of
6426 characters from the string.
6428 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6429 characters have been returned. FIELD_WIDTH < 0 means an infinite
6432 MULTIBYTE = 0 means disable processing of multibyte characters,
6433 MULTIBYTE > 0 means enable it,
6434 MULTIBYTE < 0 means use IT->multibyte_p.
6436 IT must be initialized via a prior call to init_iterator before
6437 calling this function. */
6440 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6441 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6444 /* No region in strings. */
6445 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6447 /* No text property checks performed by default, but see below. */
6448 it
->stop_charpos
= -1;
6450 /* Set iterator position and end position. */
6451 memset (&it
->current
, 0, sizeof it
->current
);
6452 it
->current
.overlay_string_index
= -1;
6453 it
->current
.dpvec_index
= -1;
6454 eassert (charpos
>= 0);
6456 /* If STRING is specified, use its multibyteness, otherwise use the
6457 setting of MULTIBYTE, if specified. */
6459 it
->multibyte_p
= multibyte
> 0;
6461 /* Bidirectional reordering of strings is controlled by the default
6462 value of bidi-display-reordering. Don't try to reorder while
6463 loading loadup.el, as the necessary character property tables are
6464 not yet available. */
6467 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6471 eassert (STRINGP (string
));
6472 it
->string
= string
;
6474 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6475 it
->method
= GET_FROM_STRING
;
6476 it
->current
.string_pos
= string_pos (charpos
, string
);
6480 it
->bidi_it
.string
.lstring
= string
;
6481 it
->bidi_it
.string
.s
= NULL
;
6482 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6483 it
->bidi_it
.string
.bufpos
= 0;
6484 it
->bidi_it
.string
.from_disp_str
= 0;
6485 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6486 it
->bidi_it
.w
= it
->w
;
6487 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6488 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6493 it
->s
= (const unsigned char *) s
;
6496 /* Note that we use IT->current.pos, not it->current.string_pos,
6497 for displaying C strings. */
6498 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6499 if (it
->multibyte_p
)
6501 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6502 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6506 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6507 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6512 it
->bidi_it
.string
.lstring
= Qnil
;
6513 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6514 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6515 it
->bidi_it
.string
.bufpos
= 0;
6516 it
->bidi_it
.string
.from_disp_str
= 0;
6517 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6518 it
->bidi_it
.w
= it
->w
;
6519 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6522 it
->method
= GET_FROM_C_STRING
;
6525 /* PRECISION > 0 means don't return more than PRECISION characters
6527 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6529 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6531 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6534 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6535 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6536 FIELD_WIDTH < 0 means infinite field width. This is useful for
6537 padding with `-' at the end of a mode line. */
6538 if (field_width
< 0)
6539 field_width
= INFINITY
;
6540 /* Implementation note: We deliberately don't enlarge
6541 it->bidi_it.string.schars here to fit it->end_charpos, because
6542 the bidi iterator cannot produce characters out of thin air. */
6543 if (field_width
> it
->end_charpos
- charpos
)
6544 it
->end_charpos
= charpos
+ field_width
;
6546 /* Use the standard display table for displaying strings. */
6547 if (DISP_TABLE_P (Vstandard_display_table
))
6548 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6550 it
->stop_charpos
= charpos
;
6551 it
->prev_stop
= charpos
;
6552 it
->base_level_stop
= 0;
6555 it
->bidi_it
.first_elt
= 1;
6556 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6557 it
->bidi_it
.disp_pos
= -1;
6559 if (s
== NULL
&& it
->multibyte_p
)
6561 ptrdiff_t endpos
= SCHARS (it
->string
);
6562 if (endpos
> it
->end_charpos
)
6563 endpos
= it
->end_charpos
;
6564 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6572 /***********************************************************************
6574 ***********************************************************************/
6576 /* Map enum it_method value to corresponding next_element_from_* function. */
6578 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6580 next_element_from_buffer
,
6581 next_element_from_display_vector
,
6582 next_element_from_string
,
6583 next_element_from_c_string
,
6584 next_element_from_image
,
6585 next_element_from_stretch
6588 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6591 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6592 (possibly with the following characters). */
6594 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6595 ((IT)->cmp_it.id >= 0 \
6596 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6597 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6598 END_CHARPOS, (IT)->w, \
6599 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6603 /* Lookup the char-table Vglyphless_char_display for character C (-1
6604 if we want information for no-font case), and return the display
6605 method symbol. By side-effect, update it->what and
6606 it->glyphless_method. This function is called from
6607 get_next_display_element for each character element, and from
6608 x_produce_glyphs when no suitable font was found. */
6611 lookup_glyphless_char_display (int c
, struct it
*it
)
6613 Lisp_Object glyphless_method
= Qnil
;
6615 if (CHAR_TABLE_P (Vglyphless_char_display
)
6616 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6620 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6621 if (CONSP (glyphless_method
))
6622 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6623 ? XCAR (glyphless_method
)
6624 : XCDR (glyphless_method
);
6627 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6631 if (NILP (glyphless_method
))
6634 /* The default is to display the character by a proper font. */
6636 /* The default for the no-font case is to display an empty box. */
6637 glyphless_method
= Qempty_box
;
6639 if (EQ (glyphless_method
, Qzero_width
))
6642 return glyphless_method
;
6643 /* This method can't be used for the no-font case. */
6644 glyphless_method
= Qempty_box
;
6646 if (EQ (glyphless_method
, Qthin_space
))
6647 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6648 else if (EQ (glyphless_method
, Qempty_box
))
6649 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6650 else if (EQ (glyphless_method
, Qhex_code
))
6651 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6652 else if (STRINGP (glyphless_method
))
6653 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6656 /* Invalid value. We use the default method. */
6657 glyphless_method
= Qnil
;
6660 it
->what
= IT_GLYPHLESS
;
6661 return glyphless_method
;
6664 /* Merge escape glyph face and cache the result. */
6666 static struct frame
*last_escape_glyph_frame
= NULL
;
6667 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6668 static int last_escape_glyph_merged_face_id
= 0;
6671 merge_escape_glyph_face (struct it
*it
)
6675 if (it
->f
== last_escape_glyph_frame
6676 && it
->face_id
== last_escape_glyph_face_id
)
6677 face_id
= last_escape_glyph_merged_face_id
;
6680 /* Merge the `escape-glyph' face into the current face. */
6681 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6682 last_escape_glyph_frame
= it
->f
;
6683 last_escape_glyph_face_id
= it
->face_id
;
6684 last_escape_glyph_merged_face_id
= face_id
;
6689 /* Likewise for glyphless glyph face. */
6691 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6692 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6693 static int last_glyphless_glyph_merged_face_id
= 0;
6696 merge_glyphless_glyph_face (struct it
*it
)
6700 if (it
->f
== last_glyphless_glyph_frame
6701 && it
->face_id
== last_glyphless_glyph_face_id
)
6702 face_id
= last_glyphless_glyph_merged_face_id
;
6705 /* Merge the `glyphless-char' face into the current face. */
6706 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6707 last_glyphless_glyph_frame
= it
->f
;
6708 last_glyphless_glyph_face_id
= it
->face_id
;
6709 last_glyphless_glyph_merged_face_id
= face_id
;
6714 /* Load IT's display element fields with information about the next
6715 display element from the current position of IT. Value is zero if
6716 end of buffer (or C string) is reached. */
6719 get_next_display_element (struct it
*it
)
6721 /* Non-zero means that we found a display element. Zero means that
6722 we hit the end of what we iterate over. Performance note: the
6723 function pointer `method' used here turns out to be faster than
6724 using a sequence of if-statements. */
6728 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6730 if (it
->what
== IT_CHARACTER
)
6732 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6733 and only if (a) the resolved directionality of that character
6735 /* FIXME: Do we need an exception for characters from display
6737 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6738 it
->c
= bidi_mirror_char (it
->c
);
6739 /* Map via display table or translate control characters.
6740 IT->c, IT->len etc. have been set to the next character by
6741 the function call above. If we have a display table, and it
6742 contains an entry for IT->c, translate it. Don't do this if
6743 IT->c itself comes from a display table, otherwise we could
6744 end up in an infinite recursion. (An alternative could be to
6745 count the recursion depth of this function and signal an
6746 error when a certain maximum depth is reached.) Is it worth
6748 if (success_p
&& it
->dpvec
== NULL
)
6751 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6752 int nonascii_space_p
= 0;
6753 int nonascii_hyphen_p
= 0;
6754 int c
= it
->c
; /* This is the character to display. */
6756 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6758 eassert (SINGLE_BYTE_CHAR_P (c
));
6759 if (unibyte_display_via_language_environment
)
6761 c
= DECODE_CHAR (unibyte
, c
);
6763 c
= BYTE8_TO_CHAR (it
->c
);
6766 c
= BYTE8_TO_CHAR (it
->c
);
6770 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6773 struct Lisp_Vector
*v
= XVECTOR (dv
);
6775 /* Return the first character from the display table
6776 entry, if not empty. If empty, don't display the
6777 current character. */
6780 it
->dpvec_char_len
= it
->len
;
6781 it
->dpvec
= v
->u
.contents
;
6782 it
->dpend
= v
->u
.contents
+ v
->header
.size
;
6783 it
->current
.dpvec_index
= 0;
6784 it
->dpvec_face_id
= -1;
6785 it
->saved_face_id
= it
->face_id
;
6786 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6791 set_iterator_to_next (it
, 0);
6796 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6798 if (it
->what
== IT_GLYPHLESS
)
6800 /* Don't display this character. */
6801 set_iterator_to_next (it
, 0);
6805 /* If `nobreak-char-display' is non-nil, we display
6806 non-ASCII spaces and hyphens specially. */
6807 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6810 nonascii_space_p
= 1;
6811 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6812 nonascii_hyphen_p
= 1;
6815 /* Translate control characters into `\003' or `^C' form.
6816 Control characters coming from a display table entry are
6817 currently not translated because we use IT->dpvec to hold
6818 the translation. This could easily be changed but I
6819 don't believe that it is worth doing.
6821 The characters handled by `nobreak-char-display' must be
6824 Non-printable characters and raw-byte characters are also
6825 translated to octal form. */
6826 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6827 ? (it
->area
!= TEXT_AREA
6828 /* In mode line, treat \n, \t like other crl chars. */
6831 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6832 || (c
!= '\n' && c
!= '\t'))
6834 || nonascii_hyphen_p
6836 || ! CHAR_PRINTABLE_P (c
))))
6838 /* C is a control character, non-ASCII space/hyphen,
6839 raw-byte, or a non-printable character which must be
6840 displayed either as '\003' or as `^C' where the '\\'
6841 and '^' can be defined in the display table. Fill
6842 IT->ctl_chars with glyphs for what we have to
6843 display. Then, set IT->dpvec to these glyphs. */
6850 /* Handle control characters with ^. */
6852 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6856 g
= '^'; /* default glyph for Control */
6857 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6859 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6861 g
= GLYPH_CODE_CHAR (gc
);
6862 lface_id
= GLYPH_CODE_FACE (gc
);
6866 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6867 : merge_escape_glyph_face (it
));
6869 XSETINT (it
->ctl_chars
[0], g
);
6870 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6872 goto display_control
;
6875 /* Handle non-ascii space in the mode where it only gets
6878 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6880 /* Merge `nobreak-space' into the current face. */
6881 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6883 XSETINT (it
->ctl_chars
[0], ' ');
6885 goto display_control
;
6888 /* Handle sequences that start with the "escape glyph". */
6890 /* the default escape glyph is \. */
6891 escape_glyph
= '\\';
6894 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6896 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6897 lface_id
= GLYPH_CODE_FACE (gc
);
6901 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6902 : merge_escape_glyph_face (it
));
6904 /* Draw non-ASCII hyphen with just highlighting: */
6906 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6908 XSETINT (it
->ctl_chars
[0], '-');
6910 goto display_control
;
6913 /* Draw non-ASCII space/hyphen with escape glyph: */
6915 if (nonascii_space_p
|| nonascii_hyphen_p
)
6917 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6918 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6920 goto display_control
;
6927 if (CHAR_BYTE8_P (c
))
6928 /* Display \200 instead of \17777600. */
6929 c
= CHAR_TO_BYTE8 (c
);
6930 len
= sprintf (str
, "%03o", c
);
6932 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6933 for (i
= 0; i
< len
; i
++)
6934 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6939 /* Set up IT->dpvec and return first character from it. */
6940 it
->dpvec_char_len
= it
->len
;
6941 it
->dpvec
= it
->ctl_chars
;
6942 it
->dpend
= it
->dpvec
+ ctl_len
;
6943 it
->current
.dpvec_index
= 0;
6944 it
->dpvec_face_id
= face_id
;
6945 it
->saved_face_id
= it
->face_id
;
6946 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6950 it
->char_to_display
= c
;
6954 it
->char_to_display
= it
->c
;
6958 /* Adjust face id for a multibyte character. There are no multibyte
6959 character in unibyte text. */
6960 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6963 && FRAME_WINDOW_P (it
->f
))
6965 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6967 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6969 /* Automatic composition with glyph-string. */
6970 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6972 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6976 ptrdiff_t pos
= (it
->s
? -1
6977 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6978 : IT_CHARPOS (*it
));
6981 if (it
->what
== IT_CHARACTER
)
6982 c
= it
->char_to_display
;
6985 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6989 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6990 /* TAB in a composition means display glyphs with
6991 padding space on the left or right. */
6992 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6995 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7000 /* Is this character the last one of a run of characters with
7001 box? If yes, set IT->end_of_box_run_p to 1. */
7005 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7007 int face_id
= underlying_face_id (it
);
7008 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7012 if (face
->box
== FACE_NO_BOX
)
7014 /* If the box comes from face properties in a
7015 display string, check faces in that string. */
7016 int string_face_id
= face_after_it_pos (it
);
7017 it
->end_of_box_run_p
7018 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7021 /* Otherwise, the box comes from the underlying face.
7022 If this is the last string character displayed, check
7023 the next buffer location. */
7024 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7025 && (it
->current
.overlay_string_index
7026 == it
->n_overlay_strings
- 1))
7030 struct text_pos pos
= it
->current
.pos
;
7031 INC_TEXT_POS (pos
, it
->multibyte_p
);
7033 next_face_id
= face_at_buffer_position
7034 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7035 it
->region_end_charpos
, &ignore
,
7036 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7038 it
->end_of_box_run_p
7039 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7044 /* next_element_from_display_vector sets this flag according to
7045 faces of the display vector glyphs, see there. */
7046 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7048 int face_id
= face_after_it_pos (it
);
7049 it
->end_of_box_run_p
7050 = (face_id
!= it
->face_id
7051 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7054 /* If we reached the end of the object we've been iterating (e.g., a
7055 display string or an overlay string), and there's something on
7056 IT->stack, proceed with what's on the stack. It doesn't make
7057 sense to return zero if there's unprocessed stuff on the stack,
7058 because otherwise that stuff will never be displayed. */
7059 if (!success_p
&& it
->sp
> 0)
7061 set_iterator_to_next (it
, 0);
7062 success_p
= get_next_display_element (it
);
7065 /* Value is 0 if end of buffer or string reached. */
7070 /* Move IT to the next display element.
7072 RESEAT_P non-zero means if called on a newline in buffer text,
7073 skip to the next visible line start.
7075 Functions get_next_display_element and set_iterator_to_next are
7076 separate because I find this arrangement easier to handle than a
7077 get_next_display_element function that also increments IT's
7078 position. The way it is we can first look at an iterator's current
7079 display element, decide whether it fits on a line, and if it does,
7080 increment the iterator position. The other way around we probably
7081 would either need a flag indicating whether the iterator has to be
7082 incremented the next time, or we would have to implement a
7083 decrement position function which would not be easy to write. */
7086 set_iterator_to_next (struct it
*it
, int reseat_p
)
7088 /* Reset flags indicating start and end of a sequence of characters
7089 with box. Reset them at the start of this function because
7090 moving the iterator to a new position might set them. */
7091 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7095 case GET_FROM_BUFFER
:
7096 /* The current display element of IT is a character from
7097 current_buffer. Advance in the buffer, and maybe skip over
7098 invisible lines that are so because of selective display. */
7099 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7100 reseat_at_next_visible_line_start (it
, 0);
7101 else if (it
->cmp_it
.id
>= 0)
7103 /* We are currently getting glyphs from a composition. */
7108 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7109 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7110 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7112 it
->cmp_it
.from
= it
->cmp_it
.to
;
7117 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7119 it
->end_charpos
, Qnil
);
7122 else if (! it
->cmp_it
.reversed_p
)
7124 /* Composition created while scanning forward. */
7125 /* Update IT's char/byte positions to point to the first
7126 character of the next grapheme cluster, or to the
7127 character visually after the current composition. */
7128 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
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
;
7133 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7135 /* Proceed to the next grapheme cluster. */
7136 it
->cmp_it
.from
= it
->cmp_it
.to
;
7140 /* No more grapheme clusters in this composition.
7141 Find the next stop position. */
7142 ptrdiff_t stop
= it
->end_charpos
;
7143 if (it
->bidi_it
.scan_dir
< 0)
7144 /* Now we are scanning backward and don't know
7147 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7148 IT_BYTEPOS (*it
), stop
, Qnil
);
7153 /* Composition created while scanning backward. */
7154 /* Update IT's char/byte positions to point to the last
7155 character of the previous grapheme cluster, or the
7156 character visually after the current composition. */
7157 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7158 bidi_move_to_visually_next (&it
->bidi_it
);
7159 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7160 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7161 if (it
->cmp_it
.from
> 0)
7163 /* Proceed to the previous grapheme cluster. */
7164 it
->cmp_it
.to
= it
->cmp_it
.from
;
7168 /* No more grapheme clusters in this composition.
7169 Find the next stop position. */
7170 ptrdiff_t stop
= it
->end_charpos
;
7171 if (it
->bidi_it
.scan_dir
< 0)
7172 /* Now we are scanning backward and don't know
7175 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7176 IT_BYTEPOS (*it
), stop
, Qnil
);
7182 eassert (it
->len
!= 0);
7186 IT_BYTEPOS (*it
) += it
->len
;
7187 IT_CHARPOS (*it
) += 1;
7191 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7192 /* If this is a new paragraph, determine its base
7193 direction (a.k.a. its base embedding level). */
7194 if (it
->bidi_it
.new_paragraph
)
7195 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7196 bidi_move_to_visually_next (&it
->bidi_it
);
7197 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7198 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7199 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7201 /* As the scan direction was changed, we must
7202 re-compute the stop position for composition. */
7203 ptrdiff_t stop
= it
->end_charpos
;
7204 if (it
->bidi_it
.scan_dir
< 0)
7206 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7207 IT_BYTEPOS (*it
), stop
, Qnil
);
7210 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7214 case GET_FROM_C_STRING
:
7215 /* Current display element of IT is from a C string. */
7217 /* If the string position is beyond string's end, it means
7218 next_element_from_c_string is padding the string with
7219 blanks, in which case we bypass the bidi iterator,
7220 because it cannot deal with such virtual characters. */
7221 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7223 IT_BYTEPOS (*it
) += it
->len
;
7224 IT_CHARPOS (*it
) += 1;
7228 bidi_move_to_visually_next (&it
->bidi_it
);
7229 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7230 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7234 case GET_FROM_DISPLAY_VECTOR
:
7235 /* Current display element of IT is from a display table entry.
7236 Advance in the display table definition. Reset it to null if
7237 end reached, and continue with characters from buffers/
7239 ++it
->current
.dpvec_index
;
7241 /* Restore face of the iterator to what they were before the
7242 display vector entry (these entries may contain faces). */
7243 it
->face_id
= it
->saved_face_id
;
7245 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7247 int recheck_faces
= it
->ellipsis_p
;
7250 it
->method
= GET_FROM_C_STRING
;
7251 else if (STRINGP (it
->string
))
7252 it
->method
= GET_FROM_STRING
;
7255 it
->method
= GET_FROM_BUFFER
;
7256 it
->object
= it
->w
->contents
;
7260 it
->current
.dpvec_index
= -1;
7262 /* Skip over characters which were displayed via IT->dpvec. */
7263 if (it
->dpvec_char_len
< 0)
7264 reseat_at_next_visible_line_start (it
, 1);
7265 else if (it
->dpvec_char_len
> 0)
7267 if (it
->method
== GET_FROM_STRING
7268 && it
->current
.overlay_string_index
>= 0
7269 && it
->n_overlay_strings
> 0)
7270 it
->ignore_overlay_strings_at_pos_p
= 1;
7271 it
->len
= it
->dpvec_char_len
;
7272 set_iterator_to_next (it
, reseat_p
);
7275 /* Maybe recheck faces after display vector */
7277 it
->stop_charpos
= IT_CHARPOS (*it
);
7281 case GET_FROM_STRING
:
7282 /* Current display element is a character from a Lisp string. */
7283 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7284 /* Don't advance past string end. These conditions are true
7285 when set_iterator_to_next is called at the end of
7286 get_next_display_element, in which case the Lisp string is
7287 already exhausted, and all we want is pop the iterator
7289 if (it
->current
.overlay_string_index
>= 0)
7291 /* This is an overlay string, so there's no padding with
7292 spaces, and the number of characters in the string is
7293 where the string ends. */
7294 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7295 goto consider_string_end
;
7299 /* Not an overlay string. There could be padding, so test
7300 against it->end_charpos . */
7301 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7302 goto consider_string_end
;
7304 if (it
->cmp_it
.id
>= 0)
7310 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7311 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7312 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7313 it
->cmp_it
.from
= it
->cmp_it
.to
;
7317 composition_compute_stop_pos (&it
->cmp_it
,
7318 IT_STRING_CHARPOS (*it
),
7319 IT_STRING_BYTEPOS (*it
),
7320 it
->end_charpos
, it
->string
);
7323 else if (! it
->cmp_it
.reversed_p
)
7325 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7326 bidi_move_to_visually_next (&it
->bidi_it
);
7327 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7328 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7330 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7331 it
->cmp_it
.from
= it
->cmp_it
.to
;
7334 ptrdiff_t stop
= it
->end_charpos
;
7335 if (it
->bidi_it
.scan_dir
< 0)
7337 composition_compute_stop_pos (&it
->cmp_it
,
7338 IT_STRING_CHARPOS (*it
),
7339 IT_STRING_BYTEPOS (*it
), stop
,
7345 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7346 bidi_move_to_visually_next (&it
->bidi_it
);
7347 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7348 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7349 if (it
->cmp_it
.from
> 0)
7350 it
->cmp_it
.to
= it
->cmp_it
.from
;
7353 ptrdiff_t stop
= it
->end_charpos
;
7354 if (it
->bidi_it
.scan_dir
< 0)
7356 composition_compute_stop_pos (&it
->cmp_it
,
7357 IT_STRING_CHARPOS (*it
),
7358 IT_STRING_BYTEPOS (*it
), stop
,
7366 /* If the string position is beyond string's end, it
7367 means next_element_from_string is padding the string
7368 with blanks, in which case we bypass the bidi
7369 iterator, because it cannot deal with such virtual
7371 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7373 IT_STRING_BYTEPOS (*it
) += it
->len
;
7374 IT_STRING_CHARPOS (*it
) += 1;
7378 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7380 bidi_move_to_visually_next (&it
->bidi_it
);
7381 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7382 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7383 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7385 ptrdiff_t stop
= it
->end_charpos
;
7387 if (it
->bidi_it
.scan_dir
< 0)
7389 composition_compute_stop_pos (&it
->cmp_it
,
7390 IT_STRING_CHARPOS (*it
),
7391 IT_STRING_BYTEPOS (*it
), stop
,
7397 consider_string_end
:
7399 if (it
->current
.overlay_string_index
>= 0)
7401 /* IT->string is an overlay string. Advance to the
7402 next, if there is one. */
7403 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7406 next_overlay_string (it
);
7408 setup_for_ellipsis (it
, 0);
7413 /* IT->string is not an overlay string. If we reached
7414 its end, and there is something on IT->stack, proceed
7415 with what is on the stack. This can be either another
7416 string, this time an overlay string, or a buffer. */
7417 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7421 if (it
->method
== GET_FROM_STRING
)
7422 goto consider_string_end
;
7427 case GET_FROM_IMAGE
:
7428 case GET_FROM_STRETCH
:
7429 /* The position etc with which we have to proceed are on
7430 the stack. The position may be at the end of a string,
7431 if the `display' property takes up the whole string. */
7432 eassert (it
->sp
> 0);
7434 if (it
->method
== GET_FROM_STRING
)
7435 goto consider_string_end
;
7439 /* There are no other methods defined, so this should be a bug. */
7443 eassert (it
->method
!= GET_FROM_STRING
7444 || (STRINGP (it
->string
)
7445 && IT_STRING_CHARPOS (*it
) >= 0));
7448 /* Load IT's display element fields with information about the next
7449 display element which comes from a display table entry or from the
7450 result of translating a control character to one of the forms `^C'
7453 IT->dpvec holds the glyphs to return as characters.
7454 IT->saved_face_id holds the face id before the display vector--it
7455 is restored into IT->face_id in set_iterator_to_next. */
7458 next_element_from_display_vector (struct it
*it
)
7461 int prev_face_id
= it
->face_id
;
7465 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7467 it
->face_id
= it
->saved_face_id
;
7469 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7470 That seemed totally bogus - so I changed it... */
7471 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7473 if (GLYPH_CODE_P (gc
))
7475 struct face
*this_face
, *prev_face
, *next_face
;
7477 it
->c
= GLYPH_CODE_CHAR (gc
);
7478 it
->len
= CHAR_BYTES (it
->c
);
7480 /* The entry may contain a face id to use. Such a face id is
7481 the id of a Lisp face, not a realized face. A face id of
7482 zero means no face is specified. */
7483 if (it
->dpvec_face_id
>= 0)
7484 it
->face_id
= it
->dpvec_face_id
;
7487 int lface_id
= GLYPH_CODE_FACE (gc
);
7489 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7493 /* Glyphs in the display vector could have the box face, so we
7494 need to set the related flags in the iterator, as
7496 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7497 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7499 /* Is this character the first character of a box-face run? */
7500 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7502 || prev_face
->box
== FACE_NO_BOX
));
7504 /* For the last character of the box-face run, we need to look
7505 either at the next glyph from the display vector, or at the
7506 face we saw before the display vector. */
7507 next_face_id
= it
->saved_face_id
;
7508 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7510 if (it
->dpvec_face_id
>= 0)
7511 next_face_id
= it
->dpvec_face_id
;
7515 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7518 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7522 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7523 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7525 || next_face
->box
== FACE_NO_BOX
));
7526 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7529 /* Display table entry is invalid. Return a space. */
7530 it
->c
= ' ', it
->len
= 1;
7532 /* Don't change position and object of the iterator here. They are
7533 still the values of the character that had this display table
7534 entry or was translated, and that's what we want. */
7535 it
->what
= IT_CHARACTER
;
7539 /* Get the first element of string/buffer in the visual order, after
7540 being reseated to a new position in a string or a buffer. */
7542 get_visually_first_element (struct it
*it
)
7544 int string_p
= STRINGP (it
->string
) || it
->s
;
7545 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7546 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7548 if (STRINGP (it
->string
))
7550 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7551 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7555 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7556 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7559 if (it
->bidi_it
.charpos
== eob
)
7561 /* Nothing to do, but reset the FIRST_ELT flag, like
7562 bidi_paragraph_init does, because we are not going to
7564 it
->bidi_it
.first_elt
= 0;
7566 else if (it
->bidi_it
.charpos
== bob
7568 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7569 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7571 /* If we are at the beginning of a line/string, we can produce
7572 the next element right away. */
7573 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7574 bidi_move_to_visually_next (&it
->bidi_it
);
7578 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7580 /* We need to prime the bidi iterator starting at the line's or
7581 string's beginning, before we will be able to produce the
7584 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7586 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7587 IT_BYTEPOS (*it
), -1,
7588 &it
->bidi_it
.bytepos
);
7589 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7592 /* Now return to buffer/string position where we were asked
7593 to get the next display element, and produce that. */
7594 bidi_move_to_visually_next (&it
->bidi_it
);
7596 while (it
->bidi_it
.bytepos
!= orig_bytepos
7597 && it
->bidi_it
.charpos
< eob
);
7600 /* Adjust IT's position information to where we ended up. */
7601 if (STRINGP (it
->string
))
7603 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7604 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7608 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7609 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7612 if (STRINGP (it
->string
) || !it
->s
)
7614 ptrdiff_t stop
, charpos
, bytepos
;
7616 if (STRINGP (it
->string
))
7619 stop
= SCHARS (it
->string
);
7620 if (stop
> it
->end_charpos
)
7621 stop
= it
->end_charpos
;
7622 charpos
= IT_STRING_CHARPOS (*it
);
7623 bytepos
= IT_STRING_BYTEPOS (*it
);
7627 stop
= it
->end_charpos
;
7628 charpos
= IT_CHARPOS (*it
);
7629 bytepos
= IT_BYTEPOS (*it
);
7631 if (it
->bidi_it
.scan_dir
< 0)
7633 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7638 /* Load IT with the next display element from Lisp string IT->string.
7639 IT->current.string_pos is the current position within the string.
7640 If IT->current.overlay_string_index >= 0, the Lisp string is an
7644 next_element_from_string (struct it
*it
)
7646 struct text_pos position
;
7648 eassert (STRINGP (it
->string
));
7649 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7650 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7651 position
= it
->current
.string_pos
;
7653 /* With bidi reordering, the character to display might not be the
7654 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7655 that we were reseat()ed to a new string, whose paragraph
7656 direction is not known. */
7657 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7659 get_visually_first_element (it
);
7660 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7663 /* Time to check for invisible text? */
7664 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7666 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7669 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7670 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7672 /* With bidi non-linear iteration, we could find
7673 ourselves far beyond the last computed stop_charpos,
7674 with several other stop positions in between that we
7675 missed. Scan them all now, in buffer's logical
7676 order, until we find and handle the last stop_charpos
7677 that precedes our current position. */
7678 handle_stop_backwards (it
, it
->stop_charpos
);
7679 return GET_NEXT_DISPLAY_ELEMENT (it
);
7685 /* Take note of the stop position we just moved
7686 across, for when we will move back across it. */
7687 it
->prev_stop
= it
->stop_charpos
;
7688 /* If we are at base paragraph embedding level, take
7689 note of the last stop position seen at this
7691 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7692 it
->base_level_stop
= it
->stop_charpos
;
7696 /* Since a handler may have changed IT->method, we must
7698 return GET_NEXT_DISPLAY_ELEMENT (it
);
7702 /* If we are before prev_stop, we may have overstepped
7703 on our way backwards a stop_pos, and if so, we need
7704 to handle that stop_pos. */
7705 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7706 /* We can sometimes back up for reasons that have nothing
7707 to do with bidi reordering. E.g., compositions. The
7708 code below is only needed when we are above the base
7709 embedding level, so test for that explicitly. */
7710 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7712 /* If we lost track of base_level_stop, we have no better
7713 place for handle_stop_backwards to start from than string
7714 beginning. This happens, e.g., when we were reseated to
7715 the previous screenful of text by vertical-motion. */
7716 if (it
->base_level_stop
<= 0
7717 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7718 it
->base_level_stop
= 0;
7719 handle_stop_backwards (it
, it
->base_level_stop
);
7720 return GET_NEXT_DISPLAY_ELEMENT (it
);
7724 if (it
->current
.overlay_string_index
>= 0)
7726 /* Get the next character from an overlay string. In overlay
7727 strings, there is no field width or padding with spaces to
7729 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7734 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7735 IT_STRING_BYTEPOS (*it
),
7736 it
->bidi_it
.scan_dir
< 0
7738 : SCHARS (it
->string
))
7739 && next_element_from_composition (it
))
7743 else if (STRING_MULTIBYTE (it
->string
))
7745 const unsigned char *s
= (SDATA (it
->string
)
7746 + IT_STRING_BYTEPOS (*it
));
7747 it
->c
= string_char_and_length (s
, &it
->len
);
7751 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7757 /* Get the next character from a Lisp string that is not an
7758 overlay string. Such strings come from the mode line, for
7759 example. We may have to pad with spaces, or truncate the
7760 string. See also next_element_from_c_string. */
7761 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7766 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7768 /* Pad with spaces. */
7769 it
->c
= ' ', it
->len
= 1;
7770 CHARPOS (position
) = BYTEPOS (position
) = -1;
7772 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7773 IT_STRING_BYTEPOS (*it
),
7774 it
->bidi_it
.scan_dir
< 0
7776 : it
->string_nchars
)
7777 && next_element_from_composition (it
))
7781 else if (STRING_MULTIBYTE (it
->string
))
7783 const unsigned char *s
= (SDATA (it
->string
)
7784 + IT_STRING_BYTEPOS (*it
));
7785 it
->c
= string_char_and_length (s
, &it
->len
);
7789 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7794 /* Record what we have and where it came from. */
7795 it
->what
= IT_CHARACTER
;
7796 it
->object
= it
->string
;
7797 it
->position
= position
;
7802 /* Load IT with next display element from C string IT->s.
7803 IT->string_nchars is the maximum number of characters to return
7804 from the string. IT->end_charpos may be greater than
7805 IT->string_nchars when this function is called, in which case we
7806 may have to return padding spaces. Value is zero if end of string
7807 reached, including padding spaces. */
7810 next_element_from_c_string (struct it
*it
)
7815 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7816 it
->what
= IT_CHARACTER
;
7817 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7820 /* With bidi reordering, the character to display might not be the
7821 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7822 we were reseated to a new string, whose paragraph direction is
7824 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7825 get_visually_first_element (it
);
7827 /* IT's position can be greater than IT->string_nchars in case a
7828 field width or precision has been specified when the iterator was
7830 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7832 /* End of the game. */
7836 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7838 /* Pad with spaces. */
7839 it
->c
= ' ', it
->len
= 1;
7840 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7842 else if (it
->multibyte_p
)
7843 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7845 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7851 /* Set up IT to return characters from an ellipsis, if appropriate.
7852 The definition of the ellipsis glyphs may come from a display table
7853 entry. This function fills IT with the first glyph from the
7854 ellipsis if an ellipsis is to be displayed. */
7857 next_element_from_ellipsis (struct it
*it
)
7859 if (it
->selective_display_ellipsis_p
)
7860 setup_for_ellipsis (it
, it
->len
);
7863 /* The face at the current position may be different from the
7864 face we find after the invisible text. Remember what it
7865 was in IT->saved_face_id, and signal that it's there by
7866 setting face_before_selective_p. */
7867 it
->saved_face_id
= it
->face_id
;
7868 it
->method
= GET_FROM_BUFFER
;
7869 it
->object
= it
->w
->contents
;
7870 reseat_at_next_visible_line_start (it
, 1);
7871 it
->face_before_selective_p
= 1;
7874 return GET_NEXT_DISPLAY_ELEMENT (it
);
7878 /* Deliver an image display element. The iterator IT is already
7879 filled with image information (done in handle_display_prop). Value
7884 next_element_from_image (struct it
*it
)
7886 it
->what
= IT_IMAGE
;
7887 it
->ignore_overlay_strings_at_pos_p
= 0;
7892 /* Fill iterator IT with next display element from a stretch glyph
7893 property. IT->object is the value of the text property. Value is
7897 next_element_from_stretch (struct it
*it
)
7899 it
->what
= IT_STRETCH
;
7903 /* Scan backwards from IT's current position until we find a stop
7904 position, or until BEGV. This is called when we find ourself
7905 before both the last known prev_stop and base_level_stop while
7906 reordering bidirectional text. */
7909 compute_stop_pos_backwards (struct it
*it
)
7911 const int SCAN_BACK_LIMIT
= 1000;
7912 struct text_pos pos
;
7913 struct display_pos save_current
= it
->current
;
7914 struct text_pos save_position
= it
->position
;
7915 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7916 ptrdiff_t where_we_are
= charpos
;
7917 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7918 ptrdiff_t save_end_pos
= it
->end_charpos
;
7920 eassert (NILP (it
->string
) && !it
->s
);
7921 eassert (it
->bidi_p
);
7925 it
->end_charpos
= min (charpos
+ 1, ZV
);
7926 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7927 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7928 reseat_1 (it
, pos
, 0);
7929 compute_stop_pos (it
);
7930 /* We must advance forward, right? */
7931 if (it
->stop_charpos
<= charpos
)
7934 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7936 if (it
->stop_charpos
<= where_we_are
)
7937 it
->prev_stop
= it
->stop_charpos
;
7939 it
->prev_stop
= BEGV
;
7941 it
->current
= save_current
;
7942 it
->position
= save_position
;
7943 it
->stop_charpos
= save_stop_pos
;
7944 it
->end_charpos
= save_end_pos
;
7947 /* Scan forward from CHARPOS in the current buffer/string, until we
7948 find a stop position > current IT's position. Then handle the stop
7949 position before that. This is called when we bump into a stop
7950 position while reordering bidirectional text. CHARPOS should be
7951 the last previously processed stop_pos (or BEGV/0, if none were
7952 processed yet) whose position is less that IT's current
7956 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7958 int bufp
= !STRINGP (it
->string
);
7959 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7960 struct display_pos save_current
= it
->current
;
7961 struct text_pos save_position
= it
->position
;
7962 struct text_pos pos1
;
7963 ptrdiff_t next_stop
;
7965 /* Scan in strict logical order. */
7966 eassert (it
->bidi_p
);
7970 it
->prev_stop
= charpos
;
7973 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7974 reseat_1 (it
, pos1
, 0);
7977 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7978 compute_stop_pos (it
);
7979 /* We must advance forward, right? */
7980 if (it
->stop_charpos
<= it
->prev_stop
)
7982 charpos
= it
->stop_charpos
;
7984 while (charpos
<= where_we_are
);
7987 it
->current
= save_current
;
7988 it
->position
= save_position
;
7989 next_stop
= it
->stop_charpos
;
7990 it
->stop_charpos
= it
->prev_stop
;
7992 it
->stop_charpos
= next_stop
;
7995 /* Load IT with the next display element from current_buffer. Value
7996 is zero if end of buffer reached. IT->stop_charpos is the next
7997 position at which to stop and check for text properties or buffer
8001 next_element_from_buffer (struct it
*it
)
8005 eassert (IT_CHARPOS (*it
) >= BEGV
);
8006 eassert (NILP (it
->string
) && !it
->s
);
8007 eassert (!it
->bidi_p
8008 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8009 && it
->bidi_it
.string
.s
== NULL
));
8011 /* With bidi reordering, the character to display might not be the
8012 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8013 we were reseat()ed to a new buffer position, which is potentially
8014 a different paragraph. */
8015 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8017 get_visually_first_element (it
);
8018 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8021 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8023 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8025 int overlay_strings_follow_p
;
8027 /* End of the game, except when overlay strings follow that
8028 haven't been returned yet. */
8029 if (it
->overlay_strings_at_end_processed_p
)
8030 overlay_strings_follow_p
= 0;
8033 it
->overlay_strings_at_end_processed_p
= 1;
8034 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8037 if (overlay_strings_follow_p
)
8038 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8042 it
->position
= it
->current
.pos
;
8046 else if (!(!it
->bidi_p
8047 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8048 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8050 /* With bidi non-linear iteration, we could find ourselves
8051 far beyond the last computed stop_charpos, with several
8052 other stop positions in between that we missed. Scan
8053 them all now, in buffer's logical order, until we find
8054 and handle the last stop_charpos that precedes our
8055 current position. */
8056 handle_stop_backwards (it
, it
->stop_charpos
);
8057 return GET_NEXT_DISPLAY_ELEMENT (it
);
8063 /* Take note of the stop position we just moved across,
8064 for when we will move back across it. */
8065 it
->prev_stop
= it
->stop_charpos
;
8066 /* If we are at base paragraph embedding level, take
8067 note of the last stop position seen at this
8069 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8070 it
->base_level_stop
= it
->stop_charpos
;
8073 return GET_NEXT_DISPLAY_ELEMENT (it
);
8077 /* If we are before prev_stop, we may have overstepped on
8078 our way backwards a stop_pos, and if so, we need to
8079 handle that stop_pos. */
8080 && IT_CHARPOS (*it
) < it
->prev_stop
8081 /* We can sometimes back up for reasons that have nothing
8082 to do with bidi reordering. E.g., compositions. The
8083 code below is only needed when we are above the base
8084 embedding level, so test for that explicitly. */
8085 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8087 if (it
->base_level_stop
<= 0
8088 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8090 /* If we lost track of base_level_stop, we need to find
8091 prev_stop by looking backwards. This happens, e.g., when
8092 we were reseated to the previous screenful of text by
8094 it
->base_level_stop
= BEGV
;
8095 compute_stop_pos_backwards (it
);
8096 handle_stop_backwards (it
, it
->prev_stop
);
8099 handle_stop_backwards (it
, it
->base_level_stop
);
8100 return GET_NEXT_DISPLAY_ELEMENT (it
);
8104 /* No face changes, overlays etc. in sight, so just return a
8105 character from current_buffer. */
8109 /* Maybe run the redisplay end trigger hook. Performance note:
8110 This doesn't seem to cost measurable time. */
8111 if (it
->redisplay_end_trigger_charpos
8113 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8114 run_redisplay_end_trigger_hook (it
);
8116 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8117 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8119 && next_element_from_composition (it
))
8124 /* Get the next character, maybe multibyte. */
8125 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8126 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8127 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8129 it
->c
= *p
, it
->len
= 1;
8131 /* Record what we have and where it came from. */
8132 it
->what
= IT_CHARACTER
;
8133 it
->object
= it
->w
->contents
;
8134 it
->position
= it
->current
.pos
;
8136 /* Normally we return the character found above, except when we
8137 really want to return an ellipsis for selective display. */
8142 /* A value of selective > 0 means hide lines indented more
8143 than that number of columns. */
8144 if (it
->selective
> 0
8145 && IT_CHARPOS (*it
) + 1 < ZV
8146 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8147 IT_BYTEPOS (*it
) + 1,
8150 success_p
= next_element_from_ellipsis (it
);
8151 it
->dpvec_char_len
= -1;
8154 else if (it
->c
== '\r' && it
->selective
== -1)
8156 /* A value of selective == -1 means that everything from the
8157 CR to the end of the line is invisible, with maybe an
8158 ellipsis displayed for it. */
8159 success_p
= next_element_from_ellipsis (it
);
8160 it
->dpvec_char_len
= -1;
8165 /* Value is zero if end of buffer reached. */
8166 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8171 /* Run the redisplay end trigger hook for IT. */
8174 run_redisplay_end_trigger_hook (struct it
*it
)
8176 Lisp_Object args
[3];
8178 /* IT->glyph_row should be non-null, i.e. we should be actually
8179 displaying something, or otherwise we should not run the hook. */
8180 eassert (it
->glyph_row
);
8182 /* Set up hook arguments. */
8183 args
[0] = Qredisplay_end_trigger_functions
;
8184 args
[1] = it
->window
;
8185 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8186 it
->redisplay_end_trigger_charpos
= 0;
8188 /* Since we are *trying* to run these functions, don't try to run
8189 them again, even if they get an error. */
8190 wset_redisplay_end_trigger (it
->w
, Qnil
);
8191 Frun_hook_with_args (3, args
);
8193 /* Notice if it changed the face of the character we are on. */
8194 handle_face_prop (it
);
8198 /* Deliver a composition display element. Unlike the other
8199 next_element_from_XXX, this function is not registered in the array
8200 get_next_element[]. It is called from next_element_from_buffer and
8201 next_element_from_string when necessary. */
8204 next_element_from_composition (struct it
*it
)
8206 it
->what
= IT_COMPOSITION
;
8207 it
->len
= it
->cmp_it
.nbytes
;
8208 if (STRINGP (it
->string
))
8212 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8213 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8216 it
->position
= it
->current
.string_pos
;
8217 it
->object
= it
->string
;
8218 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8219 IT_STRING_BYTEPOS (*it
), it
->string
);
8225 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8226 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8229 if (it
->bidi_it
.new_paragraph
)
8230 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8231 /* Resync the bidi iterator with IT's new position.
8232 FIXME: this doesn't support bidirectional text. */
8233 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8234 bidi_move_to_visually_next (&it
->bidi_it
);
8238 it
->position
= it
->current
.pos
;
8239 it
->object
= it
->w
->contents
;
8240 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8241 IT_BYTEPOS (*it
), Qnil
);
8248 /***********************************************************************
8249 Moving an iterator without producing glyphs
8250 ***********************************************************************/
8252 /* Check if iterator is at a position corresponding to a valid buffer
8253 position after some move_it_ call. */
8255 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8256 ((it)->method == GET_FROM_STRING \
8257 ? IT_STRING_CHARPOS (*it) == 0 \
8261 /* Move iterator IT to a specified buffer or X position within one
8262 line on the display without producing glyphs.
8264 OP should be a bit mask including some or all of these bits:
8265 MOVE_TO_X: Stop upon reaching x-position TO_X.
8266 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8267 Regardless of OP's value, stop upon reaching the end of the display line.
8269 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8270 This means, in particular, that TO_X includes window's horizontal
8273 The return value has several possible values that
8274 say what condition caused the scan to stop:
8276 MOVE_POS_MATCH_OR_ZV
8277 - when TO_POS or ZV was reached.
8280 -when TO_X was reached before TO_POS or ZV were reached.
8283 - when we reached the end of the display area and the line must
8287 - when we reached the end of the display area and the line is
8291 - when we stopped at a line end, i.e. a newline or a CR and selective
8294 static enum move_it_result
8295 move_it_in_display_line_to (struct it
*it
,
8296 ptrdiff_t to_charpos
, int to_x
,
8297 enum move_operation_enum op
)
8299 enum move_it_result result
= MOVE_UNDEFINED
;
8300 struct glyph_row
*saved_glyph_row
;
8301 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8302 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8303 void *ppos_data
= NULL
;
8305 enum it_method prev_method
= it
->method
;
8306 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8307 int saw_smaller_pos
= prev_pos
< to_charpos
;
8309 /* Don't produce glyphs in produce_glyphs. */
8310 saved_glyph_row
= it
->glyph_row
;
8311 it
->glyph_row
= NULL
;
8313 /* Use wrap_it to save a copy of IT wherever a word wrap could
8314 occur. Use atpos_it to save a copy of IT at the desired buffer
8315 position, if found, so that we can scan ahead and check if the
8316 word later overshoots the window edge. Use atx_it similarly, for
8322 /* Use ppos_it under bidi reordering to save a copy of IT for the
8323 position > CHARPOS that is the closest to CHARPOS. We restore
8324 that position in IT when we have scanned the entire display line
8325 without finding a match for CHARPOS and all the character
8326 positions are greater than CHARPOS. */
8329 SAVE_IT (ppos_it
, *it
, ppos_data
);
8330 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8331 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8332 SAVE_IT (ppos_it
, *it
, ppos_data
);
8335 #define BUFFER_POS_REACHED_P() \
8336 ((op & MOVE_TO_POS) != 0 \
8337 && BUFFERP (it->object) \
8338 && (IT_CHARPOS (*it) == to_charpos \
8340 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8341 && IT_CHARPOS (*it) > to_charpos) \
8342 || (it->what == IT_COMPOSITION \
8343 && ((IT_CHARPOS (*it) > to_charpos \
8344 && to_charpos >= it->cmp_it.charpos) \
8345 || (IT_CHARPOS (*it) < to_charpos \
8346 && to_charpos <= it->cmp_it.charpos)))) \
8347 && (it->method == GET_FROM_BUFFER \
8348 || (it->method == GET_FROM_DISPLAY_VECTOR \
8349 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8351 /* If there's a line-/wrap-prefix, handle it. */
8352 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8353 && it
->current_y
< it
->last_visible_y
)
8354 handle_line_prefix (it
);
8356 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8357 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8361 int x
, i
, ascent
= 0, descent
= 0;
8363 /* Utility macro to reset an iterator with x, ascent, and descent. */
8364 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8365 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8366 (IT)->max_descent = descent)
8368 /* Stop if we move beyond TO_CHARPOS (after an image or a
8369 display string or stretch glyph). */
8370 if ((op
& MOVE_TO_POS
) != 0
8371 && BUFFERP (it
->object
)
8372 && it
->method
== GET_FROM_BUFFER
8374 /* When the iterator is at base embedding level, we
8375 are guaranteed that characters are delivered for
8376 display in strictly increasing order of their
8377 buffer positions. */
8378 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8379 && IT_CHARPOS (*it
) > to_charpos
)
8381 && (prev_method
== GET_FROM_IMAGE
8382 || prev_method
== GET_FROM_STRETCH
8383 || prev_method
== GET_FROM_STRING
)
8384 /* Passed TO_CHARPOS from left to right. */
8385 && ((prev_pos
< to_charpos
8386 && IT_CHARPOS (*it
) > to_charpos
)
8387 /* Passed TO_CHARPOS from right to left. */
8388 || (prev_pos
> to_charpos
8389 && IT_CHARPOS (*it
) < to_charpos
)))))
8391 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8393 result
= MOVE_POS_MATCH_OR_ZV
;
8396 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8397 /* If wrap_it is valid, the current position might be in a
8398 word that is wrapped. So, save the iterator in
8399 atpos_it and continue to see if wrapping happens. */
8400 SAVE_IT (atpos_it
, *it
, atpos_data
);
8403 /* Stop when ZV reached.
8404 We used to stop here when TO_CHARPOS reached as well, but that is
8405 too soon if this glyph does not fit on this line. So we handle it
8406 explicitly below. */
8407 if (!get_next_display_element (it
))
8409 result
= MOVE_POS_MATCH_OR_ZV
;
8413 if (it
->line_wrap
== TRUNCATE
)
8415 if (BUFFER_POS_REACHED_P ())
8417 result
= MOVE_POS_MATCH_OR_ZV
;
8423 if (it
->line_wrap
== WORD_WRAP
)
8425 if (IT_DISPLAYING_WHITESPACE (it
))
8429 /* We have reached a glyph that follows one or more
8430 whitespace characters. If the position is
8431 already found, we are done. */
8432 if (atpos_it
.sp
>= 0)
8434 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8435 result
= MOVE_POS_MATCH_OR_ZV
;
8440 RESTORE_IT (it
, &atx_it
, atx_data
);
8441 result
= MOVE_X_REACHED
;
8444 /* Otherwise, we can wrap here. */
8445 SAVE_IT (wrap_it
, *it
, wrap_data
);
8451 /* Remember the line height for the current line, in case
8452 the next element doesn't fit on the line. */
8453 ascent
= it
->max_ascent
;
8454 descent
= it
->max_descent
;
8456 /* The call to produce_glyphs will get the metrics of the
8457 display element IT is loaded with. Record the x-position
8458 before this display element, in case it doesn't fit on the
8462 PRODUCE_GLYPHS (it
);
8464 if (it
->area
!= TEXT_AREA
)
8466 prev_method
= it
->method
;
8467 if (it
->method
== GET_FROM_BUFFER
)
8468 prev_pos
= IT_CHARPOS (*it
);
8469 set_iterator_to_next (it
, 1);
8470 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8471 SET_TEXT_POS (this_line_min_pos
,
8472 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8474 && (op
& MOVE_TO_POS
)
8475 && IT_CHARPOS (*it
) > to_charpos
8476 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8477 SAVE_IT (ppos_it
, *it
, ppos_data
);
8481 /* The number of glyphs we get back in IT->nglyphs will normally
8482 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8483 character on a terminal frame, or (iii) a line end. For the
8484 second case, IT->nglyphs - 1 padding glyphs will be present.
8485 (On X frames, there is only one glyph produced for a
8486 composite character.)
8488 The behavior implemented below means, for continuation lines,
8489 that as many spaces of a TAB as fit on the current line are
8490 displayed there. For terminal frames, as many glyphs of a
8491 multi-glyph character are displayed in the current line, too.
8492 This is what the old redisplay code did, and we keep it that
8493 way. Under X, the whole shape of a complex character must
8494 fit on the line or it will be completely displayed in the
8497 Note that both for tabs and padding glyphs, all glyphs have
8501 /* More than one glyph or glyph doesn't fit on line. All
8502 glyphs have the same width. */
8503 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8505 int x_before_this_char
= x
;
8506 int hpos_before_this_char
= it
->hpos
;
8508 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8510 new_x
= x
+ single_glyph_width
;
8512 /* We want to leave anything reaching TO_X to the caller. */
8513 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8515 if (BUFFER_POS_REACHED_P ())
8517 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8518 goto buffer_pos_reached
;
8519 if (atpos_it
.sp
< 0)
8521 SAVE_IT (atpos_it
, *it
, atpos_data
);
8522 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8527 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8530 result
= MOVE_X_REACHED
;
8535 SAVE_IT (atx_it
, *it
, atx_data
);
8536 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8541 if (/* Lines are continued. */
8542 it
->line_wrap
!= TRUNCATE
8543 && (/* And glyph doesn't fit on the line. */
8544 new_x
> it
->last_visible_x
8545 /* Or it fits exactly and we're on a window
8547 || (new_x
== it
->last_visible_x
8548 && FRAME_WINDOW_P (it
->f
)
8549 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8550 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8551 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8553 if (/* IT->hpos == 0 means the very first glyph
8554 doesn't fit on the line, e.g. a wide image. */
8556 || (new_x
== it
->last_visible_x
8557 && FRAME_WINDOW_P (it
->f
)))
8560 it
->current_x
= new_x
;
8562 /* The character's last glyph just barely fits
8564 if (i
== it
->nglyphs
- 1)
8566 /* If this is the destination position,
8567 return a position *before* it in this row,
8568 now that we know it fits in this row. */
8569 if (BUFFER_POS_REACHED_P ())
8571 if (it
->line_wrap
!= WORD_WRAP
8574 it
->hpos
= hpos_before_this_char
;
8575 it
->current_x
= x_before_this_char
;
8576 result
= MOVE_POS_MATCH_OR_ZV
;
8579 if (it
->line_wrap
== WORD_WRAP
8582 SAVE_IT (atpos_it
, *it
, atpos_data
);
8583 atpos_it
.current_x
= x_before_this_char
;
8584 atpos_it
.hpos
= hpos_before_this_char
;
8588 prev_method
= it
->method
;
8589 if (it
->method
== GET_FROM_BUFFER
)
8590 prev_pos
= IT_CHARPOS (*it
);
8591 set_iterator_to_next (it
, 1);
8592 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8593 SET_TEXT_POS (this_line_min_pos
,
8594 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8595 /* On graphical terminals, newlines may
8596 "overflow" into the fringe if
8597 overflow-newline-into-fringe is non-nil.
8598 On text terminals, and on graphical
8599 terminals with no right margin, newlines
8600 may overflow into the last glyph on the
8602 if (!FRAME_WINDOW_P (it
->f
)
8604 && it
->bidi_it
.paragraph_dir
== R2L
)
8605 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8606 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8607 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8609 if (!get_next_display_element (it
))
8611 result
= MOVE_POS_MATCH_OR_ZV
;
8614 if (BUFFER_POS_REACHED_P ())
8616 if (ITERATOR_AT_END_OF_LINE_P (it
))
8617 result
= MOVE_POS_MATCH_OR_ZV
;
8619 result
= MOVE_LINE_CONTINUED
;
8622 if (ITERATOR_AT_END_OF_LINE_P (it
)
8623 && (it
->line_wrap
!= WORD_WRAP
8626 result
= MOVE_NEWLINE_OR_CR
;
8633 IT_RESET_X_ASCENT_DESCENT (it
);
8635 if (wrap_it
.sp
>= 0)
8637 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8642 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8644 result
= MOVE_LINE_CONTINUED
;
8648 if (BUFFER_POS_REACHED_P ())
8650 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8651 goto buffer_pos_reached
;
8652 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8654 SAVE_IT (atpos_it
, *it
, atpos_data
);
8655 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8659 if (new_x
> it
->first_visible_x
)
8661 /* Glyph is visible. Increment number of glyphs that
8662 would be displayed. */
8667 if (result
!= MOVE_UNDEFINED
)
8670 else if (BUFFER_POS_REACHED_P ())
8673 IT_RESET_X_ASCENT_DESCENT (it
);
8674 result
= MOVE_POS_MATCH_OR_ZV
;
8677 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8679 /* Stop when TO_X specified and reached. This check is
8680 necessary here because of lines consisting of a line end,
8681 only. The line end will not produce any glyphs and we
8682 would never get MOVE_X_REACHED. */
8683 eassert (it
->nglyphs
== 0);
8684 result
= MOVE_X_REACHED
;
8688 /* Is this a line end? If yes, we're done. */
8689 if (ITERATOR_AT_END_OF_LINE_P (it
))
8691 /* If we are past TO_CHARPOS, but never saw any character
8692 positions smaller than TO_CHARPOS, return
8693 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8695 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8697 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8699 if (IT_CHARPOS (ppos_it
) < ZV
)
8701 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8702 result
= MOVE_POS_MATCH_OR_ZV
;
8705 goto buffer_pos_reached
;
8707 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8708 && IT_CHARPOS (*it
) > to_charpos
)
8709 goto buffer_pos_reached
;
8711 result
= MOVE_NEWLINE_OR_CR
;
8714 result
= MOVE_NEWLINE_OR_CR
;
8718 prev_method
= it
->method
;
8719 if (it
->method
== GET_FROM_BUFFER
)
8720 prev_pos
= IT_CHARPOS (*it
);
8721 /* The current display element has been consumed. Advance
8723 set_iterator_to_next (it
, 1);
8724 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8725 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8726 if (IT_CHARPOS (*it
) < to_charpos
)
8727 saw_smaller_pos
= 1;
8729 && (op
& MOVE_TO_POS
)
8730 && IT_CHARPOS (*it
) >= to_charpos
8731 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8732 SAVE_IT (ppos_it
, *it
, ppos_data
);
8734 /* Stop if lines are truncated and IT's current x-position is
8735 past the right edge of the window now. */
8736 if (it
->line_wrap
== TRUNCATE
8737 && it
->current_x
>= it
->last_visible_x
)
8739 if (!FRAME_WINDOW_P (it
->f
)
8740 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8741 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8742 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8743 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8747 if ((at_eob_p
= !get_next_display_element (it
))
8748 || BUFFER_POS_REACHED_P ()
8749 /* If we are past TO_CHARPOS, but never saw any
8750 character positions smaller than TO_CHARPOS,
8751 return MOVE_POS_MATCH_OR_ZV, like the
8752 unidirectional display did. */
8753 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8755 && IT_CHARPOS (*it
) > to_charpos
))
8758 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8759 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8760 result
= MOVE_POS_MATCH_OR_ZV
;
8763 if (ITERATOR_AT_END_OF_LINE_P (it
))
8765 result
= MOVE_NEWLINE_OR_CR
;
8769 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8771 && IT_CHARPOS (*it
) > to_charpos
)
8773 if (IT_CHARPOS (ppos_it
) < ZV
)
8774 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8775 result
= MOVE_POS_MATCH_OR_ZV
;
8778 result
= MOVE_LINE_TRUNCATED
;
8781 #undef IT_RESET_X_ASCENT_DESCENT
8784 #undef BUFFER_POS_REACHED_P
8786 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8787 restore the saved iterator. */
8788 if (atpos_it
.sp
>= 0)
8789 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8790 else if (atx_it
.sp
>= 0)
8791 RESTORE_IT (it
, &atx_it
, atx_data
);
8796 bidi_unshelve_cache (atpos_data
, 1);
8798 bidi_unshelve_cache (atx_data
, 1);
8800 bidi_unshelve_cache (wrap_data
, 1);
8802 bidi_unshelve_cache (ppos_data
, 1);
8804 /* Restore the iterator settings altered at the beginning of this
8806 it
->glyph_row
= saved_glyph_row
;
8810 /* For external use. */
8812 move_it_in_display_line (struct it
*it
,
8813 ptrdiff_t to_charpos
, int to_x
,
8814 enum move_operation_enum op
)
8816 if (it
->line_wrap
== WORD_WRAP
8817 && (op
& MOVE_TO_X
))
8820 void *save_data
= NULL
;
8823 SAVE_IT (save_it
, *it
, save_data
);
8824 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8825 /* When word-wrap is on, TO_X may lie past the end
8826 of a wrapped line. Then it->current is the
8827 character on the next line, so backtrack to the
8828 space before the wrap point. */
8829 if (skip
== MOVE_LINE_CONTINUED
)
8831 int prev_x
= max (it
->current_x
- 1, 0);
8832 RESTORE_IT (it
, &save_it
, save_data
);
8833 move_it_in_display_line_to
8834 (it
, -1, prev_x
, MOVE_TO_X
);
8837 bidi_unshelve_cache (save_data
, 1);
8840 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8844 /* Move IT forward until it satisfies one or more of the criteria in
8845 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8847 OP is a bit-mask that specifies where to stop, and in particular,
8848 which of those four position arguments makes a difference. See the
8849 description of enum move_operation_enum.
8851 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8852 screen line, this function will set IT to the next position that is
8853 displayed to the right of TO_CHARPOS on the screen. */
8856 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8858 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8859 int line_height
, line_start_x
= 0, reached
= 0;
8860 void *backup_data
= NULL
;
8864 if (op
& MOVE_TO_VPOS
)
8866 /* If no TO_CHARPOS and no TO_X specified, stop at the
8867 start of the line TO_VPOS. */
8868 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8870 if (it
->vpos
== to_vpos
)
8876 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8880 /* TO_VPOS >= 0 means stop at TO_X in the line at
8881 TO_VPOS, or at TO_POS, whichever comes first. */
8882 if (it
->vpos
== to_vpos
)
8888 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8890 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8895 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8897 /* We have reached TO_X but not in the line we want. */
8898 skip
= move_it_in_display_line_to (it
, to_charpos
,
8900 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8908 else if (op
& MOVE_TO_Y
)
8910 struct it it_backup
;
8912 if (it
->line_wrap
== WORD_WRAP
)
8913 SAVE_IT (it_backup
, *it
, backup_data
);
8915 /* TO_Y specified means stop at TO_X in the line containing
8916 TO_Y---or at TO_CHARPOS if this is reached first. The
8917 problem is that we can't really tell whether the line
8918 contains TO_Y before we have completely scanned it, and
8919 this may skip past TO_X. What we do is to first scan to
8922 If TO_X is not specified, use a TO_X of zero. The reason
8923 is to make the outcome of this function more predictable.
8924 If we didn't use TO_X == 0, we would stop at the end of
8925 the line which is probably not what a caller would expect
8927 skip
= move_it_in_display_line_to
8928 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8929 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8931 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8932 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8934 else if (skip
== MOVE_X_REACHED
)
8936 /* If TO_X was reached, we want to know whether TO_Y is
8937 in the line. We know this is the case if the already
8938 scanned glyphs make the line tall enough. Otherwise,
8939 we must check by scanning the rest of the line. */
8940 line_height
= it
->max_ascent
+ it
->max_descent
;
8941 if (to_y
>= it
->current_y
8942 && to_y
< it
->current_y
+ line_height
)
8947 SAVE_IT (it_backup
, *it
, backup_data
);
8948 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8949 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8951 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8952 line_height
= it
->max_ascent
+ it
->max_descent
;
8953 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8955 if (to_y
>= it
->current_y
8956 && to_y
< it
->current_y
+ line_height
)
8958 /* If TO_Y is in this line and TO_X was reached
8959 above, we scanned too far. We have to restore
8960 IT's settings to the ones before skipping. But
8961 keep the more accurate values of max_ascent and
8962 max_descent we've found while skipping the rest
8963 of the line, for the sake of callers, such as
8964 pos_visible_p, that need to know the line
8966 int max_ascent
= it
->max_ascent
;
8967 int max_descent
= it
->max_descent
;
8969 RESTORE_IT (it
, &it_backup
, backup_data
);
8970 it
->max_ascent
= max_ascent
;
8971 it
->max_descent
= max_descent
;
8977 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8983 /* Check whether TO_Y is in this line. */
8984 line_height
= it
->max_ascent
+ it
->max_descent
;
8985 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8987 if (to_y
>= it
->current_y
8988 && to_y
< it
->current_y
+ line_height
)
8990 /* When word-wrap is on, TO_X may lie past the end
8991 of a wrapped line. Then it->current is the
8992 character on the next line, so backtrack to the
8993 space before the wrap point. */
8994 if (skip
== MOVE_LINE_CONTINUED
8995 && it
->line_wrap
== WORD_WRAP
)
8997 int prev_x
= max (it
->current_x
- 1, 0);
8998 RESTORE_IT (it
, &it_backup
, backup_data
);
8999 skip
= move_it_in_display_line_to
9000 (it
, -1, prev_x
, MOVE_TO_X
);
9009 else if (BUFFERP (it
->object
)
9010 && (it
->method
== GET_FROM_BUFFER
9011 || it
->method
== GET_FROM_STRETCH
)
9012 && IT_CHARPOS (*it
) >= to_charpos
9013 /* Under bidi iteration, a call to set_iterator_to_next
9014 can scan far beyond to_charpos if the initial
9015 portion of the next line needs to be reordered. In
9016 that case, give move_it_in_display_line_to another
9019 && it
->bidi_it
.scan_dir
== -1))
9020 skip
= MOVE_POS_MATCH_OR_ZV
;
9022 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9026 case MOVE_POS_MATCH_OR_ZV
:
9030 case MOVE_NEWLINE_OR_CR
:
9031 set_iterator_to_next (it
, 1);
9032 it
->continuation_lines_width
= 0;
9035 case MOVE_LINE_TRUNCATED
:
9036 it
->continuation_lines_width
= 0;
9037 reseat_at_next_visible_line_start (it
, 0);
9038 if ((op
& MOVE_TO_POS
) != 0
9039 && IT_CHARPOS (*it
) > to_charpos
)
9046 case MOVE_LINE_CONTINUED
:
9047 /* For continued lines ending in a tab, some of the glyphs
9048 associated with the tab are displayed on the current
9049 line. Since it->current_x does not include these glyphs,
9050 we use it->last_visible_x instead. */
9053 it
->continuation_lines_width
+= it
->last_visible_x
;
9054 /* When moving by vpos, ensure that the iterator really
9055 advances to the next line (bug#847, bug#969). Fixme:
9056 do we need to do this in other circumstances? */
9057 if (it
->current_x
!= it
->last_visible_x
9058 && (op
& MOVE_TO_VPOS
)
9059 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9061 line_start_x
= it
->current_x
+ it
->pixel_width
9062 - it
->last_visible_x
;
9063 set_iterator_to_next (it
, 0);
9067 it
->continuation_lines_width
+= it
->current_x
;
9074 /* Reset/increment for the next run. */
9075 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9076 it
->current_x
= line_start_x
;
9079 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9081 last_height
= it
->max_ascent
+ it
->max_descent
;
9082 it
->max_ascent
= it
->max_descent
= 0;
9087 /* On text terminals, we may stop at the end of a line in the middle
9088 of a multi-character glyph. If the glyph itself is continued,
9089 i.e. it is actually displayed on the next line, don't treat this
9090 stopping point as valid; move to the next line instead (unless
9091 that brings us offscreen). */
9092 if (!FRAME_WINDOW_P (it
->f
)
9094 && IT_CHARPOS (*it
) == to_charpos
9095 && it
->what
== IT_CHARACTER
9097 && it
->line_wrap
== WINDOW_WRAP
9098 && it
->current_x
== it
->last_visible_x
- 1
9101 && it
->vpos
< it
->w
->window_end_vpos
)
9103 it
->continuation_lines_width
+= it
->current_x
;
9104 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9105 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9107 last_height
= it
->max_ascent
+ it
->max_descent
;
9111 bidi_unshelve_cache (backup_data
, 1);
9113 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9117 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9119 If DY > 0, move IT backward at least that many pixels. DY = 0
9120 means move IT backward to the preceding line start or BEGV. This
9121 function may move over more than DY pixels if IT->current_y - DY
9122 ends up in the middle of a line; in this case IT->current_y will be
9123 set to the top of the line moved to. */
9126 move_it_vertically_backward (struct it
*it
, int dy
)
9130 void *it2data
= NULL
, *it3data
= NULL
;
9131 ptrdiff_t start_pos
;
9133 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9134 ptrdiff_t pos_limit
;
9139 start_pos
= IT_CHARPOS (*it
);
9141 /* Estimate how many newlines we must move back. */
9142 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9143 if (it
->line_wrap
== TRUNCATE
)
9146 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9148 /* Set the iterator's position that many lines back. But don't go
9149 back more than NLINES full screen lines -- this wins a day with
9150 buffers which have very long lines. */
9151 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9152 back_to_previous_visible_line_start (it
);
9154 /* Reseat the iterator here. When moving backward, we don't want
9155 reseat to skip forward over invisible text, set up the iterator
9156 to deliver from overlay strings at the new position etc. So,
9157 use reseat_1 here. */
9158 reseat_1 (it
, it
->current
.pos
, 1);
9160 /* We are now surely at a line start. */
9161 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9162 reordering is in effect. */
9163 it
->continuation_lines_width
= 0;
9165 /* Move forward and see what y-distance we moved. First move to the
9166 start of the next line so that we get its height. We need this
9167 height to be able to tell whether we reached the specified
9169 SAVE_IT (it2
, *it
, it2data
);
9170 it2
.max_ascent
= it2
.max_descent
= 0;
9173 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9174 MOVE_TO_POS
| MOVE_TO_VPOS
);
9176 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9177 /* If we are in a display string which starts at START_POS,
9178 and that display string includes a newline, and we are
9179 right after that newline (i.e. at the beginning of a
9180 display line), exit the loop, because otherwise we will
9181 infloop, since move_it_to will see that it is already at
9182 START_POS and will not move. */
9183 || (it2
.method
== GET_FROM_STRING
9184 && IT_CHARPOS (it2
) == start_pos
9185 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9186 eassert (IT_CHARPOS (*it
) >= BEGV
);
9187 SAVE_IT (it3
, it2
, it3data
);
9189 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9190 eassert (IT_CHARPOS (*it
) >= BEGV
);
9191 /* H is the actual vertical distance from the position in *IT
9192 and the starting position. */
9193 h
= it2
.current_y
- it
->current_y
;
9194 /* NLINES is the distance in number of lines. */
9195 nlines
= it2
.vpos
- it
->vpos
;
9197 /* Correct IT's y and vpos position
9198 so that they are relative to the starting point. */
9204 /* DY == 0 means move to the start of the screen line. The
9205 value of nlines is > 0 if continuation lines were involved,
9206 or if the original IT position was at start of a line. */
9207 RESTORE_IT (it
, it
, it2data
);
9209 move_it_by_lines (it
, nlines
);
9210 /* The above code moves us to some position NLINES down,
9211 usually to its first glyph (leftmost in an L2R line), but
9212 that's not necessarily the start of the line, under bidi
9213 reordering. We want to get to the character position
9214 that is immediately after the newline of the previous
9217 && !it
->continuation_lines_width
9218 && !STRINGP (it
->string
)
9219 && IT_CHARPOS (*it
) > BEGV
9220 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9222 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9225 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9226 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9228 bidi_unshelve_cache (it3data
, 1);
9232 /* The y-position we try to reach, relative to *IT.
9233 Note that H has been subtracted in front of the if-statement. */
9234 int target_y
= it
->current_y
+ h
- dy
;
9235 int y0
= it3
.current_y
;
9239 RESTORE_IT (&it3
, &it3
, it3data
);
9240 y1
= line_bottom_y (&it3
);
9241 line_height
= y1
- y0
;
9242 RESTORE_IT (it
, it
, it2data
);
9243 /* If we did not reach target_y, try to move further backward if
9244 we can. If we moved too far backward, try to move forward. */
9245 if (target_y
< it
->current_y
9246 /* This is heuristic. In a window that's 3 lines high, with
9247 a line height of 13 pixels each, recentering with point
9248 on the bottom line will try to move -39/2 = 19 pixels
9249 backward. Try to avoid moving into the first line. */
9250 && (it
->current_y
- target_y
9251 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9252 && IT_CHARPOS (*it
) > BEGV
)
9254 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9255 target_y
- it
->current_y
));
9256 dy
= it
->current_y
- target_y
;
9257 goto move_further_back
;
9259 else if (target_y
>= it
->current_y
+ line_height
9260 && IT_CHARPOS (*it
) < ZV
)
9262 /* Should move forward by at least one line, maybe more.
9264 Note: Calling move_it_by_lines can be expensive on
9265 terminal frames, where compute_motion is used (via
9266 vmotion) to do the job, when there are very long lines
9267 and truncate-lines is nil. That's the reason for
9268 treating terminal frames specially here. */
9270 if (!FRAME_WINDOW_P (it
->f
))
9271 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9276 move_it_by_lines (it
, 1);
9278 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9285 /* Move IT by a specified amount of pixel lines DY. DY negative means
9286 move backwards. DY = 0 means move to start of screen line. At the
9287 end, IT will be on the start of a screen line. */
9290 move_it_vertically (struct it
*it
, int dy
)
9293 move_it_vertically_backward (it
, -dy
);
9296 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9297 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9298 MOVE_TO_POS
| MOVE_TO_Y
);
9299 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9301 /* If buffer ends in ZV without a newline, move to the start of
9302 the line to satisfy the post-condition. */
9303 if (IT_CHARPOS (*it
) == ZV
9305 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9306 move_it_by_lines (it
, 0);
9311 /* Move iterator IT past the end of the text line it is in. */
9314 move_it_past_eol (struct it
*it
)
9316 enum move_it_result rc
;
9318 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9319 if (rc
== MOVE_NEWLINE_OR_CR
)
9320 set_iterator_to_next (it
, 0);
9324 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9325 negative means move up. DVPOS == 0 means move to the start of the
9328 Optimization idea: If we would know that IT->f doesn't use
9329 a face with proportional font, we could be faster for
9330 truncate-lines nil. */
9333 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9336 /* The commented-out optimization uses vmotion on terminals. This
9337 gives bad results, because elements like it->what, on which
9338 callers such as pos_visible_p rely, aren't updated. */
9339 /* struct position pos;
9340 if (!FRAME_WINDOW_P (it->f))
9342 struct text_pos textpos;
9344 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9345 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9346 reseat (it, textpos, 1);
9347 it->vpos += pos.vpos;
9348 it->current_y += pos.vpos;
9354 /* DVPOS == 0 means move to the start of the screen line. */
9355 move_it_vertically_backward (it
, 0);
9356 /* Let next call to line_bottom_y calculate real line height */
9361 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9362 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9364 /* Only move to the next buffer position if we ended up in a
9365 string from display property, not in an overlay string
9366 (before-string or after-string). That is because the
9367 latter don't conceal the underlying buffer position, so
9368 we can ask to move the iterator to the exact position we
9369 are interested in. Note that, even if we are already at
9370 IT_CHARPOS (*it), the call below is not a no-op, as it
9371 will detect that we are at the end of the string, pop the
9372 iterator, and compute it->current_x and it->hpos
9374 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9375 -1, -1, -1, MOVE_TO_POS
);
9381 void *it2data
= NULL
;
9382 ptrdiff_t start_charpos
, i
;
9384 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9385 ptrdiff_t pos_limit
;
9387 /* Start at the beginning of the screen line containing IT's
9388 position. This may actually move vertically backwards,
9389 in case of overlays, so adjust dvpos accordingly. */
9391 move_it_vertically_backward (it
, 0);
9394 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9395 screen lines, and reseat the iterator there. */
9396 start_charpos
= IT_CHARPOS (*it
);
9397 if (it
->line_wrap
== TRUNCATE
)
9400 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9401 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9402 back_to_previous_visible_line_start (it
);
9403 reseat (it
, it
->current
.pos
, 1);
9405 /* Move further back if we end up in a string or an image. */
9406 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9408 /* First try to move to start of display line. */
9410 move_it_vertically_backward (it
, 0);
9412 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9414 /* If start of line is still in string or image,
9415 move further back. */
9416 back_to_previous_visible_line_start (it
);
9417 reseat (it
, it
->current
.pos
, 1);
9421 it
->current_x
= it
->hpos
= 0;
9423 /* Above call may have moved too far if continuation lines
9424 are involved. Scan forward and see if it did. */
9425 SAVE_IT (it2
, *it
, it2data
);
9426 it2
.vpos
= it2
.current_y
= 0;
9427 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9428 it
->vpos
-= it2
.vpos
;
9429 it
->current_y
-= it2
.current_y
;
9430 it
->current_x
= it
->hpos
= 0;
9432 /* If we moved too far back, move IT some lines forward. */
9433 if (it2
.vpos
> -dvpos
)
9435 int delta
= it2
.vpos
+ dvpos
;
9437 RESTORE_IT (&it2
, &it2
, it2data
);
9438 SAVE_IT (it2
, *it
, it2data
);
9439 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9440 /* Move back again if we got too far ahead. */
9441 if (IT_CHARPOS (*it
) >= start_charpos
)
9442 RESTORE_IT (it
, &it2
, it2data
);
9444 bidi_unshelve_cache (it2data
, 1);
9447 RESTORE_IT (it
, it
, it2data
);
9451 /* Return 1 if IT points into the middle of a display vector. */
9454 in_display_vector_p (struct it
*it
)
9456 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9457 && it
->current
.dpvec_index
> 0
9458 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9462 /***********************************************************************
9464 ***********************************************************************/
9467 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9471 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9473 Lisp_Object args
[3];
9474 Lisp_Object msg
, fmt
;
9477 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9481 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9483 args
[0] = fmt
= build_string (format
);
9486 msg
= Fformat (3, args
);
9488 len
= SBYTES (msg
) + 1;
9489 buffer
= SAFE_ALLOCA (len
);
9490 memcpy (buffer
, SDATA (msg
), len
);
9492 message_dolog (buffer
, len
- 1, 1, 0);
9499 /* Output a newline in the *Messages* buffer if "needs" one. */
9502 message_log_maybe_newline (void)
9504 if (message_log_need_newline
)
9505 message_dolog ("", 0, 1, 0);
9509 /* Add a string M of length NBYTES to the message log, optionally
9510 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9511 true, means interpret the contents of M as multibyte. This
9512 function calls low-level routines in order to bypass text property
9513 hooks, etc. which might not be safe to run.
9515 This may GC (insert may run before/after change hooks),
9516 so the buffer M must NOT point to a Lisp string. */
9519 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9521 const unsigned char *msg
= (const unsigned char *) m
;
9523 if (!NILP (Vmemory_full
))
9526 if (!NILP (Vmessage_log_max
))
9528 struct buffer
*oldbuf
;
9529 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9530 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9531 ptrdiff_t point_at_end
= 0;
9532 ptrdiff_t zv_at_end
= 0;
9533 Lisp_Object old_deactivate_mark
;
9535 struct gcpro gcpro1
;
9537 old_deactivate_mark
= Vdeactivate_mark
;
9538 oldbuf
= current_buffer
;
9540 /* Ensure the Messages buffer exists, and switch to it.
9541 If we created it, set the major-mode. */
9544 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9546 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9549 !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9550 call0 (intern ("messages-buffer-mode"));
9553 bset_undo_list (current_buffer
, Qt
);
9555 oldpoint
= message_dolog_marker1
;
9556 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9557 oldbegv
= message_dolog_marker2
;
9558 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9559 oldzv
= message_dolog_marker3
;
9560 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9561 GCPRO1 (old_deactivate_mark
);
9569 BEGV_BYTE
= BEG_BYTE
;
9572 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9574 /* Insert the string--maybe converting multibyte to single byte
9575 or vice versa, so that all the text fits the buffer. */
9577 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9583 /* Convert a multibyte string to single-byte
9584 for the *Message* buffer. */
9585 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9587 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9588 work
[0] = (ASCII_CHAR_P (c
)
9590 : multibyte_char_to_unibyte (c
));
9591 insert_1_both (work
, 1, 1, 1, 0, 0);
9594 else if (! multibyte
9595 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9599 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9600 /* Convert a single-byte string to multibyte
9601 for the *Message* buffer. */
9602 for (i
= 0; i
< nbytes
; i
++)
9605 MAKE_CHAR_MULTIBYTE (c
);
9606 char_bytes
= CHAR_STRING (c
, str
);
9607 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9611 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9615 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9618 insert_1_both ("\n", 1, 1, 1, 0, 0);
9620 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9622 this_bol_byte
= PT_BYTE
;
9624 /* See if this line duplicates the previous one.
9625 If so, combine duplicates. */
9628 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9630 prev_bol_byte
= PT_BYTE
;
9632 dups
= message_log_check_duplicate (prev_bol_byte
,
9636 del_range_both (prev_bol
, prev_bol_byte
,
9637 this_bol
, this_bol_byte
, 0);
9640 char dupstr
[sizeof " [ times]"
9641 + INT_STRLEN_BOUND (printmax_t
)];
9643 /* If you change this format, don't forget to also
9644 change message_log_check_duplicate. */
9645 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9646 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9647 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9652 /* If we have more than the desired maximum number of lines
9653 in the *Messages* buffer now, delete the oldest ones.
9654 This is safe because we don't have undo in this buffer. */
9656 if (NATNUMP (Vmessage_log_max
))
9658 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9659 -XFASTINT (Vmessage_log_max
) - 1, 0);
9660 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9663 BEGV
= marker_position (oldbegv
);
9664 BEGV_BYTE
= marker_byte_position (oldbegv
);
9673 ZV
= marker_position (oldzv
);
9674 ZV_BYTE
= marker_byte_position (oldzv
);
9678 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9680 /* We can't do Fgoto_char (oldpoint) because it will run some
9682 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9683 marker_byte_position (oldpoint
));
9686 unchain_marker (XMARKER (oldpoint
));
9687 unchain_marker (XMARKER (oldbegv
));
9688 unchain_marker (XMARKER (oldzv
));
9690 shown
= buffer_window_count (current_buffer
) > 0;
9691 set_buffer_internal (oldbuf
);
9692 /* We called insert_1_both above with its 5th argument (PREPARE)
9693 zero, which prevents insert_1_both from calling
9694 prepare_to_modify_buffer, which in turns prevents us from
9695 incrementing windows_or_buffers_changed even if *Messages* is
9696 shown in some window. So we must manually incrementing
9697 windows_or_buffers_changed here to make up for that. */
9699 windows_or_buffers_changed
++;
9701 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9702 message_log_need_newline
= !nlflag
;
9703 Vdeactivate_mark
= old_deactivate_mark
;
9708 /* We are at the end of the buffer after just having inserted a newline.
9709 (Note: We depend on the fact we won't be crossing the gap.)
9710 Check to see if the most recent message looks a lot like the previous one.
9711 Return 0 if different, 1 if the new one should just replace it, or a
9712 value N > 1 if we should also append " [N times]". */
9715 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9718 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9720 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9721 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9723 for (i
= 0; i
< len
; i
++)
9725 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9733 if (*p1
++ == ' ' && *p1
++ == '[')
9736 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9737 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9744 /* Display an echo area message M with a specified length of NBYTES
9745 bytes. The string may include null characters. If M is not a
9746 string, clear out any existing message, and let the mini-buffer
9749 This function cancels echoing. */
9752 message3 (Lisp_Object m
)
9754 struct gcpro gcpro1
;
9757 clear_message (1,1);
9760 /* First flush out any partial line written with print. */
9761 message_log_maybe_newline ();
9764 ptrdiff_t nbytes
= SBYTES (m
);
9765 bool multibyte
= STRING_MULTIBYTE (m
);
9767 char *buffer
= SAFE_ALLOCA (nbytes
);
9768 memcpy (buffer
, SDATA (m
), nbytes
);
9769 message_dolog (buffer
, nbytes
, 1, multibyte
);
9778 /* The non-logging version of message3.
9779 This does not cancel echoing, because it is used for echoing.
9780 Perhaps we need to make a separate function for echoing
9781 and make this cancel echoing. */
9784 message3_nolog (Lisp_Object m
)
9786 struct frame
*sf
= SELECTED_FRAME ();
9788 if (FRAME_INITIAL_P (sf
))
9790 if (noninteractive_need_newline
)
9791 putc ('\n', stderr
);
9792 noninteractive_need_newline
= 0;
9794 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9795 if (cursor_in_echo_area
== 0)
9796 fprintf (stderr
, "\n");
9799 /* Error messages get reported properly by cmd_error, so this must be just an
9800 informative message; if the frame hasn't really been initialized yet, just
9802 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9804 /* Get the frame containing the mini-buffer
9805 that the selected frame is using. */
9806 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9807 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9808 struct frame
*f
= XFRAME (frame
);
9810 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9811 Fmake_frame_visible (frame
);
9813 if (STRINGP (m
) && SCHARS (m
) > 0)
9816 if (minibuffer_auto_raise
)
9817 Fraise_frame (frame
);
9818 /* Assume we are not echoing.
9819 (If we are, echo_now will override this.) */
9820 echo_message_buffer
= Qnil
;
9823 clear_message (1, 1);
9825 do_pending_window_change (0);
9826 echo_area_display (1);
9827 do_pending_window_change (0);
9828 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9829 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9834 /* Display a null-terminated echo area message M. If M is 0, clear
9835 out any existing message, and let the mini-buffer text show through.
9837 The buffer M must continue to exist until after the echo area gets
9838 cleared or some other message gets displayed there. Do not pass
9839 text that is stored in a Lisp string. Do not pass text in a buffer
9840 that was alloca'd. */
9843 message1 (const char *m
)
9845 message3 (m
? build_unibyte_string (m
) : Qnil
);
9849 /* The non-logging counterpart of message1. */
9852 message1_nolog (const char *m
)
9854 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9857 /* Display a message M which contains a single %s
9858 which gets replaced with STRING. */
9861 message_with_string (const char *m
, Lisp_Object string
, int log
)
9863 CHECK_STRING (string
);
9869 if (noninteractive_need_newline
)
9870 putc ('\n', stderr
);
9871 noninteractive_need_newline
= 0;
9872 fprintf (stderr
, m
, SDATA (string
));
9873 if (!cursor_in_echo_area
)
9874 fprintf (stderr
, "\n");
9878 else if (INTERACTIVE
)
9880 /* The frame whose minibuffer we're going to display the message on.
9881 It may be larger than the selected frame, so we need
9882 to use its buffer, not the selected frame's buffer. */
9883 Lisp_Object mini_window
;
9884 struct frame
*f
, *sf
= SELECTED_FRAME ();
9886 /* Get the frame containing the minibuffer
9887 that the selected frame is using. */
9888 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9889 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9891 /* Error messages get reported properly by cmd_error, so this must be
9892 just an informative message; if the frame hasn't really been
9893 initialized yet, just toss it. */
9894 if (f
->glyphs_initialized_p
)
9896 Lisp_Object args
[2], msg
;
9897 struct gcpro gcpro1
, gcpro2
;
9899 args
[0] = build_string (m
);
9900 args
[1] = msg
= string
;
9901 GCPRO2 (args
[0], msg
);
9904 msg
= Fformat (2, args
);
9909 message3_nolog (msg
);
9913 /* Print should start at the beginning of the message
9914 buffer next time. */
9915 message_buf_print
= 0;
9921 /* Dump an informative message to the minibuf. If M is 0, clear out
9922 any existing message, and let the mini-buffer text show through. */
9925 vmessage (const char *m
, va_list ap
)
9931 if (noninteractive_need_newline
)
9932 putc ('\n', stderr
);
9933 noninteractive_need_newline
= 0;
9934 vfprintf (stderr
, m
, ap
);
9935 if (cursor_in_echo_area
== 0)
9936 fprintf (stderr
, "\n");
9940 else if (INTERACTIVE
)
9942 /* The frame whose mini-buffer we're going to display the message
9943 on. It may be larger than the selected frame, so we need to
9944 use its buffer, not the selected frame's buffer. */
9945 Lisp_Object mini_window
;
9946 struct frame
*f
, *sf
= SELECTED_FRAME ();
9948 /* Get the frame containing the mini-buffer
9949 that the selected frame is using. */
9950 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9951 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9953 /* Error messages get reported properly by cmd_error, so this must be
9954 just an informative message; if the frame hasn't really been
9955 initialized yet, just toss it. */
9956 if (f
->glyphs_initialized_p
)
9961 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9962 char *message_buf
= alloca (maxsize
+ 1);
9964 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9966 message3 (make_string (message_buf
, len
));
9971 /* Print should start at the beginning of the message
9972 buffer next time. */
9973 message_buf_print
= 0;
9979 message (const char *m
, ...)
9989 /* The non-logging version of message. */
9992 message_nolog (const char *m
, ...)
9994 Lisp_Object old_log_max
;
9997 old_log_max
= Vmessage_log_max
;
9998 Vmessage_log_max
= Qnil
;
10000 Vmessage_log_max
= old_log_max
;
10006 /* Display the current message in the current mini-buffer. This is
10007 only called from error handlers in process.c, and is not time
10011 update_echo_area (void)
10013 if (!NILP (echo_area_buffer
[0]))
10015 Lisp_Object string
;
10016 string
= Fcurrent_message ();
10022 /* Make sure echo area buffers in `echo_buffers' are live.
10023 If they aren't, make new ones. */
10026 ensure_echo_area_buffers (void)
10030 for (i
= 0; i
< 2; ++i
)
10031 if (!BUFFERP (echo_buffer
[i
])
10032 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10035 Lisp_Object old_buffer
;
10038 old_buffer
= echo_buffer
[i
];
10039 echo_buffer
[i
] = Fget_buffer_create
10040 (make_formatted_string (name
, " *Echo Area %d*", i
));
10041 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10042 /* to force word wrap in echo area -
10043 it was decided to postpone this*/
10044 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10046 for (j
= 0; j
< 2; ++j
)
10047 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10048 echo_area_buffer
[j
] = echo_buffer
[i
];
10053 /* Call FN with args A1..A2 with either the current or last displayed
10054 echo_area_buffer as current buffer.
10056 WHICH zero means use the current message buffer
10057 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10058 from echo_buffer[] and clear it.
10060 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10061 suitable buffer from echo_buffer[] and clear it.
10063 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10064 that the current message becomes the last displayed one, make
10065 choose a suitable buffer for echo_area_buffer[0], and clear it.
10067 Value is what FN returns. */
10070 with_echo_area_buffer (struct window
*w
, int which
,
10071 int (*fn
) (ptrdiff_t, Lisp_Object
),
10072 ptrdiff_t a1
, Lisp_Object a2
)
10074 Lisp_Object buffer
;
10075 int this_one
, the_other
, clear_buffer_p
, rc
;
10076 ptrdiff_t count
= SPECPDL_INDEX ();
10078 /* If buffers aren't live, make new ones. */
10079 ensure_echo_area_buffers ();
10081 clear_buffer_p
= 0;
10084 this_one
= 0, the_other
= 1;
10085 else if (which
> 0)
10086 this_one
= 1, the_other
= 0;
10089 this_one
= 0, the_other
= 1;
10090 clear_buffer_p
= 1;
10092 /* We need a fresh one in case the current echo buffer equals
10093 the one containing the last displayed echo area message. */
10094 if (!NILP (echo_area_buffer
[this_one
])
10095 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10096 echo_area_buffer
[this_one
] = Qnil
;
10099 /* Choose a suitable buffer from echo_buffer[] is we don't
10101 if (NILP (echo_area_buffer
[this_one
]))
10103 echo_area_buffer
[this_one
]
10104 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10105 ? echo_buffer
[the_other
]
10106 : echo_buffer
[this_one
]);
10107 clear_buffer_p
= 1;
10110 buffer
= echo_area_buffer
[this_one
];
10112 /* Don't get confused by reusing the buffer used for echoing
10113 for a different purpose. */
10114 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10117 record_unwind_protect (unwind_with_echo_area_buffer
,
10118 with_echo_area_buffer_unwind_data (w
));
10120 /* Make the echo area buffer current. Note that for display
10121 purposes, it is not necessary that the displayed window's buffer
10122 == current_buffer, except for text property lookup. So, let's
10123 only set that buffer temporarily here without doing a full
10124 Fset_window_buffer. We must also change w->pointm, though,
10125 because otherwise an assertions in unshow_buffer fails, and Emacs
10127 set_buffer_internal_1 (XBUFFER (buffer
));
10130 wset_buffer (w
, buffer
);
10131 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10134 bset_undo_list (current_buffer
, Qt
);
10135 bset_read_only (current_buffer
, Qnil
);
10136 specbind (Qinhibit_read_only
, Qt
);
10137 specbind (Qinhibit_modification_hooks
, Qt
);
10139 if (clear_buffer_p
&& Z
> BEG
)
10140 del_range (BEG
, Z
);
10142 eassert (BEGV
>= BEG
);
10143 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10147 eassert (BEGV
>= BEG
);
10148 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10150 unbind_to (count
, Qnil
);
10155 /* Save state that should be preserved around the call to the function
10156 FN called in with_echo_area_buffer. */
10159 with_echo_area_buffer_unwind_data (struct window
*w
)
10162 Lisp_Object vector
, tmp
;
10164 /* Reduce consing by keeping one vector in
10165 Vwith_echo_area_save_vector. */
10166 vector
= Vwith_echo_area_save_vector
;
10167 Vwith_echo_area_save_vector
= Qnil
;
10170 vector
= Fmake_vector (make_number (9), Qnil
);
10172 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10173 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10174 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10178 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10179 ASET (vector
, i
, w
->contents
); ++i
;
10180 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10181 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10182 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10183 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10188 for (; i
< end
; ++i
)
10189 ASET (vector
, i
, Qnil
);
10192 eassert (i
== ASIZE (vector
));
10197 /* Restore global state from VECTOR which was created by
10198 with_echo_area_buffer_unwind_data. */
10201 unwind_with_echo_area_buffer (Lisp_Object vector
)
10203 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10204 Vdeactivate_mark
= AREF (vector
, 1);
10205 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10207 if (WINDOWP (AREF (vector
, 3)))
10210 Lisp_Object buffer
;
10212 w
= XWINDOW (AREF (vector
, 3));
10213 buffer
= AREF (vector
, 4);
10215 wset_buffer (w
, buffer
);
10216 set_marker_both (w
->pointm
, buffer
,
10217 XFASTINT (AREF (vector
, 5)),
10218 XFASTINT (AREF (vector
, 6)));
10219 set_marker_both (w
->start
, buffer
,
10220 XFASTINT (AREF (vector
, 7)),
10221 XFASTINT (AREF (vector
, 8)));
10224 Vwith_echo_area_save_vector
= vector
;
10228 /* Set up the echo area for use by print functions. MULTIBYTE_P
10229 non-zero means we will print multibyte. */
10232 setup_echo_area_for_printing (int multibyte_p
)
10234 /* If we can't find an echo area any more, exit. */
10235 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10236 Fkill_emacs (Qnil
);
10238 ensure_echo_area_buffers ();
10240 if (!message_buf_print
)
10242 /* A message has been output since the last time we printed.
10243 Choose a fresh echo area buffer. */
10244 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10245 echo_area_buffer
[0] = echo_buffer
[1];
10247 echo_area_buffer
[0] = echo_buffer
[0];
10249 /* Switch to that buffer and clear it. */
10250 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10251 bset_truncate_lines (current_buffer
, Qnil
);
10255 ptrdiff_t count
= SPECPDL_INDEX ();
10256 specbind (Qinhibit_read_only
, Qt
);
10257 /* Note that undo recording is always disabled. */
10258 del_range (BEG
, Z
);
10259 unbind_to (count
, Qnil
);
10261 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10263 /* Set up the buffer for the multibyteness we need. */
10265 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10266 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10268 /* Raise the frame containing the echo area. */
10269 if (minibuffer_auto_raise
)
10271 struct frame
*sf
= SELECTED_FRAME ();
10272 Lisp_Object mini_window
;
10273 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10274 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10277 message_log_maybe_newline ();
10278 message_buf_print
= 1;
10282 if (NILP (echo_area_buffer
[0]))
10284 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10285 echo_area_buffer
[0] = echo_buffer
[1];
10287 echo_area_buffer
[0] = echo_buffer
[0];
10290 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10292 /* Someone switched buffers between print requests. */
10293 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10294 bset_truncate_lines (current_buffer
, Qnil
);
10300 /* Display an echo area message in window W. Value is non-zero if W's
10301 height is changed. If display_last_displayed_message_p is
10302 non-zero, display the message that was last displayed, otherwise
10303 display the current message. */
10306 display_echo_area (struct window
*w
)
10308 int i
, no_message_p
, window_height_changed_p
;
10310 /* Temporarily disable garbage collections while displaying the echo
10311 area. This is done because a GC can print a message itself.
10312 That message would modify the echo area buffer's contents while a
10313 redisplay of the buffer is going on, and seriously confuse
10315 ptrdiff_t count
= inhibit_garbage_collection ();
10317 /* If there is no message, we must call display_echo_area_1
10318 nevertheless because it resizes the window. But we will have to
10319 reset the echo_area_buffer in question to nil at the end because
10320 with_echo_area_buffer will sets it to an empty buffer. */
10321 i
= display_last_displayed_message_p
? 1 : 0;
10322 no_message_p
= NILP (echo_area_buffer
[i
]);
10324 window_height_changed_p
10325 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10326 display_echo_area_1
,
10327 (intptr_t) w
, Qnil
);
10330 echo_area_buffer
[i
] = Qnil
;
10332 unbind_to (count
, Qnil
);
10333 return window_height_changed_p
;
10337 /* Helper for display_echo_area. Display the current buffer which
10338 contains the current echo area message in window W, a mini-window,
10339 a pointer to which is passed in A1. A2..A4 are currently not used.
10340 Change the height of W so that all of the message is displayed.
10341 Value is non-zero if height of W was changed. */
10344 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10347 struct window
*w
= (struct window
*) i1
;
10348 Lisp_Object window
;
10349 struct text_pos start
;
10350 int window_height_changed_p
= 0;
10352 /* Do this before displaying, so that we have a large enough glyph
10353 matrix for the display. If we can't get enough space for the
10354 whole text, display the last N lines. That works by setting w->start. */
10355 window_height_changed_p
= resize_mini_window (w
, 0);
10357 /* Use the starting position chosen by resize_mini_window. */
10358 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10361 clear_glyph_matrix (w
->desired_matrix
);
10362 XSETWINDOW (window
, w
);
10363 try_window (window
, start
, 0);
10365 return window_height_changed_p
;
10369 /* Resize the echo area window to exactly the size needed for the
10370 currently displayed message, if there is one. If a mini-buffer
10371 is active, don't shrink it. */
10374 resize_echo_area_exactly (void)
10376 if (BUFFERP (echo_area_buffer
[0])
10377 && WINDOWP (echo_area_window
))
10379 struct window
*w
= XWINDOW (echo_area_window
);
10381 Lisp_Object resize_exactly
;
10383 if (minibuf_level
== 0)
10384 resize_exactly
= Qt
;
10386 resize_exactly
= Qnil
;
10388 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10389 (intptr_t) w
, resize_exactly
);
10392 ++windows_or_buffers_changed
;
10393 ++update_mode_lines
;
10394 redisplay_internal ();
10400 /* Callback function for with_echo_area_buffer, when used from
10401 resize_echo_area_exactly. A1 contains a pointer to the window to
10402 resize, EXACTLY non-nil means resize the mini-window exactly to the
10403 size of the text displayed. A3 and A4 are not used. Value is what
10404 resize_mini_window returns. */
10407 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10410 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10414 /* Resize mini-window W to fit the size of its contents. EXACT_P
10415 means size the window exactly to the size needed. Otherwise, it's
10416 only enlarged until W's buffer is empty.
10418 Set W->start to the right place to begin display. If the whole
10419 contents fit, start at the beginning. Otherwise, start so as
10420 to make the end of the contents appear. This is particularly
10421 important for y-or-n-p, but seems desirable generally.
10423 Value is non-zero if the window height has been changed. */
10426 resize_mini_window (struct window
*w
, int exact_p
)
10428 struct frame
*f
= XFRAME (w
->frame
);
10429 int window_height_changed_p
= 0;
10431 eassert (MINI_WINDOW_P (w
));
10433 /* By default, start display at the beginning. */
10434 set_marker_both (w
->start
, w
->contents
,
10435 BUF_BEGV (XBUFFER (w
->contents
)),
10436 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10438 /* Don't resize windows while redisplaying a window; it would
10439 confuse redisplay functions when the size of the window they are
10440 displaying changes from under them. Such a resizing can happen,
10441 for instance, when which-func prints a long message while
10442 we are running fontification-functions. We're running these
10443 functions with safe_call which binds inhibit-redisplay to t. */
10444 if (!NILP (Vinhibit_redisplay
))
10447 /* Nil means don't try to resize. */
10448 if (NILP (Vresize_mini_windows
)
10449 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10452 if (!FRAME_MINIBUF_ONLY_P (f
))
10455 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10456 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10458 EMACS_INT max_height
;
10459 int unit
= FRAME_LINE_HEIGHT (f
);
10460 struct text_pos start
;
10461 struct buffer
*old_current_buffer
= NULL
;
10463 if (current_buffer
!= XBUFFER (w
->contents
))
10465 old_current_buffer
= current_buffer
;
10466 set_buffer_internal (XBUFFER (w
->contents
));
10469 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10471 /* Compute the max. number of lines specified by the user. */
10472 if (FLOATP (Vmax_mini_window_height
))
10473 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10474 else if (INTEGERP (Vmax_mini_window_height
))
10475 max_height
= XINT (Vmax_mini_window_height
);
10477 max_height
= total_height
/ 4;
10479 /* Correct that max. height if it's bogus. */
10480 max_height
= clip_to_bounds (1, max_height
, total_height
);
10482 /* Find out the height of the text in the window. */
10483 if (it
.line_wrap
== TRUNCATE
)
10488 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10489 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10490 height
= it
.current_y
+ last_height
;
10492 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10493 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10494 height
= (height
+ unit
- 1) / unit
;
10497 /* Compute a suitable window start. */
10498 if (height
> max_height
)
10500 height
= max_height
;
10501 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10502 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10503 start
= it
.current
.pos
;
10506 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10507 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10509 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10511 /* Let it grow only, until we display an empty message, in which
10512 case the window shrinks again. */
10513 if (height
> WINDOW_TOTAL_LINES (w
))
10515 int old_height
= WINDOW_TOTAL_LINES (w
);
10517 FRAME_WINDOWS_FROZEN (f
) = 1;
10518 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10519 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10521 else if (height
< WINDOW_TOTAL_LINES (w
)
10522 && (exact_p
|| BEGV
== ZV
))
10524 int old_height
= WINDOW_TOTAL_LINES (w
);
10526 FRAME_WINDOWS_FROZEN (f
) = 0;
10527 shrink_mini_window (w
);
10528 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10533 /* Always resize to exact size needed. */
10534 if (height
> WINDOW_TOTAL_LINES (w
))
10536 int old_height
= WINDOW_TOTAL_LINES (w
);
10538 FRAME_WINDOWS_FROZEN (f
) = 1;
10539 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10540 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10542 else if (height
< WINDOW_TOTAL_LINES (w
))
10544 int old_height
= WINDOW_TOTAL_LINES (w
);
10546 FRAME_WINDOWS_FROZEN (f
) = 0;
10547 shrink_mini_window (w
);
10551 FRAME_WINDOWS_FROZEN (f
) = 1;
10552 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10555 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10559 if (old_current_buffer
)
10560 set_buffer_internal (old_current_buffer
);
10563 return window_height_changed_p
;
10567 /* Value is the current message, a string, or nil if there is no
10568 current message. */
10571 current_message (void)
10575 if (!BUFFERP (echo_area_buffer
[0]))
10579 with_echo_area_buffer (0, 0, current_message_1
,
10580 (intptr_t) &msg
, Qnil
);
10582 echo_area_buffer
[0] = Qnil
;
10590 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10593 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10596 *msg
= make_buffer_string (BEG
, Z
, 1);
10603 /* Push the current message on Vmessage_stack for later restoration
10604 by restore_message. Value is non-zero if the current message isn't
10605 empty. This is a relatively infrequent operation, so it's not
10606 worth optimizing. */
10609 push_message (void)
10611 Lisp_Object msg
= current_message ();
10612 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10613 return STRINGP (msg
);
10617 /* Restore message display from the top of Vmessage_stack. */
10620 restore_message (void)
10622 eassert (CONSP (Vmessage_stack
));
10623 message3_nolog (XCAR (Vmessage_stack
));
10627 /* Handler for unwind-protect calling pop_message. */
10630 pop_message_unwind (void)
10632 /* Pop the top-most entry off Vmessage_stack. */
10633 eassert (CONSP (Vmessage_stack
));
10634 Vmessage_stack
= XCDR (Vmessage_stack
);
10638 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10639 exits. If the stack is not empty, we have a missing pop_message
10643 check_message_stack (void)
10645 if (!NILP (Vmessage_stack
))
10650 /* Truncate to NCHARS what will be displayed in the echo area the next
10651 time we display it---but don't redisplay it now. */
10654 truncate_echo_area (ptrdiff_t nchars
)
10657 echo_area_buffer
[0] = Qnil
;
10658 else if (!noninteractive
10660 && !NILP (echo_area_buffer
[0]))
10662 struct frame
*sf
= SELECTED_FRAME ();
10663 /* Error messages get reported properly by cmd_error, so this must be
10664 just an informative message; if the frame hasn't really been
10665 initialized yet, just toss it. */
10666 if (sf
->glyphs_initialized_p
)
10667 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10672 /* Helper function for truncate_echo_area. Truncate the current
10673 message to at most NCHARS characters. */
10676 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10678 if (BEG
+ nchars
< Z
)
10679 del_range (BEG
+ nchars
, Z
);
10681 echo_area_buffer
[0] = Qnil
;
10685 /* Set the current message to STRING. */
10688 set_message (Lisp_Object string
)
10690 eassert (STRINGP (string
));
10692 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10694 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10695 message_buf_print
= 0;
10696 help_echo_showing_p
= 0;
10698 if (STRINGP (Vdebug_on_message
)
10699 && STRINGP (string
)
10700 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10701 call_debugger (list2 (Qerror
, string
));
10705 /* Helper function for set_message. First argument is ignored and second
10706 argument has the same meaning as for set_message.
10707 This function is called with the echo area buffer being current. */
10710 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10712 eassert (STRINGP (string
));
10714 /* Change multibyteness of the echo buffer appropriately. */
10715 if (message_enable_multibyte
10716 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10717 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10719 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10720 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10721 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10723 /* Insert new message at BEG. */
10724 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10726 /* This function takes care of single/multibyte conversion.
10727 We just have to ensure that the echo area buffer has the right
10728 setting of enable_multibyte_characters. */
10729 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10735 /* Clear messages. CURRENT_P non-zero means clear the current
10736 message. LAST_DISPLAYED_P non-zero means clear the message
10740 clear_message (int current_p
, int last_displayed_p
)
10744 echo_area_buffer
[0] = Qnil
;
10745 message_cleared_p
= 1;
10748 if (last_displayed_p
)
10749 echo_area_buffer
[1] = Qnil
;
10751 message_buf_print
= 0;
10754 /* Clear garbaged frames.
10756 This function is used where the old redisplay called
10757 redraw_garbaged_frames which in turn called redraw_frame which in
10758 turn called clear_frame. The call to clear_frame was a source of
10759 flickering. I believe a clear_frame is not necessary. It should
10760 suffice in the new redisplay to invalidate all current matrices,
10761 and ensure a complete redisplay of all windows. */
10764 clear_garbaged_frames (void)
10766 if (frame_garbaged
)
10768 Lisp_Object tail
, frame
;
10769 int changed_count
= 0;
10771 FOR_EACH_FRAME (tail
, frame
)
10773 struct frame
*f
= XFRAME (frame
);
10775 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10780 clear_current_matrices (f
);
10787 frame_garbaged
= 0;
10789 ++windows_or_buffers_changed
;
10794 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10795 is non-zero update selected_frame. Value is non-zero if the
10796 mini-windows height has been changed. */
10799 echo_area_display (int update_frame_p
)
10801 Lisp_Object mini_window
;
10804 int window_height_changed_p
= 0;
10805 struct frame
*sf
= SELECTED_FRAME ();
10807 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10808 w
= XWINDOW (mini_window
);
10809 f
= XFRAME (WINDOW_FRAME (w
));
10811 /* Don't display if frame is invisible or not yet initialized. */
10812 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10815 #ifdef HAVE_WINDOW_SYSTEM
10816 /* When Emacs starts, selected_frame may be the initial terminal
10817 frame. If we let this through, a message would be displayed on
10819 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10821 #endif /* HAVE_WINDOW_SYSTEM */
10823 /* Redraw garbaged frames. */
10824 clear_garbaged_frames ();
10826 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10828 echo_area_window
= mini_window
;
10829 window_height_changed_p
= display_echo_area (w
);
10830 w
->must_be_updated_p
= 1;
10832 /* Update the display, unless called from redisplay_internal.
10833 Also don't update the screen during redisplay itself. The
10834 update will happen at the end of redisplay, and an update
10835 here could cause confusion. */
10836 if (update_frame_p
&& !redisplaying_p
)
10840 /* If the display update has been interrupted by pending
10841 input, update mode lines in the frame. Due to the
10842 pending input, it might have been that redisplay hasn't
10843 been called, so that mode lines above the echo area are
10844 garbaged. This looks odd, so we prevent it here. */
10845 if (!display_completed
)
10846 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10848 if (window_height_changed_p
10849 /* Don't do this if Emacs is shutting down. Redisplay
10850 needs to run hooks. */
10851 && !NILP (Vrun_hooks
))
10853 /* Must update other windows. Likewise as in other
10854 cases, don't let this update be interrupted by
10856 ptrdiff_t count
= SPECPDL_INDEX ();
10857 specbind (Qredisplay_dont_pause
, Qt
);
10858 windows_or_buffers_changed
= 1;
10859 redisplay_internal ();
10860 unbind_to (count
, Qnil
);
10862 else if (FRAME_WINDOW_P (f
) && n
== 0)
10864 /* Window configuration is the same as before.
10865 Can do with a display update of the echo area,
10866 unless we displayed some mode lines. */
10867 update_single_window (w
, 1);
10871 update_frame (f
, 1, 1);
10873 /* If cursor is in the echo area, make sure that the next
10874 redisplay displays the minibuffer, so that the cursor will
10875 be replaced with what the minibuffer wants. */
10876 if (cursor_in_echo_area
)
10877 ++windows_or_buffers_changed
;
10880 else if (!EQ (mini_window
, selected_window
))
10881 windows_or_buffers_changed
++;
10883 /* Last displayed message is now the current message. */
10884 echo_area_buffer
[1] = echo_area_buffer
[0];
10885 /* Inform read_char that we're not echoing. */
10886 echo_message_buffer
= Qnil
;
10888 /* Prevent redisplay optimization in redisplay_internal by resetting
10889 this_line_start_pos. This is done because the mini-buffer now
10890 displays the message instead of its buffer text. */
10891 if (EQ (mini_window
, selected_window
))
10892 CHARPOS (this_line_start_pos
) = 0;
10894 return window_height_changed_p
;
10897 /* Nonzero if the current window's buffer is shown in more than one
10898 window and was modified since last redisplay. */
10901 buffer_shared_and_changed (void)
10903 return (buffer_window_count (current_buffer
) > 1
10904 && UNCHANGED_MODIFIED
< MODIFF
);
10907 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10908 is enabled and mark of W's buffer was changed since last W's update. */
10911 window_buffer_changed (struct window
*w
)
10913 struct buffer
*b
= XBUFFER (w
->contents
);
10915 eassert (BUFFER_LIVE_P (b
));
10917 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10918 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10919 != (w
->region_showing
!= 0)));
10922 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10925 mode_line_update_needed (struct window
*w
)
10927 return (w
->column_number_displayed
!= -1
10928 && !(PT
== w
->last_point
&& !window_outdated (w
))
10929 && (w
->column_number_displayed
!= current_column ()));
10932 /* Nonzero if window start of W is frozen and may not be changed during
10936 window_frozen_p (struct window
*w
)
10938 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10940 Lisp_Object window
;
10942 XSETWINDOW (window
, w
);
10943 if (MINI_WINDOW_P (w
))
10945 else if (EQ (window
, selected_window
))
10947 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10948 && EQ (window
, Vminibuf_scroll_window
))
10949 /* This special window can't be frozen too. */
10957 /***********************************************************************
10958 Mode Lines and Frame Titles
10959 ***********************************************************************/
10961 /* A buffer for constructing non-propertized mode-line strings and
10962 frame titles in it; allocated from the heap in init_xdisp and
10963 resized as needed in store_mode_line_noprop_char. */
10965 static char *mode_line_noprop_buf
;
10967 /* The buffer's end, and a current output position in it. */
10969 static char *mode_line_noprop_buf_end
;
10970 static char *mode_line_noprop_ptr
;
10972 #define MODE_LINE_NOPROP_LEN(start) \
10973 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10976 MODE_LINE_DISPLAY
= 0,
10980 } mode_line_target
;
10982 /* Alist that caches the results of :propertize.
10983 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10984 static Lisp_Object mode_line_proptrans_alist
;
10986 /* List of strings making up the mode-line. */
10987 static Lisp_Object mode_line_string_list
;
10989 /* Base face property when building propertized mode line string. */
10990 static Lisp_Object mode_line_string_face
;
10991 static Lisp_Object mode_line_string_face_prop
;
10994 /* Unwind data for mode line strings */
10996 static Lisp_Object Vmode_line_unwind_vector
;
10999 format_mode_line_unwind_data (struct frame
*target_frame
,
11000 struct buffer
*obuf
,
11002 int save_proptrans
)
11004 Lisp_Object vector
, tmp
;
11006 /* Reduce consing by keeping one vector in
11007 Vwith_echo_area_save_vector. */
11008 vector
= Vmode_line_unwind_vector
;
11009 Vmode_line_unwind_vector
= Qnil
;
11012 vector
= Fmake_vector (make_number (10), Qnil
);
11014 ASET (vector
, 0, make_number (mode_line_target
));
11015 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11016 ASET (vector
, 2, mode_line_string_list
);
11017 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11018 ASET (vector
, 4, mode_line_string_face
);
11019 ASET (vector
, 5, mode_line_string_face_prop
);
11022 XSETBUFFER (tmp
, obuf
);
11025 ASET (vector
, 6, tmp
);
11026 ASET (vector
, 7, owin
);
11029 /* Similarly to `with-selected-window', if the operation selects
11030 a window on another frame, we must restore that frame's
11031 selected window, and (for a tty) the top-frame. */
11032 ASET (vector
, 8, target_frame
->selected_window
);
11033 if (FRAME_TERMCAP_P (target_frame
))
11034 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11041 unwind_format_mode_line (Lisp_Object vector
)
11043 Lisp_Object old_window
= AREF (vector
, 7);
11044 Lisp_Object target_frame_window
= AREF (vector
, 8);
11045 Lisp_Object old_top_frame
= AREF (vector
, 9);
11047 mode_line_target
= XINT (AREF (vector
, 0));
11048 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11049 mode_line_string_list
= AREF (vector
, 2);
11050 if (! EQ (AREF (vector
, 3), Qt
))
11051 mode_line_proptrans_alist
= AREF (vector
, 3);
11052 mode_line_string_face
= AREF (vector
, 4);
11053 mode_line_string_face_prop
= AREF (vector
, 5);
11055 /* Select window before buffer, since it may change the buffer. */
11056 if (!NILP (old_window
))
11058 /* If the operation that we are unwinding had selected a window
11059 on a different frame, reset its frame-selected-window. For a
11060 text terminal, reset its top-frame if necessary. */
11061 if (!NILP (target_frame_window
))
11064 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11066 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11067 Fselect_window (target_frame_window
, Qt
);
11069 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11070 Fselect_frame (old_top_frame
, Qt
);
11073 Fselect_window (old_window
, Qt
);
11076 if (!NILP (AREF (vector
, 6)))
11078 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11079 ASET (vector
, 6, Qnil
);
11082 Vmode_line_unwind_vector
= vector
;
11086 /* Store a single character C for the frame title in mode_line_noprop_buf.
11087 Re-allocate mode_line_noprop_buf if necessary. */
11090 store_mode_line_noprop_char (char c
)
11092 /* If output position has reached the end of the allocated buffer,
11093 increase the buffer's size. */
11094 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11096 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11097 ptrdiff_t size
= len
;
11098 mode_line_noprop_buf
=
11099 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11100 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11101 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11104 *mode_line_noprop_ptr
++ = c
;
11108 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11109 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11110 characters that yield more columns than PRECISION; PRECISION <= 0
11111 means copy the whole string. Pad with spaces until FIELD_WIDTH
11112 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11113 pad. Called from display_mode_element when it is used to build a
11117 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11119 const unsigned char *str
= (const unsigned char *) string
;
11121 ptrdiff_t dummy
, nbytes
;
11123 /* Copy at most PRECISION chars from STR. */
11124 nbytes
= strlen (string
);
11125 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11127 store_mode_line_noprop_char (*str
++);
11129 /* Fill up with spaces until FIELD_WIDTH reached. */
11130 while (field_width
> 0
11131 && n
< field_width
)
11133 store_mode_line_noprop_char (' ');
11140 /***********************************************************************
11142 ***********************************************************************/
11144 #ifdef HAVE_WINDOW_SYSTEM
11146 /* Set the title of FRAME, if it has changed. The title format is
11147 Vicon_title_format if FRAME is iconified, otherwise it is
11148 frame_title_format. */
11151 x_consider_frame_title (Lisp_Object frame
)
11153 struct frame
*f
= XFRAME (frame
);
11155 if (FRAME_WINDOW_P (f
)
11156 || FRAME_MINIBUF_ONLY_P (f
)
11157 || f
->explicit_name
)
11159 /* Do we have more than one visible frame on this X display? */
11160 Lisp_Object tail
, other_frame
, fmt
;
11161 ptrdiff_t title_start
;
11165 ptrdiff_t count
= SPECPDL_INDEX ();
11167 FOR_EACH_FRAME (tail
, other_frame
)
11169 struct frame
*tf
= XFRAME (other_frame
);
11172 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11173 && !FRAME_MINIBUF_ONLY_P (tf
)
11174 && !EQ (other_frame
, tip_frame
)
11175 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11179 /* Set global variable indicating that multiple frames exist. */
11180 multiple_frames
= CONSP (tail
);
11182 /* Switch to the buffer of selected window of the frame. Set up
11183 mode_line_target so that display_mode_element will output into
11184 mode_line_noprop_buf; then display the title. */
11185 record_unwind_protect (unwind_format_mode_line
,
11186 format_mode_line_unwind_data
11187 (f
, current_buffer
, selected_window
, 0));
11189 Fselect_window (f
->selected_window
, Qt
);
11190 set_buffer_internal_1
11191 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11192 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11194 mode_line_target
= MODE_LINE_TITLE
;
11195 title_start
= MODE_LINE_NOPROP_LEN (0);
11196 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11197 NULL
, DEFAULT_FACE_ID
);
11198 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11199 len
= MODE_LINE_NOPROP_LEN (title_start
);
11200 title
= mode_line_noprop_buf
+ title_start
;
11201 unbind_to (count
, Qnil
);
11203 /* Set the title only if it's changed. This avoids consing in
11204 the common case where it hasn't. (If it turns out that we've
11205 already wasted too much time by walking through the list with
11206 display_mode_element, then we might need to optimize at a
11207 higher level than this.) */
11208 if (! STRINGP (f
->name
)
11209 || SBYTES (f
->name
) != len
11210 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11211 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11215 #endif /* not HAVE_WINDOW_SYSTEM */
11218 /***********************************************************************
11220 ***********************************************************************/
11223 /* Prepare for redisplay by updating menu-bar item lists when
11224 appropriate. This can call eval. */
11227 prepare_menu_bars (void)
11230 struct gcpro gcpro1
, gcpro2
;
11232 Lisp_Object tooltip_frame
;
11234 #ifdef HAVE_WINDOW_SYSTEM
11235 tooltip_frame
= tip_frame
;
11237 tooltip_frame
= Qnil
;
11240 /* Update all frame titles based on their buffer names, etc. We do
11241 this before the menu bars so that the buffer-menu will show the
11242 up-to-date frame titles. */
11243 #ifdef HAVE_WINDOW_SYSTEM
11244 if (windows_or_buffers_changed
|| update_mode_lines
)
11246 Lisp_Object tail
, frame
;
11248 FOR_EACH_FRAME (tail
, frame
)
11250 f
= XFRAME (frame
);
11251 if (!EQ (frame
, tooltip_frame
)
11252 && (FRAME_ICONIFIED_P (f
)
11253 || FRAME_VISIBLE_P (f
) == 1
11254 /* Exclude TTY frames that are obscured because they
11255 are not the top frame on their console. This is
11256 because x_consider_frame_title actually switches
11257 to the frame, which for TTY frames means it is
11258 marked as garbaged, and will be completely
11259 redrawn on the next redisplay cycle. This causes
11260 TTY frames to be completely redrawn, when there
11261 are more than one of them, even though nothing
11262 should be changed on display. */
11263 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11264 x_consider_frame_title (frame
);
11267 #endif /* HAVE_WINDOW_SYSTEM */
11269 /* Update the menu bar item lists, if appropriate. This has to be
11270 done before any actual redisplay or generation of display lines. */
11271 all_windows
= (update_mode_lines
11272 || buffer_shared_and_changed ()
11273 || windows_or_buffers_changed
);
11276 Lisp_Object tail
, frame
;
11277 ptrdiff_t count
= SPECPDL_INDEX ();
11278 /* 1 means that update_menu_bar has run its hooks
11279 so any further calls to update_menu_bar shouldn't do so again. */
11280 int menu_bar_hooks_run
= 0;
11282 record_unwind_save_match_data ();
11284 FOR_EACH_FRAME (tail
, frame
)
11286 f
= XFRAME (frame
);
11288 /* Ignore tooltip frame. */
11289 if (EQ (frame
, tooltip_frame
))
11292 /* If a window on this frame changed size, report that to
11293 the user and clear the size-change flag. */
11294 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11296 Lisp_Object functions
;
11298 /* Clear flag first in case we get an error below. */
11299 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11300 functions
= Vwindow_size_change_functions
;
11301 GCPRO2 (tail
, functions
);
11303 while (CONSP (functions
))
11305 if (!EQ (XCAR (functions
), Qt
))
11306 call1 (XCAR (functions
), frame
);
11307 functions
= XCDR (functions
);
11313 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11314 #ifdef HAVE_WINDOW_SYSTEM
11315 update_tool_bar (f
, 0);
11318 if (windows_or_buffers_changed
11321 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11326 unbind_to (count
, Qnil
);
11330 struct frame
*sf
= SELECTED_FRAME ();
11331 update_menu_bar (sf
, 1, 0);
11332 #ifdef HAVE_WINDOW_SYSTEM
11333 update_tool_bar (sf
, 1);
11339 /* Update the menu bar item list for frame F. This has to be done
11340 before we start to fill in any display lines, because it can call
11343 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11345 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11346 already ran the menu bar hooks for this redisplay, so there
11347 is no need to run them again. The return value is the
11348 updated value of this flag, to pass to the next call. */
11351 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11353 Lisp_Object window
;
11354 register struct window
*w
;
11356 /* If called recursively during a menu update, do nothing. This can
11357 happen when, for instance, an activate-menubar-hook causes a
11359 if (inhibit_menubar_update
)
11362 window
= FRAME_SELECTED_WINDOW (f
);
11363 w
= XWINDOW (window
);
11365 if (FRAME_WINDOW_P (f
)
11367 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11368 || defined (HAVE_NS) || defined (USE_GTK)
11369 FRAME_EXTERNAL_MENU_BAR (f
)
11371 FRAME_MENU_BAR_LINES (f
) > 0
11373 : FRAME_MENU_BAR_LINES (f
) > 0)
11375 /* If the user has switched buffers or windows, we need to
11376 recompute to reflect the new bindings. But we'll
11377 recompute when update_mode_lines is set too; that means
11378 that people can use force-mode-line-update to request
11379 that the menu bar be recomputed. The adverse effect on
11380 the rest of the redisplay algorithm is about the same as
11381 windows_or_buffers_changed anyway. */
11382 if (windows_or_buffers_changed
11383 /* This used to test w->update_mode_line, but we believe
11384 there is no need to recompute the menu in that case. */
11385 || update_mode_lines
11386 || window_buffer_changed (w
))
11388 struct buffer
*prev
= current_buffer
;
11389 ptrdiff_t count
= SPECPDL_INDEX ();
11391 specbind (Qinhibit_menubar_update
, Qt
);
11393 set_buffer_internal_1 (XBUFFER (w
->contents
));
11394 if (save_match_data
)
11395 record_unwind_save_match_data ();
11396 if (NILP (Voverriding_local_map_menu_flag
))
11398 specbind (Qoverriding_terminal_local_map
, Qnil
);
11399 specbind (Qoverriding_local_map
, Qnil
);
11404 /* Run the Lucid hook. */
11405 safe_run_hooks (Qactivate_menubar_hook
);
11407 /* If it has changed current-menubar from previous value,
11408 really recompute the menu-bar from the value. */
11409 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11410 call0 (Qrecompute_lucid_menubar
);
11412 safe_run_hooks (Qmenu_bar_update_hook
);
11417 XSETFRAME (Vmenu_updating_frame
, f
);
11418 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11420 /* Redisplay the menu bar in case we changed it. */
11421 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11422 || defined (HAVE_NS) || defined (USE_GTK)
11423 if (FRAME_WINDOW_P (f
))
11425 #if defined (HAVE_NS)
11426 /* All frames on Mac OS share the same menubar. So only
11427 the selected frame should be allowed to set it. */
11428 if (f
== SELECTED_FRAME ())
11430 set_frame_menubar (f
, 0, 0);
11433 /* On a terminal screen, the menu bar is an ordinary screen
11434 line, and this makes it get updated. */
11435 w
->update_mode_line
= 1;
11436 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11437 /* In the non-toolkit version, the menu bar is an ordinary screen
11438 line, and this makes it get updated. */
11439 w
->update_mode_line
= 1;
11440 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11442 unbind_to (count
, Qnil
);
11443 set_buffer_internal_1 (prev
);
11450 /***********************************************************************
11452 ***********************************************************************/
11454 #ifdef HAVE_WINDOW_SYSTEM
11456 /* Tool-bar item index of the item on which a mouse button was pressed
11459 int last_tool_bar_item
;
11461 /* Select `frame' temporarily without running all the code in
11463 FIXME: Maybe do_switch_frame should be trimmed down similarly
11464 when `norecord' is set. */
11466 fast_set_selected_frame (Lisp_Object frame
)
11468 if (!EQ (selected_frame
, frame
))
11470 selected_frame
= frame
;
11471 selected_window
= XFRAME (frame
)->selected_window
;
11475 /* Update the tool-bar item list for frame F. This has to be done
11476 before we start to fill in any display lines. Called from
11477 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11478 and restore it here. */
11481 update_tool_bar (struct frame
*f
, int save_match_data
)
11483 #if defined (USE_GTK) || defined (HAVE_NS)
11484 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11486 int do_update
= WINDOWP (f
->tool_bar_window
)
11487 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11492 Lisp_Object window
;
11495 window
= FRAME_SELECTED_WINDOW (f
);
11496 w
= XWINDOW (window
);
11498 /* If the user has switched buffers or windows, we need to
11499 recompute to reflect the new bindings. But we'll
11500 recompute when update_mode_lines is set too; that means
11501 that people can use force-mode-line-update to request
11502 that the menu bar be recomputed. The adverse effect on
11503 the rest of the redisplay algorithm is about the same as
11504 windows_or_buffers_changed anyway. */
11505 if (windows_or_buffers_changed
11506 || w
->update_mode_line
11507 || update_mode_lines
11508 || window_buffer_changed (w
))
11510 struct buffer
*prev
= current_buffer
;
11511 ptrdiff_t count
= SPECPDL_INDEX ();
11512 Lisp_Object frame
, new_tool_bar
;
11513 int new_n_tool_bar
;
11514 struct gcpro gcpro1
;
11516 /* Set current_buffer to the buffer of the selected
11517 window of the frame, so that we get the right local
11519 set_buffer_internal_1 (XBUFFER (w
->contents
));
11521 /* Save match data, if we must. */
11522 if (save_match_data
)
11523 record_unwind_save_match_data ();
11525 /* Make sure that we don't accidentally use bogus keymaps. */
11526 if (NILP (Voverriding_local_map_menu_flag
))
11528 specbind (Qoverriding_terminal_local_map
, Qnil
);
11529 specbind (Qoverriding_local_map
, Qnil
);
11532 GCPRO1 (new_tool_bar
);
11534 /* We must temporarily set the selected frame to this frame
11535 before calling tool_bar_items, because the calculation of
11536 the tool-bar keymap uses the selected frame (see
11537 `tool-bar-make-keymap' in tool-bar.el). */
11538 eassert (EQ (selected_window
,
11539 /* Since we only explicitly preserve selected_frame,
11540 check that selected_window would be redundant. */
11541 XFRAME (selected_frame
)->selected_window
));
11542 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11543 XSETFRAME (frame
, f
);
11544 fast_set_selected_frame (frame
);
11546 /* Build desired tool-bar items from keymaps. */
11548 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11551 /* Redisplay the tool-bar if we changed it. */
11552 if (new_n_tool_bar
!= f
->n_tool_bar_items
11553 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11555 /* Redisplay that happens asynchronously due to an expose event
11556 may access f->tool_bar_items. Make sure we update both
11557 variables within BLOCK_INPUT so no such event interrupts. */
11559 fset_tool_bar_items (f
, new_tool_bar
);
11560 f
->n_tool_bar_items
= new_n_tool_bar
;
11561 w
->update_mode_line
= 1;
11567 unbind_to (count
, Qnil
);
11568 set_buffer_internal_1 (prev
);
11573 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11575 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11576 F's desired tool-bar contents. F->tool_bar_items must have
11577 been set up previously by calling prepare_menu_bars. */
11580 build_desired_tool_bar_string (struct frame
*f
)
11582 int i
, size
, size_needed
;
11583 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11584 Lisp_Object image
, plist
, props
;
11586 image
= plist
= props
= Qnil
;
11587 GCPRO3 (image
, plist
, props
);
11589 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11590 Otherwise, make a new string. */
11592 /* The size of the string we might be able to reuse. */
11593 size
= (STRINGP (f
->desired_tool_bar_string
)
11594 ? SCHARS (f
->desired_tool_bar_string
)
11597 /* We need one space in the string for each image. */
11598 size_needed
= f
->n_tool_bar_items
;
11600 /* Reuse f->desired_tool_bar_string, if possible. */
11601 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11602 fset_desired_tool_bar_string
11603 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11606 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11607 Fremove_text_properties (make_number (0), make_number (size
),
11608 props
, f
->desired_tool_bar_string
);
11611 /* Put a `display' property on the string for the images to display,
11612 put a `menu_item' property on tool-bar items with a value that
11613 is the index of the item in F's tool-bar item vector. */
11614 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11616 #define PROP(IDX) \
11617 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11619 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11620 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11621 int hmargin
, vmargin
, relief
, idx
, end
;
11623 /* If image is a vector, choose the image according to the
11625 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11626 if (VECTORP (image
))
11630 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11631 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11634 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11635 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11637 eassert (ASIZE (image
) >= idx
);
11638 image
= AREF (image
, idx
);
11643 /* Ignore invalid image specifications. */
11644 if (!valid_image_p (image
))
11647 /* Display the tool-bar button pressed, or depressed. */
11648 plist
= Fcopy_sequence (XCDR (image
));
11650 /* Compute margin and relief to draw. */
11651 relief
= (tool_bar_button_relief
>= 0
11652 ? tool_bar_button_relief
11653 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11654 hmargin
= vmargin
= relief
;
11656 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11657 INT_MAX
- max (hmargin
, vmargin
)))
11659 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11660 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11662 else if (CONSP (Vtool_bar_button_margin
))
11664 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11665 INT_MAX
- hmargin
))
11666 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11668 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11669 INT_MAX
- vmargin
))
11670 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11673 if (auto_raise_tool_bar_buttons_p
)
11675 /* Add a `:relief' property to the image spec if the item is
11679 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11686 /* If image is selected, display it pressed, i.e. with a
11687 negative relief. If it's not selected, display it with a
11689 plist
= Fplist_put (plist
, QCrelief
,
11691 ? make_number (-relief
)
11692 : make_number (relief
)));
11697 /* Put a margin around the image. */
11698 if (hmargin
|| vmargin
)
11700 if (hmargin
== vmargin
)
11701 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11703 plist
= Fplist_put (plist
, QCmargin
,
11704 Fcons (make_number (hmargin
),
11705 make_number (vmargin
)));
11708 /* If button is not enabled, and we don't have special images
11709 for the disabled state, make the image appear disabled by
11710 applying an appropriate algorithm to it. */
11711 if (!enabled_p
&& idx
< 0)
11712 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11714 /* Put a `display' text property on the string for the image to
11715 display. Put a `menu-item' property on the string that gives
11716 the start of this item's properties in the tool-bar items
11718 image
= Fcons (Qimage
, plist
);
11719 props
= list4 (Qdisplay
, image
,
11720 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11722 /* Let the last image hide all remaining spaces in the tool bar
11723 string. The string can be longer than needed when we reuse a
11724 previous string. */
11725 if (i
+ 1 == f
->n_tool_bar_items
)
11726 end
= SCHARS (f
->desired_tool_bar_string
);
11729 Fadd_text_properties (make_number (i
), make_number (end
),
11730 props
, f
->desired_tool_bar_string
);
11738 /* Display one line of the tool-bar of frame IT->f.
11740 HEIGHT specifies the desired height of the tool-bar line.
11741 If the actual height of the glyph row is less than HEIGHT, the
11742 row's height is increased to HEIGHT, and the icons are centered
11743 vertically in the new height.
11745 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11746 count a final empty row in case the tool-bar width exactly matches
11751 display_tool_bar_line (struct it
*it
, int height
)
11753 struct glyph_row
*row
= it
->glyph_row
;
11754 int max_x
= it
->last_visible_x
;
11755 struct glyph
*last
;
11757 prepare_desired_row (row
);
11758 row
->y
= it
->current_y
;
11760 /* Note that this isn't made use of if the face hasn't a box,
11761 so there's no need to check the face here. */
11762 it
->start_of_box_run_p
= 1;
11764 while (it
->current_x
< max_x
)
11766 int x
, n_glyphs_before
, i
, nglyphs
;
11767 struct it it_before
;
11769 /* Get the next display element. */
11770 if (!get_next_display_element (it
))
11772 /* Don't count empty row if we are counting needed tool-bar lines. */
11773 if (height
< 0 && !it
->hpos
)
11778 /* Produce glyphs. */
11779 n_glyphs_before
= row
->used
[TEXT_AREA
];
11782 PRODUCE_GLYPHS (it
);
11784 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11786 x
= it_before
.current_x
;
11787 while (i
< nglyphs
)
11789 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11791 if (x
+ glyph
->pixel_width
> max_x
)
11793 /* Glyph doesn't fit on line. Backtrack. */
11794 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11796 /* If this is the only glyph on this line, it will never fit on the
11797 tool-bar, so skip it. But ensure there is at least one glyph,
11798 so we don't accidentally disable the tool-bar. */
11799 if (n_glyphs_before
== 0
11800 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11806 x
+= glyph
->pixel_width
;
11810 /* Stop at line end. */
11811 if (ITERATOR_AT_END_OF_LINE_P (it
))
11814 set_iterator_to_next (it
, 1);
11819 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11821 /* Use default face for the border below the tool bar.
11823 FIXME: When auto-resize-tool-bars is grow-only, there is
11824 no additional border below the possibly empty tool-bar lines.
11825 So to make the extra empty lines look "normal", we have to
11826 use the tool-bar face for the border too. */
11827 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11828 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11829 it
->face_id
= DEFAULT_FACE_ID
;
11831 extend_face_to_end_of_line (it
);
11832 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11833 last
->right_box_line_p
= 1;
11834 if (last
== row
->glyphs
[TEXT_AREA
])
11835 last
->left_box_line_p
= 1;
11837 /* Make line the desired height and center it vertically. */
11838 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11840 /* Don't add more than one line height. */
11841 height
%= FRAME_LINE_HEIGHT (it
->f
);
11842 it
->max_ascent
+= height
/ 2;
11843 it
->max_descent
+= (height
+ 1) / 2;
11846 compute_line_metrics (it
);
11848 /* If line is empty, make it occupy the rest of the tool-bar. */
11849 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11851 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11852 row
->visible_height
= row
->height
;
11853 row
->ascent
= row
->phys_ascent
= 0;
11854 row
->extra_line_spacing
= 0;
11857 row
->full_width_p
= 1;
11858 row
->continued_p
= 0;
11859 row
->truncated_on_left_p
= 0;
11860 row
->truncated_on_right_p
= 0;
11862 it
->current_x
= it
->hpos
= 0;
11863 it
->current_y
+= row
->height
;
11869 /* Max tool-bar height. */
11871 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11872 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11874 /* Value is the number of screen lines needed to make all tool-bar
11875 items of frame F visible. The number of actual rows needed is
11876 returned in *N_ROWS if non-NULL. */
11879 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11881 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11883 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11884 the desired matrix, so use (unused) mode-line row as temporary row to
11885 avoid destroying the first tool-bar row. */
11886 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11888 /* Initialize an iterator for iteration over
11889 F->desired_tool_bar_string in the tool-bar window of frame F. */
11890 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11891 it
.first_visible_x
= 0;
11892 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11893 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11894 it
.paragraph_embedding
= L2R
;
11896 while (!ITERATOR_AT_END_P (&it
))
11898 clear_glyph_row (temp_row
);
11899 it
.glyph_row
= temp_row
;
11900 display_tool_bar_line (&it
, -1);
11902 clear_glyph_row (temp_row
);
11904 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11906 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11908 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11911 #endif /* !USE_GTK && !HAVE_NS */
11913 #if defined USE_GTK || defined HAVE_NS
11914 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
11917 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11919 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11920 If FRAME is nil or omitted, use the selected frame. */)
11921 (Lisp_Object frame
)
11924 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11925 struct frame
*f
= decode_any_frame (frame
);
11928 if (WINDOWP (f
->tool_bar_window
)
11929 && (w
= XWINDOW (f
->tool_bar_window
),
11930 WINDOW_TOTAL_LINES (w
) > 0))
11932 update_tool_bar (f
, 1);
11933 if (f
->n_tool_bar_items
)
11935 build_desired_tool_bar_string (f
);
11936 nlines
= tool_bar_lines_needed (f
, NULL
);
11940 return make_number (nlines
);
11944 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11945 height should be changed. */
11948 redisplay_tool_bar (struct frame
*f
)
11950 #if defined (USE_GTK) || defined (HAVE_NS)
11952 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11953 update_frame_tool_bar (f
);
11956 #else /* !USE_GTK && !HAVE_NS */
11960 struct glyph_row
*row
;
11962 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11963 do anything. This means you must start with tool-bar-lines
11964 non-zero to get the auto-sizing effect. Or in other words, you
11965 can turn off tool-bars by specifying tool-bar-lines zero. */
11966 if (!WINDOWP (f
->tool_bar_window
)
11967 || (w
= XWINDOW (f
->tool_bar_window
),
11968 WINDOW_TOTAL_LINES (w
) == 0))
11971 /* Set up an iterator for the tool-bar window. */
11972 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11973 it
.first_visible_x
= 0;
11974 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11975 row
= it
.glyph_row
;
11977 /* Build a string that represents the contents of the tool-bar. */
11978 build_desired_tool_bar_string (f
);
11979 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11980 /* FIXME: This should be controlled by a user option. But it
11981 doesn't make sense to have an R2L tool bar if the menu bar cannot
11982 be drawn also R2L, and making the menu bar R2L is tricky due
11983 toolkit-specific code that implements it. If an R2L tool bar is
11984 ever supported, display_tool_bar_line should also be augmented to
11985 call unproduce_glyphs like display_line and display_string
11987 it
.paragraph_embedding
= L2R
;
11989 if (f
->n_tool_bar_rows
== 0)
11993 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11994 nlines
!= WINDOW_TOTAL_LINES (w
)))
11997 int old_height
= WINDOW_TOTAL_LINES (w
);
11999 XSETFRAME (frame
, f
);
12000 Fmodify_frame_parameters (frame
,
12001 list1 (Fcons (Qtool_bar_lines
,
12002 make_number (nlines
))));
12003 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12005 clear_glyph_matrix (w
->desired_matrix
);
12006 f
->fonts_changed
= 1;
12012 /* Display as many lines as needed to display all tool-bar items. */
12014 if (f
->n_tool_bar_rows
> 0)
12016 int border
, rows
, height
, extra
;
12018 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12019 border
= XINT (Vtool_bar_border
);
12020 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12021 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12022 else if (EQ (Vtool_bar_border
, Qborder_width
))
12023 border
= f
->border_width
;
12029 rows
= f
->n_tool_bar_rows
;
12030 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12031 extra
= it
.last_visible_y
- border
- height
* rows
;
12033 while (it
.current_y
< it
.last_visible_y
)
12036 if (extra
> 0 && rows
-- > 0)
12038 h
= (extra
+ rows
- 1) / rows
;
12041 display_tool_bar_line (&it
, height
+ h
);
12046 while (it
.current_y
< it
.last_visible_y
)
12047 display_tool_bar_line (&it
, 0);
12050 /* It doesn't make much sense to try scrolling in the tool-bar
12051 window, so don't do it. */
12052 w
->desired_matrix
->no_scrolling_p
= 1;
12053 w
->must_be_updated_p
= 1;
12055 if (!NILP (Vauto_resize_tool_bars
))
12057 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12058 int change_height_p
= 0;
12060 /* If we couldn't display everything, change the tool-bar's
12061 height if there is room for more. */
12062 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12063 && it
.current_y
< max_tool_bar_height
)
12064 change_height_p
= 1;
12066 row
= it
.glyph_row
- 1;
12068 /* If there are blank lines at the end, except for a partially
12069 visible blank line at the end that is smaller than
12070 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12071 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12072 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12073 change_height_p
= 1;
12075 /* If row displays tool-bar items, but is partially visible,
12076 change the tool-bar's height. */
12077 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12078 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12079 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12080 change_height_p
= 1;
12082 /* Resize windows as needed by changing the `tool-bar-lines'
12083 frame parameter. */
12084 if (change_height_p
)
12087 int old_height
= WINDOW_TOTAL_LINES (w
);
12089 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12091 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12092 && !f
->minimize_tool_bar_window_p
)
12093 ? (nlines
> old_height
)
12094 : (nlines
!= old_height
));
12095 f
->minimize_tool_bar_window_p
= 0;
12097 if (change_height_p
)
12099 XSETFRAME (frame
, f
);
12100 Fmodify_frame_parameters (frame
,
12101 list1 (Fcons (Qtool_bar_lines
,
12102 make_number (nlines
))));
12103 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12105 clear_glyph_matrix (w
->desired_matrix
);
12106 f
->n_tool_bar_rows
= nrows
;
12107 f
->fonts_changed
= 1;
12114 f
->minimize_tool_bar_window_p
= 0;
12117 #endif /* USE_GTK || HAVE_NS */
12120 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12122 /* Get information about the tool-bar item which is displayed in GLYPH
12123 on frame F. Return in *PROP_IDX the index where tool-bar item
12124 properties start in F->tool_bar_items. Value is zero if
12125 GLYPH doesn't display a tool-bar item. */
12128 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12134 /* This function can be called asynchronously, which means we must
12135 exclude any possibility that Fget_text_property signals an
12137 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12138 charpos
= max (0, charpos
);
12140 /* Get the text property `menu-item' at pos. The value of that
12141 property is the start index of this item's properties in
12142 F->tool_bar_items. */
12143 prop
= Fget_text_property (make_number (charpos
),
12144 Qmenu_item
, f
->current_tool_bar_string
);
12145 if (INTEGERP (prop
))
12147 *prop_idx
= XINT (prop
);
12157 /* Get information about the tool-bar item at position X/Y on frame F.
12158 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12159 the current matrix of the tool-bar window of F, or NULL if not
12160 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12161 item in F->tool_bar_items. Value is
12163 -1 if X/Y is not on a tool-bar item
12164 0 if X/Y is on the same item that was highlighted before.
12168 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12169 int *hpos
, int *vpos
, int *prop_idx
)
12171 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12172 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12175 /* Find the glyph under X/Y. */
12176 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12177 if (*glyph
== NULL
)
12180 /* Get the start of this tool-bar item's properties in
12181 f->tool_bar_items. */
12182 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12185 /* Is mouse on the highlighted item? */
12186 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12187 && *vpos
>= hlinfo
->mouse_face_beg_row
12188 && *vpos
<= hlinfo
->mouse_face_end_row
12189 && (*vpos
> hlinfo
->mouse_face_beg_row
12190 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12191 && (*vpos
< hlinfo
->mouse_face_end_row
12192 || *hpos
< hlinfo
->mouse_face_end_col
12193 || hlinfo
->mouse_face_past_end
))
12201 Handle mouse button event on the tool-bar of frame F, at
12202 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12203 0 for button release. MODIFIERS is event modifiers for button
12207 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12210 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12211 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12212 int hpos
, vpos
, prop_idx
;
12213 struct glyph
*glyph
;
12214 Lisp_Object enabled_p
;
12217 /* If not on the highlighted tool-bar item, and mouse-highlight is
12218 non-nil, return. This is so we generate the tool-bar button
12219 click only when the mouse button is released on the same item as
12220 where it was pressed. However, when mouse-highlight is disabled,
12221 generate the click when the button is released regardless of the
12222 highlight, since tool-bar items are not highlighted in that
12224 frame_to_window_pixel_xy (w
, &x
, &y
);
12225 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12227 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12230 /* When mouse-highlight is off, generate the click for the item
12231 where the button was pressed, disregarding where it was
12233 if (NILP (Vmouse_highlight
) && !down_p
)
12234 prop_idx
= last_tool_bar_item
;
12236 /* If item is disabled, do nothing. */
12237 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12238 if (NILP (enabled_p
))
12243 /* Show item in pressed state. */
12244 if (!NILP (Vmouse_highlight
))
12245 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12246 last_tool_bar_item
= prop_idx
;
12250 Lisp_Object key
, frame
;
12251 struct input_event event
;
12252 EVENT_INIT (event
);
12254 /* Show item in released state. */
12255 if (!NILP (Vmouse_highlight
))
12256 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12258 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12260 XSETFRAME (frame
, f
);
12261 event
.kind
= TOOL_BAR_EVENT
;
12262 event
.frame_or_window
= frame
;
12264 kbd_buffer_store_event (&event
);
12266 event
.kind
= TOOL_BAR_EVENT
;
12267 event
.frame_or_window
= frame
;
12269 event
.modifiers
= modifiers
;
12270 kbd_buffer_store_event (&event
);
12271 last_tool_bar_item
= -1;
12276 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12277 tool-bar window-relative coordinates X/Y. Called from
12278 note_mouse_highlight. */
12281 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12283 Lisp_Object window
= f
->tool_bar_window
;
12284 struct window
*w
= XWINDOW (window
);
12285 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12286 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12288 struct glyph
*glyph
;
12289 struct glyph_row
*row
;
12291 Lisp_Object enabled_p
;
12293 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12294 int mouse_down_p
, rc
;
12296 /* Function note_mouse_highlight is called with negative X/Y
12297 values when mouse moves outside of the frame. */
12298 if (x
<= 0 || y
<= 0)
12300 clear_mouse_face (hlinfo
);
12304 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12307 /* Not on tool-bar item. */
12308 clear_mouse_face (hlinfo
);
12312 /* On same tool-bar item as before. */
12313 goto set_help_echo
;
12315 clear_mouse_face (hlinfo
);
12317 /* Mouse is down, but on different tool-bar item? */
12318 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12319 && f
== dpyinfo
->last_mouse_frame
);
12322 && last_tool_bar_item
!= prop_idx
)
12325 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12327 /* If tool-bar item is not enabled, don't highlight it. */
12328 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12329 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12331 /* Compute the x-position of the glyph. In front and past the
12332 image is a space. We include this in the highlighted area. */
12333 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12334 for (i
= x
= 0; i
< hpos
; ++i
)
12335 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12337 /* Record this as the current active region. */
12338 hlinfo
->mouse_face_beg_col
= hpos
;
12339 hlinfo
->mouse_face_beg_row
= vpos
;
12340 hlinfo
->mouse_face_beg_x
= x
;
12341 hlinfo
->mouse_face_past_end
= 0;
12343 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12344 hlinfo
->mouse_face_end_row
= vpos
;
12345 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12346 hlinfo
->mouse_face_window
= window
;
12347 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12349 /* Display it as active. */
12350 show_mouse_face (hlinfo
, draw
);
12355 /* Set help_echo_string to a help string to display for this tool-bar item.
12356 XTread_socket does the rest. */
12357 help_echo_object
= help_echo_window
= Qnil
;
12358 help_echo_pos
= -1;
12359 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12360 if (NILP (help_echo_string
))
12361 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12364 #endif /* !USE_GTK && !HAVE_NS */
12366 #endif /* HAVE_WINDOW_SYSTEM */
12370 /************************************************************************
12371 Horizontal scrolling
12372 ************************************************************************/
12374 static int hscroll_window_tree (Lisp_Object
);
12375 static int hscroll_windows (Lisp_Object
);
12377 /* For all leaf windows in the window tree rooted at WINDOW, set their
12378 hscroll value so that PT is (i) visible in the window, and (ii) so
12379 that it is not within a certain margin at the window's left and
12380 right border. Value is non-zero if any window's hscroll has been
12384 hscroll_window_tree (Lisp_Object window
)
12386 int hscrolled_p
= 0;
12387 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12388 int hscroll_step_abs
= 0;
12389 double hscroll_step_rel
= 0;
12391 if (hscroll_relative_p
)
12393 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12394 if (hscroll_step_rel
< 0)
12396 hscroll_relative_p
= 0;
12397 hscroll_step_abs
= 0;
12400 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12402 hscroll_step_abs
= XINT (Vhscroll_step
);
12403 if (hscroll_step_abs
< 0)
12404 hscroll_step_abs
= 0;
12407 hscroll_step_abs
= 0;
12409 while (WINDOWP (window
))
12411 struct window
*w
= XWINDOW (window
);
12413 if (WINDOWP (w
->contents
))
12414 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12415 else if (w
->cursor
.vpos
>= 0)
12418 int text_area_width
;
12419 struct glyph_row
*current_cursor_row
12420 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12421 struct glyph_row
*desired_cursor_row
12422 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12423 struct glyph_row
*cursor_row
12424 = (desired_cursor_row
->enabled_p
12425 ? desired_cursor_row
12426 : current_cursor_row
);
12427 int row_r2l_p
= cursor_row
->reversed_p
;
12429 text_area_width
= window_box_width (w
, TEXT_AREA
);
12431 /* Scroll when cursor is inside this scroll margin. */
12432 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12434 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12435 /* For left-to-right rows, hscroll when cursor is either
12436 (i) inside the right hscroll margin, or (ii) if it is
12437 inside the left margin and the window is already
12441 && w
->cursor
.x
<= h_margin
)
12442 || (cursor_row
->enabled_p
12443 && cursor_row
->truncated_on_right_p
12444 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12445 /* For right-to-left rows, the logic is similar,
12446 except that rules for scrolling to left and right
12447 are reversed. E.g., if cursor.x <= h_margin, we
12448 need to hscroll "to the right" unconditionally,
12449 and that will scroll the screen to the left so as
12450 to reveal the next portion of the row. */
12452 && ((cursor_row
->enabled_p
12453 /* FIXME: It is confusing to set the
12454 truncated_on_right_p flag when R2L rows
12455 are actually truncated on the left. */
12456 && cursor_row
->truncated_on_right_p
12457 && w
->cursor
.x
<= h_margin
)
12459 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12463 struct buffer
*saved_current_buffer
;
12467 /* Find point in a display of infinite width. */
12468 saved_current_buffer
= current_buffer
;
12469 current_buffer
= XBUFFER (w
->contents
);
12471 if (w
== XWINDOW (selected_window
))
12474 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12476 /* Move iterator to pt starting at cursor_row->start in
12477 a line with infinite width. */
12478 init_to_row_start (&it
, w
, cursor_row
);
12479 it
.last_visible_x
= INFINITY
;
12480 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12481 current_buffer
= saved_current_buffer
;
12483 /* Position cursor in window. */
12484 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12485 hscroll
= max (0, (it
.current_x
12486 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12487 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12488 : (text_area_width
/ 2))))
12489 / FRAME_COLUMN_WIDTH (it
.f
);
12490 else if ((!row_r2l_p
12491 && w
->cursor
.x
>= text_area_width
- h_margin
)
12492 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12494 if (hscroll_relative_p
)
12495 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12498 wanted_x
= text_area_width
12499 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12502 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12506 if (hscroll_relative_p
)
12507 wanted_x
= text_area_width
* hscroll_step_rel
12510 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12513 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12515 hscroll
= max (hscroll
, w
->min_hscroll
);
12517 /* Don't prevent redisplay optimizations if hscroll
12518 hasn't changed, as it will unnecessarily slow down
12520 if (w
->hscroll
!= hscroll
)
12522 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12523 w
->hscroll
= hscroll
;
12532 /* Value is non-zero if hscroll of any leaf window has been changed. */
12533 return hscrolled_p
;
12537 /* Set hscroll so that cursor is visible and not inside horizontal
12538 scroll margins for all windows in the tree rooted at WINDOW. See
12539 also hscroll_window_tree above. Value is non-zero if any window's
12540 hscroll has been changed. If it has, desired matrices on the frame
12541 of WINDOW are cleared. */
12544 hscroll_windows (Lisp_Object window
)
12546 int hscrolled_p
= hscroll_window_tree (window
);
12548 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12549 return hscrolled_p
;
12554 /************************************************************************
12556 ************************************************************************/
12558 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12559 to a non-zero value. This is sometimes handy to have in a debugger
12564 /* First and last unchanged row for try_window_id. */
12566 static int debug_first_unchanged_at_end_vpos
;
12567 static int debug_last_unchanged_at_beg_vpos
;
12569 /* Delta vpos and y. */
12571 static int debug_dvpos
, debug_dy
;
12573 /* Delta in characters and bytes for try_window_id. */
12575 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12577 /* Values of window_end_pos and window_end_vpos at the end of
12580 static ptrdiff_t debug_end_vpos
;
12582 /* Append a string to W->desired_matrix->method. FMT is a printf
12583 format string. If trace_redisplay_p is non-zero also printf the
12584 resulting string to stderr. */
12586 static void debug_method_add (struct window
*, char const *, ...)
12587 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12590 debug_method_add (struct window
*w
, char const *fmt
, ...)
12593 char *method
= w
->desired_matrix
->method
;
12594 int len
= strlen (method
);
12595 int size
= sizeof w
->desired_matrix
->method
;
12596 int remaining
= size
- len
- 1;
12599 if (len
&& remaining
)
12602 --remaining
, ++len
;
12605 va_start (ap
, fmt
);
12606 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12609 if (trace_redisplay_p
)
12610 fprintf (stderr
, "%p (%s): %s\n",
12612 ((BUFFERP (w
->contents
)
12613 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12614 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12619 #endif /* GLYPH_DEBUG */
12622 /* Value is non-zero if all changes in window W, which displays
12623 current_buffer, are in the text between START and END. START is a
12624 buffer position, END is given as a distance from Z. Used in
12625 redisplay_internal for display optimization. */
12628 text_outside_line_unchanged_p (struct window
*w
,
12629 ptrdiff_t start
, ptrdiff_t end
)
12631 int unchanged_p
= 1;
12633 /* If text or overlays have changed, see where. */
12634 if (window_outdated (w
))
12636 /* Gap in the line? */
12637 if (GPT
< start
|| Z
- GPT
< end
)
12640 /* Changes start in front of the line, or end after it? */
12642 && (BEG_UNCHANGED
< start
- 1
12643 || END_UNCHANGED
< end
))
12646 /* If selective display, can't optimize if changes start at the
12647 beginning of the line. */
12649 && INTEGERP (BVAR (current_buffer
, selective_display
))
12650 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12651 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12654 /* If there are overlays at the start or end of the line, these
12655 may have overlay strings with newlines in them. A change at
12656 START, for instance, may actually concern the display of such
12657 overlay strings as well, and they are displayed on different
12658 lines. So, quickly rule out this case. (For the future, it
12659 might be desirable to implement something more telling than
12660 just BEG/END_UNCHANGED.) */
12663 if (BEG
+ BEG_UNCHANGED
== start
12664 && overlay_touches_p (start
))
12666 if (END_UNCHANGED
== end
12667 && overlay_touches_p (Z
- end
))
12671 /* Under bidi reordering, adding or deleting a character in the
12672 beginning of a paragraph, before the first strong directional
12673 character, can change the base direction of the paragraph (unless
12674 the buffer specifies a fixed paragraph direction), which will
12675 require to redisplay the whole paragraph. It might be worthwhile
12676 to find the paragraph limits and widen the range of redisplayed
12677 lines to that, but for now just give up this optimization. */
12678 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12679 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12683 return unchanged_p
;
12687 /* Do a frame update, taking possible shortcuts into account. This is
12688 the main external entry point for redisplay.
12690 If the last redisplay displayed an echo area message and that message
12691 is no longer requested, we clear the echo area or bring back the
12692 mini-buffer if that is in use. */
12697 redisplay_internal ();
12702 overlay_arrow_string_or_property (Lisp_Object var
)
12706 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12709 return Voverlay_arrow_string
;
12712 /* Return 1 if there are any overlay-arrows in current_buffer. */
12714 overlay_arrow_in_current_buffer_p (void)
12718 for (vlist
= Voverlay_arrow_variable_list
;
12720 vlist
= XCDR (vlist
))
12722 Lisp_Object var
= XCAR (vlist
);
12725 if (!SYMBOLP (var
))
12727 val
= find_symbol_value (var
);
12729 && current_buffer
== XMARKER (val
)->buffer
)
12736 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12740 overlay_arrows_changed_p (void)
12744 for (vlist
= Voverlay_arrow_variable_list
;
12746 vlist
= XCDR (vlist
))
12748 Lisp_Object var
= XCAR (vlist
);
12749 Lisp_Object val
, pstr
;
12751 if (!SYMBOLP (var
))
12753 val
= find_symbol_value (var
);
12754 if (!MARKERP (val
))
12756 if (! EQ (COERCE_MARKER (val
),
12757 Fget (var
, Qlast_arrow_position
))
12758 || ! (pstr
= overlay_arrow_string_or_property (var
),
12759 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12765 /* Mark overlay arrows to be updated on next redisplay. */
12768 update_overlay_arrows (int up_to_date
)
12772 for (vlist
= Voverlay_arrow_variable_list
;
12774 vlist
= XCDR (vlist
))
12776 Lisp_Object var
= XCAR (vlist
);
12778 if (!SYMBOLP (var
))
12781 if (up_to_date
> 0)
12783 Lisp_Object val
= find_symbol_value (var
);
12784 Fput (var
, Qlast_arrow_position
,
12785 COERCE_MARKER (val
));
12786 Fput (var
, Qlast_arrow_string
,
12787 overlay_arrow_string_or_property (var
));
12789 else if (up_to_date
< 0
12790 || !NILP (Fget (var
, Qlast_arrow_position
)))
12792 Fput (var
, Qlast_arrow_position
, Qt
);
12793 Fput (var
, Qlast_arrow_string
, Qt
);
12799 /* Return overlay arrow string to display at row.
12800 Return integer (bitmap number) for arrow bitmap in left fringe.
12801 Return nil if no overlay arrow. */
12804 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12808 for (vlist
= Voverlay_arrow_variable_list
;
12810 vlist
= XCDR (vlist
))
12812 Lisp_Object var
= XCAR (vlist
);
12815 if (!SYMBOLP (var
))
12818 val
= find_symbol_value (var
);
12821 && current_buffer
== XMARKER (val
)->buffer
12822 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12824 if (FRAME_WINDOW_P (it
->f
)
12825 /* FIXME: if ROW->reversed_p is set, this should test
12826 the right fringe, not the left one. */
12827 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12829 #ifdef HAVE_WINDOW_SYSTEM
12830 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12833 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12834 return make_number (fringe_bitmap
);
12837 return make_number (-1); /* Use default arrow bitmap. */
12839 return overlay_arrow_string_or_property (var
);
12846 /* Return 1 if point moved out of or into a composition. Otherwise
12847 return 0. PREV_BUF and PREV_PT are the last point buffer and
12848 position. BUF and PT are the current point buffer and position. */
12851 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12852 struct buffer
*buf
, ptrdiff_t pt
)
12854 ptrdiff_t start
, end
;
12856 Lisp_Object buffer
;
12858 XSETBUFFER (buffer
, buf
);
12859 /* Check a composition at the last point if point moved within the
12861 if (prev_buf
== buf
)
12864 /* Point didn't move. */
12867 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12868 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12869 && composition_valid_p (start
, end
, prop
)
12870 && start
< prev_pt
&& end
> prev_pt
)
12871 /* The last point was within the composition. Return 1 iff
12872 point moved out of the composition. */
12873 return (pt
<= start
|| pt
>= end
);
12876 /* Check a composition at the current point. */
12877 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12878 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12879 && composition_valid_p (start
, end
, prop
)
12880 && start
< pt
&& end
> pt
);
12883 /* Reconsider the clip changes of buffer which is displayed in W. */
12886 reconsider_clip_changes (struct window
*w
)
12888 struct buffer
*b
= XBUFFER (w
->contents
);
12890 if (b
->clip_changed
12891 && w
->window_end_valid
12892 && w
->current_matrix
->buffer
== b
12893 && w
->current_matrix
->zv
== BUF_ZV (b
)
12894 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12895 b
->clip_changed
= 0;
12897 /* If display wasn't paused, and W is not a tool bar window, see if
12898 point has been moved into or out of a composition. In that case,
12899 we set b->clip_changed to 1 to force updating the screen. If
12900 b->clip_changed has already been set to 1, we can skip this
12902 if (!b
->clip_changed
&& w
->window_end_valid
)
12904 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12905 ? PT
: marker_position (w
->pointm
));
12907 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12908 && check_point_in_composition (w
->current_matrix
->buffer
,
12909 w
->last_point
, b
, pt
))
12910 b
->clip_changed
= 1;
12914 #define STOP_POLLING \
12915 do { if (! polling_stopped_here) stop_polling (); \
12916 polling_stopped_here = 1; } while (0)
12918 #define RESUME_POLLING \
12919 do { if (polling_stopped_here) start_polling (); \
12920 polling_stopped_here = 0; } while (0)
12923 /* Perhaps in the future avoid recentering windows if it
12924 is not necessary; currently that causes some problems. */
12927 redisplay_internal (void)
12929 struct window
*w
= XWINDOW (selected_window
);
12933 bool must_finish
= 0, match_p
;
12934 struct text_pos tlbufpos
, tlendpos
;
12935 int number_of_visible_frames
;
12938 int polling_stopped_here
= 0;
12939 Lisp_Object tail
, frame
;
12941 /* Non-zero means redisplay has to consider all windows on all
12942 frames. Zero means, only selected_window is considered. */
12943 int consider_all_windows_p
;
12945 /* Non-zero means redisplay has to redisplay the miniwindow. */
12946 int update_miniwindow_p
= 0;
12948 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12950 /* No redisplay if running in batch mode or frame is not yet fully
12951 initialized, or redisplay is explicitly turned off by setting
12952 Vinhibit_redisplay. */
12953 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12954 || !NILP (Vinhibit_redisplay
))
12957 /* Don't examine these until after testing Vinhibit_redisplay.
12958 When Emacs is shutting down, perhaps because its connection to
12959 X has dropped, we should not look at them at all. */
12960 fr
= XFRAME (w
->frame
);
12961 sf
= SELECTED_FRAME ();
12963 if (!fr
->glyphs_initialized_p
)
12966 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12967 if (popup_activated ())
12971 /* I don't think this happens but let's be paranoid. */
12972 if (redisplaying_p
)
12975 /* Record a function that clears redisplaying_p
12976 when we leave this function. */
12977 count
= SPECPDL_INDEX ();
12978 record_unwind_protect_void (unwind_redisplay
);
12979 redisplaying_p
= 1;
12980 specbind (Qinhibit_free_realized_faces
, Qnil
);
12982 /* Record this function, so it appears on the profiler's backtraces. */
12983 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
12985 FOR_EACH_FRAME (tail
, frame
)
12986 XFRAME (frame
)->already_hscrolled_p
= 0;
12989 /* Remember the currently selected window. */
12993 last_escape_glyph_frame
= NULL
;
12994 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12995 last_glyphless_glyph_frame
= NULL
;
12996 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12998 /* If face_change_count is non-zero, init_iterator will free all
12999 realized faces, which includes the faces referenced from current
13000 matrices. So, we can't reuse current matrices in this case. */
13001 if (face_change_count
)
13002 ++windows_or_buffers_changed
;
13004 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13005 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13007 /* Since frames on a single ASCII terminal share the same
13008 display area, displaying a different frame means redisplay
13009 the whole thing. */
13010 windows_or_buffers_changed
++;
13011 SET_FRAME_GARBAGED (sf
);
13013 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13015 FRAME_TTY (sf
)->previous_frame
= sf
;
13018 /* Set the visible flags for all frames. Do this before checking for
13019 resized or garbaged frames; they want to know if their frames are
13020 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13021 number_of_visible_frames
= 0;
13023 FOR_EACH_FRAME (tail
, frame
)
13025 struct frame
*f
= XFRAME (frame
);
13027 if (FRAME_VISIBLE_P (f
))
13029 ++number_of_visible_frames
;
13030 /* Adjust matrices for visible frames only. */
13031 if (f
->fonts_changed
)
13033 adjust_frame_glyphs (f
);
13034 f
->fonts_changed
= 0;
13036 /* If cursor type has been changed on the frame
13037 other than selected, consider all frames. */
13038 if (f
!= sf
&& f
->cursor_type_changed
)
13039 update_mode_lines
++;
13041 clear_desired_matrices (f
);
13044 /* Notice any pending interrupt request to change frame size. */
13045 do_pending_window_change (1);
13047 /* do_pending_window_change could change the selected_window due to
13048 frame resizing which makes the selected window too small. */
13049 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13052 /* Clear frames marked as garbaged. */
13053 clear_garbaged_frames ();
13055 /* Build menubar and tool-bar items. */
13056 if (NILP (Vmemory_full
))
13057 prepare_menu_bars ();
13059 if (windows_or_buffers_changed
)
13060 update_mode_lines
++;
13062 reconsider_clip_changes (w
);
13064 /* In most cases selected window displays current buffer. */
13065 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13070 /* Detect case that we need to write or remove a star in the mode line. */
13071 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13073 w
->update_mode_line
= 1;
13074 if (buffer_shared_and_changed ())
13075 update_mode_lines
++;
13078 /* Avoid invocation of point motion hooks by `current_column' below. */
13079 count1
= SPECPDL_INDEX ();
13080 specbind (Qinhibit_point_motion_hooks
, Qt
);
13082 if (mode_line_update_needed (w
))
13083 w
->update_mode_line
= 1;
13085 unbind_to (count1
, Qnil
);
13088 consider_all_windows_p
= (update_mode_lines
13089 || buffer_shared_and_changed ());
13091 /* If specs for an arrow have changed, do thorough redisplay
13092 to ensure we remove any arrow that should no longer exist. */
13093 if (overlay_arrows_changed_p ())
13094 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13096 /* Normally the message* functions will have already displayed and
13097 updated the echo area, but the frame may have been trashed, or
13098 the update may have been preempted, so display the echo area
13099 again here. Checking message_cleared_p captures the case that
13100 the echo area should be cleared. */
13101 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13102 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13103 || (message_cleared_p
13104 && minibuf_level
== 0
13105 /* If the mini-window is currently selected, this means the
13106 echo-area doesn't show through. */
13107 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13109 int window_height_changed_p
= echo_area_display (0);
13111 if (message_cleared_p
)
13112 update_miniwindow_p
= 1;
13116 /* If we don't display the current message, don't clear the
13117 message_cleared_p flag, because, if we did, we wouldn't clear
13118 the echo area in the next redisplay which doesn't preserve
13120 if (!display_last_displayed_message_p
)
13121 message_cleared_p
= 0;
13123 if (window_height_changed_p
)
13125 consider_all_windows_p
= 1;
13126 ++update_mode_lines
;
13127 ++windows_or_buffers_changed
;
13129 /* If window configuration was changed, frames may have been
13130 marked garbaged. Clear them or we will experience
13131 surprises wrt scrolling. */
13132 clear_garbaged_frames ();
13135 else if (EQ (selected_window
, minibuf_window
)
13136 && (current_buffer
->clip_changed
|| window_outdated (w
))
13137 && resize_mini_window (w
, 0))
13139 /* Resized active mini-window to fit the size of what it is
13140 showing if its contents might have changed. */
13142 /* FIXME: this causes all frames to be updated, which seems unnecessary
13143 since only the current frame needs to be considered. This function
13144 needs to be rewritten with two variables, consider_all_windows and
13145 consider_all_frames. */
13146 consider_all_windows_p
= 1;
13147 ++windows_or_buffers_changed
;
13148 ++update_mode_lines
;
13150 /* If window configuration was changed, frames may have been
13151 marked garbaged. Clear them or we will experience
13152 surprises wrt scrolling. */
13153 clear_garbaged_frames ();
13156 /* If showing the region, and mark has changed, we must redisplay
13157 the whole window. The assignment to this_line_start_pos prevents
13158 the optimization directly below this if-statement. */
13159 if (((!NILP (Vtransient_mark_mode
)
13160 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13161 != (w
->region_showing
> 0))
13162 || (w
->region_showing
13163 && w
->region_showing
13164 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13165 CHARPOS (this_line_start_pos
) = 0;
13167 /* Optimize the case that only the line containing the cursor in the
13168 selected window has changed. Variables starting with this_ are
13169 set in display_line and record information about the line
13170 containing the cursor. */
13171 tlbufpos
= this_line_start_pos
;
13172 tlendpos
= this_line_end_pos
;
13173 if (!consider_all_windows_p
13174 && CHARPOS (tlbufpos
) > 0
13175 && !w
->update_mode_line
13176 && !current_buffer
->clip_changed
13177 && !current_buffer
->prevent_redisplay_optimizations_p
13178 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13179 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13180 && !XFRAME (w
->frame
)->cursor_type_changed
13181 /* Make sure recorded data applies to current buffer, etc. */
13182 && this_line_buffer
== current_buffer
13185 && !w
->optional_new_start
13186 /* Point must be on the line that we have info recorded about. */
13187 && PT
>= CHARPOS (tlbufpos
)
13188 && PT
<= Z
- CHARPOS (tlendpos
)
13189 /* All text outside that line, including its final newline,
13190 must be unchanged. */
13191 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13192 CHARPOS (tlendpos
)))
13194 if (CHARPOS (tlbufpos
) > BEGV
13195 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13196 && (CHARPOS (tlbufpos
) == ZV
13197 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13198 /* Former continuation line has disappeared by becoming empty. */
13200 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13202 /* We have to handle the case of continuation around a
13203 wide-column character (see the comment in indent.c around
13206 For instance, in the following case:
13208 -------- Insert --------
13209 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13210 J_I_ ==> J_I_ `^^' are cursors.
13214 As we have to redraw the line above, we cannot use this
13218 int line_height_before
= this_line_pixel_height
;
13220 /* Note that start_display will handle the case that the
13221 line starting at tlbufpos is a continuation line. */
13222 start_display (&it
, w
, tlbufpos
);
13224 /* Implementation note: It this still necessary? */
13225 if (it
.current_x
!= this_line_start_x
)
13228 TRACE ((stderr
, "trying display optimization 1\n"));
13229 w
->cursor
.vpos
= -1;
13230 overlay_arrow_seen
= 0;
13231 it
.vpos
= this_line_vpos
;
13232 it
.current_y
= this_line_y
;
13233 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13234 display_line (&it
);
13236 /* If line contains point, is not continued,
13237 and ends at same distance from eob as before, we win. */
13238 if (w
->cursor
.vpos
>= 0
13239 /* Line is not continued, otherwise this_line_start_pos
13240 would have been set to 0 in display_line. */
13241 && CHARPOS (this_line_start_pos
)
13242 /* Line ends as before. */
13243 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13244 /* Line has same height as before. Otherwise other lines
13245 would have to be shifted up or down. */
13246 && this_line_pixel_height
== line_height_before
)
13248 /* If this is not the window's last line, we must adjust
13249 the charstarts of the lines below. */
13250 if (it
.current_y
< it
.last_visible_y
)
13252 struct glyph_row
*row
13253 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13254 ptrdiff_t delta
, delta_bytes
;
13256 /* We used to distinguish between two cases here,
13257 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13258 when the line ends in a newline or the end of the
13259 buffer's accessible portion. But both cases did
13260 the same, so they were collapsed. */
13262 - CHARPOS (tlendpos
)
13263 - MATRIX_ROW_START_CHARPOS (row
));
13264 delta_bytes
= (Z_BYTE
13265 - BYTEPOS (tlendpos
)
13266 - MATRIX_ROW_START_BYTEPOS (row
));
13268 increment_matrix_positions (w
->current_matrix
,
13269 this_line_vpos
+ 1,
13270 w
->current_matrix
->nrows
,
13271 delta
, delta_bytes
);
13274 /* If this row displays text now but previously didn't,
13275 or vice versa, w->window_end_vpos may have to be
13277 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13279 if (w
->window_end_vpos
< this_line_vpos
)
13280 w
->window_end_vpos
= this_line_vpos
;
13282 else if (w
->window_end_vpos
== this_line_vpos
13283 && this_line_vpos
> 0)
13284 w
->window_end_vpos
= this_line_vpos
- 1;
13285 w
->window_end_valid
= 0;
13287 /* Update hint: No need to try to scroll in update_window. */
13288 w
->desired_matrix
->no_scrolling_p
= 1;
13291 *w
->desired_matrix
->method
= 0;
13292 debug_method_add (w
, "optimization 1");
13294 #ifdef HAVE_WINDOW_SYSTEM
13295 update_window_fringes (w
, 0);
13302 else if (/* Cursor position hasn't changed. */
13303 PT
== w
->last_point
13304 /* Make sure the cursor was last displayed
13305 in this window. Otherwise we have to reposition it. */
13306 && 0 <= w
->cursor
.vpos
13307 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13311 do_pending_window_change (1);
13312 /* If selected_window changed, redisplay again. */
13313 if (WINDOWP (selected_window
)
13314 && (w
= XWINDOW (selected_window
)) != sw
)
13317 /* We used to always goto end_of_redisplay here, but this
13318 isn't enough if we have a blinking cursor. */
13319 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13320 goto end_of_redisplay
;
13324 /* If highlighting the region, or if the cursor is in the echo area,
13325 then we can't just move the cursor. */
13326 else if (! (!NILP (Vtransient_mark_mode
)
13327 && !NILP (BVAR (current_buffer
, mark_active
)))
13328 && (EQ (selected_window
,
13329 BVAR (current_buffer
, last_selected_window
))
13330 || highlight_nonselected_windows
)
13331 && !w
->region_showing
13332 && NILP (Vshow_trailing_whitespace
)
13333 && !cursor_in_echo_area
)
13336 struct glyph_row
*row
;
13338 /* Skip from tlbufpos to PT and see where it is. Note that
13339 PT may be in invisible text. If so, we will end at the
13340 next visible position. */
13341 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13342 NULL
, DEFAULT_FACE_ID
);
13343 it
.current_x
= this_line_start_x
;
13344 it
.current_y
= this_line_y
;
13345 it
.vpos
= this_line_vpos
;
13347 /* The call to move_it_to stops in front of PT, but
13348 moves over before-strings. */
13349 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13351 if (it
.vpos
== this_line_vpos
13352 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13355 eassert (this_line_vpos
== it
.vpos
);
13356 eassert (this_line_y
== it
.current_y
);
13357 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13359 *w
->desired_matrix
->method
= 0;
13360 debug_method_add (w
, "optimization 3");
13369 /* Text changed drastically or point moved off of line. */
13370 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13373 CHARPOS (this_line_start_pos
) = 0;
13374 consider_all_windows_p
|= buffer_shared_and_changed ();
13375 ++clear_face_cache_count
;
13376 #ifdef HAVE_WINDOW_SYSTEM
13377 ++clear_image_cache_count
;
13380 /* Build desired matrices, and update the display. If
13381 consider_all_windows_p is non-zero, do it for all windows on all
13382 frames. Otherwise do it for selected_window, only. */
13384 if (consider_all_windows_p
)
13386 FOR_EACH_FRAME (tail
, frame
)
13387 XFRAME (frame
)->updated_p
= 0;
13389 FOR_EACH_FRAME (tail
, frame
)
13391 struct frame
*f
= XFRAME (frame
);
13393 /* We don't have to do anything for unselected terminal
13395 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13396 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13401 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13403 /* Mark all the scroll bars to be removed; we'll redeem
13404 the ones we want when we redisplay their windows. */
13405 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13406 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13408 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13409 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13411 /* The X error handler may have deleted that frame. */
13412 if (!FRAME_LIVE_P (f
))
13415 /* Any scroll bars which redisplay_windows should have
13416 nuked should now go away. */
13417 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13418 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13420 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13422 /* If fonts changed on visible frame, display again. */
13423 if (f
->fonts_changed
)
13425 adjust_frame_glyphs (f
);
13426 f
->fonts_changed
= 0;
13430 /* See if we have to hscroll. */
13431 if (!f
->already_hscrolled_p
)
13433 f
->already_hscrolled_p
= 1;
13434 if (hscroll_windows (f
->root_window
))
13438 /* Prevent various kinds of signals during display
13439 update. stdio is not robust about handling
13440 signals, which can cause an apparent I/O
13442 if (interrupt_input
)
13443 unrequest_sigio ();
13446 /* Update the display. */
13447 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13448 pending
|= update_frame (f
, 0, 0);
13449 f
->cursor_type_changed
= 0;
13455 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13459 /* Do the mark_window_display_accurate after all windows have
13460 been redisplayed because this call resets flags in buffers
13461 which are needed for proper redisplay. */
13462 FOR_EACH_FRAME (tail
, frame
)
13464 struct frame
*f
= XFRAME (frame
);
13467 mark_window_display_accurate (f
->root_window
, 1);
13468 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13469 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13474 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13476 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13477 struct frame
*mini_frame
;
13479 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13480 /* Use list_of_error, not Qerror, so that
13481 we catch only errors and don't run the debugger. */
13482 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13484 redisplay_window_error
);
13485 if (update_miniwindow_p
)
13486 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13488 redisplay_window_error
);
13490 /* Compare desired and current matrices, perform output. */
13493 /* If fonts changed, display again. */
13494 if (sf
->fonts_changed
)
13497 /* Prevent various kinds of signals during display update.
13498 stdio is not robust about handling signals,
13499 which can cause an apparent I/O error. */
13500 if (interrupt_input
)
13501 unrequest_sigio ();
13504 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13506 if (hscroll_windows (selected_window
))
13509 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13510 pending
= update_frame (sf
, 0, 0);
13511 sf
->cursor_type_changed
= 0;
13514 /* We may have called echo_area_display at the top of this
13515 function. If the echo area is on another frame, that may
13516 have put text on a frame other than the selected one, so the
13517 above call to update_frame would not have caught it. Catch
13519 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13520 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13522 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13524 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13525 pending
|= update_frame (mini_frame
, 0, 0);
13526 mini_frame
->cursor_type_changed
= 0;
13527 if (!pending
&& hscroll_windows (mini_window
))
13532 /* If display was paused because of pending input, make sure we do a
13533 thorough update the next time. */
13536 /* Prevent the optimization at the beginning of
13537 redisplay_internal that tries a single-line update of the
13538 line containing the cursor in the selected window. */
13539 CHARPOS (this_line_start_pos
) = 0;
13541 /* Let the overlay arrow be updated the next time. */
13542 update_overlay_arrows (0);
13544 /* If we pause after scrolling, some rows in the current
13545 matrices of some windows are not valid. */
13546 if (!WINDOW_FULL_WIDTH_P (w
)
13547 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13548 update_mode_lines
= 1;
13552 if (!consider_all_windows_p
)
13554 /* This has already been done above if
13555 consider_all_windows_p is set. */
13556 mark_window_display_accurate_1 (w
, 1);
13558 /* Say overlay arrows are up to date. */
13559 update_overlay_arrows (1);
13561 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13562 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13565 update_mode_lines
= 0;
13566 windows_or_buffers_changed
= 0;
13569 /* Start SIGIO interrupts coming again. Having them off during the
13570 code above makes it less likely one will discard output, but not
13571 impossible, since there might be stuff in the system buffer here.
13572 But it is much hairier to try to do anything about that. */
13573 if (interrupt_input
)
13577 /* If a frame has become visible which was not before, redisplay
13578 again, so that we display it. Expose events for such a frame
13579 (which it gets when becoming visible) don't call the parts of
13580 redisplay constructing glyphs, so simply exposing a frame won't
13581 display anything in this case. So, we have to display these
13582 frames here explicitly. */
13587 FOR_EACH_FRAME (tail
, frame
)
13589 int this_is_visible
= 0;
13591 if (XFRAME (frame
)->visible
)
13592 this_is_visible
= 1;
13594 if (this_is_visible
)
13598 if (new_count
!= number_of_visible_frames
)
13599 windows_or_buffers_changed
++;
13602 /* Change frame size now if a change is pending. */
13603 do_pending_window_change (1);
13605 /* If we just did a pending size change, or have additional
13606 visible frames, or selected_window changed, redisplay again. */
13607 if ((windows_or_buffers_changed
&& !pending
)
13608 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13611 /* Clear the face and image caches.
13613 We used to do this only if consider_all_windows_p. But the cache
13614 needs to be cleared if a timer creates images in the current
13615 buffer (e.g. the test case in Bug#6230). */
13617 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13619 clear_face_cache (0);
13620 clear_face_cache_count
= 0;
13623 #ifdef HAVE_WINDOW_SYSTEM
13624 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13626 clear_image_caches (Qnil
);
13627 clear_image_cache_count
= 0;
13629 #endif /* HAVE_WINDOW_SYSTEM */
13632 unbind_to (count
, Qnil
);
13637 /* Redisplay, but leave alone any recent echo area message unless
13638 another message has been requested in its place.
13640 This is useful in situations where you need to redisplay but no
13641 user action has occurred, making it inappropriate for the message
13642 area to be cleared. See tracking_off and
13643 wait_reading_process_output for examples of these situations.
13645 FROM_WHERE is an integer saying from where this function was
13646 called. This is useful for debugging. */
13649 redisplay_preserve_echo_area (int from_where
)
13651 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13653 if (!NILP (echo_area_buffer
[1]))
13655 /* We have a previously displayed message, but no current
13656 message. Redisplay the previous message. */
13657 display_last_displayed_message_p
= 1;
13658 redisplay_internal ();
13659 display_last_displayed_message_p
= 0;
13662 redisplay_internal ();
13664 flush_frame (SELECTED_FRAME ());
13668 /* Function registered with record_unwind_protect in redisplay_internal. */
13671 unwind_redisplay (void)
13673 redisplaying_p
= 0;
13677 /* Mark the display of leaf window W as accurate or inaccurate.
13678 If ACCURATE_P is non-zero mark display of W as accurate. If
13679 ACCURATE_P is zero, arrange for W to be redisplayed the next
13680 time redisplay_internal is called. */
13683 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13685 struct buffer
*b
= XBUFFER (w
->contents
);
13687 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13688 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13689 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13693 b
->clip_changed
= 0;
13694 b
->prevent_redisplay_optimizations_p
= 0;
13696 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13697 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13698 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13699 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13701 w
->current_matrix
->buffer
= b
;
13702 w
->current_matrix
->begv
= BUF_BEGV (b
);
13703 w
->current_matrix
->zv
= BUF_ZV (b
);
13705 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13706 w
->last_cursor_off_p
= w
->cursor_off_p
;
13708 if (w
== XWINDOW (selected_window
))
13709 w
->last_point
= BUF_PT (b
);
13711 w
->last_point
= marker_position (w
->pointm
);
13713 w
->window_end_valid
= 1;
13714 w
->update_mode_line
= 0;
13719 /* Mark the display of windows in the window tree rooted at WINDOW as
13720 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13721 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13722 be redisplayed the next time redisplay_internal is called. */
13725 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13729 for (; !NILP (window
); window
= w
->next
)
13731 w
= XWINDOW (window
);
13732 if (WINDOWP (w
->contents
))
13733 mark_window_display_accurate (w
->contents
, accurate_p
);
13735 mark_window_display_accurate_1 (w
, accurate_p
);
13739 update_overlay_arrows (1);
13741 /* Force a thorough redisplay the next time by setting
13742 last_arrow_position and last_arrow_string to t, which is
13743 unequal to any useful value of Voverlay_arrow_... */
13744 update_overlay_arrows (-1);
13748 /* Return value in display table DP (Lisp_Char_Table *) for character
13749 C. Since a display table doesn't have any parent, we don't have to
13750 follow parent. Do not call this function directly but use the
13751 macro DISP_CHAR_VECTOR. */
13754 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13758 if (ASCII_CHAR_P (c
))
13761 if (SUB_CHAR_TABLE_P (val
))
13762 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13768 XSETCHAR_TABLE (table
, dp
);
13769 val
= char_table_ref (table
, c
);
13778 /***********************************************************************
13780 ***********************************************************************/
13782 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13785 redisplay_windows (Lisp_Object window
)
13787 while (!NILP (window
))
13789 struct window
*w
= XWINDOW (window
);
13791 if (WINDOWP (w
->contents
))
13792 redisplay_windows (w
->contents
);
13793 else if (BUFFERP (w
->contents
))
13795 displayed_buffer
= XBUFFER (w
->contents
);
13796 /* Use list_of_error, not Qerror, so that
13797 we catch only errors and don't run the debugger. */
13798 internal_condition_case_1 (redisplay_window_0
, window
,
13800 redisplay_window_error
);
13808 redisplay_window_error (Lisp_Object ignore
)
13810 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13815 redisplay_window_0 (Lisp_Object window
)
13817 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13818 redisplay_window (window
, 0);
13823 redisplay_window_1 (Lisp_Object window
)
13825 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13826 redisplay_window (window
, 1);
13831 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13832 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13833 which positions recorded in ROW differ from current buffer
13836 Return 0 if cursor is not on this row, 1 otherwise. */
13839 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13840 struct glyph_matrix
*matrix
,
13841 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13844 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13845 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13846 struct glyph
*cursor
= NULL
;
13847 /* The last known character position in row. */
13848 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13850 ptrdiff_t pt_old
= PT
- delta
;
13851 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13852 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13853 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13854 /* A glyph beyond the edge of TEXT_AREA which we should never
13856 struct glyph
*glyphs_end
= end
;
13857 /* Non-zero means we've found a match for cursor position, but that
13858 glyph has the avoid_cursor_p flag set. */
13859 int match_with_avoid_cursor
= 0;
13860 /* Non-zero means we've seen at least one glyph that came from a
13862 int string_seen
= 0;
13863 /* Largest and smallest buffer positions seen so far during scan of
13865 ptrdiff_t bpos_max
= pos_before
;
13866 ptrdiff_t bpos_min
= pos_after
;
13867 /* Last buffer position covered by an overlay string with an integer
13868 `cursor' property. */
13869 ptrdiff_t bpos_covered
= 0;
13870 /* Non-zero means the display string on which to display the cursor
13871 comes from a text property, not from an overlay. */
13872 int string_from_text_prop
= 0;
13874 /* Don't even try doing anything if called for a mode-line or
13875 header-line row, since the rest of the code isn't prepared to
13876 deal with such calamities. */
13877 eassert (!row
->mode_line_p
);
13878 if (row
->mode_line_p
)
13881 /* Skip over glyphs not having an object at the start and the end of
13882 the row. These are special glyphs like truncation marks on
13883 terminal frames. */
13884 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13886 if (!row
->reversed_p
)
13889 && INTEGERP (glyph
->object
)
13890 && glyph
->charpos
< 0)
13892 x
+= glyph
->pixel_width
;
13896 && INTEGERP ((end
- 1)->object
)
13897 /* CHARPOS is zero for blanks and stretch glyphs
13898 inserted by extend_face_to_end_of_line. */
13899 && (end
- 1)->charpos
<= 0)
13901 glyph_before
= glyph
- 1;
13908 /* If the glyph row is reversed, we need to process it from back
13909 to front, so swap the edge pointers. */
13910 glyphs_end
= end
= glyph
- 1;
13911 glyph
+= row
->used
[TEXT_AREA
] - 1;
13913 while (glyph
> end
+ 1
13914 && INTEGERP (glyph
->object
)
13915 && glyph
->charpos
< 0)
13918 x
-= glyph
->pixel_width
;
13920 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13922 /* By default, in reversed rows we put the cursor on the
13923 rightmost (first in the reading order) glyph. */
13924 for (g
= end
+ 1; g
< glyph
; g
++)
13925 x
+= g
->pixel_width
;
13927 && INTEGERP ((end
+ 1)->object
)
13928 && (end
+ 1)->charpos
<= 0)
13930 glyph_before
= glyph
+ 1;
13934 else if (row
->reversed_p
)
13936 /* In R2L rows that don't display text, put the cursor on the
13937 rightmost glyph. Case in point: an empty last line that is
13938 part of an R2L paragraph. */
13940 /* Avoid placing the cursor on the last glyph of the row, where
13941 on terminal frames we hold the vertical border between
13942 adjacent windows. */
13943 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13944 && !WINDOW_RIGHTMOST_P (w
)
13945 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13947 x
= -1; /* will be computed below, at label compute_x */
13950 /* Step 1: Try to find the glyph whose character position
13951 corresponds to point. If that's not possible, find 2 glyphs
13952 whose character positions are the closest to point, one before
13953 point, the other after it. */
13954 if (!row
->reversed_p
)
13955 while (/* not marched to end of glyph row */
13957 /* glyph was not inserted by redisplay for internal purposes */
13958 && !INTEGERP (glyph
->object
))
13960 if (BUFFERP (glyph
->object
))
13962 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13964 if (glyph
->charpos
> bpos_max
)
13965 bpos_max
= glyph
->charpos
;
13966 if (glyph
->charpos
< bpos_min
)
13967 bpos_min
= glyph
->charpos
;
13968 if (!glyph
->avoid_cursor_p
)
13970 /* If we hit point, we've found the glyph on which to
13971 display the cursor. */
13974 match_with_avoid_cursor
= 0;
13977 /* See if we've found a better approximation to
13978 POS_BEFORE or to POS_AFTER. */
13979 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13981 pos_before
= glyph
->charpos
;
13982 glyph_before
= glyph
;
13984 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13986 pos_after
= glyph
->charpos
;
13987 glyph_after
= glyph
;
13990 else if (dpos
== 0)
13991 match_with_avoid_cursor
= 1;
13993 else if (STRINGP (glyph
->object
))
13995 Lisp_Object chprop
;
13996 ptrdiff_t glyph_pos
= glyph
->charpos
;
13998 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14000 if (!NILP (chprop
))
14002 /* If the string came from a `display' text property,
14003 look up the buffer position of that property and
14004 use that position to update bpos_max, as if we
14005 actually saw such a position in one of the row's
14006 glyphs. This helps with supporting integer values
14007 of `cursor' property on the display string in
14008 situations where most or all of the row's buffer
14009 text is completely covered by display properties,
14010 so that no glyph with valid buffer positions is
14011 ever seen in the row. */
14012 ptrdiff_t prop_pos
=
14013 string_buffer_position_lim (glyph
->object
, pos_before
,
14016 if (prop_pos
>= pos_before
)
14017 bpos_max
= prop_pos
- 1;
14019 if (INTEGERP (chprop
))
14021 bpos_covered
= bpos_max
+ XINT (chprop
);
14022 /* If the `cursor' property covers buffer positions up
14023 to and including point, we should display cursor on
14024 this glyph. Note that, if a `cursor' property on one
14025 of the string's characters has an integer value, we
14026 will break out of the loop below _before_ we get to
14027 the position match above. IOW, integer values of
14028 the `cursor' property override the "exact match for
14029 point" strategy of positioning the cursor. */
14030 /* Implementation note: bpos_max == pt_old when, e.g.,
14031 we are in an empty line, where bpos_max is set to
14032 MATRIX_ROW_START_CHARPOS, see above. */
14033 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14042 x
+= glyph
->pixel_width
;
14045 else if (glyph
> end
) /* row is reversed */
14046 while (!INTEGERP (glyph
->object
))
14048 if (BUFFERP (glyph
->object
))
14050 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14052 if (glyph
->charpos
> bpos_max
)
14053 bpos_max
= glyph
->charpos
;
14054 if (glyph
->charpos
< bpos_min
)
14055 bpos_min
= glyph
->charpos
;
14056 if (!glyph
->avoid_cursor_p
)
14060 match_with_avoid_cursor
= 0;
14063 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14065 pos_before
= glyph
->charpos
;
14066 glyph_before
= glyph
;
14068 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14070 pos_after
= glyph
->charpos
;
14071 glyph_after
= glyph
;
14074 else if (dpos
== 0)
14075 match_with_avoid_cursor
= 1;
14077 else if (STRINGP (glyph
->object
))
14079 Lisp_Object chprop
;
14080 ptrdiff_t glyph_pos
= glyph
->charpos
;
14082 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14084 if (!NILP (chprop
))
14086 ptrdiff_t prop_pos
=
14087 string_buffer_position_lim (glyph
->object
, pos_before
,
14090 if (prop_pos
>= pos_before
)
14091 bpos_max
= prop_pos
- 1;
14093 if (INTEGERP (chprop
))
14095 bpos_covered
= bpos_max
+ XINT (chprop
);
14096 /* If the `cursor' property covers buffer positions up
14097 to and including point, we should display cursor on
14099 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14108 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14110 x
--; /* can't use any pixel_width */
14113 x
-= glyph
->pixel_width
;
14116 /* Step 2: If we didn't find an exact match for point, we need to
14117 look for a proper place to put the cursor among glyphs between
14118 GLYPH_BEFORE and GLYPH_AFTER. */
14119 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14120 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14121 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14123 /* An empty line has a single glyph whose OBJECT is zero and
14124 whose CHARPOS is the position of a newline on that line.
14125 Note that on a TTY, there are more glyphs after that, which
14126 were produced by extend_face_to_end_of_line, but their
14127 CHARPOS is zero or negative. */
14129 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14130 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14131 /* On a TTY, continued and truncated rows also have a glyph at
14132 their end whose OBJECT is zero and whose CHARPOS is
14133 positive (the continuation and truncation glyphs), but such
14134 rows are obviously not "empty". */
14135 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14137 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14139 ptrdiff_t ellipsis_pos
;
14141 /* Scan back over the ellipsis glyphs. */
14142 if (!row
->reversed_p
)
14144 ellipsis_pos
= (glyph
- 1)->charpos
;
14145 while (glyph
> row
->glyphs
[TEXT_AREA
]
14146 && (glyph
- 1)->charpos
== ellipsis_pos
)
14147 glyph
--, x
-= glyph
->pixel_width
;
14148 /* That loop always goes one position too far, including
14149 the glyph before the ellipsis. So scan forward over
14151 x
+= glyph
->pixel_width
;
14154 else /* row is reversed */
14156 ellipsis_pos
= (glyph
+ 1)->charpos
;
14157 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14158 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14159 glyph
++, x
+= glyph
->pixel_width
;
14160 x
-= glyph
->pixel_width
;
14164 else if (match_with_avoid_cursor
)
14166 cursor
= glyph_after
;
14169 else if (string_seen
)
14171 int incr
= row
->reversed_p
? -1 : +1;
14173 /* Need to find the glyph that came out of a string which is
14174 present at point. That glyph is somewhere between
14175 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14176 positioned between POS_BEFORE and POS_AFTER in the
14178 struct glyph
*start
, *stop
;
14179 ptrdiff_t pos
= pos_before
;
14183 /* If the row ends in a newline from a display string,
14184 reordering could have moved the glyphs belonging to the
14185 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14186 in this case we extend the search to the last glyph in
14187 the row that was not inserted by redisplay. */
14188 if (row
->ends_in_newline_from_string_p
)
14191 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14194 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14195 correspond to POS_BEFORE and POS_AFTER, respectively. We
14196 need START and STOP in the order that corresponds to the
14197 row's direction as given by its reversed_p flag. If the
14198 directionality of characters between POS_BEFORE and
14199 POS_AFTER is the opposite of the row's base direction,
14200 these characters will have been reordered for display,
14201 and we need to reverse START and STOP. */
14202 if (!row
->reversed_p
)
14204 start
= min (glyph_before
, glyph_after
);
14205 stop
= max (glyph_before
, glyph_after
);
14209 start
= max (glyph_before
, glyph_after
);
14210 stop
= min (glyph_before
, glyph_after
);
14212 for (glyph
= start
+ incr
;
14213 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14216 /* Any glyphs that come from the buffer are here because
14217 of bidi reordering. Skip them, and only pay
14218 attention to glyphs that came from some string. */
14219 if (STRINGP (glyph
->object
))
14223 /* If the display property covers the newline, we
14224 need to search for it one position farther. */
14225 ptrdiff_t lim
= pos_after
14226 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14228 string_from_text_prop
= 0;
14229 str
= glyph
->object
;
14230 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14231 if (tem
== 0 /* from overlay */
14234 /* If the string from which this glyph came is
14235 found in the buffer at point, or at position
14236 that is closer to point than pos_after, then
14237 we've found the glyph we've been looking for.
14238 If it comes from an overlay (tem == 0), and
14239 it has the `cursor' property on one of its
14240 glyphs, record that glyph as a candidate for
14241 displaying the cursor. (As in the
14242 unidirectional version, we will display the
14243 cursor on the last candidate we find.) */
14246 || (tem
- pt_old
> 0 && tem
< pos_after
))
14248 /* The glyphs from this string could have
14249 been reordered. Find the one with the
14250 smallest string position. Or there could
14251 be a character in the string with the
14252 `cursor' property, which means display
14253 cursor on that character's glyph. */
14254 ptrdiff_t strpos
= glyph
->charpos
;
14259 string_from_text_prop
= 1;
14262 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14263 && EQ (glyph
->object
, str
);
14267 ptrdiff_t gpos
= glyph
->charpos
;
14269 cprop
= Fget_char_property (make_number (gpos
),
14277 if (tem
&& glyph
->charpos
< strpos
)
14279 strpos
= glyph
->charpos
;
14285 || (tem
- pt_old
> 0 && tem
< pos_after
))
14289 pos
= tem
+ 1; /* don't find previous instances */
14291 /* This string is not what we want; skip all of the
14292 glyphs that came from it. */
14293 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14294 && EQ (glyph
->object
, str
))
14301 /* If we reached the end of the line, and END was from a string,
14302 the cursor is not on this line. */
14304 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14305 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14306 && STRINGP (end
->object
)
14307 && row
->continued_p
)
14310 /* A truncated row may not include PT among its character positions.
14311 Setting the cursor inside the scroll margin will trigger
14312 recalculation of hscroll in hscroll_window_tree. But if a
14313 display string covers point, defer to the string-handling
14314 code below to figure this out. */
14315 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14317 cursor
= glyph_before
;
14320 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14321 /* Zero-width characters produce no glyphs. */
14323 && (row
->reversed_p
14324 ? glyph_after
> glyphs_end
14325 : glyph_after
< glyphs_end
)))
14327 cursor
= glyph_after
;
14333 if (cursor
!= NULL
)
14335 else if (glyph
== glyphs_end
14336 && pos_before
== pos_after
14337 && STRINGP ((row
->reversed_p
14338 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14339 : row
->glyphs
[TEXT_AREA
])->object
))
14341 /* If all the glyphs of this row came from strings, put the
14342 cursor on the first glyph of the row. This avoids having the
14343 cursor outside of the text area in this very rare and hard
14347 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14348 : row
->glyphs
[TEXT_AREA
];
14354 /* Need to compute x that corresponds to GLYPH. */
14355 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14357 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14359 x
+= g
->pixel_width
;
14363 /* ROW could be part of a continued line, which, under bidi
14364 reordering, might have other rows whose start and end charpos
14365 occlude point. Only set w->cursor if we found a better
14366 approximation to the cursor position than we have from previously
14367 examined candidate rows belonging to the same continued line. */
14368 if (/* we already have a candidate row */
14369 w
->cursor
.vpos
>= 0
14370 /* that candidate is not the row we are processing */
14371 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14372 /* Make sure cursor.vpos specifies a row whose start and end
14373 charpos occlude point, and it is valid candidate for being a
14374 cursor-row. This is because some callers of this function
14375 leave cursor.vpos at the row where the cursor was displayed
14376 during the last redisplay cycle. */
14377 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14378 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14379 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14382 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14384 /* Don't consider glyphs that are outside TEXT_AREA. */
14385 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14387 /* Keep the candidate whose buffer position is the closest to
14388 point or has the `cursor' property. */
14389 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14390 w
->cursor
.hpos
>= 0
14391 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14392 && ((BUFFERP (g1
->object
)
14393 && (g1
->charpos
== pt_old
/* an exact match always wins */
14394 || (BUFFERP (glyph
->object
)
14395 && eabs (g1
->charpos
- pt_old
)
14396 < eabs (glyph
->charpos
- pt_old
))))
14397 /* previous candidate is a glyph from a string that has
14398 a non-nil `cursor' property */
14399 || (STRINGP (g1
->object
)
14400 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14401 Qcursor
, g1
->object
))
14402 /* previous candidate is from the same display
14403 string as this one, and the display string
14404 came from a text property */
14405 || (EQ (g1
->object
, glyph
->object
)
14406 && string_from_text_prop
)
14407 /* this candidate is from newline and its
14408 position is not an exact match */
14409 || (INTEGERP (glyph
->object
)
14410 && glyph
->charpos
!= pt_old
)))))
14412 /* If this candidate gives an exact match, use that. */
14413 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14414 /* If this candidate is a glyph created for the
14415 terminating newline of a line, and point is on that
14416 newline, it wins because it's an exact match. */
14417 || (!row
->continued_p
14418 && INTEGERP (glyph
->object
)
14419 && glyph
->charpos
== 0
14420 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14421 /* Otherwise, keep the candidate that comes from a row
14422 spanning less buffer positions. This may win when one or
14423 both candidate positions are on glyphs that came from
14424 display strings, for which we cannot compare buffer
14426 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14427 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14428 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14431 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14433 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14434 w
->cursor
.y
= row
->y
+ dy
;
14436 if (w
== XWINDOW (selected_window
))
14438 if (!row
->continued_p
14439 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14442 this_line_buffer
= XBUFFER (w
->contents
);
14444 CHARPOS (this_line_start_pos
)
14445 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14446 BYTEPOS (this_line_start_pos
)
14447 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14449 CHARPOS (this_line_end_pos
)
14450 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14451 BYTEPOS (this_line_end_pos
)
14452 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14454 this_line_y
= w
->cursor
.y
;
14455 this_line_pixel_height
= row
->height
;
14456 this_line_vpos
= w
->cursor
.vpos
;
14457 this_line_start_x
= row
->x
;
14460 CHARPOS (this_line_start_pos
) = 0;
14467 /* Run window scroll functions, if any, for WINDOW with new window
14468 start STARTP. Sets the window start of WINDOW to that position.
14470 We assume that the window's buffer is really current. */
14472 static struct text_pos
14473 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14475 struct window
*w
= XWINDOW (window
);
14476 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14478 eassert (current_buffer
== XBUFFER (w
->contents
));
14480 if (!NILP (Vwindow_scroll_functions
))
14482 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14483 make_number (CHARPOS (startp
)));
14484 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14485 /* In case the hook functions switch buffers. */
14486 set_buffer_internal (XBUFFER (w
->contents
));
14493 /* Make sure the line containing the cursor is fully visible.
14494 A value of 1 means there is nothing to be done.
14495 (Either the line is fully visible, or it cannot be made so,
14496 or we cannot tell.)
14498 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14499 is higher than window.
14501 A value of 0 means the caller should do scrolling
14502 as if point had gone off the screen. */
14505 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14507 struct glyph_matrix
*matrix
;
14508 struct glyph_row
*row
;
14511 if (!make_cursor_line_fully_visible_p
)
14514 /* It's not always possible to find the cursor, e.g, when a window
14515 is full of overlay strings. Don't do anything in that case. */
14516 if (w
->cursor
.vpos
< 0)
14519 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14520 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14522 /* If the cursor row is not partially visible, there's nothing to do. */
14523 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14526 /* If the row the cursor is in is taller than the window's height,
14527 it's not clear what to do, so do nothing. */
14528 window_height
= window_box_height (w
);
14529 if (row
->height
>= window_height
)
14531 if (!force_p
|| MINI_WINDOW_P (w
)
14532 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14539 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14540 non-zero means only WINDOW is redisplayed in redisplay_internal.
14541 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14542 in redisplay_window to bring a partially visible line into view in
14543 the case that only the cursor has moved.
14545 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14546 last screen line's vertical height extends past the end of the screen.
14550 1 if scrolling succeeded
14552 0 if scrolling didn't find point.
14554 -1 if new fonts have been loaded so that we must interrupt
14555 redisplay, adjust glyph matrices, and try again. */
14561 SCROLLING_NEED_LARGER_MATRICES
14564 /* If scroll-conservatively is more than this, never recenter.
14566 If you change this, don't forget to update the doc string of
14567 `scroll-conservatively' and the Emacs manual. */
14568 #define SCROLL_LIMIT 100
14571 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14572 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14573 int temp_scroll_step
, int last_line_misfit
)
14575 struct window
*w
= XWINDOW (window
);
14576 struct frame
*f
= XFRAME (w
->frame
);
14577 struct text_pos pos
, startp
;
14579 int this_scroll_margin
, scroll_max
, rc
, height
;
14580 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14581 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14582 Lisp_Object aggressive
;
14583 /* We will never try scrolling more than this number of lines. */
14584 int scroll_limit
= SCROLL_LIMIT
;
14585 int frame_line_height
= default_line_pixel_height (w
);
14586 int window_total_lines
14587 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14590 debug_method_add (w
, "try_scrolling");
14593 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14595 /* Compute scroll margin height in pixels. We scroll when point is
14596 within this distance from the top or bottom of the window. */
14597 if (scroll_margin
> 0)
14598 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14599 * frame_line_height
;
14601 this_scroll_margin
= 0;
14603 /* Force arg_scroll_conservatively to have a reasonable value, to
14604 avoid scrolling too far away with slow move_it_* functions. Note
14605 that the user can supply scroll-conservatively equal to
14606 `most-positive-fixnum', which can be larger than INT_MAX. */
14607 if (arg_scroll_conservatively
> scroll_limit
)
14609 arg_scroll_conservatively
= scroll_limit
+ 1;
14610 scroll_max
= scroll_limit
* frame_line_height
;
14612 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14613 /* Compute how much we should try to scroll maximally to bring
14614 point into view. */
14615 scroll_max
= (max (scroll_step
,
14616 max (arg_scroll_conservatively
, temp_scroll_step
))
14617 * frame_line_height
);
14618 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14619 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14620 /* We're trying to scroll because of aggressive scrolling but no
14621 scroll_step is set. Choose an arbitrary one. */
14622 scroll_max
= 10 * frame_line_height
;
14628 /* Decide whether to scroll down. */
14629 if (PT
> CHARPOS (startp
))
14631 int scroll_margin_y
;
14633 /* Compute the pixel ypos of the scroll margin, then move IT to
14634 either that ypos or PT, whichever comes first. */
14635 start_display (&it
, w
, startp
);
14636 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14637 - frame_line_height
* extra_scroll_margin_lines
;
14638 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14639 (MOVE_TO_POS
| MOVE_TO_Y
));
14641 if (PT
> CHARPOS (it
.current
.pos
))
14643 int y0
= line_bottom_y (&it
);
14644 /* Compute how many pixels below window bottom to stop searching
14645 for PT. This avoids costly search for PT that is far away if
14646 the user limited scrolling by a small number of lines, but
14647 always finds PT if scroll_conservatively is set to a large
14648 number, such as most-positive-fixnum. */
14649 int slack
= max (scroll_max
, 10 * frame_line_height
);
14650 int y_to_move
= it
.last_visible_y
+ slack
;
14652 /* Compute the distance from the scroll margin to PT or to
14653 the scroll limit, whichever comes first. This should
14654 include the height of the cursor line, to make that line
14656 move_it_to (&it
, PT
, -1, y_to_move
,
14657 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14658 dy
= line_bottom_y (&it
) - y0
;
14660 if (dy
> scroll_max
)
14661 return SCROLLING_FAILED
;
14670 /* Point is in or below the bottom scroll margin, so move the
14671 window start down. If scrolling conservatively, move it just
14672 enough down to make point visible. If scroll_step is set,
14673 move it down by scroll_step. */
14674 if (arg_scroll_conservatively
)
14676 = min (max (dy
, frame_line_height
),
14677 frame_line_height
* arg_scroll_conservatively
);
14678 else if (scroll_step
|| temp_scroll_step
)
14679 amount_to_scroll
= scroll_max
;
14682 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14683 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14684 if (NUMBERP (aggressive
))
14686 double float_amount
= XFLOATINT (aggressive
) * height
;
14687 int aggressive_scroll
= float_amount
;
14688 if (aggressive_scroll
== 0 && float_amount
> 0)
14689 aggressive_scroll
= 1;
14690 /* Don't let point enter the scroll margin near top of
14691 the window. This could happen if the value of
14692 scroll_up_aggressively is too large and there are
14693 non-zero margins, because scroll_up_aggressively
14694 means put point that fraction of window height
14695 _from_the_bottom_margin_. */
14696 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14697 aggressive_scroll
= height
- 2*this_scroll_margin
;
14698 amount_to_scroll
= dy
+ aggressive_scroll
;
14702 if (amount_to_scroll
<= 0)
14703 return SCROLLING_FAILED
;
14705 start_display (&it
, w
, startp
);
14706 if (arg_scroll_conservatively
<= scroll_limit
)
14707 move_it_vertically (&it
, amount_to_scroll
);
14710 /* Extra precision for users who set scroll-conservatively
14711 to a large number: make sure the amount we scroll
14712 the window start is never less than amount_to_scroll,
14713 which was computed as distance from window bottom to
14714 point. This matters when lines at window top and lines
14715 below window bottom have different height. */
14717 void *it1data
= NULL
;
14718 /* We use a temporary it1 because line_bottom_y can modify
14719 its argument, if it moves one line down; see there. */
14722 SAVE_IT (it1
, it
, it1data
);
14723 start_y
= line_bottom_y (&it1
);
14725 RESTORE_IT (&it
, &it
, it1data
);
14726 move_it_by_lines (&it
, 1);
14727 SAVE_IT (it1
, it
, it1data
);
14728 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14731 /* If STARTP is unchanged, move it down another screen line. */
14732 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14733 move_it_by_lines (&it
, 1);
14734 startp
= it
.current
.pos
;
14738 struct text_pos scroll_margin_pos
= startp
;
14741 /* See if point is inside the scroll margin at the top of the
14743 if (this_scroll_margin
)
14747 start_display (&it
, w
, startp
);
14748 y_start
= it
.current_y
;
14749 move_it_vertically (&it
, this_scroll_margin
);
14750 scroll_margin_pos
= it
.current
.pos
;
14751 /* If we didn't move enough before hitting ZV, request
14752 additional amount of scroll, to move point out of the
14754 if (IT_CHARPOS (it
) == ZV
14755 && it
.current_y
- y_start
< this_scroll_margin
)
14756 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14759 if (PT
< CHARPOS (scroll_margin_pos
))
14761 /* Point is in the scroll margin at the top of the window or
14762 above what is displayed in the window. */
14765 /* Compute the vertical distance from PT to the scroll
14766 margin position. Move as far as scroll_max allows, or
14767 one screenful, or 10 screen lines, whichever is largest.
14768 Give up if distance is greater than scroll_max or if we
14769 didn't reach the scroll margin position. */
14770 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14771 start_display (&it
, w
, pos
);
14773 y_to_move
= max (it
.last_visible_y
,
14774 max (scroll_max
, 10 * frame_line_height
));
14775 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14777 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14778 dy
= it
.current_y
- y0
;
14779 if (dy
> scroll_max
14780 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14781 return SCROLLING_FAILED
;
14783 /* Additional scroll for when ZV was too close to point. */
14786 /* Compute new window start. */
14787 start_display (&it
, w
, startp
);
14789 if (arg_scroll_conservatively
)
14790 amount_to_scroll
= max (dy
, frame_line_height
*
14791 max (scroll_step
, temp_scroll_step
));
14792 else if (scroll_step
|| temp_scroll_step
)
14793 amount_to_scroll
= scroll_max
;
14796 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14797 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14798 if (NUMBERP (aggressive
))
14800 double float_amount
= XFLOATINT (aggressive
) * height
;
14801 int aggressive_scroll
= float_amount
;
14802 if (aggressive_scroll
== 0 && float_amount
> 0)
14803 aggressive_scroll
= 1;
14804 /* Don't let point enter the scroll margin near
14805 bottom of the window, if the value of
14806 scroll_down_aggressively happens to be too
14808 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14809 aggressive_scroll
= height
- 2*this_scroll_margin
;
14810 amount_to_scroll
= dy
+ aggressive_scroll
;
14814 if (amount_to_scroll
<= 0)
14815 return SCROLLING_FAILED
;
14817 move_it_vertically_backward (&it
, amount_to_scroll
);
14818 startp
= it
.current
.pos
;
14822 /* Run window scroll functions. */
14823 startp
= run_window_scroll_functions (window
, startp
);
14825 /* Display the window. Give up if new fonts are loaded, or if point
14827 if (!try_window (window
, startp
, 0))
14828 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14829 else if (w
->cursor
.vpos
< 0)
14831 clear_glyph_matrix (w
->desired_matrix
);
14832 rc
= SCROLLING_FAILED
;
14836 /* Maybe forget recorded base line for line number display. */
14837 if (!just_this_one_p
14838 || current_buffer
->clip_changed
14839 || BEG_UNCHANGED
< CHARPOS (startp
))
14840 w
->base_line_number
= 0;
14842 /* If cursor ends up on a partially visible line,
14843 treat that as being off the bottom of the screen. */
14844 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14845 /* It's possible that the cursor is on the first line of the
14846 buffer, which is partially obscured due to a vscroll
14847 (Bug#7537). In that case, avoid looping forever . */
14848 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14850 clear_glyph_matrix (w
->desired_matrix
);
14851 ++extra_scroll_margin_lines
;
14854 rc
= SCROLLING_SUCCESS
;
14861 /* Compute a suitable window start for window W if display of W starts
14862 on a continuation line. Value is non-zero if a new window start
14865 The new window start will be computed, based on W's width, starting
14866 from the start of the continued line. It is the start of the
14867 screen line with the minimum distance from the old start W->start. */
14870 compute_window_start_on_continuation_line (struct window
*w
)
14872 struct text_pos pos
, start_pos
;
14873 int window_start_changed_p
= 0;
14875 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14877 /* If window start is on a continuation line... Window start may be
14878 < BEGV in case there's invisible text at the start of the
14879 buffer (M-x rmail, for example). */
14880 if (CHARPOS (start_pos
) > BEGV
14881 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14884 struct glyph_row
*row
;
14886 /* Handle the case that the window start is out of range. */
14887 if (CHARPOS (start_pos
) < BEGV
)
14888 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14889 else if (CHARPOS (start_pos
) > ZV
)
14890 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14892 /* Find the start of the continued line. This should be fast
14893 because find_newline is fast (newline cache). */
14894 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14895 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14896 row
, DEFAULT_FACE_ID
);
14897 reseat_at_previous_visible_line_start (&it
);
14899 /* If the line start is "too far" away from the window start,
14900 say it takes too much time to compute a new window start. */
14901 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14902 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14904 int min_distance
, distance
;
14906 /* Move forward by display lines to find the new window
14907 start. If window width was enlarged, the new start can
14908 be expected to be > the old start. If window width was
14909 decreased, the new window start will be < the old start.
14910 So, we're looking for the display line start with the
14911 minimum distance from the old window start. */
14912 pos
= it
.current
.pos
;
14913 min_distance
= INFINITY
;
14914 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14915 distance
< min_distance
)
14917 min_distance
= distance
;
14918 pos
= it
.current
.pos
;
14919 if (it
.line_wrap
== WORD_WRAP
)
14921 /* Under WORD_WRAP, move_it_by_lines is likely to
14922 overshoot and stop not at the first, but the
14923 second character from the left margin. So in
14924 that case, we need a more tight control on the X
14925 coordinate of the iterator than move_it_by_lines
14926 promises in its contract. The method is to first
14927 go to the last (rightmost) visible character of a
14928 line, then move to the leftmost character on the
14929 next line in a separate call. */
14930 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14931 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14932 move_it_to (&it
, ZV
, 0,
14933 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14934 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14937 move_it_by_lines (&it
, 1);
14940 /* Set the window start there. */
14941 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14942 window_start_changed_p
= 1;
14946 return window_start_changed_p
;
14950 /* Try cursor movement in case text has not changed in window WINDOW,
14951 with window start STARTP. Value is
14953 CURSOR_MOVEMENT_SUCCESS if successful
14955 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14957 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14958 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14959 we want to scroll as if scroll-step were set to 1. See the code.
14961 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14962 which case we have to abort this redisplay, and adjust matrices
14967 CURSOR_MOVEMENT_SUCCESS
,
14968 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14969 CURSOR_MOVEMENT_MUST_SCROLL
,
14970 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14974 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14976 struct window
*w
= XWINDOW (window
);
14977 struct frame
*f
= XFRAME (w
->frame
);
14978 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14981 if (inhibit_try_cursor_movement
)
14985 /* Previously, there was a check for Lisp integer in the
14986 if-statement below. Now, this field is converted to
14987 ptrdiff_t, thus zero means invalid position in a buffer. */
14988 eassert (w
->last_point
> 0);
14989 /* Likewise there was a check whether window_end_vpos is nil or larger
14990 than the window. Now window_end_vpos is int and so never nil, but
14991 let's leave eassert to check whether it fits in the window. */
14992 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
14994 /* Handle case where text has not changed, only point, and it has
14995 not moved off the frame. */
14996 if (/* Point may be in this window. */
14997 PT
>= CHARPOS (startp
)
14998 /* Selective display hasn't changed. */
14999 && !current_buffer
->clip_changed
15000 /* Function force-mode-line-update is used to force a thorough
15001 redisplay. It sets either windows_or_buffers_changed or
15002 update_mode_lines. So don't take a shortcut here for these
15004 && !update_mode_lines
15005 && !windows_or_buffers_changed
15006 && !f
->cursor_type_changed
15007 /* Can't use this case if highlighting a region. When a
15008 region exists, cursor movement has to do more than just
15010 && markpos_of_region () < 0
15011 && !w
->region_showing
15012 && NILP (Vshow_trailing_whitespace
)
15013 /* This code is not used for mini-buffer for the sake of the case
15014 of redisplaying to replace an echo area message; since in
15015 that case the mini-buffer contents per se are usually
15016 unchanged. This code is of no real use in the mini-buffer
15017 since the handling of this_line_start_pos, etc., in redisplay
15018 handles the same cases. */
15019 && !EQ (window
, minibuf_window
)
15020 && (FRAME_WINDOW_P (f
)
15021 || !overlay_arrow_in_current_buffer_p ()))
15023 int this_scroll_margin
, top_scroll_margin
;
15024 struct glyph_row
*row
= NULL
;
15025 int frame_line_height
= default_line_pixel_height (w
);
15026 int window_total_lines
15027 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15030 debug_method_add (w
, "cursor movement");
15033 /* Scroll if point within this distance from the top or bottom
15034 of the window. This is a pixel value. */
15035 if (scroll_margin
> 0)
15037 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15038 this_scroll_margin
*= frame_line_height
;
15041 this_scroll_margin
= 0;
15043 top_scroll_margin
= this_scroll_margin
;
15044 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15045 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15047 /* Start with the row the cursor was displayed during the last
15048 not paused redisplay. Give up if that row is not valid. */
15049 if (w
->last_cursor_vpos
< 0
15050 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15051 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15054 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15055 if (row
->mode_line_p
)
15057 if (!row
->enabled_p
)
15058 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15061 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15063 int scroll_p
= 0, must_scroll
= 0;
15064 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15066 if (PT
> w
->last_point
)
15068 /* Point has moved forward. */
15069 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15070 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15072 eassert (row
->enabled_p
);
15076 /* If the end position of a row equals the start
15077 position of the next row, and PT is at that position,
15078 we would rather display cursor in the next line. */
15079 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15080 && MATRIX_ROW_END_CHARPOS (row
) == PT
15081 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15082 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15083 && !cursor_row_p (row
))
15086 /* If within the scroll margin, scroll. Note that
15087 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15088 the next line would be drawn, and that
15089 this_scroll_margin can be zero. */
15090 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15091 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15092 /* Line is completely visible last line in window
15093 and PT is to be set in the next line. */
15094 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15095 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15096 && !row
->ends_at_zv_p
15097 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15100 else if (PT
< w
->last_point
)
15102 /* Cursor has to be moved backward. Note that PT >=
15103 CHARPOS (startp) because of the outer if-statement. */
15104 while (!row
->mode_line_p
15105 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15106 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15107 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15108 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15109 row
> w
->current_matrix
->rows
15110 && (row
-1)->ends_in_newline_from_string_p
))))
15111 && (row
->y
> top_scroll_margin
15112 || CHARPOS (startp
) == BEGV
))
15114 eassert (row
->enabled_p
);
15118 /* Consider the following case: Window starts at BEGV,
15119 there is invisible, intangible text at BEGV, so that
15120 display starts at some point START > BEGV. It can
15121 happen that we are called with PT somewhere between
15122 BEGV and START. Try to handle that case. */
15123 if (row
< w
->current_matrix
->rows
15124 || row
->mode_line_p
)
15126 row
= w
->current_matrix
->rows
;
15127 if (row
->mode_line_p
)
15131 /* Due to newlines in overlay strings, we may have to
15132 skip forward over overlay strings. */
15133 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15134 && MATRIX_ROW_END_CHARPOS (row
) == PT
15135 && !cursor_row_p (row
))
15138 /* If within the scroll margin, scroll. */
15139 if (row
->y
< top_scroll_margin
15140 && CHARPOS (startp
) != BEGV
)
15145 /* Cursor did not move. So don't scroll even if cursor line
15146 is partially visible, as it was so before. */
15147 rc
= CURSOR_MOVEMENT_SUCCESS
;
15150 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15151 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15153 /* if PT is not in the glyph row, give up. */
15154 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15157 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15158 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15160 struct glyph_row
*row1
;
15162 /* If rows are bidi-reordered and point moved, back up
15163 until we find a row that does not belong to a
15164 continuation line. This is because we must consider
15165 all rows of a continued line as candidates for the
15166 new cursor positioning, since row start and end
15167 positions change non-linearly with vertical position
15169 /* FIXME: Revisit this when glyph ``spilling'' in
15170 continuation lines' rows is implemented for
15171 bidi-reordered rows. */
15172 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15173 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15176 /* If we hit the beginning of the displayed portion
15177 without finding the first row of a continued
15181 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15184 eassert (row
->enabled_p
);
15189 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15190 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15191 /* Make sure this isn't a header line by any chance, since
15192 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15193 && !row
->mode_line_p
15194 && make_cursor_line_fully_visible_p
)
15196 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15197 && !row
->ends_at_zv_p
15198 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15199 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15200 else if (row
->height
> window_box_height (w
))
15202 /* If we end up in a partially visible line, let's
15203 make it fully visible, except when it's taller
15204 than the window, in which case we can't do much
15207 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15211 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15212 if (!cursor_row_fully_visible_p (w
, 0, 1))
15213 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15215 rc
= CURSOR_MOVEMENT_SUCCESS
;
15219 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15220 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15221 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15223 /* With bidi-reordered rows, there could be more than
15224 one candidate row whose start and end positions
15225 occlude point. We need to let set_cursor_from_row
15226 find the best candidate. */
15227 /* FIXME: Revisit this when glyph ``spilling'' in
15228 continuation lines' rows is implemented for
15229 bidi-reordered rows. */
15234 int at_zv_p
= 0, exact_match_p
= 0;
15236 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15237 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15238 && cursor_row_p (row
))
15239 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15241 /* As soon as we've found the exact match for point,
15242 or the first suitable row whose ends_at_zv_p flag
15243 is set, we are done. */
15245 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15247 && w
->cursor
.hpos
>= 0
15248 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15251 struct glyph_row
*candidate
=
15252 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15254 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15255 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15258 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15259 || (INTEGERP (g
->object
)
15260 && (g
->charpos
== PT
15261 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15263 if (rv
&& (at_zv_p
|| exact_match_p
))
15265 rc
= CURSOR_MOVEMENT_SUCCESS
;
15268 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15272 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15273 || row
->continued_p
)
15274 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15275 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15276 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15277 /* If we didn't find any candidate rows, or exited the
15278 loop before all the candidates were examined, signal
15279 to the caller that this method failed. */
15280 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15282 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15283 && !row
->continued_p
))
15284 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15286 rc
= CURSOR_MOVEMENT_SUCCESS
;
15292 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15294 rc
= CURSOR_MOVEMENT_SUCCESS
;
15299 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15300 && MATRIX_ROW_START_CHARPOS (row
) == PT
15301 && cursor_row_p (row
));
15309 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15313 set_vertical_scroll_bar (struct window
*w
)
15315 ptrdiff_t start
, end
, whole
;
15317 /* Calculate the start and end positions for the current window.
15318 At some point, it would be nice to choose between scrollbars
15319 which reflect the whole buffer size, with special markers
15320 indicating narrowing, and scrollbars which reflect only the
15323 Note that mini-buffers sometimes aren't displaying any text. */
15324 if (!MINI_WINDOW_P (w
)
15325 || (w
== XWINDOW (minibuf_window
)
15326 && NILP (echo_area_buffer
[0])))
15328 struct buffer
*buf
= XBUFFER (w
->contents
);
15329 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15330 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15331 /* I don't think this is guaranteed to be right. For the
15332 moment, we'll pretend it is. */
15333 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15337 if (whole
< (end
- start
))
15338 whole
= end
- start
;
15341 start
= end
= whole
= 0;
15343 /* Indicate what this scroll bar ought to be displaying now. */
15344 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15345 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15346 (w
, end
- start
, whole
, start
);
15350 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15351 selected_window is redisplayed.
15353 We can return without actually redisplaying the window if fonts has been
15354 changed on window's frame. In that case, redisplay_internal will retry. */
15357 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15359 struct window
*w
= XWINDOW (window
);
15360 struct frame
*f
= XFRAME (w
->frame
);
15361 struct buffer
*buffer
= XBUFFER (w
->contents
);
15362 struct buffer
*old
= current_buffer
;
15363 struct text_pos lpoint
, opoint
, startp
;
15364 int update_mode_line
;
15367 /* Record it now because it's overwritten. */
15368 int current_matrix_up_to_date_p
= 0;
15369 int used_current_matrix_p
= 0;
15370 /* This is less strict than current_matrix_up_to_date_p.
15371 It indicates that the buffer contents and narrowing are unchanged. */
15372 int buffer_unchanged_p
= 0;
15373 int temp_scroll_step
= 0;
15374 ptrdiff_t count
= SPECPDL_INDEX ();
15376 int centering_position
= -1;
15377 int last_line_misfit
= 0;
15378 ptrdiff_t beg_unchanged
, end_unchanged
;
15379 int frame_line_height
;
15381 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15385 *w
->desired_matrix
->method
= 0;
15388 /* Make sure that both W's markers are valid. */
15389 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15390 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15393 reconsider_clip_changes (w
);
15394 frame_line_height
= default_line_pixel_height (w
);
15396 /* Has the mode line to be updated? */
15397 update_mode_line
= (w
->update_mode_line
15398 || update_mode_lines
15399 || buffer
->clip_changed
15400 || buffer
->prevent_redisplay_optimizations_p
);
15402 if (MINI_WINDOW_P (w
))
15404 if (w
== XWINDOW (echo_area_window
)
15405 && !NILP (echo_area_buffer
[0]))
15407 if (update_mode_line
)
15408 /* We may have to update a tty frame's menu bar or a
15409 tool-bar. Example `M-x C-h C-h C-g'. */
15410 goto finish_menu_bars
;
15412 /* We've already displayed the echo area glyphs in this window. */
15413 goto finish_scroll_bars
;
15415 else if ((w
!= XWINDOW (minibuf_window
)
15416 || minibuf_level
== 0)
15417 /* When buffer is nonempty, redisplay window normally. */
15418 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15419 /* Quail displays non-mini buffers in minibuffer window.
15420 In that case, redisplay the window normally. */
15421 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15423 /* W is a mini-buffer window, but it's not active, so clear
15425 int yb
= window_text_bottom_y (w
);
15426 struct glyph_row
*row
;
15429 for (y
= 0, row
= w
->desired_matrix
->rows
;
15431 y
+= row
->height
, ++row
)
15432 blank_row (w
, row
, y
);
15433 goto finish_scroll_bars
;
15436 clear_glyph_matrix (w
->desired_matrix
);
15439 /* Otherwise set up data on this window; select its buffer and point
15441 /* Really select the buffer, for the sake of buffer-local
15443 set_buffer_internal_1 (XBUFFER (w
->contents
));
15445 current_matrix_up_to_date_p
15446 = (w
->window_end_valid
15447 && !current_buffer
->clip_changed
15448 && !current_buffer
->prevent_redisplay_optimizations_p
15449 && !window_outdated (w
));
15451 /* Run the window-bottom-change-functions
15452 if it is possible that the text on the screen has changed
15453 (either due to modification of the text, or any other reason). */
15454 if (!current_matrix_up_to_date_p
15455 && !NILP (Vwindow_text_change_functions
))
15457 safe_run_hooks (Qwindow_text_change_functions
);
15461 beg_unchanged
= BEG_UNCHANGED
;
15462 end_unchanged
= END_UNCHANGED
;
15464 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15466 specbind (Qinhibit_point_motion_hooks
, Qt
);
15469 = (w
->window_end_valid
15470 && !current_buffer
->clip_changed
15471 && !window_outdated (w
));
15473 /* When windows_or_buffers_changed is non-zero, we can't rely
15474 on the window end being valid, so set it to zero there. */
15475 if (windows_or_buffers_changed
)
15477 /* If window starts on a continuation line, maybe adjust the
15478 window start in case the window's width changed. */
15479 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15480 compute_window_start_on_continuation_line (w
);
15482 w
->window_end_valid
= 0;
15483 /* If so, we also can't rely on current matrix
15484 and should not fool try_cursor_movement below. */
15485 current_matrix_up_to_date_p
= 0;
15488 /* Some sanity checks. */
15489 CHECK_WINDOW_END (w
);
15490 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15492 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15495 if (mode_line_update_needed (w
))
15496 update_mode_line
= 1;
15498 /* Point refers normally to the selected window. For any other
15499 window, set up appropriate value. */
15500 if (!EQ (window
, selected_window
))
15502 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15503 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15507 new_pt_byte
= BEGV_BYTE
;
15508 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15510 else if (new_pt
> (ZV
- 1))
15513 new_pt_byte
= ZV_BYTE
;
15514 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15517 /* We don't use SET_PT so that the point-motion hooks don't run. */
15518 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15521 /* If any of the character widths specified in the display table
15522 have changed, invalidate the width run cache. It's true that
15523 this may be a bit late to catch such changes, but the rest of
15524 redisplay goes (non-fatally) haywire when the display table is
15525 changed, so why should we worry about doing any better? */
15526 if (current_buffer
->width_run_cache
)
15528 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15530 if (! disptab_matches_widthtab
15531 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15533 invalidate_region_cache (current_buffer
,
15534 current_buffer
->width_run_cache
,
15536 recompute_width_table (current_buffer
, disptab
);
15540 /* If window-start is screwed up, choose a new one. */
15541 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15544 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15546 /* If someone specified a new starting point but did not insist,
15547 check whether it can be used. */
15548 if (w
->optional_new_start
15549 && CHARPOS (startp
) >= BEGV
15550 && CHARPOS (startp
) <= ZV
)
15552 w
->optional_new_start
= 0;
15553 start_display (&it
, w
, startp
);
15554 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15555 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15556 if (IT_CHARPOS (it
) == PT
)
15557 w
->force_start
= 1;
15558 /* IT may overshoot PT if text at PT is invisible. */
15559 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15560 w
->force_start
= 1;
15565 /* Handle case where place to start displaying has been specified,
15566 unless the specified location is outside the accessible range. */
15567 if (w
->force_start
|| window_frozen_p (w
))
15569 /* We set this later on if we have to adjust point. */
15572 w
->force_start
= 0;
15574 w
->window_end_valid
= 0;
15576 /* Forget any recorded base line for line number display. */
15577 if (!buffer_unchanged_p
)
15578 w
->base_line_number
= 0;
15580 /* Redisplay the mode line. Select the buffer properly for that.
15581 Also, run the hook window-scroll-functions
15582 because we have scrolled. */
15583 /* Note, we do this after clearing force_start because
15584 if there's an error, it is better to forget about force_start
15585 than to get into an infinite loop calling the hook functions
15586 and having them get more errors. */
15587 if (!update_mode_line
15588 || ! NILP (Vwindow_scroll_functions
))
15590 update_mode_line
= 1;
15591 w
->update_mode_line
= 1;
15592 startp
= run_window_scroll_functions (window
, startp
);
15595 if (CHARPOS (startp
) < BEGV
)
15596 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15597 else if (CHARPOS (startp
) > ZV
)
15598 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15600 /* Redisplay, then check if cursor has been set during the
15601 redisplay. Give up if new fonts were loaded. */
15602 /* We used to issue a CHECK_MARGINS argument to try_window here,
15603 but this causes scrolling to fail when point begins inside
15604 the scroll margin (bug#148) -- cyd */
15605 if (!try_window (window
, startp
, 0))
15607 w
->force_start
= 1;
15608 clear_glyph_matrix (w
->desired_matrix
);
15609 goto need_larger_matrices
;
15612 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15614 /* If point does not appear, try to move point so it does
15615 appear. The desired matrix has been built above, so we
15616 can use it here. */
15617 new_vpos
= window_box_height (w
) / 2;
15620 if (!cursor_row_fully_visible_p (w
, 0, 0))
15622 /* Point does appear, but on a line partly visible at end of window.
15623 Move it back to a fully-visible line. */
15624 new_vpos
= window_box_height (w
);
15626 else if (w
->cursor
.vpos
>=0)
15628 /* Some people insist on not letting point enter the scroll
15629 margin, even though this part handles windows that didn't
15631 int window_total_lines
15632 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15633 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15634 int pixel_margin
= margin
* frame_line_height
;
15635 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15637 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15638 below, which finds the row to move point to, advances by
15639 the Y coordinate of the _next_ row, see the definition of
15640 MATRIX_ROW_BOTTOM_Y. */
15641 if (w
->cursor
.vpos
< margin
+ header_line
)
15643 w
->cursor
.vpos
= -1;
15644 clear_glyph_matrix (w
->desired_matrix
);
15645 goto try_to_scroll
;
15649 int window_height
= window_box_height (w
);
15652 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15653 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15655 w
->cursor
.vpos
= -1;
15656 clear_glyph_matrix (w
->desired_matrix
);
15657 goto try_to_scroll
;
15662 /* If we need to move point for either of the above reasons,
15663 now actually do it. */
15666 struct glyph_row
*row
;
15668 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15669 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15672 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15673 MATRIX_ROW_START_BYTEPOS (row
));
15675 if (w
!= XWINDOW (selected_window
))
15676 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15677 else if (current_buffer
== old
)
15678 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15680 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15682 /* If we are highlighting the region, then we just changed
15683 the region, so redisplay to show it. */
15684 if (markpos_of_region () >= 0)
15686 clear_glyph_matrix (w
->desired_matrix
);
15687 if (!try_window (window
, startp
, 0))
15688 goto need_larger_matrices
;
15693 debug_method_add (w
, "forced window start");
15698 /* Handle case where text has not changed, only point, and it has
15699 not moved off the frame, and we are not retrying after hscroll.
15700 (current_matrix_up_to_date_p is nonzero when retrying.) */
15701 if (current_matrix_up_to_date_p
15702 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15703 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15707 case CURSOR_MOVEMENT_SUCCESS
:
15708 used_current_matrix_p
= 1;
15711 case CURSOR_MOVEMENT_MUST_SCROLL
:
15712 goto try_to_scroll
;
15718 /* If current starting point was originally the beginning of a line
15719 but no longer is, find a new starting point. */
15720 else if (w
->start_at_line_beg
15721 && !(CHARPOS (startp
) <= BEGV
15722 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15725 debug_method_add (w
, "recenter 1");
15730 /* Try scrolling with try_window_id. Value is > 0 if update has
15731 been done, it is -1 if we know that the same window start will
15732 not work. It is 0 if unsuccessful for some other reason. */
15733 else if ((tem
= try_window_id (w
)) != 0)
15736 debug_method_add (w
, "try_window_id %d", tem
);
15739 if (f
->fonts_changed
)
15740 goto need_larger_matrices
;
15744 /* Otherwise try_window_id has returned -1 which means that we
15745 don't want the alternative below this comment to execute. */
15747 else if (CHARPOS (startp
) >= BEGV
15748 && CHARPOS (startp
) <= ZV
15749 && PT
>= CHARPOS (startp
)
15750 && (CHARPOS (startp
) < ZV
15751 /* Avoid starting at end of buffer. */
15752 || CHARPOS (startp
) == BEGV
15753 || !window_outdated (w
)))
15755 int d1
, d2
, d3
, d4
, d5
, d6
;
15757 /* If first window line is a continuation line, and window start
15758 is inside the modified region, but the first change is before
15759 current window start, we must select a new window start.
15761 However, if this is the result of a down-mouse event (e.g. by
15762 extending the mouse-drag-overlay), we don't want to select a
15763 new window start, since that would change the position under
15764 the mouse, resulting in an unwanted mouse-movement rather
15765 than a simple mouse-click. */
15766 if (!w
->start_at_line_beg
15767 && NILP (do_mouse_tracking
)
15768 && CHARPOS (startp
) > BEGV
15769 && CHARPOS (startp
) > BEG
+ beg_unchanged
15770 && CHARPOS (startp
) <= Z
- end_unchanged
15771 /* Even if w->start_at_line_beg is nil, a new window may
15772 start at a line_beg, since that's how set_buffer_window
15773 sets it. So, we need to check the return value of
15774 compute_window_start_on_continuation_line. (See also
15776 && XMARKER (w
->start
)->buffer
== current_buffer
15777 && compute_window_start_on_continuation_line (w
)
15778 /* It doesn't make sense to force the window start like we
15779 do at label force_start if it is already known that point
15780 will not be visible in the resulting window, because
15781 doing so will move point from its correct position
15782 instead of scrolling the window to bring point into view.
15784 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15786 w
->force_start
= 1;
15787 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15792 debug_method_add (w
, "same window start");
15795 /* Try to redisplay starting at same place as before.
15796 If point has not moved off frame, accept the results. */
15797 if (!current_matrix_up_to_date_p
15798 /* Don't use try_window_reusing_current_matrix in this case
15799 because a window scroll function can have changed the
15801 || !NILP (Vwindow_scroll_functions
)
15802 || MINI_WINDOW_P (w
)
15803 || !(used_current_matrix_p
15804 = try_window_reusing_current_matrix (w
)))
15806 IF_DEBUG (debug_method_add (w
, "1"));
15807 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15808 /* -1 means we need to scroll.
15809 0 means we need new matrices, but fonts_changed
15810 is set in that case, so we will detect it below. */
15811 goto try_to_scroll
;
15814 if (f
->fonts_changed
)
15815 goto need_larger_matrices
;
15817 if (w
->cursor
.vpos
>= 0)
15819 if (!just_this_one_p
15820 || current_buffer
->clip_changed
15821 || BEG_UNCHANGED
< CHARPOS (startp
))
15822 /* Forget any recorded base line for line number display. */
15823 w
->base_line_number
= 0;
15825 if (!cursor_row_fully_visible_p (w
, 1, 0))
15827 clear_glyph_matrix (w
->desired_matrix
);
15828 last_line_misfit
= 1;
15830 /* Drop through and scroll. */
15835 clear_glyph_matrix (w
->desired_matrix
);
15840 /* Redisplay the mode line. Select the buffer properly for that. */
15841 if (!update_mode_line
)
15843 update_mode_line
= 1;
15844 w
->update_mode_line
= 1;
15847 /* Try to scroll by specified few lines. */
15848 if ((scroll_conservatively
15849 || emacs_scroll_step
15850 || temp_scroll_step
15851 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15852 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15853 && CHARPOS (startp
) >= BEGV
15854 && CHARPOS (startp
) <= ZV
)
15856 /* The function returns -1 if new fonts were loaded, 1 if
15857 successful, 0 if not successful. */
15858 int ss
= try_scrolling (window
, just_this_one_p
,
15859 scroll_conservatively
,
15861 temp_scroll_step
, last_line_misfit
);
15864 case SCROLLING_SUCCESS
:
15867 case SCROLLING_NEED_LARGER_MATRICES
:
15868 goto need_larger_matrices
;
15870 case SCROLLING_FAILED
:
15878 /* Finally, just choose a place to start which positions point
15879 according to user preferences. */
15884 debug_method_add (w
, "recenter");
15887 /* Forget any previously recorded base line for line number display. */
15888 if (!buffer_unchanged_p
)
15889 w
->base_line_number
= 0;
15891 /* Determine the window start relative to point. */
15892 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15893 it
.current_y
= it
.last_visible_y
;
15894 if (centering_position
< 0)
15896 int window_total_lines
15897 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15900 ? min (scroll_margin
, window_total_lines
/ 4)
15902 ptrdiff_t margin_pos
= CHARPOS (startp
);
15903 Lisp_Object aggressive
;
15906 /* If there is a scroll margin at the top of the window, find
15907 its character position. */
15909 /* Cannot call start_display if startp is not in the
15910 accessible region of the buffer. This can happen when we
15911 have just switched to a different buffer and/or changed
15912 its restriction. In that case, startp is initialized to
15913 the character position 1 (BEGV) because we did not yet
15914 have chance to display the buffer even once. */
15915 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15918 void *it1data
= NULL
;
15920 SAVE_IT (it1
, it
, it1data
);
15921 start_display (&it1
, w
, startp
);
15922 move_it_vertically (&it1
, margin
* frame_line_height
);
15923 margin_pos
= IT_CHARPOS (it1
);
15924 RESTORE_IT (&it
, &it
, it1data
);
15926 scrolling_up
= PT
> margin_pos
;
15929 ? BVAR (current_buffer
, scroll_up_aggressively
)
15930 : BVAR (current_buffer
, scroll_down_aggressively
);
15932 if (!MINI_WINDOW_P (w
)
15933 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15937 /* Setting scroll-conservatively overrides
15938 scroll-*-aggressively. */
15939 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15941 double float_amount
= XFLOATINT (aggressive
);
15943 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15944 if (pt_offset
== 0 && float_amount
> 0)
15946 if (pt_offset
&& margin
> 0)
15949 /* Compute how much to move the window start backward from
15950 point so that point will be displayed where the user
15954 centering_position
= it
.last_visible_y
;
15956 centering_position
-= pt_offset
;
15957 centering_position
-=
15958 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15959 + WINDOW_HEADER_LINE_HEIGHT (w
);
15960 /* Don't let point enter the scroll margin near top of
15962 if (centering_position
< margin
* frame_line_height
)
15963 centering_position
= margin
* frame_line_height
;
15966 centering_position
= margin
* frame_line_height
+ pt_offset
;
15969 /* Set the window start half the height of the window backward
15971 centering_position
= window_box_height (w
) / 2;
15973 move_it_vertically_backward (&it
, centering_position
);
15975 eassert (IT_CHARPOS (it
) >= BEGV
);
15977 /* The function move_it_vertically_backward may move over more
15978 than the specified y-distance. If it->w is small, e.g. a
15979 mini-buffer window, we may end up in front of the window's
15980 display area. Start displaying at the start of the line
15981 containing PT in this case. */
15982 if (it
.current_y
<= 0)
15984 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15985 move_it_vertically_backward (&it
, 0);
15989 it
.current_x
= it
.hpos
= 0;
15991 /* Set the window start position here explicitly, to avoid an
15992 infinite loop in case the functions in window-scroll-functions
15994 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15996 /* Run scroll hooks. */
15997 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15999 /* Redisplay the window. */
16000 if (!current_matrix_up_to_date_p
16001 || windows_or_buffers_changed
16002 || f
->cursor_type_changed
16003 /* Don't use try_window_reusing_current_matrix in this case
16004 because it can have changed the buffer. */
16005 || !NILP (Vwindow_scroll_functions
)
16006 || !just_this_one_p
16007 || MINI_WINDOW_P (w
)
16008 || !(used_current_matrix_p
16009 = try_window_reusing_current_matrix (w
)))
16010 try_window (window
, startp
, 0);
16012 /* If new fonts have been loaded (due to fontsets), give up. We
16013 have to start a new redisplay since we need to re-adjust glyph
16015 if (f
->fonts_changed
)
16016 goto need_larger_matrices
;
16018 /* If cursor did not appear assume that the middle of the window is
16019 in the first line of the window. Do it again with the next line.
16020 (Imagine a window of height 100, displaying two lines of height
16021 60. Moving back 50 from it->last_visible_y will end in the first
16023 if (w
->cursor
.vpos
< 0)
16025 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16027 clear_glyph_matrix (w
->desired_matrix
);
16028 move_it_by_lines (&it
, 1);
16029 try_window (window
, it
.current
.pos
, 0);
16031 else if (PT
< IT_CHARPOS (it
))
16033 clear_glyph_matrix (w
->desired_matrix
);
16034 move_it_by_lines (&it
, -1);
16035 try_window (window
, it
.current
.pos
, 0);
16039 /* Not much we can do about it. */
16043 /* Consider the following case: Window starts at BEGV, there is
16044 invisible, intangible text at BEGV, so that display starts at
16045 some point START > BEGV. It can happen that we are called with
16046 PT somewhere between BEGV and START. Try to handle that case. */
16047 if (w
->cursor
.vpos
< 0)
16049 struct glyph_row
*row
= w
->current_matrix
->rows
;
16050 if (row
->mode_line_p
)
16052 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16055 if (!cursor_row_fully_visible_p (w
, 0, 0))
16057 /* If vscroll is enabled, disable it and try again. */
16061 clear_glyph_matrix (w
->desired_matrix
);
16065 /* Users who set scroll-conservatively to a large number want
16066 point just above/below the scroll margin. If we ended up
16067 with point's row partially visible, move the window start to
16068 make that row fully visible and out of the margin. */
16069 if (scroll_conservatively
> SCROLL_LIMIT
)
16071 int window_total_lines
16072 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16075 ? min (scroll_margin
, window_total_lines
/ 4)
16077 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16079 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16080 clear_glyph_matrix (w
->desired_matrix
);
16081 if (1 == try_window (window
, it
.current
.pos
,
16082 TRY_WINDOW_CHECK_MARGINS
))
16086 /* If centering point failed to make the whole line visible,
16087 put point at the top instead. That has to make the whole line
16088 visible, if it can be done. */
16089 if (centering_position
== 0)
16092 clear_glyph_matrix (w
->desired_matrix
);
16093 centering_position
= 0;
16099 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16100 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16101 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16103 /* Display the mode line, if we must. */
16104 if ((update_mode_line
16105 /* If window not full width, must redo its mode line
16106 if (a) the window to its side is being redone and
16107 (b) we do a frame-based redisplay. This is a consequence
16108 of how inverted lines are drawn in frame-based redisplay. */
16109 || (!just_this_one_p
16110 && !FRAME_WINDOW_P (f
)
16111 && !WINDOW_FULL_WIDTH_P (w
))
16112 /* Line number to display. */
16113 || w
->base_line_pos
> 0
16114 /* Column number is displayed and different from the one displayed. */
16115 || (w
->column_number_displayed
!= -1
16116 && (w
->column_number_displayed
!= current_column ())))
16117 /* This means that the window has a mode line. */
16118 && (WINDOW_WANTS_MODELINE_P (w
)
16119 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16121 display_mode_lines (w
);
16123 /* If mode line height has changed, arrange for a thorough
16124 immediate redisplay using the correct mode line height. */
16125 if (WINDOW_WANTS_MODELINE_P (w
)
16126 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16128 f
->fonts_changed
= 1;
16129 w
->mode_line_height
= -1;
16130 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16131 = DESIRED_MODE_LINE_HEIGHT (w
);
16134 /* If header line height has changed, arrange for a thorough
16135 immediate redisplay using the correct header line height. */
16136 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16137 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16139 f
->fonts_changed
= 1;
16140 w
->header_line_height
= -1;
16141 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16142 = DESIRED_HEADER_LINE_HEIGHT (w
);
16145 if (f
->fonts_changed
)
16146 goto need_larger_matrices
;
16149 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16151 w
->base_line_pos
= 0;
16152 w
->base_line_number
= 0;
16157 /* When we reach a frame's selected window, redo the frame's menu bar. */
16158 if (update_mode_line
16159 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16161 int redisplay_menu_p
= 0;
16163 if (FRAME_WINDOW_P (f
))
16165 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16166 || defined (HAVE_NS) || defined (USE_GTK)
16167 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16169 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16173 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16175 if (redisplay_menu_p
)
16176 display_menu_bar (w
);
16178 #ifdef HAVE_WINDOW_SYSTEM
16179 if (FRAME_WINDOW_P (f
))
16181 #if defined (USE_GTK) || defined (HAVE_NS)
16182 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16183 redisplay_tool_bar (f
);
16185 if (WINDOWP (f
->tool_bar_window
)
16186 && (FRAME_TOOL_BAR_LINES (f
) > 0
16187 || !NILP (Vauto_resize_tool_bars
))
16188 && redisplay_tool_bar (f
))
16189 ignore_mouse_drag_p
= 1;
16195 #ifdef HAVE_WINDOW_SYSTEM
16196 if (FRAME_WINDOW_P (f
)
16197 && update_window_fringes (w
, (just_this_one_p
16198 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16199 || w
->pseudo_window_p
)))
16203 if (draw_window_fringes (w
, 1))
16204 x_draw_vertical_border (w
);
16208 #endif /* HAVE_WINDOW_SYSTEM */
16210 /* We go to this label, with fonts_changed set, if it is
16211 necessary to try again using larger glyph matrices.
16212 We have to redeem the scroll bar even in this case,
16213 because the loop in redisplay_internal expects that. */
16214 need_larger_matrices
:
16216 finish_scroll_bars
:
16218 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16220 /* Set the thumb's position and size. */
16221 set_vertical_scroll_bar (w
);
16223 /* Note that we actually used the scroll bar attached to this
16224 window, so it shouldn't be deleted at the end of redisplay. */
16225 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16226 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16229 /* Restore current_buffer and value of point in it. The window
16230 update may have changed the buffer, so first make sure `opoint'
16231 is still valid (Bug#6177). */
16232 if (CHARPOS (opoint
) < BEGV
)
16233 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16234 else if (CHARPOS (opoint
) > ZV
)
16235 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16237 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16239 set_buffer_internal_1 (old
);
16240 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16241 shorter. This can be caused by log truncation in *Messages*. */
16242 if (CHARPOS (lpoint
) <= ZV
)
16243 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16245 unbind_to (count
, Qnil
);
16249 /* Build the complete desired matrix of WINDOW with a window start
16250 buffer position POS.
16252 Value is 1 if successful. It is zero if fonts were loaded during
16253 redisplay which makes re-adjusting glyph matrices necessary, and -1
16254 if point would appear in the scroll margins.
16255 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16256 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16260 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16262 struct window
*w
= XWINDOW (window
);
16264 struct glyph_row
*last_text_row
= NULL
;
16265 struct frame
*f
= XFRAME (w
->frame
);
16266 int frame_line_height
= default_line_pixel_height (w
);
16268 /* Make POS the new window start. */
16269 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16271 /* Mark cursor position as unknown. No overlay arrow seen. */
16272 w
->cursor
.vpos
= -1;
16273 overlay_arrow_seen
= 0;
16275 /* Initialize iterator and info to start at POS. */
16276 start_display (&it
, w
, pos
);
16278 /* Display all lines of W. */
16279 while (it
.current_y
< it
.last_visible_y
)
16281 if (display_line (&it
))
16282 last_text_row
= it
.glyph_row
- 1;
16283 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16287 /* Don't let the cursor end in the scroll margins. */
16288 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16289 && !MINI_WINDOW_P (w
))
16291 int this_scroll_margin
;
16292 int window_total_lines
16293 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16295 if (scroll_margin
> 0)
16297 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16298 this_scroll_margin
*= frame_line_height
;
16301 this_scroll_margin
= 0;
16303 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16304 && w
->cursor
.y
< this_scroll_margin
16305 && CHARPOS (pos
) > BEGV
16306 && IT_CHARPOS (it
) < ZV
)
16307 /* rms: considering make_cursor_line_fully_visible_p here
16308 seems to give wrong results. We don't want to recenter
16309 when the last line is partly visible, we want to allow
16310 that case to be handled in the usual way. */
16311 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16313 w
->cursor
.vpos
= -1;
16314 clear_glyph_matrix (w
->desired_matrix
);
16319 /* If bottom moved off end of frame, change mode line percentage. */
16320 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16321 w
->update_mode_line
= 1;
16323 /* Set window_end_pos to the offset of the last character displayed
16324 on the window from the end of current_buffer. Set
16325 window_end_vpos to its row number. */
16328 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16329 adjust_window_ends (w
, last_text_row
, 0);
16331 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16332 w
->window_end_vpos
)));
16336 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16337 w
->window_end_pos
= Z
- ZV
;
16338 w
->window_end_vpos
= 0;
16341 /* But that is not valid info until redisplay finishes. */
16342 w
->window_end_valid
= 0;
16348 /************************************************************************
16349 Window redisplay reusing current matrix when buffer has not changed
16350 ************************************************************************/
16352 /* Try redisplay of window W showing an unchanged buffer with a
16353 different window start than the last time it was displayed by
16354 reusing its current matrix. Value is non-zero if successful.
16355 W->start is the new window start. */
16358 try_window_reusing_current_matrix (struct window
*w
)
16360 struct frame
*f
= XFRAME (w
->frame
);
16361 struct glyph_row
*bottom_row
;
16364 struct text_pos start
, new_start
;
16365 int nrows_scrolled
, i
;
16366 struct glyph_row
*last_text_row
;
16367 struct glyph_row
*last_reused_text_row
;
16368 struct glyph_row
*start_row
;
16369 int start_vpos
, min_y
, max_y
;
16372 if (inhibit_try_window_reusing
)
16376 if (/* This function doesn't handle terminal frames. */
16377 !FRAME_WINDOW_P (f
)
16378 /* Don't try to reuse the display if windows have been split
16380 || windows_or_buffers_changed
16381 || f
->cursor_type_changed
)
16384 /* Can't do this if region may have changed. */
16385 if (markpos_of_region () >= 0
16386 || w
->region_showing
16387 || !NILP (Vshow_trailing_whitespace
))
16390 /* If top-line visibility has changed, give up. */
16391 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16392 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16395 /* Give up if old or new display is scrolled vertically. We could
16396 make this function handle this, but right now it doesn't. */
16397 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16398 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16401 /* The variable new_start now holds the new window start. The old
16402 start `start' can be determined from the current matrix. */
16403 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16404 start
= start_row
->minpos
;
16405 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16407 /* Clear the desired matrix for the display below. */
16408 clear_glyph_matrix (w
->desired_matrix
);
16410 if (CHARPOS (new_start
) <= CHARPOS (start
))
16412 /* Don't use this method if the display starts with an ellipsis
16413 displayed for invisible text. It's not easy to handle that case
16414 below, and it's certainly not worth the effort since this is
16415 not a frequent case. */
16416 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16419 IF_DEBUG (debug_method_add (w
, "twu1"));
16421 /* Display up to a row that can be reused. The variable
16422 last_text_row is set to the last row displayed that displays
16423 text. Note that it.vpos == 0 if or if not there is a
16424 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16425 start_display (&it
, w
, new_start
);
16426 w
->cursor
.vpos
= -1;
16427 last_text_row
= last_reused_text_row
= NULL
;
16429 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16431 /* If we have reached into the characters in the START row,
16432 that means the line boundaries have changed. So we
16433 can't start copying with the row START. Maybe it will
16434 work to start copying with the following row. */
16435 while (IT_CHARPOS (it
) > CHARPOS (start
))
16437 /* Advance to the next row as the "start". */
16439 start
= start_row
->minpos
;
16440 /* If there are no more rows to try, or just one, give up. */
16441 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16442 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16443 || CHARPOS (start
) == ZV
)
16445 clear_glyph_matrix (w
->desired_matrix
);
16449 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16451 /* If we have reached alignment, we can copy the rest of the
16453 if (IT_CHARPOS (it
) == CHARPOS (start
)
16454 /* Don't accept "alignment" inside a display vector,
16455 since start_row could have started in the middle of
16456 that same display vector (thus their character
16457 positions match), and we have no way of telling if
16458 that is the case. */
16459 && it
.current
.dpvec_index
< 0)
16462 if (display_line (&it
))
16463 last_text_row
= it
.glyph_row
- 1;
16467 /* A value of current_y < last_visible_y means that we stopped
16468 at the previous window start, which in turn means that we
16469 have at least one reusable row. */
16470 if (it
.current_y
< it
.last_visible_y
)
16472 struct glyph_row
*row
;
16474 /* IT.vpos always starts from 0; it counts text lines. */
16475 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16477 /* Find PT if not already found in the lines displayed. */
16478 if (w
->cursor
.vpos
< 0)
16480 int dy
= it
.current_y
- start_row
->y
;
16482 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16483 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16485 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16486 dy
, nrows_scrolled
);
16489 clear_glyph_matrix (w
->desired_matrix
);
16494 /* Scroll the display. Do it before the current matrix is
16495 changed. The problem here is that update has not yet
16496 run, i.e. part of the current matrix is not up to date.
16497 scroll_run_hook will clear the cursor, and use the
16498 current matrix to get the height of the row the cursor is
16500 run
.current_y
= start_row
->y
;
16501 run
.desired_y
= it
.current_y
;
16502 run
.height
= it
.last_visible_y
- it
.current_y
;
16504 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16507 FRAME_RIF (f
)->update_window_begin_hook (w
);
16508 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16509 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16510 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16514 /* Shift current matrix down by nrows_scrolled lines. */
16515 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16516 rotate_matrix (w
->current_matrix
,
16518 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16521 /* Disable lines that must be updated. */
16522 for (i
= 0; i
< nrows_scrolled
; ++i
)
16523 (start_row
+ i
)->enabled_p
= 0;
16525 /* Re-compute Y positions. */
16526 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16527 max_y
= it
.last_visible_y
;
16528 for (row
= start_row
+ nrows_scrolled
;
16532 row
->y
= it
.current_y
;
16533 row
->visible_height
= row
->height
;
16535 if (row
->y
< min_y
)
16536 row
->visible_height
-= min_y
- row
->y
;
16537 if (row
->y
+ row
->height
> max_y
)
16538 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16539 if (row
->fringe_bitmap_periodic_p
)
16540 row
->redraw_fringe_bitmaps_p
= 1;
16542 it
.current_y
+= row
->height
;
16544 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16545 last_reused_text_row
= row
;
16546 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16550 /* Disable lines in the current matrix which are now
16551 below the window. */
16552 for (++row
; row
< bottom_row
; ++row
)
16553 row
->enabled_p
= row
->mode_line_p
= 0;
16556 /* Update window_end_pos etc.; last_reused_text_row is the last
16557 reused row from the current matrix containing text, if any.
16558 The value of last_text_row is the last displayed line
16559 containing text. */
16560 if (last_reused_text_row
)
16561 adjust_window_ends (w
, last_reused_text_row
, 1);
16562 else if (last_text_row
)
16563 adjust_window_ends (w
, last_text_row
, 0);
16566 /* This window must be completely empty. */
16567 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16568 w
->window_end_pos
= Z
- ZV
;
16569 w
->window_end_vpos
= 0;
16571 w
->window_end_valid
= 0;
16573 /* Update hint: don't try scrolling again in update_window. */
16574 w
->desired_matrix
->no_scrolling_p
= 1;
16577 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16581 else if (CHARPOS (new_start
) > CHARPOS (start
))
16583 struct glyph_row
*pt_row
, *row
;
16584 struct glyph_row
*first_reusable_row
;
16585 struct glyph_row
*first_row_to_display
;
16587 int yb
= window_text_bottom_y (w
);
16589 /* Find the row starting at new_start, if there is one. Don't
16590 reuse a partially visible line at the end. */
16591 first_reusable_row
= start_row
;
16592 while (first_reusable_row
->enabled_p
16593 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16594 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16595 < CHARPOS (new_start
)))
16596 ++first_reusable_row
;
16598 /* Give up if there is no row to reuse. */
16599 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16600 || !first_reusable_row
->enabled_p
16601 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16602 != CHARPOS (new_start
)))
16605 /* We can reuse fully visible rows beginning with
16606 first_reusable_row to the end of the window. Set
16607 first_row_to_display to the first row that cannot be reused.
16608 Set pt_row to the row containing point, if there is any. */
16610 for (first_row_to_display
= first_reusable_row
;
16611 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16612 ++first_row_to_display
)
16614 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16615 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16616 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16617 && first_row_to_display
->ends_at_zv_p
16618 && pt_row
== NULL
)))
16619 pt_row
= first_row_to_display
;
16622 /* Start displaying at the start of first_row_to_display. */
16623 eassert (first_row_to_display
->y
< yb
);
16624 init_to_row_start (&it
, w
, first_row_to_display
);
16626 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16628 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16630 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16631 + WINDOW_HEADER_LINE_HEIGHT (w
));
16633 /* Display lines beginning with first_row_to_display in the
16634 desired matrix. Set last_text_row to the last row displayed
16635 that displays text. */
16636 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16637 if (pt_row
== NULL
)
16638 w
->cursor
.vpos
= -1;
16639 last_text_row
= NULL
;
16640 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16641 if (display_line (&it
))
16642 last_text_row
= it
.glyph_row
- 1;
16644 /* If point is in a reused row, adjust y and vpos of the cursor
16648 w
->cursor
.vpos
-= nrows_scrolled
;
16649 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16652 /* Give up if point isn't in a row displayed or reused. (This
16653 also handles the case where w->cursor.vpos < nrows_scrolled
16654 after the calls to display_line, which can happen with scroll
16655 margins. See bug#1295.) */
16656 if (w
->cursor
.vpos
< 0)
16658 clear_glyph_matrix (w
->desired_matrix
);
16662 /* Scroll the display. */
16663 run
.current_y
= first_reusable_row
->y
;
16664 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16665 run
.height
= it
.last_visible_y
- run
.current_y
;
16666 dy
= run
.current_y
- run
.desired_y
;
16671 FRAME_RIF (f
)->update_window_begin_hook (w
);
16672 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16673 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16674 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16678 /* Adjust Y positions of reused rows. */
16679 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16680 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16681 max_y
= it
.last_visible_y
;
16682 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16685 row
->visible_height
= row
->height
;
16686 if (row
->y
< min_y
)
16687 row
->visible_height
-= min_y
- row
->y
;
16688 if (row
->y
+ row
->height
> max_y
)
16689 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16690 if (row
->fringe_bitmap_periodic_p
)
16691 row
->redraw_fringe_bitmaps_p
= 1;
16694 /* Scroll the current matrix. */
16695 eassert (nrows_scrolled
> 0);
16696 rotate_matrix (w
->current_matrix
,
16698 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16701 /* Disable rows not reused. */
16702 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16703 row
->enabled_p
= 0;
16705 /* Point may have moved to a different line, so we cannot assume that
16706 the previous cursor position is valid; locate the correct row. */
16709 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16711 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16712 && !row
->ends_at_zv_p
;
16716 w
->cursor
.y
= row
->y
;
16718 if (row
< bottom_row
)
16720 /* Can't simply scan the row for point with
16721 bidi-reordered glyph rows. Let set_cursor_from_row
16722 figure out where to put the cursor, and if it fails,
16724 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16726 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16729 clear_glyph_matrix (w
->desired_matrix
);
16735 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16736 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16739 && (!BUFFERP (glyph
->object
)
16740 || glyph
->charpos
< PT
);
16744 w
->cursor
.x
+= glyph
->pixel_width
;
16750 /* Adjust window end. A null value of last_text_row means that
16751 the window end is in reused rows which in turn means that
16752 only its vpos can have changed. */
16754 adjust_window_ends (w
, last_text_row
, 0);
16756 w
->window_end_vpos
-= nrows_scrolled
;
16758 w
->window_end_valid
= 0;
16759 w
->desired_matrix
->no_scrolling_p
= 1;
16762 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16772 /************************************************************************
16773 Window redisplay reusing current matrix when buffer has changed
16774 ************************************************************************/
16776 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16777 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16778 ptrdiff_t *, ptrdiff_t *);
16779 static struct glyph_row
*
16780 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16781 struct glyph_row
*);
16784 /* Return the last row in MATRIX displaying text. If row START is
16785 non-null, start searching with that row. IT gives the dimensions
16786 of the display. Value is null if matrix is empty; otherwise it is
16787 a pointer to the row found. */
16789 static struct glyph_row
*
16790 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16791 struct glyph_row
*start
)
16793 struct glyph_row
*row
, *row_found
;
16795 /* Set row_found to the last row in IT->w's current matrix
16796 displaying text. The loop looks funny but think of partially
16799 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16800 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16802 eassert (row
->enabled_p
);
16804 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16813 /* Return the last row in the current matrix of W that is not affected
16814 by changes at the start of current_buffer that occurred since W's
16815 current matrix was built. Value is null if no such row exists.
16817 BEG_UNCHANGED us the number of characters unchanged at the start of
16818 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16819 first changed character in current_buffer. Characters at positions <
16820 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16821 when the current matrix was built. */
16823 static struct glyph_row
*
16824 find_last_unchanged_at_beg_row (struct window
*w
)
16826 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16827 struct glyph_row
*row
;
16828 struct glyph_row
*row_found
= NULL
;
16829 int yb
= window_text_bottom_y (w
);
16831 /* Find the last row displaying unchanged text. */
16832 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16833 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16834 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16837 if (/* If row ends before first_changed_pos, it is unchanged,
16838 except in some case. */
16839 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16840 /* When row ends in ZV and we write at ZV it is not
16842 && !row
->ends_at_zv_p
16843 /* When first_changed_pos is the end of a continued line,
16844 row is not unchanged because it may be no longer
16846 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16847 && (row
->continued_p
16848 || row
->exact_window_width_line_p
))
16849 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16850 needs to be recomputed, so don't consider this row as
16851 unchanged. This happens when the last line was
16852 bidi-reordered and was killed immediately before this
16853 redisplay cycle. In that case, ROW->end stores the
16854 buffer position of the first visual-order character of
16855 the killed text, which is now beyond ZV. */
16856 && CHARPOS (row
->end
.pos
) <= ZV
)
16859 /* Stop if last visible row. */
16860 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16868 /* Find the first glyph row in the current matrix of W that is not
16869 affected by changes at the end of current_buffer since the
16870 time W's current matrix was built.
16872 Return in *DELTA the number of chars by which buffer positions in
16873 unchanged text at the end of current_buffer must be adjusted.
16875 Return in *DELTA_BYTES the corresponding number of bytes.
16877 Value is null if no such row exists, i.e. all rows are affected by
16880 static struct glyph_row
*
16881 find_first_unchanged_at_end_row (struct window
*w
,
16882 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16884 struct glyph_row
*row
;
16885 struct glyph_row
*row_found
= NULL
;
16887 *delta
= *delta_bytes
= 0;
16889 /* Display must not have been paused, otherwise the current matrix
16890 is not up to date. */
16891 eassert (w
->window_end_valid
);
16893 /* A value of window_end_pos >= END_UNCHANGED means that the window
16894 end is in the range of changed text. If so, there is no
16895 unchanged row at the end of W's current matrix. */
16896 if (w
->window_end_pos
>= END_UNCHANGED
)
16899 /* Set row to the last row in W's current matrix displaying text. */
16900 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16902 /* If matrix is entirely empty, no unchanged row exists. */
16903 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16905 /* The value of row is the last glyph row in the matrix having a
16906 meaningful buffer position in it. The end position of row
16907 corresponds to window_end_pos. This allows us to translate
16908 buffer positions in the current matrix to current buffer
16909 positions for characters not in changed text. */
16911 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16912 ptrdiff_t Z_BYTE_old
=
16913 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16914 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16915 struct glyph_row
*first_text_row
16916 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16918 *delta
= Z
- Z_old
;
16919 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16921 /* Set last_unchanged_pos to the buffer position of the last
16922 character in the buffer that has not been changed. Z is the
16923 index + 1 of the last character in current_buffer, i.e. by
16924 subtracting END_UNCHANGED we get the index of the last
16925 unchanged character, and we have to add BEG to get its buffer
16927 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16928 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16930 /* Search backward from ROW for a row displaying a line that
16931 starts at a minimum position >= last_unchanged_pos_old. */
16932 for (; row
> first_text_row
; --row
)
16934 /* This used to abort, but it can happen.
16935 It is ok to just stop the search instead here. KFS. */
16936 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16939 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16944 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16950 /* Make sure that glyph rows in the current matrix of window W
16951 reference the same glyph memory as corresponding rows in the
16952 frame's frame matrix. This function is called after scrolling W's
16953 current matrix on a terminal frame in try_window_id and
16954 try_window_reusing_current_matrix. */
16957 sync_frame_with_window_matrix_rows (struct window
*w
)
16959 struct frame
*f
= XFRAME (w
->frame
);
16960 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16962 /* Preconditions: W must be a leaf window and full-width. Its frame
16963 must have a frame matrix. */
16964 eassert (BUFFERP (w
->contents
));
16965 eassert (WINDOW_FULL_WIDTH_P (w
));
16966 eassert (!FRAME_WINDOW_P (f
));
16968 /* If W is a full-width window, glyph pointers in W's current matrix
16969 have, by definition, to be the same as glyph pointers in the
16970 corresponding frame matrix. Note that frame matrices have no
16971 marginal areas (see build_frame_matrix). */
16972 window_row
= w
->current_matrix
->rows
;
16973 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16974 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16975 while (window_row
< window_row_end
)
16977 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16978 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16980 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16981 frame_row
->glyphs
[TEXT_AREA
] = start
;
16982 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16983 frame_row
->glyphs
[LAST_AREA
] = end
;
16985 /* Disable frame rows whose corresponding window rows have
16986 been disabled in try_window_id. */
16987 if (!window_row
->enabled_p
)
16988 frame_row
->enabled_p
= 0;
16990 ++window_row
, ++frame_row
;
16995 /* Find the glyph row in window W containing CHARPOS. Consider all
16996 rows between START and END (not inclusive). END null means search
16997 all rows to the end of the display area of W. Value is the row
16998 containing CHARPOS or null. */
17001 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17002 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17004 struct glyph_row
*row
= start
;
17005 struct glyph_row
*best_row
= NULL
;
17006 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17009 /* If we happen to start on a header-line, skip that. */
17010 if (row
->mode_line_p
)
17013 if ((end
&& row
>= end
) || !row
->enabled_p
)
17016 last_y
= window_text_bottom_y (w
) - dy
;
17020 /* Give up if we have gone too far. */
17021 if (end
&& row
>= end
)
17023 /* This formerly returned if they were equal.
17024 I think that both quantities are of a "last plus one" type;
17025 if so, when they are equal, the row is within the screen. -- rms. */
17026 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17029 /* If it is in this row, return this row. */
17030 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17031 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17032 /* The end position of a row equals the start
17033 position of the next row. If CHARPOS is there, we
17034 would rather consider it displayed in the next
17035 line, except when this line ends in ZV. */
17036 && !row_for_charpos_p (row
, charpos
)))
17037 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17041 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17042 || (!best_row
&& !row
->continued_p
))
17044 /* In bidi-reordered rows, there could be several rows whose
17045 edges surround CHARPOS, all of these rows belonging to
17046 the same continued line. We need to find the row which
17047 fits CHARPOS the best. */
17048 for (g
= row
->glyphs
[TEXT_AREA
];
17049 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17052 if (!STRINGP (g
->object
))
17054 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17056 mindif
= eabs (g
->charpos
- charpos
);
17058 /* Exact match always wins. */
17065 else if (best_row
&& !row
->continued_p
)
17072 /* Try to redisplay window W by reusing its existing display. W's
17073 current matrix must be up to date when this function is called,
17074 i.e. window_end_valid must be nonzero.
17078 1 if display has been updated
17079 0 if otherwise unsuccessful
17080 -1 if redisplay with same window start is known not to succeed
17082 The following steps are performed:
17084 1. Find the last row in the current matrix of W that is not
17085 affected by changes at the start of current_buffer. If no such row
17088 2. Find the first row in W's current matrix that is not affected by
17089 changes at the end of current_buffer. Maybe there is no such row.
17091 3. Display lines beginning with the row + 1 found in step 1 to the
17092 row found in step 2 or, if step 2 didn't find a row, to the end of
17095 4. If cursor is not known to appear on the window, give up.
17097 5. If display stopped at the row found in step 2, scroll the
17098 display and current matrix as needed.
17100 6. Maybe display some lines at the end of W, if we must. This can
17101 happen under various circumstances, like a partially visible line
17102 becoming fully visible, or because newly displayed lines are displayed
17103 in smaller font sizes.
17105 7. Update W's window end information. */
17108 try_window_id (struct window
*w
)
17110 struct frame
*f
= XFRAME (w
->frame
);
17111 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17112 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17113 struct glyph_row
*last_unchanged_at_beg_row
;
17114 struct glyph_row
*first_unchanged_at_end_row
;
17115 struct glyph_row
*row
;
17116 struct glyph_row
*bottom_row
;
17119 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17121 struct text_pos start_pos
;
17123 int first_unchanged_at_end_vpos
= 0;
17124 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17125 struct text_pos start
;
17126 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17129 if (inhibit_try_window_id
)
17133 /* This is handy for debugging. */
17135 #define GIVE_UP(X) \
17137 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17141 #define GIVE_UP(X) return 0
17144 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17146 /* Don't use this for mini-windows because these can show
17147 messages and mini-buffers, and we don't handle that here. */
17148 if (MINI_WINDOW_P (w
))
17151 /* This flag is used to prevent redisplay optimizations. */
17152 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17155 /* Verify that narrowing has not changed.
17156 Also verify that we were not told to prevent redisplay optimizations.
17157 It would be nice to further
17158 reduce the number of cases where this prevents try_window_id. */
17159 if (current_buffer
->clip_changed
17160 || current_buffer
->prevent_redisplay_optimizations_p
)
17163 /* Window must either use window-based redisplay or be full width. */
17164 if (!FRAME_WINDOW_P (f
)
17165 && (!FRAME_LINE_INS_DEL_OK (f
)
17166 || !WINDOW_FULL_WIDTH_P (w
)))
17169 /* Give up if point is known NOT to appear in W. */
17170 if (PT
< CHARPOS (start
))
17173 /* Another way to prevent redisplay optimizations. */
17174 if (w
->last_modified
== 0)
17177 /* Verify that window is not hscrolled. */
17178 if (w
->hscroll
!= 0)
17181 /* Verify that display wasn't paused. */
17182 if (!w
->window_end_valid
)
17185 /* Can't use this if highlighting a region because a cursor movement
17186 will do more than just set the cursor. */
17187 if (markpos_of_region () >= 0)
17190 /* Likewise if highlighting trailing whitespace. */
17191 if (!NILP (Vshow_trailing_whitespace
))
17194 /* Likewise if showing a region. */
17195 if (w
->region_showing
)
17198 /* Can't use this if overlay arrow position and/or string have
17200 if (overlay_arrows_changed_p ())
17203 /* When word-wrap is on, adding a space to the first word of a
17204 wrapped line can change the wrap position, altering the line
17205 above it. It might be worthwhile to handle this more
17206 intelligently, but for now just redisplay from scratch. */
17207 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17210 /* Under bidi reordering, adding or deleting a character in the
17211 beginning of a paragraph, before the first strong directional
17212 character, can change the base direction of the paragraph (unless
17213 the buffer specifies a fixed paragraph direction), which will
17214 require to redisplay the whole paragraph. It might be worthwhile
17215 to find the paragraph limits and widen the range of redisplayed
17216 lines to that, but for now just give up this optimization and
17217 redisplay from scratch. */
17218 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17219 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17222 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17223 only if buffer has really changed. The reason is that the gap is
17224 initially at Z for freshly visited files. The code below would
17225 set end_unchanged to 0 in that case. */
17226 if (MODIFF
> SAVE_MODIFF
17227 /* This seems to happen sometimes after saving a buffer. */
17228 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17230 if (GPT
- BEG
< BEG_UNCHANGED
)
17231 BEG_UNCHANGED
= GPT
- BEG
;
17232 if (Z
- GPT
< END_UNCHANGED
)
17233 END_UNCHANGED
= Z
- GPT
;
17236 /* The position of the first and last character that has been changed. */
17237 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17238 last_changed_charpos
= Z
- END_UNCHANGED
;
17240 /* If window starts after a line end, and the last change is in
17241 front of that newline, then changes don't affect the display.
17242 This case happens with stealth-fontification. Note that although
17243 the display is unchanged, glyph positions in the matrix have to
17244 be adjusted, of course. */
17245 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17246 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17247 && ((last_changed_charpos
< CHARPOS (start
)
17248 && CHARPOS (start
) == BEGV
)
17249 || (last_changed_charpos
< CHARPOS (start
) - 1
17250 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17252 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17253 struct glyph_row
*r0
;
17255 /* Compute how many chars/bytes have been added to or removed
17256 from the buffer. */
17257 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17258 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17259 Z_delta
= Z
- Z_old
;
17260 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17262 /* Give up if PT is not in the window. Note that it already has
17263 been checked at the start of try_window_id that PT is not in
17264 front of the window start. */
17265 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17268 /* If window start is unchanged, we can reuse the whole matrix
17269 as is, after adjusting glyph positions. No need to compute
17270 the window end again, since its offset from Z hasn't changed. */
17271 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17272 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17273 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17274 /* PT must not be in a partially visible line. */
17275 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17276 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17278 /* Adjust positions in the glyph matrix. */
17279 if (Z_delta
|| Z_delta_bytes
)
17281 struct glyph_row
*r1
17282 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17283 increment_matrix_positions (w
->current_matrix
,
17284 MATRIX_ROW_VPOS (r0
, current_matrix
),
17285 MATRIX_ROW_VPOS (r1
, current_matrix
),
17286 Z_delta
, Z_delta_bytes
);
17289 /* Set the cursor. */
17290 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17292 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17297 /* Handle the case that changes are all below what is displayed in
17298 the window, and that PT is in the window. This shortcut cannot
17299 be taken if ZV is visible in the window, and text has been added
17300 there that is visible in the window. */
17301 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17302 /* ZV is not visible in the window, or there are no
17303 changes at ZV, actually. */
17304 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17305 || first_changed_charpos
== last_changed_charpos
))
17307 struct glyph_row
*r0
;
17309 /* Give up if PT is not in the window. Note that it already has
17310 been checked at the start of try_window_id that PT is not in
17311 front of the window start. */
17312 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17315 /* If window start is unchanged, we can reuse the whole matrix
17316 as is, without changing glyph positions since no text has
17317 been added/removed in front of the window end. */
17318 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17319 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17320 /* PT must not be in a partially visible line. */
17321 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17322 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17324 /* We have to compute the window end anew since text
17325 could have been added/removed after it. */
17326 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17327 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17329 /* Set the cursor. */
17330 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17332 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17337 /* Give up if window start is in the changed area.
17339 The condition used to read
17341 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17343 but why that was tested escapes me at the moment. */
17344 if (CHARPOS (start
) >= first_changed_charpos
17345 && CHARPOS (start
) <= last_changed_charpos
)
17348 /* Check that window start agrees with the start of the first glyph
17349 row in its current matrix. Check this after we know the window
17350 start is not in changed text, otherwise positions would not be
17352 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17353 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17356 /* Give up if the window ends in strings. Overlay strings
17357 at the end are difficult to handle, so don't try. */
17358 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17359 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17362 /* Compute the position at which we have to start displaying new
17363 lines. Some of the lines at the top of the window might be
17364 reusable because they are not displaying changed text. Find the
17365 last row in W's current matrix not affected by changes at the
17366 start of current_buffer. Value is null if changes start in the
17367 first line of window. */
17368 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17369 if (last_unchanged_at_beg_row
)
17371 /* Avoid starting to display in the middle of a character, a TAB
17372 for instance. This is easier than to set up the iterator
17373 exactly, and it's not a frequent case, so the additional
17374 effort wouldn't really pay off. */
17375 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17376 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17377 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17378 --last_unchanged_at_beg_row
;
17380 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17383 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17385 start_pos
= it
.current
.pos
;
17387 /* Start displaying new lines in the desired matrix at the same
17388 vpos we would use in the current matrix, i.e. below
17389 last_unchanged_at_beg_row. */
17390 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17392 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17393 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17395 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17399 /* There are no reusable lines at the start of the window.
17400 Start displaying in the first text line. */
17401 start_display (&it
, w
, start
);
17402 it
.vpos
= it
.first_vpos
;
17403 start_pos
= it
.current
.pos
;
17406 /* Find the first row that is not affected by changes at the end of
17407 the buffer. Value will be null if there is no unchanged row, in
17408 which case we must redisplay to the end of the window. delta
17409 will be set to the value by which buffer positions beginning with
17410 first_unchanged_at_end_row have to be adjusted due to text
17412 first_unchanged_at_end_row
17413 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17414 IF_DEBUG (debug_delta
= delta
);
17415 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17417 /* Set stop_pos to the buffer position up to which we will have to
17418 display new lines. If first_unchanged_at_end_row != NULL, this
17419 is the buffer position of the start of the line displayed in that
17420 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17421 that we don't stop at a buffer position. */
17423 if (first_unchanged_at_end_row
)
17425 eassert (last_unchanged_at_beg_row
== NULL
17426 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17428 /* If this is a continuation line, move forward to the next one
17429 that isn't. Changes in lines above affect this line.
17430 Caution: this may move first_unchanged_at_end_row to a row
17431 not displaying text. */
17432 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17433 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17434 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17435 < it
.last_visible_y
))
17436 ++first_unchanged_at_end_row
;
17438 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17439 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17440 >= it
.last_visible_y
))
17441 first_unchanged_at_end_row
= NULL
;
17444 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17446 first_unchanged_at_end_vpos
17447 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17448 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17451 else if (last_unchanged_at_beg_row
== NULL
)
17457 /* Either there is no unchanged row at the end, or the one we have
17458 now displays text. This is a necessary condition for the window
17459 end pos calculation at the end of this function. */
17460 eassert (first_unchanged_at_end_row
== NULL
17461 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17463 debug_last_unchanged_at_beg_vpos
17464 = (last_unchanged_at_beg_row
17465 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17467 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17469 #endif /* GLYPH_DEBUG */
17472 /* Display new lines. Set last_text_row to the last new line
17473 displayed which has text on it, i.e. might end up as being the
17474 line where the window_end_vpos is. */
17475 w
->cursor
.vpos
= -1;
17476 last_text_row
= NULL
;
17477 overlay_arrow_seen
= 0;
17478 while (it
.current_y
< it
.last_visible_y
17479 && !f
->fonts_changed
17480 && (first_unchanged_at_end_row
== NULL
17481 || IT_CHARPOS (it
) < stop_pos
))
17483 if (display_line (&it
))
17484 last_text_row
= it
.glyph_row
- 1;
17487 if (f
->fonts_changed
)
17491 /* Compute differences in buffer positions, y-positions etc. for
17492 lines reused at the bottom of the window. Compute what we can
17494 if (first_unchanged_at_end_row
17495 /* No lines reused because we displayed everything up to the
17496 bottom of the window. */
17497 && it
.current_y
< it
.last_visible_y
)
17500 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17502 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17503 run
.current_y
= first_unchanged_at_end_row
->y
;
17504 run
.desired_y
= run
.current_y
+ dy
;
17505 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17509 delta
= delta_bytes
= dvpos
= dy
17510 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17511 first_unchanged_at_end_row
= NULL
;
17513 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17516 /* Find the cursor if not already found. We have to decide whether
17517 PT will appear on this window (it sometimes doesn't, but this is
17518 not a very frequent case.) This decision has to be made before
17519 the current matrix is altered. A value of cursor.vpos < 0 means
17520 that PT is either in one of the lines beginning at
17521 first_unchanged_at_end_row or below the window. Don't care for
17522 lines that might be displayed later at the window end; as
17523 mentioned, this is not a frequent case. */
17524 if (w
->cursor
.vpos
< 0)
17526 /* Cursor in unchanged rows at the top? */
17527 if (PT
< CHARPOS (start_pos
)
17528 && last_unchanged_at_beg_row
)
17530 row
= row_containing_pos (w
, PT
,
17531 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17532 last_unchanged_at_beg_row
+ 1, 0);
17534 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17537 /* Start from first_unchanged_at_end_row looking for PT. */
17538 else if (first_unchanged_at_end_row
)
17540 row
= row_containing_pos (w
, PT
- delta
,
17541 first_unchanged_at_end_row
, NULL
, 0);
17543 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17544 delta_bytes
, dy
, dvpos
);
17547 /* Give up if cursor was not found. */
17548 if (w
->cursor
.vpos
< 0)
17550 clear_glyph_matrix (w
->desired_matrix
);
17555 /* Don't let the cursor end in the scroll margins. */
17557 int this_scroll_margin
, cursor_height
;
17558 int frame_line_height
= default_line_pixel_height (w
);
17559 int window_total_lines
17560 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17562 this_scroll_margin
=
17563 max (0, min (scroll_margin
, window_total_lines
/ 4));
17564 this_scroll_margin
*= frame_line_height
;
17565 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17567 if ((w
->cursor
.y
< this_scroll_margin
17568 && CHARPOS (start
) > BEGV
)
17569 /* Old redisplay didn't take scroll margin into account at the bottom,
17570 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17571 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17572 ? cursor_height
+ this_scroll_margin
17573 : 1)) > it
.last_visible_y
)
17575 w
->cursor
.vpos
= -1;
17576 clear_glyph_matrix (w
->desired_matrix
);
17581 /* Scroll the display. Do it before changing the current matrix so
17582 that xterm.c doesn't get confused about where the cursor glyph is
17584 if (dy
&& run
.height
)
17588 if (FRAME_WINDOW_P (f
))
17590 FRAME_RIF (f
)->update_window_begin_hook (w
);
17591 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17592 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17593 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17597 /* Terminal frame. In this case, dvpos gives the number of
17598 lines to scroll by; dvpos < 0 means scroll up. */
17600 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17601 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17602 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17603 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17604 + window_internal_height (w
));
17606 #if defined (HAVE_GPM) || defined (MSDOS)
17607 x_clear_window_mouse_face (w
);
17609 /* Perform the operation on the screen. */
17612 /* Scroll last_unchanged_at_beg_row to the end of the
17613 window down dvpos lines. */
17614 set_terminal_window (f
, end
);
17616 /* On dumb terminals delete dvpos lines at the end
17617 before inserting dvpos empty lines. */
17618 if (!FRAME_SCROLL_REGION_OK (f
))
17619 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17621 /* Insert dvpos empty lines in front of
17622 last_unchanged_at_beg_row. */
17623 ins_del_lines (f
, from
, dvpos
);
17625 else if (dvpos
< 0)
17627 /* Scroll up last_unchanged_at_beg_vpos to the end of
17628 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17629 set_terminal_window (f
, end
);
17631 /* Delete dvpos lines in front of
17632 last_unchanged_at_beg_vpos. ins_del_lines will set
17633 the cursor to the given vpos and emit |dvpos| delete
17635 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17637 /* On a dumb terminal insert dvpos empty lines at the
17639 if (!FRAME_SCROLL_REGION_OK (f
))
17640 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17643 set_terminal_window (f
, 0);
17649 /* Shift reused rows of the current matrix to the right position.
17650 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17652 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17653 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17656 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17657 bottom_vpos
, dvpos
);
17658 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17661 else if (dvpos
> 0)
17663 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17664 bottom_vpos
, dvpos
);
17665 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17666 first_unchanged_at_end_vpos
+ dvpos
);
17669 /* For frame-based redisplay, make sure that current frame and window
17670 matrix are in sync with respect to glyph memory. */
17671 if (!FRAME_WINDOW_P (f
))
17672 sync_frame_with_window_matrix_rows (w
);
17674 /* Adjust buffer positions in reused rows. */
17675 if (delta
|| delta_bytes
)
17676 increment_matrix_positions (current_matrix
,
17677 first_unchanged_at_end_vpos
+ dvpos
,
17678 bottom_vpos
, delta
, delta_bytes
);
17680 /* Adjust Y positions. */
17682 shift_glyph_matrix (w
, current_matrix
,
17683 first_unchanged_at_end_vpos
+ dvpos
,
17686 if (first_unchanged_at_end_row
)
17688 first_unchanged_at_end_row
+= dvpos
;
17689 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17690 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17691 first_unchanged_at_end_row
= NULL
;
17694 /* If scrolling up, there may be some lines to display at the end of
17696 last_text_row_at_end
= NULL
;
17699 /* Scrolling up can leave for example a partially visible line
17700 at the end of the window to be redisplayed. */
17701 /* Set last_row to the glyph row in the current matrix where the
17702 window end line is found. It has been moved up or down in
17703 the matrix by dvpos. */
17704 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17705 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17707 /* If last_row is the window end line, it should display text. */
17708 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17710 /* If window end line was partially visible before, begin
17711 displaying at that line. Otherwise begin displaying with the
17712 line following it. */
17713 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17715 init_to_row_start (&it
, w
, last_row
);
17716 it
.vpos
= last_vpos
;
17717 it
.current_y
= last_row
->y
;
17721 init_to_row_end (&it
, w
, last_row
);
17722 it
.vpos
= 1 + last_vpos
;
17723 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17727 /* We may start in a continuation line. If so, we have to
17728 get the right continuation_lines_width and current_x. */
17729 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17730 it
.hpos
= it
.current_x
= 0;
17732 /* Display the rest of the lines at the window end. */
17733 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17734 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17736 /* Is it always sure that the display agrees with lines in
17737 the current matrix? I don't think so, so we mark rows
17738 displayed invalid in the current matrix by setting their
17739 enabled_p flag to zero. */
17740 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17741 if (display_line (&it
))
17742 last_text_row_at_end
= it
.glyph_row
- 1;
17746 /* Update window_end_pos and window_end_vpos. */
17747 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17749 /* Window end line if one of the preserved rows from the current
17750 matrix. Set row to the last row displaying text in current
17751 matrix starting at first_unchanged_at_end_row, after
17753 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17754 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17755 first_unchanged_at_end_row
);
17756 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17757 adjust_window_ends (w
, row
, 1);
17758 eassert (w
->window_end_bytepos
>= 0);
17759 IF_DEBUG (debug_method_add (w
, "A"));
17761 else if (last_text_row_at_end
)
17763 adjust_window_ends (w
, last_text_row_at_end
, 0);
17764 eassert (w
->window_end_bytepos
>= 0);
17765 IF_DEBUG (debug_method_add (w
, "B"));
17767 else if (last_text_row
)
17769 /* We have displayed either to the end of the window or at the
17770 end of the window, i.e. the last row with text is to be found
17771 in the desired matrix. */
17772 adjust_window_ends (w
, last_text_row
, 0);
17773 eassert (w
->window_end_bytepos
>= 0);
17775 else if (first_unchanged_at_end_row
== NULL
17776 && last_text_row
== NULL
17777 && last_text_row_at_end
== NULL
)
17779 /* Displayed to end of window, but no line containing text was
17780 displayed. Lines were deleted at the end of the window. */
17781 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17782 int vpos
= w
->window_end_vpos
;
17783 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17784 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17787 row
== NULL
&& vpos
>= first_vpos
;
17788 --vpos
, --current_row
, --desired_row
)
17790 if (desired_row
->enabled_p
)
17792 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17795 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17799 eassert (row
!= NULL
);
17800 w
->window_end_vpos
= vpos
+ 1;
17801 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17802 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17803 eassert (w
->window_end_bytepos
>= 0);
17804 IF_DEBUG (debug_method_add (w
, "C"));
17809 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17810 debug_end_vpos
= w
->window_end_vpos
);
17812 /* Record that display has not been completed. */
17813 w
->window_end_valid
= 0;
17814 w
->desired_matrix
->no_scrolling_p
= 1;
17822 /***********************************************************************
17823 More debugging support
17824 ***********************************************************************/
17828 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17829 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17830 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17833 /* Dump the contents of glyph matrix MATRIX on stderr.
17835 GLYPHS 0 means don't show glyph contents.
17836 GLYPHS 1 means show glyphs in short form
17837 GLYPHS > 1 means show glyphs in long form. */
17840 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17843 for (i
= 0; i
< matrix
->nrows
; ++i
)
17844 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17848 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17849 the glyph row and area where the glyph comes from. */
17852 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17854 if (glyph
->type
== CHAR_GLYPH
17855 || glyph
->type
== GLYPHLESS_GLYPH
)
17858 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17859 glyph
- row
->glyphs
[TEXT_AREA
],
17860 (glyph
->type
== CHAR_GLYPH
17864 (BUFFERP (glyph
->object
)
17866 : (STRINGP (glyph
->object
)
17868 : (INTEGERP (glyph
->object
)
17871 glyph
->pixel_width
,
17873 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17877 glyph
->left_box_line_p
,
17878 glyph
->right_box_line_p
);
17880 else if (glyph
->type
== STRETCH_GLYPH
)
17883 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17884 glyph
- row
->glyphs
[TEXT_AREA
],
17887 (BUFFERP (glyph
->object
)
17889 : (STRINGP (glyph
->object
)
17891 : (INTEGERP (glyph
->object
)
17894 glyph
->pixel_width
,
17898 glyph
->left_box_line_p
,
17899 glyph
->right_box_line_p
);
17901 else if (glyph
->type
== IMAGE_GLYPH
)
17904 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17905 glyph
- row
->glyphs
[TEXT_AREA
],
17908 (BUFFERP (glyph
->object
)
17910 : (STRINGP (glyph
->object
)
17912 : (INTEGERP (glyph
->object
)
17915 glyph
->pixel_width
,
17919 glyph
->left_box_line_p
,
17920 glyph
->right_box_line_p
);
17922 else if (glyph
->type
== COMPOSITE_GLYPH
)
17925 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17926 glyph
- row
->glyphs
[TEXT_AREA
],
17929 (BUFFERP (glyph
->object
)
17931 : (STRINGP (glyph
->object
)
17933 : (INTEGERP (glyph
->object
)
17936 glyph
->pixel_width
,
17938 if (glyph
->u
.cmp
.automatic
)
17941 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17942 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17944 glyph
->left_box_line_p
,
17945 glyph
->right_box_line_p
);
17950 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17951 GLYPHS 0 means don't show glyph contents.
17952 GLYPHS 1 means show glyphs in short form
17953 GLYPHS > 1 means show glyphs in long form. */
17956 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17960 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17961 fprintf (stderr
, "==============================================================================\n");
17963 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17964 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17966 MATRIX_ROW_START_CHARPOS (row
),
17967 MATRIX_ROW_END_CHARPOS (row
),
17968 row
->used
[TEXT_AREA
],
17969 row
->contains_overlapping_glyphs_p
,
17971 row
->truncated_on_left_p
,
17972 row
->truncated_on_right_p
,
17974 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17975 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
17978 row
->ends_in_middle_of_char_p
,
17979 row
->starts_in_middle_of_char_p
,
17985 row
->visible_height
,
17988 /* The next 3 lines should align to "Start" in the header. */
17989 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17990 row
->end
.overlay_string_index
,
17991 row
->continuation_lines_width
);
17992 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17993 CHARPOS (row
->start
.string_pos
),
17994 CHARPOS (row
->end
.string_pos
));
17995 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17996 row
->end
.dpvec_index
);
18003 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18005 struct glyph
*glyph
= row
->glyphs
[area
];
18006 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18008 /* Glyph for a line end in text. */
18009 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18012 if (glyph
< glyph_end
)
18013 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18015 for (; glyph
< glyph_end
; ++glyph
)
18016 dump_glyph (row
, glyph
, area
);
18019 else if (glyphs
== 1)
18023 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18025 char *s
= alloca (row
->used
[area
] + 4);
18028 for (i
= 0; i
< row
->used
[area
]; ++i
)
18030 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18031 if (i
== row
->used
[area
] - 1
18032 && area
== TEXT_AREA
18033 && INTEGERP (glyph
->object
)
18034 && glyph
->type
== CHAR_GLYPH
18035 && glyph
->u
.ch
== ' ')
18037 strcpy (&s
[i
], "[\\n]");
18040 else if (glyph
->type
== CHAR_GLYPH
18041 && glyph
->u
.ch
< 0x80
18042 && glyph
->u
.ch
>= ' ')
18043 s
[i
] = glyph
->u
.ch
;
18049 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18055 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18056 Sdump_glyph_matrix
, 0, 1, "p",
18057 doc
: /* Dump the current matrix of the selected window to stderr.
18058 Shows contents of glyph row structures. With non-nil
18059 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18060 glyphs in short form, otherwise show glyphs in long form. */)
18061 (Lisp_Object glyphs
)
18063 struct window
*w
= XWINDOW (selected_window
);
18064 struct buffer
*buffer
= XBUFFER (w
->contents
);
18066 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18067 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18068 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18069 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18070 fprintf (stderr
, "=============================================\n");
18071 dump_glyph_matrix (w
->current_matrix
,
18072 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18077 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18078 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18081 struct frame
*f
= XFRAME (selected_frame
);
18082 dump_glyph_matrix (f
->current_matrix
, 1);
18087 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18088 doc
: /* Dump glyph row ROW to stderr.
18089 GLYPH 0 means don't dump glyphs.
18090 GLYPH 1 means dump glyphs in short form.
18091 GLYPH > 1 or omitted means dump glyphs in long form. */)
18092 (Lisp_Object row
, Lisp_Object glyphs
)
18094 struct glyph_matrix
*matrix
;
18097 CHECK_NUMBER (row
);
18098 matrix
= XWINDOW (selected_window
)->current_matrix
;
18100 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18101 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18103 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18108 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18109 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18110 GLYPH 0 means don't dump glyphs.
18111 GLYPH 1 means dump glyphs in short form.
18112 GLYPH > 1 or omitted means dump glyphs in long form. */)
18113 (Lisp_Object row
, Lisp_Object glyphs
)
18115 struct frame
*sf
= SELECTED_FRAME ();
18116 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18119 CHECK_NUMBER (row
);
18121 if (vpos
>= 0 && vpos
< m
->nrows
)
18122 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18123 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18128 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18129 doc
: /* Toggle tracing of redisplay.
18130 With ARG, turn tracing on if and only if ARG is positive. */)
18134 trace_redisplay_p
= !trace_redisplay_p
;
18137 arg
= Fprefix_numeric_value (arg
);
18138 trace_redisplay_p
= XINT (arg
) > 0;
18145 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18146 doc
: /* Like `format', but print result to stderr.
18147 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18148 (ptrdiff_t nargs
, Lisp_Object
*args
)
18150 Lisp_Object s
= Fformat (nargs
, args
);
18151 fprintf (stderr
, "%s", SDATA (s
));
18155 #endif /* GLYPH_DEBUG */
18159 /***********************************************************************
18160 Building Desired Matrix Rows
18161 ***********************************************************************/
18163 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18164 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18166 static struct glyph_row
*
18167 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18169 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18170 struct buffer
*buffer
= XBUFFER (w
->contents
);
18171 struct buffer
*old
= current_buffer
;
18172 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18173 int arrow_len
= SCHARS (overlay_arrow_string
);
18174 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18175 const unsigned char *p
;
18178 int n_glyphs_before
;
18180 set_buffer_temp (buffer
);
18181 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18182 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18183 SET_TEXT_POS (it
.position
, 0, 0);
18185 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18187 while (p
< arrow_end
)
18189 Lisp_Object face
, ilisp
;
18191 /* Get the next character. */
18193 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18196 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18197 if (! ASCII_CHAR_P (it
.c
))
18198 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18202 /* Get its face. */
18203 ilisp
= make_number (p
- arrow_string
);
18204 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18205 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18207 /* Compute its width, get its glyphs. */
18208 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18209 SET_TEXT_POS (it
.position
, -1, -1);
18210 PRODUCE_GLYPHS (&it
);
18212 /* If this character doesn't fit any more in the line, we have
18213 to remove some glyphs. */
18214 if (it
.current_x
> it
.last_visible_x
)
18216 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18221 set_buffer_temp (old
);
18222 return it
.glyph_row
;
18226 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18227 glyphs to insert is determined by produce_special_glyphs. */
18230 insert_left_trunc_glyphs (struct it
*it
)
18232 struct it truncate_it
;
18233 struct glyph
*from
, *end
, *to
, *toend
;
18235 eassert (!FRAME_WINDOW_P (it
->f
)
18236 || (!it
->glyph_row
->reversed_p
18237 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18238 || (it
->glyph_row
->reversed_p
18239 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18241 /* Get the truncation glyphs. */
18243 truncate_it
.current_x
= 0;
18244 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18245 truncate_it
.glyph_row
= &scratch_glyph_row
;
18246 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18247 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18248 truncate_it
.object
= make_number (0);
18249 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18251 /* Overwrite glyphs from IT with truncation glyphs. */
18252 if (!it
->glyph_row
->reversed_p
)
18254 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18256 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18257 end
= from
+ tused
;
18258 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18259 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18260 if (FRAME_WINDOW_P (it
->f
))
18262 /* On GUI frames, when variable-size fonts are displayed,
18263 the truncation glyphs may need more pixels than the row's
18264 glyphs they overwrite. We overwrite more glyphs to free
18265 enough screen real estate, and enlarge the stretch glyph
18266 on the right (see display_line), if there is one, to
18267 preserve the screen position of the truncation glyphs on
18270 struct glyph
*g
= to
;
18273 /* The first glyph could be partially visible, in which case
18274 it->glyph_row->x will be negative. But we want the left
18275 truncation glyphs to be aligned at the left margin of the
18276 window, so we override the x coordinate at which the row
18278 it
->glyph_row
->x
= 0;
18279 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18281 w
+= g
->pixel_width
;
18284 if (g
- to
- tused
> 0)
18286 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18287 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18289 used
= it
->glyph_row
->used
[TEXT_AREA
];
18290 if (it
->glyph_row
->truncated_on_right_p
18291 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18292 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18295 int extra
= w
- it
->truncation_pixel_width
;
18297 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18304 /* There may be padding glyphs left over. Overwrite them too. */
18305 if (!FRAME_WINDOW_P (it
->f
))
18307 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18309 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18316 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18320 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18322 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18323 that back to front. */
18324 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18325 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18326 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18327 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18328 if (FRAME_WINDOW_P (it
->f
))
18331 struct glyph
*g
= to
;
18333 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18335 w
+= g
->pixel_width
;
18338 if (to
- g
- tused
> 0)
18340 if (it
->glyph_row
->truncated_on_right_p
18341 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18342 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18344 int extra
= w
- it
->truncation_pixel_width
;
18346 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18350 while (from
>= end
&& to
>= toend
)
18352 if (!FRAME_WINDOW_P (it
->f
))
18354 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18357 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18358 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18359 while (from
>= end
&& to
>= toend
)
18365 /* Need to free some room before prepending additional
18367 int move_by
= from
- end
+ 1;
18368 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18369 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18371 for ( ; g
>= g0
; g
--)
18373 while (from
>= end
)
18375 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18380 /* Compute the hash code for ROW. */
18382 row_hash (struct glyph_row
*row
)
18385 unsigned hashval
= 0;
18387 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18388 for (k
= 0; k
< row
->used
[area
]; ++k
)
18389 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18390 + row
->glyphs
[area
][k
].u
.val
18391 + row
->glyphs
[area
][k
].face_id
18392 + row
->glyphs
[area
][k
].padding_p
18393 + (row
->glyphs
[area
][k
].type
<< 2));
18398 /* Compute the pixel height and width of IT->glyph_row.
18400 Most of the time, ascent and height of a display line will be equal
18401 to the max_ascent and max_height values of the display iterator
18402 structure. This is not the case if
18404 1. We hit ZV without displaying anything. In this case, max_ascent
18405 and max_height will be zero.
18407 2. We have some glyphs that don't contribute to the line height.
18408 (The glyph row flag contributes_to_line_height_p is for future
18409 pixmap extensions).
18411 The first case is easily covered by using default values because in
18412 these cases, the line height does not really matter, except that it
18413 must not be zero. */
18416 compute_line_metrics (struct it
*it
)
18418 struct glyph_row
*row
= it
->glyph_row
;
18420 if (FRAME_WINDOW_P (it
->f
))
18422 int i
, min_y
, max_y
;
18424 /* The line may consist of one space only, that was added to
18425 place the cursor on it. If so, the row's height hasn't been
18427 if (row
->height
== 0)
18429 if (it
->max_ascent
+ it
->max_descent
== 0)
18430 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18431 row
->ascent
= it
->max_ascent
;
18432 row
->height
= it
->max_ascent
+ it
->max_descent
;
18433 row
->phys_ascent
= it
->max_phys_ascent
;
18434 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18435 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18438 /* Compute the width of this line. */
18439 row
->pixel_width
= row
->x
;
18440 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18441 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18443 eassert (row
->pixel_width
>= 0);
18444 eassert (row
->ascent
>= 0 && row
->height
> 0);
18446 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18447 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18449 /* If first line's physical ascent is larger than its logical
18450 ascent, use the physical ascent, and make the row taller.
18451 This makes accented characters fully visible. */
18452 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18453 && row
->phys_ascent
> row
->ascent
)
18455 row
->height
+= row
->phys_ascent
- row
->ascent
;
18456 row
->ascent
= row
->phys_ascent
;
18459 /* Compute how much of the line is visible. */
18460 row
->visible_height
= row
->height
;
18462 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18463 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18465 if (row
->y
< min_y
)
18466 row
->visible_height
-= min_y
- row
->y
;
18467 if (row
->y
+ row
->height
> max_y
)
18468 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18472 row
->pixel_width
= row
->used
[TEXT_AREA
];
18473 if (row
->continued_p
)
18474 row
->pixel_width
-= it
->continuation_pixel_width
;
18475 else if (row
->truncated_on_right_p
)
18476 row
->pixel_width
-= it
->truncation_pixel_width
;
18477 row
->ascent
= row
->phys_ascent
= 0;
18478 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18479 row
->extra_line_spacing
= 0;
18482 /* Compute a hash code for this row. */
18483 row
->hash
= row_hash (row
);
18485 it
->max_ascent
= it
->max_descent
= 0;
18486 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18490 /* Append one space to the glyph row of iterator IT if doing a
18491 window-based redisplay. The space has the same face as
18492 IT->face_id. Value is non-zero if a space was added.
18494 This function is called to make sure that there is always one glyph
18495 at the end of a glyph row that the cursor can be set on under
18496 window-systems. (If there weren't such a glyph we would not know
18497 how wide and tall a box cursor should be displayed).
18499 At the same time this space let's a nicely handle clearing to the
18500 end of the line if the row ends in italic text. */
18503 append_space_for_newline (struct it
*it
, int default_face_p
)
18505 if (FRAME_WINDOW_P (it
->f
))
18507 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18509 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18510 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18512 /* Save some values that must not be changed.
18513 Must save IT->c and IT->len because otherwise
18514 ITERATOR_AT_END_P wouldn't work anymore after
18515 append_space_for_newline has been called. */
18516 enum display_element_type saved_what
= it
->what
;
18517 int saved_c
= it
->c
, saved_len
= it
->len
;
18518 int saved_char_to_display
= it
->char_to_display
;
18519 int saved_x
= it
->current_x
;
18520 int saved_face_id
= it
->face_id
;
18521 int saved_box_end
= it
->end_of_box_run_p
;
18522 struct text_pos saved_pos
;
18523 Lisp_Object saved_object
;
18526 saved_object
= it
->object
;
18527 saved_pos
= it
->position
;
18529 it
->what
= IT_CHARACTER
;
18530 memset (&it
->position
, 0, sizeof it
->position
);
18531 it
->object
= make_number (0);
18532 it
->c
= it
->char_to_display
= ' ';
18535 /* If the default face was remapped, be sure to use the
18536 remapped face for the appended newline. */
18537 if (default_face_p
)
18538 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18539 else if (it
->face_before_selective_p
)
18540 it
->face_id
= it
->saved_face_id
;
18541 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18542 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18543 /* In R2L rows, we will prepend a stretch glyph that will
18544 have the end_of_box_run_p flag set for it, so there's no
18545 need for the appended newline glyph to have that flag
18547 if (it
->glyph_row
->reversed_p
18548 /* But if the appended newline glyph goes all the way to
18549 the end of the row, there will be no stretch glyph,
18550 so leave the box flag set. */
18551 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18552 it
->end_of_box_run_p
= 0;
18554 PRODUCE_GLYPHS (it
);
18556 it
->override_ascent
= -1;
18557 it
->constrain_row_ascent_descent_p
= 0;
18558 it
->current_x
= saved_x
;
18559 it
->object
= saved_object
;
18560 it
->position
= saved_pos
;
18561 it
->what
= saved_what
;
18562 it
->face_id
= saved_face_id
;
18563 it
->len
= saved_len
;
18565 it
->char_to_display
= saved_char_to_display
;
18566 it
->end_of_box_run_p
= saved_box_end
;
18575 /* Extend the face of the last glyph in the text area of IT->glyph_row
18576 to the end of the display line. Called from display_line. If the
18577 glyph row is empty, add a space glyph to it so that we know the
18578 face to draw. Set the glyph row flag fill_line_p. If the glyph
18579 row is R2L, prepend a stretch glyph to cover the empty space to the
18580 left of the leftmost glyph. */
18583 extend_face_to_end_of_line (struct it
*it
)
18585 struct face
*face
, *default_face
;
18586 struct frame
*f
= it
->f
;
18588 /* If line is already filled, do nothing. Non window-system frames
18589 get a grace of one more ``pixel'' because their characters are
18590 1-``pixel'' wide, so they hit the equality too early. This grace
18591 is needed only for R2L rows that are not continued, to produce
18592 one extra blank where we could display the cursor. */
18593 if (it
->current_x
>= it
->last_visible_x
18594 + (!FRAME_WINDOW_P (f
)
18595 && it
->glyph_row
->reversed_p
18596 && !it
->glyph_row
->continued_p
))
18599 /* The default face, possibly remapped. */
18600 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18602 /* Face extension extends the background and box of IT->face_id
18603 to the end of the line. If the background equals the background
18604 of the frame, we don't have to do anything. */
18605 if (it
->face_before_selective_p
)
18606 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18608 face
= FACE_FROM_ID (f
, it
->face_id
);
18610 if (FRAME_WINDOW_P (f
)
18611 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18612 && face
->box
== FACE_NO_BOX
18613 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18615 && !it
->glyph_row
->reversed_p
)
18618 /* Set the glyph row flag indicating that the face of the last glyph
18619 in the text area has to be drawn to the end of the text area. */
18620 it
->glyph_row
->fill_line_p
= 1;
18622 /* If current character of IT is not ASCII, make sure we have the
18623 ASCII face. This will be automatically undone the next time
18624 get_next_display_element returns a multibyte character. Note
18625 that the character will always be single byte in unibyte
18627 if (!ASCII_CHAR_P (it
->c
))
18629 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18632 if (FRAME_WINDOW_P (f
))
18634 /* If the row is empty, add a space with the current face of IT,
18635 so that we know which face to draw. */
18636 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18638 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18639 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18640 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18642 #ifdef HAVE_WINDOW_SYSTEM
18643 if (it
->glyph_row
->reversed_p
)
18645 /* Prepend a stretch glyph to the row, such that the
18646 rightmost glyph will be drawn flushed all the way to the
18647 right margin of the window. The stretch glyph that will
18648 occupy the empty space, if any, to the left of the
18650 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18651 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18652 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18654 int row_width
, stretch_ascent
, stretch_width
;
18655 struct text_pos saved_pos
;
18656 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18658 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18659 row_width
+= g
->pixel_width
;
18660 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18661 if (stretch_width
> 0)
18664 (((it
->ascent
+ it
->descent
)
18665 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18666 saved_pos
= it
->position
;
18667 memset (&it
->position
, 0, sizeof it
->position
);
18668 saved_avoid_cursor
= it
->avoid_cursor_p
;
18669 it
->avoid_cursor_p
= 1;
18670 saved_face_id
= it
->face_id
;
18671 saved_box_start
= it
->start_of_box_run_p
;
18672 /* The last row's stretch glyph should get the default
18673 face, to avoid painting the rest of the window with
18674 the region face, if the region ends at ZV. */
18675 if (it
->glyph_row
->ends_at_zv_p
)
18676 it
->face_id
= default_face
->id
;
18678 it
->face_id
= face
->id
;
18679 it
->start_of_box_run_p
= 0;
18680 append_stretch_glyph (it
, make_number (0), stretch_width
,
18681 it
->ascent
+ it
->descent
, stretch_ascent
);
18682 it
->position
= saved_pos
;
18683 it
->avoid_cursor_p
= saved_avoid_cursor
;
18684 it
->face_id
= saved_face_id
;
18685 it
->start_of_box_run_p
= saved_box_start
;
18688 #endif /* HAVE_WINDOW_SYSTEM */
18692 /* Save some values that must not be changed. */
18693 int saved_x
= it
->current_x
;
18694 struct text_pos saved_pos
;
18695 Lisp_Object saved_object
;
18696 enum display_element_type saved_what
= it
->what
;
18697 int saved_face_id
= it
->face_id
;
18699 saved_object
= it
->object
;
18700 saved_pos
= it
->position
;
18702 it
->what
= IT_CHARACTER
;
18703 memset (&it
->position
, 0, sizeof it
->position
);
18704 it
->object
= make_number (0);
18705 it
->c
= it
->char_to_display
= ' ';
18707 /* The last row's blank glyphs should get the default face, to
18708 avoid painting the rest of the window with the region face,
18709 if the region ends at ZV. */
18710 if (it
->glyph_row
->ends_at_zv_p
)
18711 it
->face_id
= default_face
->id
;
18713 it
->face_id
= face
->id
;
18715 PRODUCE_GLYPHS (it
);
18717 while (it
->current_x
<= it
->last_visible_x
)
18718 PRODUCE_GLYPHS (it
);
18720 /* Don't count these blanks really. It would let us insert a left
18721 truncation glyph below and make us set the cursor on them, maybe. */
18722 it
->current_x
= saved_x
;
18723 it
->object
= saved_object
;
18724 it
->position
= saved_pos
;
18725 it
->what
= saved_what
;
18726 it
->face_id
= saved_face_id
;
18731 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18732 trailing whitespace. */
18735 trailing_whitespace_p (ptrdiff_t charpos
)
18737 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18740 while (bytepos
< ZV_BYTE
18741 && (c
= FETCH_CHAR (bytepos
),
18742 c
== ' ' || c
== '\t'))
18745 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18747 if (bytepos
!= PT_BYTE
)
18754 /* Highlight trailing whitespace, if any, in ROW. */
18757 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18759 int used
= row
->used
[TEXT_AREA
];
18763 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18764 struct glyph
*glyph
= start
+ used
- 1;
18766 if (row
->reversed_p
)
18768 /* Right-to-left rows need to be processed in the opposite
18769 direction, so swap the edge pointers. */
18771 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18774 /* Skip over glyphs inserted to display the cursor at the
18775 end of a line, for extending the face of the last glyph
18776 to the end of the line on terminals, and for truncation
18777 and continuation glyphs. */
18778 if (!row
->reversed_p
)
18780 while (glyph
>= start
18781 && glyph
->type
== CHAR_GLYPH
18782 && INTEGERP (glyph
->object
))
18787 while (glyph
<= start
18788 && glyph
->type
== CHAR_GLYPH
18789 && INTEGERP (glyph
->object
))
18793 /* If last glyph is a space or stretch, and it's trailing
18794 whitespace, set the face of all trailing whitespace glyphs in
18795 IT->glyph_row to `trailing-whitespace'. */
18796 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18797 && BUFFERP (glyph
->object
)
18798 && (glyph
->type
== STRETCH_GLYPH
18799 || (glyph
->type
== CHAR_GLYPH
18800 && glyph
->u
.ch
== ' '))
18801 && trailing_whitespace_p (glyph
->charpos
))
18803 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18807 if (!row
->reversed_p
)
18809 while (glyph
>= start
18810 && BUFFERP (glyph
->object
)
18811 && (glyph
->type
== STRETCH_GLYPH
18812 || (glyph
->type
== CHAR_GLYPH
18813 && glyph
->u
.ch
== ' ')))
18814 (glyph
--)->face_id
= face_id
;
18818 while (glyph
<= start
18819 && BUFFERP (glyph
->object
)
18820 && (glyph
->type
== STRETCH_GLYPH
18821 || (glyph
->type
== CHAR_GLYPH
18822 && glyph
->u
.ch
== ' ')))
18823 (glyph
++)->face_id
= face_id
;
18830 /* Value is non-zero if glyph row ROW should be
18831 considered to hold the buffer position CHARPOS. */
18834 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18838 if (charpos
== CHARPOS (row
->end
.pos
)
18839 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18841 /* Suppose the row ends on a string.
18842 Unless the row is continued, that means it ends on a newline
18843 in the string. If it's anything other than a display string
18844 (e.g., a before-string from an overlay), we don't want the
18845 cursor there. (This heuristic seems to give the optimal
18846 behavior for the various types of multi-line strings.)
18847 One exception: if the string has `cursor' property on one of
18848 its characters, we _do_ want the cursor there. */
18849 if (CHARPOS (row
->end
.string_pos
) >= 0)
18851 if (row
->continued_p
)
18855 /* Check for `display' property. */
18856 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18857 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18858 struct glyph
*glyph
;
18861 for (glyph
= end
; glyph
>= beg
; --glyph
)
18862 if (STRINGP (glyph
->object
))
18865 = Fget_char_property (make_number (charpos
),
18869 && display_prop_string_p (prop
, glyph
->object
));
18870 /* If there's a `cursor' property on one of the
18871 string's characters, this row is a cursor row,
18872 even though this is not a display string. */
18875 Lisp_Object s
= glyph
->object
;
18877 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18879 ptrdiff_t gpos
= glyph
->charpos
;
18881 if (!NILP (Fget_char_property (make_number (gpos
),
18893 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18895 /* If the row ends in middle of a real character,
18896 and the line is continued, we want the cursor here.
18897 That's because CHARPOS (ROW->end.pos) would equal
18898 PT if PT is before the character. */
18899 if (!row
->ends_in_ellipsis_p
)
18900 result
= row
->continued_p
;
18902 /* If the row ends in an ellipsis, then
18903 CHARPOS (ROW->end.pos) will equal point after the
18904 invisible text. We want that position to be displayed
18905 after the ellipsis. */
18908 /* If the row ends at ZV, display the cursor at the end of that
18909 row instead of at the start of the row below. */
18910 else if (row
->ends_at_zv_p
)
18919 /* Value is non-zero if glyph row ROW should be
18920 used to hold the cursor. */
18923 cursor_row_p (struct glyph_row
*row
)
18925 return row_for_charpos_p (row
, PT
);
18930 /* Push the property PROP so that it will be rendered at the current
18931 position in IT. Return 1 if PROP was successfully pushed, 0
18932 otherwise. Called from handle_line_prefix to handle the
18933 `line-prefix' and `wrap-prefix' properties. */
18936 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18938 struct text_pos pos
=
18939 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18941 eassert (it
->method
== GET_FROM_BUFFER
18942 || it
->method
== GET_FROM_DISPLAY_VECTOR
18943 || it
->method
== GET_FROM_STRING
);
18945 /* We need to save the current buffer/string position, so it will be
18946 restored by pop_it, because iterate_out_of_display_property
18947 depends on that being set correctly, but some situations leave
18948 it->position not yet set when this function is called. */
18949 push_it (it
, &pos
);
18951 if (STRINGP (prop
))
18953 if (SCHARS (prop
) == 0)
18960 it
->string_from_prefix_prop_p
= 1;
18961 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18962 it
->current
.overlay_string_index
= -1;
18963 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18964 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18965 it
->method
= GET_FROM_STRING
;
18966 it
->stop_charpos
= 0;
18968 it
->base_level_stop
= 0;
18970 /* Force paragraph direction to be that of the parent
18972 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18973 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18975 it
->paragraph_embedding
= L2R
;
18977 /* Set up the bidi iterator for this display string. */
18980 it
->bidi_it
.string
.lstring
= it
->string
;
18981 it
->bidi_it
.string
.s
= NULL
;
18982 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18983 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18984 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18985 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18986 it
->bidi_it
.w
= it
->w
;
18987 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18990 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18992 it
->method
= GET_FROM_STRETCH
;
18995 #ifdef HAVE_WINDOW_SYSTEM
18996 else if (IMAGEP (prop
))
18998 it
->what
= IT_IMAGE
;
18999 it
->image_id
= lookup_image (it
->f
, prop
);
19000 it
->method
= GET_FROM_IMAGE
;
19002 #endif /* HAVE_WINDOW_SYSTEM */
19005 pop_it (it
); /* bogus display property, give up */
19012 /* Return the character-property PROP at the current position in IT. */
19015 get_it_property (struct it
*it
, Lisp_Object prop
)
19017 Lisp_Object position
, object
= it
->object
;
19019 if (STRINGP (object
))
19020 position
= make_number (IT_STRING_CHARPOS (*it
));
19021 else if (BUFFERP (object
))
19023 position
= make_number (IT_CHARPOS (*it
));
19024 object
= it
->window
;
19029 return Fget_char_property (position
, prop
, object
);
19032 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19035 handle_line_prefix (struct it
*it
)
19037 Lisp_Object prefix
;
19039 if (it
->continuation_lines_width
> 0)
19041 prefix
= get_it_property (it
, Qwrap_prefix
);
19043 prefix
= Vwrap_prefix
;
19047 prefix
= get_it_property (it
, Qline_prefix
);
19049 prefix
= Vline_prefix
;
19051 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19053 /* If the prefix is wider than the window, and we try to wrap
19054 it, it would acquire its own wrap prefix, and so on till the
19055 iterator stack overflows. So, don't wrap the prefix. */
19056 it
->line_wrap
= TRUNCATE
;
19057 it
->avoid_cursor_p
= 1;
19063 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19064 only for R2L lines from display_line and display_string, when they
19065 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19066 the line/string needs to be continued on the next glyph row. */
19068 unproduce_glyphs (struct it
*it
, int n
)
19070 struct glyph
*glyph
, *end
;
19072 eassert (it
->glyph_row
);
19073 eassert (it
->glyph_row
->reversed_p
);
19074 eassert (it
->area
== TEXT_AREA
);
19075 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19077 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19078 n
= it
->glyph_row
->used
[TEXT_AREA
];
19079 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19080 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19081 for ( ; glyph
< end
; glyph
++)
19082 glyph
[-n
] = *glyph
;
19085 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19086 and ROW->maxpos. */
19088 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19089 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19090 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19092 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19093 lines' rows is implemented for bidi-reordered rows. */
19095 /* ROW->minpos is the value of min_pos, the minimal buffer position
19096 we have in ROW, or ROW->start.pos if that is smaller. */
19097 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19098 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19100 /* We didn't find buffer positions smaller than ROW->start, or
19101 didn't find _any_ valid buffer positions in any of the glyphs,
19102 so we must trust the iterator's computed positions. */
19103 row
->minpos
= row
->start
.pos
;
19106 max_pos
= CHARPOS (it
->current
.pos
);
19107 max_bpos
= BYTEPOS (it
->current
.pos
);
19110 /* Here are the various use-cases for ending the row, and the
19111 corresponding values for ROW->maxpos:
19113 Line ends in a newline from buffer eol_pos + 1
19114 Line is continued from buffer max_pos + 1
19115 Line is truncated on right it->current.pos
19116 Line ends in a newline from string max_pos + 1(*)
19117 (*) + 1 only when line ends in a forward scan
19118 Line is continued from string max_pos
19119 Line is continued from display vector max_pos
19120 Line is entirely from a string min_pos == max_pos
19121 Line is entirely from a display vector min_pos == max_pos
19122 Line that ends at ZV ZV
19124 If you discover other use-cases, please add them here as
19126 if (row
->ends_at_zv_p
)
19127 row
->maxpos
= it
->current
.pos
;
19128 else if (row
->used
[TEXT_AREA
])
19130 int seen_this_string
= 0;
19131 struct glyph_row
*r1
= row
- 1;
19133 /* Did we see the same display string on the previous row? */
19134 if (STRINGP (it
->object
)
19135 /* this is not the first row */
19136 && row
> it
->w
->desired_matrix
->rows
19137 /* previous row is not the header line */
19138 && !r1
->mode_line_p
19139 /* previous row also ends in a newline from a string */
19140 && r1
->ends_in_newline_from_string_p
)
19142 struct glyph
*start
, *end
;
19144 /* Search for the last glyph of the previous row that came
19145 from buffer or string. Depending on whether the row is
19146 L2R or R2L, we need to process it front to back or the
19147 other way round. */
19148 if (!r1
->reversed_p
)
19150 start
= r1
->glyphs
[TEXT_AREA
];
19151 end
= start
+ r1
->used
[TEXT_AREA
];
19152 /* Glyphs inserted by redisplay have an integer (zero)
19153 as their object. */
19155 && INTEGERP ((end
- 1)->object
)
19156 && (end
- 1)->charpos
<= 0)
19160 if (EQ ((end
- 1)->object
, it
->object
))
19161 seen_this_string
= 1;
19164 /* If all the glyphs of the previous row were inserted
19165 by redisplay, it means the previous row was
19166 produced from a single newline, which is only
19167 possible if that newline came from the same string
19168 as the one which produced this ROW. */
19169 seen_this_string
= 1;
19173 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19174 start
= end
+ r1
->used
[TEXT_AREA
];
19176 && INTEGERP ((end
+ 1)->object
)
19177 && (end
+ 1)->charpos
<= 0)
19181 if (EQ ((end
+ 1)->object
, it
->object
))
19182 seen_this_string
= 1;
19185 seen_this_string
= 1;
19188 /* Take note of each display string that covers a newline only
19189 once, the first time we see it. This is for when a display
19190 string includes more than one newline in it. */
19191 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19193 /* If we were scanning the buffer forward when we displayed
19194 the string, we want to account for at least one buffer
19195 position that belongs to this row (position covered by
19196 the display string), so that cursor positioning will
19197 consider this row as a candidate when point is at the end
19198 of the visual line represented by this row. This is not
19199 required when scanning back, because max_pos will already
19200 have a much larger value. */
19201 if (CHARPOS (row
->end
.pos
) > max_pos
)
19202 INC_BOTH (max_pos
, max_bpos
);
19203 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19205 else if (CHARPOS (it
->eol_pos
) > 0)
19206 SET_TEXT_POS (row
->maxpos
,
19207 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19208 else if (row
->continued_p
)
19210 /* If max_pos is different from IT's current position, it
19211 means IT->method does not belong to the display element
19212 at max_pos. However, it also means that the display
19213 element at max_pos was displayed in its entirety on this
19214 line, which is equivalent to saying that the next line
19215 starts at the next buffer position. */
19216 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19217 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19220 INC_BOTH (max_pos
, max_bpos
);
19221 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19224 else if (row
->truncated_on_right_p
)
19225 /* display_line already called reseat_at_next_visible_line_start,
19226 which puts the iterator at the beginning of the next line, in
19227 the logical order. */
19228 row
->maxpos
= it
->current
.pos
;
19229 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19230 /* A line that is entirely from a string/image/stretch... */
19231 row
->maxpos
= row
->minpos
;
19236 row
->maxpos
= it
->current
.pos
;
19239 /* Construct the glyph row IT->glyph_row in the desired matrix of
19240 IT->w from text at the current position of IT. See dispextern.h
19241 for an overview of struct it. Value is non-zero if
19242 IT->glyph_row displays text, as opposed to a line displaying ZV
19246 display_line (struct it
*it
)
19248 struct glyph_row
*row
= it
->glyph_row
;
19249 Lisp_Object overlay_arrow_string
;
19251 void *wrap_data
= NULL
;
19252 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19253 int wrap_row_used
= -1;
19254 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19255 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19256 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19257 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19258 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19260 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19261 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19263 /* We always start displaying at hpos zero even if hscrolled. */
19264 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19266 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19267 >= it
->w
->desired_matrix
->nrows
)
19269 it
->w
->nrows_scale_factor
++;
19270 it
->f
->fonts_changed
= 1;
19274 /* Is IT->w showing the region? */
19275 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19277 /* Clear the result glyph row and enable it. */
19278 prepare_desired_row (row
);
19280 row
->y
= it
->current_y
;
19281 row
->start
= it
->start
;
19282 row
->continuation_lines_width
= it
->continuation_lines_width
;
19283 row
->displays_text_p
= 1;
19284 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19285 it
->starts_in_middle_of_char_p
= 0;
19287 /* Arrange the overlays nicely for our purposes. Usually, we call
19288 display_line on only one line at a time, in which case this
19289 can't really hurt too much, or we call it on lines which appear
19290 one after another in the buffer, in which case all calls to
19291 recenter_overlay_lists but the first will be pretty cheap. */
19292 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19294 /* Move over display elements that are not visible because we are
19295 hscrolled. This may stop at an x-position < IT->first_visible_x
19296 if the first glyph is partially visible or if we hit a line end. */
19297 if (it
->current_x
< it
->first_visible_x
)
19299 enum move_it_result move_result
;
19301 this_line_min_pos
= row
->start
.pos
;
19302 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19303 MOVE_TO_POS
| MOVE_TO_X
);
19304 /* If we are under a large hscroll, move_it_in_display_line_to
19305 could hit the end of the line without reaching
19306 it->first_visible_x. Pretend that we did reach it. This is
19307 especially important on a TTY, where we will call
19308 extend_face_to_end_of_line, which needs to know how many
19309 blank glyphs to produce. */
19310 if (it
->current_x
< it
->first_visible_x
19311 && (move_result
== MOVE_NEWLINE_OR_CR
19312 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19313 it
->current_x
= it
->first_visible_x
;
19315 /* Record the smallest positions seen while we moved over
19316 display elements that are not visible. This is needed by
19317 redisplay_internal for optimizing the case where the cursor
19318 stays inside the same line. The rest of this function only
19319 considers positions that are actually displayed, so
19320 RECORD_MAX_MIN_POS will not otherwise record positions that
19321 are hscrolled to the left of the left edge of the window. */
19322 min_pos
= CHARPOS (this_line_min_pos
);
19323 min_bpos
= BYTEPOS (this_line_min_pos
);
19327 /* We only do this when not calling `move_it_in_display_line_to'
19328 above, because move_it_in_display_line_to calls
19329 handle_line_prefix itself. */
19330 handle_line_prefix (it
);
19333 /* Get the initial row height. This is either the height of the
19334 text hscrolled, if there is any, or zero. */
19335 row
->ascent
= it
->max_ascent
;
19336 row
->height
= it
->max_ascent
+ it
->max_descent
;
19337 row
->phys_ascent
= it
->max_phys_ascent
;
19338 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19339 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19341 /* Utility macro to record max and min buffer positions seen until now. */
19342 #define RECORD_MAX_MIN_POS(IT) \
19345 int composition_p = !STRINGP ((IT)->string) \
19346 && ((IT)->what == IT_COMPOSITION); \
19347 ptrdiff_t current_pos = \
19348 composition_p ? (IT)->cmp_it.charpos \
19349 : IT_CHARPOS (*(IT)); \
19350 ptrdiff_t current_bpos = \
19351 composition_p ? CHAR_TO_BYTE (current_pos) \
19352 : IT_BYTEPOS (*(IT)); \
19353 if (current_pos < min_pos) \
19355 min_pos = current_pos; \
19356 min_bpos = current_bpos; \
19358 if (IT_CHARPOS (*it) > max_pos) \
19360 max_pos = IT_CHARPOS (*it); \
19361 max_bpos = IT_BYTEPOS (*it); \
19366 /* Loop generating characters. The loop is left with IT on the next
19367 character to display. */
19370 int n_glyphs_before
, hpos_before
, x_before
;
19372 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19374 /* Retrieve the next thing to display. Value is zero if end of
19376 if (!get_next_display_element (it
))
19378 /* Maybe add a space at the end of this line that is used to
19379 display the cursor there under X. Set the charpos of the
19380 first glyph of blank lines not corresponding to any text
19382 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19383 row
->exact_window_width_line_p
= 1;
19384 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19385 || row
->used
[TEXT_AREA
] == 0)
19387 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19388 row
->displays_text_p
= 0;
19390 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19391 && (!MINI_WINDOW_P (it
->w
)
19392 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19393 row
->indicate_empty_line_p
= 1;
19396 it
->continuation_lines_width
= 0;
19397 row
->ends_at_zv_p
= 1;
19398 /* A row that displays right-to-left text must always have
19399 its last face extended all the way to the end of line,
19400 even if this row ends in ZV, because we still write to
19401 the screen left to right. We also need to extend the
19402 last face if the default face is remapped to some
19403 different face, otherwise the functions that clear
19404 portions of the screen will clear with the default face's
19405 background color. */
19406 if (row
->reversed_p
19407 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19408 extend_face_to_end_of_line (it
);
19412 /* Now, get the metrics of what we want to display. This also
19413 generates glyphs in `row' (which is IT->glyph_row). */
19414 n_glyphs_before
= row
->used
[TEXT_AREA
];
19417 /* Remember the line height so far in case the next element doesn't
19418 fit on the line. */
19419 if (it
->line_wrap
!= TRUNCATE
)
19421 ascent
= it
->max_ascent
;
19422 descent
= it
->max_descent
;
19423 phys_ascent
= it
->max_phys_ascent
;
19424 phys_descent
= it
->max_phys_descent
;
19426 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19428 if (IT_DISPLAYING_WHITESPACE (it
))
19432 SAVE_IT (wrap_it
, *it
, wrap_data
);
19434 wrap_row_used
= row
->used
[TEXT_AREA
];
19435 wrap_row_ascent
= row
->ascent
;
19436 wrap_row_height
= row
->height
;
19437 wrap_row_phys_ascent
= row
->phys_ascent
;
19438 wrap_row_phys_height
= row
->phys_height
;
19439 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19440 wrap_row_min_pos
= min_pos
;
19441 wrap_row_min_bpos
= min_bpos
;
19442 wrap_row_max_pos
= max_pos
;
19443 wrap_row_max_bpos
= max_bpos
;
19449 PRODUCE_GLYPHS (it
);
19451 /* If this display element was in marginal areas, continue with
19453 if (it
->area
!= TEXT_AREA
)
19455 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19456 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19457 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19458 row
->phys_height
= max (row
->phys_height
,
19459 it
->max_phys_ascent
+ it
->max_phys_descent
);
19460 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19461 it
->max_extra_line_spacing
);
19462 set_iterator_to_next (it
, 1);
19466 /* Does the display element fit on the line? If we truncate
19467 lines, we should draw past the right edge of the window. If
19468 we don't truncate, we want to stop so that we can display the
19469 continuation glyph before the right margin. If lines are
19470 continued, there are two possible strategies for characters
19471 resulting in more than 1 glyph (e.g. tabs): Display as many
19472 glyphs as possible in this line and leave the rest for the
19473 continuation line, or display the whole element in the next
19474 line. Original redisplay did the former, so we do it also. */
19475 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19476 hpos_before
= it
->hpos
;
19479 if (/* Not a newline. */
19481 /* Glyphs produced fit entirely in the line. */
19482 && it
->current_x
< it
->last_visible_x
)
19484 it
->hpos
+= nglyphs
;
19485 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19486 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19487 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19488 row
->phys_height
= max (row
->phys_height
,
19489 it
->max_phys_ascent
+ it
->max_phys_descent
);
19490 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19491 it
->max_extra_line_spacing
);
19492 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19493 row
->x
= x
- it
->first_visible_x
;
19494 /* Record the maximum and minimum buffer positions seen so
19495 far in glyphs that will be displayed by this row. */
19497 RECORD_MAX_MIN_POS (it
);
19502 struct glyph
*glyph
;
19504 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19506 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19507 new_x
= x
+ glyph
->pixel_width
;
19509 if (/* Lines are continued. */
19510 it
->line_wrap
!= TRUNCATE
19511 && (/* Glyph doesn't fit on the line. */
19512 new_x
> it
->last_visible_x
19513 /* Or it fits exactly on a window system frame. */
19514 || (new_x
== it
->last_visible_x
19515 && FRAME_WINDOW_P (it
->f
)
19516 && (row
->reversed_p
19517 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19518 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19520 /* End of a continued line. */
19523 || (new_x
== it
->last_visible_x
19524 && FRAME_WINDOW_P (it
->f
)
19525 && (row
->reversed_p
19526 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19527 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19529 /* Current glyph is the only one on the line or
19530 fits exactly on the line. We must continue
19531 the line because we can't draw the cursor
19532 after the glyph. */
19533 row
->continued_p
= 1;
19534 it
->current_x
= new_x
;
19535 it
->continuation_lines_width
+= new_x
;
19537 if (i
== nglyphs
- 1)
19539 /* If line-wrap is on, check if a previous
19540 wrap point was found. */
19541 if (wrap_row_used
> 0
19542 /* Even if there is a previous wrap
19543 point, continue the line here as
19544 usual, if (i) the previous character
19545 was a space or tab AND (ii) the
19546 current character is not. */
19548 || IT_DISPLAYING_WHITESPACE (it
)))
19551 /* Record the maximum and minimum buffer
19552 positions seen so far in glyphs that will be
19553 displayed by this row. */
19555 RECORD_MAX_MIN_POS (it
);
19556 set_iterator_to_next (it
, 1);
19557 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19559 if (!get_next_display_element (it
))
19561 row
->exact_window_width_line_p
= 1;
19562 it
->continuation_lines_width
= 0;
19563 row
->continued_p
= 0;
19564 row
->ends_at_zv_p
= 1;
19566 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19568 row
->continued_p
= 0;
19569 row
->exact_window_width_line_p
= 1;
19573 else if (it
->bidi_p
)
19574 RECORD_MAX_MIN_POS (it
);
19576 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19577 && !FRAME_WINDOW_P (it
->f
))
19579 /* A padding glyph that doesn't fit on this line.
19580 This means the whole character doesn't fit
19582 if (row
->reversed_p
)
19583 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19584 - n_glyphs_before
);
19585 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19587 /* Fill the rest of the row with continuation
19588 glyphs like in 20.x. */
19589 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19590 < row
->glyphs
[1 + TEXT_AREA
])
19591 produce_special_glyphs (it
, IT_CONTINUATION
);
19593 row
->continued_p
= 1;
19594 it
->current_x
= x_before
;
19595 it
->continuation_lines_width
+= x_before
;
19597 /* Restore the height to what it was before the
19598 element not fitting on the line. */
19599 it
->max_ascent
= ascent
;
19600 it
->max_descent
= descent
;
19601 it
->max_phys_ascent
= phys_ascent
;
19602 it
->max_phys_descent
= phys_descent
;
19604 else if (wrap_row_used
> 0)
19607 if (row
->reversed_p
)
19608 unproduce_glyphs (it
,
19609 row
->used
[TEXT_AREA
] - wrap_row_used
);
19610 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19611 it
->continuation_lines_width
+= wrap_x
;
19612 row
->used
[TEXT_AREA
] = wrap_row_used
;
19613 row
->ascent
= wrap_row_ascent
;
19614 row
->height
= wrap_row_height
;
19615 row
->phys_ascent
= wrap_row_phys_ascent
;
19616 row
->phys_height
= wrap_row_phys_height
;
19617 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19618 min_pos
= wrap_row_min_pos
;
19619 min_bpos
= wrap_row_min_bpos
;
19620 max_pos
= wrap_row_max_pos
;
19621 max_bpos
= wrap_row_max_bpos
;
19622 row
->continued_p
= 1;
19623 row
->ends_at_zv_p
= 0;
19624 row
->exact_window_width_line_p
= 0;
19625 it
->continuation_lines_width
+= x
;
19627 /* Make sure that a non-default face is extended
19628 up to the right margin of the window. */
19629 extend_face_to_end_of_line (it
);
19631 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19633 /* A TAB that extends past the right edge of the
19634 window. This produces a single glyph on
19635 window system frames. We leave the glyph in
19636 this row and let it fill the row, but don't
19637 consume the TAB. */
19638 if ((row
->reversed_p
19639 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19640 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19641 produce_special_glyphs (it
, IT_CONTINUATION
);
19642 it
->continuation_lines_width
+= it
->last_visible_x
;
19643 row
->ends_in_middle_of_char_p
= 1;
19644 row
->continued_p
= 1;
19645 glyph
->pixel_width
= it
->last_visible_x
- x
;
19646 it
->starts_in_middle_of_char_p
= 1;
19650 /* Something other than a TAB that draws past
19651 the right edge of the window. Restore
19652 positions to values before the element. */
19653 if (row
->reversed_p
)
19654 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19655 - (n_glyphs_before
+ i
));
19656 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19658 /* Display continuation glyphs. */
19659 it
->current_x
= x_before
;
19660 it
->continuation_lines_width
+= x
;
19661 if (!FRAME_WINDOW_P (it
->f
)
19662 || (row
->reversed_p
19663 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19664 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19665 produce_special_glyphs (it
, IT_CONTINUATION
);
19666 row
->continued_p
= 1;
19668 extend_face_to_end_of_line (it
);
19670 if (nglyphs
> 1 && i
> 0)
19672 row
->ends_in_middle_of_char_p
= 1;
19673 it
->starts_in_middle_of_char_p
= 1;
19676 /* Restore the height to what it was before the
19677 element not fitting on the line. */
19678 it
->max_ascent
= ascent
;
19679 it
->max_descent
= descent
;
19680 it
->max_phys_ascent
= phys_ascent
;
19681 it
->max_phys_descent
= phys_descent
;
19686 else if (new_x
> it
->first_visible_x
)
19688 /* Increment number of glyphs actually displayed. */
19691 /* Record the maximum and minimum buffer positions
19692 seen so far in glyphs that will be displayed by
19695 RECORD_MAX_MIN_POS (it
);
19697 if (x
< it
->first_visible_x
)
19698 /* Glyph is partially visible, i.e. row starts at
19699 negative X position. */
19700 row
->x
= x
- it
->first_visible_x
;
19704 /* Glyph is completely off the left margin of the
19705 window. This should not happen because of the
19706 move_it_in_display_line at the start of this
19707 function, unless the text display area of the
19708 window is empty. */
19709 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19712 /* Even if this display element produced no glyphs at all,
19713 we want to record its position. */
19714 if (it
->bidi_p
&& nglyphs
== 0)
19715 RECORD_MAX_MIN_POS (it
);
19717 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19718 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19719 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19720 row
->phys_height
= max (row
->phys_height
,
19721 it
->max_phys_ascent
+ it
->max_phys_descent
);
19722 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19723 it
->max_extra_line_spacing
);
19725 /* End of this display line if row is continued. */
19726 if (row
->continued_p
|| row
->ends_at_zv_p
)
19731 /* Is this a line end? If yes, we're also done, after making
19732 sure that a non-default face is extended up to the right
19733 margin of the window. */
19734 if (ITERATOR_AT_END_OF_LINE_P (it
))
19736 int used_before
= row
->used
[TEXT_AREA
];
19738 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19740 /* Add a space at the end of the line that is used to
19741 display the cursor there. */
19742 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19743 append_space_for_newline (it
, 0);
19745 /* Extend the face to the end of the line. */
19746 extend_face_to_end_of_line (it
);
19748 /* Make sure we have the position. */
19749 if (used_before
== 0)
19750 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19752 /* Record the position of the newline, for use in
19754 it
->eol_pos
= it
->current
.pos
;
19756 /* Consume the line end. This skips over invisible lines. */
19757 set_iterator_to_next (it
, 1);
19758 it
->continuation_lines_width
= 0;
19762 /* Proceed with next display element. Note that this skips
19763 over lines invisible because of selective display. */
19764 set_iterator_to_next (it
, 1);
19766 /* If we truncate lines, we are done when the last displayed
19767 glyphs reach past the right margin of the window. */
19768 if (it
->line_wrap
== TRUNCATE
19769 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19770 ? (it
->current_x
>= it
->last_visible_x
)
19771 : (it
->current_x
> it
->last_visible_x
)))
19773 /* Maybe add truncation glyphs. */
19774 if (!FRAME_WINDOW_P (it
->f
)
19775 || (row
->reversed_p
19776 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19777 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19781 if (!row
->reversed_p
)
19783 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19784 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19789 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19790 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19792 /* Remove any padding glyphs at the front of ROW, to
19793 make room for the truncation glyphs we will be
19794 adding below. The loop below always inserts at
19795 least one truncation glyph, so also remove the
19796 last glyph added to ROW. */
19797 unproduce_glyphs (it
, i
+ 1);
19798 /* Adjust i for the loop below. */
19799 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19802 it
->current_x
= x_before
;
19803 if (!FRAME_WINDOW_P (it
->f
))
19805 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19807 row
->used
[TEXT_AREA
] = i
;
19808 produce_special_glyphs (it
, IT_TRUNCATION
);
19813 row
->used
[TEXT_AREA
] = i
;
19814 produce_special_glyphs (it
, IT_TRUNCATION
);
19817 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19819 /* Don't truncate if we can overflow newline into fringe. */
19820 if (!get_next_display_element (it
))
19822 it
->continuation_lines_width
= 0;
19823 row
->ends_at_zv_p
= 1;
19824 row
->exact_window_width_line_p
= 1;
19827 if (ITERATOR_AT_END_OF_LINE_P (it
))
19829 row
->exact_window_width_line_p
= 1;
19830 goto at_end_of_line
;
19832 it
->current_x
= x_before
;
19835 row
->truncated_on_right_p
= 1;
19836 it
->continuation_lines_width
= 0;
19837 reseat_at_next_visible_line_start (it
, 0);
19838 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19839 it
->hpos
= hpos_before
;
19845 bidi_unshelve_cache (wrap_data
, 1);
19847 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19848 at the left window margin. */
19849 if (it
->first_visible_x
19850 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19852 if (!FRAME_WINDOW_P (it
->f
)
19853 || (row
->reversed_p
19854 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19855 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19856 insert_left_trunc_glyphs (it
);
19857 row
->truncated_on_left_p
= 1;
19860 /* Remember the position at which this line ends.
19862 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19863 cannot be before the call to find_row_edges below, since that is
19864 where these positions are determined. */
19865 row
->end
= it
->current
;
19868 row
->minpos
= row
->start
.pos
;
19869 row
->maxpos
= row
->end
.pos
;
19873 /* ROW->minpos and ROW->maxpos must be the smallest and
19874 `1 + the largest' buffer positions in ROW. But if ROW was
19875 bidi-reordered, these two positions can be anywhere in the
19876 row, so we must determine them now. */
19877 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19880 /* If the start of this line is the overlay arrow-position, then
19881 mark this glyph row as the one containing the overlay arrow.
19882 This is clearly a mess with variable size fonts. It would be
19883 better to let it be displayed like cursors under X. */
19884 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19885 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19886 !NILP (overlay_arrow_string
)))
19888 /* Overlay arrow in window redisplay is a fringe bitmap. */
19889 if (STRINGP (overlay_arrow_string
))
19891 struct glyph_row
*arrow_row
19892 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19893 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19894 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19895 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19896 struct glyph
*p2
, *end
;
19898 /* Copy the arrow glyphs. */
19899 while (glyph
< arrow_end
)
19902 /* Throw away padding glyphs. */
19904 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19905 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19911 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19916 eassert (INTEGERP (overlay_arrow_string
));
19917 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19919 overlay_arrow_seen
= 1;
19922 /* Highlight trailing whitespace. */
19923 if (!NILP (Vshow_trailing_whitespace
))
19924 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19926 /* Compute pixel dimensions of this line. */
19927 compute_line_metrics (it
);
19929 /* Implementation note: No changes in the glyphs of ROW or in their
19930 faces can be done past this point, because compute_line_metrics
19931 computes ROW's hash value and stores it within the glyph_row
19934 /* Record whether this row ends inside an ellipsis. */
19935 row
->ends_in_ellipsis_p
19936 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19937 && it
->ellipsis_p
);
19939 /* Save fringe bitmaps in this row. */
19940 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19941 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19942 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19943 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19945 it
->left_user_fringe_bitmap
= 0;
19946 it
->left_user_fringe_face_id
= 0;
19947 it
->right_user_fringe_bitmap
= 0;
19948 it
->right_user_fringe_face_id
= 0;
19950 /* Maybe set the cursor. */
19951 cvpos
= it
->w
->cursor
.vpos
;
19953 /* In bidi-reordered rows, keep checking for proper cursor
19954 position even if one has been found already, because buffer
19955 positions in such rows change non-linearly with ROW->VPOS,
19956 when a line is continued. One exception: when we are at ZV,
19957 display cursor on the first suitable glyph row, since all
19958 the empty rows after that also have their position set to ZV. */
19959 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19960 lines' rows is implemented for bidi-reordered rows. */
19962 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19963 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19964 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19965 && cursor_row_p (row
))
19966 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19968 /* Prepare for the next line. This line starts horizontally at (X
19969 HPOS) = (0 0). Vertical positions are incremented. As a
19970 convenience for the caller, IT->glyph_row is set to the next
19972 it
->current_x
= it
->hpos
= 0;
19973 it
->current_y
+= row
->height
;
19974 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19977 /* The next row should by default use the same value of the
19978 reversed_p flag as this one. set_iterator_to_next decides when
19979 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19980 the flag accordingly. */
19981 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19982 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19983 it
->start
= row
->end
;
19984 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
19986 #undef RECORD_MAX_MIN_POS
19989 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19990 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19991 doc
: /* Return paragraph direction at point in BUFFER.
19992 Value is either `left-to-right' or `right-to-left'.
19993 If BUFFER is omitted or nil, it defaults to the current buffer.
19995 Paragraph direction determines how the text in the paragraph is displayed.
19996 In left-to-right paragraphs, text begins at the left margin of the window
19997 and the reading direction is generally left to right. In right-to-left
19998 paragraphs, text begins at the right margin and is read from right to left.
20000 See also `bidi-paragraph-direction'. */)
20001 (Lisp_Object buffer
)
20003 struct buffer
*buf
= current_buffer
;
20004 struct buffer
*old
= buf
;
20006 if (! NILP (buffer
))
20008 CHECK_BUFFER (buffer
);
20009 buf
= XBUFFER (buffer
);
20012 if (NILP (BVAR (buf
, bidi_display_reordering
))
20013 || NILP (BVAR (buf
, enable_multibyte_characters
))
20014 /* When we are loading loadup.el, the character property tables
20015 needed for bidi iteration are not yet available. */
20016 || !NILP (Vpurify_flag
))
20017 return Qleft_to_right
;
20018 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20019 return BVAR (buf
, bidi_paragraph_direction
);
20022 /* Determine the direction from buffer text. We could try to
20023 use current_matrix if it is up to date, but this seems fast
20024 enough as it is. */
20025 struct bidi_it itb
;
20026 ptrdiff_t pos
= BUF_PT (buf
);
20027 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20029 void *itb_data
= bidi_shelve_cache ();
20031 set_buffer_temp (buf
);
20032 /* bidi_paragraph_init finds the base direction of the paragraph
20033 by searching forward from paragraph start. We need the base
20034 direction of the current or _previous_ paragraph, so we need
20035 to make sure we are within that paragraph. To that end, find
20036 the previous non-empty line. */
20037 if (pos
>= ZV
&& pos
> BEGV
)
20038 DEC_BOTH (pos
, bytepos
);
20039 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20040 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20042 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20043 || c
== ' ' || c
== '\t' || c
== '\f')
20045 if (bytepos
<= BEGV_BYTE
)
20050 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20053 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20054 itb
.paragraph_dir
= NEUTRAL_DIR
;
20055 itb
.string
.s
= NULL
;
20056 itb
.string
.lstring
= Qnil
;
20057 itb
.string
.bufpos
= 0;
20058 itb
.string
.unibyte
= 0;
20059 /* We have no window to use here for ignoring window-specific
20060 overlays. Using NULL for window pointer will cause
20061 compute_display_string_pos to use the current buffer. */
20063 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20064 bidi_unshelve_cache (itb_data
, 0);
20065 set_buffer_temp (old
);
20066 switch (itb
.paragraph_dir
)
20069 return Qleft_to_right
;
20072 return Qright_to_left
;
20080 DEFUN ("move-point-visually", Fmove_point_visually
,
20081 Smove_point_visually
, 1, 1, 0,
20082 doc
: /* Move point in the visual order in the specified DIRECTION.
20083 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20086 Value is the new character position of point. */)
20087 (Lisp_Object direction
)
20089 struct window
*w
= XWINDOW (selected_window
);
20090 struct buffer
*b
= XBUFFER (w
->contents
);
20091 struct glyph_row
*row
;
20093 Lisp_Object paragraph_dir
;
20095 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20096 (!(ROW)->continued_p \
20097 && INTEGERP ((GLYPH)->object) \
20098 && (GLYPH)->type == CHAR_GLYPH \
20099 && (GLYPH)->u.ch == ' ' \
20100 && (GLYPH)->charpos >= 0 \
20101 && !(GLYPH)->avoid_cursor_p)
20103 CHECK_NUMBER (direction
);
20104 dir
= XINT (direction
);
20110 /* If current matrix is up-to-date, we can use the information
20111 recorded in the glyphs, at least as long as the goal is on the
20113 if (w
->window_end_valid
20114 && !windows_or_buffers_changed
20116 && !b
->clip_changed
20117 && !b
->prevent_redisplay_optimizations_p
20118 && !window_outdated (w
)
20119 && w
->cursor
.vpos
>= 0
20120 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20121 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20123 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20124 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20125 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20127 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20129 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20131 SET_PT (g
->charpos
);
20132 w
->cursor
.vpos
= -1;
20133 return make_number (PT
);
20135 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20139 if (BUFFERP (gpt
->object
))
20142 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20143 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20145 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20147 else if (BUFFERP (g
->object
))
20148 new_pos
= g
->charpos
;
20152 w
->cursor
.vpos
= -1;
20153 return make_number (PT
);
20155 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20157 /* Glyphs inserted at the end of a non-empty line for
20158 positioning the cursor have zero charpos, so we must
20159 deduce the value of point by other means. */
20160 if (g
->charpos
> 0)
20161 SET_PT (g
->charpos
);
20162 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20164 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20165 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20168 w
->cursor
.vpos
= -1;
20169 return make_number (PT
);
20172 if (g
== e
|| INTEGERP (g
->object
))
20174 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20175 goto simulate_display
;
20176 if (!row
->reversed_p
)
20180 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20181 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20182 goto simulate_display
;
20186 if (row
->reversed_p
&& !row
->continued_p
)
20188 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20189 w
->cursor
.vpos
= -1;
20190 return make_number (PT
);
20192 g
= row
->glyphs
[TEXT_AREA
];
20193 e
= g
+ row
->used
[TEXT_AREA
];
20194 for ( ; g
< e
; g
++)
20196 if (BUFFERP (g
->object
)
20197 /* Empty lines have only one glyph, which stands
20198 for the newline, and whose charpos is the
20199 buffer position of the newline. */
20200 || ROW_GLYPH_NEWLINE_P (row
, g
)
20201 /* When the buffer ends in a newline, the line at
20202 EOB also has one glyph, but its charpos is -1. */
20203 || (row
->ends_at_zv_p
20204 && !row
->reversed_p
20205 && INTEGERP (g
->object
)
20206 && g
->type
== CHAR_GLYPH
20207 && g
->u
.ch
== ' '))
20209 if (g
->charpos
> 0)
20210 SET_PT (g
->charpos
);
20211 else if (!row
->reversed_p
20212 && row
->ends_at_zv_p
20217 w
->cursor
.vpos
= -1;
20218 return make_number (PT
);
20224 if (!row
->reversed_p
&& !row
->continued_p
)
20226 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20227 w
->cursor
.vpos
= -1;
20228 return make_number (PT
);
20230 e
= row
->glyphs
[TEXT_AREA
];
20231 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20232 for ( ; g
>= e
; g
--)
20234 if (BUFFERP (g
->object
)
20235 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20237 /* Empty R2L lines on GUI frames have the buffer
20238 position of the newline stored in the stretch
20240 || g
->type
== STRETCH_GLYPH
20241 || (row
->ends_at_zv_p
20243 && INTEGERP (g
->object
)
20244 && g
->type
== CHAR_GLYPH
20245 && g
->u
.ch
== ' '))
20247 if (g
->charpos
> 0)
20248 SET_PT (g
->charpos
);
20249 else if (row
->reversed_p
20250 && row
->ends_at_zv_p
20255 w
->cursor
.vpos
= -1;
20256 return make_number (PT
);
20265 /* If we wind up here, we failed to move by using the glyphs, so we
20266 need to simulate display instead. */
20269 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20271 paragraph_dir
= Qleft_to_right
;
20272 if (EQ (paragraph_dir
, Qright_to_left
))
20274 if (PT
<= BEGV
&& dir
< 0)
20275 xsignal0 (Qbeginning_of_buffer
);
20276 else if (PT
>= ZV
&& dir
> 0)
20277 xsignal0 (Qend_of_buffer
);
20280 struct text_pos pt
;
20282 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20284 bool overshoot_expected
= false;
20285 bool target_is_eol_p
= false;
20287 /* Setup the arena. */
20288 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20289 start_display (&it
, w
, pt
);
20291 if (it
.cmp_it
.id
< 0
20292 && it
.method
== GET_FROM_STRING
20293 && it
.area
== TEXT_AREA
20294 && it
.string_from_display_prop_p
20295 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20296 overshoot_expected
= true;
20298 /* Find the X coordinate of point. We start from the beginning
20299 of this or previous line to make sure we are before point in
20300 the logical order (since the move_it_* functions can only
20302 reseat_at_previous_visible_line_start (&it
);
20303 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20304 if (IT_CHARPOS (it
) != PT
)
20305 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20306 -1, -1, -1, MOVE_TO_POS
);
20307 pt_x
= it
.current_x
;
20309 if (dir
> 0 || overshoot_expected
)
20311 struct glyph_row
*row
= it
.glyph_row
;
20313 /* When point is at beginning of line, we don't have
20314 information about the glyph there loaded into struct
20315 it. Calling get_next_display_element fixes that. */
20317 get_next_display_element (&it
);
20318 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20319 it
.glyph_row
= NULL
;
20320 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20321 it
.glyph_row
= row
;
20322 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20323 it, lest it will become out of sync with it's buffer
20325 it
.current_x
= pt_x
;
20328 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20329 pixel_width
= it
.pixel_width
;
20330 if (overshoot_expected
&& at_eol_p
)
20332 else if (pixel_width
<= 0)
20335 /* If there's a display string at point, we are actually at the
20336 glyph to the left of point, so we need to correct the X
20338 if (overshoot_expected
)
20339 pt_x
+= pixel_width
;
20341 /* Compute target X coordinate, either to the left or to the
20342 right of point. On TTY frames, all characters have the same
20343 pixel width of 1, so we can use that. On GUI frames we don't
20344 have an easy way of getting at the pixel width of the
20345 character to the left of point, so we use a different method
20346 of getting to that place. */
20348 target_x
= pt_x
+ pixel_width
;
20350 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20352 /* Target X coordinate could be one line above or below the line
20353 of point, in which case we need to adjust the target X
20354 coordinate. Also, if moving to the left, we need to begin at
20355 the left edge of the point's screen line. */
20360 start_display (&it
, w
, pt
);
20361 reseat_at_previous_visible_line_start (&it
);
20362 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20364 move_it_by_lines (&it
, pt_vpos
);
20368 move_it_by_lines (&it
, -1);
20369 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20370 target_is_eol_p
= true;
20376 || (target_x
>= it
.last_visible_x
20377 && it
.line_wrap
!= TRUNCATE
))
20380 move_it_by_lines (&it
, 0);
20381 move_it_by_lines (&it
, 1);
20386 /* Move to the target X coordinate. */
20387 #ifdef HAVE_WINDOW_SYSTEM
20388 /* On GUI frames, as we don't know the X coordinate of the
20389 character to the left of point, moving point to the left
20390 requires walking, one grapheme cluster at a time, until we
20391 find ourself at a place immediately to the left of the
20392 character at point. */
20393 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20395 struct text_pos new_pos
= it
.current
.pos
;
20396 enum move_it_result rc
= MOVE_X_REACHED
;
20398 while (it
.current_x
+ it
.pixel_width
<= target_x
20399 && rc
== MOVE_X_REACHED
)
20401 int new_x
= it
.current_x
+ it
.pixel_width
;
20403 new_pos
= it
.current
.pos
;
20404 if (new_x
== it
.current_x
)
20406 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20407 MOVE_TO_POS
| MOVE_TO_X
);
20408 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20411 /* If we ended up on a composed character inside
20412 bidi-reordered text (e.g., Hebrew text with diacritics),
20413 the iterator gives us the buffer position of the last (in
20414 logical order) character of the composed grapheme cluster,
20415 which is not what we want. So we cheat: we compute the
20416 character position of the character that follows (in the
20417 logical order) the one where the above loop stopped. That
20418 character will appear on display to the left of point. */
20420 && it
.bidi_it
.scan_dir
== -1
20421 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20423 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20424 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20426 it
.current
.pos
= new_pos
;
20430 if (it
.current_x
!= target_x
)
20431 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20433 /* When lines are truncated, the above loop will stop at the
20434 window edge. But we want to get to the end of line, even if
20435 it is beyond the window edge; automatic hscroll will then
20436 scroll the window to show point as appropriate. */
20437 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20438 && get_next_display_element (&it
))
20440 struct text_pos new_pos
= it
.current
.pos
;
20442 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20444 set_iterator_to_next (&it
, 0);
20445 if (it
.method
== GET_FROM_BUFFER
)
20446 new_pos
= it
.current
.pos
;
20447 if (!get_next_display_element (&it
))
20451 it
.current
.pos
= new_pos
;
20454 /* If we ended up in a display string that covers point, move to
20455 buffer position to the right in the visual order. */
20458 while (IT_CHARPOS (it
) == PT
)
20460 set_iterator_to_next (&it
, 0);
20461 if (!get_next_display_element (&it
))
20466 /* Move point to that position. */
20467 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20470 return make_number (PT
);
20472 #undef ROW_GLYPH_NEWLINE_P
20476 /***********************************************************************
20478 ***********************************************************************/
20480 /* Redisplay the menu bar in the frame for window W.
20482 The menu bar of X frames that don't have X toolkit support is
20483 displayed in a special window W->frame->menu_bar_window.
20485 The menu bar of terminal frames is treated specially as far as
20486 glyph matrices are concerned. Menu bar lines are not part of
20487 windows, so the update is done directly on the frame matrix rows
20488 for the menu bar. */
20491 display_menu_bar (struct window
*w
)
20493 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20498 /* Don't do all this for graphical frames. */
20500 if (FRAME_W32_P (f
))
20503 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20509 if (FRAME_NS_P (f
))
20511 #endif /* HAVE_NS */
20513 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20514 eassert (!FRAME_WINDOW_P (f
));
20515 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20516 it
.first_visible_x
= 0;
20517 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20518 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20519 if (FRAME_WINDOW_P (f
))
20521 /* Menu bar lines are displayed in the desired matrix of the
20522 dummy window menu_bar_window. */
20523 struct window
*menu_w
;
20524 menu_w
= XWINDOW (f
->menu_bar_window
);
20525 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20527 it
.first_visible_x
= 0;
20528 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20531 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20533 /* This is a TTY frame, i.e. character hpos/vpos are used as
20535 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20537 it
.first_visible_x
= 0;
20538 it
.last_visible_x
= FRAME_COLS (f
);
20541 /* FIXME: This should be controlled by a user option. See the
20542 comments in redisplay_tool_bar and display_mode_line about
20544 it
.paragraph_embedding
= L2R
;
20546 /* Clear all rows of the menu bar. */
20547 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20549 struct glyph_row
*row
= it
.glyph_row
+ i
;
20550 clear_glyph_row (row
);
20551 row
->enabled_p
= 1;
20552 row
->full_width_p
= 1;
20555 /* Display all items of the menu bar. */
20556 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20557 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20559 Lisp_Object string
;
20561 /* Stop at nil string. */
20562 string
= AREF (items
, i
+ 1);
20566 /* Remember where item was displayed. */
20567 ASET (items
, i
+ 3, make_number (it
.hpos
));
20569 /* Display the item, pad with one space. */
20570 if (it
.current_x
< it
.last_visible_x
)
20571 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20572 SCHARS (string
) + 1, 0, 0, -1);
20575 /* Fill out the line with spaces. */
20576 if (it
.current_x
< it
.last_visible_x
)
20577 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20579 /* Compute the total height of the lines. */
20580 compute_line_metrics (&it
);
20584 /* Deep copy of a glyph row, including the glyphs. */
20586 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20588 int area
, i
, sum_used
= 0;
20589 struct glyph
*pointers
[1 + LAST_AREA
];
20591 /* Save glyph pointers of TO. */
20592 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20594 /* Do a structure assignment. */
20597 /* Restore original pointers of TO. */
20598 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20600 /* Count how many glyphs to copy and update glyph pointers. */
20601 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
20603 if (area
> LEFT_MARGIN_AREA
)
20605 eassert (from
->glyphs
[area
] - from
->glyphs
[area
- 1]
20606 == from
->used
[area
- 1]);
20607 to
->glyphs
[area
] = to
->glyphs
[area
- 1] + to
->used
[area
- 1];
20609 sum_used
+= from
->used
[area
];
20612 /* Copy the glyphs. */
20613 eassert (sum_used
<= to
->glyphs
[LAST_AREA
] - to
->glyphs
[LEFT_MARGIN_AREA
]);
20614 for (i
= 0; i
< sum_used
; i
++)
20615 to
->glyphs
[LEFT_MARGIN_AREA
][i
] = from
->glyphs
[LEFT_MARGIN_AREA
][i
];
20618 /* Display one menu item on a TTY, by overwriting the glyphs in the
20619 frame F's desired glyph matrix with glyphs produced from the menu
20620 item text. Called from term.c to display TTY drop-down menus one
20623 ITEM_TEXT is the menu item text as a C string.
20625 FACE_ID is the face ID to be used for this menu item. FACE_ID
20626 could specify one of 3 faces: a face for an enabled item, a face
20627 for a disabled item, or a face for a selected item.
20629 X and Y are coordinates of the first glyph in the frame's desired
20630 matrix to be overwritten by the menu item. Since this is a TTY, Y
20631 is the zero-based number of the glyph row and X is the zero-based
20632 glyph number in the row, starting from left, where to start
20633 displaying the item.
20635 SUBMENU non-zero means this menu item drops down a submenu, which
20636 should be indicated by displaying a proper visual cue after the
20640 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20641 int x
, int y
, int submenu
)
20644 struct frame
*f
= SELECTED_FRAME ();
20645 struct window
*w
= XWINDOW (f
->selected_window
);
20646 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20647 struct glyph_row
*row
;
20648 size_t item_len
= strlen (item_text
);
20650 eassert (FRAME_TERMCAP_P (f
));
20652 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20653 it
.first_visible_x
= 0;
20654 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20655 row
= it
.glyph_row
;
20656 /* Start with the row contents from the current matrix. */
20657 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20658 saved_width
= row
->full_width_p
;
20659 row
->full_width_p
= 1;
20660 saved_reversed
= row
->reversed_p
;
20661 row
->reversed_p
= 0;
20662 row
->enabled_p
= 1;
20664 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20666 it
.current_x
= it
.hpos
= x
;
20667 it
.current_y
= it
.vpos
= y
;
20668 saved_used
= row
->used
[TEXT_AREA
];
20669 saved_truncated
= row
->truncated_on_right_p
;
20670 row
->used
[TEXT_AREA
] = x
;
20671 it
.face_id
= face_id
;
20672 it
.line_wrap
= TRUNCATE
;
20674 /* FIXME: This should be controlled by a user option. See the
20675 comments in redisplay_tool_bar and display_mode_line about this.
20676 Also, if paragraph_embedding could ever be R2L, changes will be
20677 needed to avoid shifting to the right the row characters in
20678 term.c:append_glyph. */
20679 it
.paragraph_embedding
= L2R
;
20681 /* Pad with a space on the left. */
20682 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20684 /* Display the menu item, pad with spaces to WIDTH. */
20687 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20688 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20690 /* Indicate with " >" that there's a submenu. */
20691 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20692 FRAME_COLS (f
) - 1, -1);
20695 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20696 width
, 0, FRAME_COLS (f
) - 1, -1);
20698 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20699 row
->truncated_on_right_p
= saved_truncated
;
20700 row
->hash
= row_hash (row
);
20701 row
->full_width_p
= saved_width
;
20702 row
->reversed_p
= saved_reversed
;
20704 #endif /* HAVE_MENUS */
20706 /***********************************************************************
20708 ***********************************************************************/
20710 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20711 FORCE is non-zero, redisplay mode lines unconditionally.
20712 Otherwise, redisplay only mode lines that are garbaged. Value is
20713 the number of windows whose mode lines were redisplayed. */
20716 redisplay_mode_lines (Lisp_Object window
, int force
)
20720 while (!NILP (window
))
20722 struct window
*w
= XWINDOW (window
);
20724 if (WINDOWP (w
->contents
))
20725 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20727 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20728 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20730 struct text_pos lpoint
;
20731 struct buffer
*old
= current_buffer
;
20733 /* Set the window's buffer for the mode line display. */
20734 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20735 set_buffer_internal_1 (XBUFFER (w
->contents
));
20737 /* Point refers normally to the selected window. For any
20738 other window, set up appropriate value. */
20739 if (!EQ (window
, selected_window
))
20741 struct text_pos pt
;
20743 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20744 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20747 /* Display mode lines. */
20748 clear_glyph_matrix (w
->desired_matrix
);
20749 if (display_mode_lines (w
))
20752 w
->must_be_updated_p
= 1;
20755 /* Restore old settings. */
20756 set_buffer_internal_1 (old
);
20757 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20767 /* Display the mode and/or header line of window W. Value is the
20768 sum number of mode lines and header lines displayed. */
20771 display_mode_lines (struct window
*w
)
20773 Lisp_Object old_selected_window
= selected_window
;
20774 Lisp_Object old_selected_frame
= selected_frame
;
20775 Lisp_Object new_frame
= w
->frame
;
20776 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20779 selected_frame
= new_frame
;
20780 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20781 or window's point, then we'd need select_window_1 here as well. */
20782 XSETWINDOW (selected_window
, w
);
20783 XFRAME (new_frame
)->selected_window
= selected_window
;
20785 /* These will be set while the mode line specs are processed. */
20786 line_number_displayed
= 0;
20787 w
->column_number_displayed
= -1;
20789 if (WINDOW_WANTS_MODELINE_P (w
))
20791 struct window
*sel_w
= XWINDOW (old_selected_window
);
20793 /* Select mode line face based on the real selected window. */
20794 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20795 BVAR (current_buffer
, mode_line_format
));
20799 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20801 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20802 BVAR (current_buffer
, header_line_format
));
20806 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20807 selected_frame
= old_selected_frame
;
20808 selected_window
= old_selected_window
;
20813 /* Display mode or header line of window W. FACE_ID specifies which
20814 line to display; it is either MODE_LINE_FACE_ID or
20815 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20816 display. Value is the pixel height of the mode/header line
20820 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20824 ptrdiff_t count
= SPECPDL_INDEX ();
20826 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20827 /* Don't extend on a previously drawn mode-line.
20828 This may happen if called from pos_visible_p. */
20829 it
.glyph_row
->enabled_p
= 0;
20830 prepare_desired_row (it
.glyph_row
);
20832 it
.glyph_row
->mode_line_p
= 1;
20834 /* FIXME: This should be controlled by a user option. But
20835 supporting such an option is not trivial, since the mode line is
20836 made up of many separate strings. */
20837 it
.paragraph_embedding
= L2R
;
20839 record_unwind_protect (unwind_format_mode_line
,
20840 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20842 mode_line_target
= MODE_LINE_DISPLAY
;
20844 /* Temporarily make frame's keyboard the current kboard so that
20845 kboard-local variables in the mode_line_format will get the right
20847 push_kboard (FRAME_KBOARD (it
.f
));
20848 record_unwind_save_match_data ();
20849 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20852 unbind_to (count
, Qnil
);
20854 /* Fill up with spaces. */
20855 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20857 compute_line_metrics (&it
);
20858 it
.glyph_row
->full_width_p
= 1;
20859 it
.glyph_row
->continued_p
= 0;
20860 it
.glyph_row
->truncated_on_left_p
= 0;
20861 it
.glyph_row
->truncated_on_right_p
= 0;
20863 /* Make a 3D mode-line have a shadow at its right end. */
20864 face
= FACE_FROM_ID (it
.f
, face_id
);
20865 extend_face_to_end_of_line (&it
);
20866 if (face
->box
!= FACE_NO_BOX
)
20868 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20869 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20870 last
->right_box_line_p
= 1;
20873 return it
.glyph_row
->height
;
20876 /* Move element ELT in LIST to the front of LIST.
20877 Return the updated list. */
20880 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20882 register Lisp_Object tail
, prev
;
20883 register Lisp_Object tem
;
20887 while (CONSP (tail
))
20893 /* Splice out the link TAIL. */
20895 list
= XCDR (tail
);
20897 Fsetcdr (prev
, XCDR (tail
));
20899 /* Now make it the first. */
20900 Fsetcdr (tail
, list
);
20905 tail
= XCDR (tail
);
20909 /* Not found--return unchanged LIST. */
20913 /* Contribute ELT to the mode line for window IT->w. How it
20914 translates into text depends on its data type.
20916 IT describes the display environment in which we display, as usual.
20918 DEPTH is the depth in recursion. It is used to prevent
20919 infinite recursion here.
20921 FIELD_WIDTH is the number of characters the display of ELT should
20922 occupy in the mode line, and PRECISION is the maximum number of
20923 characters to display from ELT's representation. See
20924 display_string for details.
20926 Returns the hpos of the end of the text generated by ELT.
20928 PROPS is a property list to add to any string we encounter.
20930 If RISKY is nonzero, remove (disregard) any properties in any string
20931 we encounter, and ignore :eval and :propertize.
20933 The global variable `mode_line_target' determines whether the
20934 output is passed to `store_mode_line_noprop',
20935 `store_mode_line_string', or `display_string'. */
20938 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20939 Lisp_Object elt
, Lisp_Object props
, int risky
)
20941 int n
= 0, field
, prec
;
20946 elt
= build_string ("*too-deep*");
20950 switch (XTYPE (elt
))
20954 /* A string: output it and check for %-constructs within it. */
20956 ptrdiff_t offset
= 0;
20958 if (SCHARS (elt
) > 0
20959 && (!NILP (props
) || risky
))
20961 Lisp_Object oprops
, aelt
;
20962 oprops
= Ftext_properties_at (make_number (0), elt
);
20964 /* If the starting string's properties are not what
20965 we want, translate the string. Also, if the string
20966 is risky, do that anyway. */
20968 if (NILP (Fequal (props
, oprops
)) || risky
)
20970 /* If the starting string has properties,
20971 merge the specified ones onto the existing ones. */
20972 if (! NILP (oprops
) && !risky
)
20976 oprops
= Fcopy_sequence (oprops
);
20978 while (CONSP (tem
))
20980 oprops
= Fplist_put (oprops
, XCAR (tem
),
20981 XCAR (XCDR (tem
)));
20982 tem
= XCDR (XCDR (tem
));
20987 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20988 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20990 /* AELT is what we want. Move it to the front
20991 without consing. */
20993 mode_line_proptrans_alist
20994 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21000 /* If AELT has the wrong props, it is useless.
21001 so get rid of it. */
21003 mode_line_proptrans_alist
21004 = Fdelq (aelt
, mode_line_proptrans_alist
);
21006 elt
= Fcopy_sequence (elt
);
21007 Fset_text_properties (make_number (0), Flength (elt
),
21009 /* Add this item to mode_line_proptrans_alist. */
21010 mode_line_proptrans_alist
21011 = Fcons (Fcons (elt
, props
),
21012 mode_line_proptrans_alist
);
21013 /* Truncate mode_line_proptrans_alist
21014 to at most 50 elements. */
21015 tem
= Fnthcdr (make_number (50),
21016 mode_line_proptrans_alist
);
21018 XSETCDR (tem
, Qnil
);
21027 prec
= precision
- n
;
21028 switch (mode_line_target
)
21030 case MODE_LINE_NOPROP
:
21031 case MODE_LINE_TITLE
:
21032 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21034 case MODE_LINE_STRING
:
21035 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21037 case MODE_LINE_DISPLAY
:
21038 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21039 0, prec
, 0, STRING_MULTIBYTE (elt
));
21046 /* Handle the non-literal case. */
21048 while ((precision
<= 0 || n
< precision
)
21049 && SREF (elt
, offset
) != 0
21050 && (mode_line_target
!= MODE_LINE_DISPLAY
21051 || it
->current_x
< it
->last_visible_x
))
21053 ptrdiff_t last_offset
= offset
;
21055 /* Advance to end of string or next format specifier. */
21056 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21059 if (offset
- 1 != last_offset
)
21061 ptrdiff_t nchars
, nbytes
;
21063 /* Output to end of string or up to '%'. Field width
21064 is length of string. Don't output more than
21065 PRECISION allows us. */
21068 prec
= c_string_width (SDATA (elt
) + last_offset
,
21069 offset
- last_offset
, precision
- n
,
21072 switch (mode_line_target
)
21074 case MODE_LINE_NOPROP
:
21075 case MODE_LINE_TITLE
:
21076 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21078 case MODE_LINE_STRING
:
21080 ptrdiff_t bytepos
= last_offset
;
21081 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21082 ptrdiff_t endpos
= (precision
<= 0
21083 ? string_byte_to_char (elt
, offset
)
21084 : charpos
+ nchars
);
21086 n
+= store_mode_line_string (NULL
,
21087 Fsubstring (elt
, make_number (charpos
),
21088 make_number (endpos
)),
21092 case MODE_LINE_DISPLAY
:
21094 ptrdiff_t bytepos
= last_offset
;
21095 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21097 if (precision
<= 0)
21098 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21099 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21101 STRING_MULTIBYTE (elt
));
21106 else /* c == '%' */
21108 ptrdiff_t percent_position
= offset
;
21110 /* Get the specified minimum width. Zero means
21113 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21114 field
= field
* 10 + c
- '0';
21116 /* Don't pad beyond the total padding allowed. */
21117 if (field_width
- n
> 0 && field
> field_width
- n
)
21118 field
= field_width
- n
;
21120 /* Note that either PRECISION <= 0 or N < PRECISION. */
21121 prec
= precision
- n
;
21124 n
+= display_mode_element (it
, depth
, field
, prec
,
21125 Vglobal_mode_string
, props
,
21130 ptrdiff_t bytepos
, charpos
;
21132 Lisp_Object string
;
21134 bytepos
= percent_position
;
21135 charpos
= (STRING_MULTIBYTE (elt
)
21136 ? string_byte_to_char (elt
, bytepos
)
21138 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21139 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21141 switch (mode_line_target
)
21143 case MODE_LINE_NOPROP
:
21144 case MODE_LINE_TITLE
:
21145 n
+= store_mode_line_noprop (spec
, field
, prec
);
21147 case MODE_LINE_STRING
:
21149 Lisp_Object tem
= build_string (spec
);
21150 props
= Ftext_properties_at (make_number (charpos
), elt
);
21151 /* Should only keep face property in props */
21152 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21155 case MODE_LINE_DISPLAY
:
21157 int nglyphs_before
, nwritten
;
21159 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21160 nwritten
= display_string (spec
, string
, elt
,
21165 /* Assign to the glyphs written above the
21166 string where the `%x' came from, position
21170 struct glyph
*glyph
21171 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21175 for (i
= 0; i
< nwritten
; ++i
)
21177 glyph
[i
].object
= elt
;
21178 glyph
[i
].charpos
= charpos
;
21195 /* A symbol: process the value of the symbol recursively
21196 as if it appeared here directly. Avoid error if symbol void.
21197 Special case: if value of symbol is a string, output the string
21200 register Lisp_Object tem
;
21202 /* If the variable is not marked as risky to set
21203 then its contents are risky to use. */
21204 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21207 tem
= Fboundp (elt
);
21210 tem
= Fsymbol_value (elt
);
21211 /* If value is a string, output that string literally:
21212 don't check for % within it. */
21216 if (!EQ (tem
, elt
))
21218 /* Give up right away for nil or t. */
21228 register Lisp_Object car
, tem
;
21230 /* A cons cell: five distinct cases.
21231 If first element is :eval or :propertize, do something special.
21232 If first element is a string or a cons, process all the elements
21233 and effectively concatenate them.
21234 If first element is a negative number, truncate displaying cdr to
21235 at most that many characters. If positive, pad (with spaces)
21236 to at least that many characters.
21237 If first element is a symbol, process the cadr or caddr recursively
21238 according to whether the symbol's value is non-nil or nil. */
21240 if (EQ (car
, QCeval
))
21242 /* An element of the form (:eval FORM) means evaluate FORM
21243 and use the result as mode line elements. */
21248 if (CONSP (XCDR (elt
)))
21251 spec
= safe_eval (XCAR (XCDR (elt
)));
21252 n
+= display_mode_element (it
, depth
, field_width
- n
,
21253 precision
- n
, spec
, props
,
21257 else if (EQ (car
, QCpropertize
))
21259 /* An element of the form (:propertize ELT PROPS...)
21260 means display ELT but applying properties PROPS. */
21265 if (CONSP (XCDR (elt
)))
21266 n
+= display_mode_element (it
, depth
, field_width
- n
,
21267 precision
- n
, XCAR (XCDR (elt
)),
21268 XCDR (XCDR (elt
)), risky
);
21270 else if (SYMBOLP (car
))
21272 tem
= Fboundp (car
);
21276 /* elt is now the cdr, and we know it is a cons cell.
21277 Use its car if CAR has a non-nil value. */
21280 tem
= Fsymbol_value (car
);
21287 /* Symbol's value is nil (or symbol is unbound)
21288 Get the cddr of the original list
21289 and if possible find the caddr and use that. */
21293 else if (!CONSP (elt
))
21298 else if (INTEGERP (car
))
21300 register int lim
= XINT (car
);
21304 /* Negative int means reduce maximum width. */
21305 if (precision
<= 0)
21308 precision
= min (precision
, -lim
);
21312 /* Padding specified. Don't let it be more than
21313 current maximum. */
21315 lim
= min (precision
, lim
);
21317 /* If that's more padding than already wanted, queue it.
21318 But don't reduce padding already specified even if
21319 that is beyond the current truncation point. */
21320 field_width
= max (lim
, field_width
);
21324 else if (STRINGP (car
) || CONSP (car
))
21326 Lisp_Object halftail
= elt
;
21330 && (precision
<= 0 || n
< precision
))
21332 n
+= display_mode_element (it
, depth
,
21333 /* Do padding only after the last
21334 element in the list. */
21335 (! CONSP (XCDR (elt
))
21338 precision
- n
, XCAR (elt
),
21342 if ((len
& 1) == 0)
21343 halftail
= XCDR (halftail
);
21344 /* Check for cycle. */
21345 if (EQ (halftail
, elt
))
21354 elt
= build_string ("*invalid*");
21358 /* Pad to FIELD_WIDTH. */
21359 if (field_width
> 0 && n
< field_width
)
21361 switch (mode_line_target
)
21363 case MODE_LINE_NOPROP
:
21364 case MODE_LINE_TITLE
:
21365 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21367 case MODE_LINE_STRING
:
21368 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21370 case MODE_LINE_DISPLAY
:
21371 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21380 /* Store a mode-line string element in mode_line_string_list.
21382 If STRING is non-null, display that C string. Otherwise, the Lisp
21383 string LISP_STRING is displayed.
21385 FIELD_WIDTH is the minimum number of output glyphs to produce.
21386 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21387 with spaces. FIELD_WIDTH <= 0 means don't pad.
21389 PRECISION is the maximum number of characters to output from
21390 STRING. PRECISION <= 0 means don't truncate the string.
21392 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21393 properties to the string.
21395 PROPS are the properties to add to the string.
21396 The mode_line_string_face face property is always added to the string.
21400 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21401 int field_width
, int precision
, Lisp_Object props
)
21406 if (string
!= NULL
)
21408 len
= strlen (string
);
21409 if (precision
> 0 && len
> precision
)
21411 lisp_string
= make_string (string
, len
);
21413 props
= mode_line_string_face_prop
;
21414 else if (!NILP (mode_line_string_face
))
21416 Lisp_Object face
= Fplist_get (props
, Qface
);
21417 props
= Fcopy_sequence (props
);
21419 face
= mode_line_string_face
;
21421 face
= list2 (face
, mode_line_string_face
);
21422 props
= Fplist_put (props
, Qface
, face
);
21424 Fadd_text_properties (make_number (0), make_number (len
),
21425 props
, lisp_string
);
21429 len
= XFASTINT (Flength (lisp_string
));
21430 if (precision
> 0 && len
> precision
)
21433 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21436 if (!NILP (mode_line_string_face
))
21440 props
= Ftext_properties_at (make_number (0), lisp_string
);
21441 face
= Fplist_get (props
, Qface
);
21443 face
= mode_line_string_face
;
21445 face
= list2 (face
, mode_line_string_face
);
21446 props
= list2 (Qface
, face
);
21448 lisp_string
= Fcopy_sequence (lisp_string
);
21451 Fadd_text_properties (make_number (0), make_number (len
),
21452 props
, lisp_string
);
21457 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21461 if (field_width
> len
)
21463 field_width
-= len
;
21464 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21466 Fadd_text_properties (make_number (0), make_number (field_width
),
21467 props
, lisp_string
);
21468 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21476 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21478 doc
: /* Format a string out of a mode line format specification.
21479 First arg FORMAT specifies the mode line format (see `mode-line-format'
21480 for details) to use.
21482 By default, the format is evaluated for the currently selected window.
21484 Optional second arg FACE specifies the face property to put on all
21485 characters for which no face is specified. The value nil means the
21486 default face. The value t means whatever face the window's mode line
21487 currently uses (either `mode-line' or `mode-line-inactive',
21488 depending on whether the window is the selected window or not).
21489 An integer value means the value string has no text
21492 Optional third and fourth args WINDOW and BUFFER specify the window
21493 and buffer to use as the context for the formatting (defaults
21494 are the selected window and the WINDOW's buffer). */)
21495 (Lisp_Object format
, Lisp_Object face
,
21496 Lisp_Object window
, Lisp_Object buffer
)
21501 struct buffer
*old_buffer
= NULL
;
21503 int no_props
= INTEGERP (face
);
21504 ptrdiff_t count
= SPECPDL_INDEX ();
21506 int string_start
= 0;
21508 w
= decode_any_window (window
);
21509 XSETWINDOW (window
, w
);
21512 buffer
= w
->contents
;
21513 CHECK_BUFFER (buffer
);
21515 /* Make formatting the modeline a non-op when noninteractive, otherwise
21516 there will be problems later caused by a partially initialized frame. */
21517 if (NILP (format
) || noninteractive
)
21518 return empty_unibyte_string
;
21523 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21524 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21525 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21526 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21527 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21528 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21529 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21532 old_buffer
= current_buffer
;
21534 /* Save things including mode_line_proptrans_alist,
21535 and set that to nil so that we don't alter the outer value. */
21536 record_unwind_protect (unwind_format_mode_line
,
21537 format_mode_line_unwind_data
21538 (XFRAME (WINDOW_FRAME (w
)),
21539 old_buffer
, selected_window
, 1));
21540 mode_line_proptrans_alist
= Qnil
;
21542 Fselect_window (window
, Qt
);
21543 set_buffer_internal_1 (XBUFFER (buffer
));
21545 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21549 mode_line_target
= MODE_LINE_NOPROP
;
21550 mode_line_string_face_prop
= Qnil
;
21551 mode_line_string_list
= Qnil
;
21552 string_start
= MODE_LINE_NOPROP_LEN (0);
21556 mode_line_target
= MODE_LINE_STRING
;
21557 mode_line_string_list
= Qnil
;
21558 mode_line_string_face
= face
;
21559 mode_line_string_face_prop
21560 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21563 push_kboard (FRAME_KBOARD (it
.f
));
21564 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21569 len
= MODE_LINE_NOPROP_LEN (string_start
);
21570 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21574 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21575 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21576 empty_unibyte_string
);
21579 unbind_to (count
, Qnil
);
21583 /* Write a null-terminated, right justified decimal representation of
21584 the positive integer D to BUF using a minimal field width WIDTH. */
21587 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21589 register char *p
= buf
;
21597 *p
++ = d
% 10 + '0';
21602 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21613 /* Write a null-terminated, right justified decimal and "human
21614 readable" representation of the nonnegative integer D to BUF using
21615 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21617 static const char power_letter
[] =
21631 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21633 /* We aim to represent the nonnegative integer D as
21634 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21635 ptrdiff_t quotient
= d
;
21637 /* -1 means: do not use TENTHS. */
21641 /* Length of QUOTIENT.TENTHS as a string. */
21647 if (quotient
>= 1000)
21649 /* Scale to the appropriate EXPONENT. */
21652 remainder
= quotient
% 1000;
21656 while (quotient
>= 1000);
21658 /* Round to nearest and decide whether to use TENTHS or not. */
21661 tenths
= remainder
/ 100;
21662 if (remainder
% 100 >= 50)
21669 if (quotient
== 10)
21677 if (remainder
>= 500)
21679 if (quotient
< 999)
21690 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21691 if (tenths
== -1 && quotient
<= 99)
21698 p
= psuffix
= buf
+ max (width
, length
);
21700 /* Print EXPONENT. */
21701 *psuffix
++ = power_letter
[exponent
];
21704 /* Print TENTHS. */
21707 *--p
= '0' + tenths
;
21711 /* Print QUOTIENT. */
21714 int digit
= quotient
% 10;
21715 *--p
= '0' + digit
;
21717 while ((quotient
/= 10) != 0);
21719 /* Print leading spaces. */
21724 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21725 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21726 type of CODING_SYSTEM. Return updated pointer into BUF. */
21728 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21731 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21734 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21735 const unsigned char *eol_str
;
21737 /* The EOL conversion we are using. */
21738 Lisp_Object eoltype
;
21740 val
= CODING_SYSTEM_SPEC (coding_system
);
21743 if (!VECTORP (val
)) /* Not yet decided. */
21745 *buf
++ = multibyte
? '-' : ' ';
21747 eoltype
= eol_mnemonic_undecided
;
21748 /* Don't mention EOL conversion if it isn't decided. */
21753 Lisp_Object eolvalue
;
21755 attrs
= AREF (val
, 0);
21756 eolvalue
= AREF (val
, 2);
21759 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21764 /* The EOL conversion that is normal on this system. */
21766 if (NILP (eolvalue
)) /* Not yet decided. */
21767 eoltype
= eol_mnemonic_undecided
;
21768 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21769 eoltype
= eol_mnemonic_undecided
;
21770 else /* eolvalue is Qunix, Qdos, or Qmac. */
21771 eoltype
= (EQ (eolvalue
, Qunix
)
21772 ? eol_mnemonic_unix
21773 : (EQ (eolvalue
, Qdos
) == 1
21774 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21780 /* Mention the EOL conversion if it is not the usual one. */
21781 if (STRINGP (eoltype
))
21783 eol_str
= SDATA (eoltype
);
21784 eol_str_len
= SBYTES (eoltype
);
21786 else if (CHARACTERP (eoltype
))
21788 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21789 int c
= XFASTINT (eoltype
);
21790 eol_str_len
= CHAR_STRING (c
, tmp
);
21795 eol_str
= invalid_eol_type
;
21796 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21798 memcpy (buf
, eol_str
, eol_str_len
);
21799 buf
+= eol_str_len
;
21805 /* Return a string for the output of a mode line %-spec for window W,
21806 generated by character C. FIELD_WIDTH > 0 means pad the string
21807 returned with spaces to that value. Return a Lisp string in
21808 *STRING if the resulting string is taken from that Lisp string.
21810 Note we operate on the current buffer for most purposes. */
21812 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21814 static const char *
21815 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21816 Lisp_Object
*string
)
21819 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21820 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21821 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21822 produce strings from numerical values, so limit preposterously
21823 large values of FIELD_WIDTH to avoid overrunning the buffer's
21824 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21825 bytes plus the terminating null. */
21826 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21827 struct buffer
*b
= current_buffer
;
21835 if (!NILP (BVAR (b
, read_only
)))
21837 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21842 /* This differs from %* only for a modified read-only buffer. */
21843 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21845 if (!NILP (BVAR (b
, read_only
)))
21850 /* This differs from %* in ignoring read-only-ness. */
21851 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21863 if (command_loop_level
> 5)
21865 p
= decode_mode_spec_buf
;
21866 for (i
= 0; i
< command_loop_level
; i
++)
21869 return decode_mode_spec_buf
;
21877 if (command_loop_level
> 5)
21879 p
= decode_mode_spec_buf
;
21880 for (i
= 0; i
< command_loop_level
; i
++)
21883 return decode_mode_spec_buf
;
21890 /* Let lots_of_dashes be a string of infinite length. */
21891 if (mode_line_target
== MODE_LINE_NOPROP
21892 || mode_line_target
== MODE_LINE_STRING
)
21894 if (field_width
<= 0
21895 || field_width
> sizeof (lots_of_dashes
))
21897 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21898 decode_mode_spec_buf
[i
] = '-';
21899 decode_mode_spec_buf
[i
] = '\0';
21900 return decode_mode_spec_buf
;
21903 return lots_of_dashes
;
21907 obj
= BVAR (b
, name
);
21911 /* %c and %l are ignored in `frame-title-format'.
21912 (In redisplay_internal, the frame title is drawn _before_ the
21913 windows are updated, so the stuff which depends on actual
21914 window contents (such as %l) may fail to render properly, or
21915 even crash emacs.) */
21916 if (mode_line_target
== MODE_LINE_TITLE
)
21920 ptrdiff_t col
= current_column ();
21921 w
->column_number_displayed
= col
;
21922 pint2str (decode_mode_spec_buf
, width
, col
);
21923 return decode_mode_spec_buf
;
21927 #ifndef SYSTEM_MALLOC
21929 if (NILP (Vmemory_full
))
21932 return "!MEM FULL! ";
21939 /* %F displays the frame name. */
21940 if (!NILP (f
->title
))
21941 return SSDATA (f
->title
);
21942 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21943 return SSDATA (f
->name
);
21947 obj
= BVAR (b
, filename
);
21952 ptrdiff_t size
= ZV
- BEGV
;
21953 pint2str (decode_mode_spec_buf
, width
, size
);
21954 return decode_mode_spec_buf
;
21959 ptrdiff_t size
= ZV
- BEGV
;
21960 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21961 return decode_mode_spec_buf
;
21966 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21967 ptrdiff_t topline
, nlines
, height
;
21970 /* %c and %l are ignored in `frame-title-format'. */
21971 if (mode_line_target
== MODE_LINE_TITLE
)
21974 startpos
= marker_position (w
->start
);
21975 startpos_byte
= marker_byte_position (w
->start
);
21976 height
= WINDOW_TOTAL_LINES (w
);
21978 /* If we decided that this buffer isn't suitable for line numbers,
21979 don't forget that too fast. */
21980 if (w
->base_line_pos
== -1)
21983 /* If the buffer is very big, don't waste time. */
21984 if (INTEGERP (Vline_number_display_limit
)
21985 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21987 w
->base_line_pos
= 0;
21988 w
->base_line_number
= 0;
21992 if (w
->base_line_number
> 0
21993 && w
->base_line_pos
> 0
21994 && w
->base_line_pos
<= startpos
)
21996 line
= w
->base_line_number
;
21997 linepos
= w
->base_line_pos
;
21998 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22003 linepos
= BUF_BEGV (b
);
22004 linepos_byte
= BUF_BEGV_BYTE (b
);
22007 /* Count lines from base line to window start position. */
22008 nlines
= display_count_lines (linepos_byte
,
22012 topline
= nlines
+ line
;
22014 /* Determine a new base line, if the old one is too close
22015 or too far away, or if we did not have one.
22016 "Too close" means it's plausible a scroll-down would
22017 go back past it. */
22018 if (startpos
== BUF_BEGV (b
))
22020 w
->base_line_number
= topline
;
22021 w
->base_line_pos
= BUF_BEGV (b
);
22023 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22024 || linepos
== BUF_BEGV (b
))
22026 ptrdiff_t limit
= BUF_BEGV (b
);
22027 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22028 ptrdiff_t position
;
22029 ptrdiff_t distance
=
22030 (height
* 2 + 30) * line_number_display_limit_width
;
22032 if (startpos
- distance
> limit
)
22034 limit
= startpos
- distance
;
22035 limit_byte
= CHAR_TO_BYTE (limit
);
22038 nlines
= display_count_lines (startpos_byte
,
22040 - (height
* 2 + 30),
22042 /* If we couldn't find the lines we wanted within
22043 line_number_display_limit_width chars per line,
22044 give up on line numbers for this window. */
22045 if (position
== limit_byte
&& limit
== startpos
- distance
)
22047 w
->base_line_pos
= -1;
22048 w
->base_line_number
= 0;
22052 w
->base_line_number
= topline
- nlines
;
22053 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22056 /* Now count lines from the start pos to point. */
22057 nlines
= display_count_lines (startpos_byte
,
22058 PT_BYTE
, PT
, &junk
);
22060 /* Record that we did display the line number. */
22061 line_number_displayed
= 1;
22063 /* Make the string to show. */
22064 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22065 return decode_mode_spec_buf
;
22068 char* p
= decode_mode_spec_buf
;
22069 int pad
= width
- 2;
22075 return decode_mode_spec_buf
;
22081 obj
= BVAR (b
, mode_name
);
22085 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22091 ptrdiff_t pos
= marker_position (w
->start
);
22092 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22094 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22096 if (pos
<= BUF_BEGV (b
))
22101 else if (pos
<= BUF_BEGV (b
))
22105 if (total
> 1000000)
22106 /* Do it differently for a large value, to avoid overflow. */
22107 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22109 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22110 /* We can't normally display a 3-digit number,
22111 so get us a 2-digit number that is close. */
22114 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22115 return decode_mode_spec_buf
;
22119 /* Display percentage of size above the bottom of the screen. */
22122 ptrdiff_t toppos
= marker_position (w
->start
);
22123 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22124 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22126 if (botpos
>= BUF_ZV (b
))
22128 if (toppos
<= BUF_BEGV (b
))
22135 if (total
> 1000000)
22136 /* Do it differently for a large value, to avoid overflow. */
22137 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22139 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22140 /* We can't normally display a 3-digit number,
22141 so get us a 2-digit number that is close. */
22144 if (toppos
<= BUF_BEGV (b
))
22145 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22147 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22148 return decode_mode_spec_buf
;
22153 /* status of process */
22154 obj
= Fget_buffer_process (Fcurrent_buffer ());
22156 return "no process";
22158 obj
= Fsymbol_name (Fprocess_status (obj
));
22164 ptrdiff_t count
= inhibit_garbage_collection ();
22165 Lisp_Object val
= call1 (intern ("file-remote-p"),
22166 BVAR (current_buffer
, directory
));
22167 unbind_to (count
, Qnil
);
22176 /* coding-system (not including end-of-line format) */
22178 /* coding-system (including end-of-line type) */
22180 int eol_flag
= (c
== 'Z');
22181 char *p
= decode_mode_spec_buf
;
22183 if (! FRAME_WINDOW_P (f
))
22185 /* No need to mention EOL here--the terminal never needs
22186 to do EOL conversion. */
22187 p
= decode_mode_spec_coding (CODING_ID_NAME
22188 (FRAME_KEYBOARD_CODING (f
)->id
),
22190 p
= decode_mode_spec_coding (CODING_ID_NAME
22191 (FRAME_TERMINAL_CODING (f
)->id
),
22194 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22197 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22198 #ifdef subprocesses
22199 obj
= Fget_buffer_process (Fcurrent_buffer ());
22200 if (PROCESSP (obj
))
22202 p
= decode_mode_spec_coding
22203 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22204 p
= decode_mode_spec_coding
22205 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22207 #endif /* subprocesses */
22210 return decode_mode_spec_buf
;
22217 return SSDATA (obj
);
22224 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22225 means count lines back from START_BYTE. But don't go beyond
22226 LIMIT_BYTE. Return the number of lines thus found (always
22229 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22230 either the position COUNT lines after/before START_BYTE, if we
22231 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22235 display_count_lines (ptrdiff_t start_byte
,
22236 ptrdiff_t limit_byte
, ptrdiff_t count
,
22237 ptrdiff_t *byte_pos_ptr
)
22239 register unsigned char *cursor
;
22240 unsigned char *base
;
22242 register ptrdiff_t ceiling
;
22243 register unsigned char *ceiling_addr
;
22244 ptrdiff_t orig_count
= count
;
22246 /* If we are not in selective display mode,
22247 check only for newlines. */
22248 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22249 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22253 while (start_byte
< limit_byte
)
22255 ceiling
= BUFFER_CEILING_OF (start_byte
);
22256 ceiling
= min (limit_byte
- 1, ceiling
);
22257 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22258 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22262 if (selective_display
)
22264 while (*cursor
!= '\n' && *cursor
!= 015
22265 && ++cursor
!= ceiling_addr
)
22267 if (cursor
== ceiling_addr
)
22272 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22281 start_byte
+= cursor
- base
;
22282 *byte_pos_ptr
= start_byte
;
22286 while (cursor
< ceiling_addr
);
22288 start_byte
+= ceiling_addr
- base
;
22293 while (start_byte
> limit_byte
)
22295 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22296 ceiling
= max (limit_byte
, ceiling
);
22297 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22298 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22301 if (selective_display
)
22303 while (--cursor
>= ceiling_addr
22304 && *cursor
!= '\n' && *cursor
!= 015)
22306 if (cursor
< ceiling_addr
)
22311 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22318 start_byte
+= cursor
- base
+ 1;
22319 *byte_pos_ptr
= start_byte
;
22320 /* When scanning backwards, we should
22321 not count the newline posterior to which we stop. */
22322 return - orig_count
- 1;
22325 start_byte
+= ceiling_addr
- base
;
22329 *byte_pos_ptr
= limit_byte
;
22332 return - orig_count
+ count
;
22333 return orig_count
- count
;
22339 /***********************************************************************
22341 ***********************************************************************/
22343 /* Display a NUL-terminated string, starting with index START.
22345 If STRING is non-null, display that C string. Otherwise, the Lisp
22346 string LISP_STRING is displayed. There's a case that STRING is
22347 non-null and LISP_STRING is not nil. It means STRING is a string
22348 data of LISP_STRING. In that case, we display LISP_STRING while
22349 ignoring its text properties.
22351 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22352 FACE_STRING. Display STRING or LISP_STRING with the face at
22353 FACE_STRING_POS in FACE_STRING:
22355 Display the string in the environment given by IT, but use the
22356 standard display table, temporarily.
22358 FIELD_WIDTH is the minimum number of output glyphs to produce.
22359 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22360 with spaces. If STRING has more characters, more than FIELD_WIDTH
22361 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22363 PRECISION is the maximum number of characters to output from
22364 STRING. PRECISION < 0 means don't truncate the string.
22366 This is roughly equivalent to printf format specifiers:
22368 FIELD_WIDTH PRECISION PRINTF
22369 ----------------------------------------
22375 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22376 display them, and < 0 means obey the current buffer's value of
22377 enable_multibyte_characters.
22379 Value is the number of columns displayed. */
22382 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22383 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22384 int field_width
, int precision
, int max_x
, int multibyte
)
22386 int hpos_at_start
= it
->hpos
;
22387 int saved_face_id
= it
->face_id
;
22388 struct glyph_row
*row
= it
->glyph_row
;
22389 ptrdiff_t it_charpos
;
22391 /* Initialize the iterator IT for iteration over STRING beginning
22392 with index START. */
22393 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22394 precision
, field_width
, multibyte
);
22395 if (string
&& STRINGP (lisp_string
))
22396 /* LISP_STRING is the one returned by decode_mode_spec. We should
22397 ignore its text properties. */
22398 it
->stop_charpos
= it
->end_charpos
;
22400 /* If displaying STRING, set up the face of the iterator from
22401 FACE_STRING, if that's given. */
22402 if (STRINGP (face_string
))
22408 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22409 0, it
->region_beg_charpos
,
22410 it
->region_end_charpos
,
22411 &endptr
, it
->base_face_id
, 0);
22412 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22413 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22416 /* Set max_x to the maximum allowed X position. Don't let it go
22417 beyond the right edge of the window. */
22419 max_x
= it
->last_visible_x
;
22421 max_x
= min (max_x
, it
->last_visible_x
);
22423 /* Skip over display elements that are not visible. because IT->w is
22425 if (it
->current_x
< it
->first_visible_x
)
22426 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22427 MOVE_TO_POS
| MOVE_TO_X
);
22429 row
->ascent
= it
->max_ascent
;
22430 row
->height
= it
->max_ascent
+ it
->max_descent
;
22431 row
->phys_ascent
= it
->max_phys_ascent
;
22432 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22433 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22435 if (STRINGP (it
->string
))
22436 it_charpos
= IT_STRING_CHARPOS (*it
);
22438 it_charpos
= IT_CHARPOS (*it
);
22440 /* This condition is for the case that we are called with current_x
22441 past last_visible_x. */
22442 while (it
->current_x
< max_x
)
22444 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22446 /* Get the next display element. */
22447 if (!get_next_display_element (it
))
22450 /* Produce glyphs. */
22451 x_before
= it
->current_x
;
22452 n_glyphs_before
= row
->used
[TEXT_AREA
];
22453 PRODUCE_GLYPHS (it
);
22455 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22458 while (i
< nglyphs
)
22460 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22462 if (it
->line_wrap
!= TRUNCATE
22463 && x
+ glyph
->pixel_width
> max_x
)
22465 /* End of continued line or max_x reached. */
22466 if (CHAR_GLYPH_PADDING_P (*glyph
))
22468 /* A wide character is unbreakable. */
22469 if (row
->reversed_p
)
22470 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22471 - n_glyphs_before
);
22472 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22473 it
->current_x
= x_before
;
22477 if (row
->reversed_p
)
22478 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22479 - (n_glyphs_before
+ i
));
22480 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22485 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22487 /* Glyph is at least partially visible. */
22489 if (x
< it
->first_visible_x
)
22490 row
->x
= x
- it
->first_visible_x
;
22494 /* Glyph is off the left margin of the display area.
22495 Should not happen. */
22499 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22500 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22501 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22502 row
->phys_height
= max (row
->phys_height
,
22503 it
->max_phys_ascent
+ it
->max_phys_descent
);
22504 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22505 it
->max_extra_line_spacing
);
22506 x
+= glyph
->pixel_width
;
22510 /* Stop if max_x reached. */
22514 /* Stop at line ends. */
22515 if (ITERATOR_AT_END_OF_LINE_P (it
))
22517 it
->continuation_lines_width
= 0;
22521 set_iterator_to_next (it
, 1);
22522 if (STRINGP (it
->string
))
22523 it_charpos
= IT_STRING_CHARPOS (*it
);
22525 it_charpos
= IT_CHARPOS (*it
);
22527 /* Stop if truncating at the right edge. */
22528 if (it
->line_wrap
== TRUNCATE
22529 && it
->current_x
>= it
->last_visible_x
)
22531 /* Add truncation mark, but don't do it if the line is
22532 truncated at a padding space. */
22533 if (it_charpos
< it
->string_nchars
)
22535 if (!FRAME_WINDOW_P (it
->f
))
22539 if (it
->current_x
> it
->last_visible_x
)
22541 if (!row
->reversed_p
)
22543 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22544 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22549 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22550 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22552 unproduce_glyphs (it
, ii
+ 1);
22553 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22555 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22557 row
->used
[TEXT_AREA
] = ii
;
22558 produce_special_glyphs (it
, IT_TRUNCATION
);
22561 produce_special_glyphs (it
, IT_TRUNCATION
);
22563 row
->truncated_on_right_p
= 1;
22569 /* Maybe insert a truncation at the left. */
22570 if (it
->first_visible_x
22573 if (!FRAME_WINDOW_P (it
->f
)
22574 || (row
->reversed_p
22575 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22576 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22577 insert_left_trunc_glyphs (it
);
22578 row
->truncated_on_left_p
= 1;
22581 it
->face_id
= saved_face_id
;
22583 /* Value is number of columns displayed. */
22584 return it
->hpos
- hpos_at_start
;
22589 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22590 appears as an element of LIST or as the car of an element of LIST.
22591 If PROPVAL is a list, compare each element against LIST in that
22592 way, and return 1/2 if any element of PROPVAL is found in LIST.
22593 Otherwise return 0. This function cannot quit.
22594 The return value is 2 if the text is invisible but with an ellipsis
22595 and 1 if it's invisible and without an ellipsis. */
22598 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22600 register Lisp_Object tail
, proptail
;
22602 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22604 register Lisp_Object tem
;
22606 if (EQ (propval
, tem
))
22608 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22609 return NILP (XCDR (tem
)) ? 1 : 2;
22612 if (CONSP (propval
))
22614 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22616 Lisp_Object propelt
;
22617 propelt
= XCAR (proptail
);
22618 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22620 register Lisp_Object tem
;
22622 if (EQ (propelt
, tem
))
22624 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22625 return NILP (XCDR (tem
)) ? 1 : 2;
22633 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22634 doc
: /* Non-nil if the property makes the text invisible.
22635 POS-OR-PROP can be a marker or number, in which case it is taken to be
22636 a position in the current buffer and the value of the `invisible' property
22637 is checked; or it can be some other value, which is then presumed to be the
22638 value of the `invisible' property of the text of interest.
22639 The non-nil value returned can be t for truly invisible text or something
22640 else if the text is replaced by an ellipsis. */)
22641 (Lisp_Object pos_or_prop
)
22644 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22645 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22647 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22648 return (invis
== 0 ? Qnil
22650 : make_number (invis
));
22653 /* Calculate a width or height in pixels from a specification using
22654 the following elements:
22657 NUM - a (fractional) multiple of the default font width/height
22658 (NUM) - specifies exactly NUM pixels
22659 UNIT - a fixed number of pixels, see below.
22660 ELEMENT - size of a display element in pixels, see below.
22661 (NUM . SPEC) - equals NUM * SPEC
22662 (+ SPEC SPEC ...) - add pixel values
22663 (- SPEC SPEC ...) - subtract pixel values
22664 (- SPEC) - negate pixel value
22667 INT or FLOAT - a number constant
22668 SYMBOL - use symbol's (buffer local) variable binding.
22671 in - pixels per inch *)
22672 mm - pixels per 1/1000 meter *)
22673 cm - pixels per 1/100 meter *)
22674 width - width of current font in pixels.
22675 height - height of current font in pixels.
22677 *) using the ratio(s) defined in display-pixels-per-inch.
22681 left-fringe - left fringe width in pixels
22682 right-fringe - right fringe width in pixels
22684 left-margin - left margin width in pixels
22685 right-margin - right margin width in pixels
22687 scroll-bar - scroll-bar area width in pixels
22691 Pixels corresponding to 5 inches:
22694 Total width of non-text areas on left side of window (if scroll-bar is on left):
22695 '(space :width (+ left-fringe left-margin scroll-bar))
22697 Align to first text column (in header line):
22698 '(space :align-to 0)
22700 Align to middle of text area minus half the width of variable `my-image'
22701 containing a loaded image:
22702 '(space :align-to (0.5 . (- text my-image)))
22704 Width of left margin minus width of 1 character in the default font:
22705 '(space :width (- left-margin 1))
22707 Width of left margin minus width of 2 characters in the current font:
22708 '(space :width (- left-margin (2 . width)))
22710 Center 1 character over left-margin (in header line):
22711 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22713 Different ways to express width of left fringe plus left margin minus one pixel:
22714 '(space :width (- (+ left-fringe left-margin) (1)))
22715 '(space :width (+ left-fringe left-margin (- (1))))
22716 '(space :width (+ left-fringe left-margin (-1)))
22721 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22722 struct font
*font
, int width_p
, int *align_to
)
22726 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22727 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22730 return OK_PIXELS (0);
22732 eassert (FRAME_LIVE_P (it
->f
));
22734 if (SYMBOLP (prop
))
22736 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22738 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22740 if (unit
[0] == 'i' && unit
[1] == 'n')
22742 else if (unit
[0] == 'm' && unit
[1] == 'm')
22744 else if (unit
[0] == 'c' && unit
[1] == 'm')
22750 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22751 : FRAME_RES_Y (it
->f
));
22754 return OK_PIXELS (ppi
/ pixels
);
22759 #ifdef HAVE_WINDOW_SYSTEM
22760 if (EQ (prop
, Qheight
))
22761 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22762 if (EQ (prop
, Qwidth
))
22763 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22765 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22766 return OK_PIXELS (1);
22769 if (EQ (prop
, Qtext
))
22770 return OK_PIXELS (width_p
22771 ? window_box_width (it
->w
, TEXT_AREA
)
22772 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22774 if (align_to
&& *align_to
< 0)
22777 if (EQ (prop
, Qleft
))
22778 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22779 if (EQ (prop
, Qright
))
22780 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22781 if (EQ (prop
, Qcenter
))
22782 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22783 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22784 if (EQ (prop
, Qleft_fringe
))
22785 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22786 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22787 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22788 if (EQ (prop
, Qright_fringe
))
22789 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22790 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22791 : window_box_right_offset (it
->w
, TEXT_AREA
));
22792 if (EQ (prop
, Qleft_margin
))
22793 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22794 if (EQ (prop
, Qright_margin
))
22795 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22796 if (EQ (prop
, Qscroll_bar
))
22797 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22799 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22800 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22801 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22806 if (EQ (prop
, Qleft_fringe
))
22807 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22808 if (EQ (prop
, Qright_fringe
))
22809 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22810 if (EQ (prop
, Qleft_margin
))
22811 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22812 if (EQ (prop
, Qright_margin
))
22813 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22814 if (EQ (prop
, Qscroll_bar
))
22815 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22818 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22819 if (EQ (prop
, Qunbound
))
22823 if (INTEGERP (prop
) || FLOATP (prop
))
22825 int base_unit
= (width_p
22826 ? FRAME_COLUMN_WIDTH (it
->f
)
22827 : FRAME_LINE_HEIGHT (it
->f
));
22828 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22833 Lisp_Object car
= XCAR (prop
);
22834 Lisp_Object cdr
= XCDR (prop
);
22838 #ifdef HAVE_WINDOW_SYSTEM
22839 if (FRAME_WINDOW_P (it
->f
)
22840 && valid_image_p (prop
))
22842 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22843 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22845 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22848 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22854 while (CONSP (cdr
))
22856 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22857 font
, width_p
, align_to
))
22860 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22865 if (EQ (car
, Qminus
))
22867 return OK_PIXELS (pixels
);
22870 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22871 if (EQ (car
, Qunbound
))
22875 if (INTEGERP (car
) || FLOATP (car
))
22878 pixels
= XFLOATINT (car
);
22880 return OK_PIXELS (pixels
);
22881 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22882 font
, width_p
, align_to
))
22883 return OK_PIXELS (pixels
* fact
);
22894 /***********************************************************************
22896 ***********************************************************************/
22898 #ifdef HAVE_WINDOW_SYSTEM
22903 dump_glyph_string (struct glyph_string
*s
)
22905 fprintf (stderr
, "glyph string\n");
22906 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22907 s
->x
, s
->y
, s
->width
, s
->height
);
22908 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22909 fprintf (stderr
, " hl = %d\n", s
->hl
);
22910 fprintf (stderr
, " left overhang = %d, right = %d\n",
22911 s
->left_overhang
, s
->right_overhang
);
22912 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22913 fprintf (stderr
, " extends to end of line = %d\n",
22914 s
->extends_to_end_of_line_p
);
22915 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22916 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22919 #endif /* GLYPH_DEBUG */
22921 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22922 of XChar2b structures for S; it can't be allocated in
22923 init_glyph_string because it must be allocated via `alloca'. W
22924 is the window on which S is drawn. ROW and AREA are the glyph row
22925 and area within the row from which S is constructed. START is the
22926 index of the first glyph structure covered by S. HL is a
22927 face-override for drawing S. */
22930 #define OPTIONAL_HDC(hdc) HDC hdc,
22931 #define DECLARE_HDC(hdc) HDC hdc;
22932 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22933 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22936 #ifndef OPTIONAL_HDC
22937 #define OPTIONAL_HDC(hdc)
22938 #define DECLARE_HDC(hdc)
22939 #define ALLOCATE_HDC(hdc, f)
22940 #define RELEASE_HDC(hdc, f)
22944 init_glyph_string (struct glyph_string
*s
,
22946 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22947 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22949 memset (s
, 0, sizeof *s
);
22951 s
->f
= XFRAME (w
->frame
);
22955 s
->display
= FRAME_X_DISPLAY (s
->f
);
22956 s
->window
= FRAME_X_WINDOW (s
->f
);
22957 s
->char2b
= char2b
;
22961 s
->first_glyph
= row
->glyphs
[area
] + start
;
22962 s
->height
= row
->height
;
22963 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22964 s
->ybase
= s
->y
+ row
->ascent
;
22968 /* Append the list of glyph strings with head H and tail T to the list
22969 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22972 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22973 struct glyph_string
*h
, struct glyph_string
*t
)
22987 /* Prepend the list of glyph strings with head H and tail T to the
22988 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22992 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22993 struct glyph_string
*h
, struct glyph_string
*t
)
23007 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23008 Set *HEAD and *TAIL to the resulting list. */
23011 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23012 struct glyph_string
*s
)
23014 s
->next
= s
->prev
= NULL
;
23015 append_glyph_string_lists (head
, tail
, s
, s
);
23019 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23020 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23021 make sure that X resources for the face returned are allocated.
23022 Value is a pointer to a realized face that is ready for display if
23023 DISPLAY_P is non-zero. */
23025 static struct face
*
23026 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23027 XChar2b
*char2b
, int display_p
)
23029 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23034 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23036 if (code
== FONT_INVALID_CODE
)
23039 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23041 /* Make sure X resources of the face are allocated. */
23042 #ifdef HAVE_X_WINDOWS
23046 eassert (face
!= NULL
);
23047 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23054 /* Get face and two-byte form of character glyph GLYPH on frame F.
23055 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23056 a pointer to a realized face that is ready for display. */
23058 static struct face
*
23059 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23060 XChar2b
*char2b
, int *two_byte_p
)
23065 eassert (glyph
->type
== CHAR_GLYPH
);
23066 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23068 /* Make sure X resources of the face are allocated. */
23069 eassert (face
!= NULL
);
23070 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23077 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23078 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23080 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23082 if (code
== FONT_INVALID_CODE
)
23086 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23091 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23092 Return 1 if FONT has a glyph for C, otherwise return 0. */
23095 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23099 if (CHAR_BYTE8_P (c
))
23100 code
= CHAR_TO_BYTE8 (c
);
23102 code
= font
->driver
->encode_char (font
, c
);
23104 if (code
== FONT_INVALID_CODE
)
23106 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23111 /* Fill glyph string S with composition components specified by S->cmp.
23113 BASE_FACE is the base face of the composition.
23114 S->cmp_from is the index of the first component for S.
23116 OVERLAPS non-zero means S should draw the foreground only, and use
23117 its physical height for clipping. See also draw_glyphs.
23119 Value is the index of a component not in S. */
23122 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23126 /* For all glyphs of this composition, starting at the offset
23127 S->cmp_from, until we reach the end of the definition or encounter a
23128 glyph that requires the different face, add it to S. */
23133 s
->for_overlaps
= overlaps
;
23136 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23138 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23140 /* TAB in a composition means display glyphs with padding space
23141 on the left or right. */
23144 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23147 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23154 s
->font
= s
->face
->font
;
23156 else if (s
->face
!= face
)
23164 if (s
->face
== NULL
)
23166 s
->face
= base_face
->ascii_face
;
23167 s
->font
= s
->face
->font
;
23170 /* All glyph strings for the same composition has the same width,
23171 i.e. the width set for the first component of the composition. */
23172 s
->width
= s
->first_glyph
->pixel_width
;
23174 /* If the specified font could not be loaded, use the frame's
23175 default font, but record the fact that we couldn't load it in
23176 the glyph string so that we can draw rectangles for the
23177 characters of the glyph string. */
23178 if (s
->font
== NULL
)
23180 s
->font_not_found_p
= 1;
23181 s
->font
= FRAME_FONT (s
->f
);
23184 /* Adjust base line for subscript/superscript text. */
23185 s
->ybase
+= s
->first_glyph
->voffset
;
23187 /* This glyph string must always be drawn with 16-bit functions. */
23194 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23195 int start
, int end
, int overlaps
)
23197 struct glyph
*glyph
, *last
;
23198 Lisp_Object lgstring
;
23201 s
->for_overlaps
= overlaps
;
23202 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23203 last
= s
->row
->glyphs
[s
->area
] + end
;
23204 s
->cmp_id
= glyph
->u
.cmp
.id
;
23205 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23206 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23207 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23208 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23209 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23211 while (glyph
< last
23212 && glyph
->u
.cmp
.automatic
23213 && glyph
->u
.cmp
.id
== s
->cmp_id
23214 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23215 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23217 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23219 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23220 unsigned code
= LGLYPH_CODE (lglyph
);
23222 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23224 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23225 return glyph
- s
->row
->glyphs
[s
->area
];
23229 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23230 See the comment of fill_glyph_string for arguments.
23231 Value is the index of the first glyph not in S. */
23235 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23236 int start
, int end
, int overlaps
)
23238 struct glyph
*glyph
, *last
;
23241 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23242 s
->for_overlaps
= overlaps
;
23243 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23244 last
= s
->row
->glyphs
[s
->area
] + end
;
23245 voffset
= glyph
->voffset
;
23246 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23247 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23249 s
->width
= glyph
->pixel_width
;
23251 while (glyph
< last
23252 && glyph
->type
== GLYPHLESS_GLYPH
23253 && glyph
->voffset
== voffset
23254 && glyph
->face_id
== face_id
)
23257 s
->width
+= glyph
->pixel_width
;
23260 s
->ybase
+= voffset
;
23261 return glyph
- s
->row
->glyphs
[s
->area
];
23265 /* Fill glyph string S from a sequence of character glyphs.
23267 FACE_ID is the face id of the string. START is the index of the
23268 first glyph to consider, END is the index of the last + 1.
23269 OVERLAPS non-zero means S should draw the foreground only, and use
23270 its physical height for clipping. See also draw_glyphs.
23272 Value is the index of the first glyph not in S. */
23275 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23276 int start
, int end
, int overlaps
)
23278 struct glyph
*glyph
, *last
;
23280 int glyph_not_available_p
;
23282 eassert (s
->f
== XFRAME (s
->w
->frame
));
23283 eassert (s
->nchars
== 0);
23284 eassert (start
>= 0 && end
> start
);
23286 s
->for_overlaps
= overlaps
;
23287 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23288 last
= s
->row
->glyphs
[s
->area
] + end
;
23289 voffset
= glyph
->voffset
;
23290 s
->padding_p
= glyph
->padding_p
;
23291 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23293 while (glyph
< last
23294 && glyph
->type
== CHAR_GLYPH
23295 && glyph
->voffset
== voffset
23296 /* Same face id implies same font, nowadays. */
23297 && glyph
->face_id
== face_id
23298 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23302 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23303 s
->char2b
+ s
->nchars
,
23305 s
->two_byte_p
= two_byte_p
;
23307 eassert (s
->nchars
<= end
- start
);
23308 s
->width
+= glyph
->pixel_width
;
23309 if (glyph
++->padding_p
!= s
->padding_p
)
23313 s
->font
= s
->face
->font
;
23315 /* If the specified font could not be loaded, use the frame's font,
23316 but record the fact that we couldn't load it in
23317 S->font_not_found_p so that we can draw rectangles for the
23318 characters of the glyph string. */
23319 if (s
->font
== NULL
|| glyph_not_available_p
)
23321 s
->font_not_found_p
= 1;
23322 s
->font
= FRAME_FONT (s
->f
);
23325 /* Adjust base line for subscript/superscript text. */
23326 s
->ybase
+= voffset
;
23328 eassert (s
->face
&& s
->face
->gc
);
23329 return glyph
- s
->row
->glyphs
[s
->area
];
23333 /* Fill glyph string S from image glyph S->first_glyph. */
23336 fill_image_glyph_string (struct glyph_string
*s
)
23338 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23339 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23341 s
->slice
= s
->first_glyph
->slice
.img
;
23342 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23343 s
->font
= s
->face
->font
;
23344 s
->width
= s
->first_glyph
->pixel_width
;
23346 /* Adjust base line for subscript/superscript text. */
23347 s
->ybase
+= s
->first_glyph
->voffset
;
23351 /* Fill glyph string S from a sequence of stretch glyphs.
23353 START is the index of the first glyph to consider,
23354 END is the index of the last + 1.
23356 Value is the index of the first glyph not in S. */
23359 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23361 struct glyph
*glyph
, *last
;
23362 int voffset
, face_id
;
23364 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23366 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23367 last
= s
->row
->glyphs
[s
->area
] + end
;
23368 face_id
= glyph
->face_id
;
23369 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23370 s
->font
= s
->face
->font
;
23371 s
->width
= glyph
->pixel_width
;
23373 voffset
= glyph
->voffset
;
23377 && glyph
->type
== STRETCH_GLYPH
23378 && glyph
->voffset
== voffset
23379 && glyph
->face_id
== face_id
);
23381 s
->width
+= glyph
->pixel_width
;
23383 /* Adjust base line for subscript/superscript text. */
23384 s
->ybase
+= voffset
;
23386 /* The case that face->gc == 0 is handled when drawing the glyph
23387 string by calling PREPARE_FACE_FOR_DISPLAY. */
23389 return glyph
- s
->row
->glyphs
[s
->area
];
23392 static struct font_metrics
*
23393 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23395 static struct font_metrics metrics
;
23400 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23401 if (code
== FONT_INVALID_CODE
)
23403 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23408 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23409 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23410 assumed to be zero. */
23413 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23415 *left
= *right
= 0;
23417 if (glyph
->type
== CHAR_GLYPH
)
23421 struct font_metrics
*pcm
;
23423 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23424 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23426 if (pcm
->rbearing
> pcm
->width
)
23427 *right
= pcm
->rbearing
- pcm
->width
;
23428 if (pcm
->lbearing
< 0)
23429 *left
= -pcm
->lbearing
;
23432 else if (glyph
->type
== COMPOSITE_GLYPH
)
23434 if (! glyph
->u
.cmp
.automatic
)
23436 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23438 if (cmp
->rbearing
> cmp
->pixel_width
)
23439 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23440 if (cmp
->lbearing
< 0)
23441 *left
= - cmp
->lbearing
;
23445 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23446 struct font_metrics metrics
;
23448 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23449 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23450 if (metrics
.rbearing
> metrics
.width
)
23451 *right
= metrics
.rbearing
- metrics
.width
;
23452 if (metrics
.lbearing
< 0)
23453 *left
= - metrics
.lbearing
;
23459 /* Return the index of the first glyph preceding glyph string S that
23460 is overwritten by S because of S's left overhang. Value is -1
23461 if no glyphs are overwritten. */
23464 left_overwritten (struct glyph_string
*s
)
23468 if (s
->left_overhang
)
23471 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23472 int first
= s
->first_glyph
- glyphs
;
23474 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23475 x
-= glyphs
[i
].pixel_width
;
23486 /* Return the index of the first glyph preceding glyph string S that
23487 is overwriting S because of its right overhang. Value is -1 if no
23488 glyph in front of S overwrites S. */
23491 left_overwriting (struct glyph_string
*s
)
23494 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23495 int first
= s
->first_glyph
- glyphs
;
23499 for (i
= first
- 1; i
>= 0; --i
)
23502 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23505 x
-= glyphs
[i
].pixel_width
;
23512 /* Return the index of the last glyph following glyph string S that is
23513 overwritten by S because of S's right overhang. Value is -1 if
23514 no such glyph is found. */
23517 right_overwritten (struct glyph_string
*s
)
23521 if (s
->right_overhang
)
23524 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23525 int first
= (s
->first_glyph
- glyphs
23526 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23527 int end
= s
->row
->used
[s
->area
];
23529 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23530 x
+= glyphs
[i
].pixel_width
;
23539 /* Return the index of the last glyph following glyph string S that
23540 overwrites S because of its left overhang. Value is negative
23541 if no such glyph is found. */
23544 right_overwriting (struct glyph_string
*s
)
23547 int end
= s
->row
->used
[s
->area
];
23548 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23549 int first
= (s
->first_glyph
- glyphs
23550 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23554 for (i
= first
; i
< end
; ++i
)
23557 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23560 x
+= glyphs
[i
].pixel_width
;
23567 /* Set background width of glyph string S. START is the index of the
23568 first glyph following S. LAST_X is the right-most x-position + 1
23569 in the drawing area. */
23572 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23574 /* If the face of this glyph string has to be drawn to the end of
23575 the drawing area, set S->extends_to_end_of_line_p. */
23577 if (start
== s
->row
->used
[s
->area
]
23578 && s
->area
== TEXT_AREA
23579 && ((s
->row
->fill_line_p
23580 && (s
->hl
== DRAW_NORMAL_TEXT
23581 || s
->hl
== DRAW_IMAGE_RAISED
23582 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23583 || s
->hl
== DRAW_MOUSE_FACE
))
23584 s
->extends_to_end_of_line_p
= 1;
23586 /* If S extends its face to the end of the line, set its
23587 background_width to the distance to the right edge of the drawing
23589 if (s
->extends_to_end_of_line_p
)
23590 s
->background_width
= last_x
- s
->x
+ 1;
23592 s
->background_width
= s
->width
;
23596 /* Compute overhangs and x-positions for glyph string S and its
23597 predecessors, or successors. X is the starting x-position for S.
23598 BACKWARD_P non-zero means process predecessors. */
23601 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23607 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23608 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23618 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23619 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23629 /* The following macros are only called from draw_glyphs below.
23630 They reference the following parameters of that function directly:
23631 `w', `row', `area', and `overlap_p'
23632 as well as the following local variables:
23633 `s', `f', and `hdc' (in W32) */
23636 /* On W32, silently add local `hdc' variable to argument list of
23637 init_glyph_string. */
23638 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23639 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23641 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23642 init_glyph_string (s, char2b, w, row, area, start, hl)
23645 /* Add a glyph string for a stretch glyph to the list of strings
23646 between HEAD and TAIL. START is the index of the stretch glyph in
23647 row area AREA of glyph row ROW. END is the index of the last glyph
23648 in that glyph row area. X is the current output position assigned
23649 to the new glyph string constructed. HL overrides that face of the
23650 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23651 is the right-most x-position of the drawing area. */
23653 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23654 and below -- keep them on one line. */
23655 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23658 s = alloca (sizeof *s); \
23659 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23660 START = fill_stretch_glyph_string (s, START, END); \
23661 append_glyph_string (&HEAD, &TAIL, s); \
23667 /* Add a glyph string for an image glyph to the list of strings
23668 between HEAD and TAIL. START is the index of the image glyph in
23669 row area AREA of glyph row ROW. END is the index of the last glyph
23670 in that glyph row area. X is the current output position assigned
23671 to the new glyph string constructed. HL overrides that face of the
23672 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23673 is the right-most x-position of the drawing area. */
23675 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23678 s = alloca (sizeof *s); \
23679 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23680 fill_image_glyph_string (s); \
23681 append_glyph_string (&HEAD, &TAIL, s); \
23688 /* Add a glyph string for a sequence of character glyphs to the list
23689 of strings between HEAD and TAIL. START is the index of the first
23690 glyph in row area AREA of glyph row ROW that is part of the new
23691 glyph string. END is the index of the last glyph in that glyph row
23692 area. X is the current output position assigned to the new glyph
23693 string constructed. HL overrides that face of the glyph; e.g. it
23694 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23695 right-most x-position of the drawing area. */
23697 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23703 face_id = (row)->glyphs[area][START].face_id; \
23705 s = alloca (sizeof *s); \
23706 char2b = alloca ((END - START) * sizeof *char2b); \
23707 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23708 append_glyph_string (&HEAD, &TAIL, s); \
23710 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23715 /* Add a glyph string for a composite sequence to the list of strings
23716 between HEAD and TAIL. START is the index of the first glyph in
23717 row area AREA of glyph row ROW that is part of the new glyph
23718 string. END is the index of the last glyph in that glyph row area.
23719 X is the current output position assigned to the new glyph string
23720 constructed. HL overrides that face of the glyph; e.g. it is
23721 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23722 x-position of the drawing area. */
23724 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23726 int face_id = (row)->glyphs[area][START].face_id; \
23727 struct face *base_face = FACE_FROM_ID (f, face_id); \
23728 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23729 struct composition *cmp = composition_table[cmp_id]; \
23731 struct glyph_string *first_s = NULL; \
23734 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23736 /* Make glyph_strings for each glyph sequence that is drawable by \
23737 the same face, and append them to HEAD/TAIL. */ \
23738 for (n = 0; n < cmp->glyph_len;) \
23740 s = alloca (sizeof *s); \
23741 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23742 append_glyph_string (&(HEAD), &(TAIL), s); \
23748 n = fill_composite_glyph_string (s, base_face, overlaps); \
23756 /* Add a glyph string for a glyph-string sequence to the list of strings
23757 between HEAD and TAIL. */
23759 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23763 Lisp_Object gstring; \
23765 face_id = (row)->glyphs[area][START].face_id; \
23766 gstring = (composition_gstring_from_id \
23767 ((row)->glyphs[area][START].u.cmp.id)); \
23768 s = alloca (sizeof *s); \
23769 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23770 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23771 append_glyph_string (&(HEAD), &(TAIL), s); \
23773 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23777 /* Add a glyph string for a sequence of glyphless character's glyphs
23778 to the list of strings between HEAD and TAIL. The meanings of
23779 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23781 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23786 face_id = (row)->glyphs[area][START].face_id; \
23788 s = alloca (sizeof *s); \
23789 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23790 append_glyph_string (&HEAD, &TAIL, s); \
23792 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23798 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23799 of AREA of glyph row ROW on window W between indices START and END.
23800 HL overrides the face for drawing glyph strings, e.g. it is
23801 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23802 x-positions of the drawing area.
23804 This is an ugly monster macro construct because we must use alloca
23805 to allocate glyph strings (because draw_glyphs can be called
23806 asynchronously). */
23808 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23811 HEAD = TAIL = NULL; \
23812 while (START < END) \
23814 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23815 switch (first_glyph->type) \
23818 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23822 case COMPOSITE_GLYPH: \
23823 if (first_glyph->u.cmp.automatic) \
23824 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23827 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23831 case STRETCH_GLYPH: \
23832 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23836 case IMAGE_GLYPH: \
23837 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23841 case GLYPHLESS_GLYPH: \
23842 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23852 set_glyph_string_background_width (s, START, LAST_X); \
23859 /* Draw glyphs between START and END in AREA of ROW on window W,
23860 starting at x-position X. X is relative to AREA in W. HL is a
23861 face-override with the following meaning:
23863 DRAW_NORMAL_TEXT draw normally
23864 DRAW_CURSOR draw in cursor face
23865 DRAW_MOUSE_FACE draw in mouse face.
23866 DRAW_INVERSE_VIDEO draw in mode line face
23867 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23868 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23870 If OVERLAPS is non-zero, draw only the foreground of characters and
23871 clip to the physical height of ROW. Non-zero value also defines
23872 the overlapping part to be drawn:
23874 OVERLAPS_PRED overlap with preceding rows
23875 OVERLAPS_SUCC overlap with succeeding rows
23876 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23877 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23879 Value is the x-position reached, relative to AREA of W. */
23882 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23883 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23884 enum draw_glyphs_face hl
, int overlaps
)
23886 struct glyph_string
*head
, *tail
;
23887 struct glyph_string
*s
;
23888 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23889 int i
, j
, x_reached
, last_x
, area_left
= 0;
23890 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23893 ALLOCATE_HDC (hdc
, f
);
23895 /* Let's rather be paranoid than getting a SEGV. */
23896 end
= min (end
, row
->used
[area
]);
23897 start
= clip_to_bounds (0, start
, end
);
23899 /* Translate X to frame coordinates. Set last_x to the right
23900 end of the drawing area. */
23901 if (row
->full_width_p
)
23903 /* X is relative to the left edge of W, without scroll bars
23905 area_left
= WINDOW_LEFT_EDGE_X (w
);
23906 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23910 area_left
= window_box_left (w
, area
);
23911 last_x
= area_left
+ window_box_width (w
, area
);
23915 /* Build a doubly-linked list of glyph_string structures between
23916 head and tail from what we have to draw. Note that the macro
23917 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23918 the reason we use a separate variable `i'. */
23920 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23922 x_reached
= tail
->x
+ tail
->background_width
;
23926 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23927 the row, redraw some glyphs in front or following the glyph
23928 strings built above. */
23929 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23931 struct glyph_string
*h
, *t
;
23932 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23933 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23934 int check_mouse_face
= 0;
23937 /* If mouse highlighting is on, we may need to draw adjacent
23938 glyphs using mouse-face highlighting. */
23939 if (area
== TEXT_AREA
&& row
->mouse_face_p
23940 && hlinfo
->mouse_face_beg_row
>= 0
23941 && hlinfo
->mouse_face_end_row
>= 0)
23943 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23945 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23946 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23948 check_mouse_face
= 1;
23949 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23950 ? hlinfo
->mouse_face_beg_col
: 0;
23951 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23952 ? hlinfo
->mouse_face_end_col
23953 : row
->used
[TEXT_AREA
];
23957 /* Compute overhangs for all glyph strings. */
23958 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23959 for (s
= head
; s
; s
= s
->next
)
23960 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23962 /* Prepend glyph strings for glyphs in front of the first glyph
23963 string that are overwritten because of the first glyph
23964 string's left overhang. The background of all strings
23965 prepended must be drawn because the first glyph string
23967 i
= left_overwritten (head
);
23970 enum draw_glyphs_face overlap_hl
;
23972 /* If this row contains mouse highlighting, attempt to draw
23973 the overlapped glyphs with the correct highlight. This
23974 code fails if the overlap encompasses more than one glyph
23975 and mouse-highlight spans only some of these glyphs.
23976 However, making it work perfectly involves a lot more
23977 code, and I don't know if the pathological case occurs in
23978 practice, so we'll stick to this for now. --- cyd */
23979 if (check_mouse_face
23980 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23981 overlap_hl
= DRAW_MOUSE_FACE
;
23983 overlap_hl
= DRAW_NORMAL_TEXT
;
23986 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23987 overlap_hl
, dummy_x
, last_x
);
23989 compute_overhangs_and_x (t
, head
->x
, 1);
23990 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23994 /* Prepend glyph strings for glyphs in front of the first glyph
23995 string that overwrite that glyph string because of their
23996 right overhang. For these strings, only the foreground must
23997 be drawn, because it draws over the glyph string at `head'.
23998 The background must not be drawn because this would overwrite
23999 right overhangs of preceding glyphs for which no glyph
24001 i
= left_overwriting (head
);
24004 enum draw_glyphs_face overlap_hl
;
24006 if (check_mouse_face
24007 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24008 overlap_hl
= DRAW_MOUSE_FACE
;
24010 overlap_hl
= DRAW_NORMAL_TEXT
;
24013 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24014 overlap_hl
, dummy_x
, last_x
);
24015 for (s
= h
; s
; s
= s
->next
)
24016 s
->background_filled_p
= 1;
24017 compute_overhangs_and_x (t
, head
->x
, 1);
24018 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24021 /* Append glyphs strings for glyphs following the last glyph
24022 string tail that are overwritten by tail. The background of
24023 these strings has to be drawn because tail's foreground draws
24025 i
= right_overwritten (tail
);
24028 enum draw_glyphs_face overlap_hl
;
24030 if (check_mouse_face
24031 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24032 overlap_hl
= DRAW_MOUSE_FACE
;
24034 overlap_hl
= DRAW_NORMAL_TEXT
;
24036 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24037 overlap_hl
, x
, last_x
);
24038 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24039 we don't have `end = i;' here. */
24040 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24041 append_glyph_string_lists (&head
, &tail
, h
, t
);
24045 /* Append glyph strings for glyphs following the last glyph
24046 string tail that overwrite tail. The foreground of such
24047 glyphs has to be drawn because it writes into the background
24048 of tail. The background must not be drawn because it could
24049 paint over the foreground of following glyphs. */
24050 i
= right_overwriting (tail
);
24053 enum draw_glyphs_face overlap_hl
;
24054 if (check_mouse_face
24055 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24056 overlap_hl
= DRAW_MOUSE_FACE
;
24058 overlap_hl
= DRAW_NORMAL_TEXT
;
24061 i
++; /* We must include the Ith glyph. */
24062 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24063 overlap_hl
, x
, last_x
);
24064 for (s
= h
; s
; s
= s
->next
)
24065 s
->background_filled_p
= 1;
24066 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24067 append_glyph_string_lists (&head
, &tail
, h
, t
);
24069 if (clip_head
|| clip_tail
)
24070 for (s
= head
; s
; s
= s
->next
)
24072 s
->clip_head
= clip_head
;
24073 s
->clip_tail
= clip_tail
;
24077 /* Draw all strings. */
24078 for (s
= head
; s
; s
= s
->next
)
24079 FRAME_RIF (f
)->draw_glyph_string (s
);
24082 /* When focus a sole frame and move horizontally, this sets on_p to 0
24083 causing a failure to erase prev cursor position. */
24084 if (area
== TEXT_AREA
24085 && !row
->full_width_p
24086 /* When drawing overlapping rows, only the glyph strings'
24087 foreground is drawn, which doesn't erase a cursor
24091 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24092 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24093 : (tail
? tail
->x
+ tail
->background_width
: x
));
24097 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24098 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24102 /* Value is the x-position up to which drawn, relative to AREA of W.
24103 This doesn't include parts drawn because of overhangs. */
24104 if (row
->full_width_p
)
24105 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24107 x_reached
-= area_left
;
24109 RELEASE_HDC (hdc
, f
);
24114 /* Expand row matrix if too narrow. Don't expand if area
24117 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24119 if (!it->f->fonts_changed \
24120 && (it->glyph_row->glyphs[area] \
24121 < it->glyph_row->glyphs[area + 1])) \
24123 it->w->ncols_scale_factor++; \
24124 it->f->fonts_changed = 1; \
24128 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24129 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24132 append_glyph (struct it
*it
)
24134 struct glyph
*glyph
;
24135 enum glyph_row_area area
= it
->area
;
24137 eassert (it
->glyph_row
);
24138 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24140 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24141 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24143 /* If the glyph row is reversed, we need to prepend the glyph
24144 rather than append it. */
24145 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24149 /* Make room for the additional glyph. */
24150 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24152 glyph
= it
->glyph_row
->glyphs
[area
];
24154 glyph
->charpos
= CHARPOS (it
->position
);
24155 glyph
->object
= it
->object
;
24156 if (it
->pixel_width
> 0)
24158 glyph
->pixel_width
= it
->pixel_width
;
24159 glyph
->padding_p
= 0;
24163 /* Assure at least 1-pixel width. Otherwise, cursor can't
24164 be displayed correctly. */
24165 glyph
->pixel_width
= 1;
24166 glyph
->padding_p
= 1;
24168 glyph
->ascent
= it
->ascent
;
24169 glyph
->descent
= it
->descent
;
24170 glyph
->voffset
= it
->voffset
;
24171 glyph
->type
= CHAR_GLYPH
;
24172 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24173 glyph
->multibyte_p
= it
->multibyte_p
;
24174 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24176 /* In R2L rows, the left and the right box edges need to be
24177 drawn in reverse direction. */
24178 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24179 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24183 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24184 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24186 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24187 || it
->phys_descent
> it
->descent
);
24188 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24189 glyph
->face_id
= it
->face_id
;
24190 glyph
->u
.ch
= it
->char_to_display
;
24191 glyph
->slice
.img
= null_glyph_slice
;
24192 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24195 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24196 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24198 glyph
->bidi_type
= it
->bidi_it
.type
;
24202 glyph
->resolved_level
= 0;
24203 glyph
->bidi_type
= UNKNOWN_BT
;
24205 ++it
->glyph_row
->used
[area
];
24208 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24211 /* Store one glyph for the composition IT->cmp_it.id in
24212 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24216 append_composite_glyph (struct it
*it
)
24218 struct glyph
*glyph
;
24219 enum glyph_row_area area
= it
->area
;
24221 eassert (it
->glyph_row
);
24223 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24224 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24226 /* If the glyph row is reversed, we need to prepend the glyph
24227 rather than append it. */
24228 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24232 /* Make room for the new glyph. */
24233 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24235 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24237 glyph
->charpos
= it
->cmp_it
.charpos
;
24238 glyph
->object
= it
->object
;
24239 glyph
->pixel_width
= it
->pixel_width
;
24240 glyph
->ascent
= it
->ascent
;
24241 glyph
->descent
= it
->descent
;
24242 glyph
->voffset
= it
->voffset
;
24243 glyph
->type
= COMPOSITE_GLYPH
;
24244 if (it
->cmp_it
.ch
< 0)
24246 glyph
->u
.cmp
.automatic
= 0;
24247 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24248 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24252 glyph
->u
.cmp
.automatic
= 1;
24253 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24254 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24255 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24257 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24258 glyph
->multibyte_p
= it
->multibyte_p
;
24259 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24261 /* In R2L rows, the left and the right box edges need to be
24262 drawn in reverse direction. */
24263 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24264 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24268 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24269 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24271 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24272 || it
->phys_descent
> it
->descent
);
24273 glyph
->padding_p
= 0;
24274 glyph
->glyph_not_available_p
= 0;
24275 glyph
->face_id
= it
->face_id
;
24276 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24279 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24280 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24282 glyph
->bidi_type
= it
->bidi_it
.type
;
24284 ++it
->glyph_row
->used
[area
];
24287 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24291 /* Change IT->ascent and IT->height according to the setting of
24295 take_vertical_position_into_account (struct it
*it
)
24299 if (it
->voffset
< 0)
24300 /* Increase the ascent so that we can display the text higher
24302 it
->ascent
-= it
->voffset
;
24304 /* Increase the descent so that we can display the text lower
24306 it
->descent
+= it
->voffset
;
24311 /* Produce glyphs/get display metrics for the image IT is loaded with.
24312 See the description of struct display_iterator in dispextern.h for
24313 an overview of struct display_iterator. */
24316 produce_image_glyph (struct it
*it
)
24320 int glyph_ascent
, crop
;
24321 struct glyph_slice slice
;
24323 eassert (it
->what
== IT_IMAGE
);
24325 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24327 /* Make sure X resources of the face is loaded. */
24328 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24330 if (it
->image_id
< 0)
24332 /* Fringe bitmap. */
24333 it
->ascent
= it
->phys_ascent
= 0;
24334 it
->descent
= it
->phys_descent
= 0;
24335 it
->pixel_width
= 0;
24340 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24342 /* Make sure X resources of the image is loaded. */
24343 prepare_image_for_display (it
->f
, img
);
24345 slice
.x
= slice
.y
= 0;
24346 slice
.width
= img
->width
;
24347 slice
.height
= img
->height
;
24349 if (INTEGERP (it
->slice
.x
))
24350 slice
.x
= XINT (it
->slice
.x
);
24351 else if (FLOATP (it
->slice
.x
))
24352 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24354 if (INTEGERP (it
->slice
.y
))
24355 slice
.y
= XINT (it
->slice
.y
);
24356 else if (FLOATP (it
->slice
.y
))
24357 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24359 if (INTEGERP (it
->slice
.width
))
24360 slice
.width
= XINT (it
->slice
.width
);
24361 else if (FLOATP (it
->slice
.width
))
24362 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24364 if (INTEGERP (it
->slice
.height
))
24365 slice
.height
= XINT (it
->slice
.height
);
24366 else if (FLOATP (it
->slice
.height
))
24367 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24369 if (slice
.x
>= img
->width
)
24370 slice
.x
= img
->width
;
24371 if (slice
.y
>= img
->height
)
24372 slice
.y
= img
->height
;
24373 if (slice
.x
+ slice
.width
>= img
->width
)
24374 slice
.width
= img
->width
- slice
.x
;
24375 if (slice
.y
+ slice
.height
> img
->height
)
24376 slice
.height
= img
->height
- slice
.y
;
24378 if (slice
.width
== 0 || slice
.height
== 0)
24381 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24383 it
->descent
= slice
.height
- glyph_ascent
;
24385 it
->descent
+= img
->vmargin
;
24386 if (slice
.y
+ slice
.height
== img
->height
)
24387 it
->descent
+= img
->vmargin
;
24388 it
->phys_descent
= it
->descent
;
24390 it
->pixel_width
= slice
.width
;
24392 it
->pixel_width
+= img
->hmargin
;
24393 if (slice
.x
+ slice
.width
== img
->width
)
24394 it
->pixel_width
+= img
->hmargin
;
24396 /* It's quite possible for images to have an ascent greater than
24397 their height, so don't get confused in that case. */
24398 if (it
->descent
< 0)
24403 if (face
->box
!= FACE_NO_BOX
)
24405 if (face
->box_line_width
> 0)
24408 it
->ascent
+= face
->box_line_width
;
24409 if (slice
.y
+ slice
.height
== img
->height
)
24410 it
->descent
+= face
->box_line_width
;
24413 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24414 it
->pixel_width
+= eabs (face
->box_line_width
);
24415 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24416 it
->pixel_width
+= eabs (face
->box_line_width
);
24419 take_vertical_position_into_account (it
);
24421 /* Automatically crop wide image glyphs at right edge so we can
24422 draw the cursor on same display row. */
24423 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24424 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24426 it
->pixel_width
-= crop
;
24427 slice
.width
-= crop
;
24432 struct glyph
*glyph
;
24433 enum glyph_row_area area
= it
->area
;
24435 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24436 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24438 glyph
->charpos
= CHARPOS (it
->position
);
24439 glyph
->object
= it
->object
;
24440 glyph
->pixel_width
= it
->pixel_width
;
24441 glyph
->ascent
= glyph_ascent
;
24442 glyph
->descent
= it
->descent
;
24443 glyph
->voffset
= it
->voffset
;
24444 glyph
->type
= IMAGE_GLYPH
;
24445 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24446 glyph
->multibyte_p
= it
->multibyte_p
;
24447 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24449 /* In R2L rows, the left and the right box edges need to be
24450 drawn in reverse direction. */
24451 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24452 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24456 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24457 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24459 glyph
->overlaps_vertically_p
= 0;
24460 glyph
->padding_p
= 0;
24461 glyph
->glyph_not_available_p
= 0;
24462 glyph
->face_id
= it
->face_id
;
24463 glyph
->u
.img_id
= img
->id
;
24464 glyph
->slice
.img
= slice
;
24465 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24468 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24469 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24471 glyph
->bidi_type
= it
->bidi_it
.type
;
24473 ++it
->glyph_row
->used
[area
];
24476 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24481 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24482 of the glyph, WIDTH and HEIGHT are the width and height of the
24483 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24486 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24487 int width
, int height
, int ascent
)
24489 struct glyph
*glyph
;
24490 enum glyph_row_area area
= it
->area
;
24492 eassert (ascent
>= 0 && ascent
<= height
);
24494 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24495 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24497 /* If the glyph row is reversed, we need to prepend the glyph
24498 rather than append it. */
24499 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24503 /* Make room for the additional glyph. */
24504 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24506 glyph
= it
->glyph_row
->glyphs
[area
];
24508 glyph
->charpos
= CHARPOS (it
->position
);
24509 glyph
->object
= object
;
24510 glyph
->pixel_width
= width
;
24511 glyph
->ascent
= ascent
;
24512 glyph
->descent
= height
- ascent
;
24513 glyph
->voffset
= it
->voffset
;
24514 glyph
->type
= STRETCH_GLYPH
;
24515 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24516 glyph
->multibyte_p
= it
->multibyte_p
;
24517 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24519 /* In R2L rows, the left and the right box edges need to be
24520 drawn in reverse direction. */
24521 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24522 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24526 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24527 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24529 glyph
->overlaps_vertically_p
= 0;
24530 glyph
->padding_p
= 0;
24531 glyph
->glyph_not_available_p
= 0;
24532 glyph
->face_id
= it
->face_id
;
24533 glyph
->u
.stretch
.ascent
= ascent
;
24534 glyph
->u
.stretch
.height
= height
;
24535 glyph
->slice
.img
= null_glyph_slice
;
24536 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24539 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24540 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24542 glyph
->bidi_type
= it
->bidi_it
.type
;
24546 glyph
->resolved_level
= 0;
24547 glyph
->bidi_type
= UNKNOWN_BT
;
24549 ++it
->glyph_row
->used
[area
];
24552 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24555 #endif /* HAVE_WINDOW_SYSTEM */
24557 /* Produce a stretch glyph for iterator IT. IT->object is the value
24558 of the glyph property displayed. The value must be a list
24559 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24562 1. `:width WIDTH' specifies that the space should be WIDTH *
24563 canonical char width wide. WIDTH may be an integer or floating
24566 2. `:relative-width FACTOR' specifies that the width of the stretch
24567 should be computed from the width of the first character having the
24568 `glyph' property, and should be FACTOR times that width.
24570 3. `:align-to HPOS' specifies that the space should be wide enough
24571 to reach HPOS, a value in canonical character units.
24573 Exactly one of the above pairs must be present.
24575 4. `:height HEIGHT' specifies that the height of the stretch produced
24576 should be HEIGHT, measured in canonical character units.
24578 5. `:relative-height FACTOR' specifies that the height of the
24579 stretch should be FACTOR times the height of the characters having
24580 the glyph property.
24582 Either none or exactly one of 4 or 5 must be present.
24584 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24585 of the stretch should be used for the ascent of the stretch.
24586 ASCENT must be in the range 0 <= ASCENT <= 100. */
24589 produce_stretch_glyph (struct it
*it
)
24591 /* (space :width WIDTH :height HEIGHT ...) */
24592 Lisp_Object prop
, plist
;
24593 int width
= 0, height
= 0, align_to
= -1;
24594 int zero_width_ok_p
= 0;
24596 struct font
*font
= NULL
;
24598 #ifdef HAVE_WINDOW_SYSTEM
24600 int zero_height_ok_p
= 0;
24602 if (FRAME_WINDOW_P (it
->f
))
24604 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24605 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24606 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24610 /* List should start with `space'. */
24611 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24612 plist
= XCDR (it
->object
);
24614 /* Compute the width of the stretch. */
24615 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24616 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24618 /* Absolute width `:width WIDTH' specified and valid. */
24619 zero_width_ok_p
= 1;
24622 #ifdef HAVE_WINDOW_SYSTEM
24623 else if (FRAME_WINDOW_P (it
->f
)
24624 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24626 /* Relative width `:relative-width FACTOR' specified and valid.
24627 Compute the width of the characters having the `glyph'
24630 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24633 if (it
->multibyte_p
)
24634 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24637 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24638 if (! ASCII_CHAR_P (it2
.c
))
24639 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24642 it2
.glyph_row
= NULL
;
24643 it2
.what
= IT_CHARACTER
;
24644 x_produce_glyphs (&it2
);
24645 width
= NUMVAL (prop
) * it2
.pixel_width
;
24647 #endif /* HAVE_WINDOW_SYSTEM */
24648 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24649 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24651 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24652 align_to
= (align_to
< 0
24654 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24655 else if (align_to
< 0)
24656 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24657 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24658 zero_width_ok_p
= 1;
24661 /* Nothing specified -> width defaults to canonical char width. */
24662 width
= FRAME_COLUMN_WIDTH (it
->f
);
24664 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24667 #ifdef HAVE_WINDOW_SYSTEM
24668 /* Compute height. */
24669 if (FRAME_WINDOW_P (it
->f
))
24671 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24672 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24675 zero_height_ok_p
= 1;
24677 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24679 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24681 height
= FONT_HEIGHT (font
);
24683 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24686 /* Compute percentage of height used for ascent. If
24687 `:ascent ASCENT' is present and valid, use that. Otherwise,
24688 derive the ascent from the font in use. */
24689 if (prop
= Fplist_get (plist
, QCascent
),
24690 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24691 ascent
= height
* NUMVAL (prop
) / 100.0;
24692 else if (!NILP (prop
)
24693 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24694 ascent
= min (max (0, (int)tem
), height
);
24696 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24699 #endif /* HAVE_WINDOW_SYSTEM */
24702 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24703 && it
->current_x
+ width
> it
->last_visible_x
)
24705 width
= it
->last_visible_x
- it
->current_x
;
24706 #ifdef HAVE_WINDOW_SYSTEM
24707 /* Subtract one more pixel from the stretch width, but only on
24708 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24709 width
-= FRAME_WINDOW_P (it
->f
);
24713 if (width
> 0 && height
> 0 && it
->glyph_row
)
24715 Lisp_Object o_object
= it
->object
;
24716 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24719 if (!STRINGP (object
))
24720 object
= it
->w
->contents
;
24721 #ifdef HAVE_WINDOW_SYSTEM
24722 if (FRAME_WINDOW_P (it
->f
))
24723 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24727 it
->object
= object
;
24728 it
->char_to_display
= ' ';
24729 it
->pixel_width
= it
->len
= 1;
24731 tty_append_glyph (it
);
24732 it
->object
= o_object
;
24736 it
->pixel_width
= width
;
24737 #ifdef HAVE_WINDOW_SYSTEM
24738 if (FRAME_WINDOW_P (it
->f
))
24740 it
->ascent
= it
->phys_ascent
= ascent
;
24741 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24742 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24743 take_vertical_position_into_account (it
);
24747 it
->nglyphs
= width
;
24750 /* Get information about special display element WHAT in an
24751 environment described by IT. WHAT is one of IT_TRUNCATION or
24752 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24753 non-null glyph_row member. This function ensures that fields like
24754 face_id, c, len of IT are left untouched. */
24757 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24764 temp_it
.object
= make_number (0);
24765 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24767 if (what
== IT_CONTINUATION
)
24769 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24770 if (it
->bidi_it
.paragraph_dir
== R2L
)
24771 SET_GLYPH_FROM_CHAR (glyph
, '/');
24773 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24775 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24777 /* FIXME: Should we mirror GC for R2L lines? */
24778 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24779 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24782 else if (what
== IT_TRUNCATION
)
24784 /* Truncation glyph. */
24785 SET_GLYPH_FROM_CHAR (glyph
, '$');
24787 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24789 /* FIXME: Should we mirror GC for R2L lines? */
24790 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24791 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24797 #ifdef HAVE_WINDOW_SYSTEM
24798 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24799 is turned off, we precede the truncation/continuation glyphs by a
24800 stretch glyph whose width is computed such that these special
24801 glyphs are aligned at the window margin, even when very different
24802 fonts are used in different glyph rows. */
24803 if (FRAME_WINDOW_P (temp_it
.f
)
24804 /* init_iterator calls this with it->glyph_row == NULL, and it
24805 wants only the pixel width of the truncation/continuation
24807 && temp_it
.glyph_row
24808 /* insert_left_trunc_glyphs calls us at the beginning of the
24809 row, and it has its own calculation of the stretch glyph
24811 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24812 && (temp_it
.glyph_row
->reversed_p
24813 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24814 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24816 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24818 if (stretch_width
> 0)
24820 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24821 struct font
*font
=
24822 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24823 int stretch_ascent
=
24824 (((temp_it
.ascent
+ temp_it
.descent
)
24825 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24827 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24828 temp_it
.ascent
+ temp_it
.descent
,
24835 temp_it
.what
= IT_CHARACTER
;
24837 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24838 temp_it
.face_id
= GLYPH_FACE (glyph
);
24839 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24841 PRODUCE_GLYPHS (&temp_it
);
24842 it
->pixel_width
= temp_it
.pixel_width
;
24843 it
->nglyphs
= temp_it
.pixel_width
;
24846 #ifdef HAVE_WINDOW_SYSTEM
24848 /* Calculate line-height and line-spacing properties.
24849 An integer value specifies explicit pixel value.
24850 A float value specifies relative value to current face height.
24851 A cons (float . face-name) specifies relative value to
24852 height of specified face font.
24854 Returns height in pixels, or nil. */
24858 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24859 int boff
, int override
)
24861 Lisp_Object face_name
= Qnil
;
24862 int ascent
, descent
, height
;
24864 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24869 face_name
= XCAR (val
);
24871 if (!NUMBERP (val
))
24872 val
= make_number (1);
24873 if (NILP (face_name
))
24875 height
= it
->ascent
+ it
->descent
;
24880 if (NILP (face_name
))
24882 font
= FRAME_FONT (it
->f
);
24883 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24885 else if (EQ (face_name
, Qt
))
24894 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24896 return make_number (-1);
24898 face
= FACE_FROM_ID (it
->f
, face_id
);
24901 return make_number (-1);
24902 boff
= font
->baseline_offset
;
24903 if (font
->vertical_centering
)
24904 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24907 ascent
= FONT_BASE (font
) + boff
;
24908 descent
= FONT_DESCENT (font
) - boff
;
24912 it
->override_ascent
= ascent
;
24913 it
->override_descent
= descent
;
24914 it
->override_boff
= boff
;
24917 height
= ascent
+ descent
;
24921 height
= (int)(XFLOAT_DATA (val
) * height
);
24922 else if (INTEGERP (val
))
24923 height
*= XINT (val
);
24925 return make_number (height
);
24929 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24930 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24931 and only if this is for a character for which no font was found.
24933 If the display method (it->glyphless_method) is
24934 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24935 length of the acronym or the hexadecimal string, UPPER_XOFF and
24936 UPPER_YOFF are pixel offsets for the upper part of the string,
24937 LOWER_XOFF and LOWER_YOFF are for the lower part.
24939 For the other display methods, LEN through LOWER_YOFF are zero. */
24942 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24943 short upper_xoff
, short upper_yoff
,
24944 short lower_xoff
, short lower_yoff
)
24946 struct glyph
*glyph
;
24947 enum glyph_row_area area
= it
->area
;
24949 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24950 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24952 /* If the glyph row is reversed, we need to prepend the glyph
24953 rather than append it. */
24954 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24958 /* Make room for the additional glyph. */
24959 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24961 glyph
= it
->glyph_row
->glyphs
[area
];
24963 glyph
->charpos
= CHARPOS (it
->position
);
24964 glyph
->object
= it
->object
;
24965 glyph
->pixel_width
= it
->pixel_width
;
24966 glyph
->ascent
= it
->ascent
;
24967 glyph
->descent
= it
->descent
;
24968 glyph
->voffset
= it
->voffset
;
24969 glyph
->type
= GLYPHLESS_GLYPH
;
24970 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24971 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24972 glyph
->u
.glyphless
.len
= len
;
24973 glyph
->u
.glyphless
.ch
= it
->c
;
24974 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24975 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24976 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24977 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24978 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24979 glyph
->multibyte_p
= it
->multibyte_p
;
24980 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24982 /* In R2L rows, the left and the right box edges need to be
24983 drawn in reverse direction. */
24984 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24985 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24989 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24990 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24992 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24993 || it
->phys_descent
> it
->descent
);
24994 glyph
->padding_p
= 0;
24995 glyph
->glyph_not_available_p
= 0;
24996 glyph
->face_id
= face_id
;
24997 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25000 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25001 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25003 glyph
->bidi_type
= it
->bidi_it
.type
;
25005 ++it
->glyph_row
->used
[area
];
25008 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25012 /* Produce a glyph for a glyphless character for iterator IT.
25013 IT->glyphless_method specifies which method to use for displaying
25014 the character. See the description of enum
25015 glyphless_display_method in dispextern.h for the detail.
25017 FOR_NO_FONT is nonzero if and only if this is for a character for
25018 which no font was found. ACRONYM, if non-nil, is an acronym string
25019 for the character. */
25022 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25027 int base_width
, base_height
, width
, height
;
25028 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25031 /* Get the metrics of the base font. We always refer to the current
25033 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25034 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25035 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25036 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25037 base_height
= it
->ascent
+ it
->descent
;
25038 base_width
= font
->average_width
;
25040 face_id
= merge_glyphless_glyph_face (it
);
25042 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25044 it
->pixel_width
= THIN_SPACE_WIDTH
;
25046 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25048 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25050 width
= CHAR_WIDTH (it
->c
);
25053 else if (width
> 4)
25055 it
->pixel_width
= base_width
* width
;
25057 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25063 unsigned int code
[6];
25065 int ascent
, descent
;
25066 struct font_metrics metrics_upper
, metrics_lower
;
25068 face
= FACE_FROM_ID (it
->f
, face_id
);
25069 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25070 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25072 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25074 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25075 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25076 if (CONSP (acronym
))
25077 acronym
= XCAR (acronym
);
25078 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25082 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25083 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25086 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25087 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25088 upper_len
= (len
+ 1) / 2;
25089 font
->driver
->text_extents (font
, code
, upper_len
,
25091 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25096 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25097 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25098 upper_xoff
= upper_yoff
= 2; /* the typical case */
25099 if (base_width
>= width
)
25101 /* Align the upper to the left, the lower to the right. */
25102 it
->pixel_width
= base_width
;
25103 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25107 /* Center the shorter one. */
25108 it
->pixel_width
= width
;
25109 if (metrics_upper
.width
>= metrics_lower
.width
)
25110 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25113 /* FIXME: This code doesn't look right. It formerly was
25114 missing the "lower_xoff = 0;", which couldn't have
25115 been right since it left lower_xoff uninitialized. */
25117 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25121 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25122 top, bottom, and between upper and lower strings. */
25123 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25124 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25125 /* Center vertically.
25126 H:base_height, D:base_descent
25127 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25129 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25130 descent = D - H/2 + h/2;
25131 lower_yoff = descent - 2 - ld;
25132 upper_yoff = lower_yoff - la - 1 - ud; */
25133 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25134 descent
= it
->descent
- (base_height
- height
) / 2;
25135 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25136 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25137 - metrics_upper
.descent
);
25138 /* Don't make the height shorter than the base height. */
25139 if (height
> base_height
)
25141 it
->ascent
= ascent
;
25142 it
->descent
= descent
;
25146 it
->phys_ascent
= it
->ascent
;
25147 it
->phys_descent
= it
->descent
;
25149 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25150 upper_xoff
, upper_yoff
,
25151 lower_xoff
, lower_yoff
);
25153 take_vertical_position_into_account (it
);
25158 Produce glyphs/get display metrics for the display element IT is
25159 loaded with. See the description of struct it in dispextern.h
25160 for an overview of struct it. */
25163 x_produce_glyphs (struct it
*it
)
25165 int extra_line_spacing
= it
->extra_line_spacing
;
25167 it
->glyph_not_available_p
= 0;
25169 if (it
->what
== IT_CHARACTER
)
25172 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25173 struct font
*font
= face
->font
;
25174 struct font_metrics
*pcm
= NULL
;
25175 int boff
; /* baseline offset */
25179 /* When no suitable font is found, display this character by
25180 the method specified in the first extra slot of
25181 Vglyphless_char_display. */
25182 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25184 eassert (it
->what
== IT_GLYPHLESS
);
25185 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25189 boff
= font
->baseline_offset
;
25190 if (font
->vertical_centering
)
25191 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25193 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25199 if (it
->override_ascent
>= 0)
25201 it
->ascent
= it
->override_ascent
;
25202 it
->descent
= it
->override_descent
;
25203 boff
= it
->override_boff
;
25207 it
->ascent
= FONT_BASE (font
) + boff
;
25208 it
->descent
= FONT_DESCENT (font
) - boff
;
25211 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25213 pcm
= get_per_char_metric (font
, &char2b
);
25214 if (pcm
->width
== 0
25215 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25221 it
->phys_ascent
= pcm
->ascent
+ boff
;
25222 it
->phys_descent
= pcm
->descent
- boff
;
25223 it
->pixel_width
= pcm
->width
;
25227 it
->glyph_not_available_p
= 1;
25228 it
->phys_ascent
= it
->ascent
;
25229 it
->phys_descent
= it
->descent
;
25230 it
->pixel_width
= font
->space_width
;
25233 if (it
->constrain_row_ascent_descent_p
)
25235 if (it
->descent
> it
->max_descent
)
25237 it
->ascent
+= it
->descent
- it
->max_descent
;
25238 it
->descent
= it
->max_descent
;
25240 if (it
->ascent
> it
->max_ascent
)
25242 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25243 it
->ascent
= it
->max_ascent
;
25245 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25246 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25247 extra_line_spacing
= 0;
25250 /* If this is a space inside a region of text with
25251 `space-width' property, change its width. */
25252 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25254 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25256 /* If face has a box, add the box thickness to the character
25257 height. If character has a box line to the left and/or
25258 right, add the box line width to the character's width. */
25259 if (face
->box
!= FACE_NO_BOX
)
25261 int thick
= face
->box_line_width
;
25265 it
->ascent
+= thick
;
25266 it
->descent
+= thick
;
25271 if (it
->start_of_box_run_p
)
25272 it
->pixel_width
+= thick
;
25273 if (it
->end_of_box_run_p
)
25274 it
->pixel_width
+= thick
;
25277 /* If face has an overline, add the height of the overline
25278 (1 pixel) and a 1 pixel margin to the character height. */
25279 if (face
->overline_p
)
25280 it
->ascent
+= overline_margin
;
25282 if (it
->constrain_row_ascent_descent_p
)
25284 if (it
->ascent
> it
->max_ascent
)
25285 it
->ascent
= it
->max_ascent
;
25286 if (it
->descent
> it
->max_descent
)
25287 it
->descent
= it
->max_descent
;
25290 take_vertical_position_into_account (it
);
25292 /* If we have to actually produce glyphs, do it. */
25297 /* Translate a space with a `space-width' property
25298 into a stretch glyph. */
25299 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25300 / FONT_HEIGHT (font
));
25301 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25302 it
->ascent
+ it
->descent
, ascent
);
25307 /* If characters with lbearing or rbearing are displayed
25308 in this line, record that fact in a flag of the
25309 glyph row. This is used to optimize X output code. */
25310 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25311 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25313 if (! stretched_p
&& it
->pixel_width
== 0)
25314 /* We assure that all visible glyphs have at least 1-pixel
25316 it
->pixel_width
= 1;
25318 else if (it
->char_to_display
== '\n')
25320 /* A newline has no width, but we need the height of the
25321 line. But if previous part of the line sets a height,
25322 don't increase that height */
25324 Lisp_Object height
;
25325 Lisp_Object total_height
= Qnil
;
25327 it
->override_ascent
= -1;
25328 it
->pixel_width
= 0;
25331 height
= get_it_property (it
, Qline_height
);
25332 /* Split (line-height total-height) list */
25334 && CONSP (XCDR (height
))
25335 && NILP (XCDR (XCDR (height
))))
25337 total_height
= XCAR (XCDR (height
));
25338 height
= XCAR (height
);
25340 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25342 if (it
->override_ascent
>= 0)
25344 it
->ascent
= it
->override_ascent
;
25345 it
->descent
= it
->override_descent
;
25346 boff
= it
->override_boff
;
25350 it
->ascent
= FONT_BASE (font
) + boff
;
25351 it
->descent
= FONT_DESCENT (font
) - boff
;
25354 if (EQ (height
, Qt
))
25356 if (it
->descent
> it
->max_descent
)
25358 it
->ascent
+= it
->descent
- it
->max_descent
;
25359 it
->descent
= it
->max_descent
;
25361 if (it
->ascent
> it
->max_ascent
)
25363 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25364 it
->ascent
= it
->max_ascent
;
25366 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25367 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25368 it
->constrain_row_ascent_descent_p
= 1;
25369 extra_line_spacing
= 0;
25373 Lisp_Object spacing
;
25375 it
->phys_ascent
= it
->ascent
;
25376 it
->phys_descent
= it
->descent
;
25378 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25379 && face
->box
!= FACE_NO_BOX
25380 && face
->box_line_width
> 0)
25382 it
->ascent
+= face
->box_line_width
;
25383 it
->descent
+= face
->box_line_width
;
25386 && XINT (height
) > it
->ascent
+ it
->descent
)
25387 it
->ascent
= XINT (height
) - it
->descent
;
25389 if (!NILP (total_height
))
25390 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25393 spacing
= get_it_property (it
, Qline_spacing
);
25394 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25396 if (INTEGERP (spacing
))
25398 extra_line_spacing
= XINT (spacing
);
25399 if (!NILP (total_height
))
25400 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25404 else /* i.e. (it->char_to_display == '\t') */
25406 if (font
->space_width
> 0)
25408 int tab_width
= it
->tab_width
* font
->space_width
;
25409 int x
= it
->current_x
+ it
->continuation_lines_width
;
25410 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25412 /* If the distance from the current position to the next tab
25413 stop is less than a space character width, use the
25414 tab stop after that. */
25415 if (next_tab_x
- x
< font
->space_width
)
25416 next_tab_x
+= tab_width
;
25418 it
->pixel_width
= next_tab_x
- x
;
25420 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25421 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25425 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25426 it
->ascent
+ it
->descent
, it
->ascent
);
25431 it
->pixel_width
= 0;
25436 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25438 /* A static composition.
25440 Note: A composition is represented as one glyph in the
25441 glyph matrix. There are no padding glyphs.
25443 Important note: pixel_width, ascent, and descent are the
25444 values of what is drawn by draw_glyphs (i.e. the values of
25445 the overall glyphs composed). */
25446 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25447 int boff
; /* baseline offset */
25448 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25449 int glyph_len
= cmp
->glyph_len
;
25450 struct font
*font
= face
->font
;
25454 /* If we have not yet calculated pixel size data of glyphs of
25455 the composition for the current face font, calculate them
25456 now. Theoretically, we have to check all fonts for the
25457 glyphs, but that requires much time and memory space. So,
25458 here we check only the font of the first glyph. This may
25459 lead to incorrect display, but it's very rare, and C-l
25460 (recenter-top-bottom) can correct the display anyway. */
25461 if (! cmp
->font
|| cmp
->font
!= font
)
25463 /* Ascent and descent of the font of the first character
25464 of this composition (adjusted by baseline offset).
25465 Ascent and descent of overall glyphs should not be less
25466 than these, respectively. */
25467 int font_ascent
, font_descent
, font_height
;
25468 /* Bounding box of the overall glyphs. */
25469 int leftmost
, rightmost
, lowest
, highest
;
25470 int lbearing
, rbearing
;
25471 int i
, width
, ascent
, descent
;
25472 int left_padded
= 0, right_padded
= 0;
25473 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25475 struct font_metrics
*pcm
;
25476 int font_not_found_p
;
25479 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25480 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25482 if (glyph_len
< cmp
->glyph_len
)
25484 for (i
= 0; i
< glyph_len
; i
++)
25486 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25488 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25493 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25494 : IT_CHARPOS (*it
));
25495 /* If no suitable font is found, use the default font. */
25496 font_not_found_p
= font
== NULL
;
25497 if (font_not_found_p
)
25499 face
= face
->ascii_face
;
25502 boff
= font
->baseline_offset
;
25503 if (font
->vertical_centering
)
25504 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25505 font_ascent
= FONT_BASE (font
) + boff
;
25506 font_descent
= FONT_DESCENT (font
) - boff
;
25507 font_height
= FONT_HEIGHT (font
);
25512 if (! font_not_found_p
)
25514 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25516 pcm
= get_per_char_metric (font
, &char2b
);
25519 /* Initialize the bounding box. */
25522 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25523 ascent
= pcm
->ascent
;
25524 descent
= pcm
->descent
;
25525 lbearing
= pcm
->lbearing
;
25526 rbearing
= pcm
->rbearing
;
25530 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25531 ascent
= FONT_BASE (font
);
25532 descent
= FONT_DESCENT (font
);
25539 lowest
= - descent
+ boff
;
25540 highest
= ascent
+ boff
;
25542 if (! font_not_found_p
25543 && font
->default_ascent
25544 && CHAR_TABLE_P (Vuse_default_ascent
)
25545 && !NILP (Faref (Vuse_default_ascent
,
25546 make_number (it
->char_to_display
))))
25547 highest
= font
->default_ascent
+ boff
;
25549 /* Draw the first glyph at the normal position. It may be
25550 shifted to right later if some other glyphs are drawn
25552 cmp
->offsets
[i
* 2] = 0;
25553 cmp
->offsets
[i
* 2 + 1] = boff
;
25554 cmp
->lbearing
= lbearing
;
25555 cmp
->rbearing
= rbearing
;
25557 /* Set cmp->offsets for the remaining glyphs. */
25558 for (i
++; i
< glyph_len
; i
++)
25560 int left
, right
, btm
, top
;
25561 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25563 struct face
*this_face
;
25567 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25568 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25569 font
= this_face
->font
;
25575 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25577 pcm
= get_per_char_metric (font
, &char2b
);
25580 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25583 width
= pcm
->width
;
25584 ascent
= pcm
->ascent
;
25585 descent
= pcm
->descent
;
25586 lbearing
= pcm
->lbearing
;
25587 rbearing
= pcm
->rbearing
;
25588 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25590 /* Relative composition with or without
25591 alternate chars. */
25592 left
= (leftmost
+ rightmost
- width
) / 2;
25593 btm
= - descent
+ boff
;
25594 if (font
->relative_compose
25595 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25596 || NILP (Faref (Vignore_relative_composition
,
25597 make_number (ch
)))))
25600 if (- descent
>= font
->relative_compose
)
25601 /* One extra pixel between two glyphs. */
25603 else if (ascent
<= 0)
25604 /* One extra pixel between two glyphs. */
25605 btm
= lowest
- 1 - ascent
- descent
;
25610 /* A composition rule is specified by an integer
25611 value that encodes global and new reference
25612 points (GREF and NREF). GREF and NREF are
25613 specified by numbers as below:
25615 0---1---2 -- ascent
25619 9--10--11 -- center
25621 ---3---4---5--- baseline
25623 6---7---8 -- descent
25625 int rule
= COMPOSITION_RULE (cmp
, i
);
25626 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25628 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25629 grefx
= gref
% 3, nrefx
= nref
% 3;
25630 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25632 xoff
= font_height
* (xoff
- 128) / 256;
25634 yoff
= font_height
* (yoff
- 128) / 256;
25637 + grefx
* (rightmost
- leftmost
) / 2
25638 - nrefx
* width
/ 2
25641 btm
= ((grefy
== 0 ? highest
25643 : grefy
== 2 ? lowest
25644 : (highest
+ lowest
) / 2)
25645 - (nrefy
== 0 ? ascent
+ descent
25646 : nrefy
== 1 ? descent
- boff
25648 : (ascent
+ descent
) / 2)
25652 cmp
->offsets
[i
* 2] = left
;
25653 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25655 /* Update the bounding box of the overall glyphs. */
25658 right
= left
+ width
;
25659 if (left
< leftmost
)
25661 if (right
> rightmost
)
25664 top
= btm
+ descent
+ ascent
;
25670 if (cmp
->lbearing
> left
+ lbearing
)
25671 cmp
->lbearing
= left
+ lbearing
;
25672 if (cmp
->rbearing
< left
+ rbearing
)
25673 cmp
->rbearing
= left
+ rbearing
;
25677 /* If there are glyphs whose x-offsets are negative,
25678 shift all glyphs to the right and make all x-offsets
25682 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25683 cmp
->offsets
[i
* 2] -= leftmost
;
25684 rightmost
-= leftmost
;
25685 cmp
->lbearing
-= leftmost
;
25686 cmp
->rbearing
-= leftmost
;
25689 if (left_padded
&& cmp
->lbearing
< 0)
25691 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25692 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25693 rightmost
-= cmp
->lbearing
;
25694 cmp
->rbearing
-= cmp
->lbearing
;
25697 if (right_padded
&& rightmost
< cmp
->rbearing
)
25699 rightmost
= cmp
->rbearing
;
25702 cmp
->pixel_width
= rightmost
;
25703 cmp
->ascent
= highest
;
25704 cmp
->descent
= - lowest
;
25705 if (cmp
->ascent
< font_ascent
)
25706 cmp
->ascent
= font_ascent
;
25707 if (cmp
->descent
< font_descent
)
25708 cmp
->descent
= font_descent
;
25712 && (cmp
->lbearing
< 0
25713 || cmp
->rbearing
> cmp
->pixel_width
))
25714 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25716 it
->pixel_width
= cmp
->pixel_width
;
25717 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25718 it
->descent
= it
->phys_descent
= cmp
->descent
;
25719 if (face
->box
!= FACE_NO_BOX
)
25721 int thick
= face
->box_line_width
;
25725 it
->ascent
+= thick
;
25726 it
->descent
+= thick
;
25731 if (it
->start_of_box_run_p
)
25732 it
->pixel_width
+= thick
;
25733 if (it
->end_of_box_run_p
)
25734 it
->pixel_width
+= thick
;
25737 /* If face has an overline, add the height of the overline
25738 (1 pixel) and a 1 pixel margin to the character height. */
25739 if (face
->overline_p
)
25740 it
->ascent
+= overline_margin
;
25742 take_vertical_position_into_account (it
);
25743 if (it
->ascent
< 0)
25745 if (it
->descent
< 0)
25748 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25749 append_composite_glyph (it
);
25751 else if (it
->what
== IT_COMPOSITION
)
25753 /* A dynamic (automatic) composition. */
25754 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25755 Lisp_Object gstring
;
25756 struct font_metrics metrics
;
25760 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25762 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25765 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25766 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25767 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25768 it
->descent
= it
->phys_descent
= metrics
.descent
;
25769 if (face
->box
!= FACE_NO_BOX
)
25771 int thick
= face
->box_line_width
;
25775 it
->ascent
+= thick
;
25776 it
->descent
+= thick
;
25781 if (it
->start_of_box_run_p
)
25782 it
->pixel_width
+= thick
;
25783 if (it
->end_of_box_run_p
)
25784 it
->pixel_width
+= thick
;
25786 /* If face has an overline, add the height of the overline
25787 (1 pixel) and a 1 pixel margin to the character height. */
25788 if (face
->overline_p
)
25789 it
->ascent
+= overline_margin
;
25790 take_vertical_position_into_account (it
);
25791 if (it
->ascent
< 0)
25793 if (it
->descent
< 0)
25797 append_composite_glyph (it
);
25799 else if (it
->what
== IT_GLYPHLESS
)
25800 produce_glyphless_glyph (it
, 0, Qnil
);
25801 else if (it
->what
== IT_IMAGE
)
25802 produce_image_glyph (it
);
25803 else if (it
->what
== IT_STRETCH
)
25804 produce_stretch_glyph (it
);
25807 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25808 because this isn't true for images with `:ascent 100'. */
25809 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25810 if (it
->area
== TEXT_AREA
)
25811 it
->current_x
+= it
->pixel_width
;
25813 if (extra_line_spacing
> 0)
25815 it
->descent
+= extra_line_spacing
;
25816 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25817 it
->max_extra_line_spacing
= extra_line_spacing
;
25820 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25821 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25822 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25823 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25827 Output LEN glyphs starting at START at the nominal cursor position.
25828 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25829 being updated, and UPDATED_AREA is the area of that row being updated. */
25832 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25833 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25835 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25837 eassert (updated_row
);
25838 /* When the window is hscrolled, cursor hpos can legitimately be out
25839 of bounds, but we draw the cursor at the corresponding window
25840 margin in that case. */
25841 if (!updated_row
->reversed_p
&& chpos
< 0)
25843 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25844 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25848 /* Write glyphs. */
25850 hpos
= start
- updated_row
->glyphs
[updated_area
];
25851 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25852 updated_row
, updated_area
,
25854 DRAW_NORMAL_TEXT
, 0);
25856 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25857 if (updated_area
== TEXT_AREA
25858 && w
->phys_cursor_on_p
25859 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25861 && chpos
< hpos
+ len
)
25862 w
->phys_cursor_on_p
= 0;
25866 /* Advance the output cursor. */
25867 w
->output_cursor
.hpos
+= len
;
25868 w
->output_cursor
.x
= x
;
25873 Insert LEN glyphs from START at the nominal cursor position. */
25876 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25877 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25880 int line_height
, shift_by_width
, shifted_region_width
;
25881 struct glyph_row
*row
;
25882 struct glyph
*glyph
;
25883 int frame_x
, frame_y
;
25886 eassert (updated_row
);
25888 f
= XFRAME (WINDOW_FRAME (w
));
25890 /* Get the height of the line we are in. */
25892 line_height
= row
->height
;
25894 /* Get the width of the glyphs to insert. */
25895 shift_by_width
= 0;
25896 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25897 shift_by_width
+= glyph
->pixel_width
;
25899 /* Get the width of the region to shift right. */
25900 shifted_region_width
= (window_box_width (w
, updated_area
)
25901 - w
->output_cursor
.x
25905 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25906 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25908 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25909 line_height
, shift_by_width
);
25911 /* Write the glyphs. */
25912 hpos
= start
- row
->glyphs
[updated_area
];
25913 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25915 DRAW_NORMAL_TEXT
, 0);
25917 /* Advance the output cursor. */
25918 w
->output_cursor
.hpos
+= len
;
25919 w
->output_cursor
.x
+= shift_by_width
;
25925 Erase the current text line from the nominal cursor position
25926 (inclusive) to pixel column TO_X (exclusive). The idea is that
25927 everything from TO_X onward is already erased.
25929 TO_X is a pixel position relative to UPDATED_AREA of currently
25930 updated window W. TO_X == -1 means clear to the end of this area. */
25933 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25934 enum glyph_row_area updated_area
, int to_x
)
25937 int max_x
, min_y
, max_y
;
25938 int from_x
, from_y
, to_y
;
25940 eassert (updated_row
);
25941 f
= XFRAME (w
->frame
);
25943 if (updated_row
->full_width_p
)
25944 max_x
= WINDOW_TOTAL_WIDTH (w
);
25946 max_x
= window_box_width (w
, updated_area
);
25947 max_y
= window_text_bottom_y (w
);
25949 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25950 of window. For TO_X > 0, truncate to end of drawing area. */
25956 to_x
= min (to_x
, max_x
);
25958 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25960 /* Notice if the cursor will be cleared by this operation. */
25961 if (!updated_row
->full_width_p
)
25962 notice_overwritten_cursor (w
, updated_area
,
25963 w
->output_cursor
.x
, -1,
25965 MATRIX_ROW_BOTTOM_Y (updated_row
));
25967 from_x
= w
->output_cursor
.x
;
25969 /* Translate to frame coordinates. */
25970 if (updated_row
->full_width_p
)
25972 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25973 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25977 int area_left
= window_box_left (w
, updated_area
);
25978 from_x
+= area_left
;
25982 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25983 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
25984 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25986 /* Prevent inadvertently clearing to end of the X window. */
25987 if (to_x
> from_x
&& to_y
> from_y
)
25990 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25991 to_x
- from_x
, to_y
- from_y
);
25996 #endif /* HAVE_WINDOW_SYSTEM */
26000 /***********************************************************************
26002 ***********************************************************************/
26004 /* Value is the internal representation of the specified cursor type
26005 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26006 of the bar cursor. */
26008 static enum text_cursor_kinds
26009 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26011 enum text_cursor_kinds type
;
26016 if (EQ (arg
, Qbox
))
26017 return FILLED_BOX_CURSOR
;
26019 if (EQ (arg
, Qhollow
))
26020 return HOLLOW_BOX_CURSOR
;
26022 if (EQ (arg
, Qbar
))
26029 && EQ (XCAR (arg
), Qbar
)
26030 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26032 *width
= XINT (XCDR (arg
));
26036 if (EQ (arg
, Qhbar
))
26039 return HBAR_CURSOR
;
26043 && EQ (XCAR (arg
), Qhbar
)
26044 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26046 *width
= XINT (XCDR (arg
));
26047 return HBAR_CURSOR
;
26050 /* Treat anything unknown as "hollow box cursor".
26051 It was bad to signal an error; people have trouble fixing
26052 .Xdefaults with Emacs, when it has something bad in it. */
26053 type
= HOLLOW_BOX_CURSOR
;
26058 /* Set the default cursor types for specified frame. */
26060 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26065 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26066 FRAME_CURSOR_WIDTH (f
) = width
;
26068 /* By default, set up the blink-off state depending on the on-state. */
26070 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26073 FRAME_BLINK_OFF_CURSOR (f
)
26074 = get_specified_cursor_type (XCDR (tem
), &width
);
26075 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26078 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26080 /* Make sure the cursor gets redrawn. */
26081 f
->cursor_type_changed
= 1;
26085 #ifdef HAVE_WINDOW_SYSTEM
26087 /* Return the cursor we want to be displayed in window W. Return
26088 width of bar/hbar cursor through WIDTH arg. Return with
26089 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26090 (i.e. if the `system caret' should track this cursor).
26092 In a mini-buffer window, we want the cursor only to appear if we
26093 are reading input from this window. For the selected window, we
26094 want the cursor type given by the frame parameter or buffer local
26095 setting of cursor-type. If explicitly marked off, draw no cursor.
26096 In all other cases, we want a hollow box cursor. */
26098 static enum text_cursor_kinds
26099 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26100 int *active_cursor
)
26102 struct frame
*f
= XFRAME (w
->frame
);
26103 struct buffer
*b
= XBUFFER (w
->contents
);
26104 int cursor_type
= DEFAULT_CURSOR
;
26105 Lisp_Object alt_cursor
;
26106 int non_selected
= 0;
26108 *active_cursor
= 1;
26111 if (cursor_in_echo_area
26112 && FRAME_HAS_MINIBUF_P (f
)
26113 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26115 if (w
== XWINDOW (echo_area_window
))
26117 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26119 *width
= FRAME_CURSOR_WIDTH (f
);
26120 return FRAME_DESIRED_CURSOR (f
);
26123 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26126 *active_cursor
= 0;
26130 /* Detect a nonselected window or nonselected frame. */
26131 else if (w
!= XWINDOW (f
->selected_window
)
26132 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26134 *active_cursor
= 0;
26136 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26142 /* Never display a cursor in a window in which cursor-type is nil. */
26143 if (NILP (BVAR (b
, cursor_type
)))
26146 /* Get the normal cursor type for this window. */
26147 if (EQ (BVAR (b
, cursor_type
), Qt
))
26149 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26150 *width
= FRAME_CURSOR_WIDTH (f
);
26153 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26155 /* Use cursor-in-non-selected-windows instead
26156 for non-selected window or frame. */
26159 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26160 if (!EQ (Qt
, alt_cursor
))
26161 return get_specified_cursor_type (alt_cursor
, width
);
26162 /* t means modify the normal cursor type. */
26163 if (cursor_type
== FILLED_BOX_CURSOR
)
26164 cursor_type
= HOLLOW_BOX_CURSOR
;
26165 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26167 return cursor_type
;
26170 /* Use normal cursor if not blinked off. */
26171 if (!w
->cursor_off_p
)
26173 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26175 if (cursor_type
== FILLED_BOX_CURSOR
)
26177 /* Using a block cursor on large images can be very annoying.
26178 So use a hollow cursor for "large" images.
26179 If image is not transparent (no mask), also use hollow cursor. */
26180 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26181 if (img
!= NULL
&& IMAGEP (img
->spec
))
26183 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26184 where N = size of default frame font size.
26185 This should cover most of the "tiny" icons people may use. */
26187 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26188 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26189 cursor_type
= HOLLOW_BOX_CURSOR
;
26192 else if (cursor_type
!= NO_CURSOR
)
26194 /* Display current only supports BOX and HOLLOW cursors for images.
26195 So for now, unconditionally use a HOLLOW cursor when cursor is
26196 not a solid box cursor. */
26197 cursor_type
= HOLLOW_BOX_CURSOR
;
26200 return cursor_type
;
26203 /* Cursor is blinked off, so determine how to "toggle" it. */
26205 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26206 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26207 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26209 /* Then see if frame has specified a specific blink off cursor type. */
26210 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26212 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26213 return FRAME_BLINK_OFF_CURSOR (f
);
26217 /* Some people liked having a permanently visible blinking cursor,
26218 while others had very strong opinions against it. So it was
26219 decided to remove it. KFS 2003-09-03 */
26221 /* Finally perform built-in cursor blinking:
26222 filled box <-> hollow box
26223 wide [h]bar <-> narrow [h]bar
26224 narrow [h]bar <-> no cursor
26225 other type <-> no cursor */
26227 if (cursor_type
== FILLED_BOX_CURSOR
)
26228 return HOLLOW_BOX_CURSOR
;
26230 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26233 return cursor_type
;
26241 /* Notice when the text cursor of window W has been completely
26242 overwritten by a drawing operation that outputs glyphs in AREA
26243 starting at X0 and ending at X1 in the line starting at Y0 and
26244 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26245 the rest of the line after X0 has been written. Y coordinates
26246 are window-relative. */
26249 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26250 int x0
, int x1
, int y0
, int y1
)
26252 int cx0
, cx1
, cy0
, cy1
;
26253 struct glyph_row
*row
;
26255 if (!w
->phys_cursor_on_p
)
26257 if (area
!= TEXT_AREA
)
26260 if (w
->phys_cursor
.vpos
< 0
26261 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26262 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26263 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26266 if (row
->cursor_in_fringe_p
)
26268 row
->cursor_in_fringe_p
= 0;
26269 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26270 w
->phys_cursor_on_p
= 0;
26274 cx0
= w
->phys_cursor
.x
;
26275 cx1
= cx0
+ w
->phys_cursor_width
;
26276 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26279 /* The cursor image will be completely removed from the
26280 screen if the output area intersects the cursor area in
26281 y-direction. When we draw in [y0 y1[, and some part of
26282 the cursor is at y < y0, that part must have been drawn
26283 before. When scrolling, the cursor is erased before
26284 actually scrolling, so we don't come here. When not
26285 scrolling, the rows above the old cursor row must have
26286 changed, and in this case these rows must have written
26287 over the cursor image.
26289 Likewise if part of the cursor is below y1, with the
26290 exception of the cursor being in the first blank row at
26291 the buffer and window end because update_text_area
26292 doesn't draw that row. (Except when it does, but
26293 that's handled in update_text_area.) */
26295 cy0
= w
->phys_cursor
.y
;
26296 cy1
= cy0
+ w
->phys_cursor_height
;
26297 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26300 w
->phys_cursor_on_p
= 0;
26303 #endif /* HAVE_WINDOW_SYSTEM */
26306 /************************************************************************
26308 ************************************************************************/
26310 #ifdef HAVE_WINDOW_SYSTEM
26313 Fix the display of area AREA of overlapping row ROW in window W
26314 with respect to the overlapping part OVERLAPS. */
26317 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26318 enum glyph_row_area area
, int overlaps
)
26325 for (i
= 0; i
< row
->used
[area
];)
26327 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26329 int start
= i
, start_x
= x
;
26333 x
+= row
->glyphs
[area
][i
].pixel_width
;
26336 while (i
< row
->used
[area
]
26337 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26339 draw_glyphs (w
, start_x
, row
, area
,
26341 DRAW_NORMAL_TEXT
, overlaps
);
26345 x
+= row
->glyphs
[area
][i
].pixel_width
;
26355 Draw the cursor glyph of window W in glyph row ROW. See the
26356 comment of draw_glyphs for the meaning of HL. */
26359 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26360 enum draw_glyphs_face hl
)
26362 /* If cursor hpos is out of bounds, don't draw garbage. This can
26363 happen in mini-buffer windows when switching between echo area
26364 glyphs and mini-buffer. */
26365 if ((row
->reversed_p
26366 ? (w
->phys_cursor
.hpos
>= 0)
26367 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26369 int on_p
= w
->phys_cursor_on_p
;
26371 int hpos
= w
->phys_cursor
.hpos
;
26373 /* When the window is hscrolled, cursor hpos can legitimately be
26374 out of bounds, but we draw the cursor at the corresponding
26375 window margin in that case. */
26376 if (!row
->reversed_p
&& hpos
< 0)
26378 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26379 hpos
= row
->used
[TEXT_AREA
] - 1;
26381 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26383 w
->phys_cursor_on_p
= on_p
;
26385 if (hl
== DRAW_CURSOR
)
26386 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26387 /* When we erase the cursor, and ROW is overlapped by other
26388 rows, make sure that these overlapping parts of other rows
26390 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26392 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26394 if (row
> w
->current_matrix
->rows
26395 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26396 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26397 OVERLAPS_ERASED_CURSOR
);
26399 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26400 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26401 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26402 OVERLAPS_ERASED_CURSOR
);
26409 Erase the image of a cursor of window W from the screen. */
26412 erase_phys_cursor (struct window
*w
)
26414 struct frame
*f
= XFRAME (w
->frame
);
26415 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26416 int hpos
= w
->phys_cursor
.hpos
;
26417 int vpos
= w
->phys_cursor
.vpos
;
26418 int mouse_face_here_p
= 0;
26419 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26420 struct glyph_row
*cursor_row
;
26421 struct glyph
*cursor_glyph
;
26422 enum draw_glyphs_face hl
;
26424 /* No cursor displayed or row invalidated => nothing to do on the
26426 if (w
->phys_cursor_type
== NO_CURSOR
)
26427 goto mark_cursor_off
;
26429 /* VPOS >= active_glyphs->nrows means that window has been resized.
26430 Don't bother to erase the cursor. */
26431 if (vpos
>= active_glyphs
->nrows
)
26432 goto mark_cursor_off
;
26434 /* If row containing cursor is marked invalid, there is nothing we
26436 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26437 if (!cursor_row
->enabled_p
)
26438 goto mark_cursor_off
;
26440 /* If line spacing is > 0, old cursor may only be partially visible in
26441 window after split-window. So adjust visible height. */
26442 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26443 window_text_bottom_y (w
) - cursor_row
->y
);
26445 /* If row is completely invisible, don't attempt to delete a cursor which
26446 isn't there. This can happen if cursor is at top of a window, and
26447 we switch to a buffer with a header line in that window. */
26448 if (cursor_row
->visible_height
<= 0)
26449 goto mark_cursor_off
;
26451 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26452 if (cursor_row
->cursor_in_fringe_p
)
26454 cursor_row
->cursor_in_fringe_p
= 0;
26455 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26456 goto mark_cursor_off
;
26459 /* This can happen when the new row is shorter than the old one.
26460 In this case, either draw_glyphs or clear_end_of_line
26461 should have cleared the cursor. Note that we wouldn't be
26462 able to erase the cursor in this case because we don't have a
26463 cursor glyph at hand. */
26464 if ((cursor_row
->reversed_p
26465 ? (w
->phys_cursor
.hpos
< 0)
26466 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26467 goto mark_cursor_off
;
26469 /* When the window is hscrolled, cursor hpos can legitimately be out
26470 of bounds, but we draw the cursor at the corresponding window
26471 margin in that case. */
26472 if (!cursor_row
->reversed_p
&& hpos
< 0)
26474 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26475 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26477 /* If the cursor is in the mouse face area, redisplay that when
26478 we clear the cursor. */
26479 if (! NILP (hlinfo
->mouse_face_window
)
26480 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26481 /* Don't redraw the cursor's spot in mouse face if it is at the
26482 end of a line (on a newline). The cursor appears there, but
26483 mouse highlighting does not. */
26484 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26485 mouse_face_here_p
= 1;
26487 /* Maybe clear the display under the cursor. */
26488 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26491 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26494 cursor_glyph
= get_phys_cursor_glyph (w
);
26495 if (cursor_glyph
== NULL
)
26496 goto mark_cursor_off
;
26498 width
= cursor_glyph
->pixel_width
;
26499 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26500 x
= w
->phys_cursor
.x
;
26502 width
-= left_x
- x
;
26503 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26504 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26505 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26508 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26511 /* Erase the cursor by redrawing the character underneath it. */
26512 if (mouse_face_here_p
)
26513 hl
= DRAW_MOUSE_FACE
;
26515 hl
= DRAW_NORMAL_TEXT
;
26516 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26519 w
->phys_cursor_on_p
= 0;
26520 w
->phys_cursor_type
= NO_CURSOR
;
26525 Display or clear cursor of window W. If ON is zero, clear the
26526 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26527 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26530 display_and_set_cursor (struct window
*w
, bool on
,
26531 int hpos
, int vpos
, int x
, int y
)
26533 struct frame
*f
= XFRAME (w
->frame
);
26534 int new_cursor_type
;
26535 int new_cursor_width
;
26537 struct glyph_row
*glyph_row
;
26538 struct glyph
*glyph
;
26540 /* This is pointless on invisible frames, and dangerous on garbaged
26541 windows and frames; in the latter case, the frame or window may
26542 be in the midst of changing its size, and x and y may be off the
26544 if (! FRAME_VISIBLE_P (f
)
26545 || FRAME_GARBAGED_P (f
)
26546 || vpos
>= w
->current_matrix
->nrows
26547 || hpos
>= w
->current_matrix
->matrix_w
)
26550 /* If cursor is off and we want it off, return quickly. */
26551 if (!on
&& !w
->phys_cursor_on_p
)
26554 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26555 /* If cursor row is not enabled, we don't really know where to
26556 display the cursor. */
26557 if (!glyph_row
->enabled_p
)
26559 w
->phys_cursor_on_p
= 0;
26564 if (!glyph_row
->exact_window_width_line_p
26565 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26566 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26568 eassert (input_blocked_p ());
26570 /* Set new_cursor_type to the cursor we want to be displayed. */
26571 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26572 &new_cursor_width
, &active_cursor
);
26574 /* If cursor is currently being shown and we don't want it to be or
26575 it is in the wrong place, or the cursor type is not what we want,
26577 if (w
->phys_cursor_on_p
26579 || w
->phys_cursor
.x
!= x
26580 || w
->phys_cursor
.y
!= y
26581 || new_cursor_type
!= w
->phys_cursor_type
26582 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26583 && new_cursor_width
!= w
->phys_cursor_width
)))
26584 erase_phys_cursor (w
);
26586 /* Don't check phys_cursor_on_p here because that flag is only set
26587 to zero in some cases where we know that the cursor has been
26588 completely erased, to avoid the extra work of erasing the cursor
26589 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26590 still not be visible, or it has only been partly erased. */
26593 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26594 w
->phys_cursor_height
= glyph_row
->height
;
26596 /* Set phys_cursor_.* before x_draw_.* is called because some
26597 of them may need the information. */
26598 w
->phys_cursor
.x
= x
;
26599 w
->phys_cursor
.y
= glyph_row
->y
;
26600 w
->phys_cursor
.hpos
= hpos
;
26601 w
->phys_cursor
.vpos
= vpos
;
26604 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26605 new_cursor_type
, new_cursor_width
,
26606 on
, active_cursor
);
26610 /* Switch the display of W's cursor on or off, according to the value
26614 update_window_cursor (struct window
*w
, bool on
)
26616 /* Don't update cursor in windows whose frame is in the process
26617 of being deleted. */
26618 if (w
->current_matrix
)
26620 int hpos
= w
->phys_cursor
.hpos
;
26621 int vpos
= w
->phys_cursor
.vpos
;
26622 struct glyph_row
*row
;
26624 if (vpos
>= w
->current_matrix
->nrows
26625 || hpos
>= w
->current_matrix
->matrix_w
)
26628 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26630 /* When the window is hscrolled, cursor hpos can legitimately be
26631 out of bounds, but we draw the cursor at the corresponding
26632 window margin in that case. */
26633 if (!row
->reversed_p
&& hpos
< 0)
26635 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26636 hpos
= row
->used
[TEXT_AREA
] - 1;
26639 display_and_set_cursor (w
, on
, hpos
, vpos
,
26640 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26646 /* Call update_window_cursor with parameter ON_P on all leaf windows
26647 in the window tree rooted at W. */
26650 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26654 if (WINDOWP (w
->contents
))
26655 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26657 update_window_cursor (w
, on_p
);
26659 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26665 Display the cursor on window W, or clear it, according to ON_P.
26666 Don't change the cursor's position. */
26669 x_update_cursor (struct frame
*f
, bool on_p
)
26671 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26676 Clear the cursor of window W to background color, and mark the
26677 cursor as not shown. This is used when the text where the cursor
26678 is about to be rewritten. */
26681 x_clear_cursor (struct window
*w
)
26683 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26684 update_window_cursor (w
, 0);
26687 #endif /* HAVE_WINDOW_SYSTEM */
26689 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26692 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26693 int start_hpos
, int end_hpos
,
26694 enum draw_glyphs_face draw
)
26696 #ifdef HAVE_WINDOW_SYSTEM
26697 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26699 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26703 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26704 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26708 /* Display the active region described by mouse_face_* according to DRAW. */
26711 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26713 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26714 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26716 if (/* If window is in the process of being destroyed, don't bother
26718 w
->current_matrix
!= NULL
26719 /* Don't update mouse highlight if hidden */
26720 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26721 /* Recognize when we are called to operate on rows that don't exist
26722 anymore. This can happen when a window is split. */
26723 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26725 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26726 struct glyph_row
*row
, *first
, *last
;
26728 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26729 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26731 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26733 int start_hpos
, end_hpos
, start_x
;
26735 /* For all but the first row, the highlight starts at column 0. */
26738 /* R2L rows have BEG and END in reversed order, but the
26739 screen drawing geometry is always left to right. So
26740 we need to mirror the beginning and end of the
26741 highlighted area in R2L rows. */
26742 if (!row
->reversed_p
)
26744 start_hpos
= hlinfo
->mouse_face_beg_col
;
26745 start_x
= hlinfo
->mouse_face_beg_x
;
26747 else if (row
== last
)
26749 start_hpos
= hlinfo
->mouse_face_end_col
;
26750 start_x
= hlinfo
->mouse_face_end_x
;
26758 else if (row
->reversed_p
&& row
== last
)
26760 start_hpos
= hlinfo
->mouse_face_end_col
;
26761 start_x
= hlinfo
->mouse_face_end_x
;
26771 if (!row
->reversed_p
)
26772 end_hpos
= hlinfo
->mouse_face_end_col
;
26773 else if (row
== first
)
26774 end_hpos
= hlinfo
->mouse_face_beg_col
;
26777 end_hpos
= row
->used
[TEXT_AREA
];
26778 if (draw
== DRAW_NORMAL_TEXT
)
26779 row
->fill_line_p
= 1; /* Clear to end of line */
26782 else if (row
->reversed_p
&& row
== first
)
26783 end_hpos
= hlinfo
->mouse_face_beg_col
;
26786 end_hpos
= row
->used
[TEXT_AREA
];
26787 if (draw
== DRAW_NORMAL_TEXT
)
26788 row
->fill_line_p
= 1; /* Clear to end of line */
26791 if (end_hpos
> start_hpos
)
26793 draw_row_with_mouse_face (w
, start_x
, row
,
26794 start_hpos
, end_hpos
, draw
);
26797 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26801 #ifdef HAVE_WINDOW_SYSTEM
26802 /* When we've written over the cursor, arrange for it to
26803 be displayed again. */
26804 if (FRAME_WINDOW_P (f
)
26805 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26807 int hpos
= w
->phys_cursor
.hpos
;
26809 /* When the window is hscrolled, cursor hpos can legitimately be
26810 out of bounds, but we draw the cursor at the corresponding
26811 window margin in that case. */
26812 if (!row
->reversed_p
&& hpos
< 0)
26814 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26815 hpos
= row
->used
[TEXT_AREA
] - 1;
26818 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26819 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26822 #endif /* HAVE_WINDOW_SYSTEM */
26825 #ifdef HAVE_WINDOW_SYSTEM
26826 /* Change the mouse cursor. */
26827 if (FRAME_WINDOW_P (f
))
26829 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
26830 if (draw
== DRAW_NORMAL_TEXT
26831 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26832 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26835 if (draw
== DRAW_MOUSE_FACE
)
26836 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26838 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26840 #endif /* HAVE_WINDOW_SYSTEM */
26844 Clear out the mouse-highlighted active region.
26845 Redraw it un-highlighted first. Value is non-zero if mouse
26846 face was actually drawn unhighlighted. */
26849 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26853 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26855 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26859 reset_mouse_highlight (hlinfo
);
26863 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26864 within the mouse face on that window. */
26866 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26868 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26870 /* Quickly resolve the easy cases. */
26871 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26872 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26874 if (vpos
< hlinfo
->mouse_face_beg_row
26875 || vpos
> hlinfo
->mouse_face_end_row
)
26877 if (vpos
> hlinfo
->mouse_face_beg_row
26878 && vpos
< hlinfo
->mouse_face_end_row
)
26881 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26883 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26885 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26888 else if ((vpos
== hlinfo
->mouse_face_beg_row
26889 && hpos
>= hlinfo
->mouse_face_beg_col
)
26890 || (vpos
== hlinfo
->mouse_face_end_row
26891 && hpos
< hlinfo
->mouse_face_end_col
))
26896 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26898 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26901 else if ((vpos
== hlinfo
->mouse_face_beg_row
26902 && hpos
<= hlinfo
->mouse_face_beg_col
)
26903 || (vpos
== hlinfo
->mouse_face_end_row
26904 && hpos
> hlinfo
->mouse_face_end_col
))
26912 Non-zero if physical cursor of window W is within mouse face. */
26915 cursor_in_mouse_face_p (struct window
*w
)
26917 int hpos
= w
->phys_cursor
.hpos
;
26918 int vpos
= w
->phys_cursor
.vpos
;
26919 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26921 /* When the window is hscrolled, cursor hpos can legitimately be out
26922 of bounds, but we draw the cursor at the corresponding window
26923 margin in that case. */
26924 if (!row
->reversed_p
&& hpos
< 0)
26926 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26927 hpos
= row
->used
[TEXT_AREA
] - 1;
26929 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26934 /* Find the glyph rows START_ROW and END_ROW of window W that display
26935 characters between buffer positions START_CHARPOS and END_CHARPOS
26936 (excluding END_CHARPOS). DISP_STRING is a display string that
26937 covers these buffer positions. This is similar to
26938 row_containing_pos, but is more accurate when bidi reordering makes
26939 buffer positions change non-linearly with glyph rows. */
26941 rows_from_pos_range (struct window
*w
,
26942 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26943 Lisp_Object disp_string
,
26944 struct glyph_row
**start
, struct glyph_row
**end
)
26946 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26947 int last_y
= window_text_bottom_y (w
);
26948 struct glyph_row
*row
;
26953 while (!first
->enabled_p
26954 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26957 /* Find the START row. */
26959 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26962 /* A row can potentially be the START row if the range of the
26963 characters it displays intersects the range
26964 [START_CHARPOS..END_CHARPOS). */
26965 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26966 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26967 /* See the commentary in row_containing_pos, for the
26968 explanation of the complicated way to check whether
26969 some position is beyond the end of the characters
26970 displayed by a row. */
26971 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26972 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26973 && !row
->ends_at_zv_p
26974 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26975 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26976 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26977 && !row
->ends_at_zv_p
26978 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26980 /* Found a candidate row. Now make sure at least one of the
26981 glyphs it displays has a charpos from the range
26982 [START_CHARPOS..END_CHARPOS).
26984 This is not obvious because bidi reordering could make
26985 buffer positions of a row be 1,2,3,102,101,100, and if we
26986 want to highlight characters in [50..60), we don't want
26987 this row, even though [50..60) does intersect [1..103),
26988 the range of character positions given by the row's start
26989 and end positions. */
26990 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26991 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26995 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26996 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26997 /* A glyph that comes from DISP_STRING is by
26998 definition to be highlighted. */
26999 || EQ (g
->object
, disp_string
))
27008 /* Find the END row. */
27010 /* If the last row is partially visible, start looking for END
27011 from that row, instead of starting from FIRST. */
27012 && !(row
->enabled_p
27013 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27015 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27017 struct glyph_row
*next
= row
+ 1;
27018 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27020 if (!next
->enabled_p
27021 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27022 /* The first row >= START whose range of displayed characters
27023 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27024 is the row END + 1. */
27025 || (start_charpos
< next_start
27026 && end_charpos
< next_start
)
27027 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27028 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27029 && !next
->ends_at_zv_p
27030 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27031 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27032 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27033 && !next
->ends_at_zv_p
27034 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27041 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27042 but none of the characters it displays are in the range, it is
27044 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27045 struct glyph
*s
= g
;
27046 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27050 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27051 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27052 /* If the buffer position of the first glyph in
27053 the row is equal to END_CHARPOS, it means
27054 the last character to be highlighted is the
27055 newline of ROW, and we must consider NEXT as
27057 || (((!next
->reversed_p
&& g
== s
)
27058 || (next
->reversed_p
&& g
== e
- 1))
27059 && (g
->charpos
== end_charpos
27060 /* Special case for when NEXT is an
27061 empty line at ZV. */
27062 || (g
->charpos
== -1
27063 && !row
->ends_at_zv_p
27064 && next_start
== end_charpos
)))))
27065 /* A glyph that comes from DISP_STRING is by
27066 definition to be highlighted. */
27067 || EQ (g
->object
, disp_string
))
27076 /* The first row that ends at ZV must be the last to be
27078 else if (next
->ends_at_zv_p
)
27087 /* This function sets the mouse_face_* elements of HLINFO, assuming
27088 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27089 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27090 for the overlay or run of text properties specifying the mouse
27091 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27092 before-string and after-string that must also be highlighted.
27093 DISP_STRING, if non-nil, is a display string that may cover some
27094 or all of the highlighted text. */
27097 mouse_face_from_buffer_pos (Lisp_Object window
,
27098 Mouse_HLInfo
*hlinfo
,
27099 ptrdiff_t mouse_charpos
,
27100 ptrdiff_t start_charpos
,
27101 ptrdiff_t end_charpos
,
27102 Lisp_Object before_string
,
27103 Lisp_Object after_string
,
27104 Lisp_Object disp_string
)
27106 struct window
*w
= XWINDOW (window
);
27107 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27108 struct glyph_row
*r1
, *r2
;
27109 struct glyph
*glyph
, *end
;
27110 ptrdiff_t ignore
, pos
;
27113 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27114 eassert (NILP (before_string
) || STRINGP (before_string
));
27115 eassert (NILP (after_string
) || STRINGP (after_string
));
27117 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27118 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27120 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27121 /* If the before-string or display-string contains newlines,
27122 rows_from_pos_range skips to its last row. Move back. */
27123 if (!NILP (before_string
) || !NILP (disp_string
))
27125 struct glyph_row
*prev
;
27126 while ((prev
= r1
- 1, prev
>= first
)
27127 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27128 && prev
->used
[TEXT_AREA
] > 0)
27130 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27131 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27132 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27134 || !(EQ (glyph
->object
, before_string
)
27135 || EQ (glyph
->object
, disp_string
)))
27142 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27143 hlinfo
->mouse_face_past_end
= 1;
27145 else if (!NILP (after_string
))
27147 /* If the after-string has newlines, advance to its last row. */
27148 struct glyph_row
*next
;
27149 struct glyph_row
*last
27150 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27152 for (next
= r2
+ 1;
27154 && next
->used
[TEXT_AREA
] > 0
27155 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27159 /* The rest of the display engine assumes that mouse_face_beg_row is
27160 either above mouse_face_end_row or identical to it. But with
27161 bidi-reordered continued lines, the row for START_CHARPOS could
27162 be below the row for END_CHARPOS. If so, swap the rows and store
27163 them in correct order. */
27166 struct glyph_row
*tem
= r2
;
27172 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27173 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27175 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27176 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27177 could be anywhere in the row and in any order. The strategy
27178 below is to find the leftmost and the rightmost glyph that
27179 belongs to either of these 3 strings, or whose position is
27180 between START_CHARPOS and END_CHARPOS, and highlight all the
27181 glyphs between those two. This may cover more than just the text
27182 between START_CHARPOS and END_CHARPOS if the range of characters
27183 strides the bidi level boundary, e.g. if the beginning is in R2L
27184 text while the end is in L2R text or vice versa. */
27185 if (!r1
->reversed_p
)
27187 /* This row is in a left to right paragraph. Scan it left to
27189 glyph
= r1
->glyphs
[TEXT_AREA
];
27190 end
= glyph
+ r1
->used
[TEXT_AREA
];
27193 /* Skip truncation glyphs at the start of the glyph row. */
27194 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27196 && INTEGERP (glyph
->object
)
27197 && glyph
->charpos
< 0;
27199 x
+= glyph
->pixel_width
;
27201 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27202 or DISP_STRING, and the first glyph from buffer whose
27203 position is between START_CHARPOS and END_CHARPOS. */
27205 && !INTEGERP (glyph
->object
)
27206 && !EQ (glyph
->object
, disp_string
)
27207 && !(BUFFERP (glyph
->object
)
27208 && (glyph
->charpos
>= start_charpos
27209 && glyph
->charpos
< end_charpos
));
27212 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27213 are present at buffer positions between START_CHARPOS and
27214 END_CHARPOS, or if they come from an overlay. */
27215 if (EQ (glyph
->object
, before_string
))
27217 pos
= string_buffer_position (before_string
,
27219 /* If pos == 0, it means before_string came from an
27220 overlay, not from a buffer position. */
27221 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27224 else if (EQ (glyph
->object
, after_string
))
27226 pos
= string_buffer_position (after_string
, end_charpos
);
27227 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27230 x
+= glyph
->pixel_width
;
27232 hlinfo
->mouse_face_beg_x
= x
;
27233 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27237 /* This row is in a right to left paragraph. Scan it right to
27241 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27242 glyph
= end
+ r1
->used
[TEXT_AREA
];
27244 /* Skip truncation glyphs at the start of the glyph row. */
27245 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27247 && INTEGERP (glyph
->object
)
27248 && glyph
->charpos
< 0;
27252 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27253 or DISP_STRING, and the first glyph from buffer whose
27254 position is between START_CHARPOS and END_CHARPOS. */
27256 && !INTEGERP (glyph
->object
)
27257 && !EQ (glyph
->object
, disp_string
)
27258 && !(BUFFERP (glyph
->object
)
27259 && (glyph
->charpos
>= start_charpos
27260 && glyph
->charpos
< end_charpos
));
27263 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27264 are present at buffer positions between START_CHARPOS and
27265 END_CHARPOS, or if they come from an overlay. */
27266 if (EQ (glyph
->object
, before_string
))
27268 pos
= string_buffer_position (before_string
, start_charpos
);
27269 /* If pos == 0, it means before_string came from an
27270 overlay, not from a buffer position. */
27271 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27274 else if (EQ (glyph
->object
, after_string
))
27276 pos
= string_buffer_position (after_string
, end_charpos
);
27277 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27282 glyph
++; /* first glyph to the right of the highlighted area */
27283 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27284 x
+= g
->pixel_width
;
27285 hlinfo
->mouse_face_beg_x
= x
;
27286 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27289 /* If the highlight ends in a different row, compute GLYPH and END
27290 for the end row. Otherwise, reuse the values computed above for
27291 the row where the highlight begins. */
27294 if (!r2
->reversed_p
)
27296 glyph
= r2
->glyphs
[TEXT_AREA
];
27297 end
= glyph
+ r2
->used
[TEXT_AREA
];
27302 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27303 glyph
= end
+ r2
->used
[TEXT_AREA
];
27307 if (!r2
->reversed_p
)
27309 /* Skip truncation and continuation glyphs near the end of the
27310 row, and also blanks and stretch glyphs inserted by
27311 extend_face_to_end_of_line. */
27313 && INTEGERP ((end
- 1)->object
))
27315 /* Scan the rest of the glyph row from the end, looking for the
27316 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27317 DISP_STRING, or whose position is between START_CHARPOS
27321 && !INTEGERP (end
->object
)
27322 && !EQ (end
->object
, disp_string
)
27323 && !(BUFFERP (end
->object
)
27324 && (end
->charpos
>= start_charpos
27325 && end
->charpos
< end_charpos
));
27328 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27329 are present at buffer positions between START_CHARPOS and
27330 END_CHARPOS, or if they come from an overlay. */
27331 if (EQ (end
->object
, before_string
))
27333 pos
= string_buffer_position (before_string
, start_charpos
);
27334 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27337 else if (EQ (end
->object
, after_string
))
27339 pos
= string_buffer_position (after_string
, end_charpos
);
27340 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27344 /* Find the X coordinate of the last glyph to be highlighted. */
27345 for (; glyph
<= end
; ++glyph
)
27346 x
+= glyph
->pixel_width
;
27348 hlinfo
->mouse_face_end_x
= x
;
27349 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27353 /* Skip truncation and continuation glyphs near the end of the
27354 row, and also blanks and stretch glyphs inserted by
27355 extend_face_to_end_of_line. */
27359 && INTEGERP (end
->object
))
27361 x
+= end
->pixel_width
;
27364 /* Scan the rest of the glyph row from the end, looking for the
27365 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27366 DISP_STRING, or whose position is between START_CHARPOS
27370 && !INTEGERP (end
->object
)
27371 && !EQ (end
->object
, disp_string
)
27372 && !(BUFFERP (end
->object
)
27373 && (end
->charpos
>= start_charpos
27374 && end
->charpos
< end_charpos
));
27377 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27378 are present at buffer positions between START_CHARPOS and
27379 END_CHARPOS, or if they come from an overlay. */
27380 if (EQ (end
->object
, before_string
))
27382 pos
= string_buffer_position (before_string
, start_charpos
);
27383 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27386 else if (EQ (end
->object
, after_string
))
27388 pos
= string_buffer_position (after_string
, end_charpos
);
27389 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27392 x
+= end
->pixel_width
;
27394 /* If we exited the above loop because we arrived at the last
27395 glyph of the row, and its buffer position is still not in
27396 range, it means the last character in range is the preceding
27397 newline. Bump the end column and x values to get past the
27400 && BUFFERP (end
->object
)
27401 && (end
->charpos
< start_charpos
27402 || end
->charpos
>= end_charpos
))
27404 x
+= end
->pixel_width
;
27407 hlinfo
->mouse_face_end_x
= x
;
27408 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27411 hlinfo
->mouse_face_window
= window
;
27412 hlinfo
->mouse_face_face_id
27413 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27415 !hlinfo
->mouse_face_hidden
, -1);
27416 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27419 /* The following function is not used anymore (replaced with
27420 mouse_face_from_string_pos), but I leave it here for the time
27421 being, in case someone would. */
27423 #if 0 /* not used */
27425 /* Find the position of the glyph for position POS in OBJECT in
27426 window W's current matrix, and return in *X, *Y the pixel
27427 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27429 RIGHT_P non-zero means return the position of the right edge of the
27430 glyph, RIGHT_P zero means return the left edge position.
27432 If no glyph for POS exists in the matrix, return the position of
27433 the glyph with the next smaller position that is in the matrix, if
27434 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27435 exists in the matrix, return the position of the glyph with the
27436 next larger position in OBJECT.
27438 Value is non-zero if a glyph was found. */
27441 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27442 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27444 int yb
= window_text_bottom_y (w
);
27445 struct glyph_row
*r
;
27446 struct glyph
*best_glyph
= NULL
;
27447 struct glyph_row
*best_row
= NULL
;
27450 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27451 r
->enabled_p
&& r
->y
< yb
;
27454 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27455 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27458 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27459 if (EQ (g
->object
, object
))
27461 if (g
->charpos
== pos
)
27468 else if (best_glyph
== NULL
27469 || ((eabs (g
->charpos
- pos
)
27470 < eabs (best_glyph
->charpos
- pos
))
27473 : g
->charpos
> pos
)))
27487 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27491 *x
+= best_glyph
->pixel_width
;
27496 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27499 return best_glyph
!= NULL
;
27501 #endif /* not used */
27503 /* Find the positions of the first and the last glyphs in window W's
27504 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27505 (assumed to be a string), and return in HLINFO's mouse_face_*
27506 members the pixel and column/row coordinates of those glyphs. */
27509 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27510 Lisp_Object object
,
27511 ptrdiff_t startpos
, ptrdiff_t endpos
)
27513 int yb
= window_text_bottom_y (w
);
27514 struct glyph_row
*r
;
27515 struct glyph
*g
, *e
;
27519 /* Find the glyph row with at least one position in the range
27520 [STARTPOS..ENDPOS), and the first glyph in that row whose
27521 position belongs to that range. */
27522 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27523 r
->enabled_p
&& r
->y
< yb
;
27526 if (!r
->reversed_p
)
27528 g
= r
->glyphs
[TEXT_AREA
];
27529 e
= g
+ r
->used
[TEXT_AREA
];
27530 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27531 if (EQ (g
->object
, object
)
27532 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27534 hlinfo
->mouse_face_beg_row
27535 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27536 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27537 hlinfo
->mouse_face_beg_x
= gx
;
27546 e
= r
->glyphs
[TEXT_AREA
];
27547 g
= e
+ r
->used
[TEXT_AREA
];
27548 for ( ; g
> e
; --g
)
27549 if (EQ ((g
-1)->object
, object
)
27550 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27552 hlinfo
->mouse_face_beg_row
27553 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27554 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27555 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27556 gx
+= g1
->pixel_width
;
27557 hlinfo
->mouse_face_beg_x
= gx
;
27569 /* Starting with the next row, look for the first row which does NOT
27570 include any glyphs whose positions are in the range. */
27571 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27573 g
= r
->glyphs
[TEXT_AREA
];
27574 e
= g
+ r
->used
[TEXT_AREA
];
27576 for ( ; g
< e
; ++g
)
27577 if (EQ (g
->object
, object
)
27578 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27587 /* The highlighted region ends on the previous row. */
27590 /* Set the end row. */
27591 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27593 /* Compute and set the end column and the end column's horizontal
27594 pixel coordinate. */
27595 if (!r
->reversed_p
)
27597 g
= r
->glyphs
[TEXT_AREA
];
27598 e
= g
+ r
->used
[TEXT_AREA
];
27599 for ( ; e
> g
; --e
)
27600 if (EQ ((e
-1)->object
, object
)
27601 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27603 hlinfo
->mouse_face_end_col
= e
- g
;
27605 for (gx
= r
->x
; g
< e
; ++g
)
27606 gx
+= g
->pixel_width
;
27607 hlinfo
->mouse_face_end_x
= gx
;
27611 e
= r
->glyphs
[TEXT_AREA
];
27612 g
= e
+ r
->used
[TEXT_AREA
];
27613 for (gx
= r
->x
; e
< g
; ++e
)
27615 if (EQ (e
->object
, object
)
27616 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27618 gx
+= e
->pixel_width
;
27620 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27621 hlinfo
->mouse_face_end_x
= gx
;
27625 #ifdef HAVE_WINDOW_SYSTEM
27627 /* See if position X, Y is within a hot-spot of an image. */
27630 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27632 if (!CONSP (hot_spot
))
27635 if (EQ (XCAR (hot_spot
), Qrect
))
27637 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27638 Lisp_Object rect
= XCDR (hot_spot
);
27642 if (!CONSP (XCAR (rect
)))
27644 if (!CONSP (XCDR (rect
)))
27646 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27648 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27650 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27652 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27656 else if (EQ (XCAR (hot_spot
), Qcircle
))
27658 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27659 Lisp_Object circ
= XCDR (hot_spot
);
27660 Lisp_Object lr
, lx0
, ly0
;
27662 && CONSP (XCAR (circ
))
27663 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27664 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27665 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27667 double r
= XFLOATINT (lr
);
27668 double dx
= XINT (lx0
) - x
;
27669 double dy
= XINT (ly0
) - y
;
27670 return (dx
* dx
+ dy
* dy
<= r
* r
);
27673 else if (EQ (XCAR (hot_spot
), Qpoly
))
27675 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27676 if (VECTORP (XCDR (hot_spot
)))
27678 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27679 Lisp_Object
*poly
= v
->u
.contents
;
27680 ptrdiff_t n
= v
->header
.size
;
27683 Lisp_Object lx
, ly
;
27686 /* Need an even number of coordinates, and at least 3 edges. */
27687 if (n
< 6 || n
& 1)
27690 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27691 If count is odd, we are inside polygon. Pixels on edges
27692 may or may not be included depending on actual geometry of the
27694 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27695 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27697 x0
= XINT (lx
), y0
= XINT (ly
);
27698 for (i
= 0; i
< n
; i
+= 2)
27700 int x1
= x0
, y1
= y0
;
27701 if ((lx
= poly
[i
], !INTEGERP (lx
))
27702 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27704 x0
= XINT (lx
), y0
= XINT (ly
);
27706 /* Does this segment cross the X line? */
27714 if (y
> y0
&& y
> y1
)
27716 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27726 find_hot_spot (Lisp_Object map
, int x
, int y
)
27728 while (CONSP (map
))
27730 if (CONSP (XCAR (map
))
27731 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27739 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27741 doc
: /* Lookup in image map MAP coordinates X and Y.
27742 An image map is an alist where each element has the format (AREA ID PLIST).
27743 An AREA is specified as either a rectangle, a circle, or a polygon:
27744 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27745 pixel coordinates of the upper left and bottom right corners.
27746 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27747 and the radius of the circle; r may be a float or integer.
27748 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27749 vector describes one corner in the polygon.
27750 Returns the alist element for the first matching AREA in MAP. */)
27751 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27759 return find_hot_spot (map
,
27760 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27761 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27765 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27767 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27769 /* Do not change cursor shape while dragging mouse. */
27770 if (!NILP (do_mouse_tracking
))
27773 if (!NILP (pointer
))
27775 if (EQ (pointer
, Qarrow
))
27776 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27777 else if (EQ (pointer
, Qhand
))
27778 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27779 else if (EQ (pointer
, Qtext
))
27780 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27781 else if (EQ (pointer
, intern ("hdrag")))
27782 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27783 #ifdef HAVE_X_WINDOWS
27784 else if (EQ (pointer
, intern ("vdrag")))
27785 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27787 else if (EQ (pointer
, intern ("hourglass")))
27788 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27789 else if (EQ (pointer
, Qmodeline
))
27790 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27792 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27795 if (cursor
!= No_Cursor
)
27796 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27799 #endif /* HAVE_WINDOW_SYSTEM */
27801 /* Take proper action when mouse has moved to the mode or header line
27802 or marginal area AREA of window W, x-position X and y-position Y.
27803 X is relative to the start of the text display area of W, so the
27804 width of bitmap areas and scroll bars must be subtracted to get a
27805 position relative to the start of the mode line. */
27808 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27809 enum window_part area
)
27811 struct window
*w
= XWINDOW (window
);
27812 struct frame
*f
= XFRAME (w
->frame
);
27813 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27814 #ifdef HAVE_WINDOW_SYSTEM
27815 Display_Info
*dpyinfo
;
27817 Cursor cursor
= No_Cursor
;
27818 Lisp_Object pointer
= Qnil
;
27819 int dx
, dy
, width
, height
;
27821 Lisp_Object string
, object
= Qnil
;
27822 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27824 Lisp_Object mouse_face
;
27825 int original_x_pixel
= x
;
27826 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27827 struct glyph_row
*row
IF_LINT (= 0);
27829 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27834 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27835 returns them in row/column units! */
27836 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27837 &object
, &dx
, &dy
, &width
, &height
);
27839 row
= (area
== ON_MODE_LINE
27840 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27841 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27843 /* Find the glyph under the mouse pointer. */
27844 if (row
->mode_line_p
&& row
->enabled_p
)
27846 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27847 end
= glyph
+ row
->used
[TEXT_AREA
];
27849 for (x0
= original_x_pixel
;
27850 glyph
< end
&& x0
>= glyph
->pixel_width
;
27852 x0
-= glyph
->pixel_width
;
27860 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27861 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27862 returns them in row/column units! */
27863 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27864 &object
, &dx
, &dy
, &width
, &height
);
27869 #ifdef HAVE_WINDOW_SYSTEM
27870 if (IMAGEP (object
))
27872 Lisp_Object image_map
, hotspot
;
27873 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27875 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27877 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27881 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27882 If so, we could look for mouse-enter, mouse-leave
27883 properties in PLIST (and do something...). */
27884 hotspot
= XCDR (hotspot
);
27885 if (CONSP (hotspot
)
27886 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27888 pointer
= Fplist_get (plist
, Qpointer
);
27889 if (NILP (pointer
))
27891 help
= Fplist_get (plist
, Qhelp_echo
);
27894 help_echo_string
= help
;
27895 XSETWINDOW (help_echo_window
, w
);
27896 help_echo_object
= w
->contents
;
27897 help_echo_pos
= charpos
;
27901 if (NILP (pointer
))
27902 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27904 #endif /* HAVE_WINDOW_SYSTEM */
27906 if (STRINGP (string
))
27907 pos
= make_number (charpos
);
27909 /* Set the help text and mouse pointer. If the mouse is on a part
27910 of the mode line without any text (e.g. past the right edge of
27911 the mode line text), use the default help text and pointer. */
27912 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27914 /* Arrange to display the help by setting the global variables
27915 help_echo_string, help_echo_object, and help_echo_pos. */
27918 if (STRINGP (string
))
27919 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27923 help_echo_string
= help
;
27924 XSETWINDOW (help_echo_window
, w
);
27925 help_echo_object
= string
;
27926 help_echo_pos
= charpos
;
27928 else if (area
== ON_MODE_LINE
)
27930 Lisp_Object default_help
27931 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27934 if (STRINGP (default_help
))
27936 help_echo_string
= default_help
;
27937 XSETWINDOW (help_echo_window
, w
);
27938 help_echo_object
= Qnil
;
27939 help_echo_pos
= -1;
27944 #ifdef HAVE_WINDOW_SYSTEM
27945 /* Change the mouse pointer according to what is under it. */
27946 if (FRAME_WINDOW_P (f
))
27948 dpyinfo
= FRAME_DISPLAY_INFO (f
);
27949 if (STRINGP (string
))
27951 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27953 if (NILP (pointer
))
27954 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27956 /* Change the mouse pointer according to what is under X/Y. */
27958 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27961 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27962 if (!KEYMAPP (map
))
27963 map
= Fget_text_property (pos
, Qkeymap
, string
);
27964 if (!KEYMAPP (map
))
27965 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27969 /* Default mode-line pointer. */
27970 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27975 /* Change the mouse face according to what is under X/Y. */
27976 if (STRINGP (string
))
27978 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27979 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
27980 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27985 struct glyph
* tmp_glyph
;
27989 int total_pixel_width
;
27990 ptrdiff_t begpos
, endpos
, ignore
;
27994 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27995 Qmouse_face
, string
, Qnil
);
28001 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28003 endpos
= SCHARS (string
);
28007 /* Calculate the glyph position GPOS of GLYPH in the
28008 displayed string, relative to the beginning of the
28009 highlighted part of the string.
28011 Note: GPOS is different from CHARPOS. CHARPOS is the
28012 position of GLYPH in the internal string object. A mode
28013 line string format has structures which are converted to
28014 a flattened string by the Emacs Lisp interpreter. The
28015 internal string is an element of those structures. The
28016 displayed string is the flattened string. */
28017 tmp_glyph
= row_start_glyph
;
28018 while (tmp_glyph
< glyph
28019 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28020 && begpos
<= tmp_glyph
->charpos
28021 && tmp_glyph
->charpos
< endpos
)))
28023 gpos
= glyph
- tmp_glyph
;
28025 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28026 the highlighted part of the displayed string to which
28027 GLYPH belongs. Note: GSEQ_LENGTH is different from
28028 SCHARS (STRING), because the latter returns the length of
28029 the internal string. */
28030 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28032 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28033 && begpos
<= tmp_glyph
->charpos
28034 && tmp_glyph
->charpos
< endpos
));
28037 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28039 /* Calculate the total pixel width of all the glyphs between
28040 the beginning of the highlighted area and GLYPH. */
28041 total_pixel_width
= 0;
28042 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28043 total_pixel_width
+= tmp_glyph
->pixel_width
;
28045 /* Pre calculation of re-rendering position. Note: X is in
28046 column units here, after the call to mode_line_string or
28047 marginal_area_string. */
28049 vpos
= (area
== ON_MODE_LINE
28050 ? (w
->current_matrix
)->nrows
- 1
28053 /* If GLYPH's position is included in the region that is
28054 already drawn in mouse face, we have nothing to do. */
28055 if ( EQ (window
, hlinfo
->mouse_face_window
)
28056 && (!row
->reversed_p
28057 ? (hlinfo
->mouse_face_beg_col
<= hpos
28058 && hpos
< hlinfo
->mouse_face_end_col
)
28059 /* In R2L rows we swap BEG and END, see below. */
28060 : (hlinfo
->mouse_face_end_col
<= hpos
28061 && hpos
< hlinfo
->mouse_face_beg_col
))
28062 && hlinfo
->mouse_face_beg_row
== vpos
)
28065 if (clear_mouse_face (hlinfo
))
28066 cursor
= No_Cursor
;
28068 if (!row
->reversed_p
)
28070 hlinfo
->mouse_face_beg_col
= hpos
;
28071 hlinfo
->mouse_face_beg_x
= original_x_pixel
28072 - (total_pixel_width
+ dx
);
28073 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28074 hlinfo
->mouse_face_end_x
= 0;
28078 /* In R2L rows, show_mouse_face expects BEG and END
28079 coordinates to be swapped. */
28080 hlinfo
->mouse_face_end_col
= hpos
;
28081 hlinfo
->mouse_face_end_x
= original_x_pixel
28082 - (total_pixel_width
+ dx
);
28083 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28084 hlinfo
->mouse_face_beg_x
= 0;
28087 hlinfo
->mouse_face_beg_row
= vpos
;
28088 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28089 hlinfo
->mouse_face_past_end
= 0;
28090 hlinfo
->mouse_face_window
= window
;
28092 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28098 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28100 if (NILP (pointer
))
28103 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28104 clear_mouse_face (hlinfo
);
28106 #ifdef HAVE_WINDOW_SYSTEM
28107 if (FRAME_WINDOW_P (f
))
28108 define_frame_cursor1 (f
, cursor
, pointer
);
28114 Take proper action when the mouse has moved to position X, Y on
28115 frame F with regards to highlighting portions of display that have
28116 mouse-face properties. Also de-highlight portions of display where
28117 the mouse was before, set the mouse pointer shape as appropriate
28118 for the mouse coordinates, and activate help echo (tooltips).
28119 X and Y can be negative or out of range. */
28122 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28124 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28125 enum window_part part
= ON_NOTHING
;
28126 Lisp_Object window
;
28128 Cursor cursor
= No_Cursor
;
28129 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28132 /* When a menu is active, don't highlight because this looks odd. */
28133 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28134 if (popup_activated ())
28138 if (!f
->glyphs_initialized_p
28139 || f
->pointer_invisible
)
28142 hlinfo
->mouse_face_mouse_x
= x
;
28143 hlinfo
->mouse_face_mouse_y
= y
;
28144 hlinfo
->mouse_face_mouse_frame
= f
;
28146 if (hlinfo
->mouse_face_defer
)
28149 /* Which window is that in? */
28150 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28152 /* If displaying active text in another window, clear that. */
28153 if (! EQ (window
, hlinfo
->mouse_face_window
)
28154 /* Also clear if we move out of text area in same window. */
28155 || (!NILP (hlinfo
->mouse_face_window
)
28158 && part
!= ON_MODE_LINE
28159 && part
!= ON_HEADER_LINE
))
28160 clear_mouse_face (hlinfo
);
28162 /* Not on a window -> return. */
28163 if (!WINDOWP (window
))
28166 /* Reset help_echo_string. It will get recomputed below. */
28167 help_echo_string
= Qnil
;
28169 /* Convert to window-relative pixel coordinates. */
28170 w
= XWINDOW (window
);
28171 frame_to_window_pixel_xy (w
, &x
, &y
);
28173 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28174 /* Handle tool-bar window differently since it doesn't display a
28176 if (EQ (window
, f
->tool_bar_window
))
28178 note_tool_bar_highlight (f
, x
, y
);
28183 /* Mouse is on the mode, header line or margin? */
28184 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28185 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28187 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28191 #ifdef HAVE_WINDOW_SYSTEM
28192 if (part
== ON_VERTICAL_BORDER
)
28194 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28195 help_echo_string
= build_string ("drag-mouse-1: resize");
28197 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28198 || part
== ON_SCROLL_BAR
)
28199 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28201 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28204 /* Are we in a window whose display is up to date?
28205 And verify the buffer's text has not changed. */
28206 b
= XBUFFER (w
->contents
);
28207 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28209 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28211 struct glyph
*glyph
;
28212 Lisp_Object object
;
28213 Lisp_Object mouse_face
= Qnil
, position
;
28214 Lisp_Object
*overlay_vec
= NULL
;
28215 ptrdiff_t i
, noverlays
;
28216 struct buffer
*obuf
;
28217 ptrdiff_t obegv
, ozv
;
28220 /* Find the glyph under X/Y. */
28221 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28223 #ifdef HAVE_WINDOW_SYSTEM
28224 /* Look for :pointer property on image. */
28225 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28227 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28228 if (img
!= NULL
&& IMAGEP (img
->spec
))
28230 Lisp_Object image_map
, hotspot
;
28231 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28233 && (hotspot
= find_hot_spot (image_map
,
28234 glyph
->slice
.img
.x
+ dx
,
28235 glyph
->slice
.img
.y
+ dy
),
28237 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28241 /* Could check XCAR (hotspot) to see if we enter/leave
28243 If so, we could look for mouse-enter, mouse-leave
28244 properties in PLIST (and do something...). */
28245 hotspot
= XCDR (hotspot
);
28246 if (CONSP (hotspot
)
28247 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28249 pointer
= Fplist_get (plist
, Qpointer
);
28250 if (NILP (pointer
))
28252 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28253 if (!NILP (help_echo_string
))
28255 help_echo_window
= window
;
28256 help_echo_object
= glyph
->object
;
28257 help_echo_pos
= glyph
->charpos
;
28261 if (NILP (pointer
))
28262 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28265 #endif /* HAVE_WINDOW_SYSTEM */
28267 /* Clear mouse face if X/Y not over text. */
28269 || area
!= TEXT_AREA
28270 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28271 /* Glyph's OBJECT is an integer for glyphs inserted by the
28272 display engine for its internal purposes, like truncation
28273 and continuation glyphs and blanks beyond the end of
28274 line's text on text terminals. If we are over such a
28275 glyph, we are not over any text. */
28276 || INTEGERP (glyph
->object
)
28277 /* R2L rows have a stretch glyph at their front, which
28278 stands for no text, whereas L2R rows have no glyphs at
28279 all beyond the end of text. Treat such stretch glyphs
28280 like we do with NULL glyphs in L2R rows. */
28281 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28282 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28283 && glyph
->type
== STRETCH_GLYPH
28284 && glyph
->avoid_cursor_p
))
28286 if (clear_mouse_face (hlinfo
))
28287 cursor
= No_Cursor
;
28288 #ifdef HAVE_WINDOW_SYSTEM
28289 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28291 if (area
!= TEXT_AREA
)
28292 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28294 pointer
= Vvoid_text_area_pointer
;
28300 pos
= glyph
->charpos
;
28301 object
= glyph
->object
;
28302 if (!STRINGP (object
) && !BUFFERP (object
))
28305 /* If we get an out-of-range value, return now; avoid an error. */
28306 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28309 /* Make the window's buffer temporarily current for
28310 overlays_at and compute_char_face. */
28311 obuf
= current_buffer
;
28312 current_buffer
= b
;
28318 /* Is this char mouse-active or does it have help-echo? */
28319 position
= make_number (pos
);
28321 if (BUFFERP (object
))
28323 /* Put all the overlays we want in a vector in overlay_vec. */
28324 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28325 /* Sort overlays into increasing priority order. */
28326 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28331 if (NILP (Vmouse_highlight
))
28333 clear_mouse_face (hlinfo
);
28334 goto check_help_echo
;
28337 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28340 cursor
= No_Cursor
;
28342 /* Check mouse-face highlighting. */
28344 /* If there exists an overlay with mouse-face overlapping
28345 the one we are currently highlighting, we have to
28346 check if we enter the overlapping overlay, and then
28347 highlight only that. */
28348 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28349 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28351 /* Find the highest priority overlay with a mouse-face. */
28352 Lisp_Object overlay
= Qnil
;
28353 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28355 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28356 if (!NILP (mouse_face
))
28357 overlay
= overlay_vec
[i
];
28360 /* If we're highlighting the same overlay as before, there's
28361 no need to do that again. */
28362 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28363 goto check_help_echo
;
28364 hlinfo
->mouse_face_overlay
= overlay
;
28366 /* Clear the display of the old active region, if any. */
28367 if (clear_mouse_face (hlinfo
))
28368 cursor
= No_Cursor
;
28370 /* If no overlay applies, get a text property. */
28371 if (NILP (overlay
))
28372 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28374 /* Next, compute the bounds of the mouse highlighting and
28376 if (!NILP (mouse_face
) && STRINGP (object
))
28378 /* The mouse-highlighting comes from a display string
28379 with a mouse-face. */
28383 s
= Fprevious_single_property_change
28384 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28385 e
= Fnext_single_property_change
28386 (position
, Qmouse_face
, object
, Qnil
);
28388 s
= make_number (0);
28390 e
= make_number (SCHARS (object
));
28391 mouse_face_from_string_pos (w
, hlinfo
, object
,
28392 XINT (s
), XINT (e
));
28393 hlinfo
->mouse_face_past_end
= 0;
28394 hlinfo
->mouse_face_window
= window
;
28395 hlinfo
->mouse_face_face_id
28396 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28397 glyph
->face_id
, 1);
28398 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28399 cursor
= No_Cursor
;
28403 /* The mouse-highlighting, if any, comes from an overlay
28404 or text property in the buffer. */
28405 Lisp_Object buffer
IF_LINT (= Qnil
);
28406 Lisp_Object disp_string
IF_LINT (= Qnil
);
28408 if (STRINGP (object
))
28410 /* If we are on a display string with no mouse-face,
28411 check if the text under it has one. */
28412 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28413 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28414 pos
= string_buffer_position (object
, start
);
28417 mouse_face
= get_char_property_and_overlay
28418 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28419 buffer
= w
->contents
;
28420 disp_string
= object
;
28426 disp_string
= Qnil
;
28429 if (!NILP (mouse_face
))
28431 Lisp_Object before
, after
;
28432 Lisp_Object before_string
, after_string
;
28433 /* To correctly find the limits of mouse highlight
28434 in a bidi-reordered buffer, we must not use the
28435 optimization of limiting the search in
28436 previous-single-property-change and
28437 next-single-property-change, because
28438 rows_from_pos_range needs the real start and end
28439 positions to DTRT in this case. That's because
28440 the first row visible in a window does not
28441 necessarily display the character whose position
28442 is the smallest. */
28444 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28445 ? Fmarker_position (w
->start
)
28448 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28449 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28452 if (NILP (overlay
))
28454 /* Handle the text property case. */
28455 before
= Fprevious_single_property_change
28456 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28457 after
= Fnext_single_property_change
28458 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28459 before_string
= after_string
= Qnil
;
28463 /* Handle the overlay case. */
28464 before
= Foverlay_start (overlay
);
28465 after
= Foverlay_end (overlay
);
28466 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28467 after_string
= Foverlay_get (overlay
, Qafter_string
);
28469 if (!STRINGP (before_string
)) before_string
= Qnil
;
28470 if (!STRINGP (after_string
)) after_string
= Qnil
;
28473 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28476 : XFASTINT (before
),
28478 ? BUF_Z (XBUFFER (buffer
))
28479 : XFASTINT (after
),
28480 before_string
, after_string
,
28482 cursor
= No_Cursor
;
28489 /* Look for a `help-echo' property. */
28490 if (NILP (help_echo_string
)) {
28491 Lisp_Object help
, overlay
;
28493 /* Check overlays first. */
28494 help
= overlay
= Qnil
;
28495 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28497 overlay
= overlay_vec
[i
];
28498 help
= Foverlay_get (overlay
, Qhelp_echo
);
28503 help_echo_string
= help
;
28504 help_echo_window
= window
;
28505 help_echo_object
= overlay
;
28506 help_echo_pos
= pos
;
28510 Lisp_Object obj
= glyph
->object
;
28511 ptrdiff_t charpos
= glyph
->charpos
;
28513 /* Try text properties. */
28516 && charpos
< SCHARS (obj
))
28518 help
= Fget_text_property (make_number (charpos
),
28522 /* If the string itself doesn't specify a help-echo,
28523 see if the buffer text ``under'' it does. */
28524 struct glyph_row
*r
28525 = MATRIX_ROW (w
->current_matrix
, vpos
);
28526 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28527 ptrdiff_t p
= string_buffer_position (obj
, start
);
28530 help
= Fget_char_property (make_number (p
),
28531 Qhelp_echo
, w
->contents
);
28540 else if (BUFFERP (obj
)
28543 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28548 help_echo_string
= help
;
28549 help_echo_window
= window
;
28550 help_echo_object
= obj
;
28551 help_echo_pos
= charpos
;
28556 #ifdef HAVE_WINDOW_SYSTEM
28557 /* Look for a `pointer' property. */
28558 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28560 /* Check overlays first. */
28561 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28562 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28564 if (NILP (pointer
))
28566 Lisp_Object obj
= glyph
->object
;
28567 ptrdiff_t charpos
= glyph
->charpos
;
28569 /* Try text properties. */
28572 && charpos
< SCHARS (obj
))
28574 pointer
= Fget_text_property (make_number (charpos
),
28576 if (NILP (pointer
))
28578 /* If the string itself doesn't specify a pointer,
28579 see if the buffer text ``under'' it does. */
28580 struct glyph_row
*r
28581 = MATRIX_ROW (w
->current_matrix
, vpos
);
28582 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28583 ptrdiff_t p
= string_buffer_position (obj
, start
);
28585 pointer
= Fget_char_property (make_number (p
),
28586 Qpointer
, w
->contents
);
28589 else if (BUFFERP (obj
)
28592 pointer
= Fget_text_property (make_number (charpos
),
28596 #endif /* HAVE_WINDOW_SYSTEM */
28600 current_buffer
= obuf
;
28605 #ifdef HAVE_WINDOW_SYSTEM
28606 if (FRAME_WINDOW_P (f
))
28607 define_frame_cursor1 (f
, cursor
, pointer
);
28609 /* This is here to prevent a compiler error, about "label at end of
28610 compound statement". */
28617 Clear any mouse-face on window W. This function is part of the
28618 redisplay interface, and is called from try_window_id and similar
28619 functions to ensure the mouse-highlight is off. */
28622 x_clear_window_mouse_face (struct window
*w
)
28624 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28625 Lisp_Object window
;
28628 XSETWINDOW (window
, w
);
28629 if (EQ (window
, hlinfo
->mouse_face_window
))
28630 clear_mouse_face (hlinfo
);
28636 Just discard the mouse face information for frame F, if any.
28637 This is used when the size of F is changed. */
28640 cancel_mouse_face (struct frame
*f
)
28642 Lisp_Object window
;
28643 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28645 window
= hlinfo
->mouse_face_window
;
28646 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28647 reset_mouse_highlight (hlinfo
);
28652 /***********************************************************************
28654 ***********************************************************************/
28656 #ifdef HAVE_WINDOW_SYSTEM
28658 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28659 which intersects rectangle R. R is in window-relative coordinates. */
28662 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28663 enum glyph_row_area area
)
28665 struct glyph
*first
= row
->glyphs
[area
];
28666 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28667 struct glyph
*last
;
28668 int first_x
, start_x
, x
;
28670 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28671 /* If row extends face to end of line write the whole line. */
28672 draw_glyphs (w
, 0, row
, area
,
28673 0, row
->used
[area
],
28674 DRAW_NORMAL_TEXT
, 0);
28677 /* Set START_X to the window-relative start position for drawing glyphs of
28678 AREA. The first glyph of the text area can be partially visible.
28679 The first glyphs of other areas cannot. */
28680 start_x
= window_box_left_offset (w
, area
);
28682 if (area
== TEXT_AREA
)
28685 /* Find the first glyph that must be redrawn. */
28687 && x
+ first
->pixel_width
< r
->x
)
28689 x
+= first
->pixel_width
;
28693 /* Find the last one. */
28697 && x
< r
->x
+ r
->width
)
28699 x
+= last
->pixel_width
;
28705 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28706 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28707 DRAW_NORMAL_TEXT
, 0);
28712 /* Redraw the parts of the glyph row ROW on window W intersecting
28713 rectangle R. R is in window-relative coordinates. Value is
28714 non-zero if mouse-face was overwritten. */
28717 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28719 eassert (row
->enabled_p
);
28721 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28722 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28723 0, row
->used
[TEXT_AREA
],
28724 DRAW_NORMAL_TEXT
, 0);
28727 if (row
->used
[LEFT_MARGIN_AREA
])
28728 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28729 if (row
->used
[TEXT_AREA
])
28730 expose_area (w
, row
, r
, TEXT_AREA
);
28731 if (row
->used
[RIGHT_MARGIN_AREA
])
28732 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28733 draw_row_fringe_bitmaps (w
, row
);
28736 return row
->mouse_face_p
;
28740 /* Redraw those parts of glyphs rows during expose event handling that
28741 overlap other rows. Redrawing of an exposed line writes over parts
28742 of lines overlapping that exposed line; this function fixes that.
28744 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28745 row in W's current matrix that is exposed and overlaps other rows.
28746 LAST_OVERLAPPING_ROW is the last such row. */
28749 expose_overlaps (struct window
*w
,
28750 struct glyph_row
*first_overlapping_row
,
28751 struct glyph_row
*last_overlapping_row
,
28754 struct glyph_row
*row
;
28756 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28757 if (row
->overlapping_p
)
28759 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28762 if (row
->used
[LEFT_MARGIN_AREA
])
28763 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28765 if (row
->used
[TEXT_AREA
])
28766 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28768 if (row
->used
[RIGHT_MARGIN_AREA
])
28769 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28775 /* Return non-zero if W's cursor intersects rectangle R. */
28778 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28780 XRectangle cr
, result
;
28781 struct glyph
*cursor_glyph
;
28782 struct glyph_row
*row
;
28784 if (w
->phys_cursor
.vpos
>= 0
28785 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28786 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28788 && row
->cursor_in_fringe_p
)
28790 /* Cursor is in the fringe. */
28791 cr
.x
= window_box_right_offset (w
,
28792 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28793 ? RIGHT_MARGIN_AREA
28796 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28797 cr
.height
= row
->height
;
28798 return x_intersect_rectangles (&cr
, r
, &result
);
28801 cursor_glyph
= get_phys_cursor_glyph (w
);
28804 /* r is relative to W's box, but w->phys_cursor.x is relative
28805 to left edge of W's TEXT area. Adjust it. */
28806 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28807 cr
.y
= w
->phys_cursor
.y
;
28808 cr
.width
= cursor_glyph
->pixel_width
;
28809 cr
.height
= w
->phys_cursor_height
;
28810 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28811 I assume the effect is the same -- and this is portable. */
28812 return x_intersect_rectangles (&cr
, r
, &result
);
28814 /* If we don't understand the format, pretend we're not in the hot-spot. */
28820 Draw a vertical window border to the right of window W if W doesn't
28821 have vertical scroll bars. */
28824 x_draw_vertical_border (struct window
*w
)
28826 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28828 /* We could do better, if we knew what type of scroll-bar the adjacent
28829 windows (on either side) have... But we don't :-(
28830 However, I think this works ok. ++KFS 2003-04-25 */
28832 /* Redraw borders between horizontally adjacent windows. Don't
28833 do it for frames with vertical scroll bars because either the
28834 right scroll bar of a window, or the left scroll bar of its
28835 neighbor will suffice as a border. */
28836 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28839 /* Note: It is necessary to redraw both the left and the right
28840 borders, for when only this single window W is being
28842 if (!WINDOW_RIGHTMOST_P (w
)
28843 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28845 int x0
, x1
, y0
, y1
;
28847 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28850 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28853 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28855 if (!WINDOW_LEFTMOST_P (w
)
28856 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28858 int x0
, x1
, y0
, y1
;
28860 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28863 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28866 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28871 /* Redraw the part of window W intersection rectangle FR. Pixel
28872 coordinates in FR are frame-relative. Call this function with
28873 input blocked. Value is non-zero if the exposure overwrites
28877 expose_window (struct window
*w
, XRectangle
*fr
)
28879 struct frame
*f
= XFRAME (w
->frame
);
28881 int mouse_face_overwritten_p
= 0;
28883 /* If window is not yet fully initialized, do nothing. This can
28884 happen when toolkit scroll bars are used and a window is split.
28885 Reconfiguring the scroll bar will generate an expose for a newly
28887 if (w
->current_matrix
== NULL
)
28890 /* When we're currently updating the window, display and current
28891 matrix usually don't agree. Arrange for a thorough display
28893 if (w
->must_be_updated_p
)
28895 SET_FRAME_GARBAGED (f
);
28899 /* Frame-relative pixel rectangle of W. */
28900 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28901 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28902 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28903 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28905 if (x_intersect_rectangles (fr
, &wr
, &r
))
28907 int yb
= window_text_bottom_y (w
);
28908 struct glyph_row
*row
;
28909 int cursor_cleared_p
, phys_cursor_on_p
;
28910 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28912 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28913 r
.x
, r
.y
, r
.width
, r
.height
));
28915 /* Convert to window coordinates. */
28916 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28917 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28919 /* Turn off the cursor. */
28920 if (!w
->pseudo_window_p
28921 && phys_cursor_in_rect_p (w
, &r
))
28923 x_clear_cursor (w
);
28924 cursor_cleared_p
= 1;
28927 cursor_cleared_p
= 0;
28929 /* If the row containing the cursor extends face to end of line,
28930 then expose_area might overwrite the cursor outside the
28931 rectangle and thus notice_overwritten_cursor might clear
28932 w->phys_cursor_on_p. We remember the original value and
28933 check later if it is changed. */
28934 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28936 /* Update lines intersecting rectangle R. */
28937 first_overlapping_row
= last_overlapping_row
= NULL
;
28938 for (row
= w
->current_matrix
->rows
;
28943 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28945 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28946 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28947 || (r
.y
>= y0
&& r
.y
< y1
)
28948 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28950 /* A header line may be overlapping, but there is no need
28951 to fix overlapping areas for them. KFS 2005-02-12 */
28952 if (row
->overlapping_p
&& !row
->mode_line_p
)
28954 if (first_overlapping_row
== NULL
)
28955 first_overlapping_row
= row
;
28956 last_overlapping_row
= row
;
28960 if (expose_line (w
, row
, &r
))
28961 mouse_face_overwritten_p
= 1;
28964 else if (row
->overlapping_p
)
28966 /* We must redraw a row overlapping the exposed area. */
28968 ? y0
+ row
->phys_height
> r
.y
28969 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28971 if (first_overlapping_row
== NULL
)
28972 first_overlapping_row
= row
;
28973 last_overlapping_row
= row
;
28981 /* Display the mode line if there is one. */
28982 if (WINDOW_WANTS_MODELINE_P (w
)
28983 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28985 && row
->y
< r
.y
+ r
.height
)
28987 if (expose_line (w
, row
, &r
))
28988 mouse_face_overwritten_p
= 1;
28991 if (!w
->pseudo_window_p
)
28993 /* Fix the display of overlapping rows. */
28994 if (first_overlapping_row
)
28995 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28998 /* Draw border between windows. */
28999 x_draw_vertical_border (w
);
29001 /* Turn the cursor on again. */
29002 if (cursor_cleared_p
29003 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29004 update_window_cursor (w
, 1);
29008 return mouse_face_overwritten_p
;
29013 /* Redraw (parts) of all windows in the window tree rooted at W that
29014 intersect R. R contains frame pixel coordinates. Value is
29015 non-zero if the exposure overwrites mouse-face. */
29018 expose_window_tree (struct window
*w
, XRectangle
*r
)
29020 struct frame
*f
= XFRAME (w
->frame
);
29021 int mouse_face_overwritten_p
= 0;
29023 while (w
&& !FRAME_GARBAGED_P (f
))
29025 if (WINDOWP (w
->contents
))
29026 mouse_face_overwritten_p
29027 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29029 mouse_face_overwritten_p
|= expose_window (w
, r
);
29031 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29034 return mouse_face_overwritten_p
;
29039 Redisplay an exposed area of frame F. X and Y are the upper-left
29040 corner of the exposed rectangle. W and H are width and height of
29041 the exposed area. All are pixel values. W or H zero means redraw
29042 the entire frame. */
29045 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29048 int mouse_face_overwritten_p
= 0;
29050 TRACE ((stderr
, "expose_frame "));
29052 /* No need to redraw if frame will be redrawn soon. */
29053 if (FRAME_GARBAGED_P (f
))
29055 TRACE ((stderr
, " garbaged\n"));
29059 /* If basic faces haven't been realized yet, there is no point in
29060 trying to redraw anything. This can happen when we get an expose
29061 event while Emacs is starting, e.g. by moving another window. */
29062 if (FRAME_FACE_CACHE (f
) == NULL
29063 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29065 TRACE ((stderr
, " no faces\n"));
29069 if (w
== 0 || h
== 0)
29072 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29073 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29083 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29084 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29086 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29087 if (WINDOWP (f
->tool_bar_window
))
29088 mouse_face_overwritten_p
29089 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29092 #ifdef HAVE_X_WINDOWS
29094 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29095 if (WINDOWP (f
->menu_bar_window
))
29096 mouse_face_overwritten_p
29097 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29098 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29102 /* Some window managers support a focus-follows-mouse style with
29103 delayed raising of frames. Imagine a partially obscured frame,
29104 and moving the mouse into partially obscured mouse-face on that
29105 frame. The visible part of the mouse-face will be highlighted,
29106 then the WM raises the obscured frame. With at least one WM, KDE
29107 2.1, Emacs is not getting any event for the raising of the frame
29108 (even tried with SubstructureRedirectMask), only Expose events.
29109 These expose events will draw text normally, i.e. not
29110 highlighted. Which means we must redo the highlight here.
29111 Subsume it under ``we love X''. --gerd 2001-08-15 */
29112 /* Included in Windows version because Windows most likely does not
29113 do the right thing if any third party tool offers
29114 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29115 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29117 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29118 if (f
== hlinfo
->mouse_face_mouse_frame
)
29120 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29121 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29122 clear_mouse_face (hlinfo
);
29123 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29130 Determine the intersection of two rectangles R1 and R2. Return
29131 the intersection in *RESULT. Value is non-zero if RESULT is not
29135 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29137 XRectangle
*left
, *right
;
29138 XRectangle
*upper
, *lower
;
29139 int intersection_p
= 0;
29141 /* Rearrange so that R1 is the left-most rectangle. */
29143 left
= r1
, right
= r2
;
29145 left
= r2
, right
= r1
;
29147 /* X0 of the intersection is right.x0, if this is inside R1,
29148 otherwise there is no intersection. */
29149 if (right
->x
<= left
->x
+ left
->width
)
29151 result
->x
= right
->x
;
29153 /* The right end of the intersection is the minimum of
29154 the right ends of left and right. */
29155 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29158 /* Same game for Y. */
29160 upper
= r1
, lower
= r2
;
29162 upper
= r2
, lower
= r1
;
29164 /* The upper end of the intersection is lower.y0, if this is inside
29165 of upper. Otherwise, there is no intersection. */
29166 if (lower
->y
<= upper
->y
+ upper
->height
)
29168 result
->y
= lower
->y
;
29170 /* The lower end of the intersection is the minimum of the lower
29171 ends of upper and lower. */
29172 result
->height
= (min (lower
->y
+ lower
->height
,
29173 upper
->y
+ upper
->height
)
29175 intersection_p
= 1;
29179 return intersection_p
;
29182 #endif /* HAVE_WINDOW_SYSTEM */
29185 /***********************************************************************
29187 ***********************************************************************/
29190 syms_of_xdisp (void)
29192 Vwith_echo_area_save_vector
= Qnil
;
29193 staticpro (&Vwith_echo_area_save_vector
);
29195 Vmessage_stack
= Qnil
;
29196 staticpro (&Vmessage_stack
);
29198 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29199 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29201 message_dolog_marker1
= Fmake_marker ();
29202 staticpro (&message_dolog_marker1
);
29203 message_dolog_marker2
= Fmake_marker ();
29204 staticpro (&message_dolog_marker2
);
29205 message_dolog_marker3
= Fmake_marker ();
29206 staticpro (&message_dolog_marker3
);
29209 defsubr (&Sdump_frame_glyph_matrix
);
29210 defsubr (&Sdump_glyph_matrix
);
29211 defsubr (&Sdump_glyph_row
);
29212 defsubr (&Sdump_tool_bar_row
);
29213 defsubr (&Strace_redisplay
);
29214 defsubr (&Strace_to_stderr
);
29216 #ifdef HAVE_WINDOW_SYSTEM
29217 defsubr (&Stool_bar_lines_needed
);
29218 defsubr (&Slookup_image_map
);
29220 defsubr (&Sline_pixel_height
);
29221 defsubr (&Sformat_mode_line
);
29222 defsubr (&Sinvisible_p
);
29223 defsubr (&Scurrent_bidi_paragraph_direction
);
29224 defsubr (&Smove_point_visually
);
29226 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29227 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29228 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29229 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29230 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29231 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29232 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29233 DEFSYM (Qeval
, "eval");
29234 DEFSYM (QCdata
, ":data");
29235 DEFSYM (Qdisplay
, "display");
29236 DEFSYM (Qspace_width
, "space-width");
29237 DEFSYM (Qraise
, "raise");
29238 DEFSYM (Qslice
, "slice");
29239 DEFSYM (Qspace
, "space");
29240 DEFSYM (Qmargin
, "margin");
29241 DEFSYM (Qpointer
, "pointer");
29242 DEFSYM (Qleft_margin
, "left-margin");
29243 DEFSYM (Qright_margin
, "right-margin");
29244 DEFSYM (Qcenter
, "center");
29245 DEFSYM (Qline_height
, "line-height");
29246 DEFSYM (QCalign_to
, ":align-to");
29247 DEFSYM (QCrelative_width
, ":relative-width");
29248 DEFSYM (QCrelative_height
, ":relative-height");
29249 DEFSYM (QCeval
, ":eval");
29250 DEFSYM (QCpropertize
, ":propertize");
29251 DEFSYM (QCfile
, ":file");
29252 DEFSYM (Qfontified
, "fontified");
29253 DEFSYM (Qfontification_functions
, "fontification-functions");
29254 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29255 DEFSYM (Qescape_glyph
, "escape-glyph");
29256 DEFSYM (Qnobreak_space
, "nobreak-space");
29257 DEFSYM (Qimage
, "image");
29258 DEFSYM (Qtext
, "text");
29259 DEFSYM (Qboth
, "both");
29260 DEFSYM (Qboth_horiz
, "both-horiz");
29261 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29262 DEFSYM (QCmap
, ":map");
29263 DEFSYM (QCpointer
, ":pointer");
29264 DEFSYM (Qrect
, "rect");
29265 DEFSYM (Qcircle
, "circle");
29266 DEFSYM (Qpoly
, "poly");
29267 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29268 DEFSYM (Qgrow_only
, "grow-only");
29269 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29270 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29271 DEFSYM (Qposition
, "position");
29272 DEFSYM (Qbuffer_position
, "buffer-position");
29273 DEFSYM (Qobject
, "object");
29274 DEFSYM (Qbar
, "bar");
29275 DEFSYM (Qhbar
, "hbar");
29276 DEFSYM (Qbox
, "box");
29277 DEFSYM (Qhollow
, "hollow");
29278 DEFSYM (Qhand
, "hand");
29279 DEFSYM (Qarrow
, "arrow");
29280 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29282 list_of_error
= list1 (list2 (intern_c_string ("error"),
29283 intern_c_string ("void-variable")));
29284 staticpro (&list_of_error
);
29286 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29287 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29288 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29289 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29291 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29292 staticpro (&echo_buffer
[0]);
29293 staticpro (&echo_buffer
[1]);
29295 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29296 staticpro (&echo_area_buffer
[0]);
29297 staticpro (&echo_area_buffer
[1]);
29299 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29300 staticpro (&Vmessages_buffer_name
);
29302 mode_line_proptrans_alist
= Qnil
;
29303 staticpro (&mode_line_proptrans_alist
);
29304 mode_line_string_list
= Qnil
;
29305 staticpro (&mode_line_string_list
);
29306 mode_line_string_face
= Qnil
;
29307 staticpro (&mode_line_string_face
);
29308 mode_line_string_face_prop
= Qnil
;
29309 staticpro (&mode_line_string_face_prop
);
29310 Vmode_line_unwind_vector
= Qnil
;
29311 staticpro (&Vmode_line_unwind_vector
);
29313 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29315 help_echo_string
= Qnil
;
29316 staticpro (&help_echo_string
);
29317 help_echo_object
= Qnil
;
29318 staticpro (&help_echo_object
);
29319 help_echo_window
= Qnil
;
29320 staticpro (&help_echo_window
);
29321 previous_help_echo_string
= Qnil
;
29322 staticpro (&previous_help_echo_string
);
29323 help_echo_pos
= -1;
29325 DEFSYM (Qright_to_left
, "right-to-left");
29326 DEFSYM (Qleft_to_right
, "left-to-right");
29328 #ifdef HAVE_WINDOW_SYSTEM
29329 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29330 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29331 For example, if a block cursor is over a tab, it will be drawn as
29332 wide as that tab on the display. */);
29333 x_stretch_cursor_p
= 0;
29336 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29337 doc
: /* Non-nil means highlight trailing whitespace.
29338 The face used for trailing whitespace is `trailing-whitespace'. */);
29339 Vshow_trailing_whitespace
= Qnil
;
29341 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29342 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29343 If the value is t, Emacs highlights non-ASCII chars which have the
29344 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29345 or `escape-glyph' face respectively.
29347 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29348 U+2011 (non-breaking hyphen) are affected.
29350 Any other non-nil value means to display these characters as a escape
29351 glyph followed by an ordinary space or hyphen.
29353 A value of nil means no special handling of these characters. */);
29354 Vnobreak_char_display
= Qt
;
29356 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29357 doc
: /* The pointer shape to show in void text areas.
29358 A value of nil means to show the text pointer. Other options are `arrow',
29359 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29360 Vvoid_text_area_pointer
= Qarrow
;
29362 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29363 doc
: /* Non-nil means don't actually do any redisplay.
29364 This is used for internal purposes. */);
29365 Vinhibit_redisplay
= Qnil
;
29367 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29368 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29369 Vglobal_mode_string
= Qnil
;
29371 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29372 doc
: /* Marker for where to display an arrow on top of the buffer text.
29373 This must be the beginning of a line in order to work.
29374 See also `overlay-arrow-string'. */);
29375 Voverlay_arrow_position
= Qnil
;
29377 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29378 doc
: /* String to display as an arrow in non-window frames.
29379 See also `overlay-arrow-position'. */);
29380 Voverlay_arrow_string
= build_pure_c_string ("=>");
29382 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29383 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29384 The symbols on this list are examined during redisplay to determine
29385 where to display overlay arrows. */);
29386 Voverlay_arrow_variable_list
29387 = list1 (intern_c_string ("overlay-arrow-position"));
29389 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29390 doc
: /* The number of lines to try scrolling a window by when point moves out.
29391 If that fails to bring point back on frame, point is centered instead.
29392 If this is zero, point is always centered after it moves off frame.
29393 If you want scrolling to always be a line at a time, you should set
29394 `scroll-conservatively' to a large value rather than set this to 1. */);
29396 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29397 doc
: /* Scroll up to this many lines, to bring point back on screen.
29398 If point moves off-screen, redisplay will scroll by up to
29399 `scroll-conservatively' lines in order to bring point just barely
29400 onto the screen again. If that cannot be done, then redisplay
29401 recenters point as usual.
29403 If the value is greater than 100, redisplay will never recenter point,
29404 but will always scroll just enough text to bring point into view, even
29405 if you move far away.
29407 A value of zero means always recenter point if it moves off screen. */);
29408 scroll_conservatively
= 0;
29410 DEFVAR_INT ("scroll-margin", scroll_margin
,
29411 doc
: /* Number of lines of margin at the top and bottom of a window.
29412 Recenter the window whenever point gets within this many lines
29413 of the top or bottom of the window. */);
29416 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29417 doc
: /* Pixels per inch value for non-window system displays.
29418 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29419 Vdisplay_pixels_per_inch
= make_float (72.0);
29422 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29425 DEFVAR_LISP ("truncate-partial-width-windows",
29426 Vtruncate_partial_width_windows
,
29427 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29428 For an integer value, truncate lines in each window narrower than the
29429 full frame width, provided the window width is less than that integer;
29430 otherwise, respect the value of `truncate-lines'.
29432 For any other non-nil value, truncate lines in all windows that do
29433 not span the full frame width.
29435 A value of nil means to respect the value of `truncate-lines'.
29437 If `word-wrap' is enabled, you might want to reduce this. */);
29438 Vtruncate_partial_width_windows
= make_number (50);
29440 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29441 doc
: /* Maximum buffer size for which line number should be displayed.
29442 If the buffer is bigger than this, the line number does not appear
29443 in the mode line. A value of nil means no limit. */);
29444 Vline_number_display_limit
= Qnil
;
29446 DEFVAR_INT ("line-number-display-limit-width",
29447 line_number_display_limit_width
,
29448 doc
: /* Maximum line width (in characters) for line number display.
29449 If the average length of the lines near point is bigger than this, then the
29450 line number may be omitted from the mode line. */);
29451 line_number_display_limit_width
= 200;
29453 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29454 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29455 highlight_nonselected_windows
= 0;
29457 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29458 doc
: /* Non-nil if more than one frame is visible on this display.
29459 Minibuffer-only frames don't count, but iconified frames do.
29460 This variable is not guaranteed to be accurate except while processing
29461 `frame-title-format' and `icon-title-format'. */);
29463 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29464 doc
: /* Template for displaying the title bar of visible frames.
29465 \(Assuming the window manager supports this feature.)
29467 This variable has the same structure as `mode-line-format', except that
29468 the %c and %l constructs are ignored. It is used only on frames for
29469 which no explicit name has been set \(see `modify-frame-parameters'). */);
29471 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29472 doc
: /* Template for displaying the title bar of an iconified frame.
29473 \(Assuming the window manager supports this feature.)
29474 This variable has the same structure as `mode-line-format' (which see),
29475 and is used only on frames for which no explicit name has been set
29476 \(see `modify-frame-parameters'). */);
29478 = Vframe_title_format
29479 = listn (CONSTYPE_PURE
, 3,
29480 intern_c_string ("multiple-frames"),
29481 build_pure_c_string ("%b"),
29482 listn (CONSTYPE_PURE
, 4,
29483 empty_unibyte_string
,
29484 intern_c_string ("invocation-name"),
29485 build_pure_c_string ("@"),
29486 intern_c_string ("system-name")));
29488 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29489 doc
: /* Maximum number of lines to keep in the message log buffer.
29490 If nil, disable message logging. If t, log messages but don't truncate
29491 the buffer when it becomes large. */);
29492 Vmessage_log_max
= make_number (1000);
29494 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29495 doc
: /* Functions called before redisplay, if window sizes have changed.
29496 The value should be a list of functions that take one argument.
29497 Just before redisplay, for each frame, if any of its windows have changed
29498 size since the last redisplay, or have been split or deleted,
29499 all the functions in the list are called, with the frame as argument. */);
29500 Vwindow_size_change_functions
= Qnil
;
29502 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29503 doc
: /* List of functions to call before redisplaying a window with scrolling.
29504 Each function is called with two arguments, the window and its new
29505 display-start position. Note that these functions are also called by
29506 `set-window-buffer'. Also note that the value of `window-end' is not
29507 valid when these functions are called.
29509 Warning: Do not use this feature to alter the way the window
29510 is scrolled. It is not designed for that, and such use probably won't
29512 Vwindow_scroll_functions
= Qnil
;
29514 DEFVAR_LISP ("window-text-change-functions",
29515 Vwindow_text_change_functions
,
29516 doc
: /* Functions to call in redisplay when text in the window might change. */);
29517 Vwindow_text_change_functions
= Qnil
;
29519 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29520 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29521 Each function is called with two arguments, the window and the end trigger value.
29522 See `set-window-redisplay-end-trigger'. */);
29523 Vredisplay_end_trigger_functions
= Qnil
;
29525 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29526 doc
: /* Non-nil means autoselect window with mouse pointer.
29527 If nil, do not autoselect windows.
29528 A positive number means delay autoselection by that many seconds: a
29529 window is autoselected only after the mouse has remained in that
29530 window for the duration of the delay.
29531 A negative number has a similar effect, but causes windows to be
29532 autoselected only after the mouse has stopped moving. \(Because of
29533 the way Emacs compares mouse events, you will occasionally wait twice
29534 that time before the window gets selected.\)
29535 Any other value means to autoselect window instantaneously when the
29536 mouse pointer enters it.
29538 Autoselection selects the minibuffer only if it is active, and never
29539 unselects the minibuffer if it is active.
29541 When customizing this variable make sure that the actual value of
29542 `focus-follows-mouse' matches the behavior of your window manager. */);
29543 Vmouse_autoselect_window
= Qnil
;
29545 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29546 doc
: /* Non-nil means automatically resize tool-bars.
29547 This dynamically changes the tool-bar's height to the minimum height
29548 that is needed to make all tool-bar items visible.
29549 If value is `grow-only', the tool-bar's height is only increased
29550 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29551 Vauto_resize_tool_bars
= Qt
;
29553 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29554 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29555 auto_raise_tool_bar_buttons_p
= 1;
29557 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29558 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29559 make_cursor_line_fully_visible_p
= 1;
29561 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29562 doc
: /* Border below tool-bar in pixels.
29563 If an integer, use it as the height of the border.
29564 If it is one of `internal-border-width' or `border-width', use the
29565 value of the corresponding frame parameter.
29566 Otherwise, no border is added below the tool-bar. */);
29567 Vtool_bar_border
= Qinternal_border_width
;
29569 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29570 doc
: /* Margin around tool-bar buttons in pixels.
29571 If an integer, use that for both horizontal and vertical margins.
29572 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29573 HORZ specifying the horizontal margin, and VERT specifying the
29574 vertical margin. */);
29575 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29577 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29578 doc
: /* Relief thickness of tool-bar buttons. */);
29579 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29581 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29582 doc
: /* Tool bar style to use.
29584 image - show images only
29585 text - show text only
29586 both - show both, text below image
29587 both-horiz - show text to the right of the image
29588 text-image-horiz - show text to the left of the image
29589 any other - use system default or image if no system default.
29591 This variable only affects the GTK+ toolkit version of Emacs. */);
29592 Vtool_bar_style
= Qnil
;
29594 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29595 doc
: /* Maximum number of characters a label can have to be shown.
29596 The tool bar style must also show labels for this to have any effect, see
29597 `tool-bar-style'. */);
29598 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29600 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29601 doc
: /* List of functions to call to fontify regions of text.
29602 Each function is called with one argument POS. Functions must
29603 fontify a region starting at POS in the current buffer, and give
29604 fontified regions the property `fontified'. */);
29605 Vfontification_functions
= Qnil
;
29606 Fmake_variable_buffer_local (Qfontification_functions
);
29608 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29609 unibyte_display_via_language_environment
,
29610 doc
: /* Non-nil means display unibyte text according to language environment.
29611 Specifically, this means that raw bytes in the range 160-255 decimal
29612 are displayed by converting them to the equivalent multibyte characters
29613 according to the current language environment. As a result, they are
29614 displayed according to the current fontset.
29616 Note that this variable affects only how these bytes are displayed,
29617 but does not change the fact they are interpreted as raw bytes. */);
29618 unibyte_display_via_language_environment
= 0;
29620 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29621 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29622 If a float, it specifies a fraction of the mini-window frame's height.
29623 If an integer, it specifies a number of lines. */);
29624 Vmax_mini_window_height
= make_float (0.25);
29626 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29627 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29628 A value of nil means don't automatically resize mini-windows.
29629 A value of t means resize them to fit the text displayed in them.
29630 A value of `grow-only', the default, means let mini-windows grow only;
29631 they return to their normal size when the minibuffer is closed, or the
29632 echo area becomes empty. */);
29633 Vresize_mini_windows
= Qgrow_only
;
29635 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29636 doc
: /* Alist specifying how to blink the cursor off.
29637 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29638 `cursor-type' frame-parameter or variable equals ON-STATE,
29639 comparing using `equal', Emacs uses OFF-STATE to specify
29640 how to blink it off. ON-STATE and OFF-STATE are values for
29641 the `cursor-type' frame parameter.
29643 If a frame's ON-STATE has no entry in this list,
29644 the frame's other specifications determine how to blink the cursor off. */);
29645 Vblink_cursor_alist
= Qnil
;
29647 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29648 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29649 If non-nil, windows are automatically scrolled horizontally to make
29650 point visible. */);
29651 automatic_hscrolling_p
= 1;
29652 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29654 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29655 doc
: /* How many columns away from the window edge point is allowed to get
29656 before automatic hscrolling will horizontally scroll the window. */);
29657 hscroll_margin
= 5;
29659 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29660 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29661 When point is less than `hscroll-margin' columns from the window
29662 edge, automatic hscrolling will scroll the window by the amount of columns
29663 determined by this variable. If its value is a positive integer, scroll that
29664 many columns. If it's a positive floating-point number, it specifies the
29665 fraction of the window's width to scroll. If it's nil or zero, point will be
29666 centered horizontally after the scroll. Any other value, including negative
29667 numbers, are treated as if the value were zero.
29669 Automatic hscrolling always moves point outside the scroll margin, so if
29670 point was more than scroll step columns inside the margin, the window will
29671 scroll more than the value given by the scroll step.
29673 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29674 and `scroll-right' overrides this variable's effect. */);
29675 Vhscroll_step
= make_number (0);
29677 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29678 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29679 Bind this around calls to `message' to let it take effect. */);
29680 message_truncate_lines
= 0;
29682 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29683 doc
: /* Normal hook run to update the menu bar definitions.
29684 Redisplay runs this hook before it redisplays the menu bar.
29685 This is used to update submenus such as Buffers,
29686 whose contents depend on various data. */);
29687 Vmenu_bar_update_hook
= Qnil
;
29689 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29690 doc
: /* Frame for which we are updating a menu.
29691 The enable predicate for a menu binding should check this variable. */);
29692 Vmenu_updating_frame
= Qnil
;
29694 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29695 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29696 inhibit_menubar_update
= 0;
29698 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29699 doc
: /* Prefix prepended to all continuation lines at display time.
29700 The value may be a string, an image, or a stretch-glyph; it is
29701 interpreted in the same way as the value of a `display' text property.
29703 This variable is overridden by any `wrap-prefix' text or overlay
29706 To add a prefix to non-continuation lines, use `line-prefix'. */);
29707 Vwrap_prefix
= Qnil
;
29708 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29709 Fmake_variable_buffer_local (Qwrap_prefix
);
29711 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29712 doc
: /* Prefix prepended to all non-continuation lines at display time.
29713 The value may be a string, an image, or a stretch-glyph; it is
29714 interpreted in the same way as the value of a `display' text property.
29716 This variable is overridden by any `line-prefix' text or overlay
29719 To add a prefix to continuation lines, use `wrap-prefix'. */);
29720 Vline_prefix
= Qnil
;
29721 DEFSYM (Qline_prefix
, "line-prefix");
29722 Fmake_variable_buffer_local (Qline_prefix
);
29724 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29725 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29726 inhibit_eval_during_redisplay
= 0;
29728 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29729 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29730 inhibit_free_realized_faces
= 0;
29733 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29734 doc
: /* Inhibit try_window_id display optimization. */);
29735 inhibit_try_window_id
= 0;
29737 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29738 doc
: /* Inhibit try_window_reusing display optimization. */);
29739 inhibit_try_window_reusing
= 0;
29741 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29742 doc
: /* Inhibit try_cursor_movement display optimization. */);
29743 inhibit_try_cursor_movement
= 0;
29744 #endif /* GLYPH_DEBUG */
29746 DEFVAR_INT ("overline-margin", overline_margin
,
29747 doc
: /* Space between overline and text, in pixels.
29748 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29749 margin to the character height. */);
29750 overline_margin
= 2;
29752 DEFVAR_INT ("underline-minimum-offset",
29753 underline_minimum_offset
,
29754 doc
: /* Minimum distance between baseline and underline.
29755 This can improve legibility of underlined text at small font sizes,
29756 particularly when using variable `x-use-underline-position-properties'
29757 with fonts that specify an UNDERLINE_POSITION relatively close to the
29758 baseline. The default value is 1. */);
29759 underline_minimum_offset
= 1;
29761 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29762 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29763 This feature only works when on a window system that can change
29764 cursor shapes. */);
29765 display_hourglass_p
= 1;
29767 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29768 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29769 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29771 #ifdef HAVE_WINDOW_SYSTEM
29772 hourglass_atimer
= NULL
;
29773 hourglass_shown_p
= 0;
29774 #endif /* HAVE_WINDOW_SYSTEM */
29776 DEFSYM (Qglyphless_char
, "glyphless-char");
29777 DEFSYM (Qhex_code
, "hex-code");
29778 DEFSYM (Qempty_box
, "empty-box");
29779 DEFSYM (Qthin_space
, "thin-space");
29780 DEFSYM (Qzero_width
, "zero-width");
29782 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29783 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29785 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29786 doc
: /* Char-table defining glyphless characters.
29787 Each element, if non-nil, should be one of the following:
29788 an ASCII acronym string: display this string in a box
29789 `hex-code': display the hexadecimal code of a character in a box
29790 `empty-box': display as an empty box
29791 `thin-space': display as 1-pixel width space
29792 `zero-width': don't display
29793 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29794 display method for graphical terminals and text terminals respectively.
29795 GRAPHICAL and TEXT should each have one of the values listed above.
29797 The char-table has one extra slot to control the display of a character for
29798 which no font is found. This slot only takes effect on graphical terminals.
29799 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29800 `thin-space'. The default is `empty-box'. */);
29801 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29802 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29805 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29806 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29807 Vdebug_on_message
= Qnil
;
29811 /* Initialize this module when Emacs starts. */
29816 CHARPOS (this_line_start_pos
) = 0;
29818 if (!noninteractive
)
29820 struct window
*m
= XWINDOW (minibuf_window
);
29821 Lisp_Object frame
= m
->frame
;
29822 struct frame
*f
= XFRAME (frame
);
29823 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29824 struct window
*r
= XWINDOW (root
);
29827 echo_area_window
= minibuf_window
;
29829 r
->top_line
= FRAME_TOP_MARGIN (f
);
29830 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29831 r
->total_cols
= FRAME_COLS (f
);
29833 m
->top_line
= FRAME_LINES (f
) - 1;
29834 m
->total_lines
= 1;
29835 m
->total_cols
= FRAME_COLS (f
);
29837 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29838 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29839 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29841 /* The default ellipsis glyphs `...'. */
29842 for (i
= 0; i
< 3; ++i
)
29843 default_invis_vector
[i
] = make_number ('.');
29847 /* Allocate the buffer for frame titles.
29848 Also used for `format-mode-line'. */
29850 mode_line_noprop_buf
= xmalloc (size
);
29851 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29852 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29853 mode_line_target
= MODE_LINE_DISPLAY
;
29856 help_echo_showing_p
= 0;
29859 #ifdef HAVE_WINDOW_SYSTEM
29861 /* Platform-independent portion of hourglass implementation. */
29863 /* Cancel a currently active hourglass timer, and start a new one. */
29865 start_hourglass (void)
29867 struct timespec delay
;
29869 cancel_hourglass ();
29871 if (INTEGERP (Vhourglass_delay
)
29872 && XINT (Vhourglass_delay
) > 0)
29873 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29874 TYPE_MAXIMUM (time_t)),
29876 else if (FLOATP (Vhourglass_delay
)
29877 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29878 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29880 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29884 extern void w32_note_current_window (void);
29885 w32_note_current_window ();
29887 #endif /* HAVE_NTGUI */
29889 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29890 show_hourglass
, NULL
);
29894 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29897 cancel_hourglass (void)
29899 if (hourglass_atimer
)
29901 cancel_atimer (hourglass_atimer
);
29902 hourglass_atimer
= NULL
;
29905 if (hourglass_shown_p
)
29909 #endif /* HAVE_WINDOW_SYSTEM */