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 static 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 /***********************************************************************
2605 Iterator initialization
2606 ***********************************************************************/
2608 /* Initialize IT for displaying current_buffer in window W, starting
2609 at character position CHARPOS. CHARPOS < 0 means that no buffer
2610 position is specified which is useful when the iterator is assigned
2611 a position later. BYTEPOS is the byte position corresponding to
2614 If ROW is not null, calls to produce_glyphs with IT as parameter
2615 will produce glyphs in that row.
2617 BASE_FACE_ID is the id of a base face to use. It must be one of
2618 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2619 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2620 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2622 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2623 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2624 will be initialized to use the corresponding mode line glyph row of
2625 the desired matrix of W. */
2628 init_iterator (struct it
*it
, struct window
*w
,
2629 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2630 struct glyph_row
*row
, enum face_id base_face_id
)
2632 enum face_id remapped_base_face_id
= base_face_id
;
2634 /* Some precondition checks. */
2635 eassert (w
!= NULL
&& it
!= NULL
);
2636 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2639 /* If face attributes have been changed since the last redisplay,
2640 free realized faces now because they depend on face definitions
2641 that might have changed. Don't free faces while there might be
2642 desired matrices pending which reference these faces. */
2643 if (face_change_count
&& !inhibit_free_realized_faces
)
2645 face_change_count
= 0;
2646 free_all_realized_faces (Qnil
);
2649 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2650 if (! NILP (Vface_remapping_alist
))
2651 remapped_base_face_id
2652 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2654 /* Use one of the mode line rows of W's desired matrix if
2658 if (base_face_id
== MODE_LINE_FACE_ID
2659 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2660 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2661 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2662 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2666 memset (it
, 0, sizeof *it
);
2667 it
->current
.overlay_string_index
= -1;
2668 it
->current
.dpvec_index
= -1;
2669 it
->base_face_id
= remapped_base_face_id
;
2671 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2672 it
->paragraph_embedding
= L2R
;
2673 it
->bidi_it
.string
.lstring
= Qnil
;
2674 it
->bidi_it
.string
.s
= NULL
;
2675 it
->bidi_it
.string
.bufpos
= 0;
2678 /* The window in which we iterate over current_buffer: */
2679 XSETWINDOW (it
->window
, w
);
2681 it
->f
= XFRAME (w
->frame
);
2685 /* Extra space between lines (on window systems only). */
2686 if (base_face_id
== DEFAULT_FACE_ID
2687 && FRAME_WINDOW_P (it
->f
))
2689 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2690 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2691 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2692 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2693 * FRAME_LINE_HEIGHT (it
->f
));
2694 else if (it
->f
->extra_line_spacing
> 0)
2695 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2696 it
->max_extra_line_spacing
= 0;
2699 /* If realized faces have been removed, e.g. because of face
2700 attribute changes of named faces, recompute them. When running
2701 in batch mode, the face cache of the initial frame is null. If
2702 we happen to get called, make a dummy face cache. */
2703 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2704 init_frame_faces (it
->f
);
2705 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2706 recompute_basic_faces (it
->f
);
2708 /* Current value of the `slice', `space-width', and 'height' properties. */
2709 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2710 it
->space_width
= Qnil
;
2711 it
->font_height
= Qnil
;
2712 it
->override_ascent
= -1;
2714 /* Are control characters displayed as `^C'? */
2715 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2717 /* -1 means everything between a CR and the following line end
2718 is invisible. >0 means lines indented more than this value are
2720 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2722 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2724 : (!NILP (BVAR (current_buffer
, selective_display
))
2726 it
->selective_display_ellipsis_p
2727 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2729 /* Display table to use. */
2730 it
->dp
= window_display_table (w
);
2732 /* Are multibyte characters enabled in current_buffer? */
2733 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2735 /* Get the position at which the redisplay_end_trigger hook should
2736 be run, if it is to be run at all. */
2737 if (MARKERP (w
->redisplay_end_trigger
)
2738 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2739 it
->redisplay_end_trigger_charpos
2740 = marker_position (w
->redisplay_end_trigger
);
2741 else if (INTEGERP (w
->redisplay_end_trigger
))
2742 it
->redisplay_end_trigger_charpos
=
2743 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2745 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2747 /* Are lines in the display truncated? */
2748 if (base_face_id
!= DEFAULT_FACE_ID
2750 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2751 && ((!NILP (Vtruncate_partial_width_windows
)
2752 && !INTEGERP (Vtruncate_partial_width_windows
))
2753 || (INTEGERP (Vtruncate_partial_width_windows
)
2754 && (WINDOW_TOTAL_COLS (it
->w
)
2755 < XINT (Vtruncate_partial_width_windows
))))))
2756 it
->line_wrap
= TRUNCATE
;
2757 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2758 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2759 ? WINDOW_WRAP
: WORD_WRAP
;
2761 it
->line_wrap
= TRUNCATE
;
2763 /* Get dimensions of truncation and continuation glyphs. These are
2764 displayed as fringe bitmaps under X, but we need them for such
2765 frames when the fringes are turned off. But leave the dimensions
2766 zero for tooltip frames, as these glyphs look ugly there and also
2767 sabotage calculations of tooltip dimensions in x-show-tip. */
2768 #ifdef HAVE_WINDOW_SYSTEM
2769 if (!(FRAME_WINDOW_P (it
->f
)
2770 && FRAMEP (tip_frame
)
2771 && it
->f
== XFRAME (tip_frame
)))
2774 if (it
->line_wrap
== TRUNCATE
)
2776 /* We will need the truncation glyph. */
2777 eassert (it
->glyph_row
== NULL
);
2778 produce_special_glyphs (it
, IT_TRUNCATION
);
2779 it
->truncation_pixel_width
= it
->pixel_width
;
2783 /* We will need the continuation glyph. */
2784 eassert (it
->glyph_row
== NULL
);
2785 produce_special_glyphs (it
, IT_CONTINUATION
);
2786 it
->continuation_pixel_width
= it
->pixel_width
;
2790 /* Reset these values to zero because the produce_special_glyphs
2791 above has changed them. */
2792 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2793 it
->phys_ascent
= it
->phys_descent
= 0;
2795 /* Set this after getting the dimensions of truncation and
2796 continuation glyphs, so that we don't produce glyphs when calling
2797 produce_special_glyphs, above. */
2798 it
->glyph_row
= row
;
2799 it
->area
= TEXT_AREA
;
2801 /* Forget any previous info about this row being reversed. */
2803 it
->glyph_row
->reversed_p
= 0;
2805 /* Get the dimensions of the display area. The display area
2806 consists of the visible window area plus a horizontally scrolled
2807 part to the left of the window. All x-values are relative to the
2808 start of this total display area. */
2809 if (base_face_id
!= DEFAULT_FACE_ID
)
2811 /* Mode lines, menu bar in terminal frames. */
2812 it
->first_visible_x
= 0;
2813 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2817 it
->first_visible_x
=
2818 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2819 it
->last_visible_x
= (it
->first_visible_x
2820 + window_box_width (w
, TEXT_AREA
));
2822 /* If we truncate lines, leave room for the truncation glyph(s) at
2823 the right margin. Otherwise, leave room for the continuation
2824 glyph(s). Done only if the window has no fringes. Since we
2825 don't know at this point whether there will be any R2L lines in
2826 the window, we reserve space for truncation/continuation glyphs
2827 even if only one of the fringes is absent. */
2828 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2829 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2831 if (it
->line_wrap
== TRUNCATE
)
2832 it
->last_visible_x
-= it
->truncation_pixel_width
;
2834 it
->last_visible_x
-= it
->continuation_pixel_width
;
2837 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2838 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2841 /* Leave room for a border glyph. */
2842 if (!FRAME_WINDOW_P (it
->f
)
2843 && !WINDOW_RIGHTMOST_P (it
->w
))
2844 it
->last_visible_x
-= 1;
2846 it
->last_visible_y
= window_text_bottom_y (w
);
2848 /* For mode lines and alike, arrange for the first glyph having a
2849 left box line if the face specifies a box. */
2850 if (base_face_id
!= DEFAULT_FACE_ID
)
2854 it
->face_id
= remapped_base_face_id
;
2856 /* If we have a boxed mode line, make the first character appear
2857 with a left box line. */
2858 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2859 if (face
->box
!= FACE_NO_BOX
)
2860 it
->start_of_box_run_p
= 1;
2863 /* If a buffer position was specified, set the iterator there,
2864 getting overlays and face properties from that position. */
2865 if (charpos
>= BUF_BEG (current_buffer
))
2867 it
->end_charpos
= ZV
;
2868 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2869 IT_CHARPOS (*it
) = charpos
;
2870 IT_BYTEPOS (*it
) = bytepos
;
2872 /* We will rely on `reseat' to set this up properly, via
2873 handle_face_prop. */
2874 it
->face_id
= it
->base_face_id
;
2876 it
->start
= it
->current
;
2877 /* Do we need to reorder bidirectional text? Not if this is a
2878 unibyte buffer: by definition, none of the single-byte
2879 characters are strong R2L, so no reordering is needed. And
2880 bidi.c doesn't support unibyte buffers anyway. Also, don't
2881 reorder while we are loading loadup.el, since the tables of
2882 character properties needed for reordering are not yet
2886 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2889 /* If we are to reorder bidirectional text, init the bidi
2893 /* Note the paragraph direction that this buffer wants to
2895 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2897 it
->paragraph_embedding
= L2R
;
2898 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2900 it
->paragraph_embedding
= R2L
;
2902 it
->paragraph_embedding
= NEUTRAL_DIR
;
2903 bidi_unshelve_cache (NULL
, 0);
2904 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2908 /* Compute faces etc. */
2909 reseat (it
, it
->current
.pos
, 1);
2916 /* Initialize IT for the display of window W with window start POS. */
2919 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2921 struct glyph_row
*row
;
2922 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2924 row
= w
->desired_matrix
->rows
+ first_vpos
;
2925 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2926 it
->first_vpos
= first_vpos
;
2928 /* Don't reseat to previous visible line start if current start
2929 position is in a string or image. */
2930 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2932 int start_at_line_beg_p
;
2933 int first_y
= it
->current_y
;
2935 /* If window start is not at a line start, skip forward to POS to
2936 get the correct continuation lines width. */
2937 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2938 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2939 if (!start_at_line_beg_p
)
2943 reseat_at_previous_visible_line_start (it
);
2944 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2946 new_x
= it
->current_x
+ it
->pixel_width
;
2948 /* If lines are continued, this line may end in the middle
2949 of a multi-glyph character (e.g. a control character
2950 displayed as \003, or in the middle of an overlay
2951 string). In this case move_it_to above will not have
2952 taken us to the start of the continuation line but to the
2953 end of the continued line. */
2954 if (it
->current_x
> 0
2955 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2956 && (/* And glyph doesn't fit on the line. */
2957 new_x
> it
->last_visible_x
2958 /* Or it fits exactly and we're on a window
2960 || (new_x
== it
->last_visible_x
2961 && FRAME_WINDOW_P (it
->f
)
2962 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2963 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2964 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2966 if ((it
->current
.dpvec_index
>= 0
2967 || it
->current
.overlay_string_index
>= 0)
2968 /* If we are on a newline from a display vector or
2969 overlay string, then we are already at the end of
2970 a screen line; no need to go to the next line in
2971 that case, as this line is not really continued.
2972 (If we do go to the next line, C-e will not DTRT.) */
2975 set_iterator_to_next (it
, 1);
2976 move_it_in_display_line_to (it
, -1, -1, 0);
2979 it
->continuation_lines_width
+= it
->current_x
;
2981 /* If the character at POS is displayed via a display
2982 vector, move_it_to above stops at the final glyph of
2983 IT->dpvec. To make the caller redisplay that character
2984 again (a.k.a. start at POS), we need to reset the
2985 dpvec_index to the beginning of IT->dpvec. */
2986 else if (it
->current
.dpvec_index
>= 0)
2987 it
->current
.dpvec_index
= 0;
2989 /* We're starting a new display line, not affected by the
2990 height of the continued line, so clear the appropriate
2991 fields in the iterator structure. */
2992 it
->max_ascent
= it
->max_descent
= 0;
2993 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2995 it
->current_y
= first_y
;
2997 it
->current_x
= it
->hpos
= 0;
3003 /* Return 1 if POS is a position in ellipses displayed for invisible
3004 text. W is the window we display, for text property lookup. */
3007 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3009 Lisp_Object prop
, window
;
3011 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3013 /* If POS specifies a position in a display vector, this might
3014 be for an ellipsis displayed for invisible text. We won't
3015 get the iterator set up for delivering that ellipsis unless
3016 we make sure that it gets aware of the invisible text. */
3017 if (pos
->dpvec_index
>= 0
3018 && pos
->overlay_string_index
< 0
3019 && CHARPOS (pos
->string_pos
) < 0
3021 && (XSETWINDOW (window
, w
),
3022 prop
= Fget_char_property (make_number (charpos
),
3023 Qinvisible
, window
),
3024 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3026 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3028 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3035 /* Initialize IT for stepping through current_buffer in window W,
3036 starting at position POS that includes overlay string and display
3037 vector/ control character translation position information. Value
3038 is zero if there are overlay strings with newlines at POS. */
3041 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3043 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3044 int i
, overlay_strings_with_newlines
= 0;
3046 /* If POS specifies a position in a display vector, this might
3047 be for an ellipsis displayed for invisible text. We won't
3048 get the iterator set up for delivering that ellipsis unless
3049 we make sure that it gets aware of the invisible text. */
3050 if (in_ellipses_for_invisible_text_p (pos
, w
))
3056 /* Keep in mind: the call to reseat in init_iterator skips invisible
3057 text, so we might end up at a position different from POS. This
3058 is only a problem when POS is a row start after a newline and an
3059 overlay starts there with an after-string, and the overlay has an
3060 invisible property. Since we don't skip invisible text in
3061 display_line and elsewhere immediately after consuming the
3062 newline before the row start, such a POS will not be in a string,
3063 but the call to init_iterator below will move us to the
3065 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3067 /* This only scans the current chunk -- it should scan all chunks.
3068 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3069 to 16 in 22.1 to make this a lesser problem. */
3070 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3072 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3073 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3075 while (s
< e
&& *s
!= '\n')
3080 overlay_strings_with_newlines
= 1;
3085 /* If position is within an overlay string, set up IT to the right
3087 if (pos
->overlay_string_index
>= 0)
3091 /* If the first overlay string happens to have a `display'
3092 property for an image, the iterator will be set up for that
3093 image, and we have to undo that setup first before we can
3094 correct the overlay string index. */
3095 if (it
->method
== GET_FROM_IMAGE
)
3098 /* We already have the first chunk of overlay strings in
3099 IT->overlay_strings. Load more until the one for
3100 pos->overlay_string_index is in IT->overlay_strings. */
3101 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3103 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3104 it
->current
.overlay_string_index
= 0;
3107 load_overlay_strings (it
, 0);
3108 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3112 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3113 relative_index
= (it
->current
.overlay_string_index
3114 % OVERLAY_STRING_CHUNK_SIZE
);
3115 it
->string
= it
->overlay_strings
[relative_index
];
3116 eassert (STRINGP (it
->string
));
3117 it
->current
.string_pos
= pos
->string_pos
;
3118 it
->method
= GET_FROM_STRING
;
3119 it
->end_charpos
= SCHARS (it
->string
);
3120 /* Set up the bidi iterator for this overlay string. */
3123 it
->bidi_it
.string
.lstring
= it
->string
;
3124 it
->bidi_it
.string
.s
= NULL
;
3125 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3126 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3127 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3128 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3129 it
->bidi_it
.w
= it
->w
;
3130 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3131 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3133 /* Synchronize the state of the bidi iterator with
3134 pos->string_pos. For any string position other than
3135 zero, this will be done automagically when we resume
3136 iteration over the string and get_visually_first_element
3137 is called. But if string_pos is zero, and the string is
3138 to be reordered for display, we need to resync manually,
3139 since it could be that the iteration state recorded in
3140 pos ended at string_pos of 0 moving backwards in string. */
3141 if (CHARPOS (pos
->string_pos
) == 0)
3143 get_visually_first_element (it
);
3144 if (IT_STRING_CHARPOS (*it
) != 0)
3147 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3148 bidi_move_to_visually_next (&it
->bidi_it
);
3149 } while (it
->bidi_it
.charpos
!= 0);
3151 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3152 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3156 if (CHARPOS (pos
->string_pos
) >= 0)
3158 /* Recorded position is not in an overlay string, but in another
3159 string. This can only be a string from a `display' property.
3160 IT should already be filled with that string. */
3161 it
->current
.string_pos
= pos
->string_pos
;
3162 eassert (STRINGP (it
->string
));
3164 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3165 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3168 /* Restore position in display vector translations, control
3169 character translations or ellipses. */
3170 if (pos
->dpvec_index
>= 0)
3172 if (it
->dpvec
== NULL
)
3173 get_next_display_element (it
);
3174 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3175 it
->current
.dpvec_index
= pos
->dpvec_index
;
3179 return !overlay_strings_with_newlines
;
3183 /* Initialize IT for stepping through current_buffer in window W
3184 starting at ROW->start. */
3187 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3189 init_from_display_pos (it
, w
, &row
->start
);
3190 it
->start
= row
->start
;
3191 it
->continuation_lines_width
= row
->continuation_lines_width
;
3196 /* Initialize IT for stepping through current_buffer in window W
3197 starting in the line following ROW, i.e. starting at ROW->end.
3198 Value is zero if there are overlay strings with newlines at ROW's
3202 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3206 if (init_from_display_pos (it
, w
, &row
->end
))
3208 if (row
->continued_p
)
3209 it
->continuation_lines_width
3210 = row
->continuation_lines_width
+ row
->pixel_width
;
3221 /***********************************************************************
3223 ***********************************************************************/
3225 /* Called when IT reaches IT->stop_charpos. Handle text property and
3226 overlay changes. Set IT->stop_charpos to the next position where
3230 handle_stop (struct it
*it
)
3232 enum prop_handled handled
;
3233 int handle_overlay_change_p
;
3237 it
->current
.dpvec_index
= -1;
3238 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3239 it
->ignore_overlay_strings_at_pos_p
= 0;
3242 /* Use face of preceding text for ellipsis (if invisible) */
3243 if (it
->selective_display_ellipsis_p
)
3244 it
->saved_face_id
= it
->face_id
;
3248 handled
= HANDLED_NORMALLY
;
3250 /* Call text property handlers. */
3251 for (p
= it_props
; p
->handler
; ++p
)
3253 handled
= p
->handler (it
);
3255 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3257 else if (handled
== HANDLED_RETURN
)
3259 /* We still want to show before and after strings from
3260 overlays even if the actual buffer text is replaced. */
3261 if (!handle_overlay_change_p
3263 /* Don't call get_overlay_strings_1 if we already
3264 have overlay strings loaded, because doing so
3265 will load them again and push the iterator state
3266 onto the stack one more time, which is not
3267 expected by the rest of the code that processes
3269 || (it
->current
.overlay_string_index
< 0
3270 ? !get_overlay_strings_1 (it
, 0, 0)
3274 setup_for_ellipsis (it
, 0);
3275 /* When handling a display spec, we might load an
3276 empty string. In that case, discard it here. We
3277 used to discard it in handle_single_display_spec,
3278 but that causes get_overlay_strings_1, above, to
3279 ignore overlay strings that we must check. */
3280 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3284 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3288 it
->ignore_overlay_strings_at_pos_p
= 1;
3289 it
->string_from_display_prop_p
= 0;
3290 it
->from_disp_prop_p
= 0;
3291 handle_overlay_change_p
= 0;
3293 handled
= HANDLED_RECOMPUTE_PROPS
;
3296 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3297 handle_overlay_change_p
= 0;
3300 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3302 /* Don't check for overlay strings below when set to deliver
3303 characters from a display vector. */
3304 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3305 handle_overlay_change_p
= 0;
3307 /* Handle overlay changes.
3308 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3309 if it finds overlays. */
3310 if (handle_overlay_change_p
)
3311 handled
= handle_overlay_change (it
);
3316 setup_for_ellipsis (it
, 0);
3320 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3322 /* Determine where to stop next. */
3323 if (handled
== HANDLED_NORMALLY
)
3324 compute_stop_pos (it
);
3328 /* Compute IT->stop_charpos from text property and overlay change
3329 information for IT's current position. */
3332 compute_stop_pos (struct it
*it
)
3334 register INTERVAL iv
, next_iv
;
3335 Lisp_Object object
, limit
, position
;
3336 ptrdiff_t charpos
, bytepos
;
3338 if (STRINGP (it
->string
))
3340 /* Strings are usually short, so don't limit the search for
3342 it
->stop_charpos
= it
->end_charpos
;
3343 object
= it
->string
;
3345 charpos
= IT_STRING_CHARPOS (*it
);
3346 bytepos
= IT_STRING_BYTEPOS (*it
);
3352 /* If end_charpos is out of range for some reason, such as a
3353 misbehaving display function, rationalize it (Bug#5984). */
3354 if (it
->end_charpos
> ZV
)
3355 it
->end_charpos
= ZV
;
3356 it
->stop_charpos
= it
->end_charpos
;
3358 /* If next overlay change is in front of the current stop pos
3359 (which is IT->end_charpos), stop there. Note: value of
3360 next_overlay_change is point-max if no overlay change
3362 charpos
= IT_CHARPOS (*it
);
3363 bytepos
= IT_BYTEPOS (*it
);
3364 pos
= next_overlay_change (charpos
);
3365 if (pos
< it
->stop_charpos
)
3366 it
->stop_charpos
= pos
;
3368 /* Set up variables for computing the stop position from text
3369 property changes. */
3370 XSETBUFFER (object
, current_buffer
);
3371 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3374 /* Get the interval containing IT's position. Value is a null
3375 interval if there isn't such an interval. */
3376 position
= make_number (charpos
);
3377 iv
= validate_interval_range (object
, &position
, &position
, 0);
3380 Lisp_Object values_here
[LAST_PROP_IDX
];
3383 /* Get properties here. */
3384 for (p
= it_props
; p
->handler
; ++p
)
3385 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3387 /* Look for an interval following iv that has different
3389 for (next_iv
= next_interval (iv
);
3392 || XFASTINT (limit
) > next_iv
->position
));
3393 next_iv
= next_interval (next_iv
))
3395 for (p
= it_props
; p
->handler
; ++p
)
3397 Lisp_Object new_value
;
3399 new_value
= textget (next_iv
->plist
, *p
->name
);
3400 if (!EQ (values_here
[p
->idx
], new_value
))
3410 if (INTEGERP (limit
)
3411 && next_iv
->position
>= XFASTINT (limit
))
3412 /* No text property change up to limit. */
3413 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3415 /* Text properties change in next_iv. */
3416 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3420 if (it
->cmp_it
.id
< 0)
3422 ptrdiff_t stoppos
= it
->end_charpos
;
3424 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3426 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3427 stoppos
, it
->string
);
3430 eassert (STRINGP (it
->string
)
3431 || (it
->stop_charpos
>= BEGV
3432 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3436 /* Return the position of the next overlay change after POS in
3437 current_buffer. Value is point-max if no overlay change
3438 follows. This is like `next-overlay-change' but doesn't use
3442 next_overlay_change (ptrdiff_t pos
)
3444 ptrdiff_t i
, noverlays
;
3446 Lisp_Object
*overlays
;
3448 /* Get all overlays at the given position. */
3449 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3451 /* If any of these overlays ends before endpos,
3452 use its ending point instead. */
3453 for (i
= 0; i
< noverlays
; ++i
)
3458 oend
= OVERLAY_END (overlays
[i
]);
3459 oendpos
= OVERLAY_POSITION (oend
);
3460 endpos
= min (endpos
, oendpos
);
3466 /* How many characters forward to search for a display property or
3467 display string. Searching too far forward makes the bidi display
3468 sluggish, especially in small windows. */
3469 #define MAX_DISP_SCAN 250
3471 /* Return the character position of a display string at or after
3472 position specified by POSITION. If no display string exists at or
3473 after POSITION, return ZV. A display string is either an overlay
3474 with `display' property whose value is a string, or a `display'
3475 text property whose value is a string. STRING is data about the
3476 string to iterate; if STRING->lstring is nil, we are iterating a
3477 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3478 on a GUI frame. DISP_PROP is set to zero if we searched
3479 MAX_DISP_SCAN characters forward without finding any display
3480 strings, non-zero otherwise. It is set to 2 if the display string
3481 uses any kind of `(space ...)' spec that will produce a stretch of
3482 white space in the text area. */
3484 compute_display_string_pos (struct text_pos
*position
,
3485 struct bidi_string_data
*string
,
3487 int frame_window_p
, int *disp_prop
)
3489 /* OBJECT = nil means current buffer. */
3490 Lisp_Object object
, object1
;
3491 Lisp_Object pos
, spec
, limpos
;
3492 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3493 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3494 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3495 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3497 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3498 struct text_pos tpos
;
3501 if (string
&& STRINGP (string
->lstring
))
3502 object1
= object
= string
->lstring
;
3503 else if (w
&& !string_p
)
3505 XSETWINDOW (object
, w
);
3509 object1
= object
= Qnil
;
3514 /* We don't support display properties whose values are strings
3515 that have display string properties. */
3516 || string
->from_disp_str
3517 /* C strings cannot have display properties. */
3518 || (string
->s
&& !STRINGP (object
)))
3524 /* If the character at CHARPOS is where the display string begins,
3526 pos
= make_number (charpos
);
3527 if (STRINGP (object
))
3528 bufpos
= string
->bufpos
;
3532 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3534 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3537 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3545 /* Look forward for the first character with a `display' property
3546 that will replace the underlying text when displayed. */
3547 limpos
= make_number (lim
);
3549 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3550 CHARPOS (tpos
) = XFASTINT (pos
);
3551 if (CHARPOS (tpos
) >= lim
)
3556 if (STRINGP (object
))
3557 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3559 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3560 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3561 if (!STRINGP (object
))
3562 bufpos
= CHARPOS (tpos
);
3563 } while (NILP (spec
)
3564 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3565 bufpos
, frame_window_p
)));
3569 return CHARPOS (tpos
);
3572 /* Return the character position of the end of the display string that
3573 started at CHARPOS. If there's no display string at CHARPOS,
3574 return -1. A display string is either an overlay with `display'
3575 property whose value is a string or a `display' text property whose
3576 value is a string. */
3578 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3580 /* OBJECT = nil means current buffer. */
3581 Lisp_Object object
=
3582 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3583 Lisp_Object pos
= make_number (charpos
);
3585 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3587 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3590 /* It could happen that the display property or overlay was removed
3591 since we found it in compute_display_string_pos above. One way
3592 this can happen is if JIT font-lock was called (through
3593 handle_fontified_prop), and jit-lock-functions remove text
3594 properties or overlays from the portion of buffer that includes
3595 CHARPOS. Muse mode is known to do that, for example. In this
3596 case, we return -1 to the caller, to signal that no display
3597 string is actually present at CHARPOS. See bidi_fetch_char for
3598 how this is handled.
3600 An alternative would be to never look for display properties past
3601 it->stop_charpos. But neither compute_display_string_pos nor
3602 bidi_fetch_char that calls it know or care where the next
3604 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3607 /* Look forward for the first character where the `display' property
3609 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3611 return XFASTINT (pos
);
3616 /***********************************************************************
3618 ***********************************************************************/
3620 /* Handle changes in the `fontified' property of the current buffer by
3621 calling hook functions from Qfontification_functions to fontify
3624 static enum prop_handled
3625 handle_fontified_prop (struct it
*it
)
3627 Lisp_Object prop
, pos
;
3628 enum prop_handled handled
= HANDLED_NORMALLY
;
3630 if (!NILP (Vmemory_full
))
3633 /* Get the value of the `fontified' property at IT's current buffer
3634 position. (The `fontified' property doesn't have a special
3635 meaning in strings.) If the value is nil, call functions from
3636 Qfontification_functions. */
3637 if (!STRINGP (it
->string
)
3639 && !NILP (Vfontification_functions
)
3640 && !NILP (Vrun_hooks
)
3641 && (pos
= make_number (IT_CHARPOS (*it
)),
3642 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3643 /* Ignore the special cased nil value always present at EOB since
3644 no amount of fontifying will be able to change it. */
3645 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3647 ptrdiff_t count
= SPECPDL_INDEX ();
3649 struct buffer
*obuf
= current_buffer
;
3650 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3651 bool old_clip_changed
= current_buffer
->clip_changed
;
3653 val
= Vfontification_functions
;
3654 specbind (Qfontification_functions
, Qnil
);
3656 eassert (it
->end_charpos
== ZV
);
3658 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3659 safe_call1 (val
, pos
);
3662 Lisp_Object fns
, fn
;
3663 struct gcpro gcpro1
, gcpro2
;
3668 for (; CONSP (val
); val
= XCDR (val
))
3674 /* A value of t indicates this hook has a local
3675 binding; it means to run the global binding too.
3676 In a global value, t should not occur. If it
3677 does, we must ignore it to avoid an endless
3679 for (fns
= Fdefault_value (Qfontification_functions
);
3685 safe_call1 (fn
, pos
);
3689 safe_call1 (fn
, pos
);
3695 unbind_to (count
, Qnil
);
3697 /* Fontification functions routinely call `save-restriction'.
3698 Normally, this tags clip_changed, which can confuse redisplay
3699 (see discussion in Bug#6671). Since we don't perform any
3700 special handling of fontification changes in the case where
3701 `save-restriction' isn't called, there's no point doing so in
3702 this case either. So, if the buffer's restrictions are
3703 actually left unchanged, reset clip_changed. */
3704 if (obuf
== current_buffer
)
3706 if (begv
== BEGV
&& zv
== ZV
)
3707 current_buffer
->clip_changed
= old_clip_changed
;
3709 /* There isn't much we can reasonably do to protect against
3710 misbehaving fontification, but here's a fig leaf. */
3711 else if (BUFFER_LIVE_P (obuf
))
3712 set_buffer_internal_1 (obuf
);
3714 /* The fontification code may have added/removed text.
3715 It could do even a lot worse, but let's at least protect against
3716 the most obvious case where only the text past `pos' gets changed',
3717 as is/was done in grep.el where some escapes sequences are turned
3718 into face properties (bug#7876). */
3719 it
->end_charpos
= ZV
;
3721 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3722 something. This avoids an endless loop if they failed to
3723 fontify the text for which reason ever. */
3724 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3725 handled
= HANDLED_RECOMPUTE_PROPS
;
3733 /***********************************************************************
3735 ***********************************************************************/
3737 /* Set up iterator IT from face properties at its current position.
3738 Called from handle_stop. */
3740 static enum prop_handled
3741 handle_face_prop (struct it
*it
)
3744 ptrdiff_t next_stop
;
3746 if (!STRINGP (it
->string
))
3749 = face_at_buffer_position (it
->w
,
3753 + TEXT_PROP_DISTANCE_LIMIT
),
3754 0, it
->base_face_id
);
3756 /* Is this a start of a run of characters with box face?
3757 Caveat: this can be called for a freshly initialized
3758 iterator; face_id is -1 in this case. We know that the new
3759 face will not change until limit, i.e. if the new face has a
3760 box, all characters up to limit will have one. But, as
3761 usual, we don't know whether limit is really the end. */
3762 if (new_face_id
!= it
->face_id
)
3764 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3765 /* If it->face_id is -1, old_face below will be NULL, see
3766 the definition of FACE_FROM_ID. This will happen if this
3767 is the initial call that gets the face. */
3768 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3770 /* If the value of face_id of the iterator is -1, we have to
3771 look in front of IT's position and see whether there is a
3772 face there that's different from new_face_id. */
3773 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3775 int prev_face_id
= face_before_it_pos (it
);
3777 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3780 /* If the new face has a box, but the old face does not,
3781 this is the start of a run of characters with box face,
3782 i.e. this character has a shadow on the left side. */
3783 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3784 && (old_face
== NULL
|| !old_face
->box
));
3785 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3793 Lisp_Object from_overlay
3794 = (it
->current
.overlay_string_index
>= 0
3795 ? it
->string_overlays
[it
->current
.overlay_string_index
3796 % OVERLAY_STRING_CHUNK_SIZE
]
3799 /* See if we got to this string directly or indirectly from
3800 an overlay property. That includes the before-string or
3801 after-string of an overlay, strings in display properties
3802 provided by an overlay, their text properties, etc.
3804 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3805 if (! NILP (from_overlay
))
3806 for (i
= it
->sp
- 1; i
>= 0; i
--)
3808 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3810 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3811 % OVERLAY_STRING_CHUNK_SIZE
];
3812 else if (! NILP (it
->stack
[i
].from_overlay
))
3813 from_overlay
= it
->stack
[i
].from_overlay
;
3815 if (!NILP (from_overlay
))
3819 if (! NILP (from_overlay
))
3821 bufpos
= IT_CHARPOS (*it
);
3822 /* For a string from an overlay, the base face depends
3823 only on text properties and ignores overlays. */
3825 = face_for_overlay_string (it
->w
,
3829 + TEXT_PROP_DISTANCE_LIMIT
),
3837 /* For strings from a `display' property, use the face at
3838 IT's current buffer position as the base face to merge
3839 with, so that overlay strings appear in the same face as
3840 surrounding text, unless they specify their own faces.
3841 For strings from wrap-prefix and line-prefix properties,
3842 use the default face, possibly remapped via
3843 Vface_remapping_alist. */
3844 base_face_id
= it
->string_from_prefix_prop_p
3845 ? (!NILP (Vface_remapping_alist
)
3846 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3848 : underlying_face_id (it
);
3851 new_face_id
= face_at_string_position (it
->w
,
3853 IT_STRING_CHARPOS (*it
),
3858 /* Is this a start of a run of characters with box? Caveat:
3859 this can be called for a freshly allocated iterator; face_id
3860 is -1 is this case. We know that the new face will not
3861 change until the next check pos, i.e. if the new face has a
3862 box, all characters up to that position will have a
3863 box. But, as usual, we don't know whether that position
3864 is really the end. */
3865 if (new_face_id
!= it
->face_id
)
3867 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3868 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3870 /* If new face has a box but old face hasn't, this is the
3871 start of a run of characters with box, i.e. it has a
3872 shadow on the left side. */
3873 it
->start_of_box_run_p
3874 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3875 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3879 it
->face_id
= new_face_id
;
3880 return HANDLED_NORMALLY
;
3884 /* Return the ID of the face ``underlying'' IT's current position,
3885 which is in a string. If the iterator is associated with a
3886 buffer, return the face at IT's current buffer position.
3887 Otherwise, use the iterator's base_face_id. */
3890 underlying_face_id (struct it
*it
)
3892 int face_id
= it
->base_face_id
, i
;
3894 eassert (STRINGP (it
->string
));
3896 for (i
= it
->sp
- 1; i
>= 0; --i
)
3897 if (NILP (it
->stack
[i
].string
))
3898 face_id
= it
->stack
[i
].face_id
;
3904 /* Compute the face one character before or after the current position
3905 of IT, in the visual order. BEFORE_P non-zero means get the face
3906 in front (to the left in L2R paragraphs, to the right in R2L
3907 paragraphs) of IT's screen position. Value is the ID of the face. */
3910 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3913 ptrdiff_t next_check_charpos
;
3915 void *it_copy_data
= NULL
;
3917 eassert (it
->s
== NULL
);
3919 if (STRINGP (it
->string
))
3921 ptrdiff_t bufpos
, charpos
;
3924 /* No face change past the end of the string (for the case
3925 we are padding with spaces). No face change before the
3927 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3928 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3933 /* Set charpos to the position before or after IT's current
3934 position, in the logical order, which in the non-bidi
3935 case is the same as the visual order. */
3937 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3938 else if (it
->what
== IT_COMPOSITION
)
3939 /* For composition, we must check the character after the
3941 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3943 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3949 /* With bidi iteration, the character before the current
3950 in the visual order cannot be found by simple
3951 iteration, because "reverse" reordering is not
3952 supported. Instead, we need to use the move_it_*
3953 family of functions. */
3954 /* Ignore face changes before the first visible
3955 character on this display line. */
3956 if (it
->current_x
<= it
->first_visible_x
)
3958 SAVE_IT (it_copy
, *it
, it_copy_data
);
3959 /* Implementation note: Since move_it_in_display_line
3960 works in the iterator geometry, and thinks the first
3961 character is always the leftmost, even in R2L lines,
3962 we don't need to distinguish between the R2L and L2R
3964 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3965 it_copy
.current_x
- 1, MOVE_TO_X
);
3966 charpos
= IT_STRING_CHARPOS (it_copy
);
3967 RESTORE_IT (it
, it
, it_copy_data
);
3971 /* Set charpos to the string position of the character
3972 that comes after IT's current position in the visual
3974 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3978 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3980 charpos
= it_copy
.bidi_it
.charpos
;
3983 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3985 if (it
->current
.overlay_string_index
>= 0)
3986 bufpos
= IT_CHARPOS (*it
);
3990 base_face_id
= underlying_face_id (it
);
3992 /* Get the face for ASCII, or unibyte. */
3993 face_id
= face_at_string_position (it
->w
,
3997 &next_check_charpos
,
4000 /* Correct the face for charsets different from ASCII. Do it
4001 for the multibyte case only. The face returned above is
4002 suitable for unibyte text if IT->string is unibyte. */
4003 if (STRING_MULTIBYTE (it
->string
))
4005 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4006 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4008 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4010 c
= string_char_and_length (p
, &len
);
4011 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4016 struct text_pos pos
;
4018 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4019 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4022 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4023 pos
= it
->current
.pos
;
4028 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4031 if (it
->what
== IT_COMPOSITION
)
4033 /* For composition, we must check the position after
4035 pos
.charpos
+= it
->cmp_it
.nchars
;
4036 pos
.bytepos
+= it
->len
;
4039 INC_TEXT_POS (pos
, it
->multibyte_p
);
4046 /* With bidi iteration, the character before the current
4047 in the visual order cannot be found by simple
4048 iteration, because "reverse" reordering is not
4049 supported. Instead, we need to use the move_it_*
4050 family of functions. */
4051 /* Ignore face changes before the first visible
4052 character on this display line. */
4053 if (it
->current_x
<= it
->first_visible_x
)
4055 SAVE_IT (it_copy
, *it
, it_copy_data
);
4056 /* Implementation note: Since move_it_in_display_line
4057 works in the iterator geometry, and thinks the first
4058 character is always the leftmost, even in R2L lines,
4059 we don't need to distinguish between the R2L and L2R
4061 move_it_in_display_line (&it_copy
, ZV
,
4062 it_copy
.current_x
- 1, MOVE_TO_X
);
4063 pos
= it_copy
.current
.pos
;
4064 RESTORE_IT (it
, it
, it_copy_data
);
4068 /* Set charpos to the buffer position of the character
4069 that comes after IT's current position in the visual
4071 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4075 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4078 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4081 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4083 /* Determine face for CHARSET_ASCII, or unibyte. */
4084 face_id
= face_at_buffer_position (it
->w
,
4086 &next_check_charpos
,
4089 /* Correct the face for charsets different from ASCII. Do it
4090 for the multibyte case only. The face returned above is
4091 suitable for unibyte text if current_buffer is unibyte. */
4092 if (it
->multibyte_p
)
4094 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4095 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4096 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4105 /***********************************************************************
4107 ***********************************************************************/
4109 /* Set up iterator IT from invisible properties at its current
4110 position. Called from handle_stop. */
4112 static enum prop_handled
4113 handle_invisible_prop (struct it
*it
)
4115 enum prop_handled handled
= HANDLED_NORMALLY
;
4119 if (STRINGP (it
->string
))
4121 Lisp_Object end_charpos
, limit
, charpos
;
4123 /* Get the value of the invisible text property at the
4124 current position. Value will be nil if there is no such
4126 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4127 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4128 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4130 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4132 /* Record whether we have to display an ellipsis for the
4134 int display_ellipsis_p
= (invis_p
== 2);
4135 ptrdiff_t len
, endpos
;
4137 handled
= HANDLED_RECOMPUTE_PROPS
;
4139 /* Get the position at which the next visible text can be
4140 found in IT->string, if any. */
4141 endpos
= len
= SCHARS (it
->string
);
4142 XSETINT (limit
, len
);
4145 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4147 if (INTEGERP (end_charpos
))
4149 endpos
= XFASTINT (end_charpos
);
4150 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4151 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4153 display_ellipsis_p
= 1;
4156 while (invis_p
&& endpos
< len
);
4158 if (display_ellipsis_p
)
4163 /* Text at END_CHARPOS is visible. Move IT there. */
4164 struct text_pos old
;
4167 old
= it
->current
.string_pos
;
4168 oldpos
= CHARPOS (old
);
4171 if (it
->bidi_it
.first_elt
4172 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4173 bidi_paragraph_init (it
->paragraph_embedding
,
4175 /* Bidi-iterate out of the invisible text. */
4178 bidi_move_to_visually_next (&it
->bidi_it
);
4180 while (oldpos
<= it
->bidi_it
.charpos
4181 && it
->bidi_it
.charpos
< endpos
);
4183 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4184 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4185 if (IT_CHARPOS (*it
) >= endpos
)
4186 it
->prev_stop
= endpos
;
4190 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4191 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4196 /* The rest of the string is invisible. If this is an
4197 overlay string, proceed with the next overlay string
4198 or whatever comes and return a character from there. */
4199 if (it
->current
.overlay_string_index
>= 0
4200 && !display_ellipsis_p
)
4202 next_overlay_string (it
);
4203 /* Don't check for overlay strings when we just
4204 finished processing them. */
4205 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4209 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4210 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4217 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4218 Lisp_Object pos
, overlay
;
4220 /* First of all, is there invisible text at this position? */
4221 tem
= start_charpos
= IT_CHARPOS (*it
);
4222 pos
= make_number (tem
);
4223 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4225 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4227 /* If we are on invisible text, skip over it. */
4228 if (invis_p
&& start_charpos
< it
->end_charpos
)
4230 /* Record whether we have to display an ellipsis for the
4232 int display_ellipsis_p
= invis_p
== 2;
4234 handled
= HANDLED_RECOMPUTE_PROPS
;
4236 /* Loop skipping over invisible text. The loop is left at
4237 ZV or with IT on the first char being visible again. */
4240 /* Try to skip some invisible text. Return value is the
4241 position reached which can be equal to where we start
4242 if there is nothing invisible there. This skips both
4243 over invisible text properties and overlays with
4244 invisible property. */
4245 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4247 /* If we skipped nothing at all we weren't at invisible
4248 text in the first place. If everything to the end of
4249 the buffer was skipped, end the loop. */
4250 if (newpos
== tem
|| newpos
>= ZV
)
4254 /* We skipped some characters but not necessarily
4255 all there are. Check if we ended up on visible
4256 text. Fget_char_property returns the property of
4257 the char before the given position, i.e. if we
4258 get invis_p = 0, this means that the char at
4259 newpos is visible. */
4260 pos
= make_number (newpos
);
4261 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4262 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4265 /* If we ended up on invisible text, proceed to
4266 skip starting with next_stop. */
4270 /* If there are adjacent invisible texts, don't lose the
4271 second one's ellipsis. */
4273 display_ellipsis_p
= 1;
4277 /* The position newpos is now either ZV or on visible text. */
4280 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4282 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4284 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4286 /* If the invisible text ends on a newline or on a
4287 character after a newline, we can avoid the costly,
4288 character by character, bidi iteration to NEWPOS, and
4289 instead simply reseat the iterator there. That's
4290 because all bidi reordering information is tossed at
4291 the newline. This is a big win for modes that hide
4292 complete lines, like Outline, Org, etc. */
4293 if (on_newline
|| after_newline
)
4295 struct text_pos tpos
;
4296 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4298 SET_TEXT_POS (tpos
, newpos
, bpos
);
4299 reseat_1 (it
, tpos
, 0);
4300 /* If we reseat on a newline/ZV, we need to prep the
4301 bidi iterator for advancing to the next character
4302 after the newline/EOB, keeping the current paragraph
4303 direction (so that PRODUCE_GLYPHS does TRT wrt
4304 prepending/appending glyphs to a glyph row). */
4307 it
->bidi_it
.first_elt
= 0;
4308 it
->bidi_it
.paragraph_dir
= pdir
;
4309 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4310 it
->bidi_it
.nchars
= 1;
4311 it
->bidi_it
.ch_len
= 1;
4314 else /* Must use the slow method. */
4316 /* With bidi iteration, the region of invisible text
4317 could start and/or end in the middle of a
4318 non-base embedding level. Therefore, we need to
4319 skip invisible text using the bidi iterator,
4320 starting at IT's current position, until we find
4321 ourselves outside of the invisible text.
4322 Skipping invisible text _after_ bidi iteration
4323 avoids affecting the visual order of the
4324 displayed text when invisible properties are
4325 added or removed. */
4326 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4328 /* If we were `reseat'ed to a new paragraph,
4329 determine the paragraph base direction. We
4330 need to do it now because
4331 next_element_from_buffer may not have a
4332 chance to do it, if we are going to skip any
4333 text at the beginning, which resets the
4335 bidi_paragraph_init (it
->paragraph_embedding
,
4340 bidi_move_to_visually_next (&it
->bidi_it
);
4342 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4343 && it
->bidi_it
.charpos
< newpos
);
4344 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4345 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4346 /* If we overstepped NEWPOS, record its position in
4347 the iterator, so that we skip invisible text if
4348 later the bidi iteration lands us in the
4349 invisible region again. */
4350 if (IT_CHARPOS (*it
) >= newpos
)
4351 it
->prev_stop
= newpos
;
4356 IT_CHARPOS (*it
) = newpos
;
4357 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4360 /* If there are before-strings at the start of invisible
4361 text, and the text is invisible because of a text
4362 property, arrange to show before-strings because 20.x did
4363 it that way. (If the text is invisible because of an
4364 overlay property instead of a text property, this is
4365 already handled in the overlay code.) */
4367 && get_overlay_strings (it
, it
->stop_charpos
))
4369 handled
= HANDLED_RECOMPUTE_PROPS
;
4370 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4372 else if (display_ellipsis_p
)
4374 /* Make sure that the glyphs of the ellipsis will get
4375 correct `charpos' values. If we would not update
4376 it->position here, the glyphs would belong to the
4377 last visible character _before_ the invisible
4378 text, which confuses `set_cursor_from_row'.
4380 We use the last invisible position instead of the
4381 first because this way the cursor is always drawn on
4382 the first "." of the ellipsis, whenever PT is inside
4383 the invisible text. Otherwise the cursor would be
4384 placed _after_ the ellipsis when the point is after the
4385 first invisible character. */
4386 if (!STRINGP (it
->object
))
4388 it
->position
.charpos
= newpos
- 1;
4389 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4392 /* Let the ellipsis display before
4393 considering any properties of the following char.
4394 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4395 handled
= HANDLED_RETURN
;
4404 /* Make iterator IT return `...' next.
4405 Replaces LEN characters from buffer. */
4408 setup_for_ellipsis (struct it
*it
, int len
)
4410 /* Use the display table definition for `...'. Invalid glyphs
4411 will be handled by the method returning elements from dpvec. */
4412 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4414 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4415 it
->dpvec
= v
->u
.contents
;
4416 it
->dpend
= v
->u
.contents
+ v
->header
.size
;
4420 /* Default `...'. */
4421 it
->dpvec
= default_invis_vector
;
4422 it
->dpend
= default_invis_vector
+ 3;
4425 it
->dpvec_char_len
= len
;
4426 it
->current
.dpvec_index
= 0;
4427 it
->dpvec_face_id
= -1;
4429 /* Remember the current face id in case glyphs specify faces.
4430 IT's face is restored in set_iterator_to_next.
4431 saved_face_id was set to preceding char's face in handle_stop. */
4432 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4433 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4435 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4441 /***********************************************************************
4443 ***********************************************************************/
4445 /* Set up iterator IT from `display' property at its current position.
4446 Called from handle_stop.
4447 We return HANDLED_RETURN if some part of the display property
4448 overrides the display of the buffer text itself.
4449 Otherwise we return HANDLED_NORMALLY. */
4451 static enum prop_handled
4452 handle_display_prop (struct it
*it
)
4454 Lisp_Object propval
, object
, overlay
;
4455 struct text_pos
*position
;
4457 /* Nonzero if some property replaces the display of the text itself. */
4458 int display_replaced_p
= 0;
4460 if (STRINGP (it
->string
))
4462 object
= it
->string
;
4463 position
= &it
->current
.string_pos
;
4464 bufpos
= CHARPOS (it
->current
.pos
);
4468 XSETWINDOW (object
, it
->w
);
4469 position
= &it
->current
.pos
;
4470 bufpos
= CHARPOS (*position
);
4473 /* Reset those iterator values set from display property values. */
4474 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4475 it
->space_width
= Qnil
;
4476 it
->font_height
= Qnil
;
4479 /* We don't support recursive `display' properties, i.e. string
4480 values that have a string `display' property, that have a string
4481 `display' property etc. */
4482 if (!it
->string_from_display_prop_p
)
4483 it
->area
= TEXT_AREA
;
4485 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4486 Qdisplay
, object
, &overlay
);
4488 return HANDLED_NORMALLY
;
4489 /* Now OVERLAY is the overlay that gave us this property, or nil
4490 if it was a text property. */
4492 if (!STRINGP (it
->string
))
4493 object
= it
->w
->contents
;
4495 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4497 FRAME_WINDOW_P (it
->f
));
4499 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4502 /* Subroutine of handle_display_prop. Returns non-zero if the display
4503 specification in SPEC is a replacing specification, i.e. it would
4504 replace the text covered by `display' property with something else,
4505 such as an image or a display string. If SPEC includes any kind or
4506 `(space ...) specification, the value is 2; this is used by
4507 compute_display_string_pos, which see.
4509 See handle_single_display_spec for documentation of arguments.
4510 frame_window_p is non-zero if the window being redisplayed is on a
4511 GUI frame; this argument is used only if IT is NULL, see below.
4513 IT can be NULL, if this is called by the bidi reordering code
4514 through compute_display_string_pos, which see. In that case, this
4515 function only examines SPEC, but does not otherwise "handle" it, in
4516 the sense that it doesn't set up members of IT from the display
4519 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4520 Lisp_Object overlay
, struct text_pos
*position
,
4521 ptrdiff_t bufpos
, int frame_window_p
)
4523 int replacing_p
= 0;
4527 /* Simple specifications. */
4528 && !EQ (XCAR (spec
), Qimage
)
4529 && !EQ (XCAR (spec
), Qspace
)
4530 && !EQ (XCAR (spec
), Qwhen
)
4531 && !EQ (XCAR (spec
), Qslice
)
4532 && !EQ (XCAR (spec
), Qspace_width
)
4533 && !EQ (XCAR (spec
), Qheight
)
4534 && !EQ (XCAR (spec
), Qraise
)
4535 /* Marginal area specifications. */
4536 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4537 && !EQ (XCAR (spec
), Qleft_fringe
)
4538 && !EQ (XCAR (spec
), Qright_fringe
)
4539 && !NILP (XCAR (spec
)))
4541 for (; CONSP (spec
); spec
= XCDR (spec
))
4543 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4544 overlay
, position
, bufpos
,
4545 replacing_p
, frame_window_p
)))
4548 /* If some text in a string is replaced, `position' no
4549 longer points to the position of `object'. */
4550 if (!it
|| STRINGP (object
))
4555 else if (VECTORP (spec
))
4558 for (i
= 0; i
< ASIZE (spec
); ++i
)
4559 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4560 overlay
, position
, bufpos
,
4561 replacing_p
, frame_window_p
)))
4564 /* If some text in a string is replaced, `position' no
4565 longer points to the position of `object'. */
4566 if (!it
|| STRINGP (object
))
4572 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4573 position
, bufpos
, 0,
4581 /* Value is the position of the end of the `display' property starting
4582 at START_POS in OBJECT. */
4584 static struct text_pos
4585 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4588 struct text_pos end_pos
;
4590 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4591 Qdisplay
, object
, Qnil
);
4592 CHARPOS (end_pos
) = XFASTINT (end
);
4593 if (STRINGP (object
))
4594 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4596 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4602 /* Set up IT from a single `display' property specification SPEC. OBJECT
4603 is the object in which the `display' property was found. *POSITION
4604 is the position in OBJECT at which the `display' property was found.
4605 BUFPOS is the buffer position of OBJECT (different from POSITION if
4606 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4607 previously saw a display specification which already replaced text
4608 display with something else, for example an image; we ignore such
4609 properties after the first one has been processed.
4611 OVERLAY is the overlay this `display' property came from,
4612 or nil if it was a text property.
4614 If SPEC is a `space' or `image' specification, and in some other
4615 cases too, set *POSITION to the position where the `display'
4618 If IT is NULL, only examine the property specification in SPEC, but
4619 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4620 is intended to be displayed in a window on a GUI frame.
4622 Value is non-zero if something was found which replaces the display
4623 of buffer or string text. */
4626 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4627 Lisp_Object overlay
, struct text_pos
*position
,
4628 ptrdiff_t bufpos
, int display_replaced_p
,
4632 Lisp_Object location
, value
;
4633 struct text_pos start_pos
= *position
;
4636 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4637 If the result is non-nil, use VALUE instead of SPEC. */
4639 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4648 if (!NILP (form
) && !EQ (form
, Qt
))
4650 ptrdiff_t count
= SPECPDL_INDEX ();
4651 struct gcpro gcpro1
;
4653 /* Bind `object' to the object having the `display' property, a
4654 buffer or string. Bind `position' to the position in the
4655 object where the property was found, and `buffer-position'
4656 to the current position in the buffer. */
4659 XSETBUFFER (object
, current_buffer
);
4660 specbind (Qobject
, object
);
4661 specbind (Qposition
, make_number (CHARPOS (*position
)));
4662 specbind (Qbuffer_position
, make_number (bufpos
));
4664 form
= safe_eval (form
);
4666 unbind_to (count
, Qnil
);
4672 /* Handle `(height HEIGHT)' specifications. */
4674 && EQ (XCAR (spec
), Qheight
)
4675 && CONSP (XCDR (spec
)))
4679 if (!FRAME_WINDOW_P (it
->f
))
4682 it
->font_height
= XCAR (XCDR (spec
));
4683 if (!NILP (it
->font_height
))
4685 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4686 int new_height
= -1;
4688 if (CONSP (it
->font_height
)
4689 && (EQ (XCAR (it
->font_height
), Qplus
)
4690 || EQ (XCAR (it
->font_height
), Qminus
))
4691 && CONSP (XCDR (it
->font_height
))
4692 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4694 /* `(+ N)' or `(- N)' where N is an integer. */
4695 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4696 if (EQ (XCAR (it
->font_height
), Qplus
))
4698 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4700 else if (FUNCTIONP (it
->font_height
))
4702 /* Call function with current height as argument.
4703 Value is the new height. */
4705 height
= safe_call1 (it
->font_height
,
4706 face
->lface
[LFACE_HEIGHT_INDEX
]);
4707 if (NUMBERP (height
))
4708 new_height
= XFLOATINT (height
);
4710 else if (NUMBERP (it
->font_height
))
4712 /* Value is a multiple of the canonical char height. */
4715 f
= FACE_FROM_ID (it
->f
,
4716 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4717 new_height
= (XFLOATINT (it
->font_height
)
4718 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4722 /* Evaluate IT->font_height with `height' bound to the
4723 current specified height to get the new height. */
4724 ptrdiff_t count
= SPECPDL_INDEX ();
4726 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4727 value
= safe_eval (it
->font_height
);
4728 unbind_to (count
, Qnil
);
4730 if (NUMBERP (value
))
4731 new_height
= XFLOATINT (value
);
4735 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4742 /* Handle `(space-width WIDTH)'. */
4744 && EQ (XCAR (spec
), Qspace_width
)
4745 && CONSP (XCDR (spec
)))
4749 if (!FRAME_WINDOW_P (it
->f
))
4752 value
= XCAR (XCDR (spec
));
4753 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4754 it
->space_width
= value
;
4760 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4762 && EQ (XCAR (spec
), Qslice
))
4768 if (!FRAME_WINDOW_P (it
->f
))
4771 if (tem
= XCDR (spec
), CONSP (tem
))
4773 it
->slice
.x
= XCAR (tem
);
4774 if (tem
= XCDR (tem
), CONSP (tem
))
4776 it
->slice
.y
= XCAR (tem
);
4777 if (tem
= XCDR (tem
), CONSP (tem
))
4779 it
->slice
.width
= XCAR (tem
);
4780 if (tem
= XCDR (tem
), CONSP (tem
))
4781 it
->slice
.height
= XCAR (tem
);
4790 /* Handle `(raise FACTOR)'. */
4792 && EQ (XCAR (spec
), Qraise
)
4793 && CONSP (XCDR (spec
)))
4797 if (!FRAME_WINDOW_P (it
->f
))
4800 #ifdef HAVE_WINDOW_SYSTEM
4801 value
= XCAR (XCDR (spec
));
4802 if (NUMBERP (value
))
4804 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4805 it
->voffset
= - (XFLOATINT (value
)
4806 * (FONT_HEIGHT (face
->font
)));
4808 #endif /* HAVE_WINDOW_SYSTEM */
4814 /* Don't handle the other kinds of display specifications
4815 inside a string that we got from a `display' property. */
4816 if (it
&& it
->string_from_display_prop_p
)
4819 /* Characters having this form of property are not displayed, so
4820 we have to find the end of the property. */
4823 start_pos
= *position
;
4824 *position
= display_prop_end (it
, object
, start_pos
);
4828 /* Stop the scan at that end position--we assume that all
4829 text properties change there. */
4831 it
->stop_charpos
= position
->charpos
;
4833 /* Handle `(left-fringe BITMAP [FACE])'
4834 and `(right-fringe BITMAP [FACE])'. */
4836 && (EQ (XCAR (spec
), Qleft_fringe
)
4837 || EQ (XCAR (spec
), Qright_fringe
))
4838 && CONSP (XCDR (spec
)))
4844 if (!FRAME_WINDOW_P (it
->f
))
4845 /* If we return here, POSITION has been advanced
4846 across the text with this property. */
4848 /* Synchronize the bidi iterator with POSITION. This is
4849 needed because we are not going to push the iterator
4850 on behalf of this display property, so there will be
4851 no pop_it call to do this synchronization for us. */
4854 it
->position
= *position
;
4855 iterate_out_of_display_property (it
);
4856 *position
= it
->position
;
4861 else if (!frame_window_p
)
4864 #ifdef HAVE_WINDOW_SYSTEM
4865 value
= XCAR (XCDR (spec
));
4866 if (!SYMBOLP (value
)
4867 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4868 /* If we return here, POSITION has been advanced
4869 across the text with this property. */
4871 if (it
&& it
->bidi_p
)
4873 it
->position
= *position
;
4874 iterate_out_of_display_property (it
);
4875 *position
= it
->position
;
4882 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4884 if (CONSP (XCDR (XCDR (spec
))))
4886 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4887 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4893 /* Save current settings of IT so that we can restore them
4894 when we are finished with the glyph property value. */
4895 push_it (it
, position
);
4897 it
->area
= TEXT_AREA
;
4898 it
->what
= IT_IMAGE
;
4899 it
->image_id
= -1; /* no image */
4900 it
->position
= start_pos
;
4901 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4902 it
->method
= GET_FROM_IMAGE
;
4903 it
->from_overlay
= Qnil
;
4904 it
->face_id
= face_id
;
4905 it
->from_disp_prop_p
= 1;
4907 /* Say that we haven't consumed the characters with
4908 `display' property yet. The call to pop_it in
4909 set_iterator_to_next will clean this up. */
4910 *position
= start_pos
;
4912 if (EQ (XCAR (spec
), Qleft_fringe
))
4914 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4915 it
->left_user_fringe_face_id
= face_id
;
4919 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4920 it
->right_user_fringe_face_id
= face_id
;
4923 #endif /* HAVE_WINDOW_SYSTEM */
4927 /* Prepare to handle `((margin left-margin) ...)',
4928 `((margin right-margin) ...)' and `((margin nil) ...)'
4929 prefixes for display specifications. */
4930 location
= Qunbound
;
4931 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4935 value
= XCDR (spec
);
4937 value
= XCAR (value
);
4940 if (EQ (XCAR (tem
), Qmargin
)
4941 && (tem
= XCDR (tem
),
4942 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4944 || EQ (tem
, Qleft_margin
)
4945 || EQ (tem
, Qright_margin
))))
4949 if (EQ (location
, Qunbound
))
4955 /* After this point, VALUE is the property after any
4956 margin prefix has been stripped. It must be a string,
4957 an image specification, or `(space ...)'.
4959 LOCATION specifies where to display: `left-margin',
4960 `right-margin' or nil. */
4962 valid_p
= (STRINGP (value
)
4963 #ifdef HAVE_WINDOW_SYSTEM
4964 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4965 && valid_image_p (value
))
4966 #endif /* not HAVE_WINDOW_SYSTEM */
4967 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4969 if (valid_p
&& !display_replaced_p
)
4975 /* Callers need to know whether the display spec is any kind
4976 of `(space ...)' spec that is about to affect text-area
4978 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4983 /* Save current settings of IT so that we can restore them
4984 when we are finished with the glyph property value. */
4985 push_it (it
, position
);
4986 it
->from_overlay
= overlay
;
4987 it
->from_disp_prop_p
= 1;
4989 if (NILP (location
))
4990 it
->area
= TEXT_AREA
;
4991 else if (EQ (location
, Qleft_margin
))
4992 it
->area
= LEFT_MARGIN_AREA
;
4994 it
->area
= RIGHT_MARGIN_AREA
;
4996 if (STRINGP (value
))
4999 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5000 it
->current
.overlay_string_index
= -1;
5001 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5002 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5003 it
->method
= GET_FROM_STRING
;
5004 it
->stop_charpos
= 0;
5006 it
->base_level_stop
= 0;
5007 it
->string_from_display_prop_p
= 1;
5008 /* Say that we haven't consumed the characters with
5009 `display' property yet. The call to pop_it in
5010 set_iterator_to_next will clean this up. */
5011 if (BUFFERP (object
))
5012 *position
= start_pos
;
5014 /* Force paragraph direction to be that of the parent
5015 object. If the parent object's paragraph direction is
5016 not yet determined, default to L2R. */
5017 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5018 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5020 it
->paragraph_embedding
= L2R
;
5022 /* Set up the bidi iterator for this display string. */
5025 it
->bidi_it
.string
.lstring
= it
->string
;
5026 it
->bidi_it
.string
.s
= NULL
;
5027 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5028 it
->bidi_it
.string
.bufpos
= bufpos
;
5029 it
->bidi_it
.string
.from_disp_str
= 1;
5030 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5031 it
->bidi_it
.w
= it
->w
;
5032 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5035 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5037 it
->method
= GET_FROM_STRETCH
;
5039 *position
= it
->position
= start_pos
;
5040 retval
= 1 + (it
->area
== TEXT_AREA
);
5042 #ifdef HAVE_WINDOW_SYSTEM
5045 it
->what
= IT_IMAGE
;
5046 it
->image_id
= lookup_image (it
->f
, value
);
5047 it
->position
= start_pos
;
5048 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5049 it
->method
= GET_FROM_IMAGE
;
5051 /* Say that we haven't consumed the characters with
5052 `display' property yet. The call to pop_it in
5053 set_iterator_to_next will clean this up. */
5054 *position
= start_pos
;
5056 #endif /* HAVE_WINDOW_SYSTEM */
5061 /* Invalid property or property not supported. Restore
5062 POSITION to what it was before. */
5063 *position
= start_pos
;
5067 /* Check if PROP is a display property value whose text should be
5068 treated as intangible. OVERLAY is the overlay from which PROP
5069 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5070 specify the buffer position covered by PROP. */
5073 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5074 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5076 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5077 struct text_pos position
;
5079 SET_TEXT_POS (position
, charpos
, bytepos
);
5080 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5081 &position
, charpos
, frame_window_p
);
5085 /* Return 1 if PROP is a display sub-property value containing STRING.
5087 Implementation note: this and the following function are really
5088 special cases of handle_display_spec and
5089 handle_single_display_spec, and should ideally use the same code.
5090 Until they do, these two pairs must be consistent and must be
5091 modified in sync. */
5094 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5096 if (EQ (string
, prop
))
5099 /* Skip over `when FORM'. */
5100 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5105 /* Actually, the condition following `when' should be eval'ed,
5106 like handle_single_display_spec does, and we should return
5107 zero if it evaluates to nil. However, this function is
5108 called only when the buffer was already displayed and some
5109 glyph in the glyph matrix was found to come from a display
5110 string. Therefore, the condition was already evaluated, and
5111 the result was non-nil, otherwise the display string wouldn't
5112 have been displayed and we would have never been called for
5113 this property. Thus, we can skip the evaluation and assume
5114 its result is non-nil. */
5119 /* Skip over `margin LOCATION'. */
5120 if (EQ (XCAR (prop
), Qmargin
))
5131 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5135 /* Return 1 if STRING appears in the `display' property PROP. */
5138 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5141 && !EQ (XCAR (prop
), Qwhen
)
5142 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5144 /* A list of sub-properties. */
5145 while (CONSP (prop
))
5147 if (single_display_spec_string_p (XCAR (prop
), string
))
5152 else if (VECTORP (prop
))
5154 /* A vector of sub-properties. */
5156 for (i
= 0; i
< ASIZE (prop
); ++i
)
5157 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5161 return single_display_spec_string_p (prop
, string
);
5166 /* Look for STRING in overlays and text properties in the current
5167 buffer, between character positions FROM and TO (excluding TO).
5168 BACK_P non-zero means look back (in this case, TO is supposed to be
5170 Value is the first character position where STRING was found, or
5171 zero if it wasn't found before hitting TO.
5173 This function may only use code that doesn't eval because it is
5174 called asynchronously from note_mouse_highlight. */
5177 string_buffer_position_lim (Lisp_Object string
,
5178 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5180 Lisp_Object limit
, prop
, pos
;
5183 pos
= make_number (max (from
, BEGV
));
5185 if (!back_p
) /* looking forward */
5187 limit
= make_number (min (to
, ZV
));
5188 while (!found
&& !EQ (pos
, limit
))
5190 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5191 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5194 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5198 else /* looking back */
5200 limit
= make_number (max (to
, BEGV
));
5201 while (!found
&& !EQ (pos
, limit
))
5203 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5204 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5207 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5212 return found
? XINT (pos
) : 0;
5215 /* Determine which buffer position in current buffer STRING comes from.
5216 AROUND_CHARPOS is an approximate position where it could come from.
5217 Value is the buffer position or 0 if it couldn't be determined.
5219 This function is necessary because we don't record buffer positions
5220 in glyphs generated from strings (to keep struct glyph small).
5221 This function may only use code that doesn't eval because it is
5222 called asynchronously from note_mouse_highlight. */
5225 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5227 const int MAX_DISTANCE
= 1000;
5228 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5229 around_charpos
+ MAX_DISTANCE
,
5233 found
= string_buffer_position_lim (string
, around_charpos
,
5234 around_charpos
- MAX_DISTANCE
, 1);
5240 /***********************************************************************
5241 `composition' property
5242 ***********************************************************************/
5244 /* Set up iterator IT from `composition' property at its current
5245 position. Called from handle_stop. */
5247 static enum prop_handled
5248 handle_composition_prop (struct it
*it
)
5250 Lisp_Object prop
, string
;
5251 ptrdiff_t pos
, pos_byte
, start
, end
;
5253 if (STRINGP (it
->string
))
5257 pos
= IT_STRING_CHARPOS (*it
);
5258 pos_byte
= IT_STRING_BYTEPOS (*it
);
5259 string
= it
->string
;
5260 s
= SDATA (string
) + pos_byte
;
5261 it
->c
= STRING_CHAR (s
);
5265 pos
= IT_CHARPOS (*it
);
5266 pos_byte
= IT_BYTEPOS (*it
);
5268 it
->c
= FETCH_CHAR (pos_byte
);
5271 /* If there's a valid composition and point is not inside of the
5272 composition (in the case that the composition is from the current
5273 buffer), draw a glyph composed from the composition components. */
5274 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5275 && composition_valid_p (start
, end
, prop
)
5276 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5279 /* As we can't handle this situation (perhaps font-lock added
5280 a new composition), we just return here hoping that next
5281 redisplay will detect this composition much earlier. */
5282 return HANDLED_NORMALLY
;
5285 if (STRINGP (it
->string
))
5286 pos_byte
= string_char_to_byte (it
->string
, start
);
5288 pos_byte
= CHAR_TO_BYTE (start
);
5290 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5293 if (it
->cmp_it
.id
>= 0)
5296 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5297 it
->cmp_it
.nglyphs
= -1;
5301 return HANDLED_NORMALLY
;
5306 /***********************************************************************
5308 ***********************************************************************/
5310 /* The following structure is used to record overlay strings for
5311 later sorting in load_overlay_strings. */
5313 struct overlay_entry
5315 Lisp_Object overlay
;
5322 /* Set up iterator IT from overlay strings at its current position.
5323 Called from handle_stop. */
5325 static enum prop_handled
5326 handle_overlay_change (struct it
*it
)
5328 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5329 return HANDLED_RECOMPUTE_PROPS
;
5331 return HANDLED_NORMALLY
;
5335 /* Set up the next overlay string for delivery by IT, if there is an
5336 overlay string to deliver. Called by set_iterator_to_next when the
5337 end of the current overlay string is reached. If there are more
5338 overlay strings to display, IT->string and
5339 IT->current.overlay_string_index are set appropriately here.
5340 Otherwise IT->string is set to nil. */
5343 next_overlay_string (struct it
*it
)
5345 ++it
->current
.overlay_string_index
;
5346 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5348 /* No more overlay strings. Restore IT's settings to what
5349 they were before overlay strings were processed, and
5350 continue to deliver from current_buffer. */
5352 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5355 || (NILP (it
->string
)
5356 && it
->method
== GET_FROM_BUFFER
5357 && it
->stop_charpos
>= BEGV
5358 && it
->stop_charpos
<= it
->end_charpos
));
5359 it
->current
.overlay_string_index
= -1;
5360 it
->n_overlay_strings
= 0;
5361 it
->overlay_strings_charpos
= -1;
5362 /* If there's an empty display string on the stack, pop the
5363 stack, to resync the bidi iterator with IT's position. Such
5364 empty strings are pushed onto the stack in
5365 get_overlay_strings_1. */
5366 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5369 /* If we're at the end of the buffer, record that we have
5370 processed the overlay strings there already, so that
5371 next_element_from_buffer doesn't try it again. */
5372 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5373 it
->overlay_strings_at_end_processed_p
= 1;
5377 /* There are more overlay strings to process. If
5378 IT->current.overlay_string_index has advanced to a position
5379 where we must load IT->overlay_strings with more strings, do
5380 it. We must load at the IT->overlay_strings_charpos where
5381 IT->n_overlay_strings was originally computed; when invisible
5382 text is present, this might not be IT_CHARPOS (Bug#7016). */
5383 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5385 if (it
->current
.overlay_string_index
&& i
== 0)
5386 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5388 /* Initialize IT to deliver display elements from the overlay
5390 it
->string
= it
->overlay_strings
[i
];
5391 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5392 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5393 it
->method
= GET_FROM_STRING
;
5394 it
->stop_charpos
= 0;
5395 it
->end_charpos
= SCHARS (it
->string
);
5396 if (it
->cmp_it
.stop_pos
>= 0)
5397 it
->cmp_it
.stop_pos
= 0;
5399 it
->base_level_stop
= 0;
5401 /* Set up the bidi iterator for this overlay string. */
5404 it
->bidi_it
.string
.lstring
= it
->string
;
5405 it
->bidi_it
.string
.s
= NULL
;
5406 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5407 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5408 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5409 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5410 it
->bidi_it
.w
= it
->w
;
5411 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5419 /* Compare two overlay_entry structures E1 and E2. Used as a
5420 comparison function for qsort in load_overlay_strings. Overlay
5421 strings for the same position are sorted so that
5423 1. All after-strings come in front of before-strings, except
5424 when they come from the same overlay.
5426 2. Within after-strings, strings are sorted so that overlay strings
5427 from overlays with higher priorities come first.
5429 2. Within before-strings, strings are sorted so that overlay
5430 strings from overlays with higher priorities come last.
5432 Value is analogous to strcmp. */
5436 compare_overlay_entries (const void *e1
, const void *e2
)
5438 struct overlay_entry
const *entry1
= e1
;
5439 struct overlay_entry
const *entry2
= e2
;
5442 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5444 /* Let after-strings appear in front of before-strings if
5445 they come from different overlays. */
5446 if (EQ (entry1
->overlay
, entry2
->overlay
))
5447 result
= entry1
->after_string_p
? 1 : -1;
5449 result
= entry1
->after_string_p
? -1 : 1;
5451 else if (entry1
->priority
!= entry2
->priority
)
5453 if (entry1
->after_string_p
)
5454 /* After-strings sorted in order of decreasing priority. */
5455 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5457 /* Before-strings sorted in order of increasing priority. */
5458 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5467 /* Load the vector IT->overlay_strings with overlay strings from IT's
5468 current buffer position, or from CHARPOS if that is > 0. Set
5469 IT->n_overlays to the total number of overlay strings found.
5471 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5472 a time. On entry into load_overlay_strings,
5473 IT->current.overlay_string_index gives the number of overlay
5474 strings that have already been loaded by previous calls to this
5477 IT->add_overlay_start contains an additional overlay start
5478 position to consider for taking overlay strings from, if non-zero.
5479 This position comes into play when the overlay has an `invisible'
5480 property, and both before and after-strings. When we've skipped to
5481 the end of the overlay, because of its `invisible' property, we
5482 nevertheless want its before-string to appear.
5483 IT->add_overlay_start will contain the overlay start position
5486 Overlay strings are sorted so that after-string strings come in
5487 front of before-string strings. Within before and after-strings,
5488 strings are sorted by overlay priority. See also function
5489 compare_overlay_entries. */
5492 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5494 Lisp_Object overlay
, window
, str
, invisible
;
5495 struct Lisp_Overlay
*ov
;
5496 ptrdiff_t start
, end
;
5497 ptrdiff_t size
= 20;
5498 ptrdiff_t n
= 0, i
, j
;
5500 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5504 charpos
= IT_CHARPOS (*it
);
5506 /* Append the overlay string STRING of overlay OVERLAY to vector
5507 `entries' which has size `size' and currently contains `n'
5508 elements. AFTER_P non-zero means STRING is an after-string of
5510 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5513 Lisp_Object priority; \
5517 struct overlay_entry *old = entries; \
5518 SAFE_NALLOCA (entries, 2, size); \
5519 memcpy (entries, old, size * sizeof *entries); \
5523 entries[n].string = (STRING); \
5524 entries[n].overlay = (OVERLAY); \
5525 priority = Foverlay_get ((OVERLAY), Qpriority); \
5526 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5527 entries[n].after_string_p = (AFTER_P); \
5532 /* Process overlay before the overlay center. */
5533 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5535 XSETMISC (overlay
, ov
);
5536 eassert (OVERLAYP (overlay
));
5537 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5538 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5543 /* Skip this overlay if it doesn't start or end at IT's current
5545 if (end
!= charpos
&& start
!= charpos
)
5548 /* Skip this overlay if it doesn't apply to IT->w. */
5549 window
= Foverlay_get (overlay
, Qwindow
);
5550 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5553 /* If the text ``under'' the overlay is invisible, both before-
5554 and after-strings from this overlay are visible; start and
5555 end position are indistinguishable. */
5556 invisible
= Foverlay_get (overlay
, Qinvisible
);
5557 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5559 /* If overlay has a non-empty before-string, record it. */
5560 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5561 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5563 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5565 /* If overlay has a non-empty after-string, record it. */
5566 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5567 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5569 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5572 /* Process overlays after the overlay center. */
5573 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5575 XSETMISC (overlay
, ov
);
5576 eassert (OVERLAYP (overlay
));
5577 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5578 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5580 if (start
> charpos
)
5583 /* Skip this overlay if it doesn't start or end at IT's current
5585 if (end
!= charpos
&& start
!= charpos
)
5588 /* Skip this overlay if it doesn't apply to IT->w. */
5589 window
= Foverlay_get (overlay
, Qwindow
);
5590 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5593 /* If the text ``under'' the overlay is invisible, it has a zero
5594 dimension, and both before- and after-strings apply. */
5595 invisible
= Foverlay_get (overlay
, Qinvisible
);
5596 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5598 /* If overlay has a non-empty before-string, record it. */
5599 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5600 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5602 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5604 /* If overlay has a non-empty after-string, record it. */
5605 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5606 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5608 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5611 #undef RECORD_OVERLAY_STRING
5615 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5617 /* Record number of overlay strings, and where we computed it. */
5618 it
->n_overlay_strings
= n
;
5619 it
->overlay_strings_charpos
= charpos
;
5621 /* IT->current.overlay_string_index is the number of overlay strings
5622 that have already been consumed by IT. Copy some of the
5623 remaining overlay strings to IT->overlay_strings. */
5625 j
= it
->current
.overlay_string_index
;
5626 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5628 it
->overlay_strings
[i
] = entries
[j
].string
;
5629 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5637 /* Get the first chunk of overlay strings at IT's current buffer
5638 position, or at CHARPOS if that is > 0. Value is non-zero if at
5639 least one overlay string was found. */
5642 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5644 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5645 process. This fills IT->overlay_strings with strings, and sets
5646 IT->n_overlay_strings to the total number of strings to process.
5647 IT->pos.overlay_string_index has to be set temporarily to zero
5648 because load_overlay_strings needs this; it must be set to -1
5649 when no overlay strings are found because a zero value would
5650 indicate a position in the first overlay string. */
5651 it
->current
.overlay_string_index
= 0;
5652 load_overlay_strings (it
, charpos
);
5654 /* If we found overlay strings, set up IT to deliver display
5655 elements from the first one. Otherwise set up IT to deliver
5656 from current_buffer. */
5657 if (it
->n_overlay_strings
)
5659 /* Make sure we know settings in current_buffer, so that we can
5660 restore meaningful values when we're done with the overlay
5663 compute_stop_pos (it
);
5664 eassert (it
->face_id
>= 0);
5666 /* Save IT's settings. They are restored after all overlay
5667 strings have been processed. */
5668 eassert (!compute_stop_p
|| it
->sp
== 0);
5670 /* When called from handle_stop, there might be an empty display
5671 string loaded. In that case, don't bother saving it. But
5672 don't use this optimization with the bidi iterator, since we
5673 need the corresponding pop_it call to resync the bidi
5674 iterator's position with IT's position, after we are done
5675 with the overlay strings. (The corresponding call to pop_it
5676 in case of an empty display string is in
5677 next_overlay_string.) */
5679 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5682 /* Set up IT to deliver display elements from the first overlay
5684 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5685 it
->string
= it
->overlay_strings
[0];
5686 it
->from_overlay
= Qnil
;
5687 it
->stop_charpos
= 0;
5688 eassert (STRINGP (it
->string
));
5689 it
->end_charpos
= SCHARS (it
->string
);
5691 it
->base_level_stop
= 0;
5692 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5693 it
->method
= GET_FROM_STRING
;
5694 it
->from_disp_prop_p
= 0;
5696 /* Force paragraph direction to be that of the parent
5698 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5699 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5701 it
->paragraph_embedding
= L2R
;
5703 /* Set up the bidi iterator for this overlay string. */
5706 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5708 it
->bidi_it
.string
.lstring
= it
->string
;
5709 it
->bidi_it
.string
.s
= NULL
;
5710 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5711 it
->bidi_it
.string
.bufpos
= pos
;
5712 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5713 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5714 it
->bidi_it
.w
= it
->w
;
5715 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5720 it
->current
.overlay_string_index
= -1;
5725 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5728 it
->method
= GET_FROM_BUFFER
;
5730 (void) get_overlay_strings_1 (it
, charpos
, 1);
5734 /* Value is non-zero if we found at least one overlay string. */
5735 return STRINGP (it
->string
);
5740 /***********************************************************************
5741 Saving and restoring state
5742 ***********************************************************************/
5744 /* Save current settings of IT on IT->stack. Called, for example,
5745 before setting up IT for an overlay string, to be able to restore
5746 IT's settings to what they were after the overlay string has been
5747 processed. If POSITION is non-NULL, it is the position to save on
5748 the stack instead of IT->position. */
5751 push_it (struct it
*it
, struct text_pos
*position
)
5753 struct iterator_stack_entry
*p
;
5755 eassert (it
->sp
< IT_STACK_SIZE
);
5756 p
= it
->stack
+ it
->sp
;
5758 p
->stop_charpos
= it
->stop_charpos
;
5759 p
->prev_stop
= it
->prev_stop
;
5760 p
->base_level_stop
= it
->base_level_stop
;
5761 p
->cmp_it
= it
->cmp_it
;
5762 eassert (it
->face_id
>= 0);
5763 p
->face_id
= it
->face_id
;
5764 p
->string
= it
->string
;
5765 p
->method
= it
->method
;
5766 p
->from_overlay
= it
->from_overlay
;
5769 case GET_FROM_IMAGE
:
5770 p
->u
.image
.object
= it
->object
;
5771 p
->u
.image
.image_id
= it
->image_id
;
5772 p
->u
.image
.slice
= it
->slice
;
5774 case GET_FROM_STRETCH
:
5775 p
->u
.stretch
.object
= it
->object
;
5778 p
->position
= position
? *position
: it
->position
;
5779 p
->current
= it
->current
;
5780 p
->end_charpos
= it
->end_charpos
;
5781 p
->string_nchars
= it
->string_nchars
;
5783 p
->multibyte_p
= it
->multibyte_p
;
5784 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5785 p
->space_width
= it
->space_width
;
5786 p
->font_height
= it
->font_height
;
5787 p
->voffset
= it
->voffset
;
5788 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5789 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5790 p
->display_ellipsis_p
= 0;
5791 p
->line_wrap
= it
->line_wrap
;
5792 p
->bidi_p
= it
->bidi_p
;
5793 p
->paragraph_embedding
= it
->paragraph_embedding
;
5794 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5797 /* Save the state of the bidi iterator as well. */
5799 bidi_push_it (&it
->bidi_it
);
5803 iterate_out_of_display_property (struct it
*it
)
5805 int buffer_p
= !STRINGP (it
->string
);
5806 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5807 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5809 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5811 /* Maybe initialize paragraph direction. If we are at the beginning
5812 of a new paragraph, next_element_from_buffer may not have a
5813 chance to do that. */
5814 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5815 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5816 /* prev_stop can be zero, so check against BEGV as well. */
5817 while (it
->bidi_it
.charpos
>= bob
5818 && it
->prev_stop
<= it
->bidi_it
.charpos
5819 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5820 && it
->bidi_it
.charpos
< eob
)
5821 bidi_move_to_visually_next (&it
->bidi_it
);
5822 /* Record the stop_pos we just crossed, for when we cross it
5824 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5825 it
->prev_stop
= CHARPOS (it
->position
);
5826 /* If we ended up not where pop_it put us, resync IT's
5827 positional members with the bidi iterator. */
5828 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5829 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5831 it
->current
.pos
= it
->position
;
5833 it
->current
.string_pos
= it
->position
;
5836 /* Restore IT's settings from IT->stack. Called, for example, when no
5837 more overlay strings must be processed, and we return to delivering
5838 display elements from a buffer, or when the end of a string from a
5839 `display' property is reached and we return to delivering display
5840 elements from an overlay string, or from a buffer. */
5843 pop_it (struct it
*it
)
5845 struct iterator_stack_entry
*p
;
5846 int from_display_prop
= it
->from_disp_prop_p
;
5848 eassert (it
->sp
> 0);
5850 p
= it
->stack
+ it
->sp
;
5851 it
->stop_charpos
= p
->stop_charpos
;
5852 it
->prev_stop
= p
->prev_stop
;
5853 it
->base_level_stop
= p
->base_level_stop
;
5854 it
->cmp_it
= p
->cmp_it
;
5855 it
->face_id
= p
->face_id
;
5856 it
->current
= p
->current
;
5857 it
->position
= p
->position
;
5858 it
->string
= p
->string
;
5859 it
->from_overlay
= p
->from_overlay
;
5860 if (NILP (it
->string
))
5861 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5862 it
->method
= p
->method
;
5865 case GET_FROM_IMAGE
:
5866 it
->image_id
= p
->u
.image
.image_id
;
5867 it
->object
= p
->u
.image
.object
;
5868 it
->slice
= p
->u
.image
.slice
;
5870 case GET_FROM_STRETCH
:
5871 it
->object
= p
->u
.stretch
.object
;
5873 case GET_FROM_BUFFER
:
5874 it
->object
= it
->w
->contents
;
5876 case GET_FROM_STRING
:
5877 it
->object
= it
->string
;
5879 case GET_FROM_DISPLAY_VECTOR
:
5881 it
->method
= GET_FROM_C_STRING
;
5882 else if (STRINGP (it
->string
))
5883 it
->method
= GET_FROM_STRING
;
5886 it
->method
= GET_FROM_BUFFER
;
5887 it
->object
= it
->w
->contents
;
5890 it
->end_charpos
= p
->end_charpos
;
5891 it
->string_nchars
= p
->string_nchars
;
5893 it
->multibyte_p
= p
->multibyte_p
;
5894 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5895 it
->space_width
= p
->space_width
;
5896 it
->font_height
= p
->font_height
;
5897 it
->voffset
= p
->voffset
;
5898 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5899 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5900 it
->line_wrap
= p
->line_wrap
;
5901 it
->bidi_p
= p
->bidi_p
;
5902 it
->paragraph_embedding
= p
->paragraph_embedding
;
5903 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5906 bidi_pop_it (&it
->bidi_it
);
5907 /* Bidi-iterate until we get out of the portion of text, if any,
5908 covered by a `display' text property or by an overlay with
5909 `display' property. (We cannot just jump there, because the
5910 internal coherency of the bidi iterator state can not be
5911 preserved across such jumps.) We also must determine the
5912 paragraph base direction if the overlay we just processed is
5913 at the beginning of a new paragraph. */
5914 if (from_display_prop
5915 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5916 iterate_out_of_display_property (it
);
5918 eassert ((BUFFERP (it
->object
)
5919 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5920 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5921 || (STRINGP (it
->object
)
5922 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5923 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5924 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5930 /***********************************************************************
5932 ***********************************************************************/
5934 /* Set IT's current position to the previous line start. */
5937 back_to_previous_line_start (struct it
*it
)
5939 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
5942 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
5946 /* Move IT to the next line start.
5948 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5949 we skipped over part of the text (as opposed to moving the iterator
5950 continuously over the text). Otherwise, don't change the value
5953 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5954 iterator on the newline, if it was found.
5956 Newlines may come from buffer text, overlay strings, or strings
5957 displayed via the `display' property. That's the reason we can't
5958 simply use find_newline_no_quit.
5960 Note that this function may not skip over invisible text that is so
5961 because of text properties and immediately follows a newline. If
5962 it would, function reseat_at_next_visible_line_start, when called
5963 from set_iterator_to_next, would effectively make invisible
5964 characters following a newline part of the wrong glyph row, which
5965 leads to wrong cursor motion. */
5968 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5969 struct bidi_it
*bidi_it_prev
)
5971 ptrdiff_t old_selective
;
5972 int newline_found_p
, n
;
5973 const int MAX_NEWLINE_DISTANCE
= 500;
5975 /* If already on a newline, just consume it to avoid unintended
5976 skipping over invisible text below. */
5977 if (it
->what
== IT_CHARACTER
5979 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5981 if (it
->bidi_p
&& bidi_it_prev
)
5982 *bidi_it_prev
= it
->bidi_it
;
5983 set_iterator_to_next (it
, 0);
5988 /* Don't handle selective display in the following. It's (a)
5989 unnecessary because it's done by the caller, and (b) leads to an
5990 infinite recursion because next_element_from_ellipsis indirectly
5991 calls this function. */
5992 old_selective
= it
->selective
;
5995 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5996 from buffer text. */
5997 for (n
= newline_found_p
= 0;
5998 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5999 n
+= STRINGP (it
->string
) ? 0 : 1)
6001 if (!get_next_display_element (it
))
6003 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6004 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6005 *bidi_it_prev
= it
->bidi_it
;
6006 set_iterator_to_next (it
, 0);
6009 /* If we didn't find a newline near enough, see if we can use a
6011 if (!newline_found_p
)
6013 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6014 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6018 eassert (!STRINGP (it
->string
));
6020 /* If there isn't any `display' property in sight, and no
6021 overlays, we can just use the position of the newline in
6023 if (it
->stop_charpos
>= limit
6024 || ((pos
= Fnext_single_property_change (make_number (start
),
6026 make_number (limit
)),
6028 && next_overlay_change (start
) == ZV
))
6032 IT_CHARPOS (*it
) = limit
;
6033 IT_BYTEPOS (*it
) = bytepos
;
6037 struct bidi_it bprev
;
6039 /* Help bidi.c avoid expensive searches for display
6040 properties and overlays, by telling it that there are
6041 none up to `limit'. */
6042 if (it
->bidi_it
.disp_pos
< limit
)
6044 it
->bidi_it
.disp_pos
= limit
;
6045 it
->bidi_it
.disp_prop
= 0;
6048 bprev
= it
->bidi_it
;
6049 bidi_move_to_visually_next (&it
->bidi_it
);
6050 } while (it
->bidi_it
.charpos
!= limit
);
6051 IT_CHARPOS (*it
) = limit
;
6052 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6054 *bidi_it_prev
= bprev
;
6056 *skipped_p
= newline_found_p
= 1;
6060 while (get_next_display_element (it
)
6061 && !newline_found_p
)
6063 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6064 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6065 *bidi_it_prev
= it
->bidi_it
;
6066 set_iterator_to_next (it
, 0);
6071 it
->selective
= old_selective
;
6072 return newline_found_p
;
6076 /* Set IT's current position to the previous visible line start. Skip
6077 invisible text that is so either due to text properties or due to
6078 selective display. Caution: this does not change IT->current_x and
6082 back_to_previous_visible_line_start (struct it
*it
)
6084 while (IT_CHARPOS (*it
) > BEGV
)
6086 back_to_previous_line_start (it
);
6088 if (IT_CHARPOS (*it
) <= BEGV
)
6091 /* If selective > 0, then lines indented more than its value are
6093 if (it
->selective
> 0
6094 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6098 /* Check the newline before point for invisibility. */
6101 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6102 Qinvisible
, it
->window
);
6103 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6107 if (IT_CHARPOS (*it
) <= BEGV
)
6112 void *it2data
= NULL
;
6115 Lisp_Object val
, overlay
;
6117 SAVE_IT (it2
, *it
, it2data
);
6119 /* If newline is part of a composition, continue from start of composition */
6120 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6121 && beg
< IT_CHARPOS (*it
))
6124 /* If newline is replaced by a display property, find start of overlay
6125 or interval and continue search from that point. */
6126 pos
= --IT_CHARPOS (it2
);
6129 bidi_unshelve_cache (NULL
, 0);
6130 it2
.string_from_display_prop_p
= 0;
6131 it2
.from_disp_prop_p
= 0;
6132 if (handle_display_prop (&it2
) == HANDLED_RETURN
6133 && !NILP (val
= get_char_property_and_overlay
6134 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6135 && (OVERLAYP (overlay
)
6136 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6137 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6139 RESTORE_IT (it
, it
, it2data
);
6143 /* Newline is not replaced by anything -- so we are done. */
6144 RESTORE_IT (it
, it
, it2data
);
6150 IT_CHARPOS (*it
) = beg
;
6151 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6155 it
->continuation_lines_width
= 0;
6157 eassert (IT_CHARPOS (*it
) >= BEGV
);
6158 eassert (IT_CHARPOS (*it
) == BEGV
6159 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6164 /* Reseat iterator IT at the previous visible line start. Skip
6165 invisible text that is so either due to text properties or due to
6166 selective display. At the end, update IT's overlay information,
6167 face information etc. */
6170 reseat_at_previous_visible_line_start (struct it
*it
)
6172 back_to_previous_visible_line_start (it
);
6173 reseat (it
, it
->current
.pos
, 1);
6178 /* Reseat iterator IT on the next visible line start in the current
6179 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6180 preceding the line start. Skip over invisible text that is so
6181 because of selective display. Compute faces, overlays etc at the
6182 new position. Note that this function does not skip over text that
6183 is invisible because of text properties. */
6186 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6188 int newline_found_p
, skipped_p
= 0;
6189 struct bidi_it bidi_it_prev
;
6191 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6193 /* Skip over lines that are invisible because they are indented
6194 more than the value of IT->selective. */
6195 if (it
->selective
> 0)
6196 while (IT_CHARPOS (*it
) < ZV
6197 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6200 eassert (IT_BYTEPOS (*it
) == BEGV
6201 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6203 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6206 /* Position on the newline if that's what's requested. */
6207 if (on_newline_p
&& newline_found_p
)
6209 if (STRINGP (it
->string
))
6211 if (IT_STRING_CHARPOS (*it
) > 0)
6215 --IT_STRING_CHARPOS (*it
);
6216 --IT_STRING_BYTEPOS (*it
);
6220 /* We need to restore the bidi iterator to the state
6221 it had on the newline, and resync the IT's
6222 position with that. */
6223 it
->bidi_it
= bidi_it_prev
;
6224 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6225 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6229 else if (IT_CHARPOS (*it
) > BEGV
)
6238 /* We need to restore the bidi iterator to the state it
6239 had on the newline and resync IT with that. */
6240 it
->bidi_it
= bidi_it_prev
;
6241 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6242 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6244 reseat (it
, it
->current
.pos
, 0);
6248 reseat (it
, it
->current
.pos
, 0);
6255 /***********************************************************************
6256 Changing an iterator's position
6257 ***********************************************************************/
6259 /* Change IT's current position to POS in current_buffer. If FORCE_P
6260 is non-zero, always check for text properties at the new position.
6261 Otherwise, text properties are only looked up if POS >=
6262 IT->check_charpos of a property. */
6265 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6267 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6269 reseat_1 (it
, pos
, 0);
6271 /* Determine where to check text properties. Avoid doing it
6272 where possible because text property lookup is very expensive. */
6274 || CHARPOS (pos
) > it
->stop_charpos
6275 || CHARPOS (pos
) < original_pos
)
6279 /* For bidi iteration, we need to prime prev_stop and
6280 base_level_stop with our best estimations. */
6281 /* Implementation note: Of course, POS is not necessarily a
6282 stop position, so assigning prev_pos to it is a lie; we
6283 should have called compute_stop_backwards. However, if
6284 the current buffer does not include any R2L characters,
6285 that call would be a waste of cycles, because the
6286 iterator will never move back, and thus never cross this
6287 "fake" stop position. So we delay that backward search
6288 until the time we really need it, in next_element_from_buffer. */
6289 if (CHARPOS (pos
) != it
->prev_stop
)
6290 it
->prev_stop
= CHARPOS (pos
);
6291 if (CHARPOS (pos
) < it
->base_level_stop
)
6292 it
->base_level_stop
= 0; /* meaning it's unknown */
6298 it
->prev_stop
= it
->base_level_stop
= 0;
6307 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6308 IT->stop_pos to POS, also. */
6311 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6313 /* Don't call this function when scanning a C string. */
6314 eassert (it
->s
== NULL
);
6316 /* POS must be a reasonable value. */
6317 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6319 it
->current
.pos
= it
->position
= pos
;
6320 it
->end_charpos
= ZV
;
6322 it
->current
.dpvec_index
= -1;
6323 it
->current
.overlay_string_index
= -1;
6324 IT_STRING_CHARPOS (*it
) = -1;
6325 IT_STRING_BYTEPOS (*it
) = -1;
6327 it
->method
= GET_FROM_BUFFER
;
6328 it
->object
= it
->w
->contents
;
6329 it
->area
= TEXT_AREA
;
6330 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6332 it
->string_from_display_prop_p
= 0;
6333 it
->string_from_prefix_prop_p
= 0;
6335 it
->from_disp_prop_p
= 0;
6336 it
->face_before_selective_p
= 0;
6339 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6341 bidi_unshelve_cache (NULL
, 0);
6342 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6343 it
->bidi_it
.string
.s
= NULL
;
6344 it
->bidi_it
.string
.lstring
= Qnil
;
6345 it
->bidi_it
.string
.bufpos
= 0;
6346 it
->bidi_it
.string
.unibyte
= 0;
6347 it
->bidi_it
.w
= it
->w
;
6352 it
->stop_charpos
= CHARPOS (pos
);
6353 it
->base_level_stop
= CHARPOS (pos
);
6355 /* This make the information stored in it->cmp_it invalidate. */
6360 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6361 If S is non-null, it is a C string to iterate over. Otherwise,
6362 STRING gives a Lisp string to iterate over.
6364 If PRECISION > 0, don't return more then PRECISION number of
6365 characters from the string.
6367 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6368 characters have been returned. FIELD_WIDTH < 0 means an infinite
6371 MULTIBYTE = 0 means disable processing of multibyte characters,
6372 MULTIBYTE > 0 means enable it,
6373 MULTIBYTE < 0 means use IT->multibyte_p.
6375 IT must be initialized via a prior call to init_iterator before
6376 calling this function. */
6379 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6380 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6383 /* No text property checks performed by default, but see below. */
6384 it
->stop_charpos
= -1;
6386 /* Set iterator position and end position. */
6387 memset (&it
->current
, 0, sizeof it
->current
);
6388 it
->current
.overlay_string_index
= -1;
6389 it
->current
.dpvec_index
= -1;
6390 eassert (charpos
>= 0);
6392 /* If STRING is specified, use its multibyteness, otherwise use the
6393 setting of MULTIBYTE, if specified. */
6395 it
->multibyte_p
= multibyte
> 0;
6397 /* Bidirectional reordering of strings is controlled by the default
6398 value of bidi-display-reordering. Don't try to reorder while
6399 loading loadup.el, as the necessary character property tables are
6400 not yet available. */
6403 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6407 eassert (STRINGP (string
));
6408 it
->string
= string
;
6410 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6411 it
->method
= GET_FROM_STRING
;
6412 it
->current
.string_pos
= string_pos (charpos
, string
);
6416 it
->bidi_it
.string
.lstring
= string
;
6417 it
->bidi_it
.string
.s
= NULL
;
6418 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6419 it
->bidi_it
.string
.bufpos
= 0;
6420 it
->bidi_it
.string
.from_disp_str
= 0;
6421 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6422 it
->bidi_it
.w
= it
->w
;
6423 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6424 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6429 it
->s
= (const unsigned char *) s
;
6432 /* Note that we use IT->current.pos, not it->current.string_pos,
6433 for displaying C strings. */
6434 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6435 if (it
->multibyte_p
)
6437 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6438 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6442 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6443 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6448 it
->bidi_it
.string
.lstring
= Qnil
;
6449 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6450 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6451 it
->bidi_it
.string
.bufpos
= 0;
6452 it
->bidi_it
.string
.from_disp_str
= 0;
6453 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6454 it
->bidi_it
.w
= it
->w
;
6455 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6458 it
->method
= GET_FROM_C_STRING
;
6461 /* PRECISION > 0 means don't return more than PRECISION characters
6463 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6465 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6467 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6470 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6471 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6472 FIELD_WIDTH < 0 means infinite field width. This is useful for
6473 padding with `-' at the end of a mode line. */
6474 if (field_width
< 0)
6475 field_width
= INFINITY
;
6476 /* Implementation note: We deliberately don't enlarge
6477 it->bidi_it.string.schars here to fit it->end_charpos, because
6478 the bidi iterator cannot produce characters out of thin air. */
6479 if (field_width
> it
->end_charpos
- charpos
)
6480 it
->end_charpos
= charpos
+ field_width
;
6482 /* Use the standard display table for displaying strings. */
6483 if (DISP_TABLE_P (Vstandard_display_table
))
6484 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6486 it
->stop_charpos
= charpos
;
6487 it
->prev_stop
= charpos
;
6488 it
->base_level_stop
= 0;
6491 it
->bidi_it
.first_elt
= 1;
6492 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6493 it
->bidi_it
.disp_pos
= -1;
6495 if (s
== NULL
&& it
->multibyte_p
)
6497 ptrdiff_t endpos
= SCHARS (it
->string
);
6498 if (endpos
> it
->end_charpos
)
6499 endpos
= it
->end_charpos
;
6500 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6508 /***********************************************************************
6510 ***********************************************************************/
6512 /* Map enum it_method value to corresponding next_element_from_* function. */
6514 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6516 next_element_from_buffer
,
6517 next_element_from_display_vector
,
6518 next_element_from_string
,
6519 next_element_from_c_string
,
6520 next_element_from_image
,
6521 next_element_from_stretch
6524 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6527 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6528 (possibly with the following characters). */
6530 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6531 ((IT)->cmp_it.id >= 0 \
6532 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6533 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6534 END_CHARPOS, (IT)->w, \
6535 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6539 /* Lookup the char-table Vglyphless_char_display for character C (-1
6540 if we want information for no-font case), and return the display
6541 method symbol. By side-effect, update it->what and
6542 it->glyphless_method. This function is called from
6543 get_next_display_element for each character element, and from
6544 x_produce_glyphs when no suitable font was found. */
6547 lookup_glyphless_char_display (int c
, struct it
*it
)
6549 Lisp_Object glyphless_method
= Qnil
;
6551 if (CHAR_TABLE_P (Vglyphless_char_display
)
6552 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6556 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6557 if (CONSP (glyphless_method
))
6558 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6559 ? XCAR (glyphless_method
)
6560 : XCDR (glyphless_method
);
6563 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6567 if (NILP (glyphless_method
))
6570 /* The default is to display the character by a proper font. */
6572 /* The default for the no-font case is to display an empty box. */
6573 glyphless_method
= Qempty_box
;
6575 if (EQ (glyphless_method
, Qzero_width
))
6578 return glyphless_method
;
6579 /* This method can't be used for the no-font case. */
6580 glyphless_method
= Qempty_box
;
6582 if (EQ (glyphless_method
, Qthin_space
))
6583 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6584 else if (EQ (glyphless_method
, Qempty_box
))
6585 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6586 else if (EQ (glyphless_method
, Qhex_code
))
6587 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6588 else if (STRINGP (glyphless_method
))
6589 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6592 /* Invalid value. We use the default method. */
6593 glyphless_method
= Qnil
;
6596 it
->what
= IT_GLYPHLESS
;
6597 return glyphless_method
;
6600 /* Merge escape glyph face and cache the result. */
6602 static struct frame
*last_escape_glyph_frame
= NULL
;
6603 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6604 static int last_escape_glyph_merged_face_id
= 0;
6607 merge_escape_glyph_face (struct it
*it
)
6611 if (it
->f
== last_escape_glyph_frame
6612 && it
->face_id
== last_escape_glyph_face_id
)
6613 face_id
= last_escape_glyph_merged_face_id
;
6616 /* Merge the `escape-glyph' face into the current face. */
6617 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6618 last_escape_glyph_frame
= it
->f
;
6619 last_escape_glyph_face_id
= it
->face_id
;
6620 last_escape_glyph_merged_face_id
= face_id
;
6625 /* Likewise for glyphless glyph face. */
6627 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6628 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6629 static int last_glyphless_glyph_merged_face_id
= 0;
6632 merge_glyphless_glyph_face (struct it
*it
)
6636 if (it
->f
== last_glyphless_glyph_frame
6637 && it
->face_id
== last_glyphless_glyph_face_id
)
6638 face_id
= last_glyphless_glyph_merged_face_id
;
6641 /* Merge the `glyphless-char' face into the current face. */
6642 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6643 last_glyphless_glyph_frame
= it
->f
;
6644 last_glyphless_glyph_face_id
= it
->face_id
;
6645 last_glyphless_glyph_merged_face_id
= face_id
;
6650 /* Load IT's display element fields with information about the next
6651 display element from the current position of IT. Value is zero if
6652 end of buffer (or C string) is reached. */
6655 get_next_display_element (struct it
*it
)
6657 /* Non-zero means that we found a display element. Zero means that
6658 we hit the end of what we iterate over. Performance note: the
6659 function pointer `method' used here turns out to be faster than
6660 using a sequence of if-statements. */
6664 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6666 if (it
->what
== IT_CHARACTER
)
6668 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6669 and only if (a) the resolved directionality of that character
6671 /* FIXME: Do we need an exception for characters from display
6673 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6674 it
->c
= bidi_mirror_char (it
->c
);
6675 /* Map via display table or translate control characters.
6676 IT->c, IT->len etc. have been set to the next character by
6677 the function call above. If we have a display table, and it
6678 contains an entry for IT->c, translate it. Don't do this if
6679 IT->c itself comes from a display table, otherwise we could
6680 end up in an infinite recursion. (An alternative could be to
6681 count the recursion depth of this function and signal an
6682 error when a certain maximum depth is reached.) Is it worth
6684 if (success_p
&& it
->dpvec
== NULL
)
6687 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6688 int nonascii_space_p
= 0;
6689 int nonascii_hyphen_p
= 0;
6690 int c
= it
->c
; /* This is the character to display. */
6692 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6694 eassert (SINGLE_BYTE_CHAR_P (c
));
6695 if (unibyte_display_via_language_environment
)
6697 c
= DECODE_CHAR (unibyte
, c
);
6699 c
= BYTE8_TO_CHAR (it
->c
);
6702 c
= BYTE8_TO_CHAR (it
->c
);
6706 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6709 struct Lisp_Vector
*v
= XVECTOR (dv
);
6711 /* Return the first character from the display table
6712 entry, if not empty. If empty, don't display the
6713 current character. */
6716 it
->dpvec_char_len
= it
->len
;
6717 it
->dpvec
= v
->u
.contents
;
6718 it
->dpend
= v
->u
.contents
+ v
->header
.size
;
6719 it
->current
.dpvec_index
= 0;
6720 it
->dpvec_face_id
= -1;
6721 it
->saved_face_id
= it
->face_id
;
6722 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6727 set_iterator_to_next (it
, 0);
6732 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6734 if (it
->what
== IT_GLYPHLESS
)
6736 /* Don't display this character. */
6737 set_iterator_to_next (it
, 0);
6741 /* If `nobreak-char-display' is non-nil, we display
6742 non-ASCII spaces and hyphens specially. */
6743 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6746 nonascii_space_p
= 1;
6747 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6748 nonascii_hyphen_p
= 1;
6751 /* Translate control characters into `\003' or `^C' form.
6752 Control characters coming from a display table entry are
6753 currently not translated because we use IT->dpvec to hold
6754 the translation. This could easily be changed but I
6755 don't believe that it is worth doing.
6757 The characters handled by `nobreak-char-display' must be
6760 Non-printable characters and raw-byte characters are also
6761 translated to octal form. */
6762 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6763 ? (it
->area
!= TEXT_AREA
6764 /* In mode line, treat \n, \t like other crl chars. */
6767 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6768 || (c
!= '\n' && c
!= '\t'))
6770 || nonascii_hyphen_p
6772 || ! CHAR_PRINTABLE_P (c
))))
6774 /* C is a control character, non-ASCII space/hyphen,
6775 raw-byte, or a non-printable character which must be
6776 displayed either as '\003' or as `^C' where the '\\'
6777 and '^' can be defined in the display table. Fill
6778 IT->ctl_chars with glyphs for what we have to
6779 display. Then, set IT->dpvec to these glyphs. */
6786 /* Handle control characters with ^. */
6788 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6792 g
= '^'; /* default glyph for Control */
6793 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6795 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6797 g
= GLYPH_CODE_CHAR (gc
);
6798 lface_id
= GLYPH_CODE_FACE (gc
);
6802 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6803 : merge_escape_glyph_face (it
));
6805 XSETINT (it
->ctl_chars
[0], g
);
6806 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6808 goto display_control
;
6811 /* Handle non-ascii space in the mode where it only gets
6814 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6816 /* Merge `nobreak-space' into the current face. */
6817 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6819 XSETINT (it
->ctl_chars
[0], ' ');
6821 goto display_control
;
6824 /* Handle sequences that start with the "escape glyph". */
6826 /* the default escape glyph is \. */
6827 escape_glyph
= '\\';
6830 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6832 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6833 lface_id
= GLYPH_CODE_FACE (gc
);
6837 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6838 : merge_escape_glyph_face (it
));
6840 /* Draw non-ASCII hyphen with just highlighting: */
6842 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6844 XSETINT (it
->ctl_chars
[0], '-');
6846 goto display_control
;
6849 /* Draw non-ASCII space/hyphen with escape glyph: */
6851 if (nonascii_space_p
|| nonascii_hyphen_p
)
6853 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6854 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6856 goto display_control
;
6863 if (CHAR_BYTE8_P (c
))
6864 /* Display \200 instead of \17777600. */
6865 c
= CHAR_TO_BYTE8 (c
);
6866 len
= sprintf (str
, "%03o", c
);
6868 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6869 for (i
= 0; i
< len
; i
++)
6870 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6875 /* Set up IT->dpvec and return first character from it. */
6876 it
->dpvec_char_len
= it
->len
;
6877 it
->dpvec
= it
->ctl_chars
;
6878 it
->dpend
= it
->dpvec
+ ctl_len
;
6879 it
->current
.dpvec_index
= 0;
6880 it
->dpvec_face_id
= face_id
;
6881 it
->saved_face_id
= it
->face_id
;
6882 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6886 it
->char_to_display
= c
;
6890 it
->char_to_display
= it
->c
;
6894 #ifdef HAVE_WINDOW_SYSTEM
6895 /* Adjust face id for a multibyte character. There are no multibyte
6896 character in unibyte text. */
6897 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6900 && FRAME_WINDOW_P (it
->f
))
6902 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6904 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6906 /* Automatic composition with glyph-string. */
6907 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6909 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6913 ptrdiff_t pos
= (it
->s
? -1
6914 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6915 : IT_CHARPOS (*it
));
6918 if (it
->what
== IT_CHARACTER
)
6919 c
= it
->char_to_display
;
6922 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6926 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6927 /* TAB in a composition means display glyphs with
6928 padding space on the left or right. */
6929 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6932 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6935 #endif /* HAVE_WINDOW_SYSTEM */
6938 /* Is this character the last one of a run of characters with
6939 box? If yes, set IT->end_of_box_run_p to 1. */
6943 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6945 int face_id
= underlying_face_id (it
);
6946 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6950 if (face
->box
== FACE_NO_BOX
)
6952 /* If the box comes from face properties in a
6953 display string, check faces in that string. */
6954 int string_face_id
= face_after_it_pos (it
);
6955 it
->end_of_box_run_p
6956 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6959 /* Otherwise, the box comes from the underlying face.
6960 If this is the last string character displayed, check
6961 the next buffer location. */
6962 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6963 && (it
->current
.overlay_string_index
6964 == it
->n_overlay_strings
- 1))
6968 struct text_pos pos
= it
->current
.pos
;
6969 INC_TEXT_POS (pos
, it
->multibyte_p
);
6971 next_face_id
= face_at_buffer_position
6972 (it
->w
, CHARPOS (pos
), &ignore
,
6973 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6975 it
->end_of_box_run_p
6976 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6981 /* next_element_from_display_vector sets this flag according to
6982 faces of the display vector glyphs, see there. */
6983 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
6985 int face_id
= face_after_it_pos (it
);
6986 it
->end_of_box_run_p
6987 = (face_id
!= it
->face_id
6988 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6991 /* If we reached the end of the object we've been iterating (e.g., a
6992 display string or an overlay string), and there's something on
6993 IT->stack, proceed with what's on the stack. It doesn't make
6994 sense to return zero if there's unprocessed stuff on the stack,
6995 because otherwise that stuff will never be displayed. */
6996 if (!success_p
&& it
->sp
> 0)
6998 set_iterator_to_next (it
, 0);
6999 success_p
= get_next_display_element (it
);
7002 /* Value is 0 if end of buffer or string reached. */
7007 /* Move IT to the next display element.
7009 RESEAT_P non-zero means if called on a newline in buffer text,
7010 skip to the next visible line start.
7012 Functions get_next_display_element and set_iterator_to_next are
7013 separate because I find this arrangement easier to handle than a
7014 get_next_display_element function that also increments IT's
7015 position. The way it is we can first look at an iterator's current
7016 display element, decide whether it fits on a line, and if it does,
7017 increment the iterator position. The other way around we probably
7018 would either need a flag indicating whether the iterator has to be
7019 incremented the next time, or we would have to implement a
7020 decrement position function which would not be easy to write. */
7023 set_iterator_to_next (struct it
*it
, int reseat_p
)
7025 /* Reset flags indicating start and end of a sequence of characters
7026 with box. Reset them at the start of this function because
7027 moving the iterator to a new position might set them. */
7028 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7032 case GET_FROM_BUFFER
:
7033 /* The current display element of IT is a character from
7034 current_buffer. Advance in the buffer, and maybe skip over
7035 invisible lines that are so because of selective display. */
7036 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7037 reseat_at_next_visible_line_start (it
, 0);
7038 else if (it
->cmp_it
.id
>= 0)
7040 /* We are currently getting glyphs from a composition. */
7045 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7046 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7047 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7049 it
->cmp_it
.from
= it
->cmp_it
.to
;
7054 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7056 it
->end_charpos
, Qnil
);
7059 else if (! it
->cmp_it
.reversed_p
)
7061 /* Composition created while scanning forward. */
7062 /* Update IT's char/byte positions to point to the first
7063 character of the next grapheme cluster, or to the
7064 character visually after the current composition. */
7065 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7066 bidi_move_to_visually_next (&it
->bidi_it
);
7067 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7068 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7070 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7072 /* Proceed to the next grapheme cluster. */
7073 it
->cmp_it
.from
= it
->cmp_it
.to
;
7077 /* No more grapheme clusters in this composition.
7078 Find the next stop position. */
7079 ptrdiff_t stop
= it
->end_charpos
;
7080 if (it
->bidi_it
.scan_dir
< 0)
7081 /* Now we are scanning backward and don't know
7084 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7085 IT_BYTEPOS (*it
), stop
, Qnil
);
7090 /* Composition created while scanning backward. */
7091 /* Update IT's char/byte positions to point to the last
7092 character of the previous grapheme cluster, or the
7093 character visually after the current composition. */
7094 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7095 bidi_move_to_visually_next (&it
->bidi_it
);
7096 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7097 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7098 if (it
->cmp_it
.from
> 0)
7100 /* Proceed to the previous grapheme cluster. */
7101 it
->cmp_it
.to
= it
->cmp_it
.from
;
7105 /* No more grapheme clusters in this composition.
7106 Find the next stop position. */
7107 ptrdiff_t stop
= it
->end_charpos
;
7108 if (it
->bidi_it
.scan_dir
< 0)
7109 /* Now we are scanning backward and don't know
7112 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7113 IT_BYTEPOS (*it
), stop
, Qnil
);
7119 eassert (it
->len
!= 0);
7123 IT_BYTEPOS (*it
) += it
->len
;
7124 IT_CHARPOS (*it
) += 1;
7128 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7129 /* If this is a new paragraph, determine its base
7130 direction (a.k.a. its base embedding level). */
7131 if (it
->bidi_it
.new_paragraph
)
7132 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7133 bidi_move_to_visually_next (&it
->bidi_it
);
7134 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7135 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7136 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7138 /* As the scan direction was changed, we must
7139 re-compute the stop position for composition. */
7140 ptrdiff_t stop
= it
->end_charpos
;
7141 if (it
->bidi_it
.scan_dir
< 0)
7143 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7144 IT_BYTEPOS (*it
), stop
, Qnil
);
7147 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7151 case GET_FROM_C_STRING
:
7152 /* Current display element of IT is from a C string. */
7154 /* If the string position is beyond string's end, it means
7155 next_element_from_c_string is padding the string with
7156 blanks, in which case we bypass the bidi iterator,
7157 because it cannot deal with such virtual characters. */
7158 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7160 IT_BYTEPOS (*it
) += it
->len
;
7161 IT_CHARPOS (*it
) += 1;
7165 bidi_move_to_visually_next (&it
->bidi_it
);
7166 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7167 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7171 case GET_FROM_DISPLAY_VECTOR
:
7172 /* Current display element of IT is from a display table entry.
7173 Advance in the display table definition. Reset it to null if
7174 end reached, and continue with characters from buffers/
7176 ++it
->current
.dpvec_index
;
7178 /* Restore face of the iterator to what they were before the
7179 display vector entry (these entries may contain faces). */
7180 it
->face_id
= it
->saved_face_id
;
7182 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7184 int recheck_faces
= it
->ellipsis_p
;
7187 it
->method
= GET_FROM_C_STRING
;
7188 else if (STRINGP (it
->string
))
7189 it
->method
= GET_FROM_STRING
;
7192 it
->method
= GET_FROM_BUFFER
;
7193 it
->object
= it
->w
->contents
;
7197 it
->current
.dpvec_index
= -1;
7199 /* Skip over characters which were displayed via IT->dpvec. */
7200 if (it
->dpvec_char_len
< 0)
7201 reseat_at_next_visible_line_start (it
, 1);
7202 else if (it
->dpvec_char_len
> 0)
7204 if (it
->method
== GET_FROM_STRING
7205 && it
->current
.overlay_string_index
>= 0
7206 && it
->n_overlay_strings
> 0)
7207 it
->ignore_overlay_strings_at_pos_p
= 1;
7208 it
->len
= it
->dpvec_char_len
;
7209 set_iterator_to_next (it
, reseat_p
);
7212 /* Maybe recheck faces after display vector */
7214 it
->stop_charpos
= IT_CHARPOS (*it
);
7218 case GET_FROM_STRING
:
7219 /* Current display element is a character from a Lisp string. */
7220 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7221 /* Don't advance past string end. These conditions are true
7222 when set_iterator_to_next is called at the end of
7223 get_next_display_element, in which case the Lisp string is
7224 already exhausted, and all we want is pop the iterator
7226 if (it
->current
.overlay_string_index
>= 0)
7228 /* This is an overlay string, so there's no padding with
7229 spaces, and the number of characters in the string is
7230 where the string ends. */
7231 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7232 goto consider_string_end
;
7236 /* Not an overlay string. There could be padding, so test
7237 against it->end_charpos . */
7238 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7239 goto consider_string_end
;
7241 if (it
->cmp_it
.id
>= 0)
7247 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7248 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7249 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7250 it
->cmp_it
.from
= it
->cmp_it
.to
;
7254 composition_compute_stop_pos (&it
->cmp_it
,
7255 IT_STRING_CHARPOS (*it
),
7256 IT_STRING_BYTEPOS (*it
),
7257 it
->end_charpos
, it
->string
);
7260 else if (! it
->cmp_it
.reversed_p
)
7262 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7263 bidi_move_to_visually_next (&it
->bidi_it
);
7264 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7265 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7267 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7268 it
->cmp_it
.from
= it
->cmp_it
.to
;
7271 ptrdiff_t stop
= it
->end_charpos
;
7272 if (it
->bidi_it
.scan_dir
< 0)
7274 composition_compute_stop_pos (&it
->cmp_it
,
7275 IT_STRING_CHARPOS (*it
),
7276 IT_STRING_BYTEPOS (*it
), stop
,
7282 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7283 bidi_move_to_visually_next (&it
->bidi_it
);
7284 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7285 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7286 if (it
->cmp_it
.from
> 0)
7287 it
->cmp_it
.to
= it
->cmp_it
.from
;
7290 ptrdiff_t stop
= it
->end_charpos
;
7291 if (it
->bidi_it
.scan_dir
< 0)
7293 composition_compute_stop_pos (&it
->cmp_it
,
7294 IT_STRING_CHARPOS (*it
),
7295 IT_STRING_BYTEPOS (*it
), stop
,
7303 /* If the string position is beyond string's end, it
7304 means next_element_from_string is padding the string
7305 with blanks, in which case we bypass the bidi
7306 iterator, because it cannot deal with such virtual
7308 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7310 IT_STRING_BYTEPOS (*it
) += it
->len
;
7311 IT_STRING_CHARPOS (*it
) += 1;
7315 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7317 bidi_move_to_visually_next (&it
->bidi_it
);
7318 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7319 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7320 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7322 ptrdiff_t stop
= it
->end_charpos
;
7324 if (it
->bidi_it
.scan_dir
< 0)
7326 composition_compute_stop_pos (&it
->cmp_it
,
7327 IT_STRING_CHARPOS (*it
),
7328 IT_STRING_BYTEPOS (*it
), stop
,
7334 consider_string_end
:
7336 if (it
->current
.overlay_string_index
>= 0)
7338 /* IT->string is an overlay string. Advance to the
7339 next, if there is one. */
7340 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7343 next_overlay_string (it
);
7345 setup_for_ellipsis (it
, 0);
7350 /* IT->string is not an overlay string. If we reached
7351 its end, and there is something on IT->stack, proceed
7352 with what is on the stack. This can be either another
7353 string, this time an overlay string, or a buffer. */
7354 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7358 if (it
->method
== GET_FROM_STRING
)
7359 goto consider_string_end
;
7364 case GET_FROM_IMAGE
:
7365 case GET_FROM_STRETCH
:
7366 /* The position etc with which we have to proceed are on
7367 the stack. The position may be at the end of a string,
7368 if the `display' property takes up the whole string. */
7369 eassert (it
->sp
> 0);
7371 if (it
->method
== GET_FROM_STRING
)
7372 goto consider_string_end
;
7376 /* There are no other methods defined, so this should be a bug. */
7380 eassert (it
->method
!= GET_FROM_STRING
7381 || (STRINGP (it
->string
)
7382 && IT_STRING_CHARPOS (*it
) >= 0));
7385 /* Load IT's display element fields with information about the next
7386 display element which comes from a display table entry or from the
7387 result of translating a control character to one of the forms `^C'
7390 IT->dpvec holds the glyphs to return as characters.
7391 IT->saved_face_id holds the face id before the display vector--it
7392 is restored into IT->face_id in set_iterator_to_next. */
7395 next_element_from_display_vector (struct it
*it
)
7398 int prev_face_id
= it
->face_id
;
7402 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7404 it
->face_id
= it
->saved_face_id
;
7406 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7407 That seemed totally bogus - so I changed it... */
7408 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7410 if (GLYPH_CODE_P (gc
))
7412 struct face
*this_face
, *prev_face
, *next_face
;
7414 it
->c
= GLYPH_CODE_CHAR (gc
);
7415 it
->len
= CHAR_BYTES (it
->c
);
7417 /* The entry may contain a face id to use. Such a face id is
7418 the id of a Lisp face, not a realized face. A face id of
7419 zero means no face is specified. */
7420 if (it
->dpvec_face_id
>= 0)
7421 it
->face_id
= it
->dpvec_face_id
;
7424 int lface_id
= GLYPH_CODE_FACE (gc
);
7426 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7430 /* Glyphs in the display vector could have the box face, so we
7431 need to set the related flags in the iterator, as
7433 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7434 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7436 /* Is this character the first character of a box-face run? */
7437 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7439 || prev_face
->box
== FACE_NO_BOX
));
7441 /* For the last character of the box-face run, we need to look
7442 either at the next glyph from the display vector, or at the
7443 face we saw before the display vector. */
7444 next_face_id
= it
->saved_face_id
;
7445 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7447 if (it
->dpvec_face_id
>= 0)
7448 next_face_id
= it
->dpvec_face_id
;
7452 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7455 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7459 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7460 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7462 || next_face
->box
== FACE_NO_BOX
));
7463 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7466 /* Display table entry is invalid. Return a space. */
7467 it
->c
= ' ', it
->len
= 1;
7469 /* Don't change position and object of the iterator here. They are
7470 still the values of the character that had this display table
7471 entry or was translated, and that's what we want. */
7472 it
->what
= IT_CHARACTER
;
7476 /* Get the first element of string/buffer in the visual order, after
7477 being reseated to a new position in a string or a buffer. */
7479 get_visually_first_element (struct it
*it
)
7481 int string_p
= STRINGP (it
->string
) || it
->s
;
7482 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7483 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7485 if (STRINGP (it
->string
))
7487 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7488 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7492 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7493 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7496 if (it
->bidi_it
.charpos
== eob
)
7498 /* Nothing to do, but reset the FIRST_ELT flag, like
7499 bidi_paragraph_init does, because we are not going to
7501 it
->bidi_it
.first_elt
= 0;
7503 else if (it
->bidi_it
.charpos
== bob
7505 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7506 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7508 /* If we are at the beginning of a line/string, we can produce
7509 the next element right away. */
7510 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7511 bidi_move_to_visually_next (&it
->bidi_it
);
7515 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7517 /* We need to prime the bidi iterator starting at the line's or
7518 string's beginning, before we will be able to produce the
7521 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7523 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7524 IT_BYTEPOS (*it
), -1,
7525 &it
->bidi_it
.bytepos
);
7526 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7529 /* Now return to buffer/string position where we were asked
7530 to get the next display element, and produce that. */
7531 bidi_move_to_visually_next (&it
->bidi_it
);
7533 while (it
->bidi_it
.bytepos
!= orig_bytepos
7534 && it
->bidi_it
.charpos
< eob
);
7537 /* Adjust IT's position information to where we ended up. */
7538 if (STRINGP (it
->string
))
7540 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7541 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7545 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7546 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7549 if (STRINGP (it
->string
) || !it
->s
)
7551 ptrdiff_t stop
, charpos
, bytepos
;
7553 if (STRINGP (it
->string
))
7556 stop
= SCHARS (it
->string
);
7557 if (stop
> it
->end_charpos
)
7558 stop
= it
->end_charpos
;
7559 charpos
= IT_STRING_CHARPOS (*it
);
7560 bytepos
= IT_STRING_BYTEPOS (*it
);
7564 stop
= it
->end_charpos
;
7565 charpos
= IT_CHARPOS (*it
);
7566 bytepos
= IT_BYTEPOS (*it
);
7568 if (it
->bidi_it
.scan_dir
< 0)
7570 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7575 /* Load IT with the next display element from Lisp string IT->string.
7576 IT->current.string_pos is the current position within the string.
7577 If IT->current.overlay_string_index >= 0, the Lisp string is an
7581 next_element_from_string (struct it
*it
)
7583 struct text_pos position
;
7585 eassert (STRINGP (it
->string
));
7586 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7587 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7588 position
= it
->current
.string_pos
;
7590 /* With bidi reordering, the character to display might not be the
7591 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7592 that we were reseat()ed to a new string, whose paragraph
7593 direction is not known. */
7594 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7596 get_visually_first_element (it
);
7597 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7600 /* Time to check for invisible text? */
7601 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7603 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7606 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7607 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7609 /* With bidi non-linear iteration, we could find
7610 ourselves far beyond the last computed stop_charpos,
7611 with several other stop positions in between that we
7612 missed. Scan them all now, in buffer's logical
7613 order, until we find and handle the last stop_charpos
7614 that precedes our current position. */
7615 handle_stop_backwards (it
, it
->stop_charpos
);
7616 return GET_NEXT_DISPLAY_ELEMENT (it
);
7622 /* Take note of the stop position we just moved
7623 across, for when we will move back across it. */
7624 it
->prev_stop
= it
->stop_charpos
;
7625 /* If we are at base paragraph embedding level, take
7626 note of the last stop position seen at this
7628 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7629 it
->base_level_stop
= it
->stop_charpos
;
7633 /* Since a handler may have changed IT->method, we must
7635 return GET_NEXT_DISPLAY_ELEMENT (it
);
7639 /* If we are before prev_stop, we may have overstepped
7640 on our way backwards a stop_pos, and if so, we need
7641 to handle that stop_pos. */
7642 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7643 /* We can sometimes back up for reasons that have nothing
7644 to do with bidi reordering. E.g., compositions. The
7645 code below is only needed when we are above the base
7646 embedding level, so test for that explicitly. */
7647 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7649 /* If we lost track of base_level_stop, we have no better
7650 place for handle_stop_backwards to start from than string
7651 beginning. This happens, e.g., when we were reseated to
7652 the previous screenful of text by vertical-motion. */
7653 if (it
->base_level_stop
<= 0
7654 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7655 it
->base_level_stop
= 0;
7656 handle_stop_backwards (it
, it
->base_level_stop
);
7657 return GET_NEXT_DISPLAY_ELEMENT (it
);
7661 if (it
->current
.overlay_string_index
>= 0)
7663 /* Get the next character from an overlay string. In overlay
7664 strings, there is no field width or padding with spaces to
7666 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7671 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7672 IT_STRING_BYTEPOS (*it
),
7673 it
->bidi_it
.scan_dir
< 0
7675 : SCHARS (it
->string
))
7676 && next_element_from_composition (it
))
7680 else if (STRING_MULTIBYTE (it
->string
))
7682 const unsigned char *s
= (SDATA (it
->string
)
7683 + IT_STRING_BYTEPOS (*it
));
7684 it
->c
= string_char_and_length (s
, &it
->len
);
7688 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7694 /* Get the next character from a Lisp string that is not an
7695 overlay string. Such strings come from the mode line, for
7696 example. We may have to pad with spaces, or truncate the
7697 string. See also next_element_from_c_string. */
7698 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7703 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7705 /* Pad with spaces. */
7706 it
->c
= ' ', it
->len
= 1;
7707 CHARPOS (position
) = BYTEPOS (position
) = -1;
7709 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7710 IT_STRING_BYTEPOS (*it
),
7711 it
->bidi_it
.scan_dir
< 0
7713 : it
->string_nchars
)
7714 && next_element_from_composition (it
))
7718 else if (STRING_MULTIBYTE (it
->string
))
7720 const unsigned char *s
= (SDATA (it
->string
)
7721 + IT_STRING_BYTEPOS (*it
));
7722 it
->c
= string_char_and_length (s
, &it
->len
);
7726 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7731 /* Record what we have and where it came from. */
7732 it
->what
= IT_CHARACTER
;
7733 it
->object
= it
->string
;
7734 it
->position
= position
;
7739 /* Load IT with next display element from C string IT->s.
7740 IT->string_nchars is the maximum number of characters to return
7741 from the string. IT->end_charpos may be greater than
7742 IT->string_nchars when this function is called, in which case we
7743 may have to return padding spaces. Value is zero if end of string
7744 reached, including padding spaces. */
7747 next_element_from_c_string (struct it
*it
)
7752 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7753 it
->what
= IT_CHARACTER
;
7754 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7757 /* With bidi reordering, the character to display might not be the
7758 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7759 we were reseated to a new string, whose paragraph direction is
7761 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7762 get_visually_first_element (it
);
7764 /* IT's position can be greater than IT->string_nchars in case a
7765 field width or precision has been specified when the iterator was
7767 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7769 /* End of the game. */
7773 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7775 /* Pad with spaces. */
7776 it
->c
= ' ', it
->len
= 1;
7777 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7779 else if (it
->multibyte_p
)
7780 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7782 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7788 /* Set up IT to return characters from an ellipsis, if appropriate.
7789 The definition of the ellipsis glyphs may come from a display table
7790 entry. This function fills IT with the first glyph from the
7791 ellipsis if an ellipsis is to be displayed. */
7794 next_element_from_ellipsis (struct it
*it
)
7796 if (it
->selective_display_ellipsis_p
)
7797 setup_for_ellipsis (it
, it
->len
);
7800 /* The face at the current position may be different from the
7801 face we find after the invisible text. Remember what it
7802 was in IT->saved_face_id, and signal that it's there by
7803 setting face_before_selective_p. */
7804 it
->saved_face_id
= it
->face_id
;
7805 it
->method
= GET_FROM_BUFFER
;
7806 it
->object
= it
->w
->contents
;
7807 reseat_at_next_visible_line_start (it
, 1);
7808 it
->face_before_selective_p
= 1;
7811 return GET_NEXT_DISPLAY_ELEMENT (it
);
7815 /* Deliver an image display element. The iterator IT is already
7816 filled with image information (done in handle_display_prop). Value
7821 next_element_from_image (struct it
*it
)
7823 it
->what
= IT_IMAGE
;
7824 it
->ignore_overlay_strings_at_pos_p
= 0;
7829 /* Fill iterator IT with next display element from a stretch glyph
7830 property. IT->object is the value of the text property. Value is
7834 next_element_from_stretch (struct it
*it
)
7836 it
->what
= IT_STRETCH
;
7840 /* Scan backwards from IT's current position until we find a stop
7841 position, or until BEGV. This is called when we find ourself
7842 before both the last known prev_stop and base_level_stop while
7843 reordering bidirectional text. */
7846 compute_stop_pos_backwards (struct it
*it
)
7848 const int SCAN_BACK_LIMIT
= 1000;
7849 struct text_pos pos
;
7850 struct display_pos save_current
= it
->current
;
7851 struct text_pos save_position
= it
->position
;
7852 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7853 ptrdiff_t where_we_are
= charpos
;
7854 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7855 ptrdiff_t save_end_pos
= it
->end_charpos
;
7857 eassert (NILP (it
->string
) && !it
->s
);
7858 eassert (it
->bidi_p
);
7862 it
->end_charpos
= min (charpos
+ 1, ZV
);
7863 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7864 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7865 reseat_1 (it
, pos
, 0);
7866 compute_stop_pos (it
);
7867 /* We must advance forward, right? */
7868 if (it
->stop_charpos
<= charpos
)
7871 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7873 if (it
->stop_charpos
<= where_we_are
)
7874 it
->prev_stop
= it
->stop_charpos
;
7876 it
->prev_stop
= BEGV
;
7878 it
->current
= save_current
;
7879 it
->position
= save_position
;
7880 it
->stop_charpos
= save_stop_pos
;
7881 it
->end_charpos
= save_end_pos
;
7884 /* Scan forward from CHARPOS in the current buffer/string, until we
7885 find a stop position > current IT's position. Then handle the stop
7886 position before that. This is called when we bump into a stop
7887 position while reordering bidirectional text. CHARPOS should be
7888 the last previously processed stop_pos (or BEGV/0, if none were
7889 processed yet) whose position is less that IT's current
7893 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7895 int bufp
= !STRINGP (it
->string
);
7896 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7897 struct display_pos save_current
= it
->current
;
7898 struct text_pos save_position
= it
->position
;
7899 struct text_pos pos1
;
7900 ptrdiff_t next_stop
;
7902 /* Scan in strict logical order. */
7903 eassert (it
->bidi_p
);
7907 it
->prev_stop
= charpos
;
7910 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7911 reseat_1 (it
, pos1
, 0);
7914 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7915 compute_stop_pos (it
);
7916 /* We must advance forward, right? */
7917 if (it
->stop_charpos
<= it
->prev_stop
)
7919 charpos
= it
->stop_charpos
;
7921 while (charpos
<= where_we_are
);
7924 it
->current
= save_current
;
7925 it
->position
= save_position
;
7926 next_stop
= it
->stop_charpos
;
7927 it
->stop_charpos
= it
->prev_stop
;
7929 it
->stop_charpos
= next_stop
;
7932 /* Load IT with the next display element from current_buffer. Value
7933 is zero if end of buffer reached. IT->stop_charpos is the next
7934 position at which to stop and check for text properties or buffer
7938 next_element_from_buffer (struct it
*it
)
7942 eassert (IT_CHARPOS (*it
) >= BEGV
);
7943 eassert (NILP (it
->string
) && !it
->s
);
7944 eassert (!it
->bidi_p
7945 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7946 && it
->bidi_it
.string
.s
== NULL
));
7948 /* With bidi reordering, the character to display might not be the
7949 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7950 we were reseat()ed to a new buffer position, which is potentially
7951 a different paragraph. */
7952 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7954 get_visually_first_element (it
);
7955 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7958 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7960 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7962 int overlay_strings_follow_p
;
7964 /* End of the game, except when overlay strings follow that
7965 haven't been returned yet. */
7966 if (it
->overlay_strings_at_end_processed_p
)
7967 overlay_strings_follow_p
= 0;
7970 it
->overlay_strings_at_end_processed_p
= 1;
7971 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7974 if (overlay_strings_follow_p
)
7975 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7979 it
->position
= it
->current
.pos
;
7983 else if (!(!it
->bidi_p
7984 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7985 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7987 /* With bidi non-linear iteration, we could find ourselves
7988 far beyond the last computed stop_charpos, with several
7989 other stop positions in between that we missed. Scan
7990 them all now, in buffer's logical order, until we find
7991 and handle the last stop_charpos that precedes our
7992 current position. */
7993 handle_stop_backwards (it
, it
->stop_charpos
);
7994 return GET_NEXT_DISPLAY_ELEMENT (it
);
8000 /* Take note of the stop position we just moved across,
8001 for when we will move back across it. */
8002 it
->prev_stop
= it
->stop_charpos
;
8003 /* If we are at base paragraph embedding level, take
8004 note of the last stop position seen at this
8006 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8007 it
->base_level_stop
= it
->stop_charpos
;
8010 return GET_NEXT_DISPLAY_ELEMENT (it
);
8014 /* If we are before prev_stop, we may have overstepped on
8015 our way backwards a stop_pos, and if so, we need to
8016 handle that stop_pos. */
8017 && IT_CHARPOS (*it
) < it
->prev_stop
8018 /* We can sometimes back up for reasons that have nothing
8019 to do with bidi reordering. E.g., compositions. The
8020 code below is only needed when we are above the base
8021 embedding level, so test for that explicitly. */
8022 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8024 if (it
->base_level_stop
<= 0
8025 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8027 /* If we lost track of base_level_stop, we need to find
8028 prev_stop by looking backwards. This happens, e.g., when
8029 we were reseated to the previous screenful of text by
8031 it
->base_level_stop
= BEGV
;
8032 compute_stop_pos_backwards (it
);
8033 handle_stop_backwards (it
, it
->prev_stop
);
8036 handle_stop_backwards (it
, it
->base_level_stop
);
8037 return GET_NEXT_DISPLAY_ELEMENT (it
);
8041 /* No face changes, overlays etc. in sight, so just return a
8042 character from current_buffer. */
8046 /* Maybe run the redisplay end trigger hook. Performance note:
8047 This doesn't seem to cost measurable time. */
8048 if (it
->redisplay_end_trigger_charpos
8050 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8051 run_redisplay_end_trigger_hook (it
);
8053 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8054 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8056 && next_element_from_composition (it
))
8061 /* Get the next character, maybe multibyte. */
8062 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8063 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8064 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8066 it
->c
= *p
, it
->len
= 1;
8068 /* Record what we have and where it came from. */
8069 it
->what
= IT_CHARACTER
;
8070 it
->object
= it
->w
->contents
;
8071 it
->position
= it
->current
.pos
;
8073 /* Normally we return the character found above, except when we
8074 really want to return an ellipsis for selective display. */
8079 /* A value of selective > 0 means hide lines indented more
8080 than that number of columns. */
8081 if (it
->selective
> 0
8082 && IT_CHARPOS (*it
) + 1 < ZV
8083 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8084 IT_BYTEPOS (*it
) + 1,
8087 success_p
= next_element_from_ellipsis (it
);
8088 it
->dpvec_char_len
= -1;
8091 else if (it
->c
== '\r' && it
->selective
== -1)
8093 /* A value of selective == -1 means that everything from the
8094 CR to the end of the line is invisible, with maybe an
8095 ellipsis displayed for it. */
8096 success_p
= next_element_from_ellipsis (it
);
8097 it
->dpvec_char_len
= -1;
8102 /* Value is zero if end of buffer reached. */
8103 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8108 /* Run the redisplay end trigger hook for IT. */
8111 run_redisplay_end_trigger_hook (struct it
*it
)
8113 Lisp_Object args
[3];
8115 /* IT->glyph_row should be non-null, i.e. we should be actually
8116 displaying something, or otherwise we should not run the hook. */
8117 eassert (it
->glyph_row
);
8119 /* Set up hook arguments. */
8120 args
[0] = Qredisplay_end_trigger_functions
;
8121 args
[1] = it
->window
;
8122 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8123 it
->redisplay_end_trigger_charpos
= 0;
8125 /* Since we are *trying* to run these functions, don't try to run
8126 them again, even if they get an error. */
8127 wset_redisplay_end_trigger (it
->w
, Qnil
);
8128 Frun_hook_with_args (3, args
);
8130 /* Notice if it changed the face of the character we are on. */
8131 handle_face_prop (it
);
8135 /* Deliver a composition display element. Unlike the other
8136 next_element_from_XXX, this function is not registered in the array
8137 get_next_element[]. It is called from next_element_from_buffer and
8138 next_element_from_string when necessary. */
8141 next_element_from_composition (struct it
*it
)
8143 it
->what
= IT_COMPOSITION
;
8144 it
->len
= it
->cmp_it
.nbytes
;
8145 if (STRINGP (it
->string
))
8149 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8150 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8153 it
->position
= it
->current
.string_pos
;
8154 it
->object
= it
->string
;
8155 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8156 IT_STRING_BYTEPOS (*it
), it
->string
);
8162 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8163 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8166 if (it
->bidi_it
.new_paragraph
)
8167 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8168 /* Resync the bidi iterator with IT's new position.
8169 FIXME: this doesn't support bidirectional text. */
8170 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8171 bidi_move_to_visually_next (&it
->bidi_it
);
8175 it
->position
= it
->current
.pos
;
8176 it
->object
= it
->w
->contents
;
8177 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8178 IT_BYTEPOS (*it
), Qnil
);
8185 /***********************************************************************
8186 Moving an iterator without producing glyphs
8187 ***********************************************************************/
8189 /* Check if iterator is at a position corresponding to a valid buffer
8190 position after some move_it_ call. */
8192 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8193 ((it)->method == GET_FROM_STRING \
8194 ? IT_STRING_CHARPOS (*it) == 0 \
8198 /* Move iterator IT to a specified buffer or X position within one
8199 line on the display without producing glyphs.
8201 OP should be a bit mask including some or all of these bits:
8202 MOVE_TO_X: Stop upon reaching x-position TO_X.
8203 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8204 Regardless of OP's value, stop upon reaching the end of the display line.
8206 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8207 This means, in particular, that TO_X includes window's horizontal
8210 The return value has several possible values that
8211 say what condition caused the scan to stop:
8213 MOVE_POS_MATCH_OR_ZV
8214 - when TO_POS or ZV was reached.
8217 -when TO_X was reached before TO_POS or ZV were reached.
8220 - when we reached the end of the display area and the line must
8224 - when we reached the end of the display area and the line is
8228 - when we stopped at a line end, i.e. a newline or a CR and selective
8231 static enum move_it_result
8232 move_it_in_display_line_to (struct it
*it
,
8233 ptrdiff_t to_charpos
, int to_x
,
8234 enum move_operation_enum op
)
8236 enum move_it_result result
= MOVE_UNDEFINED
;
8237 struct glyph_row
*saved_glyph_row
;
8238 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8239 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8240 void *ppos_data
= NULL
;
8242 enum it_method prev_method
= it
->method
;
8243 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8244 int saw_smaller_pos
= prev_pos
< to_charpos
;
8246 /* Don't produce glyphs in produce_glyphs. */
8247 saved_glyph_row
= it
->glyph_row
;
8248 it
->glyph_row
= NULL
;
8250 /* Use wrap_it to save a copy of IT wherever a word wrap could
8251 occur. Use atpos_it to save a copy of IT at the desired buffer
8252 position, if found, so that we can scan ahead and check if the
8253 word later overshoots the window edge. Use atx_it similarly, for
8259 /* Use ppos_it under bidi reordering to save a copy of IT for the
8260 position > CHARPOS that is the closest to CHARPOS. We restore
8261 that position in IT when we have scanned the entire display line
8262 without finding a match for CHARPOS and all the character
8263 positions are greater than CHARPOS. */
8266 SAVE_IT (ppos_it
, *it
, ppos_data
);
8267 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8268 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8269 SAVE_IT (ppos_it
, *it
, ppos_data
);
8272 #define BUFFER_POS_REACHED_P() \
8273 ((op & MOVE_TO_POS) != 0 \
8274 && BUFFERP (it->object) \
8275 && (IT_CHARPOS (*it) == to_charpos \
8277 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8278 && IT_CHARPOS (*it) > to_charpos) \
8279 || (it->what == IT_COMPOSITION \
8280 && ((IT_CHARPOS (*it) > to_charpos \
8281 && to_charpos >= it->cmp_it.charpos) \
8282 || (IT_CHARPOS (*it) < to_charpos \
8283 && to_charpos <= it->cmp_it.charpos)))) \
8284 && (it->method == GET_FROM_BUFFER \
8285 || (it->method == GET_FROM_DISPLAY_VECTOR \
8286 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8288 /* If there's a line-/wrap-prefix, handle it. */
8289 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8290 && it
->current_y
< it
->last_visible_y
)
8291 handle_line_prefix (it
);
8293 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8294 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8298 int x
, i
, ascent
= 0, descent
= 0;
8300 /* Utility macro to reset an iterator with x, ascent, and descent. */
8301 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8302 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8303 (IT)->max_descent = descent)
8305 /* Stop if we move beyond TO_CHARPOS (after an image or a
8306 display string or stretch glyph). */
8307 if ((op
& MOVE_TO_POS
) != 0
8308 && BUFFERP (it
->object
)
8309 && it
->method
== GET_FROM_BUFFER
8311 /* When the iterator is at base embedding level, we
8312 are guaranteed that characters are delivered for
8313 display in strictly increasing order of their
8314 buffer positions. */
8315 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8316 && IT_CHARPOS (*it
) > to_charpos
)
8318 && (prev_method
== GET_FROM_IMAGE
8319 || prev_method
== GET_FROM_STRETCH
8320 || prev_method
== GET_FROM_STRING
)
8321 /* Passed TO_CHARPOS from left to right. */
8322 && ((prev_pos
< to_charpos
8323 && IT_CHARPOS (*it
) > to_charpos
)
8324 /* Passed TO_CHARPOS from right to left. */
8325 || (prev_pos
> to_charpos
8326 && IT_CHARPOS (*it
) < to_charpos
)))))
8328 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8330 result
= MOVE_POS_MATCH_OR_ZV
;
8333 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8334 /* If wrap_it is valid, the current position might be in a
8335 word that is wrapped. So, save the iterator in
8336 atpos_it and continue to see if wrapping happens. */
8337 SAVE_IT (atpos_it
, *it
, atpos_data
);
8340 /* Stop when ZV reached.
8341 We used to stop here when TO_CHARPOS reached as well, but that is
8342 too soon if this glyph does not fit on this line. So we handle it
8343 explicitly below. */
8344 if (!get_next_display_element (it
))
8346 result
= MOVE_POS_MATCH_OR_ZV
;
8350 if (it
->line_wrap
== TRUNCATE
)
8352 if (BUFFER_POS_REACHED_P ())
8354 result
= MOVE_POS_MATCH_OR_ZV
;
8360 if (it
->line_wrap
== WORD_WRAP
)
8362 if (IT_DISPLAYING_WHITESPACE (it
))
8366 /* We have reached a glyph that follows one or more
8367 whitespace characters. If the position is
8368 already found, we are done. */
8369 if (atpos_it
.sp
>= 0)
8371 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8372 result
= MOVE_POS_MATCH_OR_ZV
;
8377 RESTORE_IT (it
, &atx_it
, atx_data
);
8378 result
= MOVE_X_REACHED
;
8381 /* Otherwise, we can wrap here. */
8382 SAVE_IT (wrap_it
, *it
, wrap_data
);
8388 /* Remember the line height for the current line, in case
8389 the next element doesn't fit on the line. */
8390 ascent
= it
->max_ascent
;
8391 descent
= it
->max_descent
;
8393 /* The call to produce_glyphs will get the metrics of the
8394 display element IT is loaded with. Record the x-position
8395 before this display element, in case it doesn't fit on the
8399 PRODUCE_GLYPHS (it
);
8401 if (it
->area
!= TEXT_AREA
)
8403 prev_method
= it
->method
;
8404 if (it
->method
== GET_FROM_BUFFER
)
8405 prev_pos
= IT_CHARPOS (*it
);
8406 set_iterator_to_next (it
, 1);
8407 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8408 SET_TEXT_POS (this_line_min_pos
,
8409 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8411 && (op
& MOVE_TO_POS
)
8412 && IT_CHARPOS (*it
) > to_charpos
8413 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8414 SAVE_IT (ppos_it
, *it
, ppos_data
);
8418 /* The number of glyphs we get back in IT->nglyphs will normally
8419 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8420 character on a terminal frame, or (iii) a line end. For the
8421 second case, IT->nglyphs - 1 padding glyphs will be present.
8422 (On X frames, there is only one glyph produced for a
8423 composite character.)
8425 The behavior implemented below means, for continuation lines,
8426 that as many spaces of a TAB as fit on the current line are
8427 displayed there. For terminal frames, as many glyphs of a
8428 multi-glyph character are displayed in the current line, too.
8429 This is what the old redisplay code did, and we keep it that
8430 way. Under X, the whole shape of a complex character must
8431 fit on the line or it will be completely displayed in the
8434 Note that both for tabs and padding glyphs, all glyphs have
8438 /* More than one glyph or glyph doesn't fit on line. All
8439 glyphs have the same width. */
8440 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8442 int x_before_this_char
= x
;
8443 int hpos_before_this_char
= it
->hpos
;
8445 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8447 new_x
= x
+ single_glyph_width
;
8449 /* We want to leave anything reaching TO_X to the caller. */
8450 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8452 if (BUFFER_POS_REACHED_P ())
8454 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8455 goto buffer_pos_reached
;
8456 if (atpos_it
.sp
< 0)
8458 SAVE_IT (atpos_it
, *it
, atpos_data
);
8459 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8464 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8467 result
= MOVE_X_REACHED
;
8472 SAVE_IT (atx_it
, *it
, atx_data
);
8473 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8478 if (/* Lines are continued. */
8479 it
->line_wrap
!= TRUNCATE
8480 && (/* And glyph doesn't fit on the line. */
8481 new_x
> it
->last_visible_x
8482 /* Or it fits exactly and we're on a window
8484 || (new_x
== it
->last_visible_x
8485 && FRAME_WINDOW_P (it
->f
)
8486 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8487 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8488 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8490 if (/* IT->hpos == 0 means the very first glyph
8491 doesn't fit on the line, e.g. a wide image. */
8493 || (new_x
== it
->last_visible_x
8494 && FRAME_WINDOW_P (it
->f
)))
8497 it
->current_x
= new_x
;
8499 /* The character's last glyph just barely fits
8501 if (i
== it
->nglyphs
- 1)
8503 /* If this is the destination position,
8504 return a position *before* it in this row,
8505 now that we know it fits in this row. */
8506 if (BUFFER_POS_REACHED_P ())
8508 if (it
->line_wrap
!= WORD_WRAP
8511 it
->hpos
= hpos_before_this_char
;
8512 it
->current_x
= x_before_this_char
;
8513 result
= MOVE_POS_MATCH_OR_ZV
;
8516 if (it
->line_wrap
== WORD_WRAP
8519 SAVE_IT (atpos_it
, *it
, atpos_data
);
8520 atpos_it
.current_x
= x_before_this_char
;
8521 atpos_it
.hpos
= hpos_before_this_char
;
8525 prev_method
= it
->method
;
8526 if (it
->method
== GET_FROM_BUFFER
)
8527 prev_pos
= IT_CHARPOS (*it
);
8528 set_iterator_to_next (it
, 1);
8529 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8530 SET_TEXT_POS (this_line_min_pos
,
8531 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8532 /* On graphical terminals, newlines may
8533 "overflow" into the fringe if
8534 overflow-newline-into-fringe is non-nil.
8535 On text terminals, and on graphical
8536 terminals with no right margin, newlines
8537 may overflow into the last glyph on the
8539 if (!FRAME_WINDOW_P (it
->f
)
8541 && it
->bidi_it
.paragraph_dir
== R2L
)
8542 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8543 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8544 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8546 if (!get_next_display_element (it
))
8548 result
= MOVE_POS_MATCH_OR_ZV
;
8551 if (BUFFER_POS_REACHED_P ())
8553 if (ITERATOR_AT_END_OF_LINE_P (it
))
8554 result
= MOVE_POS_MATCH_OR_ZV
;
8556 result
= MOVE_LINE_CONTINUED
;
8559 if (ITERATOR_AT_END_OF_LINE_P (it
)
8560 && (it
->line_wrap
!= WORD_WRAP
8563 result
= MOVE_NEWLINE_OR_CR
;
8570 IT_RESET_X_ASCENT_DESCENT (it
);
8572 if (wrap_it
.sp
>= 0)
8574 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8579 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8581 result
= MOVE_LINE_CONTINUED
;
8585 if (BUFFER_POS_REACHED_P ())
8587 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8588 goto buffer_pos_reached
;
8589 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8591 SAVE_IT (atpos_it
, *it
, atpos_data
);
8592 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8596 if (new_x
> it
->first_visible_x
)
8598 /* Glyph is visible. Increment number of glyphs that
8599 would be displayed. */
8604 if (result
!= MOVE_UNDEFINED
)
8607 else if (BUFFER_POS_REACHED_P ())
8610 IT_RESET_X_ASCENT_DESCENT (it
);
8611 result
= MOVE_POS_MATCH_OR_ZV
;
8614 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8616 /* Stop when TO_X specified and reached. This check is
8617 necessary here because of lines consisting of a line end,
8618 only. The line end will not produce any glyphs and we
8619 would never get MOVE_X_REACHED. */
8620 eassert (it
->nglyphs
== 0);
8621 result
= MOVE_X_REACHED
;
8625 /* Is this a line end? If yes, we're done. */
8626 if (ITERATOR_AT_END_OF_LINE_P (it
))
8628 /* If we are past TO_CHARPOS, but never saw any character
8629 positions smaller than TO_CHARPOS, return
8630 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8632 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8634 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8636 if (IT_CHARPOS (ppos_it
) < ZV
)
8638 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8639 result
= MOVE_POS_MATCH_OR_ZV
;
8642 goto buffer_pos_reached
;
8644 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8645 && IT_CHARPOS (*it
) > to_charpos
)
8646 goto buffer_pos_reached
;
8648 result
= MOVE_NEWLINE_OR_CR
;
8651 result
= MOVE_NEWLINE_OR_CR
;
8655 prev_method
= it
->method
;
8656 if (it
->method
== GET_FROM_BUFFER
)
8657 prev_pos
= IT_CHARPOS (*it
);
8658 /* The current display element has been consumed. Advance
8660 set_iterator_to_next (it
, 1);
8661 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8662 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8663 if (IT_CHARPOS (*it
) < to_charpos
)
8664 saw_smaller_pos
= 1;
8666 && (op
& MOVE_TO_POS
)
8667 && IT_CHARPOS (*it
) >= to_charpos
8668 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8669 SAVE_IT (ppos_it
, *it
, ppos_data
);
8671 /* Stop if lines are truncated and IT's current x-position is
8672 past the right edge of the window now. */
8673 if (it
->line_wrap
== TRUNCATE
8674 && it
->current_x
>= it
->last_visible_x
)
8676 if (!FRAME_WINDOW_P (it
->f
)
8677 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8678 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8679 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8680 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8684 if ((at_eob_p
= !get_next_display_element (it
))
8685 || BUFFER_POS_REACHED_P ()
8686 /* If we are past TO_CHARPOS, but never saw any
8687 character positions smaller than TO_CHARPOS,
8688 return MOVE_POS_MATCH_OR_ZV, like the
8689 unidirectional display did. */
8690 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8692 && IT_CHARPOS (*it
) > to_charpos
))
8695 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8696 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8697 result
= MOVE_POS_MATCH_OR_ZV
;
8700 if (ITERATOR_AT_END_OF_LINE_P (it
))
8702 result
= MOVE_NEWLINE_OR_CR
;
8706 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8708 && IT_CHARPOS (*it
) > to_charpos
)
8710 if (IT_CHARPOS (ppos_it
) < ZV
)
8711 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8712 result
= MOVE_POS_MATCH_OR_ZV
;
8715 result
= MOVE_LINE_TRUNCATED
;
8718 #undef IT_RESET_X_ASCENT_DESCENT
8721 #undef BUFFER_POS_REACHED_P
8723 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8724 restore the saved iterator. */
8725 if (atpos_it
.sp
>= 0)
8726 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8727 else if (atx_it
.sp
>= 0)
8728 RESTORE_IT (it
, &atx_it
, atx_data
);
8733 bidi_unshelve_cache (atpos_data
, 1);
8735 bidi_unshelve_cache (atx_data
, 1);
8737 bidi_unshelve_cache (wrap_data
, 1);
8739 bidi_unshelve_cache (ppos_data
, 1);
8741 /* Restore the iterator settings altered at the beginning of this
8743 it
->glyph_row
= saved_glyph_row
;
8747 /* For external use. */
8749 move_it_in_display_line (struct it
*it
,
8750 ptrdiff_t to_charpos
, int to_x
,
8751 enum move_operation_enum op
)
8753 if (it
->line_wrap
== WORD_WRAP
8754 && (op
& MOVE_TO_X
))
8757 void *save_data
= NULL
;
8760 SAVE_IT (save_it
, *it
, save_data
);
8761 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8762 /* When word-wrap is on, TO_X may lie past the end
8763 of a wrapped line. Then it->current is the
8764 character on the next line, so backtrack to the
8765 space before the wrap point. */
8766 if (skip
== MOVE_LINE_CONTINUED
)
8768 int prev_x
= max (it
->current_x
- 1, 0);
8769 RESTORE_IT (it
, &save_it
, save_data
);
8770 move_it_in_display_line_to
8771 (it
, -1, prev_x
, MOVE_TO_X
);
8774 bidi_unshelve_cache (save_data
, 1);
8777 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8781 /* Move IT forward until it satisfies one or more of the criteria in
8782 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8784 OP is a bit-mask that specifies where to stop, and in particular,
8785 which of those four position arguments makes a difference. See the
8786 description of enum move_operation_enum.
8788 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8789 screen line, this function will set IT to the next position that is
8790 displayed to the right of TO_CHARPOS on the screen. */
8793 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8795 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8796 int line_height
, line_start_x
= 0, reached
= 0;
8797 void *backup_data
= NULL
;
8801 if (op
& MOVE_TO_VPOS
)
8803 /* If no TO_CHARPOS and no TO_X specified, stop at the
8804 start of the line TO_VPOS. */
8805 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8807 if (it
->vpos
== to_vpos
)
8813 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8817 /* TO_VPOS >= 0 means stop at TO_X in the line at
8818 TO_VPOS, or at TO_POS, whichever comes first. */
8819 if (it
->vpos
== to_vpos
)
8825 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8827 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8832 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8834 /* We have reached TO_X but not in the line we want. */
8835 skip
= move_it_in_display_line_to (it
, to_charpos
,
8837 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8845 else if (op
& MOVE_TO_Y
)
8847 struct it it_backup
;
8849 if (it
->line_wrap
== WORD_WRAP
)
8850 SAVE_IT (it_backup
, *it
, backup_data
);
8852 /* TO_Y specified means stop at TO_X in the line containing
8853 TO_Y---or at TO_CHARPOS if this is reached first. The
8854 problem is that we can't really tell whether the line
8855 contains TO_Y before we have completely scanned it, and
8856 this may skip past TO_X. What we do is to first scan to
8859 If TO_X is not specified, use a TO_X of zero. The reason
8860 is to make the outcome of this function more predictable.
8861 If we didn't use TO_X == 0, we would stop at the end of
8862 the line which is probably not what a caller would expect
8864 skip
= move_it_in_display_line_to
8865 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8866 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8868 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8869 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8871 else if (skip
== MOVE_X_REACHED
)
8873 /* If TO_X was reached, we want to know whether TO_Y is
8874 in the line. We know this is the case if the already
8875 scanned glyphs make the line tall enough. Otherwise,
8876 we must check by scanning the rest of the line. */
8877 line_height
= it
->max_ascent
+ it
->max_descent
;
8878 if (to_y
>= it
->current_y
8879 && to_y
< it
->current_y
+ line_height
)
8884 SAVE_IT (it_backup
, *it
, backup_data
);
8885 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8886 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8888 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8889 line_height
= it
->max_ascent
+ it
->max_descent
;
8890 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8892 if (to_y
>= it
->current_y
8893 && to_y
< it
->current_y
+ line_height
)
8895 /* If TO_Y is in this line and TO_X was reached
8896 above, we scanned too far. We have to restore
8897 IT's settings to the ones before skipping. But
8898 keep the more accurate values of max_ascent and
8899 max_descent we've found while skipping the rest
8900 of the line, for the sake of callers, such as
8901 pos_visible_p, that need to know the line
8903 int max_ascent
= it
->max_ascent
;
8904 int max_descent
= it
->max_descent
;
8906 RESTORE_IT (it
, &it_backup
, backup_data
);
8907 it
->max_ascent
= max_ascent
;
8908 it
->max_descent
= max_descent
;
8914 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8920 /* Check whether TO_Y is in this line. */
8921 line_height
= it
->max_ascent
+ it
->max_descent
;
8922 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8924 if (to_y
>= it
->current_y
8925 && to_y
< it
->current_y
+ line_height
)
8927 /* When word-wrap is on, TO_X may lie past the end
8928 of a wrapped line. Then it->current is the
8929 character on the next line, so backtrack to the
8930 space before the wrap point. */
8931 if (skip
== MOVE_LINE_CONTINUED
8932 && it
->line_wrap
== WORD_WRAP
)
8934 int prev_x
= max (it
->current_x
- 1, 0);
8935 RESTORE_IT (it
, &it_backup
, backup_data
);
8936 skip
= move_it_in_display_line_to
8937 (it
, -1, prev_x
, MOVE_TO_X
);
8946 else if (BUFFERP (it
->object
)
8947 && (it
->method
== GET_FROM_BUFFER
8948 || it
->method
== GET_FROM_STRETCH
)
8949 && IT_CHARPOS (*it
) >= to_charpos
8950 /* Under bidi iteration, a call to set_iterator_to_next
8951 can scan far beyond to_charpos if the initial
8952 portion of the next line needs to be reordered. In
8953 that case, give move_it_in_display_line_to another
8956 && it
->bidi_it
.scan_dir
== -1))
8957 skip
= MOVE_POS_MATCH_OR_ZV
;
8959 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8963 case MOVE_POS_MATCH_OR_ZV
:
8967 case MOVE_NEWLINE_OR_CR
:
8968 set_iterator_to_next (it
, 1);
8969 it
->continuation_lines_width
= 0;
8972 case MOVE_LINE_TRUNCATED
:
8973 it
->continuation_lines_width
= 0;
8974 reseat_at_next_visible_line_start (it
, 0);
8975 if ((op
& MOVE_TO_POS
) != 0
8976 && IT_CHARPOS (*it
) > to_charpos
)
8983 case MOVE_LINE_CONTINUED
:
8984 /* For continued lines ending in a tab, some of the glyphs
8985 associated with the tab are displayed on the current
8986 line. Since it->current_x does not include these glyphs,
8987 we use it->last_visible_x instead. */
8990 it
->continuation_lines_width
+= it
->last_visible_x
;
8991 /* When moving by vpos, ensure that the iterator really
8992 advances to the next line (bug#847, bug#969). Fixme:
8993 do we need to do this in other circumstances? */
8994 if (it
->current_x
!= it
->last_visible_x
8995 && (op
& MOVE_TO_VPOS
)
8996 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8998 line_start_x
= it
->current_x
+ it
->pixel_width
8999 - it
->last_visible_x
;
9000 set_iterator_to_next (it
, 0);
9004 it
->continuation_lines_width
+= it
->current_x
;
9011 /* Reset/increment for the next run. */
9012 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9013 it
->current_x
= line_start_x
;
9016 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9018 last_height
= it
->max_ascent
+ it
->max_descent
;
9019 it
->max_ascent
= it
->max_descent
= 0;
9024 /* On text terminals, we may stop at the end of a line in the middle
9025 of a multi-character glyph. If the glyph itself is continued,
9026 i.e. it is actually displayed on the next line, don't treat this
9027 stopping point as valid; move to the next line instead (unless
9028 that brings us offscreen). */
9029 if (!FRAME_WINDOW_P (it
->f
)
9031 && IT_CHARPOS (*it
) == to_charpos
9032 && it
->what
== IT_CHARACTER
9034 && it
->line_wrap
== WINDOW_WRAP
9035 && it
->current_x
== it
->last_visible_x
- 1
9038 && it
->vpos
< it
->w
->window_end_vpos
)
9040 it
->continuation_lines_width
+= it
->current_x
;
9041 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9042 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9044 last_height
= it
->max_ascent
+ it
->max_descent
;
9048 bidi_unshelve_cache (backup_data
, 1);
9050 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9054 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9056 If DY > 0, move IT backward at least that many pixels. DY = 0
9057 means move IT backward to the preceding line start or BEGV. This
9058 function may move over more than DY pixels if IT->current_y - DY
9059 ends up in the middle of a line; in this case IT->current_y will be
9060 set to the top of the line moved to. */
9063 move_it_vertically_backward (struct it
*it
, int dy
)
9067 void *it2data
= NULL
, *it3data
= NULL
;
9068 ptrdiff_t start_pos
;
9070 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9071 ptrdiff_t pos_limit
;
9076 start_pos
= IT_CHARPOS (*it
);
9078 /* Estimate how many newlines we must move back. */
9079 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9080 if (it
->line_wrap
== TRUNCATE
)
9083 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9085 /* Set the iterator's position that many lines back. But don't go
9086 back more than NLINES full screen lines -- this wins a day with
9087 buffers which have very long lines. */
9088 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9089 back_to_previous_visible_line_start (it
);
9091 /* Reseat the iterator here. When moving backward, we don't want
9092 reseat to skip forward over invisible text, set up the iterator
9093 to deliver from overlay strings at the new position etc. So,
9094 use reseat_1 here. */
9095 reseat_1 (it
, it
->current
.pos
, 1);
9097 /* We are now surely at a line start. */
9098 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9099 reordering is in effect. */
9100 it
->continuation_lines_width
= 0;
9102 /* Move forward and see what y-distance we moved. First move to the
9103 start of the next line so that we get its height. We need this
9104 height to be able to tell whether we reached the specified
9106 SAVE_IT (it2
, *it
, it2data
);
9107 it2
.max_ascent
= it2
.max_descent
= 0;
9110 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9111 MOVE_TO_POS
| MOVE_TO_VPOS
);
9113 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9114 /* If we are in a display string which starts at START_POS,
9115 and that display string includes a newline, and we are
9116 right after that newline (i.e. at the beginning of a
9117 display line), exit the loop, because otherwise we will
9118 infloop, since move_it_to will see that it is already at
9119 START_POS and will not move. */
9120 || (it2
.method
== GET_FROM_STRING
9121 && IT_CHARPOS (it2
) == start_pos
9122 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9123 eassert (IT_CHARPOS (*it
) >= BEGV
);
9124 SAVE_IT (it3
, it2
, it3data
);
9126 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9127 eassert (IT_CHARPOS (*it
) >= BEGV
);
9128 /* H is the actual vertical distance from the position in *IT
9129 and the starting position. */
9130 h
= it2
.current_y
- it
->current_y
;
9131 /* NLINES is the distance in number of lines. */
9132 nlines
= it2
.vpos
- it
->vpos
;
9134 /* Correct IT's y and vpos position
9135 so that they are relative to the starting point. */
9141 /* DY == 0 means move to the start of the screen line. The
9142 value of nlines is > 0 if continuation lines were involved,
9143 or if the original IT position was at start of a line. */
9144 RESTORE_IT (it
, it
, it2data
);
9146 move_it_by_lines (it
, nlines
);
9147 /* The above code moves us to some position NLINES down,
9148 usually to its first glyph (leftmost in an L2R line), but
9149 that's not necessarily the start of the line, under bidi
9150 reordering. We want to get to the character position
9151 that is immediately after the newline of the previous
9154 && !it
->continuation_lines_width
9155 && !STRINGP (it
->string
)
9156 && IT_CHARPOS (*it
) > BEGV
9157 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9159 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9162 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9163 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9165 bidi_unshelve_cache (it3data
, 1);
9169 /* The y-position we try to reach, relative to *IT.
9170 Note that H has been subtracted in front of the if-statement. */
9171 int target_y
= it
->current_y
+ h
- dy
;
9172 int y0
= it3
.current_y
;
9176 RESTORE_IT (&it3
, &it3
, it3data
);
9177 y1
= line_bottom_y (&it3
);
9178 line_height
= y1
- y0
;
9179 RESTORE_IT (it
, it
, it2data
);
9180 /* If we did not reach target_y, try to move further backward if
9181 we can. If we moved too far backward, try to move forward. */
9182 if (target_y
< it
->current_y
9183 /* This is heuristic. In a window that's 3 lines high, with
9184 a line height of 13 pixels each, recentering with point
9185 on the bottom line will try to move -39/2 = 19 pixels
9186 backward. Try to avoid moving into the first line. */
9187 && (it
->current_y
- target_y
9188 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9189 && IT_CHARPOS (*it
) > BEGV
)
9191 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9192 target_y
- it
->current_y
));
9193 dy
= it
->current_y
- target_y
;
9194 goto move_further_back
;
9196 else if (target_y
>= it
->current_y
+ line_height
9197 && IT_CHARPOS (*it
) < ZV
)
9199 /* Should move forward by at least one line, maybe more.
9201 Note: Calling move_it_by_lines can be expensive on
9202 terminal frames, where compute_motion is used (via
9203 vmotion) to do the job, when there are very long lines
9204 and truncate-lines is nil. That's the reason for
9205 treating terminal frames specially here. */
9207 if (!FRAME_WINDOW_P (it
->f
))
9208 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9213 move_it_by_lines (it
, 1);
9215 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9222 /* Move IT by a specified amount of pixel lines DY. DY negative means
9223 move backwards. DY = 0 means move to start of screen line. At the
9224 end, IT will be on the start of a screen line. */
9227 move_it_vertically (struct it
*it
, int dy
)
9230 move_it_vertically_backward (it
, -dy
);
9233 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9234 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9235 MOVE_TO_POS
| MOVE_TO_Y
);
9236 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9238 /* If buffer ends in ZV without a newline, move to the start of
9239 the line to satisfy the post-condition. */
9240 if (IT_CHARPOS (*it
) == ZV
9242 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9243 move_it_by_lines (it
, 0);
9248 /* Move iterator IT past the end of the text line it is in. */
9251 move_it_past_eol (struct it
*it
)
9253 enum move_it_result rc
;
9255 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9256 if (rc
== MOVE_NEWLINE_OR_CR
)
9257 set_iterator_to_next (it
, 0);
9261 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9262 negative means move up. DVPOS == 0 means move to the start of the
9265 Optimization idea: If we would know that IT->f doesn't use
9266 a face with proportional font, we could be faster for
9267 truncate-lines nil. */
9270 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9273 /* The commented-out optimization uses vmotion on terminals. This
9274 gives bad results, because elements like it->what, on which
9275 callers such as pos_visible_p rely, aren't updated. */
9276 /* struct position pos;
9277 if (!FRAME_WINDOW_P (it->f))
9279 struct text_pos textpos;
9281 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9282 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9283 reseat (it, textpos, 1);
9284 it->vpos += pos.vpos;
9285 it->current_y += pos.vpos;
9291 /* DVPOS == 0 means move to the start of the screen line. */
9292 move_it_vertically_backward (it
, 0);
9293 /* Let next call to line_bottom_y calculate real line height */
9298 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9299 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9301 /* Only move to the next buffer position if we ended up in a
9302 string from display property, not in an overlay string
9303 (before-string or after-string). That is because the
9304 latter don't conceal the underlying buffer position, so
9305 we can ask to move the iterator to the exact position we
9306 are interested in. Note that, even if we are already at
9307 IT_CHARPOS (*it), the call below is not a no-op, as it
9308 will detect that we are at the end of the string, pop the
9309 iterator, and compute it->current_x and it->hpos
9311 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9312 -1, -1, -1, MOVE_TO_POS
);
9318 void *it2data
= NULL
;
9319 ptrdiff_t start_charpos
, i
;
9321 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9322 ptrdiff_t pos_limit
;
9324 /* Start at the beginning of the screen line containing IT's
9325 position. This may actually move vertically backwards,
9326 in case of overlays, so adjust dvpos accordingly. */
9328 move_it_vertically_backward (it
, 0);
9331 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9332 screen lines, and reseat the iterator there. */
9333 start_charpos
= IT_CHARPOS (*it
);
9334 if (it
->line_wrap
== TRUNCATE
)
9337 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9338 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9339 back_to_previous_visible_line_start (it
);
9340 reseat (it
, it
->current
.pos
, 1);
9342 /* Move further back if we end up in a string or an image. */
9343 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9345 /* First try to move to start of display line. */
9347 move_it_vertically_backward (it
, 0);
9349 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9351 /* If start of line is still in string or image,
9352 move further back. */
9353 back_to_previous_visible_line_start (it
);
9354 reseat (it
, it
->current
.pos
, 1);
9358 it
->current_x
= it
->hpos
= 0;
9360 /* Above call may have moved too far if continuation lines
9361 are involved. Scan forward and see if it did. */
9362 SAVE_IT (it2
, *it
, it2data
);
9363 it2
.vpos
= it2
.current_y
= 0;
9364 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9365 it
->vpos
-= it2
.vpos
;
9366 it
->current_y
-= it2
.current_y
;
9367 it
->current_x
= it
->hpos
= 0;
9369 /* If we moved too far back, move IT some lines forward. */
9370 if (it2
.vpos
> -dvpos
)
9372 int delta
= it2
.vpos
+ dvpos
;
9374 RESTORE_IT (&it2
, &it2
, it2data
);
9375 SAVE_IT (it2
, *it
, it2data
);
9376 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9377 /* Move back again if we got too far ahead. */
9378 if (IT_CHARPOS (*it
) >= start_charpos
)
9379 RESTORE_IT (it
, &it2
, it2data
);
9381 bidi_unshelve_cache (it2data
, 1);
9384 RESTORE_IT (it
, it
, it2data
);
9388 /* Return 1 if IT points into the middle of a display vector. */
9391 in_display_vector_p (struct it
*it
)
9393 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9394 && it
->current
.dpvec_index
> 0
9395 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9399 /***********************************************************************
9401 ***********************************************************************/
9404 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9408 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9410 Lisp_Object args
[3];
9411 Lisp_Object msg
, fmt
;
9414 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9418 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9420 args
[0] = fmt
= build_string (format
);
9423 msg
= Fformat (3, args
);
9425 len
= SBYTES (msg
) + 1;
9426 buffer
= SAFE_ALLOCA (len
);
9427 memcpy (buffer
, SDATA (msg
), len
);
9429 message_dolog (buffer
, len
- 1, 1, 0);
9436 /* Output a newline in the *Messages* buffer if "needs" one. */
9439 message_log_maybe_newline (void)
9441 if (message_log_need_newline
)
9442 message_dolog ("", 0, 1, 0);
9446 /* Add a string M of length NBYTES to the message log, optionally
9447 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9448 true, means interpret the contents of M as multibyte. This
9449 function calls low-level routines in order to bypass text property
9450 hooks, etc. which might not be safe to run.
9452 This may GC (insert may run before/after change hooks),
9453 so the buffer M must NOT point to a Lisp string. */
9456 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9458 const unsigned char *msg
= (const unsigned char *) m
;
9460 if (!NILP (Vmemory_full
))
9463 if (!NILP (Vmessage_log_max
))
9465 struct buffer
*oldbuf
;
9466 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9467 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9468 ptrdiff_t point_at_end
= 0;
9469 ptrdiff_t zv_at_end
= 0;
9470 Lisp_Object old_deactivate_mark
;
9472 struct gcpro gcpro1
;
9474 old_deactivate_mark
= Vdeactivate_mark
;
9475 oldbuf
= current_buffer
;
9477 /* Ensure the Messages buffer exists, and switch to it.
9478 If we created it, set the major-mode. */
9481 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9483 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9486 !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9487 call0 (intern ("messages-buffer-mode"));
9490 bset_undo_list (current_buffer
, Qt
);
9492 oldpoint
= message_dolog_marker1
;
9493 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9494 oldbegv
= message_dolog_marker2
;
9495 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9496 oldzv
= message_dolog_marker3
;
9497 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9498 GCPRO1 (old_deactivate_mark
);
9506 BEGV_BYTE
= BEG_BYTE
;
9509 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9511 /* Insert the string--maybe converting multibyte to single byte
9512 or vice versa, so that all the text fits the buffer. */
9514 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9520 /* Convert a multibyte string to single-byte
9521 for the *Message* buffer. */
9522 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9524 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9525 work
[0] = (ASCII_CHAR_P (c
)
9527 : multibyte_char_to_unibyte (c
));
9528 insert_1_both (work
, 1, 1, 1, 0, 0);
9531 else if (! multibyte
9532 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9536 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9537 /* Convert a single-byte string to multibyte
9538 for the *Message* buffer. */
9539 for (i
= 0; i
< nbytes
; i
++)
9542 MAKE_CHAR_MULTIBYTE (c
);
9543 char_bytes
= CHAR_STRING (c
, str
);
9544 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9548 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9552 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9555 insert_1_both ("\n", 1, 1, 1, 0, 0);
9557 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9559 this_bol_byte
= PT_BYTE
;
9561 /* See if this line duplicates the previous one.
9562 If so, combine duplicates. */
9565 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9567 prev_bol_byte
= PT_BYTE
;
9569 dups
= message_log_check_duplicate (prev_bol_byte
,
9573 del_range_both (prev_bol
, prev_bol_byte
,
9574 this_bol
, this_bol_byte
, 0);
9577 char dupstr
[sizeof " [ times]"
9578 + INT_STRLEN_BOUND (printmax_t
)];
9580 /* If you change this format, don't forget to also
9581 change message_log_check_duplicate. */
9582 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9583 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9584 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9589 /* If we have more than the desired maximum number of lines
9590 in the *Messages* buffer now, delete the oldest ones.
9591 This is safe because we don't have undo in this buffer. */
9593 if (NATNUMP (Vmessage_log_max
))
9595 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9596 -XFASTINT (Vmessage_log_max
) - 1, 0);
9597 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9600 BEGV
= marker_position (oldbegv
);
9601 BEGV_BYTE
= marker_byte_position (oldbegv
);
9610 ZV
= marker_position (oldzv
);
9611 ZV_BYTE
= marker_byte_position (oldzv
);
9615 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9617 /* We can't do Fgoto_char (oldpoint) because it will run some
9619 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9620 marker_byte_position (oldpoint
));
9623 unchain_marker (XMARKER (oldpoint
));
9624 unchain_marker (XMARKER (oldbegv
));
9625 unchain_marker (XMARKER (oldzv
));
9627 shown
= buffer_window_count (current_buffer
) > 0;
9628 set_buffer_internal (oldbuf
);
9629 /* We called insert_1_both above with its 5th argument (PREPARE)
9630 zero, which prevents insert_1_both from calling
9631 prepare_to_modify_buffer, which in turns prevents us from
9632 incrementing windows_or_buffers_changed even if *Messages* is
9633 shown in some window. So we must manually incrementing
9634 windows_or_buffers_changed here to make up for that. */
9636 windows_or_buffers_changed
++;
9638 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9639 message_log_need_newline
= !nlflag
;
9640 Vdeactivate_mark
= old_deactivate_mark
;
9645 /* We are at the end of the buffer after just having inserted a newline.
9646 (Note: We depend on the fact we won't be crossing the gap.)
9647 Check to see if the most recent message looks a lot like the previous one.
9648 Return 0 if different, 1 if the new one should just replace it, or a
9649 value N > 1 if we should also append " [N times]". */
9652 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9655 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9657 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9658 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9660 for (i
= 0; i
< len
; i
++)
9662 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9670 if (*p1
++ == ' ' && *p1
++ == '[')
9673 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9674 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9681 /* Display an echo area message M with a specified length of NBYTES
9682 bytes. The string may include null characters. If M is not a
9683 string, clear out any existing message, and let the mini-buffer
9686 This function cancels echoing. */
9689 message3 (Lisp_Object m
)
9691 struct gcpro gcpro1
;
9694 clear_message (1,1);
9697 /* First flush out any partial line written with print. */
9698 message_log_maybe_newline ();
9701 ptrdiff_t nbytes
= SBYTES (m
);
9702 bool multibyte
= STRING_MULTIBYTE (m
);
9704 char *buffer
= SAFE_ALLOCA (nbytes
);
9705 memcpy (buffer
, SDATA (m
), nbytes
);
9706 message_dolog (buffer
, nbytes
, 1, multibyte
);
9715 /* The non-logging version of message3.
9716 This does not cancel echoing, because it is used for echoing.
9717 Perhaps we need to make a separate function for echoing
9718 and make this cancel echoing. */
9721 message3_nolog (Lisp_Object m
)
9723 struct frame
*sf
= SELECTED_FRAME ();
9725 if (FRAME_INITIAL_P (sf
))
9727 if (noninteractive_need_newline
)
9728 putc ('\n', stderr
);
9729 noninteractive_need_newline
= 0;
9731 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9732 if (cursor_in_echo_area
== 0)
9733 fprintf (stderr
, "\n");
9736 /* Error messages get reported properly by cmd_error, so this must be just an
9737 informative message; if the frame hasn't really been initialized yet, just
9739 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9741 /* Get the frame containing the mini-buffer
9742 that the selected frame is using. */
9743 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9744 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9745 struct frame
*f
= XFRAME (frame
);
9747 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9748 Fmake_frame_visible (frame
);
9750 if (STRINGP (m
) && SCHARS (m
) > 0)
9753 if (minibuffer_auto_raise
)
9754 Fraise_frame (frame
);
9755 /* Assume we are not echoing.
9756 (If we are, echo_now will override this.) */
9757 echo_message_buffer
= Qnil
;
9760 clear_message (1, 1);
9762 do_pending_window_change (0);
9763 echo_area_display (1);
9764 do_pending_window_change (0);
9765 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9766 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9771 /* Display a null-terminated echo area message M. If M is 0, clear
9772 out any existing message, and let the mini-buffer text show through.
9774 The buffer M must continue to exist until after the echo area gets
9775 cleared or some other message gets displayed there. Do not pass
9776 text that is stored in a Lisp string. Do not pass text in a buffer
9777 that was alloca'd. */
9780 message1 (const char *m
)
9782 message3 (m
? build_unibyte_string (m
) : Qnil
);
9786 /* The non-logging counterpart of message1. */
9789 message1_nolog (const char *m
)
9791 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9794 /* Display a message M which contains a single %s
9795 which gets replaced with STRING. */
9798 message_with_string (const char *m
, Lisp_Object string
, int log
)
9800 CHECK_STRING (string
);
9806 if (noninteractive_need_newline
)
9807 putc ('\n', stderr
);
9808 noninteractive_need_newline
= 0;
9809 fprintf (stderr
, m
, SDATA (string
));
9810 if (!cursor_in_echo_area
)
9811 fprintf (stderr
, "\n");
9815 else if (INTERACTIVE
)
9817 /* The frame whose minibuffer we're going to display the message on.
9818 It may be larger than the selected frame, so we need
9819 to use its buffer, not the selected frame's buffer. */
9820 Lisp_Object mini_window
;
9821 struct frame
*f
, *sf
= SELECTED_FRAME ();
9823 /* Get the frame containing the minibuffer
9824 that the selected frame is using. */
9825 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9826 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9828 /* Error messages get reported properly by cmd_error, so this must be
9829 just an informative message; if the frame hasn't really been
9830 initialized yet, just toss it. */
9831 if (f
->glyphs_initialized_p
)
9833 Lisp_Object args
[2], msg
;
9834 struct gcpro gcpro1
, gcpro2
;
9836 args
[0] = build_string (m
);
9837 args
[1] = msg
= string
;
9838 GCPRO2 (args
[0], msg
);
9841 msg
= Fformat (2, args
);
9846 message3_nolog (msg
);
9850 /* Print should start at the beginning of the message
9851 buffer next time. */
9852 message_buf_print
= 0;
9858 /* Dump an informative message to the minibuf. If M is 0, clear out
9859 any existing message, and let the mini-buffer text show through. */
9862 vmessage (const char *m
, va_list ap
)
9868 if (noninteractive_need_newline
)
9869 putc ('\n', stderr
);
9870 noninteractive_need_newline
= 0;
9871 vfprintf (stderr
, m
, ap
);
9872 if (cursor_in_echo_area
== 0)
9873 fprintf (stderr
, "\n");
9877 else if (INTERACTIVE
)
9879 /* The frame whose mini-buffer we're going to display the message
9880 on. It may be larger than the selected frame, so we need to
9881 use its buffer, not the selected frame's buffer. */
9882 Lisp_Object mini_window
;
9883 struct frame
*f
, *sf
= SELECTED_FRAME ();
9885 /* Get the frame containing the mini-buffer
9886 that the selected frame is using. */
9887 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9888 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9890 /* Error messages get reported properly by cmd_error, so this must be
9891 just an informative message; if the frame hasn't really been
9892 initialized yet, just toss it. */
9893 if (f
->glyphs_initialized_p
)
9898 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9899 char *message_buf
= alloca (maxsize
+ 1);
9901 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9903 message3 (make_string (message_buf
, len
));
9908 /* Print should start at the beginning of the message
9909 buffer next time. */
9910 message_buf_print
= 0;
9916 message (const char *m
, ...)
9926 /* The non-logging version of message. */
9929 message_nolog (const char *m
, ...)
9931 Lisp_Object old_log_max
;
9934 old_log_max
= Vmessage_log_max
;
9935 Vmessage_log_max
= Qnil
;
9937 Vmessage_log_max
= old_log_max
;
9943 /* Display the current message in the current mini-buffer. This is
9944 only called from error handlers in process.c, and is not time
9948 update_echo_area (void)
9950 if (!NILP (echo_area_buffer
[0]))
9953 string
= Fcurrent_message ();
9959 /* Make sure echo area buffers in `echo_buffers' are live.
9960 If they aren't, make new ones. */
9963 ensure_echo_area_buffers (void)
9967 for (i
= 0; i
< 2; ++i
)
9968 if (!BUFFERP (echo_buffer
[i
])
9969 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9972 Lisp_Object old_buffer
;
9975 old_buffer
= echo_buffer
[i
];
9976 echo_buffer
[i
] = Fget_buffer_create
9977 (make_formatted_string (name
, " *Echo Area %d*", i
));
9978 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9979 /* to force word wrap in echo area -
9980 it was decided to postpone this*/
9981 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9983 for (j
= 0; j
< 2; ++j
)
9984 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9985 echo_area_buffer
[j
] = echo_buffer
[i
];
9990 /* Call FN with args A1..A2 with either the current or last displayed
9991 echo_area_buffer as current buffer.
9993 WHICH zero means use the current message buffer
9994 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9995 from echo_buffer[] and clear it.
9997 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9998 suitable buffer from echo_buffer[] and clear it.
10000 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10001 that the current message becomes the last displayed one, make
10002 choose a suitable buffer for echo_area_buffer[0], and clear it.
10004 Value is what FN returns. */
10007 with_echo_area_buffer (struct window
*w
, int which
,
10008 int (*fn
) (ptrdiff_t, Lisp_Object
),
10009 ptrdiff_t a1
, Lisp_Object a2
)
10011 Lisp_Object buffer
;
10012 int this_one
, the_other
, clear_buffer_p
, rc
;
10013 ptrdiff_t count
= SPECPDL_INDEX ();
10015 /* If buffers aren't live, make new ones. */
10016 ensure_echo_area_buffers ();
10018 clear_buffer_p
= 0;
10021 this_one
= 0, the_other
= 1;
10022 else if (which
> 0)
10023 this_one
= 1, the_other
= 0;
10026 this_one
= 0, the_other
= 1;
10027 clear_buffer_p
= 1;
10029 /* We need a fresh one in case the current echo buffer equals
10030 the one containing the last displayed echo area message. */
10031 if (!NILP (echo_area_buffer
[this_one
])
10032 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10033 echo_area_buffer
[this_one
] = Qnil
;
10036 /* Choose a suitable buffer from echo_buffer[] is we don't
10038 if (NILP (echo_area_buffer
[this_one
]))
10040 echo_area_buffer
[this_one
]
10041 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10042 ? echo_buffer
[the_other
]
10043 : echo_buffer
[this_one
]);
10044 clear_buffer_p
= 1;
10047 buffer
= echo_area_buffer
[this_one
];
10049 /* Don't get confused by reusing the buffer used for echoing
10050 for a different purpose. */
10051 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10054 record_unwind_protect (unwind_with_echo_area_buffer
,
10055 with_echo_area_buffer_unwind_data (w
));
10057 /* Make the echo area buffer current. Note that for display
10058 purposes, it is not necessary that the displayed window's buffer
10059 == current_buffer, except for text property lookup. So, let's
10060 only set that buffer temporarily here without doing a full
10061 Fset_window_buffer. We must also change w->pointm, though,
10062 because otherwise an assertions in unshow_buffer fails, and Emacs
10064 set_buffer_internal_1 (XBUFFER (buffer
));
10067 wset_buffer (w
, buffer
);
10068 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10071 bset_undo_list (current_buffer
, Qt
);
10072 bset_read_only (current_buffer
, Qnil
);
10073 specbind (Qinhibit_read_only
, Qt
);
10074 specbind (Qinhibit_modification_hooks
, Qt
);
10076 if (clear_buffer_p
&& Z
> BEG
)
10077 del_range (BEG
, Z
);
10079 eassert (BEGV
>= BEG
);
10080 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10084 eassert (BEGV
>= BEG
);
10085 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10087 unbind_to (count
, Qnil
);
10092 /* Save state that should be preserved around the call to the function
10093 FN called in with_echo_area_buffer. */
10096 with_echo_area_buffer_unwind_data (struct window
*w
)
10099 Lisp_Object vector
, tmp
;
10101 /* Reduce consing by keeping one vector in
10102 Vwith_echo_area_save_vector. */
10103 vector
= Vwith_echo_area_save_vector
;
10104 Vwith_echo_area_save_vector
= Qnil
;
10107 vector
= Fmake_vector (make_number (9), Qnil
);
10109 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10110 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10111 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10115 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10116 ASET (vector
, i
, w
->contents
); ++i
;
10117 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10118 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10119 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10120 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10125 for (; i
< end
; ++i
)
10126 ASET (vector
, i
, Qnil
);
10129 eassert (i
== ASIZE (vector
));
10134 /* Restore global state from VECTOR which was created by
10135 with_echo_area_buffer_unwind_data. */
10138 unwind_with_echo_area_buffer (Lisp_Object vector
)
10140 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10141 Vdeactivate_mark
= AREF (vector
, 1);
10142 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10144 if (WINDOWP (AREF (vector
, 3)))
10147 Lisp_Object buffer
;
10149 w
= XWINDOW (AREF (vector
, 3));
10150 buffer
= AREF (vector
, 4);
10152 wset_buffer (w
, buffer
);
10153 set_marker_both (w
->pointm
, buffer
,
10154 XFASTINT (AREF (vector
, 5)),
10155 XFASTINT (AREF (vector
, 6)));
10156 set_marker_both (w
->start
, buffer
,
10157 XFASTINT (AREF (vector
, 7)),
10158 XFASTINT (AREF (vector
, 8)));
10161 Vwith_echo_area_save_vector
= vector
;
10165 /* Set up the echo area for use by print functions. MULTIBYTE_P
10166 non-zero means we will print multibyte. */
10169 setup_echo_area_for_printing (int multibyte_p
)
10171 /* If we can't find an echo area any more, exit. */
10172 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10173 Fkill_emacs (Qnil
);
10175 ensure_echo_area_buffers ();
10177 if (!message_buf_print
)
10179 /* A message has been output since the last time we printed.
10180 Choose a fresh echo area buffer. */
10181 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10182 echo_area_buffer
[0] = echo_buffer
[1];
10184 echo_area_buffer
[0] = echo_buffer
[0];
10186 /* Switch to that buffer and clear it. */
10187 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10188 bset_truncate_lines (current_buffer
, Qnil
);
10192 ptrdiff_t count
= SPECPDL_INDEX ();
10193 specbind (Qinhibit_read_only
, Qt
);
10194 /* Note that undo recording is always disabled. */
10195 del_range (BEG
, Z
);
10196 unbind_to (count
, Qnil
);
10198 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10200 /* Set up the buffer for the multibyteness we need. */
10202 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10203 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10205 /* Raise the frame containing the echo area. */
10206 if (minibuffer_auto_raise
)
10208 struct frame
*sf
= SELECTED_FRAME ();
10209 Lisp_Object mini_window
;
10210 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10211 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10214 message_log_maybe_newline ();
10215 message_buf_print
= 1;
10219 if (NILP (echo_area_buffer
[0]))
10221 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10222 echo_area_buffer
[0] = echo_buffer
[1];
10224 echo_area_buffer
[0] = echo_buffer
[0];
10227 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10229 /* Someone switched buffers between print requests. */
10230 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10231 bset_truncate_lines (current_buffer
, Qnil
);
10237 /* Display an echo area message in window W. Value is non-zero if W's
10238 height is changed. If display_last_displayed_message_p is
10239 non-zero, display the message that was last displayed, otherwise
10240 display the current message. */
10243 display_echo_area (struct window
*w
)
10245 int i
, no_message_p
, window_height_changed_p
;
10247 /* Temporarily disable garbage collections while displaying the echo
10248 area. This is done because a GC can print a message itself.
10249 That message would modify the echo area buffer's contents while a
10250 redisplay of the buffer is going on, and seriously confuse
10252 ptrdiff_t count
= inhibit_garbage_collection ();
10254 /* If there is no message, we must call display_echo_area_1
10255 nevertheless because it resizes the window. But we will have to
10256 reset the echo_area_buffer in question to nil at the end because
10257 with_echo_area_buffer will sets it to an empty buffer. */
10258 i
= display_last_displayed_message_p
? 1 : 0;
10259 no_message_p
= NILP (echo_area_buffer
[i
]);
10261 window_height_changed_p
10262 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10263 display_echo_area_1
,
10264 (intptr_t) w
, Qnil
);
10267 echo_area_buffer
[i
] = Qnil
;
10269 unbind_to (count
, Qnil
);
10270 return window_height_changed_p
;
10274 /* Helper for display_echo_area. Display the current buffer which
10275 contains the current echo area message in window W, a mini-window,
10276 a pointer to which is passed in A1. A2..A4 are currently not used.
10277 Change the height of W so that all of the message is displayed.
10278 Value is non-zero if height of W was changed. */
10281 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10284 struct window
*w
= (struct window
*) i1
;
10285 Lisp_Object window
;
10286 struct text_pos start
;
10287 int window_height_changed_p
= 0;
10289 /* Do this before displaying, so that we have a large enough glyph
10290 matrix for the display. If we can't get enough space for the
10291 whole text, display the last N lines. That works by setting w->start. */
10292 window_height_changed_p
= resize_mini_window (w
, 0);
10294 /* Use the starting position chosen by resize_mini_window. */
10295 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10298 clear_glyph_matrix (w
->desired_matrix
);
10299 XSETWINDOW (window
, w
);
10300 try_window (window
, start
, 0);
10302 return window_height_changed_p
;
10306 /* Resize the echo area window to exactly the size needed for the
10307 currently displayed message, if there is one. If a mini-buffer
10308 is active, don't shrink it. */
10311 resize_echo_area_exactly (void)
10313 if (BUFFERP (echo_area_buffer
[0])
10314 && WINDOWP (echo_area_window
))
10316 struct window
*w
= XWINDOW (echo_area_window
);
10318 Lisp_Object resize_exactly
;
10320 if (minibuf_level
== 0)
10321 resize_exactly
= Qt
;
10323 resize_exactly
= Qnil
;
10325 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10326 (intptr_t) w
, resize_exactly
);
10329 ++windows_or_buffers_changed
;
10330 ++update_mode_lines
;
10331 redisplay_internal ();
10337 /* Callback function for with_echo_area_buffer, when used from
10338 resize_echo_area_exactly. A1 contains a pointer to the window to
10339 resize, EXACTLY non-nil means resize the mini-window exactly to the
10340 size of the text displayed. A3 and A4 are not used. Value is what
10341 resize_mini_window returns. */
10344 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10347 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10351 /* Resize mini-window W to fit the size of its contents. EXACT_P
10352 means size the window exactly to the size needed. Otherwise, it's
10353 only enlarged until W's buffer is empty.
10355 Set W->start to the right place to begin display. If the whole
10356 contents fit, start at the beginning. Otherwise, start so as
10357 to make the end of the contents appear. This is particularly
10358 important for y-or-n-p, but seems desirable generally.
10360 Value is non-zero if the window height has been changed. */
10363 resize_mini_window (struct window
*w
, int exact_p
)
10365 struct frame
*f
= XFRAME (w
->frame
);
10366 int window_height_changed_p
= 0;
10368 eassert (MINI_WINDOW_P (w
));
10370 /* By default, start display at the beginning. */
10371 set_marker_both (w
->start
, w
->contents
,
10372 BUF_BEGV (XBUFFER (w
->contents
)),
10373 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10375 /* Don't resize windows while redisplaying a window; it would
10376 confuse redisplay functions when the size of the window they are
10377 displaying changes from under them. Such a resizing can happen,
10378 for instance, when which-func prints a long message while
10379 we are running fontification-functions. We're running these
10380 functions with safe_call which binds inhibit-redisplay to t. */
10381 if (!NILP (Vinhibit_redisplay
))
10384 /* Nil means don't try to resize. */
10385 if (NILP (Vresize_mini_windows
)
10386 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10389 if (!FRAME_MINIBUF_ONLY_P (f
))
10392 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10393 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10395 EMACS_INT max_height
;
10396 int unit
= FRAME_LINE_HEIGHT (f
);
10397 struct text_pos start
;
10398 struct buffer
*old_current_buffer
= NULL
;
10400 if (current_buffer
!= XBUFFER (w
->contents
))
10402 old_current_buffer
= current_buffer
;
10403 set_buffer_internal (XBUFFER (w
->contents
));
10406 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10408 /* Compute the max. number of lines specified by the user. */
10409 if (FLOATP (Vmax_mini_window_height
))
10410 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10411 else if (INTEGERP (Vmax_mini_window_height
))
10412 max_height
= XINT (Vmax_mini_window_height
);
10414 max_height
= total_height
/ 4;
10416 /* Correct that max. height if it's bogus. */
10417 max_height
= clip_to_bounds (1, max_height
, total_height
);
10419 /* Find out the height of the text in the window. */
10420 if (it
.line_wrap
== TRUNCATE
)
10425 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10426 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10427 height
= it
.current_y
+ last_height
;
10429 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10430 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10431 height
= (height
+ unit
- 1) / unit
;
10434 /* Compute a suitable window start. */
10435 if (height
> max_height
)
10437 height
= max_height
;
10438 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10439 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10440 start
= it
.current
.pos
;
10443 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10444 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10446 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10448 /* Let it grow only, until we display an empty message, in which
10449 case the window shrinks again. */
10450 if (height
> WINDOW_TOTAL_LINES (w
))
10452 int old_height
= WINDOW_TOTAL_LINES (w
);
10454 FRAME_WINDOWS_FROZEN (f
) = 1;
10455 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10456 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10458 else if (height
< WINDOW_TOTAL_LINES (w
)
10459 && (exact_p
|| BEGV
== ZV
))
10461 int old_height
= WINDOW_TOTAL_LINES (w
);
10463 FRAME_WINDOWS_FROZEN (f
) = 0;
10464 shrink_mini_window (w
);
10465 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10470 /* Always resize to exact size needed. */
10471 if (height
> WINDOW_TOTAL_LINES (w
))
10473 int old_height
= WINDOW_TOTAL_LINES (w
);
10475 FRAME_WINDOWS_FROZEN (f
) = 1;
10476 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10477 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10479 else if (height
< WINDOW_TOTAL_LINES (w
))
10481 int old_height
= WINDOW_TOTAL_LINES (w
);
10483 FRAME_WINDOWS_FROZEN (f
) = 0;
10484 shrink_mini_window (w
);
10488 FRAME_WINDOWS_FROZEN (f
) = 1;
10489 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10492 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10496 if (old_current_buffer
)
10497 set_buffer_internal (old_current_buffer
);
10500 return window_height_changed_p
;
10504 /* Value is the current message, a string, or nil if there is no
10505 current message. */
10508 current_message (void)
10512 if (!BUFFERP (echo_area_buffer
[0]))
10516 with_echo_area_buffer (0, 0, current_message_1
,
10517 (intptr_t) &msg
, Qnil
);
10519 echo_area_buffer
[0] = Qnil
;
10527 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10530 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10533 *msg
= make_buffer_string (BEG
, Z
, 1);
10540 /* Push the current message on Vmessage_stack for later restoration
10541 by restore_message. Value is non-zero if the current message isn't
10542 empty. This is a relatively infrequent operation, so it's not
10543 worth optimizing. */
10546 push_message (void)
10548 Lisp_Object msg
= current_message ();
10549 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10550 return STRINGP (msg
);
10554 /* Restore message display from the top of Vmessage_stack. */
10557 restore_message (void)
10559 eassert (CONSP (Vmessage_stack
));
10560 message3_nolog (XCAR (Vmessage_stack
));
10564 /* Handler for unwind-protect calling pop_message. */
10567 pop_message_unwind (void)
10569 /* Pop the top-most entry off Vmessage_stack. */
10570 eassert (CONSP (Vmessage_stack
));
10571 Vmessage_stack
= XCDR (Vmessage_stack
);
10575 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10576 exits. If the stack is not empty, we have a missing pop_message
10580 check_message_stack (void)
10582 if (!NILP (Vmessage_stack
))
10587 /* Truncate to NCHARS what will be displayed in the echo area the next
10588 time we display it---but don't redisplay it now. */
10591 truncate_echo_area (ptrdiff_t nchars
)
10594 echo_area_buffer
[0] = Qnil
;
10595 else if (!noninteractive
10597 && !NILP (echo_area_buffer
[0]))
10599 struct frame
*sf
= SELECTED_FRAME ();
10600 /* Error messages get reported properly by cmd_error, so this must be
10601 just an informative message; if the frame hasn't really been
10602 initialized yet, just toss it. */
10603 if (sf
->glyphs_initialized_p
)
10604 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10609 /* Helper function for truncate_echo_area. Truncate the current
10610 message to at most NCHARS characters. */
10613 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10615 if (BEG
+ nchars
< Z
)
10616 del_range (BEG
+ nchars
, Z
);
10618 echo_area_buffer
[0] = Qnil
;
10622 /* Set the current message to STRING. */
10625 set_message (Lisp_Object string
)
10627 eassert (STRINGP (string
));
10629 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10631 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10632 message_buf_print
= 0;
10633 help_echo_showing_p
= 0;
10635 if (STRINGP (Vdebug_on_message
)
10636 && STRINGP (string
)
10637 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10638 call_debugger (list2 (Qerror
, string
));
10642 /* Helper function for set_message. First argument is ignored and second
10643 argument has the same meaning as for set_message.
10644 This function is called with the echo area buffer being current. */
10647 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10649 eassert (STRINGP (string
));
10651 /* Change multibyteness of the echo buffer appropriately. */
10652 if (message_enable_multibyte
10653 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10654 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10656 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10657 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10658 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10660 /* Insert new message at BEG. */
10661 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10663 /* This function takes care of single/multibyte conversion.
10664 We just have to ensure that the echo area buffer has the right
10665 setting of enable_multibyte_characters. */
10666 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10672 /* Clear messages. CURRENT_P non-zero means clear the current
10673 message. LAST_DISPLAYED_P non-zero means clear the message
10677 clear_message (int current_p
, int last_displayed_p
)
10681 echo_area_buffer
[0] = Qnil
;
10682 message_cleared_p
= 1;
10685 if (last_displayed_p
)
10686 echo_area_buffer
[1] = Qnil
;
10688 message_buf_print
= 0;
10691 /* Clear garbaged frames.
10693 This function is used where the old redisplay called
10694 redraw_garbaged_frames which in turn called redraw_frame which in
10695 turn called clear_frame. The call to clear_frame was a source of
10696 flickering. I believe a clear_frame is not necessary. It should
10697 suffice in the new redisplay to invalidate all current matrices,
10698 and ensure a complete redisplay of all windows. */
10701 clear_garbaged_frames (void)
10703 if (frame_garbaged
)
10705 Lisp_Object tail
, frame
;
10706 int changed_count
= 0;
10708 FOR_EACH_FRAME (tail
, frame
)
10710 struct frame
*f
= XFRAME (frame
);
10712 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10717 clear_current_matrices (f
);
10724 frame_garbaged
= 0;
10726 ++windows_or_buffers_changed
;
10731 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10732 is non-zero update selected_frame. Value is non-zero if the
10733 mini-windows height has been changed. */
10736 echo_area_display (int update_frame_p
)
10738 Lisp_Object mini_window
;
10741 int window_height_changed_p
= 0;
10742 struct frame
*sf
= SELECTED_FRAME ();
10744 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10745 w
= XWINDOW (mini_window
);
10746 f
= XFRAME (WINDOW_FRAME (w
));
10748 /* Don't display if frame is invisible or not yet initialized. */
10749 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10752 #ifdef HAVE_WINDOW_SYSTEM
10753 /* When Emacs starts, selected_frame may be the initial terminal
10754 frame. If we let this through, a message would be displayed on
10756 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10758 #endif /* HAVE_WINDOW_SYSTEM */
10760 /* Redraw garbaged frames. */
10761 clear_garbaged_frames ();
10763 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10765 echo_area_window
= mini_window
;
10766 window_height_changed_p
= display_echo_area (w
);
10767 w
->must_be_updated_p
= 1;
10769 /* Update the display, unless called from redisplay_internal.
10770 Also don't update the screen during redisplay itself. The
10771 update will happen at the end of redisplay, and an update
10772 here could cause confusion. */
10773 if (update_frame_p
&& !redisplaying_p
)
10777 /* If the display update has been interrupted by pending
10778 input, update mode lines in the frame. Due to the
10779 pending input, it might have been that redisplay hasn't
10780 been called, so that mode lines above the echo area are
10781 garbaged. This looks odd, so we prevent it here. */
10782 if (!display_completed
)
10783 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10785 if (window_height_changed_p
10786 /* Don't do this if Emacs is shutting down. Redisplay
10787 needs to run hooks. */
10788 && !NILP (Vrun_hooks
))
10790 /* Must update other windows. Likewise as in other
10791 cases, don't let this update be interrupted by
10793 ptrdiff_t count
= SPECPDL_INDEX ();
10794 specbind (Qredisplay_dont_pause
, Qt
);
10795 windows_or_buffers_changed
= 1;
10796 redisplay_internal ();
10797 unbind_to (count
, Qnil
);
10799 else if (FRAME_WINDOW_P (f
) && n
== 0)
10801 /* Window configuration is the same as before.
10802 Can do with a display update of the echo area,
10803 unless we displayed some mode lines. */
10804 update_single_window (w
, 1);
10808 update_frame (f
, 1, 1);
10810 /* If cursor is in the echo area, make sure that the next
10811 redisplay displays the minibuffer, so that the cursor will
10812 be replaced with what the minibuffer wants. */
10813 if (cursor_in_echo_area
)
10814 ++windows_or_buffers_changed
;
10817 else if (!EQ (mini_window
, selected_window
))
10818 windows_or_buffers_changed
++;
10820 /* Last displayed message is now the current message. */
10821 echo_area_buffer
[1] = echo_area_buffer
[0];
10822 /* Inform read_char that we're not echoing. */
10823 echo_message_buffer
= Qnil
;
10825 /* Prevent redisplay optimization in redisplay_internal by resetting
10826 this_line_start_pos. This is done because the mini-buffer now
10827 displays the message instead of its buffer text. */
10828 if (EQ (mini_window
, selected_window
))
10829 CHARPOS (this_line_start_pos
) = 0;
10831 return window_height_changed_p
;
10834 /* Nonzero if the current window's buffer is shown in more than one
10835 window and was modified since last redisplay. */
10838 buffer_shared_and_changed (void)
10840 return (buffer_window_count (current_buffer
) > 1
10841 && UNCHANGED_MODIFIED
< MODIFF
);
10844 /* Nonzero if W's buffer was changed but not saved. */
10847 window_buffer_changed (struct window
*w
)
10849 struct buffer
*b
= XBUFFER (w
->contents
);
10851 eassert (BUFFER_LIVE_P (b
));
10853 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
10856 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10859 mode_line_update_needed (struct window
*w
)
10861 return (w
->column_number_displayed
!= -1
10862 && !(PT
== w
->last_point
&& !window_outdated (w
))
10863 && (w
->column_number_displayed
!= current_column ()));
10866 /* Nonzero if window start of W is frozen and may not be changed during
10870 window_frozen_p (struct window
*w
)
10872 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10874 Lisp_Object window
;
10876 XSETWINDOW (window
, w
);
10877 if (MINI_WINDOW_P (w
))
10879 else if (EQ (window
, selected_window
))
10881 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10882 && EQ (window
, Vminibuf_scroll_window
))
10883 /* This special window can't be frozen too. */
10891 /***********************************************************************
10892 Mode Lines and Frame Titles
10893 ***********************************************************************/
10895 /* A buffer for constructing non-propertized mode-line strings and
10896 frame titles in it; allocated from the heap in init_xdisp and
10897 resized as needed in store_mode_line_noprop_char. */
10899 static char *mode_line_noprop_buf
;
10901 /* The buffer's end, and a current output position in it. */
10903 static char *mode_line_noprop_buf_end
;
10904 static char *mode_line_noprop_ptr
;
10906 #define MODE_LINE_NOPROP_LEN(start) \
10907 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10910 MODE_LINE_DISPLAY
= 0,
10914 } mode_line_target
;
10916 /* Alist that caches the results of :propertize.
10917 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10918 static Lisp_Object mode_line_proptrans_alist
;
10920 /* List of strings making up the mode-line. */
10921 static Lisp_Object mode_line_string_list
;
10923 /* Base face property when building propertized mode line string. */
10924 static Lisp_Object mode_line_string_face
;
10925 static Lisp_Object mode_line_string_face_prop
;
10928 /* Unwind data for mode line strings */
10930 static Lisp_Object Vmode_line_unwind_vector
;
10933 format_mode_line_unwind_data (struct frame
*target_frame
,
10934 struct buffer
*obuf
,
10936 int save_proptrans
)
10938 Lisp_Object vector
, tmp
;
10940 /* Reduce consing by keeping one vector in
10941 Vwith_echo_area_save_vector. */
10942 vector
= Vmode_line_unwind_vector
;
10943 Vmode_line_unwind_vector
= Qnil
;
10946 vector
= Fmake_vector (make_number (10), Qnil
);
10948 ASET (vector
, 0, make_number (mode_line_target
));
10949 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10950 ASET (vector
, 2, mode_line_string_list
);
10951 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10952 ASET (vector
, 4, mode_line_string_face
);
10953 ASET (vector
, 5, mode_line_string_face_prop
);
10956 XSETBUFFER (tmp
, obuf
);
10959 ASET (vector
, 6, tmp
);
10960 ASET (vector
, 7, owin
);
10963 /* Similarly to `with-selected-window', if the operation selects
10964 a window on another frame, we must restore that frame's
10965 selected window, and (for a tty) the top-frame. */
10966 ASET (vector
, 8, target_frame
->selected_window
);
10967 if (FRAME_TERMCAP_P (target_frame
))
10968 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10975 unwind_format_mode_line (Lisp_Object vector
)
10977 Lisp_Object old_window
= AREF (vector
, 7);
10978 Lisp_Object target_frame_window
= AREF (vector
, 8);
10979 Lisp_Object old_top_frame
= AREF (vector
, 9);
10981 mode_line_target
= XINT (AREF (vector
, 0));
10982 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10983 mode_line_string_list
= AREF (vector
, 2);
10984 if (! EQ (AREF (vector
, 3), Qt
))
10985 mode_line_proptrans_alist
= AREF (vector
, 3);
10986 mode_line_string_face
= AREF (vector
, 4);
10987 mode_line_string_face_prop
= AREF (vector
, 5);
10989 /* Select window before buffer, since it may change the buffer. */
10990 if (!NILP (old_window
))
10992 /* If the operation that we are unwinding had selected a window
10993 on a different frame, reset its frame-selected-window. For a
10994 text terminal, reset its top-frame if necessary. */
10995 if (!NILP (target_frame_window
))
10998 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11000 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11001 Fselect_window (target_frame_window
, Qt
);
11003 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11004 Fselect_frame (old_top_frame
, Qt
);
11007 Fselect_window (old_window
, Qt
);
11010 if (!NILP (AREF (vector
, 6)))
11012 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11013 ASET (vector
, 6, Qnil
);
11016 Vmode_line_unwind_vector
= vector
;
11020 /* Store a single character C for the frame title in mode_line_noprop_buf.
11021 Re-allocate mode_line_noprop_buf if necessary. */
11024 store_mode_line_noprop_char (char c
)
11026 /* If output position has reached the end of the allocated buffer,
11027 increase the buffer's size. */
11028 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11030 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11031 ptrdiff_t size
= len
;
11032 mode_line_noprop_buf
=
11033 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11034 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11035 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11038 *mode_line_noprop_ptr
++ = c
;
11042 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11043 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11044 characters that yield more columns than PRECISION; PRECISION <= 0
11045 means copy the whole string. Pad with spaces until FIELD_WIDTH
11046 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11047 pad. Called from display_mode_element when it is used to build a
11051 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11053 const unsigned char *str
= (const unsigned char *) string
;
11055 ptrdiff_t dummy
, nbytes
;
11057 /* Copy at most PRECISION chars from STR. */
11058 nbytes
= strlen (string
);
11059 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11061 store_mode_line_noprop_char (*str
++);
11063 /* Fill up with spaces until FIELD_WIDTH reached. */
11064 while (field_width
> 0
11065 && n
< field_width
)
11067 store_mode_line_noprop_char (' ');
11074 /***********************************************************************
11076 ***********************************************************************/
11078 #ifdef HAVE_WINDOW_SYSTEM
11080 /* Set the title of FRAME, if it has changed. The title format is
11081 Vicon_title_format if FRAME is iconified, otherwise it is
11082 frame_title_format. */
11085 x_consider_frame_title (Lisp_Object frame
)
11087 struct frame
*f
= XFRAME (frame
);
11089 if (FRAME_WINDOW_P (f
)
11090 || FRAME_MINIBUF_ONLY_P (f
)
11091 || f
->explicit_name
)
11093 /* Do we have more than one visible frame on this X display? */
11094 Lisp_Object tail
, other_frame
, fmt
;
11095 ptrdiff_t title_start
;
11099 ptrdiff_t count
= SPECPDL_INDEX ();
11101 FOR_EACH_FRAME (tail
, other_frame
)
11103 struct frame
*tf
= XFRAME (other_frame
);
11106 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11107 && !FRAME_MINIBUF_ONLY_P (tf
)
11108 && !EQ (other_frame
, tip_frame
)
11109 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11113 /* Set global variable indicating that multiple frames exist. */
11114 multiple_frames
= CONSP (tail
);
11116 /* Switch to the buffer of selected window of the frame. Set up
11117 mode_line_target so that display_mode_element will output into
11118 mode_line_noprop_buf; then display the title. */
11119 record_unwind_protect (unwind_format_mode_line
,
11120 format_mode_line_unwind_data
11121 (f
, current_buffer
, selected_window
, 0));
11123 Fselect_window (f
->selected_window
, Qt
);
11124 set_buffer_internal_1
11125 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11126 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11128 mode_line_target
= MODE_LINE_TITLE
;
11129 title_start
= MODE_LINE_NOPROP_LEN (0);
11130 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11131 NULL
, DEFAULT_FACE_ID
);
11132 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11133 len
= MODE_LINE_NOPROP_LEN (title_start
);
11134 title
= mode_line_noprop_buf
+ title_start
;
11135 unbind_to (count
, Qnil
);
11137 /* Set the title only if it's changed. This avoids consing in
11138 the common case where it hasn't. (If it turns out that we've
11139 already wasted too much time by walking through the list with
11140 display_mode_element, then we might need to optimize at a
11141 higher level than this.) */
11142 if (! STRINGP (f
->name
)
11143 || SBYTES (f
->name
) != len
11144 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11145 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11149 #endif /* not HAVE_WINDOW_SYSTEM */
11152 /***********************************************************************
11154 ***********************************************************************/
11157 /* Prepare for redisplay by updating menu-bar item lists when
11158 appropriate. This can call eval. */
11161 prepare_menu_bars (void)
11164 struct gcpro gcpro1
, gcpro2
;
11166 Lisp_Object tooltip_frame
;
11168 #ifdef HAVE_WINDOW_SYSTEM
11169 tooltip_frame
= tip_frame
;
11171 tooltip_frame
= Qnil
;
11174 /* Update all frame titles based on their buffer names, etc. We do
11175 this before the menu bars so that the buffer-menu will show the
11176 up-to-date frame titles. */
11177 #ifdef HAVE_WINDOW_SYSTEM
11178 if (windows_or_buffers_changed
|| update_mode_lines
)
11180 Lisp_Object tail
, frame
;
11182 FOR_EACH_FRAME (tail
, frame
)
11184 f
= XFRAME (frame
);
11185 if (!EQ (frame
, tooltip_frame
)
11186 && (FRAME_ICONIFIED_P (f
)
11187 || FRAME_VISIBLE_P (f
) == 1
11188 /* Exclude TTY frames that are obscured because they
11189 are not the top frame on their console. This is
11190 because x_consider_frame_title actually switches
11191 to the frame, which for TTY frames means it is
11192 marked as garbaged, and will be completely
11193 redrawn on the next redisplay cycle. This causes
11194 TTY frames to be completely redrawn, when there
11195 are more than one of them, even though nothing
11196 should be changed on display. */
11197 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11198 x_consider_frame_title (frame
);
11201 #endif /* HAVE_WINDOW_SYSTEM */
11203 /* Update the menu bar item lists, if appropriate. This has to be
11204 done before any actual redisplay or generation of display lines. */
11205 all_windows
= (update_mode_lines
11206 || buffer_shared_and_changed ()
11207 || windows_or_buffers_changed
);
11209 if (FUNCTIONP (Vpre_redisplay_function
))
11210 safe_call1 (Vpre_redisplay_function
, all_windows
? Qt
: Qnil
);
11214 Lisp_Object tail
, frame
;
11215 ptrdiff_t count
= SPECPDL_INDEX ();
11216 /* 1 means that update_menu_bar has run its hooks
11217 so any further calls to update_menu_bar shouldn't do so again. */
11218 int menu_bar_hooks_run
= 0;
11220 record_unwind_save_match_data ();
11222 FOR_EACH_FRAME (tail
, frame
)
11224 f
= XFRAME (frame
);
11226 /* Ignore tooltip frame. */
11227 if (EQ (frame
, tooltip_frame
))
11230 /* If a window on this frame changed size, report that to
11231 the user and clear the size-change flag. */
11232 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11234 Lisp_Object functions
;
11236 /* Clear flag first in case we get an error below. */
11237 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11238 functions
= Vwindow_size_change_functions
;
11239 GCPRO2 (tail
, functions
);
11241 while (CONSP (functions
))
11243 if (!EQ (XCAR (functions
), Qt
))
11244 call1 (XCAR (functions
), frame
);
11245 functions
= XCDR (functions
);
11251 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11252 #ifdef HAVE_WINDOW_SYSTEM
11253 update_tool_bar (f
, 0);
11256 if (windows_or_buffers_changed
11259 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11264 unbind_to (count
, Qnil
);
11268 struct frame
*sf
= SELECTED_FRAME ();
11269 update_menu_bar (sf
, 1, 0);
11270 #ifdef HAVE_WINDOW_SYSTEM
11271 update_tool_bar (sf
, 1);
11277 /* Update the menu bar item list for frame F. This has to be done
11278 before we start to fill in any display lines, because it can call
11281 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11283 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11284 already ran the menu bar hooks for this redisplay, so there
11285 is no need to run them again. The return value is the
11286 updated value of this flag, to pass to the next call. */
11289 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11291 Lisp_Object window
;
11292 register struct window
*w
;
11294 /* If called recursively during a menu update, do nothing. This can
11295 happen when, for instance, an activate-menubar-hook causes a
11297 if (inhibit_menubar_update
)
11300 window
= FRAME_SELECTED_WINDOW (f
);
11301 w
= XWINDOW (window
);
11303 if (FRAME_WINDOW_P (f
)
11305 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11306 || defined (HAVE_NS) || defined (USE_GTK)
11307 FRAME_EXTERNAL_MENU_BAR (f
)
11309 FRAME_MENU_BAR_LINES (f
) > 0
11311 : FRAME_MENU_BAR_LINES (f
) > 0)
11313 /* If the user has switched buffers or windows, we need to
11314 recompute to reflect the new bindings. But we'll
11315 recompute when update_mode_lines is set too; that means
11316 that people can use force-mode-line-update to request
11317 that the menu bar be recomputed. The adverse effect on
11318 the rest of the redisplay algorithm is about the same as
11319 windows_or_buffers_changed anyway. */
11320 if (windows_or_buffers_changed
11321 /* This used to test w->update_mode_line, but we believe
11322 there is no need to recompute the menu in that case. */
11323 || update_mode_lines
11324 || window_buffer_changed (w
))
11326 struct buffer
*prev
= current_buffer
;
11327 ptrdiff_t count
= SPECPDL_INDEX ();
11329 specbind (Qinhibit_menubar_update
, Qt
);
11331 set_buffer_internal_1 (XBUFFER (w
->contents
));
11332 if (save_match_data
)
11333 record_unwind_save_match_data ();
11334 if (NILP (Voverriding_local_map_menu_flag
))
11336 specbind (Qoverriding_terminal_local_map
, Qnil
);
11337 specbind (Qoverriding_local_map
, Qnil
);
11342 /* Run the Lucid hook. */
11343 safe_run_hooks (Qactivate_menubar_hook
);
11345 /* If it has changed current-menubar from previous value,
11346 really recompute the menu-bar from the value. */
11347 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11348 call0 (Qrecompute_lucid_menubar
);
11350 safe_run_hooks (Qmenu_bar_update_hook
);
11355 XSETFRAME (Vmenu_updating_frame
, f
);
11356 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11358 /* Redisplay the menu bar in case we changed it. */
11359 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11360 || defined (HAVE_NS) || defined (USE_GTK)
11361 if (FRAME_WINDOW_P (f
))
11363 #if defined (HAVE_NS)
11364 /* All frames on Mac OS share the same menubar. So only
11365 the selected frame should be allowed to set it. */
11366 if (f
== SELECTED_FRAME ())
11368 set_frame_menubar (f
, 0, 0);
11371 /* On a terminal screen, the menu bar is an ordinary screen
11372 line, and this makes it get updated. */
11373 w
->update_mode_line
= 1;
11374 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11375 /* In the non-toolkit version, the menu bar is an ordinary screen
11376 line, and this makes it get updated. */
11377 w
->update_mode_line
= 1;
11378 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11380 unbind_to (count
, Qnil
);
11381 set_buffer_internal_1 (prev
);
11388 /***********************************************************************
11390 ***********************************************************************/
11392 #ifdef HAVE_WINDOW_SYSTEM
11394 /* Tool-bar item index of the item on which a mouse button was pressed
11397 int last_tool_bar_item
;
11399 /* Select `frame' temporarily without running all the code in
11401 FIXME: Maybe do_switch_frame should be trimmed down similarly
11402 when `norecord' is set. */
11404 fast_set_selected_frame (Lisp_Object frame
)
11406 if (!EQ (selected_frame
, frame
))
11408 selected_frame
= frame
;
11409 selected_window
= XFRAME (frame
)->selected_window
;
11413 /* Update the tool-bar item list for frame F. This has to be done
11414 before we start to fill in any display lines. Called from
11415 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11416 and restore it here. */
11419 update_tool_bar (struct frame
*f
, int save_match_data
)
11421 #if defined (USE_GTK) || defined (HAVE_NS)
11422 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11424 int do_update
= WINDOWP (f
->tool_bar_window
)
11425 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11430 Lisp_Object window
;
11433 window
= FRAME_SELECTED_WINDOW (f
);
11434 w
= XWINDOW (window
);
11436 /* If the user has switched buffers or windows, we need to
11437 recompute to reflect the new bindings. But we'll
11438 recompute when update_mode_lines is set too; that means
11439 that people can use force-mode-line-update to request
11440 that the menu bar be recomputed. The adverse effect on
11441 the rest of the redisplay algorithm is about the same as
11442 windows_or_buffers_changed anyway. */
11443 if (windows_or_buffers_changed
11444 || w
->update_mode_line
11445 || update_mode_lines
11446 || window_buffer_changed (w
))
11448 struct buffer
*prev
= current_buffer
;
11449 ptrdiff_t count
= SPECPDL_INDEX ();
11450 Lisp_Object frame
, new_tool_bar
;
11451 int new_n_tool_bar
;
11452 struct gcpro gcpro1
;
11454 /* Set current_buffer to the buffer of the selected
11455 window of the frame, so that we get the right local
11457 set_buffer_internal_1 (XBUFFER (w
->contents
));
11459 /* Save match data, if we must. */
11460 if (save_match_data
)
11461 record_unwind_save_match_data ();
11463 /* Make sure that we don't accidentally use bogus keymaps. */
11464 if (NILP (Voverriding_local_map_menu_flag
))
11466 specbind (Qoverriding_terminal_local_map
, Qnil
);
11467 specbind (Qoverriding_local_map
, Qnil
);
11470 GCPRO1 (new_tool_bar
);
11472 /* We must temporarily set the selected frame to this frame
11473 before calling tool_bar_items, because the calculation of
11474 the tool-bar keymap uses the selected frame (see
11475 `tool-bar-make-keymap' in tool-bar.el). */
11476 eassert (EQ (selected_window
,
11477 /* Since we only explicitly preserve selected_frame,
11478 check that selected_window would be redundant. */
11479 XFRAME (selected_frame
)->selected_window
));
11480 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11481 XSETFRAME (frame
, f
);
11482 fast_set_selected_frame (frame
);
11484 /* Build desired tool-bar items from keymaps. */
11486 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11489 /* Redisplay the tool-bar if we changed it. */
11490 if (new_n_tool_bar
!= f
->n_tool_bar_items
11491 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11493 /* Redisplay that happens asynchronously due to an expose event
11494 may access f->tool_bar_items. Make sure we update both
11495 variables within BLOCK_INPUT so no such event interrupts. */
11497 fset_tool_bar_items (f
, new_tool_bar
);
11498 f
->n_tool_bar_items
= new_n_tool_bar
;
11499 w
->update_mode_line
= 1;
11505 unbind_to (count
, Qnil
);
11506 set_buffer_internal_1 (prev
);
11511 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11513 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11514 F's desired tool-bar contents. F->tool_bar_items must have
11515 been set up previously by calling prepare_menu_bars. */
11518 build_desired_tool_bar_string (struct frame
*f
)
11520 int i
, size
, size_needed
;
11521 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11522 Lisp_Object image
, plist
, props
;
11524 image
= plist
= props
= Qnil
;
11525 GCPRO3 (image
, plist
, props
);
11527 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11528 Otherwise, make a new string. */
11530 /* The size of the string we might be able to reuse. */
11531 size
= (STRINGP (f
->desired_tool_bar_string
)
11532 ? SCHARS (f
->desired_tool_bar_string
)
11535 /* We need one space in the string for each image. */
11536 size_needed
= f
->n_tool_bar_items
;
11538 /* Reuse f->desired_tool_bar_string, if possible. */
11539 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11540 fset_desired_tool_bar_string
11541 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11544 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11545 Fremove_text_properties (make_number (0), make_number (size
),
11546 props
, f
->desired_tool_bar_string
);
11549 /* Put a `display' property on the string for the images to display,
11550 put a `menu_item' property on tool-bar items with a value that
11551 is the index of the item in F's tool-bar item vector. */
11552 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11554 #define PROP(IDX) \
11555 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11557 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11558 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11559 int hmargin
, vmargin
, relief
, idx
, end
;
11561 /* If image is a vector, choose the image according to the
11563 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11564 if (VECTORP (image
))
11568 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11569 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11572 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11573 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11575 eassert (ASIZE (image
) >= idx
);
11576 image
= AREF (image
, idx
);
11581 /* Ignore invalid image specifications. */
11582 if (!valid_image_p (image
))
11585 /* Display the tool-bar button pressed, or depressed. */
11586 plist
= Fcopy_sequence (XCDR (image
));
11588 /* Compute margin and relief to draw. */
11589 relief
= (tool_bar_button_relief
>= 0
11590 ? tool_bar_button_relief
11591 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11592 hmargin
= vmargin
= relief
;
11594 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11595 INT_MAX
- max (hmargin
, vmargin
)))
11597 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11598 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11600 else if (CONSP (Vtool_bar_button_margin
))
11602 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11603 INT_MAX
- hmargin
))
11604 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11606 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11607 INT_MAX
- vmargin
))
11608 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11611 if (auto_raise_tool_bar_buttons_p
)
11613 /* Add a `:relief' property to the image spec if the item is
11617 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11624 /* If image is selected, display it pressed, i.e. with a
11625 negative relief. If it's not selected, display it with a
11627 plist
= Fplist_put (plist
, QCrelief
,
11629 ? make_number (-relief
)
11630 : make_number (relief
)));
11635 /* Put a margin around the image. */
11636 if (hmargin
|| vmargin
)
11638 if (hmargin
== vmargin
)
11639 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11641 plist
= Fplist_put (plist
, QCmargin
,
11642 Fcons (make_number (hmargin
),
11643 make_number (vmargin
)));
11646 /* If button is not enabled, and we don't have special images
11647 for the disabled state, make the image appear disabled by
11648 applying an appropriate algorithm to it. */
11649 if (!enabled_p
&& idx
< 0)
11650 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11652 /* Put a `display' text property on the string for the image to
11653 display. Put a `menu-item' property on the string that gives
11654 the start of this item's properties in the tool-bar items
11656 image
= Fcons (Qimage
, plist
);
11657 props
= list4 (Qdisplay
, image
,
11658 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11660 /* Let the last image hide all remaining spaces in the tool bar
11661 string. The string can be longer than needed when we reuse a
11662 previous string. */
11663 if (i
+ 1 == f
->n_tool_bar_items
)
11664 end
= SCHARS (f
->desired_tool_bar_string
);
11667 Fadd_text_properties (make_number (i
), make_number (end
),
11668 props
, f
->desired_tool_bar_string
);
11676 /* Display one line of the tool-bar of frame IT->f.
11678 HEIGHT specifies the desired height of the tool-bar line.
11679 If the actual height of the glyph row is less than HEIGHT, the
11680 row's height is increased to HEIGHT, and the icons are centered
11681 vertically in the new height.
11683 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11684 count a final empty row in case the tool-bar width exactly matches
11689 display_tool_bar_line (struct it
*it
, int height
)
11691 struct glyph_row
*row
= it
->glyph_row
;
11692 int max_x
= it
->last_visible_x
;
11693 struct glyph
*last
;
11695 prepare_desired_row (row
);
11696 row
->y
= it
->current_y
;
11698 /* Note that this isn't made use of if the face hasn't a box,
11699 so there's no need to check the face here. */
11700 it
->start_of_box_run_p
= 1;
11702 while (it
->current_x
< max_x
)
11704 int x
, n_glyphs_before
, i
, nglyphs
;
11705 struct it it_before
;
11707 /* Get the next display element. */
11708 if (!get_next_display_element (it
))
11710 /* Don't count empty row if we are counting needed tool-bar lines. */
11711 if (height
< 0 && !it
->hpos
)
11716 /* Produce glyphs. */
11717 n_glyphs_before
= row
->used
[TEXT_AREA
];
11720 PRODUCE_GLYPHS (it
);
11722 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11724 x
= it_before
.current_x
;
11725 while (i
< nglyphs
)
11727 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11729 if (x
+ glyph
->pixel_width
> max_x
)
11731 /* Glyph doesn't fit on line. Backtrack. */
11732 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11734 /* If this is the only glyph on this line, it will never fit on the
11735 tool-bar, so skip it. But ensure there is at least one glyph,
11736 so we don't accidentally disable the tool-bar. */
11737 if (n_glyphs_before
== 0
11738 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11744 x
+= glyph
->pixel_width
;
11748 /* Stop at line end. */
11749 if (ITERATOR_AT_END_OF_LINE_P (it
))
11752 set_iterator_to_next (it
, 1);
11757 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11759 /* Use default face for the border below the tool bar.
11761 FIXME: When auto-resize-tool-bars is grow-only, there is
11762 no additional border below the possibly empty tool-bar lines.
11763 So to make the extra empty lines look "normal", we have to
11764 use the tool-bar face for the border too. */
11765 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11766 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11767 it
->face_id
= DEFAULT_FACE_ID
;
11769 extend_face_to_end_of_line (it
);
11770 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11771 last
->right_box_line_p
= 1;
11772 if (last
== row
->glyphs
[TEXT_AREA
])
11773 last
->left_box_line_p
= 1;
11775 /* Make line the desired height and center it vertically. */
11776 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11778 /* Don't add more than one line height. */
11779 height
%= FRAME_LINE_HEIGHT (it
->f
);
11780 it
->max_ascent
+= height
/ 2;
11781 it
->max_descent
+= (height
+ 1) / 2;
11784 compute_line_metrics (it
);
11786 /* If line is empty, make it occupy the rest of the tool-bar. */
11787 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11789 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11790 row
->visible_height
= row
->height
;
11791 row
->ascent
= row
->phys_ascent
= 0;
11792 row
->extra_line_spacing
= 0;
11795 row
->full_width_p
= 1;
11796 row
->continued_p
= 0;
11797 row
->truncated_on_left_p
= 0;
11798 row
->truncated_on_right_p
= 0;
11800 it
->current_x
= it
->hpos
= 0;
11801 it
->current_y
+= row
->height
;
11807 /* Max tool-bar height. */
11809 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11810 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11812 /* Value is the number of screen lines needed to make all tool-bar
11813 items of frame F visible. The number of actual rows needed is
11814 returned in *N_ROWS if non-NULL. */
11817 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11819 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11821 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11822 the desired matrix, so use (unused) mode-line row as temporary row to
11823 avoid destroying the first tool-bar row. */
11824 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11826 /* Initialize an iterator for iteration over
11827 F->desired_tool_bar_string in the tool-bar window of frame F. */
11828 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11829 it
.first_visible_x
= 0;
11830 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11831 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11832 it
.paragraph_embedding
= L2R
;
11834 while (!ITERATOR_AT_END_P (&it
))
11836 clear_glyph_row (temp_row
);
11837 it
.glyph_row
= temp_row
;
11838 display_tool_bar_line (&it
, -1);
11840 clear_glyph_row (temp_row
);
11842 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11844 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11846 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11849 #endif /* !USE_GTK && !HAVE_NS */
11851 #if defined USE_GTK || defined HAVE_NS
11852 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
11855 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11857 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11858 If FRAME is nil or omitted, use the selected frame. */)
11859 (Lisp_Object frame
)
11862 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11863 struct frame
*f
= decode_any_frame (frame
);
11866 if (WINDOWP (f
->tool_bar_window
)
11867 && (w
= XWINDOW (f
->tool_bar_window
),
11868 WINDOW_TOTAL_LINES (w
) > 0))
11870 update_tool_bar (f
, 1);
11871 if (f
->n_tool_bar_items
)
11873 build_desired_tool_bar_string (f
);
11874 nlines
= tool_bar_lines_needed (f
, NULL
);
11878 return make_number (nlines
);
11882 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11883 height should be changed. */
11886 redisplay_tool_bar (struct frame
*f
)
11888 #if defined (USE_GTK) || defined (HAVE_NS)
11890 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11891 update_frame_tool_bar (f
);
11894 #else /* !USE_GTK && !HAVE_NS */
11898 struct glyph_row
*row
;
11900 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11901 do anything. This means you must start with tool-bar-lines
11902 non-zero to get the auto-sizing effect. Or in other words, you
11903 can turn off tool-bars by specifying tool-bar-lines zero. */
11904 if (!WINDOWP (f
->tool_bar_window
)
11905 || (w
= XWINDOW (f
->tool_bar_window
),
11906 WINDOW_TOTAL_LINES (w
) == 0))
11909 /* Set up an iterator for the tool-bar window. */
11910 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11911 it
.first_visible_x
= 0;
11912 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11913 row
= it
.glyph_row
;
11915 /* Build a string that represents the contents of the tool-bar. */
11916 build_desired_tool_bar_string (f
);
11917 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11918 /* FIXME: This should be controlled by a user option. But it
11919 doesn't make sense to have an R2L tool bar if the menu bar cannot
11920 be drawn also R2L, and making the menu bar R2L is tricky due
11921 toolkit-specific code that implements it. If an R2L tool bar is
11922 ever supported, display_tool_bar_line should also be augmented to
11923 call unproduce_glyphs like display_line and display_string
11925 it
.paragraph_embedding
= L2R
;
11927 if (f
->n_tool_bar_rows
== 0)
11931 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11932 nlines
!= WINDOW_TOTAL_LINES (w
)))
11935 int old_height
= WINDOW_TOTAL_LINES (w
);
11937 XSETFRAME (frame
, f
);
11938 Fmodify_frame_parameters (frame
,
11939 list1 (Fcons (Qtool_bar_lines
,
11940 make_number (nlines
))));
11941 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11943 clear_glyph_matrix (w
->desired_matrix
);
11944 f
->fonts_changed
= 1;
11950 /* Display as many lines as needed to display all tool-bar items. */
11952 if (f
->n_tool_bar_rows
> 0)
11954 int border
, rows
, height
, extra
;
11956 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11957 border
= XINT (Vtool_bar_border
);
11958 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11959 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11960 else if (EQ (Vtool_bar_border
, Qborder_width
))
11961 border
= f
->border_width
;
11967 rows
= f
->n_tool_bar_rows
;
11968 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11969 extra
= it
.last_visible_y
- border
- height
* rows
;
11971 while (it
.current_y
< it
.last_visible_y
)
11974 if (extra
> 0 && rows
-- > 0)
11976 h
= (extra
+ rows
- 1) / rows
;
11979 display_tool_bar_line (&it
, height
+ h
);
11984 while (it
.current_y
< it
.last_visible_y
)
11985 display_tool_bar_line (&it
, 0);
11988 /* It doesn't make much sense to try scrolling in the tool-bar
11989 window, so don't do it. */
11990 w
->desired_matrix
->no_scrolling_p
= 1;
11991 w
->must_be_updated_p
= 1;
11993 if (!NILP (Vauto_resize_tool_bars
))
11995 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11996 int change_height_p
= 0;
11998 /* If we couldn't display everything, change the tool-bar's
11999 height if there is room for more. */
12000 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12001 && it
.current_y
< max_tool_bar_height
)
12002 change_height_p
= 1;
12004 row
= it
.glyph_row
- 1;
12006 /* If there are blank lines at the end, except for a partially
12007 visible blank line at the end that is smaller than
12008 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12009 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12010 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12011 change_height_p
= 1;
12013 /* If row displays tool-bar items, but is partially visible,
12014 change the tool-bar's height. */
12015 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12016 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12017 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12018 change_height_p
= 1;
12020 /* Resize windows as needed by changing the `tool-bar-lines'
12021 frame parameter. */
12022 if (change_height_p
)
12025 int old_height
= WINDOW_TOTAL_LINES (w
);
12027 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12029 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12030 && !f
->minimize_tool_bar_window_p
)
12031 ? (nlines
> old_height
)
12032 : (nlines
!= old_height
));
12033 f
->minimize_tool_bar_window_p
= 0;
12035 if (change_height_p
)
12037 XSETFRAME (frame
, f
);
12038 Fmodify_frame_parameters (frame
,
12039 list1 (Fcons (Qtool_bar_lines
,
12040 make_number (nlines
))));
12041 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12043 clear_glyph_matrix (w
->desired_matrix
);
12044 f
->n_tool_bar_rows
= nrows
;
12045 f
->fonts_changed
= 1;
12052 f
->minimize_tool_bar_window_p
= 0;
12055 #endif /* USE_GTK || HAVE_NS */
12058 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12060 /* Get information about the tool-bar item which is displayed in GLYPH
12061 on frame F. Return in *PROP_IDX the index where tool-bar item
12062 properties start in F->tool_bar_items. Value is zero if
12063 GLYPH doesn't display a tool-bar item. */
12066 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12072 /* This function can be called asynchronously, which means we must
12073 exclude any possibility that Fget_text_property signals an
12075 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12076 charpos
= max (0, charpos
);
12078 /* Get the text property `menu-item' at pos. The value of that
12079 property is the start index of this item's properties in
12080 F->tool_bar_items. */
12081 prop
= Fget_text_property (make_number (charpos
),
12082 Qmenu_item
, f
->current_tool_bar_string
);
12083 if (INTEGERP (prop
))
12085 *prop_idx
= XINT (prop
);
12095 /* Get information about the tool-bar item at position X/Y on frame F.
12096 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12097 the current matrix of the tool-bar window of F, or NULL if not
12098 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12099 item in F->tool_bar_items. Value is
12101 -1 if X/Y is not on a tool-bar item
12102 0 if X/Y is on the same item that was highlighted before.
12106 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12107 int *hpos
, int *vpos
, int *prop_idx
)
12109 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12110 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12113 /* Find the glyph under X/Y. */
12114 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12115 if (*glyph
== NULL
)
12118 /* Get the start of this tool-bar item's properties in
12119 f->tool_bar_items. */
12120 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12123 /* Is mouse on the highlighted item? */
12124 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12125 && *vpos
>= hlinfo
->mouse_face_beg_row
12126 && *vpos
<= hlinfo
->mouse_face_end_row
12127 && (*vpos
> hlinfo
->mouse_face_beg_row
12128 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12129 && (*vpos
< hlinfo
->mouse_face_end_row
12130 || *hpos
< hlinfo
->mouse_face_end_col
12131 || hlinfo
->mouse_face_past_end
))
12139 Handle mouse button event on the tool-bar of frame F, at
12140 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12141 0 for button release. MODIFIERS is event modifiers for button
12145 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12148 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12149 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12150 int hpos
, vpos
, prop_idx
;
12151 struct glyph
*glyph
;
12152 Lisp_Object enabled_p
;
12155 /* If not on the highlighted tool-bar item, and mouse-highlight is
12156 non-nil, return. This is so we generate the tool-bar button
12157 click only when the mouse button is released on the same item as
12158 where it was pressed. However, when mouse-highlight is disabled,
12159 generate the click when the button is released regardless of the
12160 highlight, since tool-bar items are not highlighted in that
12162 frame_to_window_pixel_xy (w
, &x
, &y
);
12163 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12165 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12168 /* When mouse-highlight is off, generate the click for the item
12169 where the button was pressed, disregarding where it was
12171 if (NILP (Vmouse_highlight
) && !down_p
)
12172 prop_idx
= last_tool_bar_item
;
12174 /* If item is disabled, do nothing. */
12175 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12176 if (NILP (enabled_p
))
12181 /* Show item in pressed state. */
12182 if (!NILP (Vmouse_highlight
))
12183 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12184 last_tool_bar_item
= prop_idx
;
12188 Lisp_Object key
, frame
;
12189 struct input_event event
;
12190 EVENT_INIT (event
);
12192 /* Show item in released state. */
12193 if (!NILP (Vmouse_highlight
))
12194 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12196 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12198 XSETFRAME (frame
, f
);
12199 event
.kind
= TOOL_BAR_EVENT
;
12200 event
.frame_or_window
= frame
;
12202 kbd_buffer_store_event (&event
);
12204 event
.kind
= TOOL_BAR_EVENT
;
12205 event
.frame_or_window
= frame
;
12207 event
.modifiers
= modifiers
;
12208 kbd_buffer_store_event (&event
);
12209 last_tool_bar_item
= -1;
12214 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12215 tool-bar window-relative coordinates X/Y. Called from
12216 note_mouse_highlight. */
12219 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12221 Lisp_Object window
= f
->tool_bar_window
;
12222 struct window
*w
= XWINDOW (window
);
12223 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12224 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12226 struct glyph
*glyph
;
12227 struct glyph_row
*row
;
12229 Lisp_Object enabled_p
;
12231 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12232 int mouse_down_p
, rc
;
12234 /* Function note_mouse_highlight is called with negative X/Y
12235 values when mouse moves outside of the frame. */
12236 if (x
<= 0 || y
<= 0)
12238 clear_mouse_face (hlinfo
);
12242 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12245 /* Not on tool-bar item. */
12246 clear_mouse_face (hlinfo
);
12250 /* On same tool-bar item as before. */
12251 goto set_help_echo
;
12253 clear_mouse_face (hlinfo
);
12255 /* Mouse is down, but on different tool-bar item? */
12256 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12257 && f
== dpyinfo
->last_mouse_frame
);
12260 && last_tool_bar_item
!= prop_idx
)
12263 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12265 /* If tool-bar item is not enabled, don't highlight it. */
12266 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12267 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12269 /* Compute the x-position of the glyph. In front and past the
12270 image is a space. We include this in the highlighted area. */
12271 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12272 for (i
= x
= 0; i
< hpos
; ++i
)
12273 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12275 /* Record this as the current active region. */
12276 hlinfo
->mouse_face_beg_col
= hpos
;
12277 hlinfo
->mouse_face_beg_row
= vpos
;
12278 hlinfo
->mouse_face_beg_x
= x
;
12279 hlinfo
->mouse_face_past_end
= 0;
12281 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12282 hlinfo
->mouse_face_end_row
= vpos
;
12283 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12284 hlinfo
->mouse_face_window
= window
;
12285 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12287 /* Display it as active. */
12288 show_mouse_face (hlinfo
, draw
);
12293 /* Set help_echo_string to a help string to display for this tool-bar item.
12294 XTread_socket does the rest. */
12295 help_echo_object
= help_echo_window
= Qnil
;
12296 help_echo_pos
= -1;
12297 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12298 if (NILP (help_echo_string
))
12299 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12302 #endif /* !USE_GTK && !HAVE_NS */
12304 #endif /* HAVE_WINDOW_SYSTEM */
12308 /************************************************************************
12309 Horizontal scrolling
12310 ************************************************************************/
12312 static int hscroll_window_tree (Lisp_Object
);
12313 static int hscroll_windows (Lisp_Object
);
12315 /* For all leaf windows in the window tree rooted at WINDOW, set their
12316 hscroll value so that PT is (i) visible in the window, and (ii) so
12317 that it is not within a certain margin at the window's left and
12318 right border. Value is non-zero if any window's hscroll has been
12322 hscroll_window_tree (Lisp_Object window
)
12324 int hscrolled_p
= 0;
12325 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12326 int hscroll_step_abs
= 0;
12327 double hscroll_step_rel
= 0;
12329 if (hscroll_relative_p
)
12331 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12332 if (hscroll_step_rel
< 0)
12334 hscroll_relative_p
= 0;
12335 hscroll_step_abs
= 0;
12338 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12340 hscroll_step_abs
= XINT (Vhscroll_step
);
12341 if (hscroll_step_abs
< 0)
12342 hscroll_step_abs
= 0;
12345 hscroll_step_abs
= 0;
12347 while (WINDOWP (window
))
12349 struct window
*w
= XWINDOW (window
);
12351 if (WINDOWP (w
->contents
))
12352 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12353 else if (w
->cursor
.vpos
>= 0)
12356 int text_area_width
;
12357 struct glyph_row
*current_cursor_row
12358 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12359 struct glyph_row
*desired_cursor_row
12360 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12361 struct glyph_row
*cursor_row
12362 = (desired_cursor_row
->enabled_p
12363 ? desired_cursor_row
12364 : current_cursor_row
);
12365 int row_r2l_p
= cursor_row
->reversed_p
;
12367 text_area_width
= window_box_width (w
, TEXT_AREA
);
12369 /* Scroll when cursor is inside this scroll margin. */
12370 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12372 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12373 /* For left-to-right rows, hscroll when cursor is either
12374 (i) inside the right hscroll margin, or (ii) if it is
12375 inside the left margin and the window is already
12379 && w
->cursor
.x
<= h_margin
)
12380 || (cursor_row
->enabled_p
12381 && cursor_row
->truncated_on_right_p
12382 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12383 /* For right-to-left rows, the logic is similar,
12384 except that rules for scrolling to left and right
12385 are reversed. E.g., if cursor.x <= h_margin, we
12386 need to hscroll "to the right" unconditionally,
12387 and that will scroll the screen to the left so as
12388 to reveal the next portion of the row. */
12390 && ((cursor_row
->enabled_p
12391 /* FIXME: It is confusing to set the
12392 truncated_on_right_p flag when R2L rows
12393 are actually truncated on the left. */
12394 && cursor_row
->truncated_on_right_p
12395 && w
->cursor
.x
<= h_margin
)
12397 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12401 struct buffer
*saved_current_buffer
;
12405 /* Find point in a display of infinite width. */
12406 saved_current_buffer
= current_buffer
;
12407 current_buffer
= XBUFFER (w
->contents
);
12409 if (w
== XWINDOW (selected_window
))
12412 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12414 /* Move iterator to pt starting at cursor_row->start in
12415 a line with infinite width. */
12416 init_to_row_start (&it
, w
, cursor_row
);
12417 it
.last_visible_x
= INFINITY
;
12418 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12419 current_buffer
= saved_current_buffer
;
12421 /* Position cursor in window. */
12422 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12423 hscroll
= max (0, (it
.current_x
12424 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12425 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12426 : (text_area_width
/ 2))))
12427 / FRAME_COLUMN_WIDTH (it
.f
);
12428 else if ((!row_r2l_p
12429 && w
->cursor
.x
>= text_area_width
- h_margin
)
12430 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12432 if (hscroll_relative_p
)
12433 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12436 wanted_x
= text_area_width
12437 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12440 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12444 if (hscroll_relative_p
)
12445 wanted_x
= text_area_width
* hscroll_step_rel
12448 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12451 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12453 hscroll
= max (hscroll
, w
->min_hscroll
);
12455 /* Don't prevent redisplay optimizations if hscroll
12456 hasn't changed, as it will unnecessarily slow down
12458 if (w
->hscroll
!= hscroll
)
12460 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12461 w
->hscroll
= hscroll
;
12470 /* Value is non-zero if hscroll of any leaf window has been changed. */
12471 return hscrolled_p
;
12475 /* Set hscroll so that cursor is visible and not inside horizontal
12476 scroll margins for all windows in the tree rooted at WINDOW. See
12477 also hscroll_window_tree above. Value is non-zero if any window's
12478 hscroll has been changed. If it has, desired matrices on the frame
12479 of WINDOW are cleared. */
12482 hscroll_windows (Lisp_Object window
)
12484 int hscrolled_p
= hscroll_window_tree (window
);
12486 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12487 return hscrolled_p
;
12492 /************************************************************************
12494 ************************************************************************/
12496 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12497 to a non-zero value. This is sometimes handy to have in a debugger
12502 /* First and last unchanged row for try_window_id. */
12504 static int debug_first_unchanged_at_end_vpos
;
12505 static int debug_last_unchanged_at_beg_vpos
;
12507 /* Delta vpos and y. */
12509 static int debug_dvpos
, debug_dy
;
12511 /* Delta in characters and bytes for try_window_id. */
12513 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12515 /* Values of window_end_pos and window_end_vpos at the end of
12518 static ptrdiff_t debug_end_vpos
;
12520 /* Append a string to W->desired_matrix->method. FMT is a printf
12521 format string. If trace_redisplay_p is non-zero also printf the
12522 resulting string to stderr. */
12524 static void debug_method_add (struct window
*, char const *, ...)
12525 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12528 debug_method_add (struct window
*w
, char const *fmt
, ...)
12531 char *method
= w
->desired_matrix
->method
;
12532 int len
= strlen (method
);
12533 int size
= sizeof w
->desired_matrix
->method
;
12534 int remaining
= size
- len
- 1;
12537 if (len
&& remaining
)
12540 --remaining
, ++len
;
12543 va_start (ap
, fmt
);
12544 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12547 if (trace_redisplay_p
)
12548 fprintf (stderr
, "%p (%s): %s\n",
12550 ((BUFFERP (w
->contents
)
12551 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12552 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12557 #endif /* GLYPH_DEBUG */
12560 /* Value is non-zero if all changes in window W, which displays
12561 current_buffer, are in the text between START and END. START is a
12562 buffer position, END is given as a distance from Z. Used in
12563 redisplay_internal for display optimization. */
12566 text_outside_line_unchanged_p (struct window
*w
,
12567 ptrdiff_t start
, ptrdiff_t end
)
12569 int unchanged_p
= 1;
12571 /* If text or overlays have changed, see where. */
12572 if (window_outdated (w
))
12574 /* Gap in the line? */
12575 if (GPT
< start
|| Z
- GPT
< end
)
12578 /* Changes start in front of the line, or end after it? */
12580 && (BEG_UNCHANGED
< start
- 1
12581 || END_UNCHANGED
< end
))
12584 /* If selective display, can't optimize if changes start at the
12585 beginning of the line. */
12587 && INTEGERP (BVAR (current_buffer
, selective_display
))
12588 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12589 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12592 /* If there are overlays at the start or end of the line, these
12593 may have overlay strings with newlines in them. A change at
12594 START, for instance, may actually concern the display of such
12595 overlay strings as well, and they are displayed on different
12596 lines. So, quickly rule out this case. (For the future, it
12597 might be desirable to implement something more telling than
12598 just BEG/END_UNCHANGED.) */
12601 if (BEG
+ BEG_UNCHANGED
== start
12602 && overlay_touches_p (start
))
12604 if (END_UNCHANGED
== end
12605 && overlay_touches_p (Z
- end
))
12609 /* Under bidi reordering, adding or deleting a character in the
12610 beginning of a paragraph, before the first strong directional
12611 character, can change the base direction of the paragraph (unless
12612 the buffer specifies a fixed paragraph direction), which will
12613 require to redisplay the whole paragraph. It might be worthwhile
12614 to find the paragraph limits and widen the range of redisplayed
12615 lines to that, but for now just give up this optimization. */
12616 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12617 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12621 return unchanged_p
;
12625 /* Do a frame update, taking possible shortcuts into account. This is
12626 the main external entry point for redisplay.
12628 If the last redisplay displayed an echo area message and that message
12629 is no longer requested, we clear the echo area or bring back the
12630 mini-buffer if that is in use. */
12635 redisplay_internal ();
12640 overlay_arrow_string_or_property (Lisp_Object var
)
12644 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12647 return Voverlay_arrow_string
;
12650 /* Return 1 if there are any overlay-arrows in current_buffer. */
12652 overlay_arrow_in_current_buffer_p (void)
12656 for (vlist
= Voverlay_arrow_variable_list
;
12658 vlist
= XCDR (vlist
))
12660 Lisp_Object var
= XCAR (vlist
);
12663 if (!SYMBOLP (var
))
12665 val
= find_symbol_value (var
);
12667 && current_buffer
== XMARKER (val
)->buffer
)
12674 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12678 overlay_arrows_changed_p (void)
12682 for (vlist
= Voverlay_arrow_variable_list
;
12684 vlist
= XCDR (vlist
))
12686 Lisp_Object var
= XCAR (vlist
);
12687 Lisp_Object val
, pstr
;
12689 if (!SYMBOLP (var
))
12691 val
= find_symbol_value (var
);
12692 if (!MARKERP (val
))
12694 if (! EQ (COERCE_MARKER (val
),
12695 Fget (var
, Qlast_arrow_position
))
12696 || ! (pstr
= overlay_arrow_string_or_property (var
),
12697 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12703 /* Mark overlay arrows to be updated on next redisplay. */
12706 update_overlay_arrows (int up_to_date
)
12710 for (vlist
= Voverlay_arrow_variable_list
;
12712 vlist
= XCDR (vlist
))
12714 Lisp_Object var
= XCAR (vlist
);
12716 if (!SYMBOLP (var
))
12719 if (up_to_date
> 0)
12721 Lisp_Object val
= find_symbol_value (var
);
12722 Fput (var
, Qlast_arrow_position
,
12723 COERCE_MARKER (val
));
12724 Fput (var
, Qlast_arrow_string
,
12725 overlay_arrow_string_or_property (var
));
12727 else if (up_to_date
< 0
12728 || !NILP (Fget (var
, Qlast_arrow_position
)))
12730 Fput (var
, Qlast_arrow_position
, Qt
);
12731 Fput (var
, Qlast_arrow_string
, Qt
);
12737 /* Return overlay arrow string to display at row.
12738 Return integer (bitmap number) for arrow bitmap in left fringe.
12739 Return nil if no overlay arrow. */
12742 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12746 for (vlist
= Voverlay_arrow_variable_list
;
12748 vlist
= XCDR (vlist
))
12750 Lisp_Object var
= XCAR (vlist
);
12753 if (!SYMBOLP (var
))
12756 val
= find_symbol_value (var
);
12759 && current_buffer
== XMARKER (val
)->buffer
12760 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12762 if (FRAME_WINDOW_P (it
->f
)
12763 /* FIXME: if ROW->reversed_p is set, this should test
12764 the right fringe, not the left one. */
12765 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12767 #ifdef HAVE_WINDOW_SYSTEM
12768 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12771 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12772 return make_number (fringe_bitmap
);
12775 return make_number (-1); /* Use default arrow bitmap. */
12777 return overlay_arrow_string_or_property (var
);
12784 /* Return 1 if point moved out of or into a composition. Otherwise
12785 return 0. PREV_BUF and PREV_PT are the last point buffer and
12786 position. BUF and PT are the current point buffer and position. */
12789 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12790 struct buffer
*buf
, ptrdiff_t pt
)
12792 ptrdiff_t start
, end
;
12794 Lisp_Object buffer
;
12796 XSETBUFFER (buffer
, buf
);
12797 /* Check a composition at the last point if point moved within the
12799 if (prev_buf
== buf
)
12802 /* Point didn't move. */
12805 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12806 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12807 && composition_valid_p (start
, end
, prop
)
12808 && start
< prev_pt
&& end
> prev_pt
)
12809 /* The last point was within the composition. Return 1 iff
12810 point moved out of the composition. */
12811 return (pt
<= start
|| pt
>= end
);
12814 /* Check a composition at the current point. */
12815 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12816 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12817 && composition_valid_p (start
, end
, prop
)
12818 && start
< pt
&& end
> pt
);
12821 /* Reconsider the clip changes of buffer which is displayed in W. */
12824 reconsider_clip_changes (struct window
*w
)
12826 struct buffer
*b
= XBUFFER (w
->contents
);
12828 if (b
->clip_changed
12829 && w
->window_end_valid
12830 && w
->current_matrix
->buffer
== b
12831 && w
->current_matrix
->zv
== BUF_ZV (b
)
12832 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12833 b
->clip_changed
= 0;
12835 /* If display wasn't paused, and W is not a tool bar window, see if
12836 point has been moved into or out of a composition. In that case,
12837 we set b->clip_changed to 1 to force updating the screen. If
12838 b->clip_changed has already been set to 1, we can skip this
12840 if (!b
->clip_changed
&& w
->window_end_valid
)
12842 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12843 ? PT
: marker_position (w
->pointm
));
12845 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12846 && check_point_in_composition (w
->current_matrix
->buffer
,
12847 w
->last_point
, b
, pt
))
12848 b
->clip_changed
= 1;
12852 #define STOP_POLLING \
12853 do { if (! polling_stopped_here) stop_polling (); \
12854 polling_stopped_here = 1; } while (0)
12856 #define RESUME_POLLING \
12857 do { if (polling_stopped_here) start_polling (); \
12858 polling_stopped_here = 0; } while (0)
12861 /* Perhaps in the future avoid recentering windows if it
12862 is not necessary; currently that causes some problems. */
12865 redisplay_internal (void)
12867 struct window
*w
= XWINDOW (selected_window
);
12871 bool must_finish
= 0, match_p
;
12872 struct text_pos tlbufpos
, tlendpos
;
12873 int number_of_visible_frames
;
12876 int polling_stopped_here
= 0;
12877 Lisp_Object tail
, frame
;
12879 /* Non-zero means redisplay has to consider all windows on all
12880 frames. Zero means, only selected_window is considered. */
12881 int consider_all_windows_p
;
12883 /* Non-zero means redisplay has to redisplay the miniwindow. */
12884 int update_miniwindow_p
= 0;
12886 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12888 /* No redisplay if running in batch mode or frame is not yet fully
12889 initialized, or redisplay is explicitly turned off by setting
12890 Vinhibit_redisplay. */
12891 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12892 || !NILP (Vinhibit_redisplay
))
12895 /* Don't examine these until after testing Vinhibit_redisplay.
12896 When Emacs is shutting down, perhaps because its connection to
12897 X has dropped, we should not look at them at all. */
12898 fr
= XFRAME (w
->frame
);
12899 sf
= SELECTED_FRAME ();
12901 if (!fr
->glyphs_initialized_p
)
12904 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12905 if (popup_activated ())
12909 /* I don't think this happens but let's be paranoid. */
12910 if (redisplaying_p
)
12913 /* Record a function that clears redisplaying_p
12914 when we leave this function. */
12915 count
= SPECPDL_INDEX ();
12916 record_unwind_protect_void (unwind_redisplay
);
12917 redisplaying_p
= 1;
12918 specbind (Qinhibit_free_realized_faces
, Qnil
);
12920 /* Record this function, so it appears on the profiler's backtraces. */
12921 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
12923 FOR_EACH_FRAME (tail
, frame
)
12924 XFRAME (frame
)->already_hscrolled_p
= 0;
12927 /* Remember the currently selected window. */
12931 last_escape_glyph_frame
= NULL
;
12932 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12933 last_glyphless_glyph_frame
= NULL
;
12934 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12936 /* If face_change_count is non-zero, init_iterator will free all
12937 realized faces, which includes the faces referenced from current
12938 matrices. So, we can't reuse current matrices in this case. */
12939 if (face_change_count
)
12940 ++windows_or_buffers_changed
;
12942 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12943 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12945 /* Since frames on a single ASCII terminal share the same
12946 display area, displaying a different frame means redisplay
12947 the whole thing. */
12948 windows_or_buffers_changed
++;
12949 SET_FRAME_GARBAGED (sf
);
12951 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12953 FRAME_TTY (sf
)->previous_frame
= sf
;
12956 /* Set the visible flags for all frames. Do this before checking for
12957 resized or garbaged frames; they want to know if their frames are
12958 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
12959 number_of_visible_frames
= 0;
12961 FOR_EACH_FRAME (tail
, frame
)
12963 struct frame
*f
= XFRAME (frame
);
12965 if (FRAME_VISIBLE_P (f
))
12967 ++number_of_visible_frames
;
12968 /* Adjust matrices for visible frames only. */
12969 if (f
->fonts_changed
)
12971 adjust_frame_glyphs (f
);
12972 f
->fonts_changed
= 0;
12974 /* If cursor type has been changed on the frame
12975 other than selected, consider all frames. */
12976 if (f
!= sf
&& f
->cursor_type_changed
)
12977 update_mode_lines
++;
12979 clear_desired_matrices (f
);
12982 /* Notice any pending interrupt request to change frame size. */
12983 do_pending_window_change (1);
12985 /* do_pending_window_change could change the selected_window due to
12986 frame resizing which makes the selected window too small. */
12987 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12990 /* Clear frames marked as garbaged. */
12991 clear_garbaged_frames ();
12993 /* Build menubar and tool-bar items. */
12994 if (NILP (Vmemory_full
))
12995 prepare_menu_bars ();
12997 if (windows_or_buffers_changed
)
12998 update_mode_lines
++;
13000 reconsider_clip_changes (w
);
13002 /* In most cases selected window displays current buffer. */
13003 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13006 /* Detect case that we need to write or remove a star in the mode line. */
13007 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13009 w
->update_mode_line
= 1;
13010 if (buffer_shared_and_changed ())
13011 update_mode_lines
++;
13014 if (mode_line_update_needed (w
))
13015 w
->update_mode_line
= 1;
13018 consider_all_windows_p
= (update_mode_lines
13019 || buffer_shared_and_changed ());
13021 /* If specs for an arrow have changed, do thorough redisplay
13022 to ensure we remove any arrow that should no longer exist. */
13023 if (overlay_arrows_changed_p ())
13024 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13026 /* Normally the message* functions will have already displayed and
13027 updated the echo area, but the frame may have been trashed, or
13028 the update may have been preempted, so display the echo area
13029 again here. Checking message_cleared_p captures the case that
13030 the echo area should be cleared. */
13031 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13032 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13033 || (message_cleared_p
13034 && minibuf_level
== 0
13035 /* If the mini-window is currently selected, this means the
13036 echo-area doesn't show through. */
13037 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13039 int window_height_changed_p
= echo_area_display (0);
13041 if (message_cleared_p
)
13042 update_miniwindow_p
= 1;
13046 /* If we don't display the current message, don't clear the
13047 message_cleared_p flag, because, if we did, we wouldn't clear
13048 the echo area in the next redisplay which doesn't preserve
13050 if (!display_last_displayed_message_p
)
13051 message_cleared_p
= 0;
13053 if (window_height_changed_p
)
13055 consider_all_windows_p
= 1;
13056 ++update_mode_lines
;
13057 ++windows_or_buffers_changed
;
13059 /* If window configuration was changed, frames may have been
13060 marked garbaged. Clear them or we will experience
13061 surprises wrt scrolling. */
13062 clear_garbaged_frames ();
13065 else if (EQ (selected_window
, minibuf_window
)
13066 && (current_buffer
->clip_changed
|| window_outdated (w
))
13067 && resize_mini_window (w
, 0))
13069 /* Resized active mini-window to fit the size of what it is
13070 showing if its contents might have changed. */
13072 /* FIXME: this causes all frames to be updated, which seems unnecessary
13073 since only the current frame needs to be considered. This function
13074 needs to be rewritten with two variables, consider_all_windows and
13075 consider_all_frames. */
13076 consider_all_windows_p
= 1;
13077 ++windows_or_buffers_changed
;
13078 ++update_mode_lines
;
13080 /* If window configuration was changed, frames may have been
13081 marked garbaged. Clear them or we will experience
13082 surprises wrt scrolling. */
13083 clear_garbaged_frames ();
13086 /* Optimize the case that only the line containing the cursor in the
13087 selected window has changed. Variables starting with this_ are
13088 set in display_line and record information about the line
13089 containing the cursor. */
13090 tlbufpos
= this_line_start_pos
;
13091 tlendpos
= this_line_end_pos
;
13092 if (!consider_all_windows_p
13093 && CHARPOS (tlbufpos
) > 0
13094 && !w
->update_mode_line
13095 && !current_buffer
->clip_changed
13096 && !current_buffer
->prevent_redisplay_optimizations_p
13097 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13098 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13099 && !XFRAME (w
->frame
)->cursor_type_changed
13100 /* Make sure recorded data applies to current buffer, etc. */
13101 && this_line_buffer
== current_buffer
13104 && !w
->optional_new_start
13105 /* Point must be on the line that we have info recorded about. */
13106 && PT
>= CHARPOS (tlbufpos
)
13107 && PT
<= Z
- CHARPOS (tlendpos
)
13108 /* All text outside that line, including its final newline,
13109 must be unchanged. */
13110 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13111 CHARPOS (tlendpos
)))
13113 if (CHARPOS (tlbufpos
) > BEGV
13114 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13115 && (CHARPOS (tlbufpos
) == ZV
13116 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13117 /* Former continuation line has disappeared by becoming empty. */
13119 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13121 /* We have to handle the case of continuation around a
13122 wide-column character (see the comment in indent.c around
13125 For instance, in the following case:
13127 -------- Insert --------
13128 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13129 J_I_ ==> J_I_ `^^' are cursors.
13133 As we have to redraw the line above, we cannot use this
13137 int line_height_before
= this_line_pixel_height
;
13139 /* Note that start_display will handle the case that the
13140 line starting at tlbufpos is a continuation line. */
13141 start_display (&it
, w
, tlbufpos
);
13143 /* Implementation note: It this still necessary? */
13144 if (it
.current_x
!= this_line_start_x
)
13147 TRACE ((stderr
, "trying display optimization 1\n"));
13148 w
->cursor
.vpos
= -1;
13149 overlay_arrow_seen
= 0;
13150 it
.vpos
= this_line_vpos
;
13151 it
.current_y
= this_line_y
;
13152 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13153 display_line (&it
);
13155 /* If line contains point, is not continued,
13156 and ends at same distance from eob as before, we win. */
13157 if (w
->cursor
.vpos
>= 0
13158 /* Line is not continued, otherwise this_line_start_pos
13159 would have been set to 0 in display_line. */
13160 && CHARPOS (this_line_start_pos
)
13161 /* Line ends as before. */
13162 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13163 /* Line has same height as before. Otherwise other lines
13164 would have to be shifted up or down. */
13165 && this_line_pixel_height
== line_height_before
)
13167 /* If this is not the window's last line, we must adjust
13168 the charstarts of the lines below. */
13169 if (it
.current_y
< it
.last_visible_y
)
13171 struct glyph_row
*row
13172 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13173 ptrdiff_t delta
, delta_bytes
;
13175 /* We used to distinguish between two cases here,
13176 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13177 when the line ends in a newline or the end of the
13178 buffer's accessible portion. But both cases did
13179 the same, so they were collapsed. */
13181 - CHARPOS (tlendpos
)
13182 - MATRIX_ROW_START_CHARPOS (row
));
13183 delta_bytes
= (Z_BYTE
13184 - BYTEPOS (tlendpos
)
13185 - MATRIX_ROW_START_BYTEPOS (row
));
13187 increment_matrix_positions (w
->current_matrix
,
13188 this_line_vpos
+ 1,
13189 w
->current_matrix
->nrows
,
13190 delta
, delta_bytes
);
13193 /* If this row displays text now but previously didn't,
13194 or vice versa, w->window_end_vpos may have to be
13196 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13198 if (w
->window_end_vpos
< this_line_vpos
)
13199 w
->window_end_vpos
= this_line_vpos
;
13201 else if (w
->window_end_vpos
== this_line_vpos
13202 && this_line_vpos
> 0)
13203 w
->window_end_vpos
= this_line_vpos
- 1;
13204 w
->window_end_valid
= 0;
13206 /* Update hint: No need to try to scroll in update_window. */
13207 w
->desired_matrix
->no_scrolling_p
= 1;
13210 *w
->desired_matrix
->method
= 0;
13211 debug_method_add (w
, "optimization 1");
13213 #ifdef HAVE_WINDOW_SYSTEM
13214 update_window_fringes (w
, 0);
13221 else if (/* Cursor position hasn't changed. */
13222 PT
== w
->last_point
13223 /* Make sure the cursor was last displayed
13224 in this window. Otherwise we have to reposition it. */
13225 && 0 <= w
->cursor
.vpos
13226 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13230 do_pending_window_change (1);
13231 /* If selected_window changed, redisplay again. */
13232 if (WINDOWP (selected_window
)
13233 && (w
= XWINDOW (selected_window
)) != sw
)
13236 /* We used to always goto end_of_redisplay here, but this
13237 isn't enough if we have a blinking cursor. */
13238 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13239 goto end_of_redisplay
;
13243 /* If highlighting the region, or if the cursor is in the echo area,
13244 then we can't just move the cursor. */
13245 else if (NILP (Vshow_trailing_whitespace
)
13246 && !cursor_in_echo_area
)
13249 struct glyph_row
*row
;
13251 /* Skip from tlbufpos to PT and see where it is. Note that
13252 PT may be in invisible text. If so, we will end at the
13253 next visible position. */
13254 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13255 NULL
, DEFAULT_FACE_ID
);
13256 it
.current_x
= this_line_start_x
;
13257 it
.current_y
= this_line_y
;
13258 it
.vpos
= this_line_vpos
;
13260 /* The call to move_it_to stops in front of PT, but
13261 moves over before-strings. */
13262 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13264 if (it
.vpos
== this_line_vpos
13265 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13268 eassert (this_line_vpos
== it
.vpos
);
13269 eassert (this_line_y
== it
.current_y
);
13270 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13272 *w
->desired_matrix
->method
= 0;
13273 debug_method_add (w
, "optimization 3");
13282 /* Text changed drastically or point moved off of line. */
13283 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13286 CHARPOS (this_line_start_pos
) = 0;
13287 consider_all_windows_p
|= buffer_shared_and_changed ();
13288 ++clear_face_cache_count
;
13289 #ifdef HAVE_WINDOW_SYSTEM
13290 ++clear_image_cache_count
;
13293 /* Build desired matrices, and update the display. If
13294 consider_all_windows_p is non-zero, do it for all windows on all
13295 frames. Otherwise do it for selected_window, only. */
13297 if (consider_all_windows_p
)
13299 FOR_EACH_FRAME (tail
, frame
)
13300 XFRAME (frame
)->updated_p
= 0;
13302 FOR_EACH_FRAME (tail
, frame
)
13304 struct frame
*f
= XFRAME (frame
);
13306 /* We don't have to do anything for unselected terminal
13308 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13309 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13314 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13316 /* Mark all the scroll bars to be removed; we'll redeem
13317 the ones we want when we redisplay their windows. */
13318 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13319 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13321 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13322 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13324 /* The X error handler may have deleted that frame. */
13325 if (!FRAME_LIVE_P (f
))
13328 /* Any scroll bars which redisplay_windows should have
13329 nuked should now go away. */
13330 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13331 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13333 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13335 /* If fonts changed on visible frame, display again. */
13336 if (f
->fonts_changed
)
13338 adjust_frame_glyphs (f
);
13339 f
->fonts_changed
= 0;
13343 /* See if we have to hscroll. */
13344 if (!f
->already_hscrolled_p
)
13346 f
->already_hscrolled_p
= 1;
13347 if (hscroll_windows (f
->root_window
))
13351 /* Prevent various kinds of signals during display
13352 update. stdio is not robust about handling
13353 signals, which can cause an apparent I/O
13355 if (interrupt_input
)
13356 unrequest_sigio ();
13359 /* Mark windows on frame F to update. If we decide to
13360 update all frames but windows_or_buffers_changed is
13361 zero, we assume that only the windows that shows
13362 current buffer should be really updated. */
13363 set_window_update_flags
13364 (XWINDOW (f
->root_window
),
13365 (windows_or_buffers_changed
? NULL
: current_buffer
), 1);
13366 pending
|= update_frame (f
, 0, 0);
13367 f
->cursor_type_changed
= 0;
13373 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13377 /* Do the mark_window_display_accurate after all windows have
13378 been redisplayed because this call resets flags in buffers
13379 which are needed for proper redisplay. */
13380 FOR_EACH_FRAME (tail
, frame
)
13382 struct frame
*f
= XFRAME (frame
);
13385 mark_window_display_accurate (f
->root_window
, 1);
13386 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13387 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13392 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13394 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13395 struct frame
*mini_frame
;
13397 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13398 /* Use list_of_error, not Qerror, so that
13399 we catch only errors and don't run the debugger. */
13400 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13402 redisplay_window_error
);
13403 if (update_miniwindow_p
)
13404 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13406 redisplay_window_error
);
13408 /* Compare desired and current matrices, perform output. */
13411 /* If fonts changed, display again. */
13412 if (sf
->fonts_changed
)
13415 /* Prevent various kinds of signals during display update.
13416 stdio is not robust about handling signals,
13417 which can cause an apparent I/O error. */
13418 if (interrupt_input
)
13419 unrequest_sigio ();
13422 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13424 if (hscroll_windows (selected_window
))
13427 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13428 pending
= update_frame (sf
, 0, 0);
13429 sf
->cursor_type_changed
= 0;
13432 /* We may have called echo_area_display at the top of this
13433 function. If the echo area is on another frame, that may
13434 have put text on a frame other than the selected one, so the
13435 above call to update_frame would not have caught it. Catch
13437 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13438 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13440 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13442 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13443 pending
|= update_frame (mini_frame
, 0, 0);
13444 mini_frame
->cursor_type_changed
= 0;
13445 if (!pending
&& hscroll_windows (mini_window
))
13450 /* If display was paused because of pending input, make sure we do a
13451 thorough update the next time. */
13454 /* Prevent the optimization at the beginning of
13455 redisplay_internal that tries a single-line update of the
13456 line containing the cursor in the selected window. */
13457 CHARPOS (this_line_start_pos
) = 0;
13459 /* Let the overlay arrow be updated the next time. */
13460 update_overlay_arrows (0);
13462 /* If we pause after scrolling, some rows in the current
13463 matrices of some windows are not valid. */
13464 if (!WINDOW_FULL_WIDTH_P (w
)
13465 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13466 update_mode_lines
= 1;
13470 if (!consider_all_windows_p
)
13472 /* This has already been done above if
13473 consider_all_windows_p is set. */
13474 mark_window_display_accurate_1 (w
, 1);
13476 /* Say overlay arrows are up to date. */
13477 update_overlay_arrows (1);
13479 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13480 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13483 update_mode_lines
= 0;
13484 windows_or_buffers_changed
= 0;
13487 /* Start SIGIO interrupts coming again. Having them off during the
13488 code above makes it less likely one will discard output, but not
13489 impossible, since there might be stuff in the system buffer here.
13490 But it is much hairier to try to do anything about that. */
13491 if (interrupt_input
)
13495 /* If a frame has become visible which was not before, redisplay
13496 again, so that we display it. Expose events for such a frame
13497 (which it gets when becoming visible) don't call the parts of
13498 redisplay constructing glyphs, so simply exposing a frame won't
13499 display anything in this case. So, we have to display these
13500 frames here explicitly. */
13505 FOR_EACH_FRAME (tail
, frame
)
13507 int this_is_visible
= 0;
13509 if (XFRAME (frame
)->visible
)
13510 this_is_visible
= 1;
13512 if (this_is_visible
)
13516 if (new_count
!= number_of_visible_frames
)
13517 windows_or_buffers_changed
++;
13520 /* Change frame size now if a change is pending. */
13521 do_pending_window_change (1);
13523 /* If we just did a pending size change, or have additional
13524 visible frames, or selected_window changed, redisplay again. */
13525 if ((windows_or_buffers_changed
&& !pending
)
13526 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13529 /* Clear the face and image caches.
13531 We used to do this only if consider_all_windows_p. But the cache
13532 needs to be cleared if a timer creates images in the current
13533 buffer (e.g. the test case in Bug#6230). */
13535 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13537 clear_face_cache (0);
13538 clear_face_cache_count
= 0;
13541 #ifdef HAVE_WINDOW_SYSTEM
13542 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13544 clear_image_caches (Qnil
);
13545 clear_image_cache_count
= 0;
13547 #endif /* HAVE_WINDOW_SYSTEM */
13550 unbind_to (count
, Qnil
);
13555 /* Redisplay, but leave alone any recent echo area message unless
13556 another message has been requested in its place.
13558 This is useful in situations where you need to redisplay but no
13559 user action has occurred, making it inappropriate for the message
13560 area to be cleared. See tracking_off and
13561 wait_reading_process_output for examples of these situations.
13563 FROM_WHERE is an integer saying from where this function was
13564 called. This is useful for debugging. */
13567 redisplay_preserve_echo_area (int from_where
)
13569 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13571 if (!NILP (echo_area_buffer
[1]))
13573 /* We have a previously displayed message, but no current
13574 message. Redisplay the previous message. */
13575 display_last_displayed_message_p
= 1;
13576 redisplay_internal ();
13577 display_last_displayed_message_p
= 0;
13580 redisplay_internal ();
13582 flush_frame (SELECTED_FRAME ());
13586 /* Function registered with record_unwind_protect in redisplay_internal. */
13589 unwind_redisplay (void)
13591 redisplaying_p
= 0;
13595 /* Mark the display of leaf window W as accurate or inaccurate.
13596 If ACCURATE_P is non-zero mark display of W as accurate. If
13597 ACCURATE_P is zero, arrange for W to be redisplayed the next
13598 time redisplay_internal is called. */
13601 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13603 struct buffer
*b
= XBUFFER (w
->contents
);
13605 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13606 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13607 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13611 b
->clip_changed
= 0;
13612 b
->prevent_redisplay_optimizations_p
= 0;
13614 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13615 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13616 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13617 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13619 w
->current_matrix
->buffer
= b
;
13620 w
->current_matrix
->begv
= BUF_BEGV (b
);
13621 w
->current_matrix
->zv
= BUF_ZV (b
);
13623 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13624 w
->last_cursor_off_p
= w
->cursor_off_p
;
13626 if (w
== XWINDOW (selected_window
))
13627 w
->last_point
= BUF_PT (b
);
13629 w
->last_point
= marker_position (w
->pointm
);
13631 w
->window_end_valid
= 1;
13632 w
->update_mode_line
= 0;
13637 /* Mark the display of windows in the window tree rooted at WINDOW as
13638 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13639 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13640 be redisplayed the next time redisplay_internal is called. */
13643 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13647 for (; !NILP (window
); window
= w
->next
)
13649 w
= XWINDOW (window
);
13650 if (WINDOWP (w
->contents
))
13651 mark_window_display_accurate (w
->contents
, accurate_p
);
13653 mark_window_display_accurate_1 (w
, accurate_p
);
13657 update_overlay_arrows (1);
13659 /* Force a thorough redisplay the next time by setting
13660 last_arrow_position and last_arrow_string to t, which is
13661 unequal to any useful value of Voverlay_arrow_... */
13662 update_overlay_arrows (-1);
13666 /* Return value in display table DP (Lisp_Char_Table *) for character
13667 C. Since a display table doesn't have any parent, we don't have to
13668 follow parent. Do not call this function directly but use the
13669 macro DISP_CHAR_VECTOR. */
13672 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13676 if (ASCII_CHAR_P (c
))
13679 if (SUB_CHAR_TABLE_P (val
))
13680 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13686 XSETCHAR_TABLE (table
, dp
);
13687 val
= char_table_ref (table
, c
);
13696 /***********************************************************************
13698 ***********************************************************************/
13700 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13703 redisplay_windows (Lisp_Object window
)
13705 while (!NILP (window
))
13707 struct window
*w
= XWINDOW (window
);
13709 if (WINDOWP (w
->contents
))
13710 redisplay_windows (w
->contents
);
13711 else if (BUFFERP (w
->contents
))
13713 displayed_buffer
= XBUFFER (w
->contents
);
13714 /* Use list_of_error, not Qerror, so that
13715 we catch only errors and don't run the debugger. */
13716 internal_condition_case_1 (redisplay_window_0
, window
,
13718 redisplay_window_error
);
13726 redisplay_window_error (Lisp_Object ignore
)
13728 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13733 redisplay_window_0 (Lisp_Object window
)
13735 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13736 redisplay_window (window
, 0);
13741 redisplay_window_1 (Lisp_Object window
)
13743 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13744 redisplay_window (window
, 1);
13749 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13750 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13751 which positions recorded in ROW differ from current buffer
13754 Return 0 if cursor is not on this row, 1 otherwise. */
13757 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13758 struct glyph_matrix
*matrix
,
13759 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13762 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13763 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13764 struct glyph
*cursor
= NULL
;
13765 /* The last known character position in row. */
13766 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13768 ptrdiff_t pt_old
= PT
- delta
;
13769 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13770 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13771 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13772 /* A glyph beyond the edge of TEXT_AREA which we should never
13774 struct glyph
*glyphs_end
= end
;
13775 /* Non-zero means we've found a match for cursor position, but that
13776 glyph has the avoid_cursor_p flag set. */
13777 int match_with_avoid_cursor
= 0;
13778 /* Non-zero means we've seen at least one glyph that came from a
13780 int string_seen
= 0;
13781 /* Largest and smallest buffer positions seen so far during scan of
13783 ptrdiff_t bpos_max
= pos_before
;
13784 ptrdiff_t bpos_min
= pos_after
;
13785 /* Last buffer position covered by an overlay string with an integer
13786 `cursor' property. */
13787 ptrdiff_t bpos_covered
= 0;
13788 /* Non-zero means the display string on which to display the cursor
13789 comes from a text property, not from an overlay. */
13790 int string_from_text_prop
= 0;
13792 /* Don't even try doing anything if called for a mode-line or
13793 header-line row, since the rest of the code isn't prepared to
13794 deal with such calamities. */
13795 eassert (!row
->mode_line_p
);
13796 if (row
->mode_line_p
)
13799 /* Skip over glyphs not having an object at the start and the end of
13800 the row. These are special glyphs like truncation marks on
13801 terminal frames. */
13802 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13804 if (!row
->reversed_p
)
13807 && INTEGERP (glyph
->object
)
13808 && glyph
->charpos
< 0)
13810 x
+= glyph
->pixel_width
;
13814 && INTEGERP ((end
- 1)->object
)
13815 /* CHARPOS is zero for blanks and stretch glyphs
13816 inserted by extend_face_to_end_of_line. */
13817 && (end
- 1)->charpos
<= 0)
13819 glyph_before
= glyph
- 1;
13826 /* If the glyph row is reversed, we need to process it from back
13827 to front, so swap the edge pointers. */
13828 glyphs_end
= end
= glyph
- 1;
13829 glyph
+= row
->used
[TEXT_AREA
] - 1;
13831 while (glyph
> end
+ 1
13832 && INTEGERP (glyph
->object
)
13833 && glyph
->charpos
< 0)
13836 x
-= glyph
->pixel_width
;
13838 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13840 /* By default, in reversed rows we put the cursor on the
13841 rightmost (first in the reading order) glyph. */
13842 for (g
= end
+ 1; g
< glyph
; g
++)
13843 x
+= g
->pixel_width
;
13845 && INTEGERP ((end
+ 1)->object
)
13846 && (end
+ 1)->charpos
<= 0)
13848 glyph_before
= glyph
+ 1;
13852 else if (row
->reversed_p
)
13854 /* In R2L rows that don't display text, put the cursor on the
13855 rightmost glyph. Case in point: an empty last line that is
13856 part of an R2L paragraph. */
13858 /* Avoid placing the cursor on the last glyph of the row, where
13859 on terminal frames we hold the vertical border between
13860 adjacent windows. */
13861 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13862 && !WINDOW_RIGHTMOST_P (w
)
13863 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13865 x
= -1; /* will be computed below, at label compute_x */
13868 /* Step 1: Try to find the glyph whose character position
13869 corresponds to point. If that's not possible, find 2 glyphs
13870 whose character positions are the closest to point, one before
13871 point, the other after it. */
13872 if (!row
->reversed_p
)
13873 while (/* not marched to end of glyph row */
13875 /* glyph was not inserted by redisplay for internal purposes */
13876 && !INTEGERP (glyph
->object
))
13878 if (BUFFERP (glyph
->object
))
13880 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13882 if (glyph
->charpos
> bpos_max
)
13883 bpos_max
= glyph
->charpos
;
13884 if (glyph
->charpos
< bpos_min
)
13885 bpos_min
= glyph
->charpos
;
13886 if (!glyph
->avoid_cursor_p
)
13888 /* If we hit point, we've found the glyph on which to
13889 display the cursor. */
13892 match_with_avoid_cursor
= 0;
13895 /* See if we've found a better approximation to
13896 POS_BEFORE or to POS_AFTER. */
13897 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13899 pos_before
= glyph
->charpos
;
13900 glyph_before
= glyph
;
13902 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13904 pos_after
= glyph
->charpos
;
13905 glyph_after
= glyph
;
13908 else if (dpos
== 0)
13909 match_with_avoid_cursor
= 1;
13911 else if (STRINGP (glyph
->object
))
13913 Lisp_Object chprop
;
13914 ptrdiff_t glyph_pos
= glyph
->charpos
;
13916 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13918 if (!NILP (chprop
))
13920 /* If the string came from a `display' text property,
13921 look up the buffer position of that property and
13922 use that position to update bpos_max, as if we
13923 actually saw such a position in one of the row's
13924 glyphs. This helps with supporting integer values
13925 of `cursor' property on the display string in
13926 situations where most or all of the row's buffer
13927 text is completely covered by display properties,
13928 so that no glyph with valid buffer positions is
13929 ever seen in the row. */
13930 ptrdiff_t prop_pos
=
13931 string_buffer_position_lim (glyph
->object
, pos_before
,
13934 if (prop_pos
>= pos_before
)
13935 bpos_max
= prop_pos
- 1;
13937 if (INTEGERP (chprop
))
13939 bpos_covered
= bpos_max
+ XINT (chprop
);
13940 /* If the `cursor' property covers buffer positions up
13941 to and including point, we should display cursor on
13942 this glyph. Note that, if a `cursor' property on one
13943 of the string's characters has an integer value, we
13944 will break out of the loop below _before_ we get to
13945 the position match above. IOW, integer values of
13946 the `cursor' property override the "exact match for
13947 point" strategy of positioning the cursor. */
13948 /* Implementation note: bpos_max == pt_old when, e.g.,
13949 we are in an empty line, where bpos_max is set to
13950 MATRIX_ROW_START_CHARPOS, see above. */
13951 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13960 x
+= glyph
->pixel_width
;
13963 else if (glyph
> end
) /* row is reversed */
13964 while (!INTEGERP (glyph
->object
))
13966 if (BUFFERP (glyph
->object
))
13968 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13970 if (glyph
->charpos
> bpos_max
)
13971 bpos_max
= glyph
->charpos
;
13972 if (glyph
->charpos
< bpos_min
)
13973 bpos_min
= glyph
->charpos
;
13974 if (!glyph
->avoid_cursor_p
)
13978 match_with_avoid_cursor
= 0;
13981 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13983 pos_before
= glyph
->charpos
;
13984 glyph_before
= glyph
;
13986 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13988 pos_after
= glyph
->charpos
;
13989 glyph_after
= glyph
;
13992 else if (dpos
== 0)
13993 match_with_avoid_cursor
= 1;
13995 else if (STRINGP (glyph
->object
))
13997 Lisp_Object chprop
;
13998 ptrdiff_t glyph_pos
= glyph
->charpos
;
14000 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14002 if (!NILP (chprop
))
14004 ptrdiff_t prop_pos
=
14005 string_buffer_position_lim (glyph
->object
, pos_before
,
14008 if (prop_pos
>= pos_before
)
14009 bpos_max
= prop_pos
- 1;
14011 if (INTEGERP (chprop
))
14013 bpos_covered
= bpos_max
+ XINT (chprop
);
14014 /* If the `cursor' property covers buffer positions up
14015 to and including point, we should display cursor on
14017 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14026 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14028 x
--; /* can't use any pixel_width */
14031 x
-= glyph
->pixel_width
;
14034 /* Step 2: If we didn't find an exact match for point, we need to
14035 look for a proper place to put the cursor among glyphs between
14036 GLYPH_BEFORE and GLYPH_AFTER. */
14037 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14038 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14039 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14041 /* An empty line has a single glyph whose OBJECT is zero and
14042 whose CHARPOS is the position of a newline on that line.
14043 Note that on a TTY, there are more glyphs after that, which
14044 were produced by extend_face_to_end_of_line, but their
14045 CHARPOS is zero or negative. */
14047 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14048 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14049 /* On a TTY, continued and truncated rows also have a glyph at
14050 their end whose OBJECT is zero and whose CHARPOS is
14051 positive (the continuation and truncation glyphs), but such
14052 rows are obviously not "empty". */
14053 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14055 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14057 ptrdiff_t ellipsis_pos
;
14059 /* Scan back over the ellipsis glyphs. */
14060 if (!row
->reversed_p
)
14062 ellipsis_pos
= (glyph
- 1)->charpos
;
14063 while (glyph
> row
->glyphs
[TEXT_AREA
]
14064 && (glyph
- 1)->charpos
== ellipsis_pos
)
14065 glyph
--, x
-= glyph
->pixel_width
;
14066 /* That loop always goes one position too far, including
14067 the glyph before the ellipsis. So scan forward over
14069 x
+= glyph
->pixel_width
;
14072 else /* row is reversed */
14074 ellipsis_pos
= (glyph
+ 1)->charpos
;
14075 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14076 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14077 glyph
++, x
+= glyph
->pixel_width
;
14078 x
-= glyph
->pixel_width
;
14082 else if (match_with_avoid_cursor
)
14084 cursor
= glyph_after
;
14087 else if (string_seen
)
14089 int incr
= row
->reversed_p
? -1 : +1;
14091 /* Need to find the glyph that came out of a string which is
14092 present at point. That glyph is somewhere between
14093 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14094 positioned between POS_BEFORE and POS_AFTER in the
14096 struct glyph
*start
, *stop
;
14097 ptrdiff_t pos
= pos_before
;
14101 /* If the row ends in a newline from a display string,
14102 reordering could have moved the glyphs belonging to the
14103 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14104 in this case we extend the search to the last glyph in
14105 the row that was not inserted by redisplay. */
14106 if (row
->ends_in_newline_from_string_p
)
14109 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14112 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14113 correspond to POS_BEFORE and POS_AFTER, respectively. We
14114 need START and STOP in the order that corresponds to the
14115 row's direction as given by its reversed_p flag. If the
14116 directionality of characters between POS_BEFORE and
14117 POS_AFTER is the opposite of the row's base direction,
14118 these characters will have been reordered for display,
14119 and we need to reverse START and STOP. */
14120 if (!row
->reversed_p
)
14122 start
= min (glyph_before
, glyph_after
);
14123 stop
= max (glyph_before
, glyph_after
);
14127 start
= max (glyph_before
, glyph_after
);
14128 stop
= min (glyph_before
, glyph_after
);
14130 for (glyph
= start
+ incr
;
14131 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14134 /* Any glyphs that come from the buffer are here because
14135 of bidi reordering. Skip them, and only pay
14136 attention to glyphs that came from some string. */
14137 if (STRINGP (glyph
->object
))
14141 /* If the display property covers the newline, we
14142 need to search for it one position farther. */
14143 ptrdiff_t lim
= pos_after
14144 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14146 string_from_text_prop
= 0;
14147 str
= glyph
->object
;
14148 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14149 if (tem
== 0 /* from overlay */
14152 /* If the string from which this glyph came is
14153 found in the buffer at point, or at position
14154 that is closer to point than pos_after, then
14155 we've found the glyph we've been looking for.
14156 If it comes from an overlay (tem == 0), and
14157 it has the `cursor' property on one of its
14158 glyphs, record that glyph as a candidate for
14159 displaying the cursor. (As in the
14160 unidirectional version, we will display the
14161 cursor on the last candidate we find.) */
14164 || (tem
- pt_old
> 0 && tem
< pos_after
))
14166 /* The glyphs from this string could have
14167 been reordered. Find the one with the
14168 smallest string position. Or there could
14169 be a character in the string with the
14170 `cursor' property, which means display
14171 cursor on that character's glyph. */
14172 ptrdiff_t strpos
= glyph
->charpos
;
14177 string_from_text_prop
= 1;
14180 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14181 && EQ (glyph
->object
, str
);
14185 ptrdiff_t gpos
= glyph
->charpos
;
14187 cprop
= Fget_char_property (make_number (gpos
),
14195 if (tem
&& glyph
->charpos
< strpos
)
14197 strpos
= glyph
->charpos
;
14203 || (tem
- pt_old
> 0 && tem
< pos_after
))
14207 pos
= tem
+ 1; /* don't find previous instances */
14209 /* This string is not what we want; skip all of the
14210 glyphs that came from it. */
14211 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14212 && EQ (glyph
->object
, str
))
14219 /* If we reached the end of the line, and END was from a string,
14220 the cursor is not on this line. */
14222 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14223 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14224 && STRINGP (end
->object
)
14225 && row
->continued_p
)
14228 /* A truncated row may not include PT among its character positions.
14229 Setting the cursor inside the scroll margin will trigger
14230 recalculation of hscroll in hscroll_window_tree. But if a
14231 display string covers point, defer to the string-handling
14232 code below to figure this out. */
14233 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14235 cursor
= glyph_before
;
14238 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14239 /* Zero-width characters produce no glyphs. */
14241 && (row
->reversed_p
14242 ? glyph_after
> glyphs_end
14243 : glyph_after
< glyphs_end
)))
14245 cursor
= glyph_after
;
14251 if (cursor
!= NULL
)
14253 else if (glyph
== glyphs_end
14254 && pos_before
== pos_after
14255 && STRINGP ((row
->reversed_p
14256 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14257 : row
->glyphs
[TEXT_AREA
])->object
))
14259 /* If all the glyphs of this row came from strings, put the
14260 cursor on the first glyph of the row. This avoids having the
14261 cursor outside of the text area in this very rare and hard
14265 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14266 : row
->glyphs
[TEXT_AREA
];
14272 /* Need to compute x that corresponds to GLYPH. */
14273 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14275 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14277 x
+= g
->pixel_width
;
14281 /* ROW could be part of a continued line, which, under bidi
14282 reordering, might have other rows whose start and end charpos
14283 occlude point. Only set w->cursor if we found a better
14284 approximation to the cursor position than we have from previously
14285 examined candidate rows belonging to the same continued line. */
14286 if (/* we already have a candidate row */
14287 w
->cursor
.vpos
>= 0
14288 /* that candidate is not the row we are processing */
14289 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14290 /* Make sure cursor.vpos specifies a row whose start and end
14291 charpos occlude point, and it is valid candidate for being a
14292 cursor-row. This is because some callers of this function
14293 leave cursor.vpos at the row where the cursor was displayed
14294 during the last redisplay cycle. */
14295 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14296 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14297 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14300 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14302 /* Don't consider glyphs that are outside TEXT_AREA. */
14303 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14305 /* Keep the candidate whose buffer position is the closest to
14306 point or has the `cursor' property. */
14307 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14308 w
->cursor
.hpos
>= 0
14309 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14310 && ((BUFFERP (g1
->object
)
14311 && (g1
->charpos
== pt_old
/* an exact match always wins */
14312 || (BUFFERP (glyph
->object
)
14313 && eabs (g1
->charpos
- pt_old
)
14314 < eabs (glyph
->charpos
- pt_old
))))
14315 /* previous candidate is a glyph from a string that has
14316 a non-nil `cursor' property */
14317 || (STRINGP (g1
->object
)
14318 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14319 Qcursor
, g1
->object
))
14320 /* previous candidate is from the same display
14321 string as this one, and the display string
14322 came from a text property */
14323 || (EQ (g1
->object
, glyph
->object
)
14324 && string_from_text_prop
)
14325 /* this candidate is from newline and its
14326 position is not an exact match */
14327 || (INTEGERP (glyph
->object
)
14328 && glyph
->charpos
!= pt_old
)))))
14330 /* If this candidate gives an exact match, use that. */
14331 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14332 /* If this candidate is a glyph created for the
14333 terminating newline of a line, and point is on that
14334 newline, it wins because it's an exact match. */
14335 || (!row
->continued_p
14336 && INTEGERP (glyph
->object
)
14337 && glyph
->charpos
== 0
14338 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14339 /* Otherwise, keep the candidate that comes from a row
14340 spanning less buffer positions. This may win when one or
14341 both candidate positions are on glyphs that came from
14342 display strings, for which we cannot compare buffer
14344 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14345 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14346 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14349 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14351 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14352 w
->cursor
.y
= row
->y
+ dy
;
14354 if (w
== XWINDOW (selected_window
))
14356 if (!row
->continued_p
14357 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14360 this_line_buffer
= XBUFFER (w
->contents
);
14362 CHARPOS (this_line_start_pos
)
14363 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14364 BYTEPOS (this_line_start_pos
)
14365 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14367 CHARPOS (this_line_end_pos
)
14368 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14369 BYTEPOS (this_line_end_pos
)
14370 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14372 this_line_y
= w
->cursor
.y
;
14373 this_line_pixel_height
= row
->height
;
14374 this_line_vpos
= w
->cursor
.vpos
;
14375 this_line_start_x
= row
->x
;
14378 CHARPOS (this_line_start_pos
) = 0;
14385 /* Run window scroll functions, if any, for WINDOW with new window
14386 start STARTP. Sets the window start of WINDOW to that position.
14388 We assume that the window's buffer is really current. */
14390 static struct text_pos
14391 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14393 struct window
*w
= XWINDOW (window
);
14394 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14396 eassert (current_buffer
== XBUFFER (w
->contents
));
14398 if (!NILP (Vwindow_scroll_functions
))
14400 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14401 make_number (CHARPOS (startp
)));
14402 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14403 /* In case the hook functions switch buffers. */
14404 set_buffer_internal (XBUFFER (w
->contents
));
14411 /* Make sure the line containing the cursor is fully visible.
14412 A value of 1 means there is nothing to be done.
14413 (Either the line is fully visible, or it cannot be made so,
14414 or we cannot tell.)
14416 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14417 is higher than window.
14419 A value of 0 means the caller should do scrolling
14420 as if point had gone off the screen. */
14423 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14425 struct glyph_matrix
*matrix
;
14426 struct glyph_row
*row
;
14429 if (!make_cursor_line_fully_visible_p
)
14432 /* It's not always possible to find the cursor, e.g, when a window
14433 is full of overlay strings. Don't do anything in that case. */
14434 if (w
->cursor
.vpos
< 0)
14437 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14438 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14440 /* If the cursor row is not partially visible, there's nothing to do. */
14441 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14444 /* If the row the cursor is in is taller than the window's height,
14445 it's not clear what to do, so do nothing. */
14446 window_height
= window_box_height (w
);
14447 if (row
->height
>= window_height
)
14449 if (!force_p
|| MINI_WINDOW_P (w
)
14450 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14457 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14458 non-zero means only WINDOW is redisplayed in redisplay_internal.
14459 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14460 in redisplay_window to bring a partially visible line into view in
14461 the case that only the cursor has moved.
14463 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14464 last screen line's vertical height extends past the end of the screen.
14468 1 if scrolling succeeded
14470 0 if scrolling didn't find point.
14472 -1 if new fonts have been loaded so that we must interrupt
14473 redisplay, adjust glyph matrices, and try again. */
14479 SCROLLING_NEED_LARGER_MATRICES
14482 /* If scroll-conservatively is more than this, never recenter.
14484 If you change this, don't forget to update the doc string of
14485 `scroll-conservatively' and the Emacs manual. */
14486 #define SCROLL_LIMIT 100
14489 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14490 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14491 int temp_scroll_step
, int last_line_misfit
)
14493 struct window
*w
= XWINDOW (window
);
14494 struct frame
*f
= XFRAME (w
->frame
);
14495 struct text_pos pos
, startp
;
14497 int this_scroll_margin
, scroll_max
, rc
, height
;
14498 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14499 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14500 Lisp_Object aggressive
;
14501 /* We will never try scrolling more than this number of lines. */
14502 int scroll_limit
= SCROLL_LIMIT
;
14503 int frame_line_height
= default_line_pixel_height (w
);
14504 int window_total_lines
14505 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14508 debug_method_add (w
, "try_scrolling");
14511 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14513 /* Compute scroll margin height in pixels. We scroll when point is
14514 within this distance from the top or bottom of the window. */
14515 if (scroll_margin
> 0)
14516 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14517 * frame_line_height
;
14519 this_scroll_margin
= 0;
14521 /* Force arg_scroll_conservatively to have a reasonable value, to
14522 avoid scrolling too far away with slow move_it_* functions. Note
14523 that the user can supply scroll-conservatively equal to
14524 `most-positive-fixnum', which can be larger than INT_MAX. */
14525 if (arg_scroll_conservatively
> scroll_limit
)
14527 arg_scroll_conservatively
= scroll_limit
+ 1;
14528 scroll_max
= scroll_limit
* frame_line_height
;
14530 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14531 /* Compute how much we should try to scroll maximally to bring
14532 point into view. */
14533 scroll_max
= (max (scroll_step
,
14534 max (arg_scroll_conservatively
, temp_scroll_step
))
14535 * frame_line_height
);
14536 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14537 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14538 /* We're trying to scroll because of aggressive scrolling but no
14539 scroll_step is set. Choose an arbitrary one. */
14540 scroll_max
= 10 * frame_line_height
;
14546 /* Decide whether to scroll down. */
14547 if (PT
> CHARPOS (startp
))
14549 int scroll_margin_y
;
14551 /* Compute the pixel ypos of the scroll margin, then move IT to
14552 either that ypos or PT, whichever comes first. */
14553 start_display (&it
, w
, startp
);
14554 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14555 - frame_line_height
* extra_scroll_margin_lines
;
14556 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14557 (MOVE_TO_POS
| MOVE_TO_Y
));
14559 if (PT
> CHARPOS (it
.current
.pos
))
14561 int y0
= line_bottom_y (&it
);
14562 /* Compute how many pixels below window bottom to stop searching
14563 for PT. This avoids costly search for PT that is far away if
14564 the user limited scrolling by a small number of lines, but
14565 always finds PT if scroll_conservatively is set to a large
14566 number, such as most-positive-fixnum. */
14567 int slack
= max (scroll_max
, 10 * frame_line_height
);
14568 int y_to_move
= it
.last_visible_y
+ slack
;
14570 /* Compute the distance from the scroll margin to PT or to
14571 the scroll limit, whichever comes first. This should
14572 include the height of the cursor line, to make that line
14574 move_it_to (&it
, PT
, -1, y_to_move
,
14575 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14576 dy
= line_bottom_y (&it
) - y0
;
14578 if (dy
> scroll_max
)
14579 return SCROLLING_FAILED
;
14588 /* Point is in or below the bottom scroll margin, so move the
14589 window start down. If scrolling conservatively, move it just
14590 enough down to make point visible. If scroll_step is set,
14591 move it down by scroll_step. */
14592 if (arg_scroll_conservatively
)
14594 = min (max (dy
, frame_line_height
),
14595 frame_line_height
* arg_scroll_conservatively
);
14596 else if (scroll_step
|| temp_scroll_step
)
14597 amount_to_scroll
= scroll_max
;
14600 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14601 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14602 if (NUMBERP (aggressive
))
14604 double float_amount
= XFLOATINT (aggressive
) * height
;
14605 int aggressive_scroll
= float_amount
;
14606 if (aggressive_scroll
== 0 && float_amount
> 0)
14607 aggressive_scroll
= 1;
14608 /* Don't let point enter the scroll margin near top of
14609 the window. This could happen if the value of
14610 scroll_up_aggressively is too large and there are
14611 non-zero margins, because scroll_up_aggressively
14612 means put point that fraction of window height
14613 _from_the_bottom_margin_. */
14614 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14615 aggressive_scroll
= height
- 2*this_scroll_margin
;
14616 amount_to_scroll
= dy
+ aggressive_scroll
;
14620 if (amount_to_scroll
<= 0)
14621 return SCROLLING_FAILED
;
14623 start_display (&it
, w
, startp
);
14624 if (arg_scroll_conservatively
<= scroll_limit
)
14625 move_it_vertically (&it
, amount_to_scroll
);
14628 /* Extra precision for users who set scroll-conservatively
14629 to a large number: make sure the amount we scroll
14630 the window start is never less than amount_to_scroll,
14631 which was computed as distance from window bottom to
14632 point. This matters when lines at window top and lines
14633 below window bottom have different height. */
14635 void *it1data
= NULL
;
14636 /* We use a temporary it1 because line_bottom_y can modify
14637 its argument, if it moves one line down; see there. */
14640 SAVE_IT (it1
, it
, it1data
);
14641 start_y
= line_bottom_y (&it1
);
14643 RESTORE_IT (&it
, &it
, it1data
);
14644 move_it_by_lines (&it
, 1);
14645 SAVE_IT (it1
, it
, it1data
);
14646 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14649 /* If STARTP is unchanged, move it down another screen line. */
14650 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14651 move_it_by_lines (&it
, 1);
14652 startp
= it
.current
.pos
;
14656 struct text_pos scroll_margin_pos
= startp
;
14659 /* See if point is inside the scroll margin at the top of the
14661 if (this_scroll_margin
)
14665 start_display (&it
, w
, startp
);
14666 y_start
= it
.current_y
;
14667 move_it_vertically (&it
, this_scroll_margin
);
14668 scroll_margin_pos
= it
.current
.pos
;
14669 /* If we didn't move enough before hitting ZV, request
14670 additional amount of scroll, to move point out of the
14672 if (IT_CHARPOS (it
) == ZV
14673 && it
.current_y
- y_start
< this_scroll_margin
)
14674 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14677 if (PT
< CHARPOS (scroll_margin_pos
))
14679 /* Point is in the scroll margin at the top of the window or
14680 above what is displayed in the window. */
14683 /* Compute the vertical distance from PT to the scroll
14684 margin position. Move as far as scroll_max allows, or
14685 one screenful, or 10 screen lines, whichever is largest.
14686 Give up if distance is greater than scroll_max or if we
14687 didn't reach the scroll margin position. */
14688 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14689 start_display (&it
, w
, pos
);
14691 y_to_move
= max (it
.last_visible_y
,
14692 max (scroll_max
, 10 * frame_line_height
));
14693 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14695 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14696 dy
= it
.current_y
- y0
;
14697 if (dy
> scroll_max
14698 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14699 return SCROLLING_FAILED
;
14701 /* Additional scroll for when ZV was too close to point. */
14704 /* Compute new window start. */
14705 start_display (&it
, w
, startp
);
14707 if (arg_scroll_conservatively
)
14708 amount_to_scroll
= max (dy
, frame_line_height
*
14709 max (scroll_step
, temp_scroll_step
));
14710 else if (scroll_step
|| temp_scroll_step
)
14711 amount_to_scroll
= scroll_max
;
14714 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14715 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14716 if (NUMBERP (aggressive
))
14718 double float_amount
= XFLOATINT (aggressive
) * height
;
14719 int aggressive_scroll
= float_amount
;
14720 if (aggressive_scroll
== 0 && float_amount
> 0)
14721 aggressive_scroll
= 1;
14722 /* Don't let point enter the scroll margin near
14723 bottom of the window, if the value of
14724 scroll_down_aggressively happens to be too
14726 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14727 aggressive_scroll
= height
- 2*this_scroll_margin
;
14728 amount_to_scroll
= dy
+ aggressive_scroll
;
14732 if (amount_to_scroll
<= 0)
14733 return SCROLLING_FAILED
;
14735 move_it_vertically_backward (&it
, amount_to_scroll
);
14736 startp
= it
.current
.pos
;
14740 /* Run window scroll functions. */
14741 startp
= run_window_scroll_functions (window
, startp
);
14743 /* Display the window. Give up if new fonts are loaded, or if point
14745 if (!try_window (window
, startp
, 0))
14746 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14747 else if (w
->cursor
.vpos
< 0)
14749 clear_glyph_matrix (w
->desired_matrix
);
14750 rc
= SCROLLING_FAILED
;
14754 /* Maybe forget recorded base line for line number display. */
14755 if (!just_this_one_p
14756 || current_buffer
->clip_changed
14757 || BEG_UNCHANGED
< CHARPOS (startp
))
14758 w
->base_line_number
= 0;
14760 /* If cursor ends up on a partially visible line,
14761 treat that as being off the bottom of the screen. */
14762 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14763 /* It's possible that the cursor is on the first line of the
14764 buffer, which is partially obscured due to a vscroll
14765 (Bug#7537). In that case, avoid looping forever . */
14766 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14768 clear_glyph_matrix (w
->desired_matrix
);
14769 ++extra_scroll_margin_lines
;
14772 rc
= SCROLLING_SUCCESS
;
14779 /* Compute a suitable window start for window W if display of W starts
14780 on a continuation line. Value is non-zero if a new window start
14783 The new window start will be computed, based on W's width, starting
14784 from the start of the continued line. It is the start of the
14785 screen line with the minimum distance from the old start W->start. */
14788 compute_window_start_on_continuation_line (struct window
*w
)
14790 struct text_pos pos
, start_pos
;
14791 int window_start_changed_p
= 0;
14793 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14795 /* If window start is on a continuation line... Window start may be
14796 < BEGV in case there's invisible text at the start of the
14797 buffer (M-x rmail, for example). */
14798 if (CHARPOS (start_pos
) > BEGV
14799 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14802 struct glyph_row
*row
;
14804 /* Handle the case that the window start is out of range. */
14805 if (CHARPOS (start_pos
) < BEGV
)
14806 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14807 else if (CHARPOS (start_pos
) > ZV
)
14808 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14810 /* Find the start of the continued line. This should be fast
14811 because find_newline is fast (newline cache). */
14812 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14813 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14814 row
, DEFAULT_FACE_ID
);
14815 reseat_at_previous_visible_line_start (&it
);
14817 /* If the line start is "too far" away from the window start,
14818 say it takes too much time to compute a new window start. */
14819 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14820 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14822 int min_distance
, distance
;
14824 /* Move forward by display lines to find the new window
14825 start. If window width was enlarged, the new start can
14826 be expected to be > the old start. If window width was
14827 decreased, the new window start will be < the old start.
14828 So, we're looking for the display line start with the
14829 minimum distance from the old window start. */
14830 pos
= it
.current
.pos
;
14831 min_distance
= INFINITY
;
14832 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14833 distance
< min_distance
)
14835 min_distance
= distance
;
14836 pos
= it
.current
.pos
;
14837 if (it
.line_wrap
== WORD_WRAP
)
14839 /* Under WORD_WRAP, move_it_by_lines is likely to
14840 overshoot and stop not at the first, but the
14841 second character from the left margin. So in
14842 that case, we need a more tight control on the X
14843 coordinate of the iterator than move_it_by_lines
14844 promises in its contract. The method is to first
14845 go to the last (rightmost) visible character of a
14846 line, then move to the leftmost character on the
14847 next line in a separate call. */
14848 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14849 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14850 move_it_to (&it
, ZV
, 0,
14851 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14852 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14855 move_it_by_lines (&it
, 1);
14858 /* Set the window start there. */
14859 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14860 window_start_changed_p
= 1;
14864 return window_start_changed_p
;
14868 /* Try cursor movement in case text has not changed in window WINDOW,
14869 with window start STARTP. Value is
14871 CURSOR_MOVEMENT_SUCCESS if successful
14873 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14875 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14876 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14877 we want to scroll as if scroll-step were set to 1. See the code.
14879 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14880 which case we have to abort this redisplay, and adjust matrices
14885 CURSOR_MOVEMENT_SUCCESS
,
14886 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14887 CURSOR_MOVEMENT_MUST_SCROLL
,
14888 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14892 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14894 struct window
*w
= XWINDOW (window
);
14895 struct frame
*f
= XFRAME (w
->frame
);
14896 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14899 if (inhibit_try_cursor_movement
)
14903 /* Previously, there was a check for Lisp integer in the
14904 if-statement below. Now, this field is converted to
14905 ptrdiff_t, thus zero means invalid position in a buffer. */
14906 eassert (w
->last_point
> 0);
14907 /* Likewise there was a check whether window_end_vpos is nil or larger
14908 than the window. Now window_end_vpos is int and so never nil, but
14909 let's leave eassert to check whether it fits in the window. */
14910 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
14912 /* Handle case where text has not changed, only point, and it has
14913 not moved off the frame. */
14914 if (/* Point may be in this window. */
14915 PT
>= CHARPOS (startp
)
14916 /* Selective display hasn't changed. */
14917 && !current_buffer
->clip_changed
14918 /* Function force-mode-line-update is used to force a thorough
14919 redisplay. It sets either windows_or_buffers_changed or
14920 update_mode_lines. So don't take a shortcut here for these
14922 && !update_mode_lines
14923 && !windows_or_buffers_changed
14924 && !f
->cursor_type_changed
14925 && NILP (Vshow_trailing_whitespace
)
14926 /* This code is not used for mini-buffer for the sake of the case
14927 of redisplaying to replace an echo area message; since in
14928 that case the mini-buffer contents per se are usually
14929 unchanged. This code is of no real use in the mini-buffer
14930 since the handling of this_line_start_pos, etc., in redisplay
14931 handles the same cases. */
14932 && !EQ (window
, minibuf_window
)
14933 && (FRAME_WINDOW_P (f
)
14934 || !overlay_arrow_in_current_buffer_p ()))
14936 int this_scroll_margin
, top_scroll_margin
;
14937 struct glyph_row
*row
= NULL
;
14938 int frame_line_height
= default_line_pixel_height (w
);
14939 int window_total_lines
14940 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14943 debug_method_add (w
, "cursor movement");
14946 /* Scroll if point within this distance from the top or bottom
14947 of the window. This is a pixel value. */
14948 if (scroll_margin
> 0)
14950 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
14951 this_scroll_margin
*= frame_line_height
;
14954 this_scroll_margin
= 0;
14956 top_scroll_margin
= this_scroll_margin
;
14957 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14958 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14960 /* Start with the row the cursor was displayed during the last
14961 not paused redisplay. Give up if that row is not valid. */
14962 if (w
->last_cursor_vpos
< 0
14963 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
14964 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14967 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
14968 if (row
->mode_line_p
)
14970 if (!row
->enabled_p
)
14971 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14974 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14976 int scroll_p
= 0, must_scroll
= 0;
14977 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14979 if (PT
> w
->last_point
)
14981 /* Point has moved forward. */
14982 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14983 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14985 eassert (row
->enabled_p
);
14989 /* If the end position of a row equals the start
14990 position of the next row, and PT is at that position,
14991 we would rather display cursor in the next line. */
14992 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14993 && MATRIX_ROW_END_CHARPOS (row
) == PT
14994 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
14995 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14996 && !cursor_row_p (row
))
14999 /* If within the scroll margin, scroll. Note that
15000 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15001 the next line would be drawn, and that
15002 this_scroll_margin can be zero. */
15003 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15004 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15005 /* Line is completely visible last line in window
15006 and PT is to be set in the next line. */
15007 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15008 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15009 && !row
->ends_at_zv_p
15010 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15013 else if (PT
< w
->last_point
)
15015 /* Cursor has to be moved backward. Note that PT >=
15016 CHARPOS (startp) because of the outer if-statement. */
15017 while (!row
->mode_line_p
15018 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15019 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15020 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15021 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15022 row
> w
->current_matrix
->rows
15023 && (row
-1)->ends_in_newline_from_string_p
))))
15024 && (row
->y
> top_scroll_margin
15025 || CHARPOS (startp
) == BEGV
))
15027 eassert (row
->enabled_p
);
15031 /* Consider the following case: Window starts at BEGV,
15032 there is invisible, intangible text at BEGV, so that
15033 display starts at some point START > BEGV. It can
15034 happen that we are called with PT somewhere between
15035 BEGV and START. Try to handle that case. */
15036 if (row
< w
->current_matrix
->rows
15037 || row
->mode_line_p
)
15039 row
= w
->current_matrix
->rows
;
15040 if (row
->mode_line_p
)
15044 /* Due to newlines in overlay strings, we may have to
15045 skip forward over overlay strings. */
15046 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15047 && MATRIX_ROW_END_CHARPOS (row
) == PT
15048 && !cursor_row_p (row
))
15051 /* If within the scroll margin, scroll. */
15052 if (row
->y
< top_scroll_margin
15053 && CHARPOS (startp
) != BEGV
)
15058 /* Cursor did not move. So don't scroll even if cursor line
15059 is partially visible, as it was so before. */
15060 rc
= CURSOR_MOVEMENT_SUCCESS
;
15063 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15064 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15066 /* if PT is not in the glyph row, give up. */
15067 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15070 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15071 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15073 struct glyph_row
*row1
;
15075 /* If rows are bidi-reordered and point moved, back up
15076 until we find a row that does not belong to a
15077 continuation line. This is because we must consider
15078 all rows of a continued line as candidates for the
15079 new cursor positioning, since row start and end
15080 positions change non-linearly with vertical position
15082 /* FIXME: Revisit this when glyph ``spilling'' in
15083 continuation lines' rows is implemented for
15084 bidi-reordered rows. */
15085 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15086 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15089 /* If we hit the beginning of the displayed portion
15090 without finding the first row of a continued
15094 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15097 eassert (row
->enabled_p
);
15102 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15103 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15104 /* Make sure this isn't a header line by any chance, since
15105 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15106 && !row
->mode_line_p
15107 && make_cursor_line_fully_visible_p
)
15109 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15110 && !row
->ends_at_zv_p
15111 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15112 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15113 else if (row
->height
> window_box_height (w
))
15115 /* If we end up in a partially visible line, let's
15116 make it fully visible, except when it's taller
15117 than the window, in which case we can't do much
15120 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15124 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15125 if (!cursor_row_fully_visible_p (w
, 0, 1))
15126 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15128 rc
= CURSOR_MOVEMENT_SUCCESS
;
15132 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15133 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15134 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15136 /* With bidi-reordered rows, there could be more than
15137 one candidate row whose start and end positions
15138 occlude point. We need to let set_cursor_from_row
15139 find the best candidate. */
15140 /* FIXME: Revisit this when glyph ``spilling'' in
15141 continuation lines' rows is implemented for
15142 bidi-reordered rows. */
15147 int at_zv_p
= 0, exact_match_p
= 0;
15149 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15150 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15151 && cursor_row_p (row
))
15152 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15154 /* As soon as we've found the exact match for point,
15155 or the first suitable row whose ends_at_zv_p flag
15156 is set, we are done. */
15158 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15160 && w
->cursor
.hpos
>= 0
15161 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15164 struct glyph_row
*candidate
=
15165 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15167 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15168 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15171 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15172 || (INTEGERP (g
->object
)
15173 && (g
->charpos
== PT
15174 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15176 if (rv
&& (at_zv_p
|| exact_match_p
))
15178 rc
= CURSOR_MOVEMENT_SUCCESS
;
15181 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15185 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15186 || row
->continued_p
)
15187 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15188 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15189 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15190 /* If we didn't find any candidate rows, or exited the
15191 loop before all the candidates were examined, signal
15192 to the caller that this method failed. */
15193 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15195 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15196 && !row
->continued_p
))
15197 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15199 rc
= CURSOR_MOVEMENT_SUCCESS
;
15205 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15207 rc
= CURSOR_MOVEMENT_SUCCESS
;
15212 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15213 && MATRIX_ROW_START_CHARPOS (row
) == PT
15214 && cursor_row_p (row
));
15222 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15226 set_vertical_scroll_bar (struct window
*w
)
15228 ptrdiff_t start
, end
, whole
;
15230 /* Calculate the start and end positions for the current window.
15231 At some point, it would be nice to choose between scrollbars
15232 which reflect the whole buffer size, with special markers
15233 indicating narrowing, and scrollbars which reflect only the
15236 Note that mini-buffers sometimes aren't displaying any text. */
15237 if (!MINI_WINDOW_P (w
)
15238 || (w
== XWINDOW (minibuf_window
)
15239 && NILP (echo_area_buffer
[0])))
15241 struct buffer
*buf
= XBUFFER (w
->contents
);
15242 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15243 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15244 /* I don't think this is guaranteed to be right. For the
15245 moment, we'll pretend it is. */
15246 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15250 if (whole
< (end
- start
))
15251 whole
= end
- start
;
15254 start
= end
= whole
= 0;
15256 /* Indicate what this scroll bar ought to be displaying now. */
15257 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15258 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15259 (w
, end
- start
, whole
, start
);
15263 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15264 selected_window is redisplayed.
15266 We can return without actually redisplaying the window if fonts has been
15267 changed on window's frame. In that case, redisplay_internal will retry. */
15270 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15272 struct window
*w
= XWINDOW (window
);
15273 struct frame
*f
= XFRAME (w
->frame
);
15274 struct buffer
*buffer
= XBUFFER (w
->contents
);
15275 struct buffer
*old
= current_buffer
;
15276 struct text_pos lpoint
, opoint
, startp
;
15277 int update_mode_line
;
15280 /* Record it now because it's overwritten. */
15281 int current_matrix_up_to_date_p
= 0;
15282 int used_current_matrix_p
= 0;
15283 /* This is less strict than current_matrix_up_to_date_p.
15284 It indicates that the buffer contents and narrowing are unchanged. */
15285 int buffer_unchanged_p
= 0;
15286 int temp_scroll_step
= 0;
15287 ptrdiff_t count
= SPECPDL_INDEX ();
15289 int centering_position
= -1;
15290 int last_line_misfit
= 0;
15291 ptrdiff_t beg_unchanged
, end_unchanged
;
15292 int frame_line_height
;
15294 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15298 *w
->desired_matrix
->method
= 0;
15301 /* Make sure that both W's markers are valid. */
15302 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15303 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15306 reconsider_clip_changes (w
);
15307 frame_line_height
= default_line_pixel_height (w
);
15309 /* Has the mode line to be updated? */
15310 update_mode_line
= (w
->update_mode_line
15311 || update_mode_lines
15312 || buffer
->clip_changed
15313 || buffer
->prevent_redisplay_optimizations_p
);
15315 if (MINI_WINDOW_P (w
))
15317 if (w
== XWINDOW (echo_area_window
)
15318 && !NILP (echo_area_buffer
[0]))
15320 if (update_mode_line
)
15321 /* We may have to update a tty frame's menu bar or a
15322 tool-bar. Example `M-x C-h C-h C-g'. */
15323 goto finish_menu_bars
;
15325 /* We've already displayed the echo area glyphs in this window. */
15326 goto finish_scroll_bars
;
15328 else if ((w
!= XWINDOW (minibuf_window
)
15329 || minibuf_level
== 0)
15330 /* When buffer is nonempty, redisplay window normally. */
15331 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15332 /* Quail displays non-mini buffers in minibuffer window.
15333 In that case, redisplay the window normally. */
15334 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15336 /* W is a mini-buffer window, but it's not active, so clear
15338 int yb
= window_text_bottom_y (w
);
15339 struct glyph_row
*row
;
15342 for (y
= 0, row
= w
->desired_matrix
->rows
;
15344 y
+= row
->height
, ++row
)
15345 blank_row (w
, row
, y
);
15346 goto finish_scroll_bars
;
15349 clear_glyph_matrix (w
->desired_matrix
);
15352 /* Otherwise set up data on this window; select its buffer and point
15354 /* Really select the buffer, for the sake of buffer-local
15356 set_buffer_internal_1 (XBUFFER (w
->contents
));
15358 current_matrix_up_to_date_p
15359 = (w
->window_end_valid
15360 && !current_buffer
->clip_changed
15361 && !current_buffer
->prevent_redisplay_optimizations_p
15362 && !window_outdated (w
));
15364 /* Run the window-bottom-change-functions
15365 if it is possible that the text on the screen has changed
15366 (either due to modification of the text, or any other reason). */
15367 if (!current_matrix_up_to_date_p
15368 && !NILP (Vwindow_text_change_functions
))
15370 safe_run_hooks (Qwindow_text_change_functions
);
15374 beg_unchanged
= BEG_UNCHANGED
;
15375 end_unchanged
= END_UNCHANGED
;
15377 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15379 specbind (Qinhibit_point_motion_hooks
, Qt
);
15382 = (w
->window_end_valid
15383 && !current_buffer
->clip_changed
15384 && !window_outdated (w
));
15386 /* When windows_or_buffers_changed is non-zero, we can't rely
15387 on the window end being valid, so set it to zero there. */
15388 if (windows_or_buffers_changed
)
15390 /* If window starts on a continuation line, maybe adjust the
15391 window start in case the window's width changed. */
15392 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15393 compute_window_start_on_continuation_line (w
);
15395 w
->window_end_valid
= 0;
15396 /* If so, we also can't rely on current matrix
15397 and should not fool try_cursor_movement below. */
15398 current_matrix_up_to_date_p
= 0;
15401 /* Some sanity checks. */
15402 CHECK_WINDOW_END (w
);
15403 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15405 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15408 if (mode_line_update_needed (w
))
15409 update_mode_line
= 1;
15411 /* Point refers normally to the selected window. For any other
15412 window, set up appropriate value. */
15413 if (!EQ (window
, selected_window
))
15415 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15416 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15420 new_pt_byte
= BEGV_BYTE
;
15421 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15423 else if (new_pt
> (ZV
- 1))
15426 new_pt_byte
= ZV_BYTE
;
15427 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15430 /* We don't use SET_PT so that the point-motion hooks don't run. */
15431 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15434 /* If any of the character widths specified in the display table
15435 have changed, invalidate the width run cache. It's true that
15436 this may be a bit late to catch such changes, but the rest of
15437 redisplay goes (non-fatally) haywire when the display table is
15438 changed, so why should we worry about doing any better? */
15439 if (current_buffer
->width_run_cache
)
15441 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15443 if (! disptab_matches_widthtab
15444 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15446 invalidate_region_cache (current_buffer
,
15447 current_buffer
->width_run_cache
,
15449 recompute_width_table (current_buffer
, disptab
);
15453 /* If window-start is screwed up, choose a new one. */
15454 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15457 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15459 /* If someone specified a new starting point but did not insist,
15460 check whether it can be used. */
15461 if (w
->optional_new_start
15462 && CHARPOS (startp
) >= BEGV
15463 && CHARPOS (startp
) <= ZV
)
15465 w
->optional_new_start
= 0;
15466 start_display (&it
, w
, startp
);
15467 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15468 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15469 if (IT_CHARPOS (it
) == PT
)
15470 w
->force_start
= 1;
15471 /* IT may overshoot PT if text at PT is invisible. */
15472 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15473 w
->force_start
= 1;
15478 /* Handle case where place to start displaying has been specified,
15479 unless the specified location is outside the accessible range. */
15480 if (w
->force_start
|| window_frozen_p (w
))
15482 /* We set this later on if we have to adjust point. */
15485 w
->force_start
= 0;
15487 w
->window_end_valid
= 0;
15489 /* Forget any recorded base line for line number display. */
15490 if (!buffer_unchanged_p
)
15491 w
->base_line_number
= 0;
15493 /* Redisplay the mode line. Select the buffer properly for that.
15494 Also, run the hook window-scroll-functions
15495 because we have scrolled. */
15496 /* Note, we do this after clearing force_start because
15497 if there's an error, it is better to forget about force_start
15498 than to get into an infinite loop calling the hook functions
15499 and having them get more errors. */
15500 if (!update_mode_line
15501 || ! NILP (Vwindow_scroll_functions
))
15503 update_mode_line
= 1;
15504 w
->update_mode_line
= 1;
15505 startp
= run_window_scroll_functions (window
, startp
);
15508 if (CHARPOS (startp
) < BEGV
)
15509 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15510 else if (CHARPOS (startp
) > ZV
)
15511 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15513 /* Redisplay, then check if cursor has been set during the
15514 redisplay. Give up if new fonts were loaded. */
15515 /* We used to issue a CHECK_MARGINS argument to try_window here,
15516 but this causes scrolling to fail when point begins inside
15517 the scroll margin (bug#148) -- cyd */
15518 if (!try_window (window
, startp
, 0))
15520 w
->force_start
= 1;
15521 clear_glyph_matrix (w
->desired_matrix
);
15522 goto need_larger_matrices
;
15525 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15527 /* If point does not appear, try to move point so it does
15528 appear. The desired matrix has been built above, so we
15529 can use it here. */
15530 new_vpos
= window_box_height (w
) / 2;
15533 if (!cursor_row_fully_visible_p (w
, 0, 0))
15535 /* Point does appear, but on a line partly visible at end of window.
15536 Move it back to a fully-visible line. */
15537 new_vpos
= window_box_height (w
);
15539 else if (w
->cursor
.vpos
>= 0)
15541 /* Some people insist on not letting point enter the scroll
15542 margin, even though this part handles windows that didn't
15544 int window_total_lines
15545 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15546 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15547 int pixel_margin
= margin
* frame_line_height
;
15548 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15550 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15551 below, which finds the row to move point to, advances by
15552 the Y coordinate of the _next_ row, see the definition of
15553 MATRIX_ROW_BOTTOM_Y. */
15554 if (w
->cursor
.vpos
< margin
+ header_line
)
15556 w
->cursor
.vpos
= -1;
15557 clear_glyph_matrix (w
->desired_matrix
);
15558 goto try_to_scroll
;
15562 int window_height
= window_box_height (w
);
15565 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15566 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15568 w
->cursor
.vpos
= -1;
15569 clear_glyph_matrix (w
->desired_matrix
);
15570 goto try_to_scroll
;
15575 /* If we need to move point for either of the above reasons,
15576 now actually do it. */
15579 struct glyph_row
*row
;
15581 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15582 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15585 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15586 MATRIX_ROW_START_BYTEPOS (row
));
15588 if (w
!= XWINDOW (selected_window
))
15589 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15590 else if (current_buffer
== old
)
15591 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15593 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15595 /* If we are highlighting the region, then we just changed
15596 the region, so redisplay to show it. */
15597 /* FIXME: We need to (re)run pre-redisplay-function! */
15598 /* if (markpos_of_region () >= 0)
15600 clear_glyph_matrix (w->desired_matrix);
15601 if (!try_window (window, startp, 0))
15602 goto need_larger_matrices;
15608 debug_method_add (w
, "forced window start");
15613 /* Handle case where text has not changed, only point, and it has
15614 not moved off the frame, and we are not retrying after hscroll.
15615 (current_matrix_up_to_date_p is nonzero when retrying.) */
15616 if (current_matrix_up_to_date_p
15617 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15618 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15622 case CURSOR_MOVEMENT_SUCCESS
:
15623 used_current_matrix_p
= 1;
15626 case CURSOR_MOVEMENT_MUST_SCROLL
:
15627 goto try_to_scroll
;
15633 /* If current starting point was originally the beginning of a line
15634 but no longer is, find a new starting point. */
15635 else if (w
->start_at_line_beg
15636 && !(CHARPOS (startp
) <= BEGV
15637 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15640 debug_method_add (w
, "recenter 1");
15645 /* Try scrolling with try_window_id. Value is > 0 if update has
15646 been done, it is -1 if we know that the same window start will
15647 not work. It is 0 if unsuccessful for some other reason. */
15648 else if ((tem
= try_window_id (w
)) != 0)
15651 debug_method_add (w
, "try_window_id %d", tem
);
15654 if (f
->fonts_changed
)
15655 goto need_larger_matrices
;
15659 /* Otherwise try_window_id has returned -1 which means that we
15660 don't want the alternative below this comment to execute. */
15662 else if (CHARPOS (startp
) >= BEGV
15663 && CHARPOS (startp
) <= ZV
15664 && PT
>= CHARPOS (startp
)
15665 && (CHARPOS (startp
) < ZV
15666 /* Avoid starting at end of buffer. */
15667 || CHARPOS (startp
) == BEGV
15668 || !window_outdated (w
)))
15670 int d1
, d2
, d3
, d4
, d5
, d6
;
15672 /* If first window line is a continuation line, and window start
15673 is inside the modified region, but the first change is before
15674 current window start, we must select a new window start.
15676 However, if this is the result of a down-mouse event (e.g. by
15677 extending the mouse-drag-overlay), we don't want to select a
15678 new window start, since that would change the position under
15679 the mouse, resulting in an unwanted mouse-movement rather
15680 than a simple mouse-click. */
15681 if (!w
->start_at_line_beg
15682 && NILP (do_mouse_tracking
)
15683 && CHARPOS (startp
) > BEGV
15684 && CHARPOS (startp
) > BEG
+ beg_unchanged
15685 && CHARPOS (startp
) <= Z
- end_unchanged
15686 /* Even if w->start_at_line_beg is nil, a new window may
15687 start at a line_beg, since that's how set_buffer_window
15688 sets it. So, we need to check the return value of
15689 compute_window_start_on_continuation_line. (See also
15691 && XMARKER (w
->start
)->buffer
== current_buffer
15692 && compute_window_start_on_continuation_line (w
)
15693 /* It doesn't make sense to force the window start like we
15694 do at label force_start if it is already known that point
15695 will not be visible in the resulting window, because
15696 doing so will move point from its correct position
15697 instead of scrolling the window to bring point into view.
15699 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15701 w
->force_start
= 1;
15702 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15707 debug_method_add (w
, "same window start");
15710 /* Try to redisplay starting at same place as before.
15711 If point has not moved off frame, accept the results. */
15712 if (!current_matrix_up_to_date_p
15713 /* Don't use try_window_reusing_current_matrix in this case
15714 because a window scroll function can have changed the
15716 || !NILP (Vwindow_scroll_functions
)
15717 || MINI_WINDOW_P (w
)
15718 || !(used_current_matrix_p
15719 = try_window_reusing_current_matrix (w
)))
15721 IF_DEBUG (debug_method_add (w
, "1"));
15722 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15723 /* -1 means we need to scroll.
15724 0 means we need new matrices, but fonts_changed
15725 is set in that case, so we will detect it below. */
15726 goto try_to_scroll
;
15729 if (f
->fonts_changed
)
15730 goto need_larger_matrices
;
15732 if (w
->cursor
.vpos
>= 0)
15734 if (!just_this_one_p
15735 || current_buffer
->clip_changed
15736 || BEG_UNCHANGED
< CHARPOS (startp
))
15737 /* Forget any recorded base line for line number display. */
15738 w
->base_line_number
= 0;
15740 if (!cursor_row_fully_visible_p (w
, 1, 0))
15742 clear_glyph_matrix (w
->desired_matrix
);
15743 last_line_misfit
= 1;
15745 /* Drop through and scroll. */
15750 clear_glyph_matrix (w
->desired_matrix
);
15755 /* Redisplay the mode line. Select the buffer properly for that. */
15756 if (!update_mode_line
)
15758 update_mode_line
= 1;
15759 w
->update_mode_line
= 1;
15762 /* Try to scroll by specified few lines. */
15763 if ((scroll_conservatively
15764 || emacs_scroll_step
15765 || temp_scroll_step
15766 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15767 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15768 && CHARPOS (startp
) >= BEGV
15769 && CHARPOS (startp
) <= ZV
)
15771 /* The function returns -1 if new fonts were loaded, 1 if
15772 successful, 0 if not successful. */
15773 int ss
= try_scrolling (window
, just_this_one_p
,
15774 scroll_conservatively
,
15776 temp_scroll_step
, last_line_misfit
);
15779 case SCROLLING_SUCCESS
:
15782 case SCROLLING_NEED_LARGER_MATRICES
:
15783 goto need_larger_matrices
;
15785 case SCROLLING_FAILED
:
15793 /* Finally, just choose a place to start which positions point
15794 according to user preferences. */
15799 debug_method_add (w
, "recenter");
15802 /* Forget any previously recorded base line for line number display. */
15803 if (!buffer_unchanged_p
)
15804 w
->base_line_number
= 0;
15806 /* Determine the window start relative to point. */
15807 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15808 it
.current_y
= it
.last_visible_y
;
15809 if (centering_position
< 0)
15811 int window_total_lines
15812 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15815 ? min (scroll_margin
, window_total_lines
/ 4)
15817 ptrdiff_t margin_pos
= CHARPOS (startp
);
15818 Lisp_Object aggressive
;
15821 /* If there is a scroll margin at the top of the window, find
15822 its character position. */
15824 /* Cannot call start_display if startp is not in the
15825 accessible region of the buffer. This can happen when we
15826 have just switched to a different buffer and/or changed
15827 its restriction. In that case, startp is initialized to
15828 the character position 1 (BEGV) because we did not yet
15829 have chance to display the buffer even once. */
15830 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15833 void *it1data
= NULL
;
15835 SAVE_IT (it1
, it
, it1data
);
15836 start_display (&it1
, w
, startp
);
15837 move_it_vertically (&it1
, margin
* frame_line_height
);
15838 margin_pos
= IT_CHARPOS (it1
);
15839 RESTORE_IT (&it
, &it
, it1data
);
15841 scrolling_up
= PT
> margin_pos
;
15844 ? BVAR (current_buffer
, scroll_up_aggressively
)
15845 : BVAR (current_buffer
, scroll_down_aggressively
);
15847 if (!MINI_WINDOW_P (w
)
15848 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15852 /* Setting scroll-conservatively overrides
15853 scroll-*-aggressively. */
15854 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15856 double float_amount
= XFLOATINT (aggressive
);
15858 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15859 if (pt_offset
== 0 && float_amount
> 0)
15861 if (pt_offset
&& margin
> 0)
15864 /* Compute how much to move the window start backward from
15865 point so that point will be displayed where the user
15869 centering_position
= it
.last_visible_y
;
15871 centering_position
-= pt_offset
;
15872 centering_position
-=
15873 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15874 + WINDOW_HEADER_LINE_HEIGHT (w
);
15875 /* Don't let point enter the scroll margin near top of
15877 if (centering_position
< margin
* frame_line_height
)
15878 centering_position
= margin
* frame_line_height
;
15881 centering_position
= margin
* frame_line_height
+ pt_offset
;
15884 /* Set the window start half the height of the window backward
15886 centering_position
= window_box_height (w
) / 2;
15888 move_it_vertically_backward (&it
, centering_position
);
15890 eassert (IT_CHARPOS (it
) >= BEGV
);
15892 /* The function move_it_vertically_backward may move over more
15893 than the specified y-distance. If it->w is small, e.g. a
15894 mini-buffer window, we may end up in front of the window's
15895 display area. Start displaying at the start of the line
15896 containing PT in this case. */
15897 if (it
.current_y
<= 0)
15899 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15900 move_it_vertically_backward (&it
, 0);
15904 it
.current_x
= it
.hpos
= 0;
15906 /* Set the window start position here explicitly, to avoid an
15907 infinite loop in case the functions in window-scroll-functions
15909 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15911 /* Run scroll hooks. */
15912 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15914 /* Redisplay the window. */
15915 if (!current_matrix_up_to_date_p
15916 || windows_or_buffers_changed
15917 || f
->cursor_type_changed
15918 /* Don't use try_window_reusing_current_matrix in this case
15919 because it can have changed the buffer. */
15920 || !NILP (Vwindow_scroll_functions
)
15921 || !just_this_one_p
15922 || MINI_WINDOW_P (w
)
15923 || !(used_current_matrix_p
15924 = try_window_reusing_current_matrix (w
)))
15925 try_window (window
, startp
, 0);
15927 /* If new fonts have been loaded (due to fontsets), give up. We
15928 have to start a new redisplay since we need to re-adjust glyph
15930 if (f
->fonts_changed
)
15931 goto need_larger_matrices
;
15933 /* If cursor did not appear assume that the middle of the window is
15934 in the first line of the window. Do it again with the next line.
15935 (Imagine a window of height 100, displaying two lines of height
15936 60. Moving back 50 from it->last_visible_y will end in the first
15938 if (w
->cursor
.vpos
< 0)
15940 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
15942 clear_glyph_matrix (w
->desired_matrix
);
15943 move_it_by_lines (&it
, 1);
15944 try_window (window
, it
.current
.pos
, 0);
15946 else if (PT
< IT_CHARPOS (it
))
15948 clear_glyph_matrix (w
->desired_matrix
);
15949 move_it_by_lines (&it
, -1);
15950 try_window (window
, it
.current
.pos
, 0);
15954 /* Not much we can do about it. */
15958 /* Consider the following case: Window starts at BEGV, there is
15959 invisible, intangible text at BEGV, so that display starts at
15960 some point START > BEGV. It can happen that we are called with
15961 PT somewhere between BEGV and START. Try to handle that case. */
15962 if (w
->cursor
.vpos
< 0)
15964 struct glyph_row
*row
= w
->current_matrix
->rows
;
15965 if (row
->mode_line_p
)
15967 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15970 if (!cursor_row_fully_visible_p (w
, 0, 0))
15972 /* If vscroll is enabled, disable it and try again. */
15976 clear_glyph_matrix (w
->desired_matrix
);
15980 /* Users who set scroll-conservatively to a large number want
15981 point just above/below the scroll margin. If we ended up
15982 with point's row partially visible, move the window start to
15983 make that row fully visible and out of the margin. */
15984 if (scroll_conservatively
> SCROLL_LIMIT
)
15986 int window_total_lines
15987 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
15990 ? min (scroll_margin
, window_total_lines
/ 4)
15992 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
15994 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15995 clear_glyph_matrix (w
->desired_matrix
);
15996 if (1 == try_window (window
, it
.current
.pos
,
15997 TRY_WINDOW_CHECK_MARGINS
))
16001 /* If centering point failed to make the whole line visible,
16002 put point at the top instead. That has to make the whole line
16003 visible, if it can be done. */
16004 if (centering_position
== 0)
16007 clear_glyph_matrix (w
->desired_matrix
);
16008 centering_position
= 0;
16014 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16015 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16016 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16018 /* Display the mode line, if we must. */
16019 if ((update_mode_line
16020 /* If window not full width, must redo its mode line
16021 if (a) the window to its side is being redone and
16022 (b) we do a frame-based redisplay. This is a consequence
16023 of how inverted lines are drawn in frame-based redisplay. */
16024 || (!just_this_one_p
16025 && !FRAME_WINDOW_P (f
)
16026 && !WINDOW_FULL_WIDTH_P (w
))
16027 /* Line number to display. */
16028 || w
->base_line_pos
> 0
16029 /* Column number is displayed and different from the one displayed. */
16030 || (w
->column_number_displayed
!= -1
16031 && (w
->column_number_displayed
!= current_column ())))
16032 /* This means that the window has a mode line. */
16033 && (WINDOW_WANTS_MODELINE_P (w
)
16034 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16036 display_mode_lines (w
);
16038 /* If mode line height has changed, arrange for a thorough
16039 immediate redisplay using the correct mode line height. */
16040 if (WINDOW_WANTS_MODELINE_P (w
)
16041 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16043 f
->fonts_changed
= 1;
16044 w
->mode_line_height
= -1;
16045 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16046 = DESIRED_MODE_LINE_HEIGHT (w
);
16049 /* If header line height has changed, arrange for a thorough
16050 immediate redisplay using the correct header line height. */
16051 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16052 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16054 f
->fonts_changed
= 1;
16055 w
->header_line_height
= -1;
16056 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16057 = DESIRED_HEADER_LINE_HEIGHT (w
);
16060 if (f
->fonts_changed
)
16061 goto need_larger_matrices
;
16064 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16066 w
->base_line_pos
= 0;
16067 w
->base_line_number
= 0;
16072 /* When we reach a frame's selected window, redo the frame's menu bar. */
16073 if (update_mode_line
16074 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16076 int redisplay_menu_p
= 0;
16078 if (FRAME_WINDOW_P (f
))
16080 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16081 || defined (HAVE_NS) || defined (USE_GTK)
16082 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16084 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16088 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16090 if (redisplay_menu_p
)
16091 display_menu_bar (w
);
16093 #ifdef HAVE_WINDOW_SYSTEM
16094 if (FRAME_WINDOW_P (f
))
16096 #if defined (USE_GTK) || defined (HAVE_NS)
16097 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16098 redisplay_tool_bar (f
);
16100 if (WINDOWP (f
->tool_bar_window
)
16101 && (FRAME_TOOL_BAR_LINES (f
) > 0
16102 || !NILP (Vauto_resize_tool_bars
))
16103 && redisplay_tool_bar (f
))
16104 ignore_mouse_drag_p
= 1;
16110 #ifdef HAVE_WINDOW_SYSTEM
16111 if (FRAME_WINDOW_P (f
)
16112 && update_window_fringes (w
, (just_this_one_p
16113 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16114 || w
->pseudo_window_p
)))
16118 if (draw_window_fringes (w
, 1))
16119 x_draw_vertical_border (w
);
16123 #endif /* HAVE_WINDOW_SYSTEM */
16125 /* We go to this label, with fonts_changed set, if it is
16126 necessary to try again using larger glyph matrices.
16127 We have to redeem the scroll bar even in this case,
16128 because the loop in redisplay_internal expects that. */
16129 need_larger_matrices
:
16131 finish_scroll_bars
:
16133 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16135 /* Set the thumb's position and size. */
16136 set_vertical_scroll_bar (w
);
16138 /* Note that we actually used the scroll bar attached to this
16139 window, so it shouldn't be deleted at the end of redisplay. */
16140 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16141 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16144 /* Restore current_buffer and value of point in it. The window
16145 update may have changed the buffer, so first make sure `opoint'
16146 is still valid (Bug#6177). */
16147 if (CHARPOS (opoint
) < BEGV
)
16148 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16149 else if (CHARPOS (opoint
) > ZV
)
16150 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16152 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16154 set_buffer_internal_1 (old
);
16155 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16156 shorter. This can be caused by log truncation in *Messages*. */
16157 if (CHARPOS (lpoint
) <= ZV
)
16158 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16160 unbind_to (count
, Qnil
);
16164 /* Build the complete desired matrix of WINDOW with a window start
16165 buffer position POS.
16167 Value is 1 if successful. It is zero if fonts were loaded during
16168 redisplay which makes re-adjusting glyph matrices necessary, and -1
16169 if point would appear in the scroll margins.
16170 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16171 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16175 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16177 struct window
*w
= XWINDOW (window
);
16179 struct glyph_row
*last_text_row
= NULL
;
16180 struct frame
*f
= XFRAME (w
->frame
);
16181 int frame_line_height
= default_line_pixel_height (w
);
16183 /* Make POS the new window start. */
16184 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16186 /* Mark cursor position as unknown. No overlay arrow seen. */
16187 w
->cursor
.vpos
= -1;
16188 overlay_arrow_seen
= 0;
16190 /* Initialize iterator and info to start at POS. */
16191 start_display (&it
, w
, pos
);
16193 /* Display all lines of W. */
16194 while (it
.current_y
< it
.last_visible_y
)
16196 if (display_line (&it
))
16197 last_text_row
= it
.glyph_row
- 1;
16198 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16202 /* Don't let the cursor end in the scroll margins. */
16203 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16204 && !MINI_WINDOW_P (w
))
16206 int this_scroll_margin
;
16207 int window_total_lines
16208 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16210 if (scroll_margin
> 0)
16212 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16213 this_scroll_margin
*= frame_line_height
;
16216 this_scroll_margin
= 0;
16218 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16219 && w
->cursor
.y
< this_scroll_margin
16220 && CHARPOS (pos
) > BEGV
16221 && IT_CHARPOS (it
) < ZV
)
16222 /* rms: considering make_cursor_line_fully_visible_p here
16223 seems to give wrong results. We don't want to recenter
16224 when the last line is partly visible, we want to allow
16225 that case to be handled in the usual way. */
16226 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16228 w
->cursor
.vpos
= -1;
16229 clear_glyph_matrix (w
->desired_matrix
);
16234 /* If bottom moved off end of frame, change mode line percentage. */
16235 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16236 w
->update_mode_line
= 1;
16238 /* Set window_end_pos to the offset of the last character displayed
16239 on the window from the end of current_buffer. Set
16240 window_end_vpos to its row number. */
16243 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16244 adjust_window_ends (w
, last_text_row
, 0);
16246 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16247 w
->window_end_vpos
)));
16251 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16252 w
->window_end_pos
= Z
- ZV
;
16253 w
->window_end_vpos
= 0;
16256 /* But that is not valid info until redisplay finishes. */
16257 w
->window_end_valid
= 0;
16263 /************************************************************************
16264 Window redisplay reusing current matrix when buffer has not changed
16265 ************************************************************************/
16267 /* Try redisplay of window W showing an unchanged buffer with a
16268 different window start than the last time it was displayed by
16269 reusing its current matrix. Value is non-zero if successful.
16270 W->start is the new window start. */
16273 try_window_reusing_current_matrix (struct window
*w
)
16275 struct frame
*f
= XFRAME (w
->frame
);
16276 struct glyph_row
*bottom_row
;
16279 struct text_pos start
, new_start
;
16280 int nrows_scrolled
, i
;
16281 struct glyph_row
*last_text_row
;
16282 struct glyph_row
*last_reused_text_row
;
16283 struct glyph_row
*start_row
;
16284 int start_vpos
, min_y
, max_y
;
16287 if (inhibit_try_window_reusing
)
16291 if (/* This function doesn't handle terminal frames. */
16292 !FRAME_WINDOW_P (f
)
16293 /* Don't try to reuse the display if windows have been split
16295 || windows_or_buffers_changed
16296 || f
->cursor_type_changed
)
16299 /* Can't do this if showing trailing whitespace. */
16300 if (!NILP (Vshow_trailing_whitespace
))
16303 /* If top-line visibility has changed, give up. */
16304 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16305 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16308 /* Give up if old or new display is scrolled vertically. We could
16309 make this function handle this, but right now it doesn't. */
16310 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16311 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16314 /* The variable new_start now holds the new window start. The old
16315 start `start' can be determined from the current matrix. */
16316 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16317 start
= start_row
->minpos
;
16318 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16320 /* Clear the desired matrix for the display below. */
16321 clear_glyph_matrix (w
->desired_matrix
);
16323 if (CHARPOS (new_start
) <= CHARPOS (start
))
16325 /* Don't use this method if the display starts with an ellipsis
16326 displayed for invisible text. It's not easy to handle that case
16327 below, and it's certainly not worth the effort since this is
16328 not a frequent case. */
16329 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16332 IF_DEBUG (debug_method_add (w
, "twu1"));
16334 /* Display up to a row that can be reused. The variable
16335 last_text_row is set to the last row displayed that displays
16336 text. Note that it.vpos == 0 if or if not there is a
16337 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16338 start_display (&it
, w
, new_start
);
16339 w
->cursor
.vpos
= -1;
16340 last_text_row
= last_reused_text_row
= NULL
;
16342 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16344 /* If we have reached into the characters in the START row,
16345 that means the line boundaries have changed. So we
16346 can't start copying with the row START. Maybe it will
16347 work to start copying with the following row. */
16348 while (IT_CHARPOS (it
) > CHARPOS (start
))
16350 /* Advance to the next row as the "start". */
16352 start
= start_row
->minpos
;
16353 /* If there are no more rows to try, or just one, give up. */
16354 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16355 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16356 || CHARPOS (start
) == ZV
)
16358 clear_glyph_matrix (w
->desired_matrix
);
16362 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16364 /* If we have reached alignment, we can copy the rest of the
16366 if (IT_CHARPOS (it
) == CHARPOS (start
)
16367 /* Don't accept "alignment" inside a display vector,
16368 since start_row could have started in the middle of
16369 that same display vector (thus their character
16370 positions match), and we have no way of telling if
16371 that is the case. */
16372 && it
.current
.dpvec_index
< 0)
16375 if (display_line (&it
))
16376 last_text_row
= it
.glyph_row
- 1;
16380 /* A value of current_y < last_visible_y means that we stopped
16381 at the previous window start, which in turn means that we
16382 have at least one reusable row. */
16383 if (it
.current_y
< it
.last_visible_y
)
16385 struct glyph_row
*row
;
16387 /* IT.vpos always starts from 0; it counts text lines. */
16388 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16390 /* Find PT if not already found in the lines displayed. */
16391 if (w
->cursor
.vpos
< 0)
16393 int dy
= it
.current_y
- start_row
->y
;
16395 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16396 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16398 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16399 dy
, nrows_scrolled
);
16402 clear_glyph_matrix (w
->desired_matrix
);
16407 /* Scroll the display. Do it before the current matrix is
16408 changed. The problem here is that update has not yet
16409 run, i.e. part of the current matrix is not up to date.
16410 scroll_run_hook will clear the cursor, and use the
16411 current matrix to get the height of the row the cursor is
16413 run
.current_y
= start_row
->y
;
16414 run
.desired_y
= it
.current_y
;
16415 run
.height
= it
.last_visible_y
- it
.current_y
;
16417 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16420 FRAME_RIF (f
)->update_window_begin_hook (w
);
16421 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16422 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16423 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16427 /* Shift current matrix down by nrows_scrolled lines. */
16428 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16429 rotate_matrix (w
->current_matrix
,
16431 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16434 /* Disable lines that must be updated. */
16435 for (i
= 0; i
< nrows_scrolled
; ++i
)
16436 (start_row
+ i
)->enabled_p
= 0;
16438 /* Re-compute Y positions. */
16439 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16440 max_y
= it
.last_visible_y
;
16441 for (row
= start_row
+ nrows_scrolled
;
16445 row
->y
= it
.current_y
;
16446 row
->visible_height
= row
->height
;
16448 if (row
->y
< min_y
)
16449 row
->visible_height
-= min_y
- row
->y
;
16450 if (row
->y
+ row
->height
> max_y
)
16451 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16452 if (row
->fringe_bitmap_periodic_p
)
16453 row
->redraw_fringe_bitmaps_p
= 1;
16455 it
.current_y
+= row
->height
;
16457 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16458 last_reused_text_row
= row
;
16459 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16463 /* Disable lines in the current matrix which are now
16464 below the window. */
16465 for (++row
; row
< bottom_row
; ++row
)
16466 row
->enabled_p
= row
->mode_line_p
= 0;
16469 /* Update window_end_pos etc.; last_reused_text_row is the last
16470 reused row from the current matrix containing text, if any.
16471 The value of last_text_row is the last displayed line
16472 containing text. */
16473 if (last_reused_text_row
)
16474 adjust_window_ends (w
, last_reused_text_row
, 1);
16475 else if (last_text_row
)
16476 adjust_window_ends (w
, last_text_row
, 0);
16479 /* This window must be completely empty. */
16480 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16481 w
->window_end_pos
= Z
- ZV
;
16482 w
->window_end_vpos
= 0;
16484 w
->window_end_valid
= 0;
16486 /* Update hint: don't try scrolling again in update_window. */
16487 w
->desired_matrix
->no_scrolling_p
= 1;
16490 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16494 else if (CHARPOS (new_start
) > CHARPOS (start
))
16496 struct glyph_row
*pt_row
, *row
;
16497 struct glyph_row
*first_reusable_row
;
16498 struct glyph_row
*first_row_to_display
;
16500 int yb
= window_text_bottom_y (w
);
16502 /* Find the row starting at new_start, if there is one. Don't
16503 reuse a partially visible line at the end. */
16504 first_reusable_row
= start_row
;
16505 while (first_reusable_row
->enabled_p
16506 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16507 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16508 < CHARPOS (new_start
)))
16509 ++first_reusable_row
;
16511 /* Give up if there is no row to reuse. */
16512 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16513 || !first_reusable_row
->enabled_p
16514 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16515 != CHARPOS (new_start
)))
16518 /* We can reuse fully visible rows beginning with
16519 first_reusable_row to the end of the window. Set
16520 first_row_to_display to the first row that cannot be reused.
16521 Set pt_row to the row containing point, if there is any. */
16523 for (first_row_to_display
= first_reusable_row
;
16524 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16525 ++first_row_to_display
)
16527 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16528 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16529 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16530 && first_row_to_display
->ends_at_zv_p
16531 && pt_row
== NULL
)))
16532 pt_row
= first_row_to_display
;
16535 /* Start displaying at the start of first_row_to_display. */
16536 eassert (first_row_to_display
->y
< yb
);
16537 init_to_row_start (&it
, w
, first_row_to_display
);
16539 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16541 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16543 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16544 + WINDOW_HEADER_LINE_HEIGHT (w
));
16546 /* Display lines beginning with first_row_to_display in the
16547 desired matrix. Set last_text_row to the last row displayed
16548 that displays text. */
16549 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16550 if (pt_row
== NULL
)
16551 w
->cursor
.vpos
= -1;
16552 last_text_row
= NULL
;
16553 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16554 if (display_line (&it
))
16555 last_text_row
= it
.glyph_row
- 1;
16557 /* If point is in a reused row, adjust y and vpos of the cursor
16561 w
->cursor
.vpos
-= nrows_scrolled
;
16562 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16565 /* Give up if point isn't in a row displayed or reused. (This
16566 also handles the case where w->cursor.vpos < nrows_scrolled
16567 after the calls to display_line, which can happen with scroll
16568 margins. See bug#1295.) */
16569 if (w
->cursor
.vpos
< 0)
16571 clear_glyph_matrix (w
->desired_matrix
);
16575 /* Scroll the display. */
16576 run
.current_y
= first_reusable_row
->y
;
16577 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16578 run
.height
= it
.last_visible_y
- run
.current_y
;
16579 dy
= run
.current_y
- run
.desired_y
;
16584 FRAME_RIF (f
)->update_window_begin_hook (w
);
16585 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16586 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16587 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16591 /* Adjust Y positions of reused rows. */
16592 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16593 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16594 max_y
= it
.last_visible_y
;
16595 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16598 row
->visible_height
= row
->height
;
16599 if (row
->y
< min_y
)
16600 row
->visible_height
-= min_y
- row
->y
;
16601 if (row
->y
+ row
->height
> max_y
)
16602 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16603 if (row
->fringe_bitmap_periodic_p
)
16604 row
->redraw_fringe_bitmaps_p
= 1;
16607 /* Scroll the current matrix. */
16608 eassert (nrows_scrolled
> 0);
16609 rotate_matrix (w
->current_matrix
,
16611 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16614 /* Disable rows not reused. */
16615 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16616 row
->enabled_p
= 0;
16618 /* Point may have moved to a different line, so we cannot assume that
16619 the previous cursor position is valid; locate the correct row. */
16622 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16624 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16625 && !row
->ends_at_zv_p
;
16629 w
->cursor
.y
= row
->y
;
16631 if (row
< bottom_row
)
16633 /* Can't simply scan the row for point with
16634 bidi-reordered glyph rows. Let set_cursor_from_row
16635 figure out where to put the cursor, and if it fails,
16637 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16639 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16642 clear_glyph_matrix (w
->desired_matrix
);
16648 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16649 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16652 && (!BUFFERP (glyph
->object
)
16653 || glyph
->charpos
< PT
);
16657 w
->cursor
.x
+= glyph
->pixel_width
;
16663 /* Adjust window end. A null value of last_text_row means that
16664 the window end is in reused rows which in turn means that
16665 only its vpos can have changed. */
16667 adjust_window_ends (w
, last_text_row
, 0);
16669 w
->window_end_vpos
-= nrows_scrolled
;
16671 w
->window_end_valid
= 0;
16672 w
->desired_matrix
->no_scrolling_p
= 1;
16675 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16685 /************************************************************************
16686 Window redisplay reusing current matrix when buffer has changed
16687 ************************************************************************/
16689 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16690 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16691 ptrdiff_t *, ptrdiff_t *);
16692 static struct glyph_row
*
16693 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16694 struct glyph_row
*);
16697 /* Return the last row in MATRIX displaying text. If row START is
16698 non-null, start searching with that row. IT gives the dimensions
16699 of the display. Value is null if matrix is empty; otherwise it is
16700 a pointer to the row found. */
16702 static struct glyph_row
*
16703 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16704 struct glyph_row
*start
)
16706 struct glyph_row
*row
, *row_found
;
16708 /* Set row_found to the last row in IT->w's current matrix
16709 displaying text. The loop looks funny but think of partially
16712 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16713 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16715 eassert (row
->enabled_p
);
16717 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16726 /* Return the last row in the current matrix of W that is not affected
16727 by changes at the start of current_buffer that occurred since W's
16728 current matrix was built. Value is null if no such row exists.
16730 BEG_UNCHANGED us the number of characters unchanged at the start of
16731 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16732 first changed character in current_buffer. Characters at positions <
16733 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16734 when the current matrix was built. */
16736 static struct glyph_row
*
16737 find_last_unchanged_at_beg_row (struct window
*w
)
16739 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16740 struct glyph_row
*row
;
16741 struct glyph_row
*row_found
= NULL
;
16742 int yb
= window_text_bottom_y (w
);
16744 /* Find the last row displaying unchanged text. */
16745 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16746 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16747 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16750 if (/* If row ends before first_changed_pos, it is unchanged,
16751 except in some case. */
16752 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16753 /* When row ends in ZV and we write at ZV it is not
16755 && !row
->ends_at_zv_p
16756 /* When first_changed_pos is the end of a continued line,
16757 row is not unchanged because it may be no longer
16759 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16760 && (row
->continued_p
16761 || row
->exact_window_width_line_p
))
16762 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16763 needs to be recomputed, so don't consider this row as
16764 unchanged. This happens when the last line was
16765 bidi-reordered and was killed immediately before this
16766 redisplay cycle. In that case, ROW->end stores the
16767 buffer position of the first visual-order character of
16768 the killed text, which is now beyond ZV. */
16769 && CHARPOS (row
->end
.pos
) <= ZV
)
16772 /* Stop if last visible row. */
16773 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16781 /* Find the first glyph row in the current matrix of W that is not
16782 affected by changes at the end of current_buffer since the
16783 time W's current matrix was built.
16785 Return in *DELTA the number of chars by which buffer positions in
16786 unchanged text at the end of current_buffer must be adjusted.
16788 Return in *DELTA_BYTES the corresponding number of bytes.
16790 Value is null if no such row exists, i.e. all rows are affected by
16793 static struct glyph_row
*
16794 find_first_unchanged_at_end_row (struct window
*w
,
16795 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16797 struct glyph_row
*row
;
16798 struct glyph_row
*row_found
= NULL
;
16800 *delta
= *delta_bytes
= 0;
16802 /* Display must not have been paused, otherwise the current matrix
16803 is not up to date. */
16804 eassert (w
->window_end_valid
);
16806 /* A value of window_end_pos >= END_UNCHANGED means that the window
16807 end is in the range of changed text. If so, there is no
16808 unchanged row at the end of W's current matrix. */
16809 if (w
->window_end_pos
>= END_UNCHANGED
)
16812 /* Set row to the last row in W's current matrix displaying text. */
16813 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16815 /* If matrix is entirely empty, no unchanged row exists. */
16816 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16818 /* The value of row is the last glyph row in the matrix having a
16819 meaningful buffer position in it. The end position of row
16820 corresponds to window_end_pos. This allows us to translate
16821 buffer positions in the current matrix to current buffer
16822 positions for characters not in changed text. */
16824 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16825 ptrdiff_t Z_BYTE_old
=
16826 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16827 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16828 struct glyph_row
*first_text_row
16829 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16831 *delta
= Z
- Z_old
;
16832 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16834 /* Set last_unchanged_pos to the buffer position of the last
16835 character in the buffer that has not been changed. Z is the
16836 index + 1 of the last character in current_buffer, i.e. by
16837 subtracting END_UNCHANGED we get the index of the last
16838 unchanged character, and we have to add BEG to get its buffer
16840 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16841 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16843 /* Search backward from ROW for a row displaying a line that
16844 starts at a minimum position >= last_unchanged_pos_old. */
16845 for (; row
> first_text_row
; --row
)
16847 /* This used to abort, but it can happen.
16848 It is ok to just stop the search instead here. KFS. */
16849 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16852 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16857 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16863 /* Make sure that glyph rows in the current matrix of window W
16864 reference the same glyph memory as corresponding rows in the
16865 frame's frame matrix. This function is called after scrolling W's
16866 current matrix on a terminal frame in try_window_id and
16867 try_window_reusing_current_matrix. */
16870 sync_frame_with_window_matrix_rows (struct window
*w
)
16872 struct frame
*f
= XFRAME (w
->frame
);
16873 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16875 /* Preconditions: W must be a leaf window and full-width. Its frame
16876 must have a frame matrix. */
16877 eassert (BUFFERP (w
->contents
));
16878 eassert (WINDOW_FULL_WIDTH_P (w
));
16879 eassert (!FRAME_WINDOW_P (f
));
16881 /* If W is a full-width window, glyph pointers in W's current matrix
16882 have, by definition, to be the same as glyph pointers in the
16883 corresponding frame matrix. Note that frame matrices have no
16884 marginal areas (see build_frame_matrix). */
16885 window_row
= w
->current_matrix
->rows
;
16886 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16887 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16888 while (window_row
< window_row_end
)
16890 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16891 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16893 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16894 frame_row
->glyphs
[TEXT_AREA
] = start
;
16895 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16896 frame_row
->glyphs
[LAST_AREA
] = end
;
16898 /* Disable frame rows whose corresponding window rows have
16899 been disabled in try_window_id. */
16900 if (!window_row
->enabled_p
)
16901 frame_row
->enabled_p
= 0;
16903 ++window_row
, ++frame_row
;
16908 /* Find the glyph row in window W containing CHARPOS. Consider all
16909 rows between START and END (not inclusive). END null means search
16910 all rows to the end of the display area of W. Value is the row
16911 containing CHARPOS or null. */
16914 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16915 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16917 struct glyph_row
*row
= start
;
16918 struct glyph_row
*best_row
= NULL
;
16919 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
16922 /* If we happen to start on a header-line, skip that. */
16923 if (row
->mode_line_p
)
16926 if ((end
&& row
>= end
) || !row
->enabled_p
)
16929 last_y
= window_text_bottom_y (w
) - dy
;
16933 /* Give up if we have gone too far. */
16934 if (end
&& row
>= end
)
16936 /* This formerly returned if they were equal.
16937 I think that both quantities are of a "last plus one" type;
16938 if so, when they are equal, the row is within the screen. -- rms. */
16939 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16942 /* If it is in this row, return this row. */
16943 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16944 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16945 /* The end position of a row equals the start
16946 position of the next row. If CHARPOS is there, we
16947 would rather consider it displayed in the next
16948 line, except when this line ends in ZV. */
16949 && !row_for_charpos_p (row
, charpos
)))
16950 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16954 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
16955 || (!best_row
&& !row
->continued_p
))
16957 /* In bidi-reordered rows, there could be several rows whose
16958 edges surround CHARPOS, all of these rows belonging to
16959 the same continued line. We need to find the row which
16960 fits CHARPOS the best. */
16961 for (g
= row
->glyphs
[TEXT_AREA
];
16962 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16965 if (!STRINGP (g
->object
))
16967 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16969 mindif
= eabs (g
->charpos
- charpos
);
16971 /* Exact match always wins. */
16978 else if (best_row
&& !row
->continued_p
)
16985 /* Try to redisplay window W by reusing its existing display. W's
16986 current matrix must be up to date when this function is called,
16987 i.e. window_end_valid must be nonzero.
16991 1 if display has been updated
16992 0 if otherwise unsuccessful
16993 -1 if redisplay with same window start is known not to succeed
16995 The following steps are performed:
16997 1. Find the last row in the current matrix of W that is not
16998 affected by changes at the start of current_buffer. If no such row
17001 2. Find the first row in W's current matrix that is not affected by
17002 changes at the end of current_buffer. Maybe there is no such row.
17004 3. Display lines beginning with the row + 1 found in step 1 to the
17005 row found in step 2 or, if step 2 didn't find a row, to the end of
17008 4. If cursor is not known to appear on the window, give up.
17010 5. If display stopped at the row found in step 2, scroll the
17011 display and current matrix as needed.
17013 6. Maybe display some lines at the end of W, if we must. This can
17014 happen under various circumstances, like a partially visible line
17015 becoming fully visible, or because newly displayed lines are displayed
17016 in smaller font sizes.
17018 7. Update W's window end information. */
17021 try_window_id (struct window
*w
)
17023 struct frame
*f
= XFRAME (w
->frame
);
17024 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17025 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17026 struct glyph_row
*last_unchanged_at_beg_row
;
17027 struct glyph_row
*first_unchanged_at_end_row
;
17028 struct glyph_row
*row
;
17029 struct glyph_row
*bottom_row
;
17032 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17034 struct text_pos start_pos
;
17036 int first_unchanged_at_end_vpos
= 0;
17037 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17038 struct text_pos start
;
17039 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17042 if (inhibit_try_window_id
)
17046 /* This is handy for debugging. */
17048 #define GIVE_UP(X) \
17050 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17054 #define GIVE_UP(X) return 0
17057 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17059 /* Don't use this for mini-windows because these can show
17060 messages and mini-buffers, and we don't handle that here. */
17061 if (MINI_WINDOW_P (w
))
17064 /* This flag is used to prevent redisplay optimizations. */
17065 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17068 /* Verify that narrowing has not changed.
17069 Also verify that we were not told to prevent redisplay optimizations.
17070 It would be nice to further
17071 reduce the number of cases where this prevents try_window_id. */
17072 if (current_buffer
->clip_changed
17073 || current_buffer
->prevent_redisplay_optimizations_p
)
17076 /* Window must either use window-based redisplay or be full width. */
17077 if (!FRAME_WINDOW_P (f
)
17078 && (!FRAME_LINE_INS_DEL_OK (f
)
17079 || !WINDOW_FULL_WIDTH_P (w
)))
17082 /* Give up if point is known NOT to appear in W. */
17083 if (PT
< CHARPOS (start
))
17086 /* Another way to prevent redisplay optimizations. */
17087 if (w
->last_modified
== 0)
17090 /* Verify that window is not hscrolled. */
17091 if (w
->hscroll
!= 0)
17094 /* Verify that display wasn't paused. */
17095 if (!w
->window_end_valid
)
17098 /* Likewise if highlighting trailing whitespace. */
17099 if (!NILP (Vshow_trailing_whitespace
))
17102 /* Can't use this if overlay arrow position and/or string have
17104 if (overlay_arrows_changed_p ())
17107 /* When word-wrap is on, adding a space to the first word of a
17108 wrapped line can change the wrap position, altering the line
17109 above it. It might be worthwhile to handle this more
17110 intelligently, but for now just redisplay from scratch. */
17111 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17114 /* Under bidi reordering, adding or deleting a character in the
17115 beginning of a paragraph, before the first strong directional
17116 character, can change the base direction of the paragraph (unless
17117 the buffer specifies a fixed paragraph direction), which will
17118 require to redisplay the whole paragraph. It might be worthwhile
17119 to find the paragraph limits and widen the range of redisplayed
17120 lines to that, but for now just give up this optimization and
17121 redisplay from scratch. */
17122 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17123 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17126 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17127 only if buffer has really changed. The reason is that the gap is
17128 initially at Z for freshly visited files. The code below would
17129 set end_unchanged to 0 in that case. */
17130 if (MODIFF
> SAVE_MODIFF
17131 /* This seems to happen sometimes after saving a buffer. */
17132 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17134 if (GPT
- BEG
< BEG_UNCHANGED
)
17135 BEG_UNCHANGED
= GPT
- BEG
;
17136 if (Z
- GPT
< END_UNCHANGED
)
17137 END_UNCHANGED
= Z
- GPT
;
17140 /* The position of the first and last character that has been changed. */
17141 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17142 last_changed_charpos
= Z
- END_UNCHANGED
;
17144 /* If window starts after a line end, and the last change is in
17145 front of that newline, then changes don't affect the display.
17146 This case happens with stealth-fontification. Note that although
17147 the display is unchanged, glyph positions in the matrix have to
17148 be adjusted, of course. */
17149 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17150 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17151 && ((last_changed_charpos
< CHARPOS (start
)
17152 && CHARPOS (start
) == BEGV
)
17153 || (last_changed_charpos
< CHARPOS (start
) - 1
17154 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17156 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17157 struct glyph_row
*r0
;
17159 /* Compute how many chars/bytes have been added to or removed
17160 from the buffer. */
17161 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17162 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17163 Z_delta
= Z
- Z_old
;
17164 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17166 /* Give up if PT is not in the window. Note that it already has
17167 been checked at the start of try_window_id that PT is not in
17168 front of the window start. */
17169 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17172 /* If window start is unchanged, we can reuse the whole matrix
17173 as is, after adjusting glyph positions. No need to compute
17174 the window end again, since its offset from Z hasn't changed. */
17175 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17176 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17177 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17178 /* PT must not be in a partially visible line. */
17179 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17180 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17182 /* Adjust positions in the glyph matrix. */
17183 if (Z_delta
|| Z_delta_bytes
)
17185 struct glyph_row
*r1
17186 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17187 increment_matrix_positions (w
->current_matrix
,
17188 MATRIX_ROW_VPOS (r0
, current_matrix
),
17189 MATRIX_ROW_VPOS (r1
, current_matrix
),
17190 Z_delta
, Z_delta_bytes
);
17193 /* Set the cursor. */
17194 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17196 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17201 /* Handle the case that changes are all below what is displayed in
17202 the window, and that PT is in the window. This shortcut cannot
17203 be taken if ZV is visible in the window, and text has been added
17204 there that is visible in the window. */
17205 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17206 /* ZV is not visible in the window, or there are no
17207 changes at ZV, actually. */
17208 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17209 || first_changed_charpos
== last_changed_charpos
))
17211 struct glyph_row
*r0
;
17213 /* Give up if PT is not in the window. Note that it already has
17214 been checked at the start of try_window_id that PT is not in
17215 front of the window start. */
17216 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17219 /* If window start is unchanged, we can reuse the whole matrix
17220 as is, without changing glyph positions since no text has
17221 been added/removed in front of the window end. */
17222 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17223 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17224 /* PT must not be in a partially visible line. */
17225 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17226 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17228 /* We have to compute the window end anew since text
17229 could have been added/removed after it. */
17230 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17231 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17233 /* Set the cursor. */
17234 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17236 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17241 /* Give up if window start is in the changed area.
17243 The condition used to read
17245 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17247 but why that was tested escapes me at the moment. */
17248 if (CHARPOS (start
) >= first_changed_charpos
17249 && CHARPOS (start
) <= last_changed_charpos
)
17252 /* Check that window start agrees with the start of the first glyph
17253 row in its current matrix. Check this after we know the window
17254 start is not in changed text, otherwise positions would not be
17256 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17257 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17260 /* Give up if the window ends in strings. Overlay strings
17261 at the end are difficult to handle, so don't try. */
17262 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17263 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17266 /* Compute the position at which we have to start displaying new
17267 lines. Some of the lines at the top of the window might be
17268 reusable because they are not displaying changed text. Find the
17269 last row in W's current matrix not affected by changes at the
17270 start of current_buffer. Value is null if changes start in the
17271 first line of window. */
17272 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17273 if (last_unchanged_at_beg_row
)
17275 /* Avoid starting to display in the middle of a character, a TAB
17276 for instance. This is easier than to set up the iterator
17277 exactly, and it's not a frequent case, so the additional
17278 effort wouldn't really pay off. */
17279 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17280 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17281 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17282 --last_unchanged_at_beg_row
;
17284 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17287 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17289 start_pos
= it
.current
.pos
;
17291 /* Start displaying new lines in the desired matrix at the same
17292 vpos we would use in the current matrix, i.e. below
17293 last_unchanged_at_beg_row. */
17294 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17296 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17297 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17299 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17303 /* There are no reusable lines at the start of the window.
17304 Start displaying in the first text line. */
17305 start_display (&it
, w
, start
);
17306 it
.vpos
= it
.first_vpos
;
17307 start_pos
= it
.current
.pos
;
17310 /* Find the first row that is not affected by changes at the end of
17311 the buffer. Value will be null if there is no unchanged row, in
17312 which case we must redisplay to the end of the window. delta
17313 will be set to the value by which buffer positions beginning with
17314 first_unchanged_at_end_row have to be adjusted due to text
17316 first_unchanged_at_end_row
17317 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17318 IF_DEBUG (debug_delta
= delta
);
17319 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17321 /* Set stop_pos to the buffer position up to which we will have to
17322 display new lines. If first_unchanged_at_end_row != NULL, this
17323 is the buffer position of the start of the line displayed in that
17324 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17325 that we don't stop at a buffer position. */
17327 if (first_unchanged_at_end_row
)
17329 eassert (last_unchanged_at_beg_row
== NULL
17330 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17332 /* If this is a continuation line, move forward to the next one
17333 that isn't. Changes in lines above affect this line.
17334 Caution: this may move first_unchanged_at_end_row to a row
17335 not displaying text. */
17336 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17337 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17338 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17339 < it
.last_visible_y
))
17340 ++first_unchanged_at_end_row
;
17342 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17343 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17344 >= it
.last_visible_y
))
17345 first_unchanged_at_end_row
= NULL
;
17348 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17350 first_unchanged_at_end_vpos
17351 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17352 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17355 else if (last_unchanged_at_beg_row
== NULL
)
17361 /* Either there is no unchanged row at the end, or the one we have
17362 now displays text. This is a necessary condition for the window
17363 end pos calculation at the end of this function. */
17364 eassert (first_unchanged_at_end_row
== NULL
17365 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17367 debug_last_unchanged_at_beg_vpos
17368 = (last_unchanged_at_beg_row
17369 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17371 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17373 #endif /* GLYPH_DEBUG */
17376 /* Display new lines. Set last_text_row to the last new line
17377 displayed which has text on it, i.e. might end up as being the
17378 line where the window_end_vpos is. */
17379 w
->cursor
.vpos
= -1;
17380 last_text_row
= NULL
;
17381 overlay_arrow_seen
= 0;
17382 while (it
.current_y
< it
.last_visible_y
17383 && !f
->fonts_changed
17384 && (first_unchanged_at_end_row
== NULL
17385 || IT_CHARPOS (it
) < stop_pos
))
17387 if (display_line (&it
))
17388 last_text_row
= it
.glyph_row
- 1;
17391 if (f
->fonts_changed
)
17395 /* Compute differences in buffer positions, y-positions etc. for
17396 lines reused at the bottom of the window. Compute what we can
17398 if (first_unchanged_at_end_row
17399 /* No lines reused because we displayed everything up to the
17400 bottom of the window. */
17401 && it
.current_y
< it
.last_visible_y
)
17404 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17406 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17407 run
.current_y
= first_unchanged_at_end_row
->y
;
17408 run
.desired_y
= run
.current_y
+ dy
;
17409 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17413 delta
= delta_bytes
= dvpos
= dy
17414 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17415 first_unchanged_at_end_row
= NULL
;
17417 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17420 /* Find the cursor if not already found. We have to decide whether
17421 PT will appear on this window (it sometimes doesn't, but this is
17422 not a very frequent case.) This decision has to be made before
17423 the current matrix is altered. A value of cursor.vpos < 0 means
17424 that PT is either in one of the lines beginning at
17425 first_unchanged_at_end_row or below the window. Don't care for
17426 lines that might be displayed later at the window end; as
17427 mentioned, this is not a frequent case. */
17428 if (w
->cursor
.vpos
< 0)
17430 /* Cursor in unchanged rows at the top? */
17431 if (PT
< CHARPOS (start_pos
)
17432 && last_unchanged_at_beg_row
)
17434 row
= row_containing_pos (w
, PT
,
17435 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17436 last_unchanged_at_beg_row
+ 1, 0);
17438 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17441 /* Start from first_unchanged_at_end_row looking for PT. */
17442 else if (first_unchanged_at_end_row
)
17444 row
= row_containing_pos (w
, PT
- delta
,
17445 first_unchanged_at_end_row
, NULL
, 0);
17447 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17448 delta_bytes
, dy
, dvpos
);
17451 /* Give up if cursor was not found. */
17452 if (w
->cursor
.vpos
< 0)
17454 clear_glyph_matrix (w
->desired_matrix
);
17459 /* Don't let the cursor end in the scroll margins. */
17461 int this_scroll_margin
, cursor_height
;
17462 int frame_line_height
= default_line_pixel_height (w
);
17463 int window_total_lines
17464 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17466 this_scroll_margin
=
17467 max (0, min (scroll_margin
, window_total_lines
/ 4));
17468 this_scroll_margin
*= frame_line_height
;
17469 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17471 if ((w
->cursor
.y
< this_scroll_margin
17472 && CHARPOS (start
) > BEGV
)
17473 /* Old redisplay didn't take scroll margin into account at the bottom,
17474 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17475 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17476 ? cursor_height
+ this_scroll_margin
17477 : 1)) > it
.last_visible_y
)
17479 w
->cursor
.vpos
= -1;
17480 clear_glyph_matrix (w
->desired_matrix
);
17485 /* Scroll the display. Do it before changing the current matrix so
17486 that xterm.c doesn't get confused about where the cursor glyph is
17488 if (dy
&& run
.height
)
17492 if (FRAME_WINDOW_P (f
))
17494 FRAME_RIF (f
)->update_window_begin_hook (w
);
17495 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17496 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17497 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17501 /* Terminal frame. In this case, dvpos gives the number of
17502 lines to scroll by; dvpos < 0 means scroll up. */
17504 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17505 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17506 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17507 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17508 + window_internal_height (w
));
17510 #if defined (HAVE_GPM) || defined (MSDOS)
17511 x_clear_window_mouse_face (w
);
17513 /* Perform the operation on the screen. */
17516 /* Scroll last_unchanged_at_beg_row to the end of the
17517 window down dvpos lines. */
17518 set_terminal_window (f
, end
);
17520 /* On dumb terminals delete dvpos lines at the end
17521 before inserting dvpos empty lines. */
17522 if (!FRAME_SCROLL_REGION_OK (f
))
17523 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17525 /* Insert dvpos empty lines in front of
17526 last_unchanged_at_beg_row. */
17527 ins_del_lines (f
, from
, dvpos
);
17529 else if (dvpos
< 0)
17531 /* Scroll up last_unchanged_at_beg_vpos to the end of
17532 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17533 set_terminal_window (f
, end
);
17535 /* Delete dvpos lines in front of
17536 last_unchanged_at_beg_vpos. ins_del_lines will set
17537 the cursor to the given vpos and emit |dvpos| delete
17539 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17541 /* On a dumb terminal insert dvpos empty lines at the
17543 if (!FRAME_SCROLL_REGION_OK (f
))
17544 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17547 set_terminal_window (f
, 0);
17553 /* Shift reused rows of the current matrix to the right position.
17554 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17556 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17557 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17560 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17561 bottom_vpos
, dvpos
);
17562 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17565 else if (dvpos
> 0)
17567 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17568 bottom_vpos
, dvpos
);
17569 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17570 first_unchanged_at_end_vpos
+ dvpos
);
17573 /* For frame-based redisplay, make sure that current frame and window
17574 matrix are in sync with respect to glyph memory. */
17575 if (!FRAME_WINDOW_P (f
))
17576 sync_frame_with_window_matrix_rows (w
);
17578 /* Adjust buffer positions in reused rows. */
17579 if (delta
|| delta_bytes
)
17580 increment_matrix_positions (current_matrix
,
17581 first_unchanged_at_end_vpos
+ dvpos
,
17582 bottom_vpos
, delta
, delta_bytes
);
17584 /* Adjust Y positions. */
17586 shift_glyph_matrix (w
, current_matrix
,
17587 first_unchanged_at_end_vpos
+ dvpos
,
17590 if (first_unchanged_at_end_row
)
17592 first_unchanged_at_end_row
+= dvpos
;
17593 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17594 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17595 first_unchanged_at_end_row
= NULL
;
17598 /* If scrolling up, there may be some lines to display at the end of
17600 last_text_row_at_end
= NULL
;
17603 /* Scrolling up can leave for example a partially visible line
17604 at the end of the window to be redisplayed. */
17605 /* Set last_row to the glyph row in the current matrix where the
17606 window end line is found. It has been moved up or down in
17607 the matrix by dvpos. */
17608 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17609 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17611 /* If last_row is the window end line, it should display text. */
17612 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17614 /* If window end line was partially visible before, begin
17615 displaying at that line. Otherwise begin displaying with the
17616 line following it. */
17617 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17619 init_to_row_start (&it
, w
, last_row
);
17620 it
.vpos
= last_vpos
;
17621 it
.current_y
= last_row
->y
;
17625 init_to_row_end (&it
, w
, last_row
);
17626 it
.vpos
= 1 + last_vpos
;
17627 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17631 /* We may start in a continuation line. If so, we have to
17632 get the right continuation_lines_width and current_x. */
17633 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17634 it
.hpos
= it
.current_x
= 0;
17636 /* Display the rest of the lines at the window end. */
17637 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17638 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17640 /* Is it always sure that the display agrees with lines in
17641 the current matrix? I don't think so, so we mark rows
17642 displayed invalid in the current matrix by setting their
17643 enabled_p flag to zero. */
17644 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17645 if (display_line (&it
))
17646 last_text_row_at_end
= it
.glyph_row
- 1;
17650 /* Update window_end_pos and window_end_vpos. */
17651 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17653 /* Window end line if one of the preserved rows from the current
17654 matrix. Set row to the last row displaying text in current
17655 matrix starting at first_unchanged_at_end_row, after
17657 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17658 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17659 first_unchanged_at_end_row
);
17660 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17661 adjust_window_ends (w
, row
, 1);
17662 eassert (w
->window_end_bytepos
>= 0);
17663 IF_DEBUG (debug_method_add (w
, "A"));
17665 else if (last_text_row_at_end
)
17667 adjust_window_ends (w
, last_text_row_at_end
, 0);
17668 eassert (w
->window_end_bytepos
>= 0);
17669 IF_DEBUG (debug_method_add (w
, "B"));
17671 else if (last_text_row
)
17673 /* We have displayed either to the end of the window or at the
17674 end of the window, i.e. the last row with text is to be found
17675 in the desired matrix. */
17676 adjust_window_ends (w
, last_text_row
, 0);
17677 eassert (w
->window_end_bytepos
>= 0);
17679 else if (first_unchanged_at_end_row
== NULL
17680 && last_text_row
== NULL
17681 && last_text_row_at_end
== NULL
)
17683 /* Displayed to end of window, but no line containing text was
17684 displayed. Lines were deleted at the end of the window. */
17685 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17686 int vpos
= w
->window_end_vpos
;
17687 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17688 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17691 row
== NULL
&& vpos
>= first_vpos
;
17692 --vpos
, --current_row
, --desired_row
)
17694 if (desired_row
->enabled_p
)
17696 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17699 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17703 eassert (row
!= NULL
);
17704 w
->window_end_vpos
= vpos
+ 1;
17705 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17706 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17707 eassert (w
->window_end_bytepos
>= 0);
17708 IF_DEBUG (debug_method_add (w
, "C"));
17713 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17714 debug_end_vpos
= w
->window_end_vpos
);
17716 /* Record that display has not been completed. */
17717 w
->window_end_valid
= 0;
17718 w
->desired_matrix
->no_scrolling_p
= 1;
17726 /***********************************************************************
17727 More debugging support
17728 ***********************************************************************/
17732 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17733 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17734 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17737 /* Dump the contents of glyph matrix MATRIX on stderr.
17739 GLYPHS 0 means don't show glyph contents.
17740 GLYPHS 1 means show glyphs in short form
17741 GLYPHS > 1 means show glyphs in long form. */
17744 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17747 for (i
= 0; i
< matrix
->nrows
; ++i
)
17748 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17752 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17753 the glyph row and area where the glyph comes from. */
17756 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17758 if (glyph
->type
== CHAR_GLYPH
17759 || glyph
->type
== GLYPHLESS_GLYPH
)
17762 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17763 glyph
- row
->glyphs
[TEXT_AREA
],
17764 (glyph
->type
== CHAR_GLYPH
17768 (BUFFERP (glyph
->object
)
17770 : (STRINGP (glyph
->object
)
17772 : (INTEGERP (glyph
->object
)
17775 glyph
->pixel_width
,
17777 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17781 glyph
->left_box_line_p
,
17782 glyph
->right_box_line_p
);
17784 else if (glyph
->type
== STRETCH_GLYPH
)
17787 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17788 glyph
- row
->glyphs
[TEXT_AREA
],
17791 (BUFFERP (glyph
->object
)
17793 : (STRINGP (glyph
->object
)
17795 : (INTEGERP (glyph
->object
)
17798 glyph
->pixel_width
,
17802 glyph
->left_box_line_p
,
17803 glyph
->right_box_line_p
);
17805 else if (glyph
->type
== IMAGE_GLYPH
)
17808 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17809 glyph
- row
->glyphs
[TEXT_AREA
],
17812 (BUFFERP (glyph
->object
)
17814 : (STRINGP (glyph
->object
)
17816 : (INTEGERP (glyph
->object
)
17819 glyph
->pixel_width
,
17823 glyph
->left_box_line_p
,
17824 glyph
->right_box_line_p
);
17826 else if (glyph
->type
== COMPOSITE_GLYPH
)
17829 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17830 glyph
- row
->glyphs
[TEXT_AREA
],
17833 (BUFFERP (glyph
->object
)
17835 : (STRINGP (glyph
->object
)
17837 : (INTEGERP (glyph
->object
)
17840 glyph
->pixel_width
,
17842 if (glyph
->u
.cmp
.automatic
)
17845 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17846 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17848 glyph
->left_box_line_p
,
17849 glyph
->right_box_line_p
);
17854 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17855 GLYPHS 0 means don't show glyph contents.
17856 GLYPHS 1 means show glyphs in short form
17857 GLYPHS > 1 means show glyphs in long form. */
17860 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17864 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17865 fprintf (stderr
, "==============================================================================\n");
17867 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17868 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17870 MATRIX_ROW_START_CHARPOS (row
),
17871 MATRIX_ROW_END_CHARPOS (row
),
17872 row
->used
[TEXT_AREA
],
17873 row
->contains_overlapping_glyphs_p
,
17875 row
->truncated_on_left_p
,
17876 row
->truncated_on_right_p
,
17878 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17879 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
17882 row
->ends_in_middle_of_char_p
,
17883 row
->starts_in_middle_of_char_p
,
17889 row
->visible_height
,
17892 /* The next 3 lines should align to "Start" in the header. */
17893 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17894 row
->end
.overlay_string_index
,
17895 row
->continuation_lines_width
);
17896 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17897 CHARPOS (row
->start
.string_pos
),
17898 CHARPOS (row
->end
.string_pos
));
17899 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17900 row
->end
.dpvec_index
);
17907 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17909 struct glyph
*glyph
= row
->glyphs
[area
];
17910 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17912 /* Glyph for a line end in text. */
17913 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17916 if (glyph
< glyph_end
)
17917 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
17919 for (; glyph
< glyph_end
; ++glyph
)
17920 dump_glyph (row
, glyph
, area
);
17923 else if (glyphs
== 1)
17927 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17929 char *s
= alloca (row
->used
[area
] + 4);
17932 for (i
= 0; i
< row
->used
[area
]; ++i
)
17934 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17935 if (i
== row
->used
[area
] - 1
17936 && area
== TEXT_AREA
17937 && INTEGERP (glyph
->object
)
17938 && glyph
->type
== CHAR_GLYPH
17939 && glyph
->u
.ch
== ' ')
17941 strcpy (&s
[i
], "[\\n]");
17944 else if (glyph
->type
== CHAR_GLYPH
17945 && glyph
->u
.ch
< 0x80
17946 && glyph
->u
.ch
>= ' ')
17947 s
[i
] = glyph
->u
.ch
;
17953 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17959 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17960 Sdump_glyph_matrix
, 0, 1, "p",
17961 doc
: /* Dump the current matrix of the selected window to stderr.
17962 Shows contents of glyph row structures. With non-nil
17963 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17964 glyphs in short form, otherwise show glyphs in long form. */)
17965 (Lisp_Object glyphs
)
17967 struct window
*w
= XWINDOW (selected_window
);
17968 struct buffer
*buffer
= XBUFFER (w
->contents
);
17970 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17971 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17972 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17973 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17974 fprintf (stderr
, "=============================================\n");
17975 dump_glyph_matrix (w
->current_matrix
,
17976 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17981 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17982 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17985 struct frame
*f
= XFRAME (selected_frame
);
17986 dump_glyph_matrix (f
->current_matrix
, 1);
17991 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17992 doc
: /* Dump glyph row ROW to stderr.
17993 GLYPH 0 means don't dump glyphs.
17994 GLYPH 1 means dump glyphs in short form.
17995 GLYPH > 1 or omitted means dump glyphs in long form. */)
17996 (Lisp_Object row
, Lisp_Object glyphs
)
17998 struct glyph_matrix
*matrix
;
18001 CHECK_NUMBER (row
);
18002 matrix
= XWINDOW (selected_window
)->current_matrix
;
18004 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18005 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18007 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18012 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18013 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18014 GLYPH 0 means don't dump glyphs.
18015 GLYPH 1 means dump glyphs in short form.
18016 GLYPH > 1 or omitted means dump glyphs in long form.
18018 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18020 (Lisp_Object row
, Lisp_Object glyphs
)
18022 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18023 struct frame
*sf
= SELECTED_FRAME ();
18024 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18027 CHECK_NUMBER (row
);
18029 if (vpos
>= 0 && vpos
< m
->nrows
)
18030 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18031 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18037 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18038 doc
: /* Toggle tracing of redisplay.
18039 With ARG, turn tracing on if and only if ARG is positive. */)
18043 trace_redisplay_p
= !trace_redisplay_p
;
18046 arg
= Fprefix_numeric_value (arg
);
18047 trace_redisplay_p
= XINT (arg
) > 0;
18054 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18055 doc
: /* Like `format', but print result to stderr.
18056 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18057 (ptrdiff_t nargs
, Lisp_Object
*args
)
18059 Lisp_Object s
= Fformat (nargs
, args
);
18060 fprintf (stderr
, "%s", SDATA (s
));
18064 #endif /* GLYPH_DEBUG */
18068 /***********************************************************************
18069 Building Desired Matrix Rows
18070 ***********************************************************************/
18072 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18073 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18075 static struct glyph_row
*
18076 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18078 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18079 struct buffer
*buffer
= XBUFFER (w
->contents
);
18080 struct buffer
*old
= current_buffer
;
18081 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18082 int arrow_len
= SCHARS (overlay_arrow_string
);
18083 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18084 const unsigned char *p
;
18087 int n_glyphs_before
;
18089 set_buffer_temp (buffer
);
18090 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18091 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18092 SET_TEXT_POS (it
.position
, 0, 0);
18094 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18096 while (p
< arrow_end
)
18098 Lisp_Object face
, ilisp
;
18100 /* Get the next character. */
18102 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18105 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18106 if (! ASCII_CHAR_P (it
.c
))
18107 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18111 /* Get its face. */
18112 ilisp
= make_number (p
- arrow_string
);
18113 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18114 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18116 /* Compute its width, get its glyphs. */
18117 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18118 SET_TEXT_POS (it
.position
, -1, -1);
18119 PRODUCE_GLYPHS (&it
);
18121 /* If this character doesn't fit any more in the line, we have
18122 to remove some glyphs. */
18123 if (it
.current_x
> it
.last_visible_x
)
18125 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18130 set_buffer_temp (old
);
18131 return it
.glyph_row
;
18135 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18136 glyphs to insert is determined by produce_special_glyphs. */
18139 insert_left_trunc_glyphs (struct it
*it
)
18141 struct it truncate_it
;
18142 struct glyph
*from
, *end
, *to
, *toend
;
18144 eassert (!FRAME_WINDOW_P (it
->f
)
18145 || (!it
->glyph_row
->reversed_p
18146 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18147 || (it
->glyph_row
->reversed_p
18148 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18150 /* Get the truncation glyphs. */
18152 truncate_it
.current_x
= 0;
18153 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18154 truncate_it
.glyph_row
= &scratch_glyph_row
;
18155 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18156 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18157 truncate_it
.object
= make_number (0);
18158 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18160 /* Overwrite glyphs from IT with truncation glyphs. */
18161 if (!it
->glyph_row
->reversed_p
)
18163 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18165 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18166 end
= from
+ tused
;
18167 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18168 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18169 if (FRAME_WINDOW_P (it
->f
))
18171 /* On GUI frames, when variable-size fonts are displayed,
18172 the truncation glyphs may need more pixels than the row's
18173 glyphs they overwrite. We overwrite more glyphs to free
18174 enough screen real estate, and enlarge the stretch glyph
18175 on the right (see display_line), if there is one, to
18176 preserve the screen position of the truncation glyphs on
18179 struct glyph
*g
= to
;
18182 /* The first glyph could be partially visible, in which case
18183 it->glyph_row->x will be negative. But we want the left
18184 truncation glyphs to be aligned at the left margin of the
18185 window, so we override the x coordinate at which the row
18187 it
->glyph_row
->x
= 0;
18188 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18190 w
+= g
->pixel_width
;
18193 if (g
- to
- tused
> 0)
18195 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18196 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18198 used
= it
->glyph_row
->used
[TEXT_AREA
];
18199 if (it
->glyph_row
->truncated_on_right_p
18200 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18201 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18204 int extra
= w
- it
->truncation_pixel_width
;
18206 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18213 /* There may be padding glyphs left over. Overwrite them too. */
18214 if (!FRAME_WINDOW_P (it
->f
))
18216 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18218 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18225 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18229 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18231 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18232 that back to front. */
18233 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18234 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18235 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18236 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18237 if (FRAME_WINDOW_P (it
->f
))
18240 struct glyph
*g
= to
;
18242 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18244 w
+= g
->pixel_width
;
18247 if (to
- g
- tused
> 0)
18249 if (it
->glyph_row
->truncated_on_right_p
18250 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18251 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18253 int extra
= w
- it
->truncation_pixel_width
;
18255 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18259 while (from
>= end
&& to
>= toend
)
18261 if (!FRAME_WINDOW_P (it
->f
))
18263 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18266 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18267 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18268 while (from
>= end
&& to
>= toend
)
18274 /* Need to free some room before prepending additional
18276 int move_by
= from
- end
+ 1;
18277 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18278 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18280 for ( ; g
>= g0
; g
--)
18282 while (from
>= end
)
18284 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18289 /* Compute the hash code for ROW. */
18291 row_hash (struct glyph_row
*row
)
18294 unsigned hashval
= 0;
18296 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18297 for (k
= 0; k
< row
->used
[area
]; ++k
)
18298 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18299 + row
->glyphs
[area
][k
].u
.val
18300 + row
->glyphs
[area
][k
].face_id
18301 + row
->glyphs
[area
][k
].padding_p
18302 + (row
->glyphs
[area
][k
].type
<< 2));
18307 /* Compute the pixel height and width of IT->glyph_row.
18309 Most of the time, ascent and height of a display line will be equal
18310 to the max_ascent and max_height values of the display iterator
18311 structure. This is not the case if
18313 1. We hit ZV without displaying anything. In this case, max_ascent
18314 and max_height will be zero.
18316 2. We have some glyphs that don't contribute to the line height.
18317 (The glyph row flag contributes_to_line_height_p is for future
18318 pixmap extensions).
18320 The first case is easily covered by using default values because in
18321 these cases, the line height does not really matter, except that it
18322 must not be zero. */
18325 compute_line_metrics (struct it
*it
)
18327 struct glyph_row
*row
= it
->glyph_row
;
18329 if (FRAME_WINDOW_P (it
->f
))
18331 int i
, min_y
, max_y
;
18333 /* The line may consist of one space only, that was added to
18334 place the cursor on it. If so, the row's height hasn't been
18336 if (row
->height
== 0)
18338 if (it
->max_ascent
+ it
->max_descent
== 0)
18339 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18340 row
->ascent
= it
->max_ascent
;
18341 row
->height
= it
->max_ascent
+ it
->max_descent
;
18342 row
->phys_ascent
= it
->max_phys_ascent
;
18343 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18344 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18347 /* Compute the width of this line. */
18348 row
->pixel_width
= row
->x
;
18349 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18350 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18352 eassert (row
->pixel_width
>= 0);
18353 eassert (row
->ascent
>= 0 && row
->height
> 0);
18355 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18356 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18358 /* If first line's physical ascent is larger than its logical
18359 ascent, use the physical ascent, and make the row taller.
18360 This makes accented characters fully visible. */
18361 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18362 && row
->phys_ascent
> row
->ascent
)
18364 row
->height
+= row
->phys_ascent
- row
->ascent
;
18365 row
->ascent
= row
->phys_ascent
;
18368 /* Compute how much of the line is visible. */
18369 row
->visible_height
= row
->height
;
18371 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18372 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18374 if (row
->y
< min_y
)
18375 row
->visible_height
-= min_y
- row
->y
;
18376 if (row
->y
+ row
->height
> max_y
)
18377 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18381 row
->pixel_width
= row
->used
[TEXT_AREA
];
18382 if (row
->continued_p
)
18383 row
->pixel_width
-= it
->continuation_pixel_width
;
18384 else if (row
->truncated_on_right_p
)
18385 row
->pixel_width
-= it
->truncation_pixel_width
;
18386 row
->ascent
= row
->phys_ascent
= 0;
18387 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18388 row
->extra_line_spacing
= 0;
18391 /* Compute a hash code for this row. */
18392 row
->hash
= row_hash (row
);
18394 it
->max_ascent
= it
->max_descent
= 0;
18395 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18399 /* Append one space to the glyph row of iterator IT if doing a
18400 window-based redisplay. The space has the same face as
18401 IT->face_id. Value is non-zero if a space was added.
18403 This function is called to make sure that there is always one glyph
18404 at the end of a glyph row that the cursor can be set on under
18405 window-systems. (If there weren't such a glyph we would not know
18406 how wide and tall a box cursor should be displayed).
18408 At the same time this space let's a nicely handle clearing to the
18409 end of the line if the row ends in italic text. */
18412 append_space_for_newline (struct it
*it
, int default_face_p
)
18414 if (FRAME_WINDOW_P (it
->f
))
18416 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18418 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18419 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18421 /* Save some values that must not be changed.
18422 Must save IT->c and IT->len because otherwise
18423 ITERATOR_AT_END_P wouldn't work anymore after
18424 append_space_for_newline has been called. */
18425 enum display_element_type saved_what
= it
->what
;
18426 int saved_c
= it
->c
, saved_len
= it
->len
;
18427 int saved_char_to_display
= it
->char_to_display
;
18428 int saved_x
= it
->current_x
;
18429 int saved_face_id
= it
->face_id
;
18430 int saved_box_end
= it
->end_of_box_run_p
;
18431 struct text_pos saved_pos
;
18432 Lisp_Object saved_object
;
18435 saved_object
= it
->object
;
18436 saved_pos
= it
->position
;
18438 it
->what
= IT_CHARACTER
;
18439 memset (&it
->position
, 0, sizeof it
->position
);
18440 it
->object
= make_number (0);
18441 it
->c
= it
->char_to_display
= ' ';
18444 /* If the default face was remapped, be sure to use the
18445 remapped face for the appended newline. */
18446 if (default_face_p
)
18447 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18448 else if (it
->face_before_selective_p
)
18449 it
->face_id
= it
->saved_face_id
;
18450 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18451 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18452 /* In R2L rows, we will prepend a stretch glyph that will
18453 have the end_of_box_run_p flag set for it, so there's no
18454 need for the appended newline glyph to have that flag
18456 if (it
->glyph_row
->reversed_p
18457 /* But if the appended newline glyph goes all the way to
18458 the end of the row, there will be no stretch glyph,
18459 so leave the box flag set. */
18460 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18461 it
->end_of_box_run_p
= 0;
18463 PRODUCE_GLYPHS (it
);
18465 it
->override_ascent
= -1;
18466 it
->constrain_row_ascent_descent_p
= 0;
18467 it
->current_x
= saved_x
;
18468 it
->object
= saved_object
;
18469 it
->position
= saved_pos
;
18470 it
->what
= saved_what
;
18471 it
->face_id
= saved_face_id
;
18472 it
->len
= saved_len
;
18474 it
->char_to_display
= saved_char_to_display
;
18475 it
->end_of_box_run_p
= saved_box_end
;
18484 /* Extend the face of the last glyph in the text area of IT->glyph_row
18485 to the end of the display line. Called from display_line. If the
18486 glyph row is empty, add a space glyph to it so that we know the
18487 face to draw. Set the glyph row flag fill_line_p. If the glyph
18488 row is R2L, prepend a stretch glyph to cover the empty space to the
18489 left of the leftmost glyph. */
18492 extend_face_to_end_of_line (struct it
*it
)
18494 struct face
*face
, *default_face
;
18495 struct frame
*f
= it
->f
;
18497 /* If line is already filled, do nothing. Non window-system frames
18498 get a grace of one more ``pixel'' because their characters are
18499 1-``pixel'' wide, so they hit the equality too early. This grace
18500 is needed only for R2L rows that are not continued, to produce
18501 one extra blank where we could display the cursor. */
18502 if (it
->current_x
>= it
->last_visible_x
18503 + (!FRAME_WINDOW_P (f
)
18504 && it
->glyph_row
->reversed_p
18505 && !it
->glyph_row
->continued_p
))
18508 /* The default face, possibly remapped. */
18509 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18511 /* Face extension extends the background and box of IT->face_id
18512 to the end of the line. If the background equals the background
18513 of the frame, we don't have to do anything. */
18514 if (it
->face_before_selective_p
)
18515 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18517 face
= FACE_FROM_ID (f
, it
->face_id
);
18519 if (FRAME_WINDOW_P (f
)
18520 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18521 && face
->box
== FACE_NO_BOX
18522 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18523 #ifdef HAVE_WINDOW_SYSTEM
18526 && !it
->glyph_row
->reversed_p
)
18529 /* Set the glyph row flag indicating that the face of the last glyph
18530 in the text area has to be drawn to the end of the text area. */
18531 it
->glyph_row
->fill_line_p
= 1;
18533 /* If current character of IT is not ASCII, make sure we have the
18534 ASCII face. This will be automatically undone the next time
18535 get_next_display_element returns a multibyte character. Note
18536 that the character will always be single byte in unibyte
18538 if (!ASCII_CHAR_P (it
->c
))
18540 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18543 if (FRAME_WINDOW_P (f
))
18545 /* If the row is empty, add a space with the current face of IT,
18546 so that we know which face to draw. */
18547 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18549 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18550 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18551 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18553 #ifdef HAVE_WINDOW_SYSTEM
18554 if (it
->glyph_row
->reversed_p
)
18556 /* Prepend a stretch glyph to the row, such that the
18557 rightmost glyph will be drawn flushed all the way to the
18558 right margin of the window. The stretch glyph that will
18559 occupy the empty space, if any, to the left of the
18561 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18562 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18563 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18565 int row_width
, stretch_ascent
, stretch_width
;
18566 struct text_pos saved_pos
;
18567 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18569 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18570 row_width
+= g
->pixel_width
;
18571 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18572 if (stretch_width
> 0)
18575 (((it
->ascent
+ it
->descent
)
18576 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18577 saved_pos
= it
->position
;
18578 memset (&it
->position
, 0, sizeof it
->position
);
18579 saved_avoid_cursor
= it
->avoid_cursor_p
;
18580 it
->avoid_cursor_p
= 1;
18581 saved_face_id
= it
->face_id
;
18582 saved_box_start
= it
->start_of_box_run_p
;
18583 /* The last row's stretch glyph should get the default
18584 face, to avoid painting the rest of the window with
18585 the region face, if the region ends at ZV. */
18586 if (it
->glyph_row
->ends_at_zv_p
)
18587 it
->face_id
= default_face
->id
;
18589 it
->face_id
= face
->id
;
18590 it
->start_of_box_run_p
= 0;
18591 append_stretch_glyph (it
, make_number (0), stretch_width
,
18592 it
->ascent
+ it
->descent
, stretch_ascent
);
18593 it
->position
= saved_pos
;
18594 it
->avoid_cursor_p
= saved_avoid_cursor
;
18595 it
->face_id
= saved_face_id
;
18596 it
->start_of_box_run_p
= saved_box_start
;
18599 #endif /* HAVE_WINDOW_SYSTEM */
18603 /* Save some values that must not be changed. */
18604 int saved_x
= it
->current_x
;
18605 struct text_pos saved_pos
;
18606 Lisp_Object saved_object
;
18607 enum display_element_type saved_what
= it
->what
;
18608 int saved_face_id
= it
->face_id
;
18610 saved_object
= it
->object
;
18611 saved_pos
= it
->position
;
18613 it
->what
= IT_CHARACTER
;
18614 memset (&it
->position
, 0, sizeof it
->position
);
18615 it
->object
= make_number (0);
18616 it
->c
= it
->char_to_display
= ' ';
18618 /* The last row's blank glyphs should get the default face, to
18619 avoid painting the rest of the window with the region face,
18620 if the region ends at ZV. */
18621 if (it
->glyph_row
->ends_at_zv_p
)
18622 it
->face_id
= default_face
->id
;
18624 it
->face_id
= face
->id
;
18626 PRODUCE_GLYPHS (it
);
18628 while (it
->current_x
<= it
->last_visible_x
)
18629 PRODUCE_GLYPHS (it
);
18631 /* Don't count these blanks really. It would let us insert a left
18632 truncation glyph below and make us set the cursor on them, maybe. */
18633 it
->current_x
= saved_x
;
18634 it
->object
= saved_object
;
18635 it
->position
= saved_pos
;
18636 it
->what
= saved_what
;
18637 it
->face_id
= saved_face_id
;
18642 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18643 trailing whitespace. */
18646 trailing_whitespace_p (ptrdiff_t charpos
)
18648 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18651 while (bytepos
< ZV_BYTE
18652 && (c
= FETCH_CHAR (bytepos
),
18653 c
== ' ' || c
== '\t'))
18656 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18658 if (bytepos
!= PT_BYTE
)
18665 /* Highlight trailing whitespace, if any, in ROW. */
18668 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18670 int used
= row
->used
[TEXT_AREA
];
18674 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18675 struct glyph
*glyph
= start
+ used
- 1;
18677 if (row
->reversed_p
)
18679 /* Right-to-left rows need to be processed in the opposite
18680 direction, so swap the edge pointers. */
18682 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18685 /* Skip over glyphs inserted to display the cursor at the
18686 end of a line, for extending the face of the last glyph
18687 to the end of the line on terminals, and for truncation
18688 and continuation glyphs. */
18689 if (!row
->reversed_p
)
18691 while (glyph
>= start
18692 && glyph
->type
== CHAR_GLYPH
18693 && INTEGERP (glyph
->object
))
18698 while (glyph
<= start
18699 && glyph
->type
== CHAR_GLYPH
18700 && INTEGERP (glyph
->object
))
18704 /* If last glyph is a space or stretch, and it's trailing
18705 whitespace, set the face of all trailing whitespace glyphs in
18706 IT->glyph_row to `trailing-whitespace'. */
18707 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18708 && BUFFERP (glyph
->object
)
18709 && (glyph
->type
== STRETCH_GLYPH
18710 || (glyph
->type
== CHAR_GLYPH
18711 && glyph
->u
.ch
== ' '))
18712 && trailing_whitespace_p (glyph
->charpos
))
18714 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18718 if (!row
->reversed_p
)
18720 while (glyph
>= start
18721 && BUFFERP (glyph
->object
)
18722 && (glyph
->type
== STRETCH_GLYPH
18723 || (glyph
->type
== CHAR_GLYPH
18724 && glyph
->u
.ch
== ' ')))
18725 (glyph
--)->face_id
= face_id
;
18729 while (glyph
<= start
18730 && BUFFERP (glyph
->object
)
18731 && (glyph
->type
== STRETCH_GLYPH
18732 || (glyph
->type
== CHAR_GLYPH
18733 && glyph
->u
.ch
== ' ')))
18734 (glyph
++)->face_id
= face_id
;
18741 /* Value is non-zero if glyph row ROW should be
18742 considered to hold the buffer position CHARPOS. */
18745 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18749 if (charpos
== CHARPOS (row
->end
.pos
)
18750 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18752 /* Suppose the row ends on a string.
18753 Unless the row is continued, that means it ends on a newline
18754 in the string. If it's anything other than a display string
18755 (e.g., a before-string from an overlay), we don't want the
18756 cursor there. (This heuristic seems to give the optimal
18757 behavior for the various types of multi-line strings.)
18758 One exception: if the string has `cursor' property on one of
18759 its characters, we _do_ want the cursor there. */
18760 if (CHARPOS (row
->end
.string_pos
) >= 0)
18762 if (row
->continued_p
)
18766 /* Check for `display' property. */
18767 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18768 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18769 struct glyph
*glyph
;
18772 for (glyph
= end
; glyph
>= beg
; --glyph
)
18773 if (STRINGP (glyph
->object
))
18776 = Fget_char_property (make_number (charpos
),
18780 && display_prop_string_p (prop
, glyph
->object
));
18781 /* If there's a `cursor' property on one of the
18782 string's characters, this row is a cursor row,
18783 even though this is not a display string. */
18786 Lisp_Object s
= glyph
->object
;
18788 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18790 ptrdiff_t gpos
= glyph
->charpos
;
18792 if (!NILP (Fget_char_property (make_number (gpos
),
18804 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18806 /* If the row ends in middle of a real character,
18807 and the line is continued, we want the cursor here.
18808 That's because CHARPOS (ROW->end.pos) would equal
18809 PT if PT is before the character. */
18810 if (!row
->ends_in_ellipsis_p
)
18811 result
= row
->continued_p
;
18813 /* If the row ends in an ellipsis, then
18814 CHARPOS (ROW->end.pos) will equal point after the
18815 invisible text. We want that position to be displayed
18816 after the ellipsis. */
18819 /* If the row ends at ZV, display the cursor at the end of that
18820 row instead of at the start of the row below. */
18821 else if (row
->ends_at_zv_p
)
18830 /* Value is non-zero if glyph row ROW should be
18831 used to hold the cursor. */
18834 cursor_row_p (struct glyph_row
*row
)
18836 return row_for_charpos_p (row
, PT
);
18841 /* Push the property PROP so that it will be rendered at the current
18842 position in IT. Return 1 if PROP was successfully pushed, 0
18843 otherwise. Called from handle_line_prefix to handle the
18844 `line-prefix' and `wrap-prefix' properties. */
18847 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18849 struct text_pos pos
=
18850 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18852 eassert (it
->method
== GET_FROM_BUFFER
18853 || it
->method
== GET_FROM_DISPLAY_VECTOR
18854 || it
->method
== GET_FROM_STRING
);
18856 /* We need to save the current buffer/string position, so it will be
18857 restored by pop_it, because iterate_out_of_display_property
18858 depends on that being set correctly, but some situations leave
18859 it->position not yet set when this function is called. */
18860 push_it (it
, &pos
);
18862 if (STRINGP (prop
))
18864 if (SCHARS (prop
) == 0)
18871 it
->string_from_prefix_prop_p
= 1;
18872 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18873 it
->current
.overlay_string_index
= -1;
18874 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18875 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18876 it
->method
= GET_FROM_STRING
;
18877 it
->stop_charpos
= 0;
18879 it
->base_level_stop
= 0;
18881 /* Force paragraph direction to be that of the parent
18883 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18884 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18886 it
->paragraph_embedding
= L2R
;
18888 /* Set up the bidi iterator for this display string. */
18891 it
->bidi_it
.string
.lstring
= it
->string
;
18892 it
->bidi_it
.string
.s
= NULL
;
18893 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18894 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18895 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18896 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18897 it
->bidi_it
.w
= it
->w
;
18898 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18901 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18903 it
->method
= GET_FROM_STRETCH
;
18906 #ifdef HAVE_WINDOW_SYSTEM
18907 else if (IMAGEP (prop
))
18909 it
->what
= IT_IMAGE
;
18910 it
->image_id
= lookup_image (it
->f
, prop
);
18911 it
->method
= GET_FROM_IMAGE
;
18913 #endif /* HAVE_WINDOW_SYSTEM */
18916 pop_it (it
); /* bogus display property, give up */
18923 /* Return the character-property PROP at the current position in IT. */
18926 get_it_property (struct it
*it
, Lisp_Object prop
)
18928 Lisp_Object position
, object
= it
->object
;
18930 if (STRINGP (object
))
18931 position
= make_number (IT_STRING_CHARPOS (*it
));
18932 else if (BUFFERP (object
))
18934 position
= make_number (IT_CHARPOS (*it
));
18935 object
= it
->window
;
18940 return Fget_char_property (position
, prop
, object
);
18943 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18946 handle_line_prefix (struct it
*it
)
18948 Lisp_Object prefix
;
18950 if (it
->continuation_lines_width
> 0)
18952 prefix
= get_it_property (it
, Qwrap_prefix
);
18954 prefix
= Vwrap_prefix
;
18958 prefix
= get_it_property (it
, Qline_prefix
);
18960 prefix
= Vline_prefix
;
18962 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18964 /* If the prefix is wider than the window, and we try to wrap
18965 it, it would acquire its own wrap prefix, and so on till the
18966 iterator stack overflows. So, don't wrap the prefix. */
18967 it
->line_wrap
= TRUNCATE
;
18968 it
->avoid_cursor_p
= 1;
18974 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18975 only for R2L lines from display_line and display_string, when they
18976 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18977 the line/string needs to be continued on the next glyph row. */
18979 unproduce_glyphs (struct it
*it
, int n
)
18981 struct glyph
*glyph
, *end
;
18983 eassert (it
->glyph_row
);
18984 eassert (it
->glyph_row
->reversed_p
);
18985 eassert (it
->area
== TEXT_AREA
);
18986 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18988 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18989 n
= it
->glyph_row
->used
[TEXT_AREA
];
18990 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18991 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18992 for ( ; glyph
< end
; glyph
++)
18993 glyph
[-n
] = *glyph
;
18996 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18997 and ROW->maxpos. */
18999 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19000 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19001 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19003 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19004 lines' rows is implemented for bidi-reordered rows. */
19006 /* ROW->minpos is the value of min_pos, the minimal buffer position
19007 we have in ROW, or ROW->start.pos if that is smaller. */
19008 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19009 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19011 /* We didn't find buffer positions smaller than ROW->start, or
19012 didn't find _any_ valid buffer positions in any of the glyphs,
19013 so we must trust the iterator's computed positions. */
19014 row
->minpos
= row
->start
.pos
;
19017 max_pos
= CHARPOS (it
->current
.pos
);
19018 max_bpos
= BYTEPOS (it
->current
.pos
);
19021 /* Here are the various use-cases for ending the row, and the
19022 corresponding values for ROW->maxpos:
19024 Line ends in a newline from buffer eol_pos + 1
19025 Line is continued from buffer max_pos + 1
19026 Line is truncated on right it->current.pos
19027 Line ends in a newline from string max_pos + 1(*)
19028 (*) + 1 only when line ends in a forward scan
19029 Line is continued from string max_pos
19030 Line is continued from display vector max_pos
19031 Line is entirely from a string min_pos == max_pos
19032 Line is entirely from a display vector min_pos == max_pos
19033 Line that ends at ZV ZV
19035 If you discover other use-cases, please add them here as
19037 if (row
->ends_at_zv_p
)
19038 row
->maxpos
= it
->current
.pos
;
19039 else if (row
->used
[TEXT_AREA
])
19041 int seen_this_string
= 0;
19042 struct glyph_row
*r1
= row
- 1;
19044 /* Did we see the same display string on the previous row? */
19045 if (STRINGP (it
->object
)
19046 /* this is not the first row */
19047 && row
> it
->w
->desired_matrix
->rows
19048 /* previous row is not the header line */
19049 && !r1
->mode_line_p
19050 /* previous row also ends in a newline from a string */
19051 && r1
->ends_in_newline_from_string_p
)
19053 struct glyph
*start
, *end
;
19055 /* Search for the last glyph of the previous row that came
19056 from buffer or string. Depending on whether the row is
19057 L2R or R2L, we need to process it front to back or the
19058 other way round. */
19059 if (!r1
->reversed_p
)
19061 start
= r1
->glyphs
[TEXT_AREA
];
19062 end
= start
+ r1
->used
[TEXT_AREA
];
19063 /* Glyphs inserted by redisplay have an integer (zero)
19064 as their object. */
19066 && INTEGERP ((end
- 1)->object
)
19067 && (end
- 1)->charpos
<= 0)
19071 if (EQ ((end
- 1)->object
, it
->object
))
19072 seen_this_string
= 1;
19075 /* If all the glyphs of the previous row were inserted
19076 by redisplay, it means the previous row was
19077 produced from a single newline, which is only
19078 possible if that newline came from the same string
19079 as the one which produced this ROW. */
19080 seen_this_string
= 1;
19084 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19085 start
= end
+ r1
->used
[TEXT_AREA
];
19087 && INTEGERP ((end
+ 1)->object
)
19088 && (end
+ 1)->charpos
<= 0)
19092 if (EQ ((end
+ 1)->object
, it
->object
))
19093 seen_this_string
= 1;
19096 seen_this_string
= 1;
19099 /* Take note of each display string that covers a newline only
19100 once, the first time we see it. This is for when a display
19101 string includes more than one newline in it. */
19102 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19104 /* If we were scanning the buffer forward when we displayed
19105 the string, we want to account for at least one buffer
19106 position that belongs to this row (position covered by
19107 the display string), so that cursor positioning will
19108 consider this row as a candidate when point is at the end
19109 of the visual line represented by this row. This is not
19110 required when scanning back, because max_pos will already
19111 have a much larger value. */
19112 if (CHARPOS (row
->end
.pos
) > max_pos
)
19113 INC_BOTH (max_pos
, max_bpos
);
19114 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19116 else if (CHARPOS (it
->eol_pos
) > 0)
19117 SET_TEXT_POS (row
->maxpos
,
19118 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19119 else if (row
->continued_p
)
19121 /* If max_pos is different from IT's current position, it
19122 means IT->method does not belong to the display element
19123 at max_pos. However, it also means that the display
19124 element at max_pos was displayed in its entirety on this
19125 line, which is equivalent to saying that the next line
19126 starts at the next buffer position. */
19127 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19128 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19131 INC_BOTH (max_pos
, max_bpos
);
19132 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19135 else if (row
->truncated_on_right_p
)
19136 /* display_line already called reseat_at_next_visible_line_start,
19137 which puts the iterator at the beginning of the next line, in
19138 the logical order. */
19139 row
->maxpos
= it
->current
.pos
;
19140 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19141 /* A line that is entirely from a string/image/stretch... */
19142 row
->maxpos
= row
->minpos
;
19147 row
->maxpos
= it
->current
.pos
;
19150 /* Construct the glyph row IT->glyph_row in the desired matrix of
19151 IT->w from text at the current position of IT. See dispextern.h
19152 for an overview of struct it. Value is non-zero if
19153 IT->glyph_row displays text, as opposed to a line displaying ZV
19157 display_line (struct it
*it
)
19159 struct glyph_row
*row
= it
->glyph_row
;
19160 Lisp_Object overlay_arrow_string
;
19162 void *wrap_data
= NULL
;
19163 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19164 int wrap_row_used
= -1;
19165 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19166 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19167 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19168 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19169 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19171 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19172 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19174 /* We always start displaying at hpos zero even if hscrolled. */
19175 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19177 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19178 >= it
->w
->desired_matrix
->nrows
)
19180 it
->w
->nrows_scale_factor
++;
19181 it
->f
->fonts_changed
= 1;
19185 /* Clear the result glyph row and enable it. */
19186 prepare_desired_row (row
);
19188 row
->y
= it
->current_y
;
19189 row
->start
= it
->start
;
19190 row
->continuation_lines_width
= it
->continuation_lines_width
;
19191 row
->displays_text_p
= 1;
19192 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19193 it
->starts_in_middle_of_char_p
= 0;
19195 /* Arrange the overlays nicely for our purposes. Usually, we call
19196 display_line on only one line at a time, in which case this
19197 can't really hurt too much, or we call it on lines which appear
19198 one after another in the buffer, in which case all calls to
19199 recenter_overlay_lists but the first will be pretty cheap. */
19200 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19202 /* Move over display elements that are not visible because we are
19203 hscrolled. This may stop at an x-position < IT->first_visible_x
19204 if the first glyph is partially visible or if we hit a line end. */
19205 if (it
->current_x
< it
->first_visible_x
)
19207 enum move_it_result move_result
;
19209 this_line_min_pos
= row
->start
.pos
;
19210 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19211 MOVE_TO_POS
| MOVE_TO_X
);
19212 /* If we are under a large hscroll, move_it_in_display_line_to
19213 could hit the end of the line without reaching
19214 it->first_visible_x. Pretend that we did reach it. This is
19215 especially important on a TTY, where we will call
19216 extend_face_to_end_of_line, which needs to know how many
19217 blank glyphs to produce. */
19218 if (it
->current_x
< it
->first_visible_x
19219 && (move_result
== MOVE_NEWLINE_OR_CR
19220 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19221 it
->current_x
= it
->first_visible_x
;
19223 /* Record the smallest positions seen while we moved over
19224 display elements that are not visible. This is needed by
19225 redisplay_internal for optimizing the case where the cursor
19226 stays inside the same line. The rest of this function only
19227 considers positions that are actually displayed, so
19228 RECORD_MAX_MIN_POS will not otherwise record positions that
19229 are hscrolled to the left of the left edge of the window. */
19230 min_pos
= CHARPOS (this_line_min_pos
);
19231 min_bpos
= BYTEPOS (this_line_min_pos
);
19235 /* We only do this when not calling `move_it_in_display_line_to'
19236 above, because move_it_in_display_line_to calls
19237 handle_line_prefix itself. */
19238 handle_line_prefix (it
);
19241 /* Get the initial row height. This is either the height of the
19242 text hscrolled, if there is any, or zero. */
19243 row
->ascent
= it
->max_ascent
;
19244 row
->height
= it
->max_ascent
+ it
->max_descent
;
19245 row
->phys_ascent
= it
->max_phys_ascent
;
19246 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19247 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19249 /* Utility macro to record max and min buffer positions seen until now. */
19250 #define RECORD_MAX_MIN_POS(IT) \
19253 int composition_p = !STRINGP ((IT)->string) \
19254 && ((IT)->what == IT_COMPOSITION); \
19255 ptrdiff_t current_pos = \
19256 composition_p ? (IT)->cmp_it.charpos \
19257 : IT_CHARPOS (*(IT)); \
19258 ptrdiff_t current_bpos = \
19259 composition_p ? CHAR_TO_BYTE (current_pos) \
19260 : IT_BYTEPOS (*(IT)); \
19261 if (current_pos < min_pos) \
19263 min_pos = current_pos; \
19264 min_bpos = current_bpos; \
19266 if (IT_CHARPOS (*it) > max_pos) \
19268 max_pos = IT_CHARPOS (*it); \
19269 max_bpos = IT_BYTEPOS (*it); \
19274 /* Loop generating characters. The loop is left with IT on the next
19275 character to display. */
19278 int n_glyphs_before
, hpos_before
, x_before
;
19280 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19282 /* Retrieve the next thing to display. Value is zero if end of
19284 if (!get_next_display_element (it
))
19286 /* Maybe add a space at the end of this line that is used to
19287 display the cursor there under X. Set the charpos of the
19288 first glyph of blank lines not corresponding to any text
19290 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19291 row
->exact_window_width_line_p
= 1;
19292 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19293 || row
->used
[TEXT_AREA
] == 0)
19295 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19296 row
->displays_text_p
= 0;
19298 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19299 && (!MINI_WINDOW_P (it
->w
)
19300 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19301 row
->indicate_empty_line_p
= 1;
19304 it
->continuation_lines_width
= 0;
19305 row
->ends_at_zv_p
= 1;
19306 /* A row that displays right-to-left text must always have
19307 its last face extended all the way to the end of line,
19308 even if this row ends in ZV, because we still write to
19309 the screen left to right. We also need to extend the
19310 last face if the default face is remapped to some
19311 different face, otherwise the functions that clear
19312 portions of the screen will clear with the default face's
19313 background color. */
19314 if (row
->reversed_p
19315 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19316 extend_face_to_end_of_line (it
);
19320 /* Now, get the metrics of what we want to display. This also
19321 generates glyphs in `row' (which is IT->glyph_row). */
19322 n_glyphs_before
= row
->used
[TEXT_AREA
];
19325 /* Remember the line height so far in case the next element doesn't
19326 fit on the line. */
19327 if (it
->line_wrap
!= TRUNCATE
)
19329 ascent
= it
->max_ascent
;
19330 descent
= it
->max_descent
;
19331 phys_ascent
= it
->max_phys_ascent
;
19332 phys_descent
= it
->max_phys_descent
;
19334 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19336 if (IT_DISPLAYING_WHITESPACE (it
))
19340 SAVE_IT (wrap_it
, *it
, wrap_data
);
19342 wrap_row_used
= row
->used
[TEXT_AREA
];
19343 wrap_row_ascent
= row
->ascent
;
19344 wrap_row_height
= row
->height
;
19345 wrap_row_phys_ascent
= row
->phys_ascent
;
19346 wrap_row_phys_height
= row
->phys_height
;
19347 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19348 wrap_row_min_pos
= min_pos
;
19349 wrap_row_min_bpos
= min_bpos
;
19350 wrap_row_max_pos
= max_pos
;
19351 wrap_row_max_bpos
= max_bpos
;
19357 PRODUCE_GLYPHS (it
);
19359 /* If this display element was in marginal areas, continue with
19361 if (it
->area
!= TEXT_AREA
)
19363 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19364 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19365 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19366 row
->phys_height
= max (row
->phys_height
,
19367 it
->max_phys_ascent
+ it
->max_phys_descent
);
19368 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19369 it
->max_extra_line_spacing
);
19370 set_iterator_to_next (it
, 1);
19374 /* Does the display element fit on the line? If we truncate
19375 lines, we should draw past the right edge of the window. If
19376 we don't truncate, we want to stop so that we can display the
19377 continuation glyph before the right margin. If lines are
19378 continued, there are two possible strategies for characters
19379 resulting in more than 1 glyph (e.g. tabs): Display as many
19380 glyphs as possible in this line and leave the rest for the
19381 continuation line, or display the whole element in the next
19382 line. Original redisplay did the former, so we do it also. */
19383 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19384 hpos_before
= it
->hpos
;
19387 if (/* Not a newline. */
19389 /* Glyphs produced fit entirely in the line. */
19390 && it
->current_x
< it
->last_visible_x
)
19392 it
->hpos
+= nglyphs
;
19393 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19394 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19395 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19396 row
->phys_height
= max (row
->phys_height
,
19397 it
->max_phys_ascent
+ it
->max_phys_descent
);
19398 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19399 it
->max_extra_line_spacing
);
19400 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19401 row
->x
= x
- it
->first_visible_x
;
19402 /* Record the maximum and minimum buffer positions seen so
19403 far in glyphs that will be displayed by this row. */
19405 RECORD_MAX_MIN_POS (it
);
19410 struct glyph
*glyph
;
19412 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19414 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19415 new_x
= x
+ glyph
->pixel_width
;
19417 if (/* Lines are continued. */
19418 it
->line_wrap
!= TRUNCATE
19419 && (/* Glyph doesn't fit on the line. */
19420 new_x
> it
->last_visible_x
19421 /* Or it fits exactly on a window system frame. */
19422 || (new_x
== it
->last_visible_x
19423 && FRAME_WINDOW_P (it
->f
)
19424 && (row
->reversed_p
19425 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19426 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19428 /* End of a continued line. */
19431 || (new_x
== it
->last_visible_x
19432 && FRAME_WINDOW_P (it
->f
)
19433 && (row
->reversed_p
19434 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19435 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19437 /* Current glyph is the only one on the line or
19438 fits exactly on the line. We must continue
19439 the line because we can't draw the cursor
19440 after the glyph. */
19441 row
->continued_p
= 1;
19442 it
->current_x
= new_x
;
19443 it
->continuation_lines_width
+= new_x
;
19445 if (i
== nglyphs
- 1)
19447 /* If line-wrap is on, check if a previous
19448 wrap point was found. */
19449 if (wrap_row_used
> 0
19450 /* Even if there is a previous wrap
19451 point, continue the line here as
19452 usual, if (i) the previous character
19453 was a space or tab AND (ii) the
19454 current character is not. */
19456 || IT_DISPLAYING_WHITESPACE (it
)))
19459 /* Record the maximum and minimum buffer
19460 positions seen so far in glyphs that will be
19461 displayed by this row. */
19463 RECORD_MAX_MIN_POS (it
);
19464 set_iterator_to_next (it
, 1);
19465 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19467 if (!get_next_display_element (it
))
19469 row
->exact_window_width_line_p
= 1;
19470 it
->continuation_lines_width
= 0;
19471 row
->continued_p
= 0;
19472 row
->ends_at_zv_p
= 1;
19474 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19476 row
->continued_p
= 0;
19477 row
->exact_window_width_line_p
= 1;
19481 else if (it
->bidi_p
)
19482 RECORD_MAX_MIN_POS (it
);
19484 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19485 && !FRAME_WINDOW_P (it
->f
))
19487 /* A padding glyph that doesn't fit on this line.
19488 This means the whole character doesn't fit
19490 if (row
->reversed_p
)
19491 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19492 - n_glyphs_before
);
19493 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19495 /* Fill the rest of the row with continuation
19496 glyphs like in 20.x. */
19497 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19498 < row
->glyphs
[1 + TEXT_AREA
])
19499 produce_special_glyphs (it
, IT_CONTINUATION
);
19501 row
->continued_p
= 1;
19502 it
->current_x
= x_before
;
19503 it
->continuation_lines_width
+= x_before
;
19505 /* Restore the height to what it was before the
19506 element not fitting on the line. */
19507 it
->max_ascent
= ascent
;
19508 it
->max_descent
= descent
;
19509 it
->max_phys_ascent
= phys_ascent
;
19510 it
->max_phys_descent
= phys_descent
;
19512 else if (wrap_row_used
> 0)
19515 if (row
->reversed_p
)
19516 unproduce_glyphs (it
,
19517 row
->used
[TEXT_AREA
] - wrap_row_used
);
19518 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19519 it
->continuation_lines_width
+= wrap_x
;
19520 row
->used
[TEXT_AREA
] = wrap_row_used
;
19521 row
->ascent
= wrap_row_ascent
;
19522 row
->height
= wrap_row_height
;
19523 row
->phys_ascent
= wrap_row_phys_ascent
;
19524 row
->phys_height
= wrap_row_phys_height
;
19525 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19526 min_pos
= wrap_row_min_pos
;
19527 min_bpos
= wrap_row_min_bpos
;
19528 max_pos
= wrap_row_max_pos
;
19529 max_bpos
= wrap_row_max_bpos
;
19530 row
->continued_p
= 1;
19531 row
->ends_at_zv_p
= 0;
19532 row
->exact_window_width_line_p
= 0;
19533 it
->continuation_lines_width
+= x
;
19535 /* Make sure that a non-default face is extended
19536 up to the right margin of the window. */
19537 extend_face_to_end_of_line (it
);
19539 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19541 /* A TAB that extends past the right edge of the
19542 window. This produces a single glyph on
19543 window system frames. We leave the glyph in
19544 this row and let it fill the row, but don't
19545 consume the TAB. */
19546 if ((row
->reversed_p
19547 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19548 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19549 produce_special_glyphs (it
, IT_CONTINUATION
);
19550 it
->continuation_lines_width
+= it
->last_visible_x
;
19551 row
->ends_in_middle_of_char_p
= 1;
19552 row
->continued_p
= 1;
19553 glyph
->pixel_width
= it
->last_visible_x
- x
;
19554 it
->starts_in_middle_of_char_p
= 1;
19558 /* Something other than a TAB that draws past
19559 the right edge of the window. Restore
19560 positions to values before the element. */
19561 if (row
->reversed_p
)
19562 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19563 - (n_glyphs_before
+ i
));
19564 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19566 /* Display continuation glyphs. */
19567 it
->current_x
= x_before
;
19568 it
->continuation_lines_width
+= x
;
19569 if (!FRAME_WINDOW_P (it
->f
)
19570 || (row
->reversed_p
19571 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19572 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19573 produce_special_glyphs (it
, IT_CONTINUATION
);
19574 row
->continued_p
= 1;
19576 extend_face_to_end_of_line (it
);
19578 if (nglyphs
> 1 && i
> 0)
19580 row
->ends_in_middle_of_char_p
= 1;
19581 it
->starts_in_middle_of_char_p
= 1;
19584 /* Restore the height to what it was before the
19585 element not fitting on the line. */
19586 it
->max_ascent
= ascent
;
19587 it
->max_descent
= descent
;
19588 it
->max_phys_ascent
= phys_ascent
;
19589 it
->max_phys_descent
= phys_descent
;
19594 else if (new_x
> it
->first_visible_x
)
19596 /* Increment number of glyphs actually displayed. */
19599 /* Record the maximum and minimum buffer positions
19600 seen so far in glyphs that will be displayed by
19603 RECORD_MAX_MIN_POS (it
);
19605 if (x
< it
->first_visible_x
)
19606 /* Glyph is partially visible, i.e. row starts at
19607 negative X position. */
19608 row
->x
= x
- it
->first_visible_x
;
19612 /* Glyph is completely off the left margin of the
19613 window. This should not happen because of the
19614 move_it_in_display_line at the start of this
19615 function, unless the text display area of the
19616 window is empty. */
19617 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19620 /* Even if this display element produced no glyphs at all,
19621 we want to record its position. */
19622 if (it
->bidi_p
&& nglyphs
== 0)
19623 RECORD_MAX_MIN_POS (it
);
19625 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19626 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19627 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19628 row
->phys_height
= max (row
->phys_height
,
19629 it
->max_phys_ascent
+ it
->max_phys_descent
);
19630 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19631 it
->max_extra_line_spacing
);
19633 /* End of this display line if row is continued. */
19634 if (row
->continued_p
|| row
->ends_at_zv_p
)
19639 /* Is this a line end? If yes, we're also done, after making
19640 sure that a non-default face is extended up to the right
19641 margin of the window. */
19642 if (ITERATOR_AT_END_OF_LINE_P (it
))
19644 int used_before
= row
->used
[TEXT_AREA
];
19646 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19648 /* Add a space at the end of the line that is used to
19649 display the cursor there. */
19650 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19651 append_space_for_newline (it
, 0);
19653 /* Extend the face to the end of the line. */
19654 extend_face_to_end_of_line (it
);
19656 /* Make sure we have the position. */
19657 if (used_before
== 0)
19658 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19660 /* Record the position of the newline, for use in
19662 it
->eol_pos
= it
->current
.pos
;
19664 /* Consume the line end. This skips over invisible lines. */
19665 set_iterator_to_next (it
, 1);
19666 it
->continuation_lines_width
= 0;
19670 /* Proceed with next display element. Note that this skips
19671 over lines invisible because of selective display. */
19672 set_iterator_to_next (it
, 1);
19674 /* If we truncate lines, we are done when the last displayed
19675 glyphs reach past the right margin of the window. */
19676 if (it
->line_wrap
== TRUNCATE
19677 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19678 ? (it
->current_x
>= it
->last_visible_x
)
19679 : (it
->current_x
> it
->last_visible_x
)))
19681 /* Maybe add truncation glyphs. */
19682 if (!FRAME_WINDOW_P (it
->f
)
19683 || (row
->reversed_p
19684 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19685 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19689 if (!row
->reversed_p
)
19691 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19692 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19697 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19698 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19700 /* Remove any padding glyphs at the front of ROW, to
19701 make room for the truncation glyphs we will be
19702 adding below. The loop below always inserts at
19703 least one truncation glyph, so also remove the
19704 last glyph added to ROW. */
19705 unproduce_glyphs (it
, i
+ 1);
19706 /* Adjust i for the loop below. */
19707 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19710 it
->current_x
= x_before
;
19711 if (!FRAME_WINDOW_P (it
->f
))
19713 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19715 row
->used
[TEXT_AREA
] = i
;
19716 produce_special_glyphs (it
, IT_TRUNCATION
);
19721 row
->used
[TEXT_AREA
] = i
;
19722 produce_special_glyphs (it
, IT_TRUNCATION
);
19725 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19727 /* Don't truncate if we can overflow newline into fringe. */
19728 if (!get_next_display_element (it
))
19730 it
->continuation_lines_width
= 0;
19731 row
->ends_at_zv_p
= 1;
19732 row
->exact_window_width_line_p
= 1;
19735 if (ITERATOR_AT_END_OF_LINE_P (it
))
19737 row
->exact_window_width_line_p
= 1;
19738 goto at_end_of_line
;
19740 it
->current_x
= x_before
;
19743 row
->truncated_on_right_p
= 1;
19744 it
->continuation_lines_width
= 0;
19745 reseat_at_next_visible_line_start (it
, 0);
19746 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19747 it
->hpos
= hpos_before
;
19753 bidi_unshelve_cache (wrap_data
, 1);
19755 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19756 at the left window margin. */
19757 if (it
->first_visible_x
19758 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19760 if (!FRAME_WINDOW_P (it
->f
)
19761 || (row
->reversed_p
19762 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19763 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19764 insert_left_trunc_glyphs (it
);
19765 row
->truncated_on_left_p
= 1;
19768 /* Remember the position at which this line ends.
19770 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19771 cannot be before the call to find_row_edges below, since that is
19772 where these positions are determined. */
19773 row
->end
= it
->current
;
19776 row
->minpos
= row
->start
.pos
;
19777 row
->maxpos
= row
->end
.pos
;
19781 /* ROW->minpos and ROW->maxpos must be the smallest and
19782 `1 + the largest' buffer positions in ROW. But if ROW was
19783 bidi-reordered, these two positions can be anywhere in the
19784 row, so we must determine them now. */
19785 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19788 /* If the start of this line is the overlay arrow-position, then
19789 mark this glyph row as the one containing the overlay arrow.
19790 This is clearly a mess with variable size fonts. It would be
19791 better to let it be displayed like cursors under X. */
19792 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19793 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19794 !NILP (overlay_arrow_string
)))
19796 /* Overlay arrow in window redisplay is a fringe bitmap. */
19797 if (STRINGP (overlay_arrow_string
))
19799 struct glyph_row
*arrow_row
19800 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19801 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19802 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19803 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19804 struct glyph
*p2
, *end
;
19806 /* Copy the arrow glyphs. */
19807 while (glyph
< arrow_end
)
19810 /* Throw away padding glyphs. */
19812 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19813 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19819 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19824 eassert (INTEGERP (overlay_arrow_string
));
19825 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19827 overlay_arrow_seen
= 1;
19830 /* Highlight trailing whitespace. */
19831 if (!NILP (Vshow_trailing_whitespace
))
19832 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19834 /* Compute pixel dimensions of this line. */
19835 compute_line_metrics (it
);
19837 /* Implementation note: No changes in the glyphs of ROW or in their
19838 faces can be done past this point, because compute_line_metrics
19839 computes ROW's hash value and stores it within the glyph_row
19842 /* Record whether this row ends inside an ellipsis. */
19843 row
->ends_in_ellipsis_p
19844 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19845 && it
->ellipsis_p
);
19847 /* Save fringe bitmaps in this row. */
19848 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19849 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19850 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19851 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19853 it
->left_user_fringe_bitmap
= 0;
19854 it
->left_user_fringe_face_id
= 0;
19855 it
->right_user_fringe_bitmap
= 0;
19856 it
->right_user_fringe_face_id
= 0;
19858 /* Maybe set the cursor. */
19859 cvpos
= it
->w
->cursor
.vpos
;
19861 /* In bidi-reordered rows, keep checking for proper cursor
19862 position even if one has been found already, because buffer
19863 positions in such rows change non-linearly with ROW->VPOS,
19864 when a line is continued. One exception: when we are at ZV,
19865 display cursor on the first suitable glyph row, since all
19866 the empty rows after that also have their position set to ZV. */
19867 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19868 lines' rows is implemented for bidi-reordered rows. */
19870 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19871 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19872 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19873 && cursor_row_p (row
))
19874 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19876 /* Prepare for the next line. This line starts horizontally at (X
19877 HPOS) = (0 0). Vertical positions are incremented. As a
19878 convenience for the caller, IT->glyph_row is set to the next
19880 it
->current_x
= it
->hpos
= 0;
19881 it
->current_y
+= row
->height
;
19882 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19885 /* The next row should by default use the same value of the
19886 reversed_p flag as this one. set_iterator_to_next decides when
19887 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19888 the flag accordingly. */
19889 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19890 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19891 it
->start
= row
->end
;
19892 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
19894 #undef RECORD_MAX_MIN_POS
19897 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19898 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19899 doc
: /* Return paragraph direction at point in BUFFER.
19900 Value is either `left-to-right' or `right-to-left'.
19901 If BUFFER is omitted or nil, it defaults to the current buffer.
19903 Paragraph direction determines how the text in the paragraph is displayed.
19904 In left-to-right paragraphs, text begins at the left margin of the window
19905 and the reading direction is generally left to right. In right-to-left
19906 paragraphs, text begins at the right margin and is read from right to left.
19908 See also `bidi-paragraph-direction'. */)
19909 (Lisp_Object buffer
)
19911 struct buffer
*buf
= current_buffer
;
19912 struct buffer
*old
= buf
;
19914 if (! NILP (buffer
))
19916 CHECK_BUFFER (buffer
);
19917 buf
= XBUFFER (buffer
);
19920 if (NILP (BVAR (buf
, bidi_display_reordering
))
19921 || NILP (BVAR (buf
, enable_multibyte_characters
))
19922 /* When we are loading loadup.el, the character property tables
19923 needed for bidi iteration are not yet available. */
19924 || !NILP (Vpurify_flag
))
19925 return Qleft_to_right
;
19926 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19927 return BVAR (buf
, bidi_paragraph_direction
);
19930 /* Determine the direction from buffer text. We could try to
19931 use current_matrix if it is up to date, but this seems fast
19932 enough as it is. */
19933 struct bidi_it itb
;
19934 ptrdiff_t pos
= BUF_PT (buf
);
19935 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19937 void *itb_data
= bidi_shelve_cache ();
19939 set_buffer_temp (buf
);
19940 /* bidi_paragraph_init finds the base direction of the paragraph
19941 by searching forward from paragraph start. We need the base
19942 direction of the current or _previous_ paragraph, so we need
19943 to make sure we are within that paragraph. To that end, find
19944 the previous non-empty line. */
19945 if (pos
>= ZV
&& pos
> BEGV
)
19946 DEC_BOTH (pos
, bytepos
);
19947 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19948 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19950 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19951 || c
== ' ' || c
== '\t' || c
== '\f')
19953 if (bytepos
<= BEGV_BYTE
)
19958 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19961 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19962 itb
.paragraph_dir
= NEUTRAL_DIR
;
19963 itb
.string
.s
= NULL
;
19964 itb
.string
.lstring
= Qnil
;
19965 itb
.string
.bufpos
= 0;
19966 itb
.string
.unibyte
= 0;
19967 /* We have no window to use here for ignoring window-specific
19968 overlays. Using NULL for window pointer will cause
19969 compute_display_string_pos to use the current buffer. */
19971 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19972 bidi_unshelve_cache (itb_data
, 0);
19973 set_buffer_temp (old
);
19974 switch (itb
.paragraph_dir
)
19977 return Qleft_to_right
;
19980 return Qright_to_left
;
19988 DEFUN ("move-point-visually", Fmove_point_visually
,
19989 Smove_point_visually
, 1, 1, 0,
19990 doc
: /* Move point in the visual order in the specified DIRECTION.
19991 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
19994 Value is the new character position of point. */)
19995 (Lisp_Object direction
)
19997 struct window
*w
= XWINDOW (selected_window
);
19998 struct buffer
*b
= XBUFFER (w
->contents
);
19999 struct glyph_row
*row
;
20001 Lisp_Object paragraph_dir
;
20003 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20004 (!(ROW)->continued_p \
20005 && INTEGERP ((GLYPH)->object) \
20006 && (GLYPH)->type == CHAR_GLYPH \
20007 && (GLYPH)->u.ch == ' ' \
20008 && (GLYPH)->charpos >= 0 \
20009 && !(GLYPH)->avoid_cursor_p)
20011 CHECK_NUMBER (direction
);
20012 dir
= XINT (direction
);
20018 /* If current matrix is up-to-date, we can use the information
20019 recorded in the glyphs, at least as long as the goal is on the
20021 if (w
->window_end_valid
20022 && !windows_or_buffers_changed
20024 && !b
->clip_changed
20025 && !b
->prevent_redisplay_optimizations_p
20026 && !window_outdated (w
)
20027 && w
->cursor
.vpos
>= 0
20028 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20029 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20031 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20032 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20033 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20035 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20037 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20039 SET_PT (g
->charpos
);
20040 w
->cursor
.vpos
= -1;
20041 return make_number (PT
);
20043 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20047 if (BUFFERP (gpt
->object
))
20050 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20051 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20053 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20055 else if (BUFFERP (g
->object
))
20056 new_pos
= g
->charpos
;
20060 w
->cursor
.vpos
= -1;
20061 return make_number (PT
);
20063 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20065 /* Glyphs inserted at the end of a non-empty line for
20066 positioning the cursor have zero charpos, so we must
20067 deduce the value of point by other means. */
20068 if (g
->charpos
> 0)
20069 SET_PT (g
->charpos
);
20070 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20072 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20073 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20076 w
->cursor
.vpos
= -1;
20077 return make_number (PT
);
20080 if (g
== e
|| INTEGERP (g
->object
))
20082 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20083 goto simulate_display
;
20084 if (!row
->reversed_p
)
20088 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20089 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20090 goto simulate_display
;
20094 if (row
->reversed_p
&& !row
->continued_p
)
20096 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20097 w
->cursor
.vpos
= -1;
20098 return make_number (PT
);
20100 g
= row
->glyphs
[TEXT_AREA
];
20101 e
= g
+ row
->used
[TEXT_AREA
];
20102 for ( ; g
< e
; g
++)
20104 if (BUFFERP (g
->object
)
20105 /* Empty lines have only one glyph, which stands
20106 for the newline, and whose charpos is the
20107 buffer position of the newline. */
20108 || ROW_GLYPH_NEWLINE_P (row
, g
)
20109 /* When the buffer ends in a newline, the line at
20110 EOB also has one glyph, but its charpos is -1. */
20111 || (row
->ends_at_zv_p
20112 && !row
->reversed_p
20113 && INTEGERP (g
->object
)
20114 && g
->type
== CHAR_GLYPH
20115 && g
->u
.ch
== ' '))
20117 if (g
->charpos
> 0)
20118 SET_PT (g
->charpos
);
20119 else if (!row
->reversed_p
20120 && row
->ends_at_zv_p
20125 w
->cursor
.vpos
= -1;
20126 return make_number (PT
);
20132 if (!row
->reversed_p
&& !row
->continued_p
)
20134 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20135 w
->cursor
.vpos
= -1;
20136 return make_number (PT
);
20138 e
= row
->glyphs
[TEXT_AREA
];
20139 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20140 for ( ; g
>= e
; g
--)
20142 if (BUFFERP (g
->object
)
20143 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20145 /* Empty R2L lines on GUI frames have the buffer
20146 position of the newline stored in the stretch
20148 || g
->type
== STRETCH_GLYPH
20149 || (row
->ends_at_zv_p
20151 && INTEGERP (g
->object
)
20152 && g
->type
== CHAR_GLYPH
20153 && g
->u
.ch
== ' '))
20155 if (g
->charpos
> 0)
20156 SET_PT (g
->charpos
);
20157 else if (row
->reversed_p
20158 && row
->ends_at_zv_p
20163 w
->cursor
.vpos
= -1;
20164 return make_number (PT
);
20173 /* If we wind up here, we failed to move by using the glyphs, so we
20174 need to simulate display instead. */
20177 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20179 paragraph_dir
= Qleft_to_right
;
20180 if (EQ (paragraph_dir
, Qright_to_left
))
20182 if (PT
<= BEGV
&& dir
< 0)
20183 xsignal0 (Qbeginning_of_buffer
);
20184 else if (PT
>= ZV
&& dir
> 0)
20185 xsignal0 (Qend_of_buffer
);
20188 struct text_pos pt
;
20190 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20192 bool overshoot_expected
= false;
20193 bool target_is_eol_p
= false;
20195 /* Setup the arena. */
20196 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20197 start_display (&it
, w
, pt
);
20199 if (it
.cmp_it
.id
< 0
20200 && it
.method
== GET_FROM_STRING
20201 && it
.area
== TEXT_AREA
20202 && it
.string_from_display_prop_p
20203 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20204 overshoot_expected
= true;
20206 /* Find the X coordinate of point. We start from the beginning
20207 of this or previous line to make sure we are before point in
20208 the logical order (since the move_it_* functions can only
20210 reseat_at_previous_visible_line_start (&it
);
20211 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20212 if (IT_CHARPOS (it
) != PT
)
20213 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20214 -1, -1, -1, MOVE_TO_POS
);
20215 pt_x
= it
.current_x
;
20217 if (dir
> 0 || overshoot_expected
)
20219 struct glyph_row
*row
= it
.glyph_row
;
20221 /* When point is at beginning of line, we don't have
20222 information about the glyph there loaded into struct
20223 it. Calling get_next_display_element fixes that. */
20225 get_next_display_element (&it
);
20226 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20227 it
.glyph_row
= NULL
;
20228 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20229 it
.glyph_row
= row
;
20230 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20231 it, lest it will become out of sync with it's buffer
20233 it
.current_x
= pt_x
;
20236 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20237 pixel_width
= it
.pixel_width
;
20238 if (overshoot_expected
&& at_eol_p
)
20240 else if (pixel_width
<= 0)
20243 /* If there's a display string at point, we are actually at the
20244 glyph to the left of point, so we need to correct the X
20246 if (overshoot_expected
)
20247 pt_x
+= pixel_width
;
20249 /* Compute target X coordinate, either to the left or to the
20250 right of point. On TTY frames, all characters have the same
20251 pixel width of 1, so we can use that. On GUI frames we don't
20252 have an easy way of getting at the pixel width of the
20253 character to the left of point, so we use a different method
20254 of getting to that place. */
20256 target_x
= pt_x
+ pixel_width
;
20258 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20260 /* Target X coordinate could be one line above or below the line
20261 of point, in which case we need to adjust the target X
20262 coordinate. Also, if moving to the left, we need to begin at
20263 the left edge of the point's screen line. */
20268 start_display (&it
, w
, pt
);
20269 reseat_at_previous_visible_line_start (&it
);
20270 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20272 move_it_by_lines (&it
, pt_vpos
);
20276 move_it_by_lines (&it
, -1);
20277 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20278 target_is_eol_p
= true;
20284 || (target_x
>= it
.last_visible_x
20285 && it
.line_wrap
!= TRUNCATE
))
20288 move_it_by_lines (&it
, 0);
20289 move_it_by_lines (&it
, 1);
20294 /* Move to the target X coordinate. */
20295 #ifdef HAVE_WINDOW_SYSTEM
20296 /* On GUI frames, as we don't know the X coordinate of the
20297 character to the left of point, moving point to the left
20298 requires walking, one grapheme cluster at a time, until we
20299 find ourself at a place immediately to the left of the
20300 character at point. */
20301 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20303 struct text_pos new_pos
= it
.current
.pos
;
20304 enum move_it_result rc
= MOVE_X_REACHED
;
20306 while (it
.current_x
+ it
.pixel_width
<= target_x
20307 && rc
== MOVE_X_REACHED
)
20309 int new_x
= it
.current_x
+ it
.pixel_width
;
20311 new_pos
= it
.current
.pos
;
20312 if (new_x
== it
.current_x
)
20314 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20315 MOVE_TO_POS
| MOVE_TO_X
);
20316 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20319 /* If we ended up on a composed character inside
20320 bidi-reordered text (e.g., Hebrew text with diacritics),
20321 the iterator gives us the buffer position of the last (in
20322 logical order) character of the composed grapheme cluster,
20323 which is not what we want. So we cheat: we compute the
20324 character position of the character that follows (in the
20325 logical order) the one where the above loop stopped. That
20326 character will appear on display to the left of point. */
20328 && it
.bidi_it
.scan_dir
== -1
20329 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20331 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20332 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20334 it
.current
.pos
= new_pos
;
20338 if (it
.current_x
!= target_x
)
20339 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20341 /* When lines are truncated, the above loop will stop at the
20342 window edge. But we want to get to the end of line, even if
20343 it is beyond the window edge; automatic hscroll will then
20344 scroll the window to show point as appropriate. */
20345 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20346 && get_next_display_element (&it
))
20348 struct text_pos new_pos
= it
.current
.pos
;
20350 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20352 set_iterator_to_next (&it
, 0);
20353 if (it
.method
== GET_FROM_BUFFER
)
20354 new_pos
= it
.current
.pos
;
20355 if (!get_next_display_element (&it
))
20359 it
.current
.pos
= new_pos
;
20362 /* If we ended up in a display string that covers point, move to
20363 buffer position to the right in the visual order. */
20366 while (IT_CHARPOS (it
) == PT
)
20368 set_iterator_to_next (&it
, 0);
20369 if (!get_next_display_element (&it
))
20374 /* Move point to that position. */
20375 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20378 return make_number (PT
);
20380 #undef ROW_GLYPH_NEWLINE_P
20384 /***********************************************************************
20386 ***********************************************************************/
20388 /* Redisplay the menu bar in the frame for window W.
20390 The menu bar of X frames that don't have X toolkit support is
20391 displayed in a special window W->frame->menu_bar_window.
20393 The menu bar of terminal frames is treated specially as far as
20394 glyph matrices are concerned. Menu bar lines are not part of
20395 windows, so the update is done directly on the frame matrix rows
20396 for the menu bar. */
20399 display_menu_bar (struct window
*w
)
20401 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20406 /* Don't do all this for graphical frames. */
20408 if (FRAME_W32_P (f
))
20411 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20417 if (FRAME_NS_P (f
))
20419 #endif /* HAVE_NS */
20421 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20422 eassert (!FRAME_WINDOW_P (f
));
20423 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20424 it
.first_visible_x
= 0;
20425 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20426 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20427 if (FRAME_WINDOW_P (f
))
20429 /* Menu bar lines are displayed in the desired matrix of the
20430 dummy window menu_bar_window. */
20431 struct window
*menu_w
;
20432 menu_w
= XWINDOW (f
->menu_bar_window
);
20433 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20435 it
.first_visible_x
= 0;
20436 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20439 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20441 /* This is a TTY frame, i.e. character hpos/vpos are used as
20443 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20445 it
.first_visible_x
= 0;
20446 it
.last_visible_x
= FRAME_COLS (f
);
20449 /* FIXME: This should be controlled by a user option. See the
20450 comments in redisplay_tool_bar and display_mode_line about
20452 it
.paragraph_embedding
= L2R
;
20454 /* Clear all rows of the menu bar. */
20455 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20457 struct glyph_row
*row
= it
.glyph_row
+ i
;
20458 clear_glyph_row (row
);
20459 row
->enabled_p
= 1;
20460 row
->full_width_p
= 1;
20463 /* Display all items of the menu bar. */
20464 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20465 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20467 Lisp_Object string
;
20469 /* Stop at nil string. */
20470 string
= AREF (items
, i
+ 1);
20474 /* Remember where item was displayed. */
20475 ASET (items
, i
+ 3, make_number (it
.hpos
));
20477 /* Display the item, pad with one space. */
20478 if (it
.current_x
< it
.last_visible_x
)
20479 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20480 SCHARS (string
) + 1, 0, 0, -1);
20483 /* Fill out the line with spaces. */
20484 if (it
.current_x
< it
.last_visible_x
)
20485 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20487 /* Compute the total height of the lines. */
20488 compute_line_metrics (&it
);
20492 /* Deep copy of a glyph row, including the glyphs. */
20494 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20496 struct glyph
*pointers
[1 + LAST_AREA
];
20497 int to_used
= to
->used
[TEXT_AREA
];
20499 /* Save glyph pointers of TO. */
20500 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20502 /* Do a structure assignment. */
20505 /* Restore original glyph pointers of TO. */
20506 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20508 /* Copy the glyphs. */
20509 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20510 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20512 /* If we filled only part of the TO row, fill the rest with
20513 space_glyph (which will display as empty space). */
20514 if (to_used
> from
->used
[TEXT_AREA
])
20515 fill_up_frame_row_with_spaces (to
, to_used
);
20518 /* Display one menu item on a TTY, by overwriting the glyphs in the
20519 frame F's desired glyph matrix with glyphs produced from the menu
20520 item text. Called from term.c to display TTY drop-down menus one
20523 ITEM_TEXT is the menu item text as a C string.
20525 FACE_ID is the face ID to be used for this menu item. FACE_ID
20526 could specify one of 3 faces: a face for an enabled item, a face
20527 for a disabled item, or a face for a selected item.
20529 X and Y are coordinates of the first glyph in the frame's desired
20530 matrix to be overwritten by the menu item. Since this is a TTY, Y
20531 is the zero-based number of the glyph row and X is the zero-based
20532 glyph number in the row, starting from left, where to start
20533 displaying the item.
20535 SUBMENU non-zero means this menu item drops down a submenu, which
20536 should be indicated by displaying a proper visual cue after the
20540 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20541 int x
, int y
, int submenu
)
20544 struct frame
*f
= SELECTED_FRAME ();
20545 struct window
*w
= XWINDOW (f
->selected_window
);
20546 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20547 struct glyph_row
*row
;
20548 size_t item_len
= strlen (item_text
);
20550 eassert (FRAME_TERMCAP_P (f
));
20552 /* Don't write beyond the matrix's last row. This can happen for
20553 TTY screens that are not high enough to show the entire menu.
20554 (This is actually a bit of defensive programming, as
20555 tty_menu_display already limits the number of menu items to one
20556 less than the number of screen lines.) */
20557 if (y
>= f
->desired_matrix
->nrows
)
20560 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20561 it
.first_visible_x
= 0;
20562 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20563 row
= it
.glyph_row
;
20564 /* Start with the row contents from the current matrix. */
20565 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20566 saved_width
= row
->full_width_p
;
20567 row
->full_width_p
= 1;
20568 saved_reversed
= row
->reversed_p
;
20569 row
->reversed_p
= 0;
20570 row
->enabled_p
= 1;
20572 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20574 eassert (x
< f
->desired_matrix
->matrix_w
);
20575 it
.current_x
= it
.hpos
= x
;
20576 it
.current_y
= it
.vpos
= y
;
20577 saved_used
= row
->used
[TEXT_AREA
];
20578 saved_truncated
= row
->truncated_on_right_p
;
20579 row
->used
[TEXT_AREA
] = x
;
20580 it
.face_id
= face_id
;
20581 it
.line_wrap
= TRUNCATE
;
20583 /* FIXME: This should be controlled by a user option. See the
20584 comments in redisplay_tool_bar and display_mode_line about this.
20585 Also, if paragraph_embedding could ever be R2L, changes will be
20586 needed to avoid shifting to the right the row characters in
20587 term.c:append_glyph. */
20588 it
.paragraph_embedding
= L2R
;
20590 /* Pad with a space on the left. */
20591 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20593 /* Display the menu item, pad with spaces to WIDTH. */
20596 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20597 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20599 /* Indicate with " >" that there's a submenu. */
20600 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20601 FRAME_COLS (f
) - 1, -1);
20604 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20605 width
, 0, FRAME_COLS (f
) - 1, -1);
20607 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20608 row
->truncated_on_right_p
= saved_truncated
;
20609 row
->hash
= row_hash (row
);
20610 row
->full_width_p
= saved_width
;
20611 row
->reversed_p
= saved_reversed
;
20613 #endif /* HAVE_MENUS */
20615 /***********************************************************************
20617 ***********************************************************************/
20619 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20620 FORCE is non-zero, redisplay mode lines unconditionally.
20621 Otherwise, redisplay only mode lines that are garbaged. Value is
20622 the number of windows whose mode lines were redisplayed. */
20625 redisplay_mode_lines (Lisp_Object window
, int force
)
20629 while (!NILP (window
))
20631 struct window
*w
= XWINDOW (window
);
20633 if (WINDOWP (w
->contents
))
20634 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20636 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20637 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20639 struct text_pos lpoint
;
20640 struct buffer
*old
= current_buffer
;
20642 /* Set the window's buffer for the mode line display. */
20643 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20644 set_buffer_internal_1 (XBUFFER (w
->contents
));
20646 /* Point refers normally to the selected window. For any
20647 other window, set up appropriate value. */
20648 if (!EQ (window
, selected_window
))
20650 struct text_pos pt
;
20652 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20653 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20656 /* Display mode lines. */
20657 clear_glyph_matrix (w
->desired_matrix
);
20658 if (display_mode_lines (w
))
20661 w
->must_be_updated_p
= 1;
20664 /* Restore old settings. */
20665 set_buffer_internal_1 (old
);
20666 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20676 /* Display the mode and/or header line of window W. Value is the
20677 sum number of mode lines and header lines displayed. */
20680 display_mode_lines (struct window
*w
)
20682 Lisp_Object old_selected_window
= selected_window
;
20683 Lisp_Object old_selected_frame
= selected_frame
;
20684 Lisp_Object new_frame
= w
->frame
;
20685 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20688 selected_frame
= new_frame
;
20689 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20690 or window's point, then we'd need select_window_1 here as well. */
20691 XSETWINDOW (selected_window
, w
);
20692 XFRAME (new_frame
)->selected_window
= selected_window
;
20694 /* These will be set while the mode line specs are processed. */
20695 line_number_displayed
= 0;
20696 w
->column_number_displayed
= -1;
20698 if (WINDOW_WANTS_MODELINE_P (w
))
20700 struct window
*sel_w
= XWINDOW (old_selected_window
);
20702 /* Select mode line face based on the real selected window. */
20703 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20704 BVAR (current_buffer
, mode_line_format
));
20708 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20710 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20711 BVAR (current_buffer
, header_line_format
));
20715 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20716 selected_frame
= old_selected_frame
;
20717 selected_window
= old_selected_window
;
20722 /* Display mode or header line of window W. FACE_ID specifies which
20723 line to display; it is either MODE_LINE_FACE_ID or
20724 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20725 display. Value is the pixel height of the mode/header line
20729 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20733 ptrdiff_t count
= SPECPDL_INDEX ();
20735 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20736 /* Don't extend on a previously drawn mode-line.
20737 This may happen if called from pos_visible_p. */
20738 it
.glyph_row
->enabled_p
= 0;
20739 prepare_desired_row (it
.glyph_row
);
20741 it
.glyph_row
->mode_line_p
= 1;
20743 /* FIXME: This should be controlled by a user option. But
20744 supporting such an option is not trivial, since the mode line is
20745 made up of many separate strings. */
20746 it
.paragraph_embedding
= L2R
;
20748 record_unwind_protect (unwind_format_mode_line
,
20749 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20751 mode_line_target
= MODE_LINE_DISPLAY
;
20753 /* Temporarily make frame's keyboard the current kboard so that
20754 kboard-local variables in the mode_line_format will get the right
20756 push_kboard (FRAME_KBOARD (it
.f
));
20757 record_unwind_save_match_data ();
20758 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20761 unbind_to (count
, Qnil
);
20763 /* Fill up with spaces. */
20764 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20766 compute_line_metrics (&it
);
20767 it
.glyph_row
->full_width_p
= 1;
20768 it
.glyph_row
->continued_p
= 0;
20769 it
.glyph_row
->truncated_on_left_p
= 0;
20770 it
.glyph_row
->truncated_on_right_p
= 0;
20772 /* Make a 3D mode-line have a shadow at its right end. */
20773 face
= FACE_FROM_ID (it
.f
, face_id
);
20774 extend_face_to_end_of_line (&it
);
20775 if (face
->box
!= FACE_NO_BOX
)
20777 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20778 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20779 last
->right_box_line_p
= 1;
20782 return it
.glyph_row
->height
;
20785 /* Move element ELT in LIST to the front of LIST.
20786 Return the updated list. */
20789 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20791 register Lisp_Object tail
, prev
;
20792 register Lisp_Object tem
;
20796 while (CONSP (tail
))
20802 /* Splice out the link TAIL. */
20804 list
= XCDR (tail
);
20806 Fsetcdr (prev
, XCDR (tail
));
20808 /* Now make it the first. */
20809 Fsetcdr (tail
, list
);
20814 tail
= XCDR (tail
);
20818 /* Not found--return unchanged LIST. */
20822 /* Contribute ELT to the mode line for window IT->w. How it
20823 translates into text depends on its data type.
20825 IT describes the display environment in which we display, as usual.
20827 DEPTH is the depth in recursion. It is used to prevent
20828 infinite recursion here.
20830 FIELD_WIDTH is the number of characters the display of ELT should
20831 occupy in the mode line, and PRECISION is the maximum number of
20832 characters to display from ELT's representation. See
20833 display_string for details.
20835 Returns the hpos of the end of the text generated by ELT.
20837 PROPS is a property list to add to any string we encounter.
20839 If RISKY is nonzero, remove (disregard) any properties in any string
20840 we encounter, and ignore :eval and :propertize.
20842 The global variable `mode_line_target' determines whether the
20843 output is passed to `store_mode_line_noprop',
20844 `store_mode_line_string', or `display_string'. */
20847 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20848 Lisp_Object elt
, Lisp_Object props
, int risky
)
20850 int n
= 0, field
, prec
;
20855 elt
= build_string ("*too-deep*");
20859 switch (XTYPE (elt
))
20863 /* A string: output it and check for %-constructs within it. */
20865 ptrdiff_t offset
= 0;
20867 if (SCHARS (elt
) > 0
20868 && (!NILP (props
) || risky
))
20870 Lisp_Object oprops
, aelt
;
20871 oprops
= Ftext_properties_at (make_number (0), elt
);
20873 /* If the starting string's properties are not what
20874 we want, translate the string. Also, if the string
20875 is risky, do that anyway. */
20877 if (NILP (Fequal (props
, oprops
)) || risky
)
20879 /* If the starting string has properties,
20880 merge the specified ones onto the existing ones. */
20881 if (! NILP (oprops
) && !risky
)
20885 oprops
= Fcopy_sequence (oprops
);
20887 while (CONSP (tem
))
20889 oprops
= Fplist_put (oprops
, XCAR (tem
),
20890 XCAR (XCDR (tem
)));
20891 tem
= XCDR (XCDR (tem
));
20896 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20897 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20899 /* AELT is what we want. Move it to the front
20900 without consing. */
20902 mode_line_proptrans_alist
20903 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20909 /* If AELT has the wrong props, it is useless.
20910 so get rid of it. */
20912 mode_line_proptrans_alist
20913 = Fdelq (aelt
, mode_line_proptrans_alist
);
20915 elt
= Fcopy_sequence (elt
);
20916 Fset_text_properties (make_number (0), Flength (elt
),
20918 /* Add this item to mode_line_proptrans_alist. */
20919 mode_line_proptrans_alist
20920 = Fcons (Fcons (elt
, props
),
20921 mode_line_proptrans_alist
);
20922 /* Truncate mode_line_proptrans_alist
20923 to at most 50 elements. */
20924 tem
= Fnthcdr (make_number (50),
20925 mode_line_proptrans_alist
);
20927 XSETCDR (tem
, Qnil
);
20936 prec
= precision
- n
;
20937 switch (mode_line_target
)
20939 case MODE_LINE_NOPROP
:
20940 case MODE_LINE_TITLE
:
20941 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20943 case MODE_LINE_STRING
:
20944 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20946 case MODE_LINE_DISPLAY
:
20947 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20948 0, prec
, 0, STRING_MULTIBYTE (elt
));
20955 /* Handle the non-literal case. */
20957 while ((precision
<= 0 || n
< precision
)
20958 && SREF (elt
, offset
) != 0
20959 && (mode_line_target
!= MODE_LINE_DISPLAY
20960 || it
->current_x
< it
->last_visible_x
))
20962 ptrdiff_t last_offset
= offset
;
20964 /* Advance to end of string or next format specifier. */
20965 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20968 if (offset
- 1 != last_offset
)
20970 ptrdiff_t nchars
, nbytes
;
20972 /* Output to end of string or up to '%'. Field width
20973 is length of string. Don't output more than
20974 PRECISION allows us. */
20977 prec
= c_string_width (SDATA (elt
) + last_offset
,
20978 offset
- last_offset
, precision
- n
,
20981 switch (mode_line_target
)
20983 case MODE_LINE_NOPROP
:
20984 case MODE_LINE_TITLE
:
20985 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20987 case MODE_LINE_STRING
:
20989 ptrdiff_t bytepos
= last_offset
;
20990 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20991 ptrdiff_t endpos
= (precision
<= 0
20992 ? string_byte_to_char (elt
, offset
)
20993 : charpos
+ nchars
);
20995 n
+= store_mode_line_string (NULL
,
20996 Fsubstring (elt
, make_number (charpos
),
20997 make_number (endpos
)),
21001 case MODE_LINE_DISPLAY
:
21003 ptrdiff_t bytepos
= last_offset
;
21004 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21006 if (precision
<= 0)
21007 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21008 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21010 STRING_MULTIBYTE (elt
));
21015 else /* c == '%' */
21017 ptrdiff_t percent_position
= offset
;
21019 /* Get the specified minimum width. Zero means
21022 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21023 field
= field
* 10 + c
- '0';
21025 /* Don't pad beyond the total padding allowed. */
21026 if (field_width
- n
> 0 && field
> field_width
- n
)
21027 field
= field_width
- n
;
21029 /* Note that either PRECISION <= 0 or N < PRECISION. */
21030 prec
= precision
- n
;
21033 n
+= display_mode_element (it
, depth
, field
, prec
,
21034 Vglobal_mode_string
, props
,
21039 ptrdiff_t bytepos
, charpos
;
21041 Lisp_Object string
;
21043 bytepos
= percent_position
;
21044 charpos
= (STRING_MULTIBYTE (elt
)
21045 ? string_byte_to_char (elt
, bytepos
)
21047 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21048 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21050 switch (mode_line_target
)
21052 case MODE_LINE_NOPROP
:
21053 case MODE_LINE_TITLE
:
21054 n
+= store_mode_line_noprop (spec
, field
, prec
);
21056 case MODE_LINE_STRING
:
21058 Lisp_Object tem
= build_string (spec
);
21059 props
= Ftext_properties_at (make_number (charpos
), elt
);
21060 /* Should only keep face property in props */
21061 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21064 case MODE_LINE_DISPLAY
:
21066 int nglyphs_before
, nwritten
;
21068 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21069 nwritten
= display_string (spec
, string
, elt
,
21074 /* Assign to the glyphs written above the
21075 string where the `%x' came from, position
21079 struct glyph
*glyph
21080 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21084 for (i
= 0; i
< nwritten
; ++i
)
21086 glyph
[i
].object
= elt
;
21087 glyph
[i
].charpos
= charpos
;
21104 /* A symbol: process the value of the symbol recursively
21105 as if it appeared here directly. Avoid error if symbol void.
21106 Special case: if value of symbol is a string, output the string
21109 register Lisp_Object tem
;
21111 /* If the variable is not marked as risky to set
21112 then its contents are risky to use. */
21113 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21116 tem
= Fboundp (elt
);
21119 tem
= Fsymbol_value (elt
);
21120 /* If value is a string, output that string literally:
21121 don't check for % within it. */
21125 if (!EQ (tem
, elt
))
21127 /* Give up right away for nil or t. */
21137 register Lisp_Object car
, tem
;
21139 /* A cons cell: five distinct cases.
21140 If first element is :eval or :propertize, do something special.
21141 If first element is a string or a cons, process all the elements
21142 and effectively concatenate them.
21143 If first element is a negative number, truncate displaying cdr to
21144 at most that many characters. If positive, pad (with spaces)
21145 to at least that many characters.
21146 If first element is a symbol, process the cadr or caddr recursively
21147 according to whether the symbol's value is non-nil or nil. */
21149 if (EQ (car
, QCeval
))
21151 /* An element of the form (:eval FORM) means evaluate FORM
21152 and use the result as mode line elements. */
21157 if (CONSP (XCDR (elt
)))
21160 spec
= safe_eval (XCAR (XCDR (elt
)));
21161 n
+= display_mode_element (it
, depth
, field_width
- n
,
21162 precision
- n
, spec
, props
,
21166 else if (EQ (car
, QCpropertize
))
21168 /* An element of the form (:propertize ELT PROPS...)
21169 means display ELT but applying properties PROPS. */
21174 if (CONSP (XCDR (elt
)))
21175 n
+= display_mode_element (it
, depth
, field_width
- n
,
21176 precision
- n
, XCAR (XCDR (elt
)),
21177 XCDR (XCDR (elt
)), risky
);
21179 else if (SYMBOLP (car
))
21181 tem
= Fboundp (car
);
21185 /* elt is now the cdr, and we know it is a cons cell.
21186 Use its car if CAR has a non-nil value. */
21189 tem
= Fsymbol_value (car
);
21196 /* Symbol's value is nil (or symbol is unbound)
21197 Get the cddr of the original list
21198 and if possible find the caddr and use that. */
21202 else if (!CONSP (elt
))
21207 else if (INTEGERP (car
))
21209 register int lim
= XINT (car
);
21213 /* Negative int means reduce maximum width. */
21214 if (precision
<= 0)
21217 precision
= min (precision
, -lim
);
21221 /* Padding specified. Don't let it be more than
21222 current maximum. */
21224 lim
= min (precision
, lim
);
21226 /* If that's more padding than already wanted, queue it.
21227 But don't reduce padding already specified even if
21228 that is beyond the current truncation point. */
21229 field_width
= max (lim
, field_width
);
21233 else if (STRINGP (car
) || CONSP (car
))
21235 Lisp_Object halftail
= elt
;
21239 && (precision
<= 0 || n
< precision
))
21241 n
+= display_mode_element (it
, depth
,
21242 /* Do padding only after the last
21243 element in the list. */
21244 (! CONSP (XCDR (elt
))
21247 precision
- n
, XCAR (elt
),
21251 if ((len
& 1) == 0)
21252 halftail
= XCDR (halftail
);
21253 /* Check for cycle. */
21254 if (EQ (halftail
, elt
))
21263 elt
= build_string ("*invalid*");
21267 /* Pad to FIELD_WIDTH. */
21268 if (field_width
> 0 && n
< field_width
)
21270 switch (mode_line_target
)
21272 case MODE_LINE_NOPROP
:
21273 case MODE_LINE_TITLE
:
21274 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21276 case MODE_LINE_STRING
:
21277 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21279 case MODE_LINE_DISPLAY
:
21280 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21289 /* Store a mode-line string element in mode_line_string_list.
21291 If STRING is non-null, display that C string. Otherwise, the Lisp
21292 string LISP_STRING is displayed.
21294 FIELD_WIDTH is the minimum number of output glyphs to produce.
21295 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21296 with spaces. FIELD_WIDTH <= 0 means don't pad.
21298 PRECISION is the maximum number of characters to output from
21299 STRING. PRECISION <= 0 means don't truncate the string.
21301 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21302 properties to the string.
21304 PROPS are the properties to add to the string.
21305 The mode_line_string_face face property is always added to the string.
21309 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21310 int field_width
, int precision
, Lisp_Object props
)
21315 if (string
!= NULL
)
21317 len
= strlen (string
);
21318 if (precision
> 0 && len
> precision
)
21320 lisp_string
= make_string (string
, len
);
21322 props
= mode_line_string_face_prop
;
21323 else if (!NILP (mode_line_string_face
))
21325 Lisp_Object face
= Fplist_get (props
, Qface
);
21326 props
= Fcopy_sequence (props
);
21328 face
= mode_line_string_face
;
21330 face
= list2 (face
, mode_line_string_face
);
21331 props
= Fplist_put (props
, Qface
, face
);
21333 Fadd_text_properties (make_number (0), make_number (len
),
21334 props
, lisp_string
);
21338 len
= XFASTINT (Flength (lisp_string
));
21339 if (precision
> 0 && len
> precision
)
21342 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21345 if (!NILP (mode_line_string_face
))
21349 props
= Ftext_properties_at (make_number (0), lisp_string
);
21350 face
= Fplist_get (props
, Qface
);
21352 face
= mode_line_string_face
;
21354 face
= list2 (face
, mode_line_string_face
);
21355 props
= list2 (Qface
, face
);
21357 lisp_string
= Fcopy_sequence (lisp_string
);
21360 Fadd_text_properties (make_number (0), make_number (len
),
21361 props
, lisp_string
);
21366 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21370 if (field_width
> len
)
21372 field_width
-= len
;
21373 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21375 Fadd_text_properties (make_number (0), make_number (field_width
),
21376 props
, lisp_string
);
21377 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21385 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21387 doc
: /* Format a string out of a mode line format specification.
21388 First arg FORMAT specifies the mode line format (see `mode-line-format'
21389 for details) to use.
21391 By default, the format is evaluated for the currently selected window.
21393 Optional second arg FACE specifies the face property to put on all
21394 characters for which no face is specified. The value nil means the
21395 default face. The value t means whatever face the window's mode line
21396 currently uses (either `mode-line' or `mode-line-inactive',
21397 depending on whether the window is the selected window or not).
21398 An integer value means the value string has no text
21401 Optional third and fourth args WINDOW and BUFFER specify the window
21402 and buffer to use as the context for the formatting (defaults
21403 are the selected window and the WINDOW's buffer). */)
21404 (Lisp_Object format
, Lisp_Object face
,
21405 Lisp_Object window
, Lisp_Object buffer
)
21410 struct buffer
*old_buffer
= NULL
;
21412 int no_props
= INTEGERP (face
);
21413 ptrdiff_t count
= SPECPDL_INDEX ();
21415 int string_start
= 0;
21417 w
= decode_any_window (window
);
21418 XSETWINDOW (window
, w
);
21421 buffer
= w
->contents
;
21422 CHECK_BUFFER (buffer
);
21424 /* Make formatting the modeline a non-op when noninteractive, otherwise
21425 there will be problems later caused by a partially initialized frame. */
21426 if (NILP (format
) || noninteractive
)
21427 return empty_unibyte_string
;
21432 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21433 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21434 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21435 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21436 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21437 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21438 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21441 old_buffer
= current_buffer
;
21443 /* Save things including mode_line_proptrans_alist,
21444 and set that to nil so that we don't alter the outer value. */
21445 record_unwind_protect (unwind_format_mode_line
,
21446 format_mode_line_unwind_data
21447 (XFRAME (WINDOW_FRAME (w
)),
21448 old_buffer
, selected_window
, 1));
21449 mode_line_proptrans_alist
= Qnil
;
21451 Fselect_window (window
, Qt
);
21452 set_buffer_internal_1 (XBUFFER (buffer
));
21454 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21458 mode_line_target
= MODE_LINE_NOPROP
;
21459 mode_line_string_face_prop
= Qnil
;
21460 mode_line_string_list
= Qnil
;
21461 string_start
= MODE_LINE_NOPROP_LEN (0);
21465 mode_line_target
= MODE_LINE_STRING
;
21466 mode_line_string_list
= Qnil
;
21467 mode_line_string_face
= face
;
21468 mode_line_string_face_prop
21469 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21472 push_kboard (FRAME_KBOARD (it
.f
));
21473 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21478 len
= MODE_LINE_NOPROP_LEN (string_start
);
21479 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21483 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21484 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21485 empty_unibyte_string
);
21488 unbind_to (count
, Qnil
);
21492 /* Write a null-terminated, right justified decimal representation of
21493 the positive integer D to BUF using a minimal field width WIDTH. */
21496 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21498 register char *p
= buf
;
21506 *p
++ = d
% 10 + '0';
21511 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21522 /* Write a null-terminated, right justified decimal and "human
21523 readable" representation of the nonnegative integer D to BUF using
21524 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21526 static const char power_letter
[] =
21540 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21542 /* We aim to represent the nonnegative integer D as
21543 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21544 ptrdiff_t quotient
= d
;
21546 /* -1 means: do not use TENTHS. */
21550 /* Length of QUOTIENT.TENTHS as a string. */
21556 if (quotient
>= 1000)
21558 /* Scale to the appropriate EXPONENT. */
21561 remainder
= quotient
% 1000;
21565 while (quotient
>= 1000);
21567 /* Round to nearest and decide whether to use TENTHS or not. */
21570 tenths
= remainder
/ 100;
21571 if (remainder
% 100 >= 50)
21578 if (quotient
== 10)
21586 if (remainder
>= 500)
21588 if (quotient
< 999)
21599 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21600 if (tenths
== -1 && quotient
<= 99)
21607 p
= psuffix
= buf
+ max (width
, length
);
21609 /* Print EXPONENT. */
21610 *psuffix
++ = power_letter
[exponent
];
21613 /* Print TENTHS. */
21616 *--p
= '0' + tenths
;
21620 /* Print QUOTIENT. */
21623 int digit
= quotient
% 10;
21624 *--p
= '0' + digit
;
21626 while ((quotient
/= 10) != 0);
21628 /* Print leading spaces. */
21633 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21634 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21635 type of CODING_SYSTEM. Return updated pointer into BUF. */
21637 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21640 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21643 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21644 const unsigned char *eol_str
;
21646 /* The EOL conversion we are using. */
21647 Lisp_Object eoltype
;
21649 val
= CODING_SYSTEM_SPEC (coding_system
);
21652 if (!VECTORP (val
)) /* Not yet decided. */
21654 *buf
++ = multibyte
? '-' : ' ';
21656 eoltype
= eol_mnemonic_undecided
;
21657 /* Don't mention EOL conversion if it isn't decided. */
21662 Lisp_Object eolvalue
;
21664 attrs
= AREF (val
, 0);
21665 eolvalue
= AREF (val
, 2);
21668 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21673 /* The EOL conversion that is normal on this system. */
21675 if (NILP (eolvalue
)) /* Not yet decided. */
21676 eoltype
= eol_mnemonic_undecided
;
21677 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21678 eoltype
= eol_mnemonic_undecided
;
21679 else /* eolvalue is Qunix, Qdos, or Qmac. */
21680 eoltype
= (EQ (eolvalue
, Qunix
)
21681 ? eol_mnemonic_unix
21682 : (EQ (eolvalue
, Qdos
) == 1
21683 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21689 /* Mention the EOL conversion if it is not the usual one. */
21690 if (STRINGP (eoltype
))
21692 eol_str
= SDATA (eoltype
);
21693 eol_str_len
= SBYTES (eoltype
);
21695 else if (CHARACTERP (eoltype
))
21697 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21698 int c
= XFASTINT (eoltype
);
21699 eol_str_len
= CHAR_STRING (c
, tmp
);
21704 eol_str
= invalid_eol_type
;
21705 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21707 memcpy (buf
, eol_str
, eol_str_len
);
21708 buf
+= eol_str_len
;
21714 /* Return a string for the output of a mode line %-spec for window W,
21715 generated by character C. FIELD_WIDTH > 0 means pad the string
21716 returned with spaces to that value. Return a Lisp string in
21717 *STRING if the resulting string is taken from that Lisp string.
21719 Note we operate on the current buffer for most purposes. */
21721 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21723 static const char *
21724 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21725 Lisp_Object
*string
)
21728 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21729 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21730 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21731 produce strings from numerical values, so limit preposterously
21732 large values of FIELD_WIDTH to avoid overrunning the buffer's
21733 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21734 bytes plus the terminating null. */
21735 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21736 struct buffer
*b
= current_buffer
;
21744 if (!NILP (BVAR (b
, read_only
)))
21746 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21751 /* This differs from %* only for a modified read-only buffer. */
21752 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21754 if (!NILP (BVAR (b
, read_only
)))
21759 /* This differs from %* in ignoring read-only-ness. */
21760 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21772 if (command_loop_level
> 5)
21774 p
= decode_mode_spec_buf
;
21775 for (i
= 0; i
< command_loop_level
; i
++)
21778 return decode_mode_spec_buf
;
21786 if (command_loop_level
> 5)
21788 p
= decode_mode_spec_buf
;
21789 for (i
= 0; i
< command_loop_level
; i
++)
21792 return decode_mode_spec_buf
;
21799 /* Let lots_of_dashes be a string of infinite length. */
21800 if (mode_line_target
== MODE_LINE_NOPROP
21801 || mode_line_target
== MODE_LINE_STRING
)
21803 if (field_width
<= 0
21804 || field_width
> sizeof (lots_of_dashes
))
21806 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21807 decode_mode_spec_buf
[i
] = '-';
21808 decode_mode_spec_buf
[i
] = '\0';
21809 return decode_mode_spec_buf
;
21812 return lots_of_dashes
;
21816 obj
= BVAR (b
, name
);
21820 /* %c and %l are ignored in `frame-title-format'.
21821 (In redisplay_internal, the frame title is drawn _before_ the
21822 windows are updated, so the stuff which depends on actual
21823 window contents (such as %l) may fail to render properly, or
21824 even crash emacs.) */
21825 if (mode_line_target
== MODE_LINE_TITLE
)
21829 ptrdiff_t col
= current_column ();
21830 w
->column_number_displayed
= col
;
21831 pint2str (decode_mode_spec_buf
, width
, col
);
21832 return decode_mode_spec_buf
;
21836 #ifndef SYSTEM_MALLOC
21838 if (NILP (Vmemory_full
))
21841 return "!MEM FULL! ";
21848 /* %F displays the frame name. */
21849 if (!NILP (f
->title
))
21850 return SSDATA (f
->title
);
21851 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21852 return SSDATA (f
->name
);
21856 obj
= BVAR (b
, filename
);
21861 ptrdiff_t size
= ZV
- BEGV
;
21862 pint2str (decode_mode_spec_buf
, width
, size
);
21863 return decode_mode_spec_buf
;
21868 ptrdiff_t size
= ZV
- BEGV
;
21869 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21870 return decode_mode_spec_buf
;
21875 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21876 ptrdiff_t topline
, nlines
, height
;
21879 /* %c and %l are ignored in `frame-title-format'. */
21880 if (mode_line_target
== MODE_LINE_TITLE
)
21883 startpos
= marker_position (w
->start
);
21884 startpos_byte
= marker_byte_position (w
->start
);
21885 height
= WINDOW_TOTAL_LINES (w
);
21887 /* If we decided that this buffer isn't suitable for line numbers,
21888 don't forget that too fast. */
21889 if (w
->base_line_pos
== -1)
21892 /* If the buffer is very big, don't waste time. */
21893 if (INTEGERP (Vline_number_display_limit
)
21894 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21896 w
->base_line_pos
= 0;
21897 w
->base_line_number
= 0;
21901 if (w
->base_line_number
> 0
21902 && w
->base_line_pos
> 0
21903 && w
->base_line_pos
<= startpos
)
21905 line
= w
->base_line_number
;
21906 linepos
= w
->base_line_pos
;
21907 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21912 linepos
= BUF_BEGV (b
);
21913 linepos_byte
= BUF_BEGV_BYTE (b
);
21916 /* Count lines from base line to window start position. */
21917 nlines
= display_count_lines (linepos_byte
,
21921 topline
= nlines
+ line
;
21923 /* Determine a new base line, if the old one is too close
21924 or too far away, or if we did not have one.
21925 "Too close" means it's plausible a scroll-down would
21926 go back past it. */
21927 if (startpos
== BUF_BEGV (b
))
21929 w
->base_line_number
= topline
;
21930 w
->base_line_pos
= BUF_BEGV (b
);
21932 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21933 || linepos
== BUF_BEGV (b
))
21935 ptrdiff_t limit
= BUF_BEGV (b
);
21936 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21937 ptrdiff_t position
;
21938 ptrdiff_t distance
=
21939 (height
* 2 + 30) * line_number_display_limit_width
;
21941 if (startpos
- distance
> limit
)
21943 limit
= startpos
- distance
;
21944 limit_byte
= CHAR_TO_BYTE (limit
);
21947 nlines
= display_count_lines (startpos_byte
,
21949 - (height
* 2 + 30),
21951 /* If we couldn't find the lines we wanted within
21952 line_number_display_limit_width chars per line,
21953 give up on line numbers for this window. */
21954 if (position
== limit_byte
&& limit
== startpos
- distance
)
21956 w
->base_line_pos
= -1;
21957 w
->base_line_number
= 0;
21961 w
->base_line_number
= topline
- nlines
;
21962 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21965 /* Now count lines from the start pos to point. */
21966 nlines
= display_count_lines (startpos_byte
,
21967 PT_BYTE
, PT
, &junk
);
21969 /* Record that we did display the line number. */
21970 line_number_displayed
= 1;
21972 /* Make the string to show. */
21973 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21974 return decode_mode_spec_buf
;
21977 char* p
= decode_mode_spec_buf
;
21978 int pad
= width
- 2;
21984 return decode_mode_spec_buf
;
21990 obj
= BVAR (b
, mode_name
);
21994 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22000 ptrdiff_t pos
= marker_position (w
->start
);
22001 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22003 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22005 if (pos
<= BUF_BEGV (b
))
22010 else if (pos
<= BUF_BEGV (b
))
22014 if (total
> 1000000)
22015 /* Do it differently for a large value, to avoid overflow. */
22016 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22018 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22019 /* We can't normally display a 3-digit number,
22020 so get us a 2-digit number that is close. */
22023 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22024 return decode_mode_spec_buf
;
22028 /* Display percentage of size above the bottom of the screen. */
22031 ptrdiff_t toppos
= marker_position (w
->start
);
22032 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22033 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22035 if (botpos
>= BUF_ZV (b
))
22037 if (toppos
<= BUF_BEGV (b
))
22044 if (total
> 1000000)
22045 /* Do it differently for a large value, to avoid overflow. */
22046 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22048 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22049 /* We can't normally display a 3-digit number,
22050 so get us a 2-digit number that is close. */
22053 if (toppos
<= BUF_BEGV (b
))
22054 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22056 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22057 return decode_mode_spec_buf
;
22062 /* status of process */
22063 obj
= Fget_buffer_process (Fcurrent_buffer ());
22065 return "no process";
22067 obj
= Fsymbol_name (Fprocess_status (obj
));
22073 ptrdiff_t count
= inhibit_garbage_collection ();
22074 Lisp_Object val
= call1 (intern ("file-remote-p"),
22075 BVAR (current_buffer
, directory
));
22076 unbind_to (count
, Qnil
);
22085 /* coding-system (not including end-of-line format) */
22087 /* coding-system (including end-of-line type) */
22089 int eol_flag
= (c
== 'Z');
22090 char *p
= decode_mode_spec_buf
;
22092 if (! FRAME_WINDOW_P (f
))
22094 /* No need to mention EOL here--the terminal never needs
22095 to do EOL conversion. */
22096 p
= decode_mode_spec_coding (CODING_ID_NAME
22097 (FRAME_KEYBOARD_CODING (f
)->id
),
22099 p
= decode_mode_spec_coding (CODING_ID_NAME
22100 (FRAME_TERMINAL_CODING (f
)->id
),
22103 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22106 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22107 #ifdef subprocesses
22108 obj
= Fget_buffer_process (Fcurrent_buffer ());
22109 if (PROCESSP (obj
))
22111 p
= decode_mode_spec_coding
22112 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22113 p
= decode_mode_spec_coding
22114 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22116 #endif /* subprocesses */
22119 return decode_mode_spec_buf
;
22126 return SSDATA (obj
);
22133 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22134 means count lines back from START_BYTE. But don't go beyond
22135 LIMIT_BYTE. Return the number of lines thus found (always
22138 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22139 either the position COUNT lines after/before START_BYTE, if we
22140 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22144 display_count_lines (ptrdiff_t start_byte
,
22145 ptrdiff_t limit_byte
, ptrdiff_t count
,
22146 ptrdiff_t *byte_pos_ptr
)
22148 register unsigned char *cursor
;
22149 unsigned char *base
;
22151 register ptrdiff_t ceiling
;
22152 register unsigned char *ceiling_addr
;
22153 ptrdiff_t orig_count
= count
;
22155 /* If we are not in selective display mode,
22156 check only for newlines. */
22157 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22158 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22162 while (start_byte
< limit_byte
)
22164 ceiling
= BUFFER_CEILING_OF (start_byte
);
22165 ceiling
= min (limit_byte
- 1, ceiling
);
22166 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22167 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22171 if (selective_display
)
22173 while (*cursor
!= '\n' && *cursor
!= 015
22174 && ++cursor
!= ceiling_addr
)
22176 if (cursor
== ceiling_addr
)
22181 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22190 start_byte
+= cursor
- base
;
22191 *byte_pos_ptr
= start_byte
;
22195 while (cursor
< ceiling_addr
);
22197 start_byte
+= ceiling_addr
- base
;
22202 while (start_byte
> limit_byte
)
22204 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22205 ceiling
= max (limit_byte
, ceiling
);
22206 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22207 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22210 if (selective_display
)
22212 while (--cursor
>= ceiling_addr
22213 && *cursor
!= '\n' && *cursor
!= 015)
22215 if (cursor
< ceiling_addr
)
22220 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22227 start_byte
+= cursor
- base
+ 1;
22228 *byte_pos_ptr
= start_byte
;
22229 /* When scanning backwards, we should
22230 not count the newline posterior to which we stop. */
22231 return - orig_count
- 1;
22234 start_byte
+= ceiling_addr
- base
;
22238 *byte_pos_ptr
= limit_byte
;
22241 return - orig_count
+ count
;
22242 return orig_count
- count
;
22248 /***********************************************************************
22250 ***********************************************************************/
22252 /* Display a NUL-terminated string, starting with index START.
22254 If STRING is non-null, display that C string. Otherwise, the Lisp
22255 string LISP_STRING is displayed. There's a case that STRING is
22256 non-null and LISP_STRING is not nil. It means STRING is a string
22257 data of LISP_STRING. In that case, we display LISP_STRING while
22258 ignoring its text properties.
22260 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22261 FACE_STRING. Display STRING or LISP_STRING with the face at
22262 FACE_STRING_POS in FACE_STRING:
22264 Display the string in the environment given by IT, but use the
22265 standard display table, temporarily.
22267 FIELD_WIDTH is the minimum number of output glyphs to produce.
22268 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22269 with spaces. If STRING has more characters, more than FIELD_WIDTH
22270 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22272 PRECISION is the maximum number of characters to output from
22273 STRING. PRECISION < 0 means don't truncate the string.
22275 This is roughly equivalent to printf format specifiers:
22277 FIELD_WIDTH PRECISION PRINTF
22278 ----------------------------------------
22284 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22285 display them, and < 0 means obey the current buffer's value of
22286 enable_multibyte_characters.
22288 Value is the number of columns displayed. */
22291 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22292 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22293 int field_width
, int precision
, int max_x
, int multibyte
)
22295 int hpos_at_start
= it
->hpos
;
22296 int saved_face_id
= it
->face_id
;
22297 struct glyph_row
*row
= it
->glyph_row
;
22298 ptrdiff_t it_charpos
;
22300 /* Initialize the iterator IT for iteration over STRING beginning
22301 with index START. */
22302 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22303 precision
, field_width
, multibyte
);
22304 if (string
&& STRINGP (lisp_string
))
22305 /* LISP_STRING is the one returned by decode_mode_spec. We should
22306 ignore its text properties. */
22307 it
->stop_charpos
= it
->end_charpos
;
22309 /* If displaying STRING, set up the face of the iterator from
22310 FACE_STRING, if that's given. */
22311 if (STRINGP (face_string
))
22317 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22318 0, &endptr
, it
->base_face_id
, 0);
22319 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22320 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22323 /* Set max_x to the maximum allowed X position. Don't let it go
22324 beyond the right edge of the window. */
22326 max_x
= it
->last_visible_x
;
22328 max_x
= min (max_x
, it
->last_visible_x
);
22330 /* Skip over display elements that are not visible. because IT->w is
22332 if (it
->current_x
< it
->first_visible_x
)
22333 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22334 MOVE_TO_POS
| MOVE_TO_X
);
22336 row
->ascent
= it
->max_ascent
;
22337 row
->height
= it
->max_ascent
+ it
->max_descent
;
22338 row
->phys_ascent
= it
->max_phys_ascent
;
22339 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22340 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22342 if (STRINGP (it
->string
))
22343 it_charpos
= IT_STRING_CHARPOS (*it
);
22345 it_charpos
= IT_CHARPOS (*it
);
22347 /* This condition is for the case that we are called with current_x
22348 past last_visible_x. */
22349 while (it
->current_x
< max_x
)
22351 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22353 /* Get the next display element. */
22354 if (!get_next_display_element (it
))
22357 /* Produce glyphs. */
22358 x_before
= it
->current_x
;
22359 n_glyphs_before
= row
->used
[TEXT_AREA
];
22360 PRODUCE_GLYPHS (it
);
22362 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22365 while (i
< nglyphs
)
22367 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22369 if (it
->line_wrap
!= TRUNCATE
22370 && x
+ glyph
->pixel_width
> max_x
)
22372 /* End of continued line or max_x reached. */
22373 if (CHAR_GLYPH_PADDING_P (*glyph
))
22375 /* A wide character is unbreakable. */
22376 if (row
->reversed_p
)
22377 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22378 - n_glyphs_before
);
22379 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22380 it
->current_x
= x_before
;
22384 if (row
->reversed_p
)
22385 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22386 - (n_glyphs_before
+ i
));
22387 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22392 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22394 /* Glyph is at least partially visible. */
22396 if (x
< it
->first_visible_x
)
22397 row
->x
= x
- it
->first_visible_x
;
22401 /* Glyph is off the left margin of the display area.
22402 Should not happen. */
22406 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22407 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22408 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22409 row
->phys_height
= max (row
->phys_height
,
22410 it
->max_phys_ascent
+ it
->max_phys_descent
);
22411 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22412 it
->max_extra_line_spacing
);
22413 x
+= glyph
->pixel_width
;
22417 /* Stop if max_x reached. */
22421 /* Stop at line ends. */
22422 if (ITERATOR_AT_END_OF_LINE_P (it
))
22424 it
->continuation_lines_width
= 0;
22428 set_iterator_to_next (it
, 1);
22429 if (STRINGP (it
->string
))
22430 it_charpos
= IT_STRING_CHARPOS (*it
);
22432 it_charpos
= IT_CHARPOS (*it
);
22434 /* Stop if truncating at the right edge. */
22435 if (it
->line_wrap
== TRUNCATE
22436 && it
->current_x
>= it
->last_visible_x
)
22438 /* Add truncation mark, but don't do it if the line is
22439 truncated at a padding space. */
22440 if (it_charpos
< it
->string_nchars
)
22442 if (!FRAME_WINDOW_P (it
->f
))
22446 if (it
->current_x
> it
->last_visible_x
)
22448 if (!row
->reversed_p
)
22450 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22451 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22456 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22457 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22459 unproduce_glyphs (it
, ii
+ 1);
22460 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22462 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22464 row
->used
[TEXT_AREA
] = ii
;
22465 produce_special_glyphs (it
, IT_TRUNCATION
);
22468 produce_special_glyphs (it
, IT_TRUNCATION
);
22470 row
->truncated_on_right_p
= 1;
22476 /* Maybe insert a truncation at the left. */
22477 if (it
->first_visible_x
22480 if (!FRAME_WINDOW_P (it
->f
)
22481 || (row
->reversed_p
22482 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22483 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22484 insert_left_trunc_glyphs (it
);
22485 row
->truncated_on_left_p
= 1;
22488 it
->face_id
= saved_face_id
;
22490 /* Value is number of columns displayed. */
22491 return it
->hpos
- hpos_at_start
;
22496 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22497 appears as an element of LIST or as the car of an element of LIST.
22498 If PROPVAL is a list, compare each element against LIST in that
22499 way, and return 1/2 if any element of PROPVAL is found in LIST.
22500 Otherwise return 0. This function cannot quit.
22501 The return value is 2 if the text is invisible but with an ellipsis
22502 and 1 if it's invisible and without an ellipsis. */
22505 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22507 register Lisp_Object tail
, proptail
;
22509 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22511 register Lisp_Object tem
;
22513 if (EQ (propval
, tem
))
22515 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22516 return NILP (XCDR (tem
)) ? 1 : 2;
22519 if (CONSP (propval
))
22521 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22523 Lisp_Object propelt
;
22524 propelt
= XCAR (proptail
);
22525 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22527 register Lisp_Object tem
;
22529 if (EQ (propelt
, tem
))
22531 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22532 return NILP (XCDR (tem
)) ? 1 : 2;
22540 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22541 doc
: /* Non-nil if the property makes the text invisible.
22542 POS-OR-PROP can be a marker or number, in which case it is taken to be
22543 a position in the current buffer and the value of the `invisible' property
22544 is checked; or it can be some other value, which is then presumed to be the
22545 value of the `invisible' property of the text of interest.
22546 The non-nil value returned can be t for truly invisible text or something
22547 else if the text is replaced by an ellipsis. */)
22548 (Lisp_Object pos_or_prop
)
22551 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22552 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22554 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22555 return (invis
== 0 ? Qnil
22557 : make_number (invis
));
22560 /* Calculate a width or height in pixels from a specification using
22561 the following elements:
22564 NUM - a (fractional) multiple of the default font width/height
22565 (NUM) - specifies exactly NUM pixels
22566 UNIT - a fixed number of pixels, see below.
22567 ELEMENT - size of a display element in pixels, see below.
22568 (NUM . SPEC) - equals NUM * SPEC
22569 (+ SPEC SPEC ...) - add pixel values
22570 (- SPEC SPEC ...) - subtract pixel values
22571 (- SPEC) - negate pixel value
22574 INT or FLOAT - a number constant
22575 SYMBOL - use symbol's (buffer local) variable binding.
22578 in - pixels per inch *)
22579 mm - pixels per 1/1000 meter *)
22580 cm - pixels per 1/100 meter *)
22581 width - width of current font in pixels.
22582 height - height of current font in pixels.
22584 *) using the ratio(s) defined in display-pixels-per-inch.
22588 left-fringe - left fringe width in pixels
22589 right-fringe - right fringe width in pixels
22591 left-margin - left margin width in pixels
22592 right-margin - right margin width in pixels
22594 scroll-bar - scroll-bar area width in pixels
22598 Pixels corresponding to 5 inches:
22601 Total width of non-text areas on left side of window (if scroll-bar is on left):
22602 '(space :width (+ left-fringe left-margin scroll-bar))
22604 Align to first text column (in header line):
22605 '(space :align-to 0)
22607 Align to middle of text area minus half the width of variable `my-image'
22608 containing a loaded image:
22609 '(space :align-to (0.5 . (- text my-image)))
22611 Width of left margin minus width of 1 character in the default font:
22612 '(space :width (- left-margin 1))
22614 Width of left margin minus width of 2 characters in the current font:
22615 '(space :width (- left-margin (2 . width)))
22617 Center 1 character over left-margin (in header line):
22618 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22620 Different ways to express width of left fringe plus left margin minus one pixel:
22621 '(space :width (- (+ left-fringe left-margin) (1)))
22622 '(space :width (+ left-fringe left-margin (- (1))))
22623 '(space :width (+ left-fringe left-margin (-1)))
22628 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22629 struct font
*font
, int width_p
, int *align_to
)
22633 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22634 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22637 return OK_PIXELS (0);
22639 eassert (FRAME_LIVE_P (it
->f
));
22641 if (SYMBOLP (prop
))
22643 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22645 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22647 if (unit
[0] == 'i' && unit
[1] == 'n')
22649 else if (unit
[0] == 'm' && unit
[1] == 'm')
22651 else if (unit
[0] == 'c' && unit
[1] == 'm')
22657 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22658 : FRAME_RES_Y (it
->f
));
22661 return OK_PIXELS (ppi
/ pixels
);
22666 #ifdef HAVE_WINDOW_SYSTEM
22667 if (EQ (prop
, Qheight
))
22668 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22669 if (EQ (prop
, Qwidth
))
22670 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22672 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22673 return OK_PIXELS (1);
22676 if (EQ (prop
, Qtext
))
22677 return OK_PIXELS (width_p
22678 ? window_box_width (it
->w
, TEXT_AREA
)
22679 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22681 if (align_to
&& *align_to
< 0)
22684 if (EQ (prop
, Qleft
))
22685 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22686 if (EQ (prop
, Qright
))
22687 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22688 if (EQ (prop
, Qcenter
))
22689 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22690 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22691 if (EQ (prop
, Qleft_fringe
))
22692 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22693 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22694 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22695 if (EQ (prop
, Qright_fringe
))
22696 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22697 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22698 : window_box_right_offset (it
->w
, TEXT_AREA
));
22699 if (EQ (prop
, Qleft_margin
))
22700 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22701 if (EQ (prop
, Qright_margin
))
22702 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22703 if (EQ (prop
, Qscroll_bar
))
22704 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22706 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22707 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22708 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22713 if (EQ (prop
, Qleft_fringe
))
22714 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22715 if (EQ (prop
, Qright_fringe
))
22716 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22717 if (EQ (prop
, Qleft_margin
))
22718 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22719 if (EQ (prop
, Qright_margin
))
22720 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22721 if (EQ (prop
, Qscroll_bar
))
22722 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22725 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22726 if (EQ (prop
, Qunbound
))
22730 if (INTEGERP (prop
) || FLOATP (prop
))
22732 int base_unit
= (width_p
22733 ? FRAME_COLUMN_WIDTH (it
->f
)
22734 : FRAME_LINE_HEIGHT (it
->f
));
22735 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22740 Lisp_Object car
= XCAR (prop
);
22741 Lisp_Object cdr
= XCDR (prop
);
22745 #ifdef HAVE_WINDOW_SYSTEM
22746 if (FRAME_WINDOW_P (it
->f
)
22747 && valid_image_p (prop
))
22749 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22750 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22752 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22755 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22761 while (CONSP (cdr
))
22763 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22764 font
, width_p
, align_to
))
22767 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22772 if (EQ (car
, Qminus
))
22774 return OK_PIXELS (pixels
);
22777 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22778 if (EQ (car
, Qunbound
))
22782 if (INTEGERP (car
) || FLOATP (car
))
22785 pixels
= XFLOATINT (car
);
22787 return OK_PIXELS (pixels
);
22788 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22789 font
, width_p
, align_to
))
22790 return OK_PIXELS (pixels
* fact
);
22801 /***********************************************************************
22803 ***********************************************************************/
22805 #ifdef HAVE_WINDOW_SYSTEM
22810 dump_glyph_string (struct glyph_string
*s
)
22812 fprintf (stderr
, "glyph string\n");
22813 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22814 s
->x
, s
->y
, s
->width
, s
->height
);
22815 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22816 fprintf (stderr
, " hl = %d\n", s
->hl
);
22817 fprintf (stderr
, " left overhang = %d, right = %d\n",
22818 s
->left_overhang
, s
->right_overhang
);
22819 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22820 fprintf (stderr
, " extends to end of line = %d\n",
22821 s
->extends_to_end_of_line_p
);
22822 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22823 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22826 #endif /* GLYPH_DEBUG */
22828 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22829 of XChar2b structures for S; it can't be allocated in
22830 init_glyph_string because it must be allocated via `alloca'. W
22831 is the window on which S is drawn. ROW and AREA are the glyph row
22832 and area within the row from which S is constructed. START is the
22833 index of the first glyph structure covered by S. HL is a
22834 face-override for drawing S. */
22837 #define OPTIONAL_HDC(hdc) HDC hdc,
22838 #define DECLARE_HDC(hdc) HDC hdc;
22839 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22840 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22843 #ifndef OPTIONAL_HDC
22844 #define OPTIONAL_HDC(hdc)
22845 #define DECLARE_HDC(hdc)
22846 #define ALLOCATE_HDC(hdc, f)
22847 #define RELEASE_HDC(hdc, f)
22851 init_glyph_string (struct glyph_string
*s
,
22853 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22854 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22856 memset (s
, 0, sizeof *s
);
22858 s
->f
= XFRAME (w
->frame
);
22862 s
->display
= FRAME_X_DISPLAY (s
->f
);
22863 s
->window
= FRAME_X_WINDOW (s
->f
);
22864 s
->char2b
= char2b
;
22868 s
->first_glyph
= row
->glyphs
[area
] + start
;
22869 s
->height
= row
->height
;
22870 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22871 s
->ybase
= s
->y
+ row
->ascent
;
22875 /* Append the list of glyph strings with head H and tail T to the list
22876 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22879 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22880 struct glyph_string
*h
, struct glyph_string
*t
)
22894 /* Prepend the list of glyph strings with head H and tail T to the
22895 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22899 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22900 struct glyph_string
*h
, struct glyph_string
*t
)
22914 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22915 Set *HEAD and *TAIL to the resulting list. */
22918 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22919 struct glyph_string
*s
)
22921 s
->next
= s
->prev
= NULL
;
22922 append_glyph_string_lists (head
, tail
, s
, s
);
22926 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22927 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22928 make sure that X resources for the face returned are allocated.
22929 Value is a pointer to a realized face that is ready for display if
22930 DISPLAY_P is non-zero. */
22932 static struct face
*
22933 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22934 XChar2b
*char2b
, int display_p
)
22936 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22941 code
= face
->font
->driver
->encode_char (face
->font
, c
);
22943 if (code
== FONT_INVALID_CODE
)
22946 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22948 /* Make sure X resources of the face are allocated. */
22949 #ifdef HAVE_X_WINDOWS
22953 eassert (face
!= NULL
);
22954 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22961 /* Get face and two-byte form of character glyph GLYPH on frame F.
22962 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22963 a pointer to a realized face that is ready for display. */
22965 static struct face
*
22966 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22967 XChar2b
*char2b
, int *two_byte_p
)
22972 eassert (glyph
->type
== CHAR_GLYPH
);
22973 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22975 /* Make sure X resources of the face are allocated. */
22976 eassert (face
!= NULL
);
22977 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22984 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22985 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22987 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22989 if (code
== FONT_INVALID_CODE
)
22993 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22998 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22999 Return 1 if FONT has a glyph for C, otherwise return 0. */
23002 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23006 if (CHAR_BYTE8_P (c
))
23007 code
= CHAR_TO_BYTE8 (c
);
23009 code
= font
->driver
->encode_char (font
, c
);
23011 if (code
== FONT_INVALID_CODE
)
23013 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23018 /* Fill glyph string S with composition components specified by S->cmp.
23020 BASE_FACE is the base face of the composition.
23021 S->cmp_from is the index of the first component for S.
23023 OVERLAPS non-zero means S should draw the foreground only, and use
23024 its physical height for clipping. See also draw_glyphs.
23026 Value is the index of a component not in S. */
23029 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23033 /* For all glyphs of this composition, starting at the offset
23034 S->cmp_from, until we reach the end of the definition or encounter a
23035 glyph that requires the different face, add it to S. */
23040 s
->for_overlaps
= overlaps
;
23043 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23045 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23047 /* TAB in a composition means display glyphs with padding space
23048 on the left or right. */
23051 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23054 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23061 s
->font
= s
->face
->font
;
23063 else if (s
->face
!= face
)
23071 if (s
->face
== NULL
)
23073 s
->face
= base_face
->ascii_face
;
23074 s
->font
= s
->face
->font
;
23077 /* All glyph strings for the same composition has the same width,
23078 i.e. the width set for the first component of the composition. */
23079 s
->width
= s
->first_glyph
->pixel_width
;
23081 /* If the specified font could not be loaded, use the frame's
23082 default font, but record the fact that we couldn't load it in
23083 the glyph string so that we can draw rectangles for the
23084 characters of the glyph string. */
23085 if (s
->font
== NULL
)
23087 s
->font_not_found_p
= 1;
23088 s
->font
= FRAME_FONT (s
->f
);
23091 /* Adjust base line for subscript/superscript text. */
23092 s
->ybase
+= s
->first_glyph
->voffset
;
23094 /* This glyph string must always be drawn with 16-bit functions. */
23101 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23102 int start
, int end
, int overlaps
)
23104 struct glyph
*glyph
, *last
;
23105 Lisp_Object lgstring
;
23108 s
->for_overlaps
= overlaps
;
23109 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23110 last
= s
->row
->glyphs
[s
->area
] + end
;
23111 s
->cmp_id
= glyph
->u
.cmp
.id
;
23112 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23113 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23114 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23115 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23116 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23118 while (glyph
< last
23119 && glyph
->u
.cmp
.automatic
23120 && glyph
->u
.cmp
.id
== s
->cmp_id
23121 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23122 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23124 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23126 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23127 unsigned code
= LGLYPH_CODE (lglyph
);
23129 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23131 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23132 return glyph
- s
->row
->glyphs
[s
->area
];
23136 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23137 See the comment of fill_glyph_string for arguments.
23138 Value is the index of the first glyph not in S. */
23142 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23143 int start
, int end
, int overlaps
)
23145 struct glyph
*glyph
, *last
;
23148 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23149 s
->for_overlaps
= overlaps
;
23150 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23151 last
= s
->row
->glyphs
[s
->area
] + end
;
23152 voffset
= glyph
->voffset
;
23153 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23154 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23156 s
->width
= glyph
->pixel_width
;
23158 while (glyph
< last
23159 && glyph
->type
== GLYPHLESS_GLYPH
23160 && glyph
->voffset
== voffset
23161 && glyph
->face_id
== face_id
)
23164 s
->width
+= glyph
->pixel_width
;
23167 s
->ybase
+= voffset
;
23168 return glyph
- s
->row
->glyphs
[s
->area
];
23172 /* Fill glyph string S from a sequence of character glyphs.
23174 FACE_ID is the face id of the string. START is the index of the
23175 first glyph to consider, END is the index of the last + 1.
23176 OVERLAPS non-zero means S should draw the foreground only, and use
23177 its physical height for clipping. See also draw_glyphs.
23179 Value is the index of the first glyph not in S. */
23182 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23183 int start
, int end
, int overlaps
)
23185 struct glyph
*glyph
, *last
;
23187 int glyph_not_available_p
;
23189 eassert (s
->f
== XFRAME (s
->w
->frame
));
23190 eassert (s
->nchars
== 0);
23191 eassert (start
>= 0 && end
> start
);
23193 s
->for_overlaps
= overlaps
;
23194 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23195 last
= s
->row
->glyphs
[s
->area
] + end
;
23196 voffset
= glyph
->voffset
;
23197 s
->padding_p
= glyph
->padding_p
;
23198 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23200 while (glyph
< last
23201 && glyph
->type
== CHAR_GLYPH
23202 && glyph
->voffset
== voffset
23203 /* Same face id implies same font, nowadays. */
23204 && glyph
->face_id
== face_id
23205 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23209 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23210 s
->char2b
+ s
->nchars
,
23212 s
->two_byte_p
= two_byte_p
;
23214 eassert (s
->nchars
<= end
- start
);
23215 s
->width
+= glyph
->pixel_width
;
23216 if (glyph
++->padding_p
!= s
->padding_p
)
23220 s
->font
= s
->face
->font
;
23222 /* If the specified font could not be loaded, use the frame's font,
23223 but record the fact that we couldn't load it in
23224 S->font_not_found_p so that we can draw rectangles for the
23225 characters of the glyph string. */
23226 if (s
->font
== NULL
|| glyph_not_available_p
)
23228 s
->font_not_found_p
= 1;
23229 s
->font
= FRAME_FONT (s
->f
);
23232 /* Adjust base line for subscript/superscript text. */
23233 s
->ybase
+= voffset
;
23235 eassert (s
->face
&& s
->face
->gc
);
23236 return glyph
- s
->row
->glyphs
[s
->area
];
23240 /* Fill glyph string S from image glyph S->first_glyph. */
23243 fill_image_glyph_string (struct glyph_string
*s
)
23245 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23246 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23248 s
->slice
= s
->first_glyph
->slice
.img
;
23249 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23250 s
->font
= s
->face
->font
;
23251 s
->width
= s
->first_glyph
->pixel_width
;
23253 /* Adjust base line for subscript/superscript text. */
23254 s
->ybase
+= s
->first_glyph
->voffset
;
23258 /* Fill glyph string S from a sequence of stretch glyphs.
23260 START is the index of the first glyph to consider,
23261 END is the index of the last + 1.
23263 Value is the index of the first glyph not in S. */
23266 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23268 struct glyph
*glyph
, *last
;
23269 int voffset
, face_id
;
23271 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23273 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23274 last
= s
->row
->glyphs
[s
->area
] + end
;
23275 face_id
= glyph
->face_id
;
23276 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23277 s
->font
= s
->face
->font
;
23278 s
->width
= glyph
->pixel_width
;
23280 voffset
= glyph
->voffset
;
23284 && glyph
->type
== STRETCH_GLYPH
23285 && glyph
->voffset
== voffset
23286 && glyph
->face_id
== face_id
);
23288 s
->width
+= glyph
->pixel_width
;
23290 /* Adjust base line for subscript/superscript text. */
23291 s
->ybase
+= voffset
;
23293 /* The case that face->gc == 0 is handled when drawing the glyph
23294 string by calling PREPARE_FACE_FOR_DISPLAY. */
23296 return glyph
- s
->row
->glyphs
[s
->area
];
23299 static struct font_metrics
*
23300 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23302 static struct font_metrics metrics
;
23307 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23308 if (code
== FONT_INVALID_CODE
)
23310 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23315 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23316 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23317 assumed to be zero. */
23320 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23322 *left
= *right
= 0;
23324 if (glyph
->type
== CHAR_GLYPH
)
23328 struct font_metrics
*pcm
;
23330 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23331 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23333 if (pcm
->rbearing
> pcm
->width
)
23334 *right
= pcm
->rbearing
- pcm
->width
;
23335 if (pcm
->lbearing
< 0)
23336 *left
= -pcm
->lbearing
;
23339 else if (glyph
->type
== COMPOSITE_GLYPH
)
23341 if (! glyph
->u
.cmp
.automatic
)
23343 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23345 if (cmp
->rbearing
> cmp
->pixel_width
)
23346 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23347 if (cmp
->lbearing
< 0)
23348 *left
= - cmp
->lbearing
;
23352 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23353 struct font_metrics metrics
;
23355 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23356 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23357 if (metrics
.rbearing
> metrics
.width
)
23358 *right
= metrics
.rbearing
- metrics
.width
;
23359 if (metrics
.lbearing
< 0)
23360 *left
= - metrics
.lbearing
;
23366 /* Return the index of the first glyph preceding glyph string S that
23367 is overwritten by S because of S's left overhang. Value is -1
23368 if no glyphs are overwritten. */
23371 left_overwritten (struct glyph_string
*s
)
23375 if (s
->left_overhang
)
23378 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23379 int first
= s
->first_glyph
- glyphs
;
23381 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23382 x
-= glyphs
[i
].pixel_width
;
23393 /* Return the index of the first glyph preceding glyph string S that
23394 is overwriting S because of its right overhang. Value is -1 if no
23395 glyph in front of S overwrites S. */
23398 left_overwriting (struct glyph_string
*s
)
23401 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23402 int first
= s
->first_glyph
- glyphs
;
23406 for (i
= first
- 1; i
>= 0; --i
)
23409 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23412 x
-= glyphs
[i
].pixel_width
;
23419 /* Return the index of the last glyph following glyph string S that is
23420 overwritten by S because of S's right overhang. Value is -1 if
23421 no such glyph is found. */
23424 right_overwritten (struct glyph_string
*s
)
23428 if (s
->right_overhang
)
23431 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23432 int first
= (s
->first_glyph
- glyphs
23433 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23434 int end
= s
->row
->used
[s
->area
];
23436 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23437 x
+= glyphs
[i
].pixel_width
;
23446 /* Return the index of the last glyph following glyph string S that
23447 overwrites S because of its left overhang. Value is negative
23448 if no such glyph is found. */
23451 right_overwriting (struct glyph_string
*s
)
23454 int end
= s
->row
->used
[s
->area
];
23455 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23456 int first
= (s
->first_glyph
- glyphs
23457 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23461 for (i
= first
; i
< end
; ++i
)
23464 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23467 x
+= glyphs
[i
].pixel_width
;
23474 /* Set background width of glyph string S. START is the index of the
23475 first glyph following S. LAST_X is the right-most x-position + 1
23476 in the drawing area. */
23479 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23481 /* If the face of this glyph string has to be drawn to the end of
23482 the drawing area, set S->extends_to_end_of_line_p. */
23484 if (start
== s
->row
->used
[s
->area
]
23485 && s
->area
== TEXT_AREA
23486 && ((s
->row
->fill_line_p
23487 && (s
->hl
== DRAW_NORMAL_TEXT
23488 || s
->hl
== DRAW_IMAGE_RAISED
23489 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23490 || s
->hl
== DRAW_MOUSE_FACE
))
23491 s
->extends_to_end_of_line_p
= 1;
23493 /* If S extends its face to the end of the line, set its
23494 background_width to the distance to the right edge of the drawing
23496 if (s
->extends_to_end_of_line_p
)
23497 s
->background_width
= last_x
- s
->x
+ 1;
23499 s
->background_width
= s
->width
;
23503 /* Compute overhangs and x-positions for glyph string S and its
23504 predecessors, or successors. X is the starting x-position for S.
23505 BACKWARD_P non-zero means process predecessors. */
23508 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23514 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23515 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23525 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23526 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23536 /* The following macros are only called from draw_glyphs below.
23537 They reference the following parameters of that function directly:
23538 `w', `row', `area', and `overlap_p'
23539 as well as the following local variables:
23540 `s', `f', and `hdc' (in W32) */
23543 /* On W32, silently add local `hdc' variable to argument list of
23544 init_glyph_string. */
23545 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23546 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23548 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23549 init_glyph_string (s, char2b, w, row, area, start, hl)
23552 /* Add a glyph string for a stretch glyph to the list of strings
23553 between HEAD and TAIL. START is the index of the stretch glyph in
23554 row area AREA of glyph row ROW. END is the index of the last glyph
23555 in that glyph row area. X is the current output position assigned
23556 to the new glyph string constructed. HL overrides that face of the
23557 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23558 is the right-most x-position of the drawing area. */
23560 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23561 and below -- keep them on one line. */
23562 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23565 s = alloca (sizeof *s); \
23566 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23567 START = fill_stretch_glyph_string (s, START, END); \
23568 append_glyph_string (&HEAD, &TAIL, s); \
23574 /* Add a glyph string for an image glyph to the list of strings
23575 between HEAD and TAIL. START is the index of the image glyph in
23576 row area AREA of glyph row ROW. END is the index of the last glyph
23577 in that glyph row area. X is the current output position assigned
23578 to the new glyph string constructed. HL overrides that face of the
23579 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23580 is the right-most x-position of the drawing area. */
23582 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23585 s = alloca (sizeof *s); \
23586 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23587 fill_image_glyph_string (s); \
23588 append_glyph_string (&HEAD, &TAIL, s); \
23595 /* Add a glyph string for a sequence of character glyphs to the list
23596 of strings between HEAD and TAIL. START is the index of the first
23597 glyph in row area AREA of glyph row ROW that is part of the new
23598 glyph string. END is the index of the last glyph in that glyph row
23599 area. X is the current output position assigned to the new glyph
23600 string constructed. HL overrides that face of the glyph; e.g. it
23601 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23602 right-most x-position of the drawing area. */
23604 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23610 face_id = (row)->glyphs[area][START].face_id; \
23612 s = alloca (sizeof *s); \
23613 char2b = alloca ((END - START) * sizeof *char2b); \
23614 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23615 append_glyph_string (&HEAD, &TAIL, s); \
23617 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23622 /* Add a glyph string for a composite sequence to the list of strings
23623 between HEAD and TAIL. START is the index of the first glyph in
23624 row area AREA of glyph row ROW that is part of the new glyph
23625 string. END is the index of the last glyph in that glyph row area.
23626 X is the current output position assigned to the new glyph string
23627 constructed. HL overrides that face of the glyph; e.g. it is
23628 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23629 x-position of the drawing area. */
23631 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23633 int face_id = (row)->glyphs[area][START].face_id; \
23634 struct face *base_face = FACE_FROM_ID (f, face_id); \
23635 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23636 struct composition *cmp = composition_table[cmp_id]; \
23638 struct glyph_string *first_s = NULL; \
23641 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23643 /* Make glyph_strings for each glyph sequence that is drawable by \
23644 the same face, and append them to HEAD/TAIL. */ \
23645 for (n = 0; n < cmp->glyph_len;) \
23647 s = alloca (sizeof *s); \
23648 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23649 append_glyph_string (&(HEAD), &(TAIL), s); \
23655 n = fill_composite_glyph_string (s, base_face, overlaps); \
23663 /* Add a glyph string for a glyph-string sequence to the list of strings
23664 between HEAD and TAIL. */
23666 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23670 Lisp_Object gstring; \
23672 face_id = (row)->glyphs[area][START].face_id; \
23673 gstring = (composition_gstring_from_id \
23674 ((row)->glyphs[area][START].u.cmp.id)); \
23675 s = alloca (sizeof *s); \
23676 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23677 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23678 append_glyph_string (&(HEAD), &(TAIL), s); \
23680 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23684 /* Add a glyph string for a sequence of glyphless character's glyphs
23685 to the list of strings between HEAD and TAIL. The meanings of
23686 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23688 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23693 face_id = (row)->glyphs[area][START].face_id; \
23695 s = alloca (sizeof *s); \
23696 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23697 append_glyph_string (&HEAD, &TAIL, s); \
23699 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23705 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23706 of AREA of glyph row ROW on window W between indices START and END.
23707 HL overrides the face for drawing glyph strings, e.g. it is
23708 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23709 x-positions of the drawing area.
23711 This is an ugly monster macro construct because we must use alloca
23712 to allocate glyph strings (because draw_glyphs can be called
23713 asynchronously). */
23715 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23718 HEAD = TAIL = NULL; \
23719 while (START < END) \
23721 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23722 switch (first_glyph->type) \
23725 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23729 case COMPOSITE_GLYPH: \
23730 if (first_glyph->u.cmp.automatic) \
23731 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23734 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23738 case STRETCH_GLYPH: \
23739 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23743 case IMAGE_GLYPH: \
23744 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23748 case GLYPHLESS_GLYPH: \
23749 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23759 set_glyph_string_background_width (s, START, LAST_X); \
23766 /* Draw glyphs between START and END in AREA of ROW on window W,
23767 starting at x-position X. X is relative to AREA in W. HL is a
23768 face-override with the following meaning:
23770 DRAW_NORMAL_TEXT draw normally
23771 DRAW_CURSOR draw in cursor face
23772 DRAW_MOUSE_FACE draw in mouse face.
23773 DRAW_INVERSE_VIDEO draw in mode line face
23774 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23775 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23777 If OVERLAPS is non-zero, draw only the foreground of characters and
23778 clip to the physical height of ROW. Non-zero value also defines
23779 the overlapping part to be drawn:
23781 OVERLAPS_PRED overlap with preceding rows
23782 OVERLAPS_SUCC overlap with succeeding rows
23783 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23784 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23786 Value is the x-position reached, relative to AREA of W. */
23789 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23790 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23791 enum draw_glyphs_face hl
, int overlaps
)
23793 struct glyph_string
*head
, *tail
;
23794 struct glyph_string
*s
;
23795 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23796 int i
, j
, x_reached
, last_x
, area_left
= 0;
23797 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23800 ALLOCATE_HDC (hdc
, f
);
23802 /* Let's rather be paranoid than getting a SEGV. */
23803 end
= min (end
, row
->used
[area
]);
23804 start
= clip_to_bounds (0, start
, end
);
23806 /* Translate X to frame coordinates. Set last_x to the right
23807 end of the drawing area. */
23808 if (row
->full_width_p
)
23810 /* X is relative to the left edge of W, without scroll bars
23812 area_left
= WINDOW_LEFT_EDGE_X (w
);
23813 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23817 area_left
= window_box_left (w
, area
);
23818 last_x
= area_left
+ window_box_width (w
, area
);
23822 /* Build a doubly-linked list of glyph_string structures between
23823 head and tail from what we have to draw. Note that the macro
23824 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23825 the reason we use a separate variable `i'. */
23827 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23829 x_reached
= tail
->x
+ tail
->background_width
;
23833 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23834 the row, redraw some glyphs in front or following the glyph
23835 strings built above. */
23836 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23838 struct glyph_string
*h
, *t
;
23839 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23840 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23841 int check_mouse_face
= 0;
23844 /* If mouse highlighting is on, we may need to draw adjacent
23845 glyphs using mouse-face highlighting. */
23846 if (area
== TEXT_AREA
&& row
->mouse_face_p
23847 && hlinfo
->mouse_face_beg_row
>= 0
23848 && hlinfo
->mouse_face_end_row
>= 0)
23850 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23852 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23853 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23855 check_mouse_face
= 1;
23856 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23857 ? hlinfo
->mouse_face_beg_col
: 0;
23858 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23859 ? hlinfo
->mouse_face_end_col
23860 : row
->used
[TEXT_AREA
];
23864 /* Compute overhangs for all glyph strings. */
23865 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23866 for (s
= head
; s
; s
= s
->next
)
23867 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23869 /* Prepend glyph strings for glyphs in front of the first glyph
23870 string that are overwritten because of the first glyph
23871 string's left overhang. The background of all strings
23872 prepended must be drawn because the first glyph string
23874 i
= left_overwritten (head
);
23877 enum draw_glyphs_face overlap_hl
;
23879 /* If this row contains mouse highlighting, attempt to draw
23880 the overlapped glyphs with the correct highlight. This
23881 code fails if the overlap encompasses more than one glyph
23882 and mouse-highlight spans only some of these glyphs.
23883 However, making it work perfectly involves a lot more
23884 code, and I don't know if the pathological case occurs in
23885 practice, so we'll stick to this for now. --- cyd */
23886 if (check_mouse_face
23887 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23888 overlap_hl
= DRAW_MOUSE_FACE
;
23890 overlap_hl
= DRAW_NORMAL_TEXT
;
23893 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23894 overlap_hl
, dummy_x
, last_x
);
23896 compute_overhangs_and_x (t
, head
->x
, 1);
23897 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23901 /* Prepend glyph strings for glyphs in front of the first glyph
23902 string that overwrite that glyph string because of their
23903 right overhang. For these strings, only the foreground must
23904 be drawn, because it draws over the glyph string at `head'.
23905 The background must not be drawn because this would overwrite
23906 right overhangs of preceding glyphs for which no glyph
23908 i
= left_overwriting (head
);
23911 enum draw_glyphs_face overlap_hl
;
23913 if (check_mouse_face
23914 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23915 overlap_hl
= DRAW_MOUSE_FACE
;
23917 overlap_hl
= DRAW_NORMAL_TEXT
;
23920 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23921 overlap_hl
, dummy_x
, last_x
);
23922 for (s
= h
; s
; s
= s
->next
)
23923 s
->background_filled_p
= 1;
23924 compute_overhangs_and_x (t
, head
->x
, 1);
23925 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23928 /* Append glyphs strings for glyphs following the last glyph
23929 string tail that are overwritten by tail. The background of
23930 these strings has to be drawn because tail's foreground draws
23932 i
= right_overwritten (tail
);
23935 enum draw_glyphs_face overlap_hl
;
23937 if (check_mouse_face
23938 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23939 overlap_hl
= DRAW_MOUSE_FACE
;
23941 overlap_hl
= DRAW_NORMAL_TEXT
;
23943 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23944 overlap_hl
, x
, last_x
);
23945 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23946 we don't have `end = i;' here. */
23947 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23948 append_glyph_string_lists (&head
, &tail
, h
, t
);
23952 /* Append glyph strings for glyphs following the last glyph
23953 string tail that overwrite tail. The foreground of such
23954 glyphs has to be drawn because it writes into the background
23955 of tail. The background must not be drawn because it could
23956 paint over the foreground of following glyphs. */
23957 i
= right_overwriting (tail
);
23960 enum draw_glyphs_face overlap_hl
;
23961 if (check_mouse_face
23962 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23963 overlap_hl
= DRAW_MOUSE_FACE
;
23965 overlap_hl
= DRAW_NORMAL_TEXT
;
23968 i
++; /* We must include the Ith glyph. */
23969 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23970 overlap_hl
, x
, last_x
);
23971 for (s
= h
; s
; s
= s
->next
)
23972 s
->background_filled_p
= 1;
23973 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23974 append_glyph_string_lists (&head
, &tail
, h
, t
);
23976 if (clip_head
|| clip_tail
)
23977 for (s
= head
; s
; s
= s
->next
)
23979 s
->clip_head
= clip_head
;
23980 s
->clip_tail
= clip_tail
;
23984 /* Draw all strings. */
23985 for (s
= head
; s
; s
= s
->next
)
23986 FRAME_RIF (f
)->draw_glyph_string (s
);
23989 /* When focus a sole frame and move horizontally, this sets on_p to 0
23990 causing a failure to erase prev cursor position. */
23991 if (area
== TEXT_AREA
23992 && !row
->full_width_p
23993 /* When drawing overlapping rows, only the glyph strings'
23994 foreground is drawn, which doesn't erase a cursor
23998 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23999 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24000 : (tail
? tail
->x
+ tail
->background_width
: x
));
24004 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24005 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24009 /* Value is the x-position up to which drawn, relative to AREA of W.
24010 This doesn't include parts drawn because of overhangs. */
24011 if (row
->full_width_p
)
24012 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24014 x_reached
-= area_left
;
24016 RELEASE_HDC (hdc
, f
);
24021 /* Expand row matrix if too narrow. Don't expand if area
24024 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24026 if (!it->f->fonts_changed \
24027 && (it->glyph_row->glyphs[area] \
24028 < it->glyph_row->glyphs[area + 1])) \
24030 it->w->ncols_scale_factor++; \
24031 it->f->fonts_changed = 1; \
24035 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24036 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24039 append_glyph (struct it
*it
)
24041 struct glyph
*glyph
;
24042 enum glyph_row_area area
= it
->area
;
24044 eassert (it
->glyph_row
);
24045 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24047 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24048 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24050 /* If the glyph row is reversed, we need to prepend the glyph
24051 rather than append it. */
24052 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24056 /* Make room for the additional glyph. */
24057 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24059 glyph
= it
->glyph_row
->glyphs
[area
];
24061 glyph
->charpos
= CHARPOS (it
->position
);
24062 glyph
->object
= it
->object
;
24063 if (it
->pixel_width
> 0)
24065 glyph
->pixel_width
= it
->pixel_width
;
24066 glyph
->padding_p
= 0;
24070 /* Assure at least 1-pixel width. Otherwise, cursor can't
24071 be displayed correctly. */
24072 glyph
->pixel_width
= 1;
24073 glyph
->padding_p
= 1;
24075 glyph
->ascent
= it
->ascent
;
24076 glyph
->descent
= it
->descent
;
24077 glyph
->voffset
= it
->voffset
;
24078 glyph
->type
= CHAR_GLYPH
;
24079 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24080 glyph
->multibyte_p
= it
->multibyte_p
;
24081 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24083 /* In R2L rows, the left and the right box edges need to be
24084 drawn in reverse direction. */
24085 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24086 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24090 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24091 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24093 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24094 || it
->phys_descent
> it
->descent
);
24095 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24096 glyph
->face_id
= it
->face_id
;
24097 glyph
->u
.ch
= it
->char_to_display
;
24098 glyph
->slice
.img
= null_glyph_slice
;
24099 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24102 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24103 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24105 glyph
->bidi_type
= it
->bidi_it
.type
;
24109 glyph
->resolved_level
= 0;
24110 glyph
->bidi_type
= UNKNOWN_BT
;
24112 ++it
->glyph_row
->used
[area
];
24115 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24118 /* Store one glyph for the composition IT->cmp_it.id in
24119 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24123 append_composite_glyph (struct it
*it
)
24125 struct glyph
*glyph
;
24126 enum glyph_row_area area
= it
->area
;
24128 eassert (it
->glyph_row
);
24130 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24131 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24133 /* If the glyph row is reversed, we need to prepend the glyph
24134 rather than append it. */
24135 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24139 /* Make room for the new glyph. */
24140 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24142 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24144 glyph
->charpos
= it
->cmp_it
.charpos
;
24145 glyph
->object
= it
->object
;
24146 glyph
->pixel_width
= it
->pixel_width
;
24147 glyph
->ascent
= it
->ascent
;
24148 glyph
->descent
= it
->descent
;
24149 glyph
->voffset
= it
->voffset
;
24150 glyph
->type
= COMPOSITE_GLYPH
;
24151 if (it
->cmp_it
.ch
< 0)
24153 glyph
->u
.cmp
.automatic
= 0;
24154 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24155 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24159 glyph
->u
.cmp
.automatic
= 1;
24160 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24161 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24162 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24164 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24165 glyph
->multibyte_p
= it
->multibyte_p
;
24166 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24168 /* In R2L rows, the left and the right box edges need to be
24169 drawn in reverse direction. */
24170 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24171 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24175 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24176 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24178 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24179 || it
->phys_descent
> it
->descent
);
24180 glyph
->padding_p
= 0;
24181 glyph
->glyph_not_available_p
= 0;
24182 glyph
->face_id
= it
->face_id
;
24183 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24186 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24187 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24189 glyph
->bidi_type
= it
->bidi_it
.type
;
24191 ++it
->glyph_row
->used
[area
];
24194 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24198 /* Change IT->ascent and IT->height according to the setting of
24202 take_vertical_position_into_account (struct it
*it
)
24206 if (it
->voffset
< 0)
24207 /* Increase the ascent so that we can display the text higher
24209 it
->ascent
-= it
->voffset
;
24211 /* Increase the descent so that we can display the text lower
24213 it
->descent
+= it
->voffset
;
24218 /* Produce glyphs/get display metrics for the image IT is loaded with.
24219 See the description of struct display_iterator in dispextern.h for
24220 an overview of struct display_iterator. */
24223 produce_image_glyph (struct it
*it
)
24227 int glyph_ascent
, crop
;
24228 struct glyph_slice slice
;
24230 eassert (it
->what
== IT_IMAGE
);
24232 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24234 /* Make sure X resources of the face is loaded. */
24235 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24237 if (it
->image_id
< 0)
24239 /* Fringe bitmap. */
24240 it
->ascent
= it
->phys_ascent
= 0;
24241 it
->descent
= it
->phys_descent
= 0;
24242 it
->pixel_width
= 0;
24247 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24249 /* Make sure X resources of the image is loaded. */
24250 prepare_image_for_display (it
->f
, img
);
24252 slice
.x
= slice
.y
= 0;
24253 slice
.width
= img
->width
;
24254 slice
.height
= img
->height
;
24256 if (INTEGERP (it
->slice
.x
))
24257 slice
.x
= XINT (it
->slice
.x
);
24258 else if (FLOATP (it
->slice
.x
))
24259 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24261 if (INTEGERP (it
->slice
.y
))
24262 slice
.y
= XINT (it
->slice
.y
);
24263 else if (FLOATP (it
->slice
.y
))
24264 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24266 if (INTEGERP (it
->slice
.width
))
24267 slice
.width
= XINT (it
->slice
.width
);
24268 else if (FLOATP (it
->slice
.width
))
24269 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24271 if (INTEGERP (it
->slice
.height
))
24272 slice
.height
= XINT (it
->slice
.height
);
24273 else if (FLOATP (it
->slice
.height
))
24274 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24276 if (slice
.x
>= img
->width
)
24277 slice
.x
= img
->width
;
24278 if (slice
.y
>= img
->height
)
24279 slice
.y
= img
->height
;
24280 if (slice
.x
+ slice
.width
>= img
->width
)
24281 slice
.width
= img
->width
- slice
.x
;
24282 if (slice
.y
+ slice
.height
> img
->height
)
24283 slice
.height
= img
->height
- slice
.y
;
24285 if (slice
.width
== 0 || slice
.height
== 0)
24288 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24290 it
->descent
= slice
.height
- glyph_ascent
;
24292 it
->descent
+= img
->vmargin
;
24293 if (slice
.y
+ slice
.height
== img
->height
)
24294 it
->descent
+= img
->vmargin
;
24295 it
->phys_descent
= it
->descent
;
24297 it
->pixel_width
= slice
.width
;
24299 it
->pixel_width
+= img
->hmargin
;
24300 if (slice
.x
+ slice
.width
== img
->width
)
24301 it
->pixel_width
+= img
->hmargin
;
24303 /* It's quite possible for images to have an ascent greater than
24304 their height, so don't get confused in that case. */
24305 if (it
->descent
< 0)
24310 if (face
->box
!= FACE_NO_BOX
)
24312 if (face
->box_line_width
> 0)
24315 it
->ascent
+= face
->box_line_width
;
24316 if (slice
.y
+ slice
.height
== img
->height
)
24317 it
->descent
+= face
->box_line_width
;
24320 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24321 it
->pixel_width
+= eabs (face
->box_line_width
);
24322 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24323 it
->pixel_width
+= eabs (face
->box_line_width
);
24326 take_vertical_position_into_account (it
);
24328 /* Automatically crop wide image glyphs at right edge so we can
24329 draw the cursor on same display row. */
24330 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24331 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24333 it
->pixel_width
-= crop
;
24334 slice
.width
-= crop
;
24339 struct glyph
*glyph
;
24340 enum glyph_row_area area
= it
->area
;
24342 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24343 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24345 glyph
->charpos
= CHARPOS (it
->position
);
24346 glyph
->object
= it
->object
;
24347 glyph
->pixel_width
= it
->pixel_width
;
24348 glyph
->ascent
= glyph_ascent
;
24349 glyph
->descent
= it
->descent
;
24350 glyph
->voffset
= it
->voffset
;
24351 glyph
->type
= IMAGE_GLYPH
;
24352 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24353 glyph
->multibyte_p
= it
->multibyte_p
;
24354 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24356 /* In R2L rows, the left and the right box edges need to be
24357 drawn in reverse direction. */
24358 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24359 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24363 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24364 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24366 glyph
->overlaps_vertically_p
= 0;
24367 glyph
->padding_p
= 0;
24368 glyph
->glyph_not_available_p
= 0;
24369 glyph
->face_id
= it
->face_id
;
24370 glyph
->u
.img_id
= img
->id
;
24371 glyph
->slice
.img
= slice
;
24372 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24375 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24376 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24378 glyph
->bidi_type
= it
->bidi_it
.type
;
24380 ++it
->glyph_row
->used
[area
];
24383 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24388 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24389 of the glyph, WIDTH and HEIGHT are the width and height of the
24390 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24393 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24394 int width
, int height
, int ascent
)
24396 struct glyph
*glyph
;
24397 enum glyph_row_area area
= it
->area
;
24399 eassert (ascent
>= 0 && ascent
<= height
);
24401 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24402 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24404 /* If the glyph row is reversed, we need to prepend the glyph
24405 rather than append it. */
24406 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24410 /* Make room for the additional glyph. */
24411 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24413 glyph
= it
->glyph_row
->glyphs
[area
];
24415 glyph
->charpos
= CHARPOS (it
->position
);
24416 glyph
->object
= object
;
24417 glyph
->pixel_width
= width
;
24418 glyph
->ascent
= ascent
;
24419 glyph
->descent
= height
- ascent
;
24420 glyph
->voffset
= it
->voffset
;
24421 glyph
->type
= STRETCH_GLYPH
;
24422 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24423 glyph
->multibyte_p
= it
->multibyte_p
;
24424 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24426 /* In R2L rows, the left and the right box edges need to be
24427 drawn in reverse direction. */
24428 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24429 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24433 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24434 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24436 glyph
->overlaps_vertically_p
= 0;
24437 glyph
->padding_p
= 0;
24438 glyph
->glyph_not_available_p
= 0;
24439 glyph
->face_id
= it
->face_id
;
24440 glyph
->u
.stretch
.ascent
= ascent
;
24441 glyph
->u
.stretch
.height
= height
;
24442 glyph
->slice
.img
= null_glyph_slice
;
24443 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24446 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24447 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24449 glyph
->bidi_type
= it
->bidi_it
.type
;
24453 glyph
->resolved_level
= 0;
24454 glyph
->bidi_type
= UNKNOWN_BT
;
24456 ++it
->glyph_row
->used
[area
];
24459 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24462 #endif /* HAVE_WINDOW_SYSTEM */
24464 /* Produce a stretch glyph for iterator IT. IT->object is the value
24465 of the glyph property displayed. The value must be a list
24466 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24469 1. `:width WIDTH' specifies that the space should be WIDTH *
24470 canonical char width wide. WIDTH may be an integer or floating
24473 2. `:relative-width FACTOR' specifies that the width of the stretch
24474 should be computed from the width of the first character having the
24475 `glyph' property, and should be FACTOR times that width.
24477 3. `:align-to HPOS' specifies that the space should be wide enough
24478 to reach HPOS, a value in canonical character units.
24480 Exactly one of the above pairs must be present.
24482 4. `:height HEIGHT' specifies that the height of the stretch produced
24483 should be HEIGHT, measured in canonical character units.
24485 5. `:relative-height FACTOR' specifies that the height of the
24486 stretch should be FACTOR times the height of the characters having
24487 the glyph property.
24489 Either none or exactly one of 4 or 5 must be present.
24491 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24492 of the stretch should be used for the ascent of the stretch.
24493 ASCENT must be in the range 0 <= ASCENT <= 100. */
24496 produce_stretch_glyph (struct it
*it
)
24498 /* (space :width WIDTH :height HEIGHT ...) */
24499 Lisp_Object prop
, plist
;
24500 int width
= 0, height
= 0, align_to
= -1;
24501 int zero_width_ok_p
= 0;
24503 struct font
*font
= NULL
;
24505 #ifdef HAVE_WINDOW_SYSTEM
24507 int zero_height_ok_p
= 0;
24509 if (FRAME_WINDOW_P (it
->f
))
24511 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24512 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24513 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24517 /* List should start with `space'. */
24518 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24519 plist
= XCDR (it
->object
);
24521 /* Compute the width of the stretch. */
24522 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24523 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24525 /* Absolute width `:width WIDTH' specified and valid. */
24526 zero_width_ok_p
= 1;
24529 #ifdef HAVE_WINDOW_SYSTEM
24530 else if (FRAME_WINDOW_P (it
->f
)
24531 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24533 /* Relative width `:relative-width FACTOR' specified and valid.
24534 Compute the width of the characters having the `glyph'
24537 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24540 if (it
->multibyte_p
)
24541 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24544 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24545 if (! ASCII_CHAR_P (it2
.c
))
24546 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24549 it2
.glyph_row
= NULL
;
24550 it2
.what
= IT_CHARACTER
;
24551 x_produce_glyphs (&it2
);
24552 width
= NUMVAL (prop
) * it2
.pixel_width
;
24554 #endif /* HAVE_WINDOW_SYSTEM */
24555 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24556 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24558 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24559 align_to
= (align_to
< 0
24561 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24562 else if (align_to
< 0)
24563 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24564 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24565 zero_width_ok_p
= 1;
24568 /* Nothing specified -> width defaults to canonical char width. */
24569 width
= FRAME_COLUMN_WIDTH (it
->f
);
24571 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24574 #ifdef HAVE_WINDOW_SYSTEM
24575 /* Compute height. */
24576 if (FRAME_WINDOW_P (it
->f
))
24578 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24579 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24582 zero_height_ok_p
= 1;
24584 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24586 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24588 height
= FONT_HEIGHT (font
);
24590 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24593 /* Compute percentage of height used for ascent. If
24594 `:ascent ASCENT' is present and valid, use that. Otherwise,
24595 derive the ascent from the font in use. */
24596 if (prop
= Fplist_get (plist
, QCascent
),
24597 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24598 ascent
= height
* NUMVAL (prop
) / 100.0;
24599 else if (!NILP (prop
)
24600 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24601 ascent
= min (max (0, (int)tem
), height
);
24603 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24606 #endif /* HAVE_WINDOW_SYSTEM */
24609 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24610 && it
->current_x
+ width
> it
->last_visible_x
)
24612 width
= it
->last_visible_x
- it
->current_x
;
24613 #ifdef HAVE_WINDOW_SYSTEM
24614 /* Subtract one more pixel from the stretch width, but only on
24615 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24616 width
-= FRAME_WINDOW_P (it
->f
);
24620 if (width
> 0 && height
> 0 && it
->glyph_row
)
24622 Lisp_Object o_object
= it
->object
;
24623 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24626 if (!STRINGP (object
))
24627 object
= it
->w
->contents
;
24628 #ifdef HAVE_WINDOW_SYSTEM
24629 if (FRAME_WINDOW_P (it
->f
))
24630 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24634 it
->object
= object
;
24635 it
->char_to_display
= ' ';
24636 it
->pixel_width
= it
->len
= 1;
24638 tty_append_glyph (it
);
24639 it
->object
= o_object
;
24643 it
->pixel_width
= width
;
24644 #ifdef HAVE_WINDOW_SYSTEM
24645 if (FRAME_WINDOW_P (it
->f
))
24647 it
->ascent
= it
->phys_ascent
= ascent
;
24648 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24649 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24650 take_vertical_position_into_account (it
);
24654 it
->nglyphs
= width
;
24657 /* Get information about special display element WHAT in an
24658 environment described by IT. WHAT is one of IT_TRUNCATION or
24659 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24660 non-null glyph_row member. This function ensures that fields like
24661 face_id, c, len of IT are left untouched. */
24664 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24671 temp_it
.object
= make_number (0);
24672 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24674 if (what
== IT_CONTINUATION
)
24676 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24677 if (it
->bidi_it
.paragraph_dir
== R2L
)
24678 SET_GLYPH_FROM_CHAR (glyph
, '/');
24680 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24682 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24684 /* FIXME: Should we mirror GC for R2L lines? */
24685 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24686 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24689 else if (what
== IT_TRUNCATION
)
24691 /* Truncation glyph. */
24692 SET_GLYPH_FROM_CHAR (glyph
, '$');
24694 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24696 /* FIXME: Should we mirror GC for R2L lines? */
24697 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24698 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24704 #ifdef HAVE_WINDOW_SYSTEM
24705 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24706 is turned off, we precede the truncation/continuation glyphs by a
24707 stretch glyph whose width is computed such that these special
24708 glyphs are aligned at the window margin, even when very different
24709 fonts are used in different glyph rows. */
24710 if (FRAME_WINDOW_P (temp_it
.f
)
24711 /* init_iterator calls this with it->glyph_row == NULL, and it
24712 wants only the pixel width of the truncation/continuation
24714 && temp_it
.glyph_row
24715 /* insert_left_trunc_glyphs calls us at the beginning of the
24716 row, and it has its own calculation of the stretch glyph
24718 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24719 && (temp_it
.glyph_row
->reversed_p
24720 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24721 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24723 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24725 if (stretch_width
> 0)
24727 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24728 struct font
*font
=
24729 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24730 int stretch_ascent
=
24731 (((temp_it
.ascent
+ temp_it
.descent
)
24732 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24734 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24735 temp_it
.ascent
+ temp_it
.descent
,
24742 temp_it
.what
= IT_CHARACTER
;
24744 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24745 temp_it
.face_id
= GLYPH_FACE (glyph
);
24746 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24748 PRODUCE_GLYPHS (&temp_it
);
24749 it
->pixel_width
= temp_it
.pixel_width
;
24750 it
->nglyphs
= temp_it
.pixel_width
;
24753 #ifdef HAVE_WINDOW_SYSTEM
24755 /* Calculate line-height and line-spacing properties.
24756 An integer value specifies explicit pixel value.
24757 A float value specifies relative value to current face height.
24758 A cons (float . face-name) specifies relative value to
24759 height of specified face font.
24761 Returns height in pixels, or nil. */
24765 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24766 int boff
, int override
)
24768 Lisp_Object face_name
= Qnil
;
24769 int ascent
, descent
, height
;
24771 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24776 face_name
= XCAR (val
);
24778 if (!NUMBERP (val
))
24779 val
= make_number (1);
24780 if (NILP (face_name
))
24782 height
= it
->ascent
+ it
->descent
;
24787 if (NILP (face_name
))
24789 font
= FRAME_FONT (it
->f
);
24790 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24792 else if (EQ (face_name
, Qt
))
24801 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24803 return make_number (-1);
24805 face
= FACE_FROM_ID (it
->f
, face_id
);
24808 return make_number (-1);
24809 boff
= font
->baseline_offset
;
24810 if (font
->vertical_centering
)
24811 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24814 ascent
= FONT_BASE (font
) + boff
;
24815 descent
= FONT_DESCENT (font
) - boff
;
24819 it
->override_ascent
= ascent
;
24820 it
->override_descent
= descent
;
24821 it
->override_boff
= boff
;
24824 height
= ascent
+ descent
;
24828 height
= (int)(XFLOAT_DATA (val
) * height
);
24829 else if (INTEGERP (val
))
24830 height
*= XINT (val
);
24832 return make_number (height
);
24836 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24837 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24838 and only if this is for a character for which no font was found.
24840 If the display method (it->glyphless_method) is
24841 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24842 length of the acronym or the hexadecimal string, UPPER_XOFF and
24843 UPPER_YOFF are pixel offsets for the upper part of the string,
24844 LOWER_XOFF and LOWER_YOFF are for the lower part.
24846 For the other display methods, LEN through LOWER_YOFF are zero. */
24849 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24850 short upper_xoff
, short upper_yoff
,
24851 short lower_xoff
, short lower_yoff
)
24853 struct glyph
*glyph
;
24854 enum glyph_row_area area
= it
->area
;
24856 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24857 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24859 /* If the glyph row is reversed, we need to prepend the glyph
24860 rather than append it. */
24861 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24865 /* Make room for the additional glyph. */
24866 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24868 glyph
= it
->glyph_row
->glyphs
[area
];
24870 glyph
->charpos
= CHARPOS (it
->position
);
24871 glyph
->object
= it
->object
;
24872 glyph
->pixel_width
= it
->pixel_width
;
24873 glyph
->ascent
= it
->ascent
;
24874 glyph
->descent
= it
->descent
;
24875 glyph
->voffset
= it
->voffset
;
24876 glyph
->type
= GLYPHLESS_GLYPH
;
24877 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24878 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24879 glyph
->u
.glyphless
.len
= len
;
24880 glyph
->u
.glyphless
.ch
= it
->c
;
24881 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24882 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24883 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24884 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24885 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24886 glyph
->multibyte_p
= it
->multibyte_p
;
24887 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24889 /* In R2L rows, the left and the right box edges need to be
24890 drawn in reverse direction. */
24891 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24892 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24896 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24897 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24899 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24900 || it
->phys_descent
> it
->descent
);
24901 glyph
->padding_p
= 0;
24902 glyph
->glyph_not_available_p
= 0;
24903 glyph
->face_id
= face_id
;
24904 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24907 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24908 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24910 glyph
->bidi_type
= it
->bidi_it
.type
;
24912 ++it
->glyph_row
->used
[area
];
24915 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24919 /* Produce a glyph for a glyphless character for iterator IT.
24920 IT->glyphless_method specifies which method to use for displaying
24921 the character. See the description of enum
24922 glyphless_display_method in dispextern.h for the detail.
24924 FOR_NO_FONT is nonzero if and only if this is for a character for
24925 which no font was found. ACRONYM, if non-nil, is an acronym string
24926 for the character. */
24929 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24934 int base_width
, base_height
, width
, height
;
24935 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24938 /* Get the metrics of the base font. We always refer to the current
24940 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24941 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24942 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24943 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24944 base_height
= it
->ascent
+ it
->descent
;
24945 base_width
= font
->average_width
;
24947 face_id
= merge_glyphless_glyph_face (it
);
24949 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24951 it
->pixel_width
= THIN_SPACE_WIDTH
;
24953 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24955 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24957 width
= CHAR_WIDTH (it
->c
);
24960 else if (width
> 4)
24962 it
->pixel_width
= base_width
* width
;
24964 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24970 unsigned int code
[6];
24972 int ascent
, descent
;
24973 struct font_metrics metrics_upper
, metrics_lower
;
24975 face
= FACE_FROM_ID (it
->f
, face_id
);
24976 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24977 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24979 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24981 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24982 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24983 if (CONSP (acronym
))
24984 acronym
= XCAR (acronym
);
24985 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24989 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24990 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24993 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24994 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24995 upper_len
= (len
+ 1) / 2;
24996 font
->driver
->text_extents (font
, code
, upper_len
,
24998 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25003 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25004 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25005 upper_xoff
= upper_yoff
= 2; /* the typical case */
25006 if (base_width
>= width
)
25008 /* Align the upper to the left, the lower to the right. */
25009 it
->pixel_width
= base_width
;
25010 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25014 /* Center the shorter one. */
25015 it
->pixel_width
= width
;
25016 if (metrics_upper
.width
>= metrics_lower
.width
)
25017 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25020 /* FIXME: This code doesn't look right. It formerly was
25021 missing the "lower_xoff = 0;", which couldn't have
25022 been right since it left lower_xoff uninitialized. */
25024 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25028 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25029 top, bottom, and between upper and lower strings. */
25030 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25031 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25032 /* Center vertically.
25033 H:base_height, D:base_descent
25034 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25036 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25037 descent = D - H/2 + h/2;
25038 lower_yoff = descent - 2 - ld;
25039 upper_yoff = lower_yoff - la - 1 - ud; */
25040 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25041 descent
= it
->descent
- (base_height
- height
) / 2;
25042 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25043 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25044 - metrics_upper
.descent
);
25045 /* Don't make the height shorter than the base height. */
25046 if (height
> base_height
)
25048 it
->ascent
= ascent
;
25049 it
->descent
= descent
;
25053 it
->phys_ascent
= it
->ascent
;
25054 it
->phys_descent
= it
->descent
;
25056 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25057 upper_xoff
, upper_yoff
,
25058 lower_xoff
, lower_yoff
);
25060 take_vertical_position_into_account (it
);
25065 Produce glyphs/get display metrics for the display element IT is
25066 loaded with. See the description of struct it in dispextern.h
25067 for an overview of struct it. */
25070 x_produce_glyphs (struct it
*it
)
25072 int extra_line_spacing
= it
->extra_line_spacing
;
25074 it
->glyph_not_available_p
= 0;
25076 if (it
->what
== IT_CHARACTER
)
25079 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25080 struct font
*font
= face
->font
;
25081 struct font_metrics
*pcm
= NULL
;
25082 int boff
; /* baseline offset */
25086 /* When no suitable font is found, display this character by
25087 the method specified in the first extra slot of
25088 Vglyphless_char_display. */
25089 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25091 eassert (it
->what
== IT_GLYPHLESS
);
25092 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25096 boff
= font
->baseline_offset
;
25097 if (font
->vertical_centering
)
25098 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25100 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25106 if (it
->override_ascent
>= 0)
25108 it
->ascent
= it
->override_ascent
;
25109 it
->descent
= it
->override_descent
;
25110 boff
= it
->override_boff
;
25114 it
->ascent
= FONT_BASE (font
) + boff
;
25115 it
->descent
= FONT_DESCENT (font
) - boff
;
25118 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25120 pcm
= get_per_char_metric (font
, &char2b
);
25121 if (pcm
->width
== 0
25122 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25128 it
->phys_ascent
= pcm
->ascent
+ boff
;
25129 it
->phys_descent
= pcm
->descent
- boff
;
25130 it
->pixel_width
= pcm
->width
;
25134 it
->glyph_not_available_p
= 1;
25135 it
->phys_ascent
= it
->ascent
;
25136 it
->phys_descent
= it
->descent
;
25137 it
->pixel_width
= font
->space_width
;
25140 if (it
->constrain_row_ascent_descent_p
)
25142 if (it
->descent
> it
->max_descent
)
25144 it
->ascent
+= it
->descent
- it
->max_descent
;
25145 it
->descent
= it
->max_descent
;
25147 if (it
->ascent
> it
->max_ascent
)
25149 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25150 it
->ascent
= it
->max_ascent
;
25152 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25153 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25154 extra_line_spacing
= 0;
25157 /* If this is a space inside a region of text with
25158 `space-width' property, change its width. */
25159 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25161 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25163 /* If face has a box, add the box thickness to the character
25164 height. If character has a box line to the left and/or
25165 right, add the box line width to the character's width. */
25166 if (face
->box
!= FACE_NO_BOX
)
25168 int thick
= face
->box_line_width
;
25172 it
->ascent
+= thick
;
25173 it
->descent
+= thick
;
25178 if (it
->start_of_box_run_p
)
25179 it
->pixel_width
+= thick
;
25180 if (it
->end_of_box_run_p
)
25181 it
->pixel_width
+= thick
;
25184 /* If face has an overline, add the height of the overline
25185 (1 pixel) and a 1 pixel margin to the character height. */
25186 if (face
->overline_p
)
25187 it
->ascent
+= overline_margin
;
25189 if (it
->constrain_row_ascent_descent_p
)
25191 if (it
->ascent
> it
->max_ascent
)
25192 it
->ascent
= it
->max_ascent
;
25193 if (it
->descent
> it
->max_descent
)
25194 it
->descent
= it
->max_descent
;
25197 take_vertical_position_into_account (it
);
25199 /* If we have to actually produce glyphs, do it. */
25204 /* Translate a space with a `space-width' property
25205 into a stretch glyph. */
25206 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25207 / FONT_HEIGHT (font
));
25208 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25209 it
->ascent
+ it
->descent
, ascent
);
25214 /* If characters with lbearing or rbearing are displayed
25215 in this line, record that fact in a flag of the
25216 glyph row. This is used to optimize X output code. */
25217 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25218 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25220 if (! stretched_p
&& it
->pixel_width
== 0)
25221 /* We assure that all visible glyphs have at least 1-pixel
25223 it
->pixel_width
= 1;
25225 else if (it
->char_to_display
== '\n')
25227 /* A newline has no width, but we need the height of the
25228 line. But if previous part of the line sets a height,
25229 don't increase that height */
25231 Lisp_Object height
;
25232 Lisp_Object total_height
= Qnil
;
25234 it
->override_ascent
= -1;
25235 it
->pixel_width
= 0;
25238 height
= get_it_property (it
, Qline_height
);
25239 /* Split (line-height total-height) list */
25241 && CONSP (XCDR (height
))
25242 && NILP (XCDR (XCDR (height
))))
25244 total_height
= XCAR (XCDR (height
));
25245 height
= XCAR (height
);
25247 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25249 if (it
->override_ascent
>= 0)
25251 it
->ascent
= it
->override_ascent
;
25252 it
->descent
= it
->override_descent
;
25253 boff
= it
->override_boff
;
25257 it
->ascent
= FONT_BASE (font
) + boff
;
25258 it
->descent
= FONT_DESCENT (font
) - boff
;
25261 if (EQ (height
, Qt
))
25263 if (it
->descent
> it
->max_descent
)
25265 it
->ascent
+= it
->descent
- it
->max_descent
;
25266 it
->descent
= it
->max_descent
;
25268 if (it
->ascent
> it
->max_ascent
)
25270 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25271 it
->ascent
= it
->max_ascent
;
25273 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25274 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25275 it
->constrain_row_ascent_descent_p
= 1;
25276 extra_line_spacing
= 0;
25280 Lisp_Object spacing
;
25282 it
->phys_ascent
= it
->ascent
;
25283 it
->phys_descent
= it
->descent
;
25285 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25286 && face
->box
!= FACE_NO_BOX
25287 && face
->box_line_width
> 0)
25289 it
->ascent
+= face
->box_line_width
;
25290 it
->descent
+= face
->box_line_width
;
25293 && XINT (height
) > it
->ascent
+ it
->descent
)
25294 it
->ascent
= XINT (height
) - it
->descent
;
25296 if (!NILP (total_height
))
25297 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25300 spacing
= get_it_property (it
, Qline_spacing
);
25301 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25303 if (INTEGERP (spacing
))
25305 extra_line_spacing
= XINT (spacing
);
25306 if (!NILP (total_height
))
25307 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25311 else /* i.e. (it->char_to_display == '\t') */
25313 if (font
->space_width
> 0)
25315 int tab_width
= it
->tab_width
* font
->space_width
;
25316 int x
= it
->current_x
+ it
->continuation_lines_width
;
25317 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25319 /* If the distance from the current position to the next tab
25320 stop is less than a space character width, use the
25321 tab stop after that. */
25322 if (next_tab_x
- x
< font
->space_width
)
25323 next_tab_x
+= tab_width
;
25325 it
->pixel_width
= next_tab_x
- x
;
25327 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25328 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25332 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25333 it
->ascent
+ it
->descent
, it
->ascent
);
25338 it
->pixel_width
= 0;
25343 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25345 /* A static composition.
25347 Note: A composition is represented as one glyph in the
25348 glyph matrix. There are no padding glyphs.
25350 Important note: pixel_width, ascent, and descent are the
25351 values of what is drawn by draw_glyphs (i.e. the values of
25352 the overall glyphs composed). */
25353 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25354 int boff
; /* baseline offset */
25355 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25356 int glyph_len
= cmp
->glyph_len
;
25357 struct font
*font
= face
->font
;
25361 /* If we have not yet calculated pixel size data of glyphs of
25362 the composition for the current face font, calculate them
25363 now. Theoretically, we have to check all fonts for the
25364 glyphs, but that requires much time and memory space. So,
25365 here we check only the font of the first glyph. This may
25366 lead to incorrect display, but it's very rare, and C-l
25367 (recenter-top-bottom) can correct the display anyway. */
25368 if (! cmp
->font
|| cmp
->font
!= font
)
25370 /* Ascent and descent of the font of the first character
25371 of this composition (adjusted by baseline offset).
25372 Ascent and descent of overall glyphs should not be less
25373 than these, respectively. */
25374 int font_ascent
, font_descent
, font_height
;
25375 /* Bounding box of the overall glyphs. */
25376 int leftmost
, rightmost
, lowest
, highest
;
25377 int lbearing
, rbearing
;
25378 int i
, width
, ascent
, descent
;
25379 int left_padded
= 0, right_padded
= 0;
25380 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25382 struct font_metrics
*pcm
;
25383 int font_not_found_p
;
25386 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25387 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25389 if (glyph_len
< cmp
->glyph_len
)
25391 for (i
= 0; i
< glyph_len
; i
++)
25393 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25395 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25400 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25401 : IT_CHARPOS (*it
));
25402 /* If no suitable font is found, use the default font. */
25403 font_not_found_p
= font
== NULL
;
25404 if (font_not_found_p
)
25406 face
= face
->ascii_face
;
25409 boff
= font
->baseline_offset
;
25410 if (font
->vertical_centering
)
25411 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25412 font_ascent
= FONT_BASE (font
) + boff
;
25413 font_descent
= FONT_DESCENT (font
) - boff
;
25414 font_height
= FONT_HEIGHT (font
);
25419 if (! font_not_found_p
)
25421 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25423 pcm
= get_per_char_metric (font
, &char2b
);
25426 /* Initialize the bounding box. */
25429 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25430 ascent
= pcm
->ascent
;
25431 descent
= pcm
->descent
;
25432 lbearing
= pcm
->lbearing
;
25433 rbearing
= pcm
->rbearing
;
25437 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25438 ascent
= FONT_BASE (font
);
25439 descent
= FONT_DESCENT (font
);
25446 lowest
= - descent
+ boff
;
25447 highest
= ascent
+ boff
;
25449 if (! font_not_found_p
25450 && font
->default_ascent
25451 && CHAR_TABLE_P (Vuse_default_ascent
)
25452 && !NILP (Faref (Vuse_default_ascent
,
25453 make_number (it
->char_to_display
))))
25454 highest
= font
->default_ascent
+ boff
;
25456 /* Draw the first glyph at the normal position. It may be
25457 shifted to right later if some other glyphs are drawn
25459 cmp
->offsets
[i
* 2] = 0;
25460 cmp
->offsets
[i
* 2 + 1] = boff
;
25461 cmp
->lbearing
= lbearing
;
25462 cmp
->rbearing
= rbearing
;
25464 /* Set cmp->offsets for the remaining glyphs. */
25465 for (i
++; i
< glyph_len
; i
++)
25467 int left
, right
, btm
, top
;
25468 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25470 struct face
*this_face
;
25474 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25475 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25476 font
= this_face
->font
;
25482 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25484 pcm
= get_per_char_metric (font
, &char2b
);
25487 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25490 width
= pcm
->width
;
25491 ascent
= pcm
->ascent
;
25492 descent
= pcm
->descent
;
25493 lbearing
= pcm
->lbearing
;
25494 rbearing
= pcm
->rbearing
;
25495 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25497 /* Relative composition with or without
25498 alternate chars. */
25499 left
= (leftmost
+ rightmost
- width
) / 2;
25500 btm
= - descent
+ boff
;
25501 if (font
->relative_compose
25502 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25503 || NILP (Faref (Vignore_relative_composition
,
25504 make_number (ch
)))))
25507 if (- descent
>= font
->relative_compose
)
25508 /* One extra pixel between two glyphs. */
25510 else if (ascent
<= 0)
25511 /* One extra pixel between two glyphs. */
25512 btm
= lowest
- 1 - ascent
- descent
;
25517 /* A composition rule is specified by an integer
25518 value that encodes global and new reference
25519 points (GREF and NREF). GREF and NREF are
25520 specified by numbers as below:
25522 0---1---2 -- ascent
25526 9--10--11 -- center
25528 ---3---4---5--- baseline
25530 6---7---8 -- descent
25532 int rule
= COMPOSITION_RULE (cmp
, i
);
25533 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25535 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25536 grefx
= gref
% 3, nrefx
= nref
% 3;
25537 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25539 xoff
= font_height
* (xoff
- 128) / 256;
25541 yoff
= font_height
* (yoff
- 128) / 256;
25544 + grefx
* (rightmost
- leftmost
) / 2
25545 - nrefx
* width
/ 2
25548 btm
= ((grefy
== 0 ? highest
25550 : grefy
== 2 ? lowest
25551 : (highest
+ lowest
) / 2)
25552 - (nrefy
== 0 ? ascent
+ descent
25553 : nrefy
== 1 ? descent
- boff
25555 : (ascent
+ descent
) / 2)
25559 cmp
->offsets
[i
* 2] = left
;
25560 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25562 /* Update the bounding box of the overall glyphs. */
25565 right
= left
+ width
;
25566 if (left
< leftmost
)
25568 if (right
> rightmost
)
25571 top
= btm
+ descent
+ ascent
;
25577 if (cmp
->lbearing
> left
+ lbearing
)
25578 cmp
->lbearing
= left
+ lbearing
;
25579 if (cmp
->rbearing
< left
+ rbearing
)
25580 cmp
->rbearing
= left
+ rbearing
;
25584 /* If there are glyphs whose x-offsets are negative,
25585 shift all glyphs to the right and make all x-offsets
25589 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25590 cmp
->offsets
[i
* 2] -= leftmost
;
25591 rightmost
-= leftmost
;
25592 cmp
->lbearing
-= leftmost
;
25593 cmp
->rbearing
-= leftmost
;
25596 if (left_padded
&& cmp
->lbearing
< 0)
25598 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25599 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25600 rightmost
-= cmp
->lbearing
;
25601 cmp
->rbearing
-= cmp
->lbearing
;
25604 if (right_padded
&& rightmost
< cmp
->rbearing
)
25606 rightmost
= cmp
->rbearing
;
25609 cmp
->pixel_width
= rightmost
;
25610 cmp
->ascent
= highest
;
25611 cmp
->descent
= - lowest
;
25612 if (cmp
->ascent
< font_ascent
)
25613 cmp
->ascent
= font_ascent
;
25614 if (cmp
->descent
< font_descent
)
25615 cmp
->descent
= font_descent
;
25619 && (cmp
->lbearing
< 0
25620 || cmp
->rbearing
> cmp
->pixel_width
))
25621 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25623 it
->pixel_width
= cmp
->pixel_width
;
25624 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25625 it
->descent
= it
->phys_descent
= cmp
->descent
;
25626 if (face
->box
!= FACE_NO_BOX
)
25628 int thick
= face
->box_line_width
;
25632 it
->ascent
+= thick
;
25633 it
->descent
+= thick
;
25638 if (it
->start_of_box_run_p
)
25639 it
->pixel_width
+= thick
;
25640 if (it
->end_of_box_run_p
)
25641 it
->pixel_width
+= thick
;
25644 /* If face has an overline, add the height of the overline
25645 (1 pixel) and a 1 pixel margin to the character height. */
25646 if (face
->overline_p
)
25647 it
->ascent
+= overline_margin
;
25649 take_vertical_position_into_account (it
);
25650 if (it
->ascent
< 0)
25652 if (it
->descent
< 0)
25655 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25656 append_composite_glyph (it
);
25658 else if (it
->what
== IT_COMPOSITION
)
25660 /* A dynamic (automatic) composition. */
25661 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25662 Lisp_Object gstring
;
25663 struct font_metrics metrics
;
25667 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25669 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25672 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25673 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25674 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25675 it
->descent
= it
->phys_descent
= metrics
.descent
;
25676 if (face
->box
!= FACE_NO_BOX
)
25678 int thick
= face
->box_line_width
;
25682 it
->ascent
+= thick
;
25683 it
->descent
+= thick
;
25688 if (it
->start_of_box_run_p
)
25689 it
->pixel_width
+= thick
;
25690 if (it
->end_of_box_run_p
)
25691 it
->pixel_width
+= thick
;
25693 /* If face has an overline, add the height of the overline
25694 (1 pixel) and a 1 pixel margin to the character height. */
25695 if (face
->overline_p
)
25696 it
->ascent
+= overline_margin
;
25697 take_vertical_position_into_account (it
);
25698 if (it
->ascent
< 0)
25700 if (it
->descent
< 0)
25704 append_composite_glyph (it
);
25706 else if (it
->what
== IT_GLYPHLESS
)
25707 produce_glyphless_glyph (it
, 0, Qnil
);
25708 else if (it
->what
== IT_IMAGE
)
25709 produce_image_glyph (it
);
25710 else if (it
->what
== IT_STRETCH
)
25711 produce_stretch_glyph (it
);
25714 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25715 because this isn't true for images with `:ascent 100'. */
25716 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25717 if (it
->area
== TEXT_AREA
)
25718 it
->current_x
+= it
->pixel_width
;
25720 if (extra_line_spacing
> 0)
25722 it
->descent
+= extra_line_spacing
;
25723 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25724 it
->max_extra_line_spacing
= extra_line_spacing
;
25727 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25728 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25729 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25730 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25734 Output LEN glyphs starting at START at the nominal cursor position.
25735 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25736 being updated, and UPDATED_AREA is the area of that row being updated. */
25739 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25740 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25742 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25744 eassert (updated_row
);
25745 /* When the window is hscrolled, cursor hpos can legitimately be out
25746 of bounds, but we draw the cursor at the corresponding window
25747 margin in that case. */
25748 if (!updated_row
->reversed_p
&& chpos
< 0)
25750 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25751 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25755 /* Write glyphs. */
25757 hpos
= start
- updated_row
->glyphs
[updated_area
];
25758 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25759 updated_row
, updated_area
,
25761 DRAW_NORMAL_TEXT
, 0);
25763 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25764 if (updated_area
== TEXT_AREA
25765 && w
->phys_cursor_on_p
25766 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25768 && chpos
< hpos
+ len
)
25769 w
->phys_cursor_on_p
= 0;
25773 /* Advance the output cursor. */
25774 w
->output_cursor
.hpos
+= len
;
25775 w
->output_cursor
.x
= x
;
25780 Insert LEN glyphs from START at the nominal cursor position. */
25783 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25784 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25787 int line_height
, shift_by_width
, shifted_region_width
;
25788 struct glyph_row
*row
;
25789 struct glyph
*glyph
;
25790 int frame_x
, frame_y
;
25793 eassert (updated_row
);
25795 f
= XFRAME (WINDOW_FRAME (w
));
25797 /* Get the height of the line we are in. */
25799 line_height
= row
->height
;
25801 /* Get the width of the glyphs to insert. */
25802 shift_by_width
= 0;
25803 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25804 shift_by_width
+= glyph
->pixel_width
;
25806 /* Get the width of the region to shift right. */
25807 shifted_region_width
= (window_box_width (w
, updated_area
)
25808 - w
->output_cursor
.x
25812 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25813 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25815 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25816 line_height
, shift_by_width
);
25818 /* Write the glyphs. */
25819 hpos
= start
- row
->glyphs
[updated_area
];
25820 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25822 DRAW_NORMAL_TEXT
, 0);
25824 /* Advance the output cursor. */
25825 w
->output_cursor
.hpos
+= len
;
25826 w
->output_cursor
.x
+= shift_by_width
;
25832 Erase the current text line from the nominal cursor position
25833 (inclusive) to pixel column TO_X (exclusive). The idea is that
25834 everything from TO_X onward is already erased.
25836 TO_X is a pixel position relative to UPDATED_AREA of currently
25837 updated window W. TO_X == -1 means clear to the end of this area. */
25840 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25841 enum glyph_row_area updated_area
, int to_x
)
25844 int max_x
, min_y
, max_y
;
25845 int from_x
, from_y
, to_y
;
25847 eassert (updated_row
);
25848 f
= XFRAME (w
->frame
);
25850 if (updated_row
->full_width_p
)
25851 max_x
= WINDOW_TOTAL_WIDTH (w
);
25853 max_x
= window_box_width (w
, updated_area
);
25854 max_y
= window_text_bottom_y (w
);
25856 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25857 of window. For TO_X > 0, truncate to end of drawing area. */
25863 to_x
= min (to_x
, max_x
);
25865 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25867 /* Notice if the cursor will be cleared by this operation. */
25868 if (!updated_row
->full_width_p
)
25869 notice_overwritten_cursor (w
, updated_area
,
25870 w
->output_cursor
.x
, -1,
25872 MATRIX_ROW_BOTTOM_Y (updated_row
));
25874 from_x
= w
->output_cursor
.x
;
25876 /* Translate to frame coordinates. */
25877 if (updated_row
->full_width_p
)
25879 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25880 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25884 int area_left
= window_box_left (w
, updated_area
);
25885 from_x
+= area_left
;
25889 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25890 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
25891 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25893 /* Prevent inadvertently clearing to end of the X window. */
25894 if (to_x
> from_x
&& to_y
> from_y
)
25897 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25898 to_x
- from_x
, to_y
- from_y
);
25903 #endif /* HAVE_WINDOW_SYSTEM */
25907 /***********************************************************************
25909 ***********************************************************************/
25911 /* Value is the internal representation of the specified cursor type
25912 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25913 of the bar cursor. */
25915 static enum text_cursor_kinds
25916 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25918 enum text_cursor_kinds type
;
25923 if (EQ (arg
, Qbox
))
25924 return FILLED_BOX_CURSOR
;
25926 if (EQ (arg
, Qhollow
))
25927 return HOLLOW_BOX_CURSOR
;
25929 if (EQ (arg
, Qbar
))
25936 && EQ (XCAR (arg
), Qbar
)
25937 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25939 *width
= XINT (XCDR (arg
));
25943 if (EQ (arg
, Qhbar
))
25946 return HBAR_CURSOR
;
25950 && EQ (XCAR (arg
), Qhbar
)
25951 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25953 *width
= XINT (XCDR (arg
));
25954 return HBAR_CURSOR
;
25957 /* Treat anything unknown as "hollow box cursor".
25958 It was bad to signal an error; people have trouble fixing
25959 .Xdefaults with Emacs, when it has something bad in it. */
25960 type
= HOLLOW_BOX_CURSOR
;
25965 /* Set the default cursor types for specified frame. */
25967 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25972 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25973 FRAME_CURSOR_WIDTH (f
) = width
;
25975 /* By default, set up the blink-off state depending on the on-state. */
25977 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25980 FRAME_BLINK_OFF_CURSOR (f
)
25981 = get_specified_cursor_type (XCDR (tem
), &width
);
25982 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25985 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25987 /* Make sure the cursor gets redrawn. */
25988 f
->cursor_type_changed
= 1;
25992 #ifdef HAVE_WINDOW_SYSTEM
25994 /* Return the cursor we want to be displayed in window W. Return
25995 width of bar/hbar cursor through WIDTH arg. Return with
25996 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25997 (i.e. if the `system caret' should track this cursor).
25999 In a mini-buffer window, we want the cursor only to appear if we
26000 are reading input from this window. For the selected window, we
26001 want the cursor type given by the frame parameter or buffer local
26002 setting of cursor-type. If explicitly marked off, draw no cursor.
26003 In all other cases, we want a hollow box cursor. */
26005 static enum text_cursor_kinds
26006 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26007 int *active_cursor
)
26009 struct frame
*f
= XFRAME (w
->frame
);
26010 struct buffer
*b
= XBUFFER (w
->contents
);
26011 int cursor_type
= DEFAULT_CURSOR
;
26012 Lisp_Object alt_cursor
;
26013 int non_selected
= 0;
26015 *active_cursor
= 1;
26018 if (cursor_in_echo_area
26019 && FRAME_HAS_MINIBUF_P (f
)
26020 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26022 if (w
== XWINDOW (echo_area_window
))
26024 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26026 *width
= FRAME_CURSOR_WIDTH (f
);
26027 return FRAME_DESIRED_CURSOR (f
);
26030 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26033 *active_cursor
= 0;
26037 /* Detect a nonselected window or nonselected frame. */
26038 else if (w
!= XWINDOW (f
->selected_window
)
26039 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26041 *active_cursor
= 0;
26043 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26049 /* Never display a cursor in a window in which cursor-type is nil. */
26050 if (NILP (BVAR (b
, cursor_type
)))
26053 /* Get the normal cursor type for this window. */
26054 if (EQ (BVAR (b
, cursor_type
), Qt
))
26056 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26057 *width
= FRAME_CURSOR_WIDTH (f
);
26060 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26062 /* Use cursor-in-non-selected-windows instead
26063 for non-selected window or frame. */
26066 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26067 if (!EQ (Qt
, alt_cursor
))
26068 return get_specified_cursor_type (alt_cursor
, width
);
26069 /* t means modify the normal cursor type. */
26070 if (cursor_type
== FILLED_BOX_CURSOR
)
26071 cursor_type
= HOLLOW_BOX_CURSOR
;
26072 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26074 return cursor_type
;
26077 /* Use normal cursor if not blinked off. */
26078 if (!w
->cursor_off_p
)
26080 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26082 if (cursor_type
== FILLED_BOX_CURSOR
)
26084 /* Using a block cursor on large images can be very annoying.
26085 So use a hollow cursor for "large" images.
26086 If image is not transparent (no mask), also use hollow cursor. */
26087 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26088 if (img
!= NULL
&& IMAGEP (img
->spec
))
26090 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26091 where N = size of default frame font size.
26092 This should cover most of the "tiny" icons people may use. */
26094 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26095 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26096 cursor_type
= HOLLOW_BOX_CURSOR
;
26099 else if (cursor_type
!= NO_CURSOR
)
26101 /* Display current only supports BOX and HOLLOW cursors for images.
26102 So for now, unconditionally use a HOLLOW cursor when cursor is
26103 not a solid box cursor. */
26104 cursor_type
= HOLLOW_BOX_CURSOR
;
26107 return cursor_type
;
26110 /* Cursor is blinked off, so determine how to "toggle" it. */
26112 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26113 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26114 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26116 /* Then see if frame has specified a specific blink off cursor type. */
26117 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26119 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26120 return FRAME_BLINK_OFF_CURSOR (f
);
26124 /* Some people liked having a permanently visible blinking cursor,
26125 while others had very strong opinions against it. So it was
26126 decided to remove it. KFS 2003-09-03 */
26128 /* Finally perform built-in cursor blinking:
26129 filled box <-> hollow box
26130 wide [h]bar <-> narrow [h]bar
26131 narrow [h]bar <-> no cursor
26132 other type <-> no cursor */
26134 if (cursor_type
== FILLED_BOX_CURSOR
)
26135 return HOLLOW_BOX_CURSOR
;
26137 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26140 return cursor_type
;
26148 /* Notice when the text cursor of window W has been completely
26149 overwritten by a drawing operation that outputs glyphs in AREA
26150 starting at X0 and ending at X1 in the line starting at Y0 and
26151 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26152 the rest of the line after X0 has been written. Y coordinates
26153 are window-relative. */
26156 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26157 int x0
, int x1
, int y0
, int y1
)
26159 int cx0
, cx1
, cy0
, cy1
;
26160 struct glyph_row
*row
;
26162 if (!w
->phys_cursor_on_p
)
26164 if (area
!= TEXT_AREA
)
26167 if (w
->phys_cursor
.vpos
< 0
26168 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26169 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26170 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26173 if (row
->cursor_in_fringe_p
)
26175 row
->cursor_in_fringe_p
= 0;
26176 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26177 w
->phys_cursor_on_p
= 0;
26181 cx0
= w
->phys_cursor
.x
;
26182 cx1
= cx0
+ w
->phys_cursor_width
;
26183 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26186 /* The cursor image will be completely removed from the
26187 screen if the output area intersects the cursor area in
26188 y-direction. When we draw in [y0 y1[, and some part of
26189 the cursor is at y < y0, that part must have been drawn
26190 before. When scrolling, the cursor is erased before
26191 actually scrolling, so we don't come here. When not
26192 scrolling, the rows above the old cursor row must have
26193 changed, and in this case these rows must have written
26194 over the cursor image.
26196 Likewise if part of the cursor is below y1, with the
26197 exception of the cursor being in the first blank row at
26198 the buffer and window end because update_text_area
26199 doesn't draw that row. (Except when it does, but
26200 that's handled in update_text_area.) */
26202 cy0
= w
->phys_cursor
.y
;
26203 cy1
= cy0
+ w
->phys_cursor_height
;
26204 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26207 w
->phys_cursor_on_p
= 0;
26210 #endif /* HAVE_WINDOW_SYSTEM */
26213 /************************************************************************
26215 ************************************************************************/
26217 #ifdef HAVE_WINDOW_SYSTEM
26220 Fix the display of area AREA of overlapping row ROW in window W
26221 with respect to the overlapping part OVERLAPS. */
26224 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26225 enum glyph_row_area area
, int overlaps
)
26232 for (i
= 0; i
< row
->used
[area
];)
26234 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26236 int start
= i
, start_x
= x
;
26240 x
+= row
->glyphs
[area
][i
].pixel_width
;
26243 while (i
< row
->used
[area
]
26244 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26246 draw_glyphs (w
, start_x
, row
, area
,
26248 DRAW_NORMAL_TEXT
, overlaps
);
26252 x
+= row
->glyphs
[area
][i
].pixel_width
;
26262 Draw the cursor glyph of window W in glyph row ROW. See the
26263 comment of draw_glyphs for the meaning of HL. */
26266 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26267 enum draw_glyphs_face hl
)
26269 /* If cursor hpos is out of bounds, don't draw garbage. This can
26270 happen in mini-buffer windows when switching between echo area
26271 glyphs and mini-buffer. */
26272 if ((row
->reversed_p
26273 ? (w
->phys_cursor
.hpos
>= 0)
26274 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26276 int on_p
= w
->phys_cursor_on_p
;
26278 int hpos
= w
->phys_cursor
.hpos
;
26280 /* When the window is hscrolled, cursor hpos can legitimately be
26281 out of bounds, but we draw the cursor at the corresponding
26282 window margin in that case. */
26283 if (!row
->reversed_p
&& hpos
< 0)
26285 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26286 hpos
= row
->used
[TEXT_AREA
] - 1;
26288 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26290 w
->phys_cursor_on_p
= on_p
;
26292 if (hl
== DRAW_CURSOR
)
26293 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26294 /* When we erase the cursor, and ROW is overlapped by other
26295 rows, make sure that these overlapping parts of other rows
26297 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26299 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26301 if (row
> w
->current_matrix
->rows
26302 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26303 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26304 OVERLAPS_ERASED_CURSOR
);
26306 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26307 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26308 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26309 OVERLAPS_ERASED_CURSOR
);
26315 /* Erase the image of a cursor of window W from the screen. */
26321 erase_phys_cursor (struct window
*w
)
26323 struct frame
*f
= XFRAME (w
->frame
);
26324 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26325 int hpos
= w
->phys_cursor
.hpos
;
26326 int vpos
= w
->phys_cursor
.vpos
;
26327 int mouse_face_here_p
= 0;
26328 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26329 struct glyph_row
*cursor_row
;
26330 struct glyph
*cursor_glyph
;
26331 enum draw_glyphs_face hl
;
26333 /* No cursor displayed or row invalidated => nothing to do on the
26335 if (w
->phys_cursor_type
== NO_CURSOR
)
26336 goto mark_cursor_off
;
26338 /* VPOS >= active_glyphs->nrows means that window has been resized.
26339 Don't bother to erase the cursor. */
26340 if (vpos
>= active_glyphs
->nrows
)
26341 goto mark_cursor_off
;
26343 /* If row containing cursor is marked invalid, there is nothing we
26345 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26346 if (!cursor_row
->enabled_p
)
26347 goto mark_cursor_off
;
26349 /* If line spacing is > 0, old cursor may only be partially visible in
26350 window after split-window. So adjust visible height. */
26351 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26352 window_text_bottom_y (w
) - cursor_row
->y
);
26354 /* If row is completely invisible, don't attempt to delete a cursor which
26355 isn't there. This can happen if cursor is at top of a window, and
26356 we switch to a buffer with a header line in that window. */
26357 if (cursor_row
->visible_height
<= 0)
26358 goto mark_cursor_off
;
26360 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26361 if (cursor_row
->cursor_in_fringe_p
)
26363 cursor_row
->cursor_in_fringe_p
= 0;
26364 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26365 goto mark_cursor_off
;
26368 /* This can happen when the new row is shorter than the old one.
26369 In this case, either draw_glyphs or clear_end_of_line
26370 should have cleared the cursor. Note that we wouldn't be
26371 able to erase the cursor in this case because we don't have a
26372 cursor glyph at hand. */
26373 if ((cursor_row
->reversed_p
26374 ? (w
->phys_cursor
.hpos
< 0)
26375 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26376 goto mark_cursor_off
;
26378 /* When the window is hscrolled, cursor hpos can legitimately be out
26379 of bounds, but we draw the cursor at the corresponding window
26380 margin in that case. */
26381 if (!cursor_row
->reversed_p
&& hpos
< 0)
26383 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26384 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26386 /* If the cursor is in the mouse face area, redisplay that when
26387 we clear the cursor. */
26388 if (! NILP (hlinfo
->mouse_face_window
)
26389 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26390 /* Don't redraw the cursor's spot in mouse face if it is at the
26391 end of a line (on a newline). The cursor appears there, but
26392 mouse highlighting does not. */
26393 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26394 mouse_face_here_p
= 1;
26396 /* Maybe clear the display under the cursor. */
26397 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26400 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26403 cursor_glyph
= get_phys_cursor_glyph (w
);
26404 if (cursor_glyph
== NULL
)
26405 goto mark_cursor_off
;
26407 width
= cursor_glyph
->pixel_width
;
26408 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26409 x
= w
->phys_cursor
.x
;
26411 width
-= left_x
- x
;
26412 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26413 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26414 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26417 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26420 /* Erase the cursor by redrawing the character underneath it. */
26421 if (mouse_face_here_p
)
26422 hl
= DRAW_MOUSE_FACE
;
26424 hl
= DRAW_NORMAL_TEXT
;
26425 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26428 w
->phys_cursor_on_p
= 0;
26429 w
->phys_cursor_type
= NO_CURSOR
;
26434 Display or clear cursor of window W. If ON is zero, clear the
26435 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26436 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26439 display_and_set_cursor (struct window
*w
, bool on
,
26440 int hpos
, int vpos
, int x
, int y
)
26442 struct frame
*f
= XFRAME (w
->frame
);
26443 int new_cursor_type
;
26444 int new_cursor_width
;
26446 struct glyph_row
*glyph_row
;
26447 struct glyph
*glyph
;
26449 /* This is pointless on invisible frames, and dangerous on garbaged
26450 windows and frames; in the latter case, the frame or window may
26451 be in the midst of changing its size, and x and y may be off the
26453 if (! FRAME_VISIBLE_P (f
)
26454 || FRAME_GARBAGED_P (f
)
26455 || vpos
>= w
->current_matrix
->nrows
26456 || hpos
>= w
->current_matrix
->matrix_w
)
26459 /* If cursor is off and we want it off, return quickly. */
26460 if (!on
&& !w
->phys_cursor_on_p
)
26463 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26464 /* If cursor row is not enabled, we don't really know where to
26465 display the cursor. */
26466 if (!glyph_row
->enabled_p
)
26468 w
->phys_cursor_on_p
= 0;
26473 if (!glyph_row
->exact_window_width_line_p
26474 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26475 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26477 eassert (input_blocked_p ());
26479 /* Set new_cursor_type to the cursor we want to be displayed. */
26480 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26481 &new_cursor_width
, &active_cursor
);
26483 /* If cursor is currently being shown and we don't want it to be or
26484 it is in the wrong place, or the cursor type is not what we want,
26486 if (w
->phys_cursor_on_p
26488 || w
->phys_cursor
.x
!= x
26489 || w
->phys_cursor
.y
!= y
26490 || new_cursor_type
!= w
->phys_cursor_type
26491 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26492 && new_cursor_width
!= w
->phys_cursor_width
)))
26493 erase_phys_cursor (w
);
26495 /* Don't check phys_cursor_on_p here because that flag is only set
26496 to zero in some cases where we know that the cursor has been
26497 completely erased, to avoid the extra work of erasing the cursor
26498 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26499 still not be visible, or it has only been partly erased. */
26502 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26503 w
->phys_cursor_height
= glyph_row
->height
;
26505 /* Set phys_cursor_.* before x_draw_.* is called because some
26506 of them may need the information. */
26507 w
->phys_cursor
.x
= x
;
26508 w
->phys_cursor
.y
= glyph_row
->y
;
26509 w
->phys_cursor
.hpos
= hpos
;
26510 w
->phys_cursor
.vpos
= vpos
;
26513 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26514 new_cursor_type
, new_cursor_width
,
26515 on
, active_cursor
);
26519 /* Switch the display of W's cursor on or off, according to the value
26523 update_window_cursor (struct window
*w
, bool on
)
26525 /* Don't update cursor in windows whose frame is in the process
26526 of being deleted. */
26527 if (w
->current_matrix
)
26529 int hpos
= w
->phys_cursor
.hpos
;
26530 int vpos
= w
->phys_cursor
.vpos
;
26531 struct glyph_row
*row
;
26533 if (vpos
>= w
->current_matrix
->nrows
26534 || hpos
>= w
->current_matrix
->matrix_w
)
26537 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26539 /* When the window is hscrolled, cursor hpos can legitimately be
26540 out of bounds, but we draw the cursor at the corresponding
26541 window margin in that case. */
26542 if (!row
->reversed_p
&& hpos
< 0)
26544 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26545 hpos
= row
->used
[TEXT_AREA
] - 1;
26548 display_and_set_cursor (w
, on
, hpos
, vpos
,
26549 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26555 /* Call update_window_cursor with parameter ON_P on all leaf windows
26556 in the window tree rooted at W. */
26559 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26563 if (WINDOWP (w
->contents
))
26564 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26566 update_window_cursor (w
, on_p
);
26568 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26574 Display the cursor on window W, or clear it, according to ON_P.
26575 Don't change the cursor's position. */
26578 x_update_cursor (struct frame
*f
, bool on_p
)
26580 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26585 Clear the cursor of window W to background color, and mark the
26586 cursor as not shown. This is used when the text where the cursor
26587 is about to be rewritten. */
26590 x_clear_cursor (struct window
*w
)
26592 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26593 update_window_cursor (w
, 0);
26596 #endif /* HAVE_WINDOW_SYSTEM */
26598 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26601 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26602 int start_hpos
, int end_hpos
,
26603 enum draw_glyphs_face draw
)
26605 #ifdef HAVE_WINDOW_SYSTEM
26606 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26608 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26612 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26613 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26617 /* Display the active region described by mouse_face_* according to DRAW. */
26620 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26622 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26623 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26625 if (/* If window is in the process of being destroyed, don't bother
26627 w
->current_matrix
!= NULL
26628 /* Don't update mouse highlight if hidden */
26629 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26630 /* Recognize when we are called to operate on rows that don't exist
26631 anymore. This can happen when a window is split. */
26632 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26634 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26635 struct glyph_row
*row
, *first
, *last
;
26637 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26638 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26640 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26642 int start_hpos
, end_hpos
, start_x
;
26644 /* For all but the first row, the highlight starts at column 0. */
26647 /* R2L rows have BEG and END in reversed order, but the
26648 screen drawing geometry is always left to right. So
26649 we need to mirror the beginning and end of the
26650 highlighted area in R2L rows. */
26651 if (!row
->reversed_p
)
26653 start_hpos
= hlinfo
->mouse_face_beg_col
;
26654 start_x
= hlinfo
->mouse_face_beg_x
;
26656 else if (row
== last
)
26658 start_hpos
= hlinfo
->mouse_face_end_col
;
26659 start_x
= hlinfo
->mouse_face_end_x
;
26667 else if (row
->reversed_p
&& row
== last
)
26669 start_hpos
= hlinfo
->mouse_face_end_col
;
26670 start_x
= hlinfo
->mouse_face_end_x
;
26680 if (!row
->reversed_p
)
26681 end_hpos
= hlinfo
->mouse_face_end_col
;
26682 else if (row
== first
)
26683 end_hpos
= hlinfo
->mouse_face_beg_col
;
26686 end_hpos
= row
->used
[TEXT_AREA
];
26687 if (draw
== DRAW_NORMAL_TEXT
)
26688 row
->fill_line_p
= 1; /* Clear to end of line */
26691 else if (row
->reversed_p
&& row
== first
)
26692 end_hpos
= hlinfo
->mouse_face_beg_col
;
26695 end_hpos
= row
->used
[TEXT_AREA
];
26696 if (draw
== DRAW_NORMAL_TEXT
)
26697 row
->fill_line_p
= 1; /* Clear to end of line */
26700 if (end_hpos
> start_hpos
)
26702 draw_row_with_mouse_face (w
, start_x
, row
,
26703 start_hpos
, end_hpos
, draw
);
26706 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26710 #ifdef HAVE_WINDOW_SYSTEM
26711 /* When we've written over the cursor, arrange for it to
26712 be displayed again. */
26713 if (FRAME_WINDOW_P (f
)
26714 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26716 int hpos
= w
->phys_cursor
.hpos
;
26718 /* When the window is hscrolled, cursor hpos can legitimately be
26719 out of bounds, but we draw the cursor at the corresponding
26720 window margin in that case. */
26721 if (!row
->reversed_p
&& hpos
< 0)
26723 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26724 hpos
= row
->used
[TEXT_AREA
] - 1;
26727 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26728 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26731 #endif /* HAVE_WINDOW_SYSTEM */
26734 #ifdef HAVE_WINDOW_SYSTEM
26735 /* Change the mouse cursor. */
26736 if (FRAME_WINDOW_P (f
))
26738 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
26739 if (draw
== DRAW_NORMAL_TEXT
26740 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26741 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26744 if (draw
== DRAW_MOUSE_FACE
)
26745 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26747 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26749 #endif /* HAVE_WINDOW_SYSTEM */
26753 Clear out the mouse-highlighted active region.
26754 Redraw it un-highlighted first. Value is non-zero if mouse
26755 face was actually drawn unhighlighted. */
26758 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26762 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26764 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26768 reset_mouse_highlight (hlinfo
);
26772 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26773 within the mouse face on that window. */
26775 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26777 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26779 /* Quickly resolve the easy cases. */
26780 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26781 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26783 if (vpos
< hlinfo
->mouse_face_beg_row
26784 || vpos
> hlinfo
->mouse_face_end_row
)
26786 if (vpos
> hlinfo
->mouse_face_beg_row
26787 && vpos
< hlinfo
->mouse_face_end_row
)
26790 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26792 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26794 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26797 else if ((vpos
== hlinfo
->mouse_face_beg_row
26798 && hpos
>= hlinfo
->mouse_face_beg_col
)
26799 || (vpos
== hlinfo
->mouse_face_end_row
26800 && hpos
< hlinfo
->mouse_face_end_col
))
26805 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26807 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26810 else if ((vpos
== hlinfo
->mouse_face_beg_row
26811 && hpos
<= hlinfo
->mouse_face_beg_col
)
26812 || (vpos
== hlinfo
->mouse_face_end_row
26813 && hpos
> hlinfo
->mouse_face_end_col
))
26821 Non-zero if physical cursor of window W is within mouse face. */
26824 cursor_in_mouse_face_p (struct window
*w
)
26826 int hpos
= w
->phys_cursor
.hpos
;
26827 int vpos
= w
->phys_cursor
.vpos
;
26828 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26830 /* When the window is hscrolled, cursor hpos can legitimately be out
26831 of bounds, but we draw the cursor at the corresponding window
26832 margin in that case. */
26833 if (!row
->reversed_p
&& hpos
< 0)
26835 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26836 hpos
= row
->used
[TEXT_AREA
] - 1;
26838 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26843 /* Find the glyph rows START_ROW and END_ROW of window W that display
26844 characters between buffer positions START_CHARPOS and END_CHARPOS
26845 (excluding END_CHARPOS). DISP_STRING is a display string that
26846 covers these buffer positions. This is similar to
26847 row_containing_pos, but is more accurate when bidi reordering makes
26848 buffer positions change non-linearly with glyph rows. */
26850 rows_from_pos_range (struct window
*w
,
26851 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26852 Lisp_Object disp_string
,
26853 struct glyph_row
**start
, struct glyph_row
**end
)
26855 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26856 int last_y
= window_text_bottom_y (w
);
26857 struct glyph_row
*row
;
26862 while (!first
->enabled_p
26863 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26866 /* Find the START row. */
26868 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26871 /* A row can potentially be the START row if the range of the
26872 characters it displays intersects the range
26873 [START_CHARPOS..END_CHARPOS). */
26874 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26875 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26876 /* See the commentary in row_containing_pos, for the
26877 explanation of the complicated way to check whether
26878 some position is beyond the end of the characters
26879 displayed by a row. */
26880 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26881 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26882 && !row
->ends_at_zv_p
26883 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26884 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26885 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26886 && !row
->ends_at_zv_p
26887 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26889 /* Found a candidate row. Now make sure at least one of the
26890 glyphs it displays has a charpos from the range
26891 [START_CHARPOS..END_CHARPOS).
26893 This is not obvious because bidi reordering could make
26894 buffer positions of a row be 1,2,3,102,101,100, and if we
26895 want to highlight characters in [50..60), we don't want
26896 this row, even though [50..60) does intersect [1..103),
26897 the range of character positions given by the row's start
26898 and end positions. */
26899 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26900 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26904 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26905 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26906 /* A glyph that comes from DISP_STRING is by
26907 definition to be highlighted. */
26908 || EQ (g
->object
, disp_string
))
26917 /* Find the END row. */
26919 /* If the last row is partially visible, start looking for END
26920 from that row, instead of starting from FIRST. */
26921 && !(row
->enabled_p
26922 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26924 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26926 struct glyph_row
*next
= row
+ 1;
26927 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26929 if (!next
->enabled_p
26930 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26931 /* The first row >= START whose range of displayed characters
26932 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26933 is the row END + 1. */
26934 || (start_charpos
< next_start
26935 && end_charpos
< next_start
)
26936 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26937 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26938 && !next
->ends_at_zv_p
26939 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26940 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26941 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26942 && !next
->ends_at_zv_p
26943 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26950 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26951 but none of the characters it displays are in the range, it is
26953 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26954 struct glyph
*s
= g
;
26955 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26959 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26960 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26961 /* If the buffer position of the first glyph in
26962 the row is equal to END_CHARPOS, it means
26963 the last character to be highlighted is the
26964 newline of ROW, and we must consider NEXT as
26966 || (((!next
->reversed_p
&& g
== s
)
26967 || (next
->reversed_p
&& g
== e
- 1))
26968 && (g
->charpos
== end_charpos
26969 /* Special case for when NEXT is an
26970 empty line at ZV. */
26971 || (g
->charpos
== -1
26972 && !row
->ends_at_zv_p
26973 && next_start
== end_charpos
)))))
26974 /* A glyph that comes from DISP_STRING is by
26975 definition to be highlighted. */
26976 || EQ (g
->object
, disp_string
))
26985 /* The first row that ends at ZV must be the last to be
26987 else if (next
->ends_at_zv_p
)
26996 /* This function sets the mouse_face_* elements of HLINFO, assuming
26997 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26998 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26999 for the overlay or run of text properties specifying the mouse
27000 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27001 before-string and after-string that must also be highlighted.
27002 DISP_STRING, if non-nil, is a display string that may cover some
27003 or all of the highlighted text. */
27006 mouse_face_from_buffer_pos (Lisp_Object window
,
27007 Mouse_HLInfo
*hlinfo
,
27008 ptrdiff_t mouse_charpos
,
27009 ptrdiff_t start_charpos
,
27010 ptrdiff_t end_charpos
,
27011 Lisp_Object before_string
,
27012 Lisp_Object after_string
,
27013 Lisp_Object disp_string
)
27015 struct window
*w
= XWINDOW (window
);
27016 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27017 struct glyph_row
*r1
, *r2
;
27018 struct glyph
*glyph
, *end
;
27019 ptrdiff_t ignore
, pos
;
27022 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27023 eassert (NILP (before_string
) || STRINGP (before_string
));
27024 eassert (NILP (after_string
) || STRINGP (after_string
));
27026 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27027 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27029 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27030 /* If the before-string or display-string contains newlines,
27031 rows_from_pos_range skips to its last row. Move back. */
27032 if (!NILP (before_string
) || !NILP (disp_string
))
27034 struct glyph_row
*prev
;
27035 while ((prev
= r1
- 1, prev
>= first
)
27036 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27037 && prev
->used
[TEXT_AREA
] > 0)
27039 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27040 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27041 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27043 || !(EQ (glyph
->object
, before_string
)
27044 || EQ (glyph
->object
, disp_string
)))
27051 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27052 hlinfo
->mouse_face_past_end
= 1;
27054 else if (!NILP (after_string
))
27056 /* If the after-string has newlines, advance to its last row. */
27057 struct glyph_row
*next
;
27058 struct glyph_row
*last
27059 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27061 for (next
= r2
+ 1;
27063 && next
->used
[TEXT_AREA
] > 0
27064 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27068 /* The rest of the display engine assumes that mouse_face_beg_row is
27069 either above mouse_face_end_row or identical to it. But with
27070 bidi-reordered continued lines, the row for START_CHARPOS could
27071 be below the row for END_CHARPOS. If so, swap the rows and store
27072 them in correct order. */
27075 struct glyph_row
*tem
= r2
;
27081 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27082 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27084 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27085 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27086 could be anywhere in the row and in any order. The strategy
27087 below is to find the leftmost and the rightmost glyph that
27088 belongs to either of these 3 strings, or whose position is
27089 between START_CHARPOS and END_CHARPOS, and highlight all the
27090 glyphs between those two. This may cover more than just the text
27091 between START_CHARPOS and END_CHARPOS if the range of characters
27092 strides the bidi level boundary, e.g. if the beginning is in R2L
27093 text while the end is in L2R text or vice versa. */
27094 if (!r1
->reversed_p
)
27096 /* This row is in a left to right paragraph. Scan it left to
27098 glyph
= r1
->glyphs
[TEXT_AREA
];
27099 end
= glyph
+ r1
->used
[TEXT_AREA
];
27102 /* Skip truncation glyphs at the start of the glyph row. */
27103 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27105 && INTEGERP (glyph
->object
)
27106 && glyph
->charpos
< 0;
27108 x
+= glyph
->pixel_width
;
27110 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27111 or DISP_STRING, and the first glyph from buffer whose
27112 position is between START_CHARPOS and END_CHARPOS. */
27114 && !INTEGERP (glyph
->object
)
27115 && !EQ (glyph
->object
, disp_string
)
27116 && !(BUFFERP (glyph
->object
)
27117 && (glyph
->charpos
>= start_charpos
27118 && glyph
->charpos
< end_charpos
));
27121 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27122 are present at buffer positions between START_CHARPOS and
27123 END_CHARPOS, or if they come from an overlay. */
27124 if (EQ (glyph
->object
, before_string
))
27126 pos
= string_buffer_position (before_string
,
27128 /* If pos == 0, it means before_string came from an
27129 overlay, not from a buffer position. */
27130 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27133 else if (EQ (glyph
->object
, after_string
))
27135 pos
= string_buffer_position (after_string
, end_charpos
);
27136 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27139 x
+= glyph
->pixel_width
;
27141 hlinfo
->mouse_face_beg_x
= x
;
27142 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27146 /* This row is in a right to left paragraph. Scan it right to
27150 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27151 glyph
= end
+ r1
->used
[TEXT_AREA
];
27153 /* Skip truncation glyphs at the start of the glyph row. */
27154 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27156 && INTEGERP (glyph
->object
)
27157 && glyph
->charpos
< 0;
27161 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27162 or DISP_STRING, and the first glyph from buffer whose
27163 position is between START_CHARPOS and END_CHARPOS. */
27165 && !INTEGERP (glyph
->object
)
27166 && !EQ (glyph
->object
, disp_string
)
27167 && !(BUFFERP (glyph
->object
)
27168 && (glyph
->charpos
>= start_charpos
27169 && glyph
->charpos
< end_charpos
));
27172 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27173 are present at buffer positions between START_CHARPOS and
27174 END_CHARPOS, or if they come from an overlay. */
27175 if (EQ (glyph
->object
, before_string
))
27177 pos
= string_buffer_position (before_string
, start_charpos
);
27178 /* If pos == 0, it means before_string came from an
27179 overlay, not from a buffer position. */
27180 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27183 else if (EQ (glyph
->object
, after_string
))
27185 pos
= string_buffer_position (after_string
, end_charpos
);
27186 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27191 glyph
++; /* first glyph to the right of the highlighted area */
27192 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27193 x
+= g
->pixel_width
;
27194 hlinfo
->mouse_face_beg_x
= x
;
27195 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27198 /* If the highlight ends in a different row, compute GLYPH and END
27199 for the end row. Otherwise, reuse the values computed above for
27200 the row where the highlight begins. */
27203 if (!r2
->reversed_p
)
27205 glyph
= r2
->glyphs
[TEXT_AREA
];
27206 end
= glyph
+ r2
->used
[TEXT_AREA
];
27211 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27212 glyph
= end
+ r2
->used
[TEXT_AREA
];
27216 if (!r2
->reversed_p
)
27218 /* Skip truncation and continuation glyphs near the end of the
27219 row, and also blanks and stretch glyphs inserted by
27220 extend_face_to_end_of_line. */
27222 && INTEGERP ((end
- 1)->object
))
27224 /* Scan the rest of the glyph row from the end, looking for the
27225 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27226 DISP_STRING, or whose position is between START_CHARPOS
27230 && !INTEGERP (end
->object
)
27231 && !EQ (end
->object
, disp_string
)
27232 && !(BUFFERP (end
->object
)
27233 && (end
->charpos
>= start_charpos
27234 && end
->charpos
< end_charpos
));
27237 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27238 are present at buffer positions between START_CHARPOS and
27239 END_CHARPOS, or if they come from an overlay. */
27240 if (EQ (end
->object
, before_string
))
27242 pos
= string_buffer_position (before_string
, start_charpos
);
27243 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27246 else if (EQ (end
->object
, after_string
))
27248 pos
= string_buffer_position (after_string
, end_charpos
);
27249 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27253 /* Find the X coordinate of the last glyph to be highlighted. */
27254 for (; glyph
<= end
; ++glyph
)
27255 x
+= glyph
->pixel_width
;
27257 hlinfo
->mouse_face_end_x
= x
;
27258 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27262 /* Skip truncation and continuation glyphs near the end of the
27263 row, and also blanks and stretch glyphs inserted by
27264 extend_face_to_end_of_line. */
27268 && INTEGERP (end
->object
))
27270 x
+= end
->pixel_width
;
27273 /* Scan the rest of the glyph row from the end, looking for the
27274 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27275 DISP_STRING, or whose position is between START_CHARPOS
27279 && !INTEGERP (end
->object
)
27280 && !EQ (end
->object
, disp_string
)
27281 && !(BUFFERP (end
->object
)
27282 && (end
->charpos
>= start_charpos
27283 && end
->charpos
< end_charpos
));
27286 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27287 are present at buffer positions between START_CHARPOS and
27288 END_CHARPOS, or if they come from an overlay. */
27289 if (EQ (end
->object
, before_string
))
27291 pos
= string_buffer_position (before_string
, start_charpos
);
27292 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27295 else if (EQ (end
->object
, after_string
))
27297 pos
= string_buffer_position (after_string
, end_charpos
);
27298 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27301 x
+= end
->pixel_width
;
27303 /* If we exited the above loop because we arrived at the last
27304 glyph of the row, and its buffer position is still not in
27305 range, it means the last character in range is the preceding
27306 newline. Bump the end column and x values to get past the
27309 && BUFFERP (end
->object
)
27310 && (end
->charpos
< start_charpos
27311 || end
->charpos
>= end_charpos
))
27313 x
+= end
->pixel_width
;
27316 hlinfo
->mouse_face_end_x
= x
;
27317 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27320 hlinfo
->mouse_face_window
= window
;
27321 hlinfo
->mouse_face_face_id
27322 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27324 !hlinfo
->mouse_face_hidden
, -1);
27325 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27328 /* The following function is not used anymore (replaced with
27329 mouse_face_from_string_pos), but I leave it here for the time
27330 being, in case someone would. */
27332 #if 0 /* not used */
27334 /* Find the position of the glyph for position POS in OBJECT in
27335 window W's current matrix, and return in *X, *Y the pixel
27336 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27338 RIGHT_P non-zero means return the position of the right edge of the
27339 glyph, RIGHT_P zero means return the left edge position.
27341 If no glyph for POS exists in the matrix, return the position of
27342 the glyph with the next smaller position that is in the matrix, if
27343 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27344 exists in the matrix, return the position of the glyph with the
27345 next larger position in OBJECT.
27347 Value is non-zero if a glyph was found. */
27350 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27351 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27353 int yb
= window_text_bottom_y (w
);
27354 struct glyph_row
*r
;
27355 struct glyph
*best_glyph
= NULL
;
27356 struct glyph_row
*best_row
= NULL
;
27359 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27360 r
->enabled_p
&& r
->y
< yb
;
27363 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27364 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27367 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27368 if (EQ (g
->object
, object
))
27370 if (g
->charpos
== pos
)
27377 else if (best_glyph
== NULL
27378 || ((eabs (g
->charpos
- pos
)
27379 < eabs (best_glyph
->charpos
- pos
))
27382 : g
->charpos
> pos
)))
27396 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27400 *x
+= best_glyph
->pixel_width
;
27405 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27408 return best_glyph
!= NULL
;
27410 #endif /* not used */
27412 /* Find the positions of the first and the last glyphs in window W's
27413 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27414 (assumed to be a string), and return in HLINFO's mouse_face_*
27415 members the pixel and column/row coordinates of those glyphs. */
27418 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27419 Lisp_Object object
,
27420 ptrdiff_t startpos
, ptrdiff_t endpos
)
27422 int yb
= window_text_bottom_y (w
);
27423 struct glyph_row
*r
;
27424 struct glyph
*g
, *e
;
27428 /* Find the glyph row with at least one position in the range
27429 [STARTPOS..ENDPOS), and the first glyph in that row whose
27430 position belongs to that range. */
27431 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27432 r
->enabled_p
&& r
->y
< yb
;
27435 if (!r
->reversed_p
)
27437 g
= r
->glyphs
[TEXT_AREA
];
27438 e
= g
+ r
->used
[TEXT_AREA
];
27439 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27440 if (EQ (g
->object
, object
)
27441 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27443 hlinfo
->mouse_face_beg_row
27444 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27445 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27446 hlinfo
->mouse_face_beg_x
= gx
;
27455 e
= r
->glyphs
[TEXT_AREA
];
27456 g
= e
+ r
->used
[TEXT_AREA
];
27457 for ( ; g
> e
; --g
)
27458 if (EQ ((g
-1)->object
, object
)
27459 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27461 hlinfo
->mouse_face_beg_row
27462 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27463 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27464 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27465 gx
+= g1
->pixel_width
;
27466 hlinfo
->mouse_face_beg_x
= gx
;
27478 /* Starting with the next row, look for the first row which does NOT
27479 include any glyphs whose positions are in the range. */
27480 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27482 g
= r
->glyphs
[TEXT_AREA
];
27483 e
= g
+ r
->used
[TEXT_AREA
];
27485 for ( ; g
< e
; ++g
)
27486 if (EQ (g
->object
, object
)
27487 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27496 /* The highlighted region ends on the previous row. */
27499 /* Set the end row. */
27500 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27502 /* Compute and set the end column and the end column's horizontal
27503 pixel coordinate. */
27504 if (!r
->reversed_p
)
27506 g
= r
->glyphs
[TEXT_AREA
];
27507 e
= g
+ r
->used
[TEXT_AREA
];
27508 for ( ; e
> g
; --e
)
27509 if (EQ ((e
-1)->object
, object
)
27510 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27512 hlinfo
->mouse_face_end_col
= e
- g
;
27514 for (gx
= r
->x
; g
< e
; ++g
)
27515 gx
+= g
->pixel_width
;
27516 hlinfo
->mouse_face_end_x
= gx
;
27520 e
= r
->glyphs
[TEXT_AREA
];
27521 g
= e
+ r
->used
[TEXT_AREA
];
27522 for (gx
= r
->x
; e
< g
; ++e
)
27524 if (EQ (e
->object
, object
)
27525 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27527 gx
+= e
->pixel_width
;
27529 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27530 hlinfo
->mouse_face_end_x
= gx
;
27534 #ifdef HAVE_WINDOW_SYSTEM
27536 /* See if position X, Y is within a hot-spot of an image. */
27539 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27541 if (!CONSP (hot_spot
))
27544 if (EQ (XCAR (hot_spot
), Qrect
))
27546 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27547 Lisp_Object rect
= XCDR (hot_spot
);
27551 if (!CONSP (XCAR (rect
)))
27553 if (!CONSP (XCDR (rect
)))
27555 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27557 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27559 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27561 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27565 else if (EQ (XCAR (hot_spot
), Qcircle
))
27567 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27568 Lisp_Object circ
= XCDR (hot_spot
);
27569 Lisp_Object lr
, lx0
, ly0
;
27571 && CONSP (XCAR (circ
))
27572 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27573 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27574 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27576 double r
= XFLOATINT (lr
);
27577 double dx
= XINT (lx0
) - x
;
27578 double dy
= XINT (ly0
) - y
;
27579 return (dx
* dx
+ dy
* dy
<= r
* r
);
27582 else if (EQ (XCAR (hot_spot
), Qpoly
))
27584 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27585 if (VECTORP (XCDR (hot_spot
)))
27587 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27588 Lisp_Object
*poly
= v
->u
.contents
;
27589 ptrdiff_t n
= v
->header
.size
;
27592 Lisp_Object lx
, ly
;
27595 /* Need an even number of coordinates, and at least 3 edges. */
27596 if (n
< 6 || n
& 1)
27599 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27600 If count is odd, we are inside polygon. Pixels on edges
27601 may or may not be included depending on actual geometry of the
27603 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27604 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27606 x0
= XINT (lx
), y0
= XINT (ly
);
27607 for (i
= 0; i
< n
; i
+= 2)
27609 int x1
= x0
, y1
= y0
;
27610 if ((lx
= poly
[i
], !INTEGERP (lx
))
27611 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27613 x0
= XINT (lx
), y0
= XINT (ly
);
27615 /* Does this segment cross the X line? */
27623 if (y
> y0
&& y
> y1
)
27625 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27635 find_hot_spot (Lisp_Object map
, int x
, int y
)
27637 while (CONSP (map
))
27639 if (CONSP (XCAR (map
))
27640 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27648 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27650 doc
: /* Lookup in image map MAP coordinates X and Y.
27651 An image map is an alist where each element has the format (AREA ID PLIST).
27652 An AREA is specified as either a rectangle, a circle, or a polygon:
27653 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27654 pixel coordinates of the upper left and bottom right corners.
27655 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27656 and the radius of the circle; r may be a float or integer.
27657 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27658 vector describes one corner in the polygon.
27659 Returns the alist element for the first matching AREA in MAP. */)
27660 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27668 return find_hot_spot (map
,
27669 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27670 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27674 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27676 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27678 /* Do not change cursor shape while dragging mouse. */
27679 if (!NILP (do_mouse_tracking
))
27682 if (!NILP (pointer
))
27684 if (EQ (pointer
, Qarrow
))
27685 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27686 else if (EQ (pointer
, Qhand
))
27687 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27688 else if (EQ (pointer
, Qtext
))
27689 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27690 else if (EQ (pointer
, intern ("hdrag")))
27691 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27692 #ifdef HAVE_X_WINDOWS
27693 else if (EQ (pointer
, intern ("vdrag")))
27694 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27696 else if (EQ (pointer
, intern ("hourglass")))
27697 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27698 else if (EQ (pointer
, Qmodeline
))
27699 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27701 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27704 if (cursor
!= No_Cursor
)
27705 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27708 #endif /* HAVE_WINDOW_SYSTEM */
27710 /* Take proper action when mouse has moved to the mode or header line
27711 or marginal area AREA of window W, x-position X and y-position Y.
27712 X is relative to the start of the text display area of W, so the
27713 width of bitmap areas and scroll bars must be subtracted to get a
27714 position relative to the start of the mode line. */
27717 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27718 enum window_part area
)
27720 struct window
*w
= XWINDOW (window
);
27721 struct frame
*f
= XFRAME (w
->frame
);
27722 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27723 #ifdef HAVE_WINDOW_SYSTEM
27724 Display_Info
*dpyinfo
;
27726 Cursor cursor
= No_Cursor
;
27727 Lisp_Object pointer
= Qnil
;
27728 int dx
, dy
, width
, height
;
27730 Lisp_Object string
, object
= Qnil
;
27731 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27733 Lisp_Object mouse_face
;
27734 int original_x_pixel
= x
;
27735 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27736 struct glyph_row
*row
IF_LINT (= 0);
27738 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27743 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27744 returns them in row/column units! */
27745 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27746 &object
, &dx
, &dy
, &width
, &height
);
27748 row
= (area
== ON_MODE_LINE
27749 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27750 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27752 /* Find the glyph under the mouse pointer. */
27753 if (row
->mode_line_p
&& row
->enabled_p
)
27755 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27756 end
= glyph
+ row
->used
[TEXT_AREA
];
27758 for (x0
= original_x_pixel
;
27759 glyph
< end
&& x0
>= glyph
->pixel_width
;
27761 x0
-= glyph
->pixel_width
;
27769 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27770 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27771 returns them in row/column units! */
27772 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27773 &object
, &dx
, &dy
, &width
, &height
);
27778 #ifdef HAVE_WINDOW_SYSTEM
27779 if (IMAGEP (object
))
27781 Lisp_Object image_map
, hotspot
;
27782 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27784 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27786 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27790 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27791 If so, we could look for mouse-enter, mouse-leave
27792 properties in PLIST (and do something...). */
27793 hotspot
= XCDR (hotspot
);
27794 if (CONSP (hotspot
)
27795 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27797 pointer
= Fplist_get (plist
, Qpointer
);
27798 if (NILP (pointer
))
27800 help
= Fplist_get (plist
, Qhelp_echo
);
27803 help_echo_string
= help
;
27804 XSETWINDOW (help_echo_window
, w
);
27805 help_echo_object
= w
->contents
;
27806 help_echo_pos
= charpos
;
27810 if (NILP (pointer
))
27811 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27813 #endif /* HAVE_WINDOW_SYSTEM */
27815 if (STRINGP (string
))
27816 pos
= make_number (charpos
);
27818 /* Set the help text and mouse pointer. If the mouse is on a part
27819 of the mode line without any text (e.g. past the right edge of
27820 the mode line text), use the default help text and pointer. */
27821 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27823 /* Arrange to display the help by setting the global variables
27824 help_echo_string, help_echo_object, and help_echo_pos. */
27827 if (STRINGP (string
))
27828 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27832 help_echo_string
= help
;
27833 XSETWINDOW (help_echo_window
, w
);
27834 help_echo_object
= string
;
27835 help_echo_pos
= charpos
;
27837 else if (area
== ON_MODE_LINE
)
27839 Lisp_Object default_help
27840 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27843 if (STRINGP (default_help
))
27845 help_echo_string
= default_help
;
27846 XSETWINDOW (help_echo_window
, w
);
27847 help_echo_object
= Qnil
;
27848 help_echo_pos
= -1;
27853 #ifdef HAVE_WINDOW_SYSTEM
27854 /* Change the mouse pointer according to what is under it. */
27855 if (FRAME_WINDOW_P (f
))
27857 dpyinfo
= FRAME_DISPLAY_INFO (f
);
27858 if (STRINGP (string
))
27860 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27862 if (NILP (pointer
))
27863 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27865 /* Change the mouse pointer according to what is under X/Y. */
27867 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27870 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27871 if (!KEYMAPP (map
))
27872 map
= Fget_text_property (pos
, Qkeymap
, string
);
27873 if (!KEYMAPP (map
))
27874 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27878 /* Default mode-line pointer. */
27879 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27884 /* Change the mouse face according to what is under X/Y. */
27885 if (STRINGP (string
))
27887 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27888 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
27889 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27894 struct glyph
* tmp_glyph
;
27898 int total_pixel_width
;
27899 ptrdiff_t begpos
, endpos
, ignore
;
27903 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27904 Qmouse_face
, string
, Qnil
);
27910 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27912 endpos
= SCHARS (string
);
27916 /* Calculate the glyph position GPOS of GLYPH in the
27917 displayed string, relative to the beginning of the
27918 highlighted part of the string.
27920 Note: GPOS is different from CHARPOS. CHARPOS is the
27921 position of GLYPH in the internal string object. A mode
27922 line string format has structures which are converted to
27923 a flattened string by the Emacs Lisp interpreter. The
27924 internal string is an element of those structures. The
27925 displayed string is the flattened string. */
27926 tmp_glyph
= row_start_glyph
;
27927 while (tmp_glyph
< glyph
27928 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27929 && begpos
<= tmp_glyph
->charpos
27930 && tmp_glyph
->charpos
< endpos
)))
27932 gpos
= glyph
- tmp_glyph
;
27934 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27935 the highlighted part of the displayed string to which
27936 GLYPH belongs. Note: GSEQ_LENGTH is different from
27937 SCHARS (STRING), because the latter returns the length of
27938 the internal string. */
27939 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27941 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27942 && begpos
<= tmp_glyph
->charpos
27943 && tmp_glyph
->charpos
< endpos
));
27946 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27948 /* Calculate the total pixel width of all the glyphs between
27949 the beginning of the highlighted area and GLYPH. */
27950 total_pixel_width
= 0;
27951 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27952 total_pixel_width
+= tmp_glyph
->pixel_width
;
27954 /* Pre calculation of re-rendering position. Note: X is in
27955 column units here, after the call to mode_line_string or
27956 marginal_area_string. */
27958 vpos
= (area
== ON_MODE_LINE
27959 ? (w
->current_matrix
)->nrows
- 1
27962 /* If GLYPH's position is included in the region that is
27963 already drawn in mouse face, we have nothing to do. */
27964 if ( EQ (window
, hlinfo
->mouse_face_window
)
27965 && (!row
->reversed_p
27966 ? (hlinfo
->mouse_face_beg_col
<= hpos
27967 && hpos
< hlinfo
->mouse_face_end_col
)
27968 /* In R2L rows we swap BEG and END, see below. */
27969 : (hlinfo
->mouse_face_end_col
<= hpos
27970 && hpos
< hlinfo
->mouse_face_beg_col
))
27971 && hlinfo
->mouse_face_beg_row
== vpos
)
27974 if (clear_mouse_face (hlinfo
))
27975 cursor
= No_Cursor
;
27977 if (!row
->reversed_p
)
27979 hlinfo
->mouse_face_beg_col
= hpos
;
27980 hlinfo
->mouse_face_beg_x
= original_x_pixel
27981 - (total_pixel_width
+ dx
);
27982 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27983 hlinfo
->mouse_face_end_x
= 0;
27987 /* In R2L rows, show_mouse_face expects BEG and END
27988 coordinates to be swapped. */
27989 hlinfo
->mouse_face_end_col
= hpos
;
27990 hlinfo
->mouse_face_end_x
= original_x_pixel
27991 - (total_pixel_width
+ dx
);
27992 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27993 hlinfo
->mouse_face_beg_x
= 0;
27996 hlinfo
->mouse_face_beg_row
= vpos
;
27997 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27998 hlinfo
->mouse_face_past_end
= 0;
27999 hlinfo
->mouse_face_window
= window
;
28001 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28006 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28008 if (NILP (pointer
))
28011 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28012 clear_mouse_face (hlinfo
);
28014 #ifdef HAVE_WINDOW_SYSTEM
28015 if (FRAME_WINDOW_P (f
))
28016 define_frame_cursor1 (f
, cursor
, pointer
);
28022 Take proper action when the mouse has moved to position X, Y on
28023 frame F with regards to highlighting portions of display that have
28024 mouse-face properties. Also de-highlight portions of display where
28025 the mouse was before, set the mouse pointer shape as appropriate
28026 for the mouse coordinates, and activate help echo (tooltips).
28027 X and Y can be negative or out of range. */
28030 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28032 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28033 enum window_part part
= ON_NOTHING
;
28034 Lisp_Object window
;
28036 Cursor cursor
= No_Cursor
;
28037 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28040 /* When a menu is active, don't highlight because this looks odd. */
28041 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28042 if (popup_activated ())
28046 if (!f
->glyphs_initialized_p
28047 || f
->pointer_invisible
)
28050 hlinfo
->mouse_face_mouse_x
= x
;
28051 hlinfo
->mouse_face_mouse_y
= y
;
28052 hlinfo
->mouse_face_mouse_frame
= f
;
28054 if (hlinfo
->mouse_face_defer
)
28057 /* Which window is that in? */
28058 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28060 /* If displaying active text in another window, clear that. */
28061 if (! EQ (window
, hlinfo
->mouse_face_window
)
28062 /* Also clear if we move out of text area in same window. */
28063 || (!NILP (hlinfo
->mouse_face_window
)
28066 && part
!= ON_MODE_LINE
28067 && part
!= ON_HEADER_LINE
))
28068 clear_mouse_face (hlinfo
);
28070 /* Not on a window -> return. */
28071 if (!WINDOWP (window
))
28074 /* Reset help_echo_string. It will get recomputed below. */
28075 help_echo_string
= Qnil
;
28077 /* Convert to window-relative pixel coordinates. */
28078 w
= XWINDOW (window
);
28079 frame_to_window_pixel_xy (w
, &x
, &y
);
28081 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28082 /* Handle tool-bar window differently since it doesn't display a
28084 if (EQ (window
, f
->tool_bar_window
))
28086 note_tool_bar_highlight (f
, x
, y
);
28091 /* Mouse is on the mode, header line or margin? */
28092 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28093 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28095 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28099 #ifdef HAVE_WINDOW_SYSTEM
28100 if (part
== ON_VERTICAL_BORDER
)
28102 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28103 help_echo_string
= build_string ("drag-mouse-1: resize");
28105 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28106 || part
== ON_SCROLL_BAR
)
28107 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28109 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28112 /* Are we in a window whose display is up to date?
28113 And verify the buffer's text has not changed. */
28114 b
= XBUFFER (w
->contents
);
28115 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28117 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28119 struct glyph
*glyph
;
28120 Lisp_Object object
;
28121 Lisp_Object mouse_face
= Qnil
, position
;
28122 Lisp_Object
*overlay_vec
= NULL
;
28123 ptrdiff_t i
, noverlays
;
28124 struct buffer
*obuf
;
28125 ptrdiff_t obegv
, ozv
;
28128 /* Find the glyph under X/Y. */
28129 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28131 #ifdef HAVE_WINDOW_SYSTEM
28132 /* Look for :pointer property on image. */
28133 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28135 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28136 if (img
!= NULL
&& IMAGEP (img
->spec
))
28138 Lisp_Object image_map
, hotspot
;
28139 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28141 && (hotspot
= find_hot_spot (image_map
,
28142 glyph
->slice
.img
.x
+ dx
,
28143 glyph
->slice
.img
.y
+ dy
),
28145 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28149 /* Could check XCAR (hotspot) to see if we enter/leave
28151 If so, we could look for mouse-enter, mouse-leave
28152 properties in PLIST (and do something...). */
28153 hotspot
= XCDR (hotspot
);
28154 if (CONSP (hotspot
)
28155 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28157 pointer
= Fplist_get (plist
, Qpointer
);
28158 if (NILP (pointer
))
28160 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28161 if (!NILP (help_echo_string
))
28163 help_echo_window
= window
;
28164 help_echo_object
= glyph
->object
;
28165 help_echo_pos
= glyph
->charpos
;
28169 if (NILP (pointer
))
28170 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28173 #endif /* HAVE_WINDOW_SYSTEM */
28175 /* Clear mouse face if X/Y not over text. */
28177 || area
!= TEXT_AREA
28178 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28179 /* Glyph's OBJECT is an integer for glyphs inserted by the
28180 display engine for its internal purposes, like truncation
28181 and continuation glyphs and blanks beyond the end of
28182 line's text on text terminals. If we are over such a
28183 glyph, we are not over any text. */
28184 || INTEGERP (glyph
->object
)
28185 /* R2L rows have a stretch glyph at their front, which
28186 stands for no text, whereas L2R rows have no glyphs at
28187 all beyond the end of text. Treat such stretch glyphs
28188 like we do with NULL glyphs in L2R rows. */
28189 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28190 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28191 && glyph
->type
== STRETCH_GLYPH
28192 && glyph
->avoid_cursor_p
))
28194 if (clear_mouse_face (hlinfo
))
28195 cursor
= No_Cursor
;
28196 #ifdef HAVE_WINDOW_SYSTEM
28197 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28199 if (area
!= TEXT_AREA
)
28200 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28202 pointer
= Vvoid_text_area_pointer
;
28208 pos
= glyph
->charpos
;
28209 object
= glyph
->object
;
28210 if (!STRINGP (object
) && !BUFFERP (object
))
28213 /* If we get an out-of-range value, return now; avoid an error. */
28214 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28217 /* Make the window's buffer temporarily current for
28218 overlays_at and compute_char_face. */
28219 obuf
= current_buffer
;
28220 current_buffer
= b
;
28226 /* Is this char mouse-active or does it have help-echo? */
28227 position
= make_number (pos
);
28229 if (BUFFERP (object
))
28231 /* Put all the overlays we want in a vector in overlay_vec. */
28232 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28233 /* Sort overlays into increasing priority order. */
28234 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28239 if (NILP (Vmouse_highlight
))
28241 clear_mouse_face (hlinfo
);
28242 goto check_help_echo
;
28245 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28248 cursor
= No_Cursor
;
28250 /* Check mouse-face highlighting. */
28252 /* If there exists an overlay with mouse-face overlapping
28253 the one we are currently highlighting, we have to
28254 check if we enter the overlapping overlay, and then
28255 highlight only that. */
28256 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28257 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28259 /* Find the highest priority overlay with a mouse-face. */
28260 Lisp_Object overlay
= Qnil
;
28261 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28263 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28264 if (!NILP (mouse_face
))
28265 overlay
= overlay_vec
[i
];
28268 /* If we're highlighting the same overlay as before, there's
28269 no need to do that again. */
28270 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28271 goto check_help_echo
;
28272 hlinfo
->mouse_face_overlay
= overlay
;
28274 /* Clear the display of the old active region, if any. */
28275 if (clear_mouse_face (hlinfo
))
28276 cursor
= No_Cursor
;
28278 /* If no overlay applies, get a text property. */
28279 if (NILP (overlay
))
28280 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28282 /* Next, compute the bounds of the mouse highlighting and
28284 if (!NILP (mouse_face
) && STRINGP (object
))
28286 /* The mouse-highlighting comes from a display string
28287 with a mouse-face. */
28291 s
= Fprevious_single_property_change
28292 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28293 e
= Fnext_single_property_change
28294 (position
, Qmouse_face
, object
, Qnil
);
28296 s
= make_number (0);
28298 e
= make_number (SCHARS (object
));
28299 mouse_face_from_string_pos (w
, hlinfo
, object
,
28300 XINT (s
), XINT (e
));
28301 hlinfo
->mouse_face_past_end
= 0;
28302 hlinfo
->mouse_face_window
= window
;
28303 hlinfo
->mouse_face_face_id
28304 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28305 glyph
->face_id
, 1);
28306 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28307 cursor
= No_Cursor
;
28311 /* The mouse-highlighting, if any, comes from an overlay
28312 or text property in the buffer. */
28313 Lisp_Object buffer
IF_LINT (= Qnil
);
28314 Lisp_Object disp_string
IF_LINT (= Qnil
);
28316 if (STRINGP (object
))
28318 /* If we are on a display string with no mouse-face,
28319 check if the text under it has one. */
28320 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28321 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28322 pos
= string_buffer_position (object
, start
);
28325 mouse_face
= get_char_property_and_overlay
28326 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28327 buffer
= w
->contents
;
28328 disp_string
= object
;
28334 disp_string
= Qnil
;
28337 if (!NILP (mouse_face
))
28339 Lisp_Object before
, after
;
28340 Lisp_Object before_string
, after_string
;
28341 /* To correctly find the limits of mouse highlight
28342 in a bidi-reordered buffer, we must not use the
28343 optimization of limiting the search in
28344 previous-single-property-change and
28345 next-single-property-change, because
28346 rows_from_pos_range needs the real start and end
28347 positions to DTRT in this case. That's because
28348 the first row visible in a window does not
28349 necessarily display the character whose position
28350 is the smallest. */
28352 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28353 ? Fmarker_position (w
->start
)
28356 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28357 ? make_number (BUF_Z (XBUFFER (buffer
))
28358 - w
->window_end_pos
)
28361 if (NILP (overlay
))
28363 /* Handle the text property case. */
28364 before
= Fprevious_single_property_change
28365 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28366 after
= Fnext_single_property_change
28367 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28368 before_string
= after_string
= Qnil
;
28372 /* Handle the overlay case. */
28373 before
= Foverlay_start (overlay
);
28374 after
= Foverlay_end (overlay
);
28375 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28376 after_string
= Foverlay_get (overlay
, Qafter_string
);
28378 if (!STRINGP (before_string
)) before_string
= Qnil
;
28379 if (!STRINGP (after_string
)) after_string
= Qnil
;
28382 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28385 : XFASTINT (before
),
28387 ? BUF_Z (XBUFFER (buffer
))
28388 : XFASTINT (after
),
28389 before_string
, after_string
,
28391 cursor
= No_Cursor
;
28398 /* Look for a `help-echo' property. */
28399 if (NILP (help_echo_string
)) {
28400 Lisp_Object help
, overlay
;
28402 /* Check overlays first. */
28403 help
= overlay
= Qnil
;
28404 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28406 overlay
= overlay_vec
[i
];
28407 help
= Foverlay_get (overlay
, Qhelp_echo
);
28412 help_echo_string
= help
;
28413 help_echo_window
= window
;
28414 help_echo_object
= overlay
;
28415 help_echo_pos
= pos
;
28419 Lisp_Object obj
= glyph
->object
;
28420 ptrdiff_t charpos
= glyph
->charpos
;
28422 /* Try text properties. */
28425 && charpos
< SCHARS (obj
))
28427 help
= Fget_text_property (make_number (charpos
),
28431 /* If the string itself doesn't specify a help-echo,
28432 see if the buffer text ``under'' it does. */
28433 struct glyph_row
*r
28434 = MATRIX_ROW (w
->current_matrix
, vpos
);
28435 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28436 ptrdiff_t p
= string_buffer_position (obj
, start
);
28439 help
= Fget_char_property (make_number (p
),
28440 Qhelp_echo
, w
->contents
);
28449 else if (BUFFERP (obj
)
28452 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28457 help_echo_string
= help
;
28458 help_echo_window
= window
;
28459 help_echo_object
= obj
;
28460 help_echo_pos
= charpos
;
28465 #ifdef HAVE_WINDOW_SYSTEM
28466 /* Look for a `pointer' property. */
28467 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28469 /* Check overlays first. */
28470 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28471 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28473 if (NILP (pointer
))
28475 Lisp_Object obj
= glyph
->object
;
28476 ptrdiff_t charpos
= glyph
->charpos
;
28478 /* Try text properties. */
28481 && charpos
< SCHARS (obj
))
28483 pointer
= Fget_text_property (make_number (charpos
),
28485 if (NILP (pointer
))
28487 /* If the string itself doesn't specify a pointer,
28488 see if the buffer text ``under'' it does. */
28489 struct glyph_row
*r
28490 = MATRIX_ROW (w
->current_matrix
, vpos
);
28491 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28492 ptrdiff_t p
= string_buffer_position (obj
, start
);
28494 pointer
= Fget_char_property (make_number (p
),
28495 Qpointer
, w
->contents
);
28498 else if (BUFFERP (obj
)
28501 pointer
= Fget_text_property (make_number (charpos
),
28505 #endif /* HAVE_WINDOW_SYSTEM */
28509 current_buffer
= obuf
;
28514 #ifdef HAVE_WINDOW_SYSTEM
28515 if (FRAME_WINDOW_P (f
))
28516 define_frame_cursor1 (f
, cursor
, pointer
);
28518 /* This is here to prevent a compiler error, about "label at end of
28519 compound statement". */
28526 Clear any mouse-face on window W. This function is part of the
28527 redisplay interface, and is called from try_window_id and similar
28528 functions to ensure the mouse-highlight is off. */
28531 x_clear_window_mouse_face (struct window
*w
)
28533 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28534 Lisp_Object window
;
28537 XSETWINDOW (window
, w
);
28538 if (EQ (window
, hlinfo
->mouse_face_window
))
28539 clear_mouse_face (hlinfo
);
28545 Just discard the mouse face information for frame F, if any.
28546 This is used when the size of F is changed. */
28549 cancel_mouse_face (struct frame
*f
)
28551 Lisp_Object window
;
28552 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28554 window
= hlinfo
->mouse_face_window
;
28555 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28556 reset_mouse_highlight (hlinfo
);
28561 /***********************************************************************
28563 ***********************************************************************/
28565 #ifdef HAVE_WINDOW_SYSTEM
28567 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28568 which intersects rectangle R. R is in window-relative coordinates. */
28571 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28572 enum glyph_row_area area
)
28574 struct glyph
*first
= row
->glyphs
[area
];
28575 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28576 struct glyph
*last
;
28577 int first_x
, start_x
, x
;
28579 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28580 /* If row extends face to end of line write the whole line. */
28581 draw_glyphs (w
, 0, row
, area
,
28582 0, row
->used
[area
],
28583 DRAW_NORMAL_TEXT
, 0);
28586 /* Set START_X to the window-relative start position for drawing glyphs of
28587 AREA. The first glyph of the text area can be partially visible.
28588 The first glyphs of other areas cannot. */
28589 start_x
= window_box_left_offset (w
, area
);
28591 if (area
== TEXT_AREA
)
28594 /* Find the first glyph that must be redrawn. */
28596 && x
+ first
->pixel_width
< r
->x
)
28598 x
+= first
->pixel_width
;
28602 /* Find the last one. */
28606 && x
< r
->x
+ r
->width
)
28608 x
+= last
->pixel_width
;
28614 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28615 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28616 DRAW_NORMAL_TEXT
, 0);
28621 /* Redraw the parts of the glyph row ROW on window W intersecting
28622 rectangle R. R is in window-relative coordinates. Value is
28623 non-zero if mouse-face was overwritten. */
28626 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28628 eassert (row
->enabled_p
);
28630 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28631 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28632 0, row
->used
[TEXT_AREA
],
28633 DRAW_NORMAL_TEXT
, 0);
28636 if (row
->used
[LEFT_MARGIN_AREA
])
28637 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28638 if (row
->used
[TEXT_AREA
])
28639 expose_area (w
, row
, r
, TEXT_AREA
);
28640 if (row
->used
[RIGHT_MARGIN_AREA
])
28641 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28642 draw_row_fringe_bitmaps (w
, row
);
28645 return row
->mouse_face_p
;
28649 /* Redraw those parts of glyphs rows during expose event handling that
28650 overlap other rows. Redrawing of an exposed line writes over parts
28651 of lines overlapping that exposed line; this function fixes that.
28653 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28654 row in W's current matrix that is exposed and overlaps other rows.
28655 LAST_OVERLAPPING_ROW is the last such row. */
28658 expose_overlaps (struct window
*w
,
28659 struct glyph_row
*first_overlapping_row
,
28660 struct glyph_row
*last_overlapping_row
,
28663 struct glyph_row
*row
;
28665 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28666 if (row
->overlapping_p
)
28668 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28671 if (row
->used
[LEFT_MARGIN_AREA
])
28672 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28674 if (row
->used
[TEXT_AREA
])
28675 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28677 if (row
->used
[RIGHT_MARGIN_AREA
])
28678 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28684 /* Return non-zero if W's cursor intersects rectangle R. */
28687 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28689 XRectangle cr
, result
;
28690 struct glyph
*cursor_glyph
;
28691 struct glyph_row
*row
;
28693 if (w
->phys_cursor
.vpos
>= 0
28694 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28695 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28697 && row
->cursor_in_fringe_p
)
28699 /* Cursor is in the fringe. */
28700 cr
.x
= window_box_right_offset (w
,
28701 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28702 ? RIGHT_MARGIN_AREA
28705 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28706 cr
.height
= row
->height
;
28707 return x_intersect_rectangles (&cr
, r
, &result
);
28710 cursor_glyph
= get_phys_cursor_glyph (w
);
28713 /* r is relative to W's box, but w->phys_cursor.x is relative
28714 to left edge of W's TEXT area. Adjust it. */
28715 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28716 cr
.y
= w
->phys_cursor
.y
;
28717 cr
.width
= cursor_glyph
->pixel_width
;
28718 cr
.height
= w
->phys_cursor_height
;
28719 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28720 I assume the effect is the same -- and this is portable. */
28721 return x_intersect_rectangles (&cr
, r
, &result
);
28723 /* If we don't understand the format, pretend we're not in the hot-spot. */
28729 Draw a vertical window border to the right of window W if W doesn't
28730 have vertical scroll bars. */
28733 x_draw_vertical_border (struct window
*w
)
28735 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28737 /* We could do better, if we knew what type of scroll-bar the adjacent
28738 windows (on either side) have... But we don't :-(
28739 However, I think this works ok. ++KFS 2003-04-25 */
28741 /* Redraw borders between horizontally adjacent windows. Don't
28742 do it for frames with vertical scroll bars because either the
28743 right scroll bar of a window, or the left scroll bar of its
28744 neighbor will suffice as a border. */
28745 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28748 /* Note: It is necessary to redraw both the left and the right
28749 borders, for when only this single window W is being
28751 if (!WINDOW_RIGHTMOST_P (w
)
28752 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28754 int x0
, x1
, y0
, y1
;
28756 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28759 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28762 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28764 if (!WINDOW_LEFTMOST_P (w
)
28765 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28767 int x0
, x1
, y0
, y1
;
28769 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28772 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28775 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28780 /* Redraw the part of window W intersection rectangle FR. Pixel
28781 coordinates in FR are frame-relative. Call this function with
28782 input blocked. Value is non-zero if the exposure overwrites
28786 expose_window (struct window
*w
, XRectangle
*fr
)
28788 struct frame
*f
= XFRAME (w
->frame
);
28790 int mouse_face_overwritten_p
= 0;
28792 /* If window is not yet fully initialized, do nothing. This can
28793 happen when toolkit scroll bars are used and a window is split.
28794 Reconfiguring the scroll bar will generate an expose for a newly
28796 if (w
->current_matrix
== NULL
)
28799 /* When we're currently updating the window, display and current
28800 matrix usually don't agree. Arrange for a thorough display
28802 if (w
->must_be_updated_p
)
28804 SET_FRAME_GARBAGED (f
);
28808 /* Frame-relative pixel rectangle of W. */
28809 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28810 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28811 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28812 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28814 if (x_intersect_rectangles (fr
, &wr
, &r
))
28816 int yb
= window_text_bottom_y (w
);
28817 struct glyph_row
*row
;
28818 int cursor_cleared_p
, phys_cursor_on_p
;
28819 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28821 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28822 r
.x
, r
.y
, r
.width
, r
.height
));
28824 /* Convert to window coordinates. */
28825 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28826 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28828 /* Turn off the cursor. */
28829 if (!w
->pseudo_window_p
28830 && phys_cursor_in_rect_p (w
, &r
))
28832 x_clear_cursor (w
);
28833 cursor_cleared_p
= 1;
28836 cursor_cleared_p
= 0;
28838 /* If the row containing the cursor extends face to end of line,
28839 then expose_area might overwrite the cursor outside the
28840 rectangle and thus notice_overwritten_cursor might clear
28841 w->phys_cursor_on_p. We remember the original value and
28842 check later if it is changed. */
28843 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28845 /* Update lines intersecting rectangle R. */
28846 first_overlapping_row
= last_overlapping_row
= NULL
;
28847 for (row
= w
->current_matrix
->rows
;
28852 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28854 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28855 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28856 || (r
.y
>= y0
&& r
.y
< y1
)
28857 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28859 /* A header line may be overlapping, but there is no need
28860 to fix overlapping areas for them. KFS 2005-02-12 */
28861 if (row
->overlapping_p
&& !row
->mode_line_p
)
28863 if (first_overlapping_row
== NULL
)
28864 first_overlapping_row
= row
;
28865 last_overlapping_row
= row
;
28869 if (expose_line (w
, row
, &r
))
28870 mouse_face_overwritten_p
= 1;
28873 else if (row
->overlapping_p
)
28875 /* We must redraw a row overlapping the exposed area. */
28877 ? y0
+ row
->phys_height
> r
.y
28878 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28880 if (first_overlapping_row
== NULL
)
28881 first_overlapping_row
= row
;
28882 last_overlapping_row
= row
;
28890 /* Display the mode line if there is one. */
28891 if (WINDOW_WANTS_MODELINE_P (w
)
28892 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28894 && row
->y
< r
.y
+ r
.height
)
28896 if (expose_line (w
, row
, &r
))
28897 mouse_face_overwritten_p
= 1;
28900 if (!w
->pseudo_window_p
)
28902 /* Fix the display of overlapping rows. */
28903 if (first_overlapping_row
)
28904 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28907 /* Draw border between windows. */
28908 x_draw_vertical_border (w
);
28910 /* Turn the cursor on again. */
28911 if (cursor_cleared_p
28912 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28913 update_window_cursor (w
, 1);
28917 return mouse_face_overwritten_p
;
28922 /* Redraw (parts) of all windows in the window tree rooted at W that
28923 intersect R. R contains frame pixel coordinates. Value is
28924 non-zero if the exposure overwrites mouse-face. */
28927 expose_window_tree (struct window
*w
, XRectangle
*r
)
28929 struct frame
*f
= XFRAME (w
->frame
);
28930 int mouse_face_overwritten_p
= 0;
28932 while (w
&& !FRAME_GARBAGED_P (f
))
28934 if (WINDOWP (w
->contents
))
28935 mouse_face_overwritten_p
28936 |= expose_window_tree (XWINDOW (w
->contents
), r
);
28938 mouse_face_overwritten_p
|= expose_window (w
, r
);
28940 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28943 return mouse_face_overwritten_p
;
28948 Redisplay an exposed area of frame F. X and Y are the upper-left
28949 corner of the exposed rectangle. W and H are width and height of
28950 the exposed area. All are pixel values. W or H zero means redraw
28951 the entire frame. */
28954 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28957 int mouse_face_overwritten_p
= 0;
28959 TRACE ((stderr
, "expose_frame "));
28961 /* No need to redraw if frame will be redrawn soon. */
28962 if (FRAME_GARBAGED_P (f
))
28964 TRACE ((stderr
, " garbaged\n"));
28968 /* If basic faces haven't been realized yet, there is no point in
28969 trying to redraw anything. This can happen when we get an expose
28970 event while Emacs is starting, e.g. by moving another window. */
28971 if (FRAME_FACE_CACHE (f
) == NULL
28972 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28974 TRACE ((stderr
, " no faces\n"));
28978 if (w
== 0 || h
== 0)
28981 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28982 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28992 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28993 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28995 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28996 if (WINDOWP (f
->tool_bar_window
))
28997 mouse_face_overwritten_p
28998 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29001 #ifdef HAVE_X_WINDOWS
29003 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29004 if (WINDOWP (f
->menu_bar_window
))
29005 mouse_face_overwritten_p
29006 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29007 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29011 /* Some window managers support a focus-follows-mouse style with
29012 delayed raising of frames. Imagine a partially obscured frame,
29013 and moving the mouse into partially obscured mouse-face on that
29014 frame. The visible part of the mouse-face will be highlighted,
29015 then the WM raises the obscured frame. With at least one WM, KDE
29016 2.1, Emacs is not getting any event for the raising of the frame
29017 (even tried with SubstructureRedirectMask), only Expose events.
29018 These expose events will draw text normally, i.e. not
29019 highlighted. Which means we must redo the highlight here.
29020 Subsume it under ``we love X''. --gerd 2001-08-15 */
29021 /* Included in Windows version because Windows most likely does not
29022 do the right thing if any third party tool offers
29023 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29024 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29026 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29027 if (f
== hlinfo
->mouse_face_mouse_frame
)
29029 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29030 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29031 clear_mouse_face (hlinfo
);
29032 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29039 Determine the intersection of two rectangles R1 and R2. Return
29040 the intersection in *RESULT. Value is non-zero if RESULT is not
29044 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29046 XRectangle
*left
, *right
;
29047 XRectangle
*upper
, *lower
;
29048 int intersection_p
= 0;
29050 /* Rearrange so that R1 is the left-most rectangle. */
29052 left
= r1
, right
= r2
;
29054 left
= r2
, right
= r1
;
29056 /* X0 of the intersection is right.x0, if this is inside R1,
29057 otherwise there is no intersection. */
29058 if (right
->x
<= left
->x
+ left
->width
)
29060 result
->x
= right
->x
;
29062 /* The right end of the intersection is the minimum of
29063 the right ends of left and right. */
29064 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29067 /* Same game for Y. */
29069 upper
= r1
, lower
= r2
;
29071 upper
= r2
, lower
= r1
;
29073 /* The upper end of the intersection is lower.y0, if this is inside
29074 of upper. Otherwise, there is no intersection. */
29075 if (lower
->y
<= upper
->y
+ upper
->height
)
29077 result
->y
= lower
->y
;
29079 /* The lower end of the intersection is the minimum of the lower
29080 ends of upper and lower. */
29081 result
->height
= (min (lower
->y
+ lower
->height
,
29082 upper
->y
+ upper
->height
)
29084 intersection_p
= 1;
29088 return intersection_p
;
29091 #endif /* HAVE_WINDOW_SYSTEM */
29094 /***********************************************************************
29096 ***********************************************************************/
29099 syms_of_xdisp (void)
29101 Vwith_echo_area_save_vector
= Qnil
;
29102 staticpro (&Vwith_echo_area_save_vector
);
29104 Vmessage_stack
= Qnil
;
29105 staticpro (&Vmessage_stack
);
29107 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29108 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29110 message_dolog_marker1
= Fmake_marker ();
29111 staticpro (&message_dolog_marker1
);
29112 message_dolog_marker2
= Fmake_marker ();
29113 staticpro (&message_dolog_marker2
);
29114 message_dolog_marker3
= Fmake_marker ();
29115 staticpro (&message_dolog_marker3
);
29118 defsubr (&Sdump_frame_glyph_matrix
);
29119 defsubr (&Sdump_glyph_matrix
);
29120 defsubr (&Sdump_glyph_row
);
29121 defsubr (&Sdump_tool_bar_row
);
29122 defsubr (&Strace_redisplay
);
29123 defsubr (&Strace_to_stderr
);
29125 #ifdef HAVE_WINDOW_SYSTEM
29126 defsubr (&Stool_bar_lines_needed
);
29127 defsubr (&Slookup_image_map
);
29129 defsubr (&Sline_pixel_height
);
29130 defsubr (&Sformat_mode_line
);
29131 defsubr (&Sinvisible_p
);
29132 defsubr (&Scurrent_bidi_paragraph_direction
);
29133 defsubr (&Smove_point_visually
);
29135 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29136 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29137 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29138 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29139 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29140 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29141 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29142 DEFSYM (Qeval
, "eval");
29143 DEFSYM (QCdata
, ":data");
29144 DEFSYM (Qdisplay
, "display");
29145 DEFSYM (Qspace_width
, "space-width");
29146 DEFSYM (Qraise
, "raise");
29147 DEFSYM (Qslice
, "slice");
29148 DEFSYM (Qspace
, "space");
29149 DEFSYM (Qmargin
, "margin");
29150 DEFSYM (Qpointer
, "pointer");
29151 DEFSYM (Qleft_margin
, "left-margin");
29152 DEFSYM (Qright_margin
, "right-margin");
29153 DEFSYM (Qcenter
, "center");
29154 DEFSYM (Qline_height
, "line-height");
29155 DEFSYM (QCalign_to
, ":align-to");
29156 DEFSYM (QCrelative_width
, ":relative-width");
29157 DEFSYM (QCrelative_height
, ":relative-height");
29158 DEFSYM (QCeval
, ":eval");
29159 DEFSYM (QCpropertize
, ":propertize");
29160 DEFSYM (QCfile
, ":file");
29161 DEFSYM (Qfontified
, "fontified");
29162 DEFSYM (Qfontification_functions
, "fontification-functions");
29163 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29164 DEFSYM (Qescape_glyph
, "escape-glyph");
29165 DEFSYM (Qnobreak_space
, "nobreak-space");
29166 DEFSYM (Qimage
, "image");
29167 DEFSYM (Qtext
, "text");
29168 DEFSYM (Qboth
, "both");
29169 DEFSYM (Qboth_horiz
, "both-horiz");
29170 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29171 DEFSYM (QCmap
, ":map");
29172 DEFSYM (QCpointer
, ":pointer");
29173 DEFSYM (Qrect
, "rect");
29174 DEFSYM (Qcircle
, "circle");
29175 DEFSYM (Qpoly
, "poly");
29176 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29177 DEFSYM (Qgrow_only
, "grow-only");
29178 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29179 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29180 DEFSYM (Qposition
, "position");
29181 DEFSYM (Qbuffer_position
, "buffer-position");
29182 DEFSYM (Qobject
, "object");
29183 DEFSYM (Qbar
, "bar");
29184 DEFSYM (Qhbar
, "hbar");
29185 DEFSYM (Qbox
, "box");
29186 DEFSYM (Qhollow
, "hollow");
29187 DEFSYM (Qhand
, "hand");
29188 DEFSYM (Qarrow
, "arrow");
29189 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29191 list_of_error
= list1 (list2 (intern_c_string ("error"),
29192 intern_c_string ("void-variable")));
29193 staticpro (&list_of_error
);
29195 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29196 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29197 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29198 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29200 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29201 staticpro (&echo_buffer
[0]);
29202 staticpro (&echo_buffer
[1]);
29204 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29205 staticpro (&echo_area_buffer
[0]);
29206 staticpro (&echo_area_buffer
[1]);
29208 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29209 staticpro (&Vmessages_buffer_name
);
29211 mode_line_proptrans_alist
= Qnil
;
29212 staticpro (&mode_line_proptrans_alist
);
29213 mode_line_string_list
= Qnil
;
29214 staticpro (&mode_line_string_list
);
29215 mode_line_string_face
= Qnil
;
29216 staticpro (&mode_line_string_face
);
29217 mode_line_string_face_prop
= Qnil
;
29218 staticpro (&mode_line_string_face_prop
);
29219 Vmode_line_unwind_vector
= Qnil
;
29220 staticpro (&Vmode_line_unwind_vector
);
29222 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29224 help_echo_string
= Qnil
;
29225 staticpro (&help_echo_string
);
29226 help_echo_object
= Qnil
;
29227 staticpro (&help_echo_object
);
29228 help_echo_window
= Qnil
;
29229 staticpro (&help_echo_window
);
29230 previous_help_echo_string
= Qnil
;
29231 staticpro (&previous_help_echo_string
);
29232 help_echo_pos
= -1;
29234 DEFSYM (Qright_to_left
, "right-to-left");
29235 DEFSYM (Qleft_to_right
, "left-to-right");
29237 #ifdef HAVE_WINDOW_SYSTEM
29238 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29239 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29240 For example, if a block cursor is over a tab, it will be drawn as
29241 wide as that tab on the display. */);
29242 x_stretch_cursor_p
= 0;
29245 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29246 doc
: /* Non-nil means highlight trailing whitespace.
29247 The face used for trailing whitespace is `trailing-whitespace'. */);
29248 Vshow_trailing_whitespace
= Qnil
;
29250 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29251 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29252 If the value is t, Emacs highlights non-ASCII chars which have the
29253 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29254 or `escape-glyph' face respectively.
29256 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29257 U+2011 (non-breaking hyphen) are affected.
29259 Any other non-nil value means to display these characters as a escape
29260 glyph followed by an ordinary space or hyphen.
29262 A value of nil means no special handling of these characters. */);
29263 Vnobreak_char_display
= Qt
;
29265 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29266 doc
: /* The pointer shape to show in void text areas.
29267 A value of nil means to show the text pointer. Other options are `arrow',
29268 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29269 Vvoid_text_area_pointer
= Qarrow
;
29271 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29272 doc
: /* Non-nil means don't actually do any redisplay.
29273 This is used for internal purposes. */);
29274 Vinhibit_redisplay
= Qnil
;
29276 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29277 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29278 Vglobal_mode_string
= Qnil
;
29280 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29281 doc
: /* Marker for where to display an arrow on top of the buffer text.
29282 This must be the beginning of a line in order to work.
29283 See also `overlay-arrow-string'. */);
29284 Voverlay_arrow_position
= Qnil
;
29286 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29287 doc
: /* String to display as an arrow in non-window frames.
29288 See also `overlay-arrow-position'. */);
29289 Voverlay_arrow_string
= build_pure_c_string ("=>");
29291 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29292 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29293 The symbols on this list are examined during redisplay to determine
29294 where to display overlay arrows. */);
29295 Voverlay_arrow_variable_list
29296 = list1 (intern_c_string ("overlay-arrow-position"));
29298 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29299 doc
: /* The number of lines to try scrolling a window by when point moves out.
29300 If that fails to bring point back on frame, point is centered instead.
29301 If this is zero, point is always centered after it moves off frame.
29302 If you want scrolling to always be a line at a time, you should set
29303 `scroll-conservatively' to a large value rather than set this to 1. */);
29305 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29306 doc
: /* Scroll up to this many lines, to bring point back on screen.
29307 If point moves off-screen, redisplay will scroll by up to
29308 `scroll-conservatively' lines in order to bring point just barely
29309 onto the screen again. If that cannot be done, then redisplay
29310 recenters point as usual.
29312 If the value is greater than 100, redisplay will never recenter point,
29313 but will always scroll just enough text to bring point into view, even
29314 if you move far away.
29316 A value of zero means always recenter point if it moves off screen. */);
29317 scroll_conservatively
= 0;
29319 DEFVAR_INT ("scroll-margin", scroll_margin
,
29320 doc
: /* Number of lines of margin at the top and bottom of a window.
29321 Recenter the window whenever point gets within this many lines
29322 of the top or bottom of the window. */);
29325 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29326 doc
: /* Pixels per inch value for non-window system displays.
29327 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29328 Vdisplay_pixels_per_inch
= make_float (72.0);
29331 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29334 DEFVAR_LISP ("truncate-partial-width-windows",
29335 Vtruncate_partial_width_windows
,
29336 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29337 For an integer value, truncate lines in each window narrower than the
29338 full frame width, provided the window width is less than that integer;
29339 otherwise, respect the value of `truncate-lines'.
29341 For any other non-nil value, truncate lines in all windows that do
29342 not span the full frame width.
29344 A value of nil means to respect the value of `truncate-lines'.
29346 If `word-wrap' is enabled, you might want to reduce this. */);
29347 Vtruncate_partial_width_windows
= make_number (50);
29349 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29350 doc
: /* Maximum buffer size for which line number should be displayed.
29351 If the buffer is bigger than this, the line number does not appear
29352 in the mode line. A value of nil means no limit. */);
29353 Vline_number_display_limit
= Qnil
;
29355 DEFVAR_INT ("line-number-display-limit-width",
29356 line_number_display_limit_width
,
29357 doc
: /* Maximum line width (in characters) for line number display.
29358 If the average length of the lines near point is bigger than this, then the
29359 line number may be omitted from the mode line. */);
29360 line_number_display_limit_width
= 200;
29362 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29363 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29364 highlight_nonselected_windows
= 0;
29366 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29367 doc
: /* Non-nil if more than one frame is visible on this display.
29368 Minibuffer-only frames don't count, but iconified frames do.
29369 This variable is not guaranteed to be accurate except while processing
29370 `frame-title-format' and `icon-title-format'. */);
29372 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29373 doc
: /* Template for displaying the title bar of visible frames.
29374 \(Assuming the window manager supports this feature.)
29376 This variable has the same structure as `mode-line-format', except that
29377 the %c and %l constructs are ignored. It is used only on frames for
29378 which no explicit name has been set \(see `modify-frame-parameters'). */);
29380 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29381 doc
: /* Template for displaying the title bar of an iconified frame.
29382 \(Assuming the window manager supports this feature.)
29383 This variable has the same structure as `mode-line-format' (which see),
29384 and is used only on frames for which no explicit name has been set
29385 \(see `modify-frame-parameters'). */);
29387 = Vframe_title_format
29388 = listn (CONSTYPE_PURE
, 3,
29389 intern_c_string ("multiple-frames"),
29390 build_pure_c_string ("%b"),
29391 listn (CONSTYPE_PURE
, 4,
29392 empty_unibyte_string
,
29393 intern_c_string ("invocation-name"),
29394 build_pure_c_string ("@"),
29395 intern_c_string ("system-name")));
29397 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29398 doc
: /* Maximum number of lines to keep in the message log buffer.
29399 If nil, disable message logging. If t, log messages but don't truncate
29400 the buffer when it becomes large. */);
29401 Vmessage_log_max
= make_number (1000);
29403 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29404 doc
: /* Functions called before redisplay, if window sizes have changed.
29405 The value should be a list of functions that take one argument.
29406 Just before redisplay, for each frame, if any of its windows have changed
29407 size since the last redisplay, or have been split or deleted,
29408 all the functions in the list are called, with the frame as argument. */);
29409 Vwindow_size_change_functions
= Qnil
;
29411 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29412 doc
: /* List of functions to call before redisplaying a window with scrolling.
29413 Each function is called with two arguments, the window and its new
29414 display-start position. Note that these functions are also called by
29415 `set-window-buffer'. Also note that the value of `window-end' is not
29416 valid when these functions are called.
29418 Warning: Do not use this feature to alter the way the window
29419 is scrolled. It is not designed for that, and such use probably won't
29421 Vwindow_scroll_functions
= Qnil
;
29423 DEFVAR_LISP ("window-text-change-functions",
29424 Vwindow_text_change_functions
,
29425 doc
: /* Functions to call in redisplay when text in the window might change. */);
29426 Vwindow_text_change_functions
= Qnil
;
29428 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29429 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29430 Each function is called with two arguments, the window and the end trigger value.
29431 See `set-window-redisplay-end-trigger'. */);
29432 Vredisplay_end_trigger_functions
= Qnil
;
29434 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29435 doc
: /* Non-nil means autoselect window with mouse pointer.
29436 If nil, do not autoselect windows.
29437 A positive number means delay autoselection by that many seconds: a
29438 window is autoselected only after the mouse has remained in that
29439 window for the duration of the delay.
29440 A negative number has a similar effect, but causes windows to be
29441 autoselected only after the mouse has stopped moving. \(Because of
29442 the way Emacs compares mouse events, you will occasionally wait twice
29443 that time before the window gets selected.\)
29444 Any other value means to autoselect window instantaneously when the
29445 mouse pointer enters it.
29447 Autoselection selects the minibuffer only if it is active, and never
29448 unselects the minibuffer if it is active.
29450 When customizing this variable make sure that the actual value of
29451 `focus-follows-mouse' matches the behavior of your window manager. */);
29452 Vmouse_autoselect_window
= Qnil
;
29454 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29455 doc
: /* Non-nil means automatically resize tool-bars.
29456 This dynamically changes the tool-bar's height to the minimum height
29457 that is needed to make all tool-bar items visible.
29458 If value is `grow-only', the tool-bar's height is only increased
29459 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29460 Vauto_resize_tool_bars
= Qt
;
29462 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29463 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29464 auto_raise_tool_bar_buttons_p
= 1;
29466 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29467 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29468 make_cursor_line_fully_visible_p
= 1;
29470 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29471 doc
: /* Border below tool-bar in pixels.
29472 If an integer, use it as the height of the border.
29473 If it is one of `internal-border-width' or `border-width', use the
29474 value of the corresponding frame parameter.
29475 Otherwise, no border is added below the tool-bar. */);
29476 Vtool_bar_border
= Qinternal_border_width
;
29478 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29479 doc
: /* Margin around tool-bar buttons in pixels.
29480 If an integer, use that for both horizontal and vertical margins.
29481 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29482 HORZ specifying the horizontal margin, and VERT specifying the
29483 vertical margin. */);
29484 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29486 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29487 doc
: /* Relief thickness of tool-bar buttons. */);
29488 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29490 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29491 doc
: /* Tool bar style to use.
29493 image - show images only
29494 text - show text only
29495 both - show both, text below image
29496 both-horiz - show text to the right of the image
29497 text-image-horiz - show text to the left of the image
29498 any other - use system default or image if no system default.
29500 This variable only affects the GTK+ toolkit version of Emacs. */);
29501 Vtool_bar_style
= Qnil
;
29503 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29504 doc
: /* Maximum number of characters a label can have to be shown.
29505 The tool bar style must also show labels for this to have any effect, see
29506 `tool-bar-style'. */);
29507 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29509 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29510 doc
: /* List of functions to call to fontify regions of text.
29511 Each function is called with one argument POS. Functions must
29512 fontify a region starting at POS in the current buffer, and give
29513 fontified regions the property `fontified'. */);
29514 Vfontification_functions
= Qnil
;
29515 Fmake_variable_buffer_local (Qfontification_functions
);
29517 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29518 unibyte_display_via_language_environment
,
29519 doc
: /* Non-nil means display unibyte text according to language environment.
29520 Specifically, this means that raw bytes in the range 160-255 decimal
29521 are displayed by converting them to the equivalent multibyte characters
29522 according to the current language environment. As a result, they are
29523 displayed according to the current fontset.
29525 Note that this variable affects only how these bytes are displayed,
29526 but does not change the fact they are interpreted as raw bytes. */);
29527 unibyte_display_via_language_environment
= 0;
29529 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29530 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29531 If a float, it specifies a fraction of the mini-window frame's height.
29532 If an integer, it specifies a number of lines. */);
29533 Vmax_mini_window_height
= make_float (0.25);
29535 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29536 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29537 A value of nil means don't automatically resize mini-windows.
29538 A value of t means resize them to fit the text displayed in them.
29539 A value of `grow-only', the default, means let mini-windows grow only;
29540 they return to their normal size when the minibuffer is closed, or the
29541 echo area becomes empty. */);
29542 Vresize_mini_windows
= Qgrow_only
;
29544 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29545 doc
: /* Alist specifying how to blink the cursor off.
29546 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29547 `cursor-type' frame-parameter or variable equals ON-STATE,
29548 comparing using `equal', Emacs uses OFF-STATE to specify
29549 how to blink it off. ON-STATE and OFF-STATE are values for
29550 the `cursor-type' frame parameter.
29552 If a frame's ON-STATE has no entry in this list,
29553 the frame's other specifications determine how to blink the cursor off. */);
29554 Vblink_cursor_alist
= Qnil
;
29556 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29557 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29558 If non-nil, windows are automatically scrolled horizontally to make
29559 point visible. */);
29560 automatic_hscrolling_p
= 1;
29561 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29563 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29564 doc
: /* How many columns away from the window edge point is allowed to get
29565 before automatic hscrolling will horizontally scroll the window. */);
29566 hscroll_margin
= 5;
29568 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29569 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29570 When point is less than `hscroll-margin' columns from the window
29571 edge, automatic hscrolling will scroll the window by the amount of columns
29572 determined by this variable. If its value is a positive integer, scroll that
29573 many columns. If it's a positive floating-point number, it specifies the
29574 fraction of the window's width to scroll. If it's nil or zero, point will be
29575 centered horizontally after the scroll. Any other value, including negative
29576 numbers, are treated as if the value were zero.
29578 Automatic hscrolling always moves point outside the scroll margin, so if
29579 point was more than scroll step columns inside the margin, the window will
29580 scroll more than the value given by the scroll step.
29582 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29583 and `scroll-right' overrides this variable's effect. */);
29584 Vhscroll_step
= make_number (0);
29586 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29587 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29588 Bind this around calls to `message' to let it take effect. */);
29589 message_truncate_lines
= 0;
29591 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29592 doc
: /* Normal hook run to update the menu bar definitions.
29593 Redisplay runs this hook before it redisplays the menu bar.
29594 This is used to update submenus such as Buffers,
29595 whose contents depend on various data. */);
29596 Vmenu_bar_update_hook
= Qnil
;
29598 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29599 doc
: /* Frame for which we are updating a menu.
29600 The enable predicate for a menu binding should check this variable. */);
29601 Vmenu_updating_frame
= Qnil
;
29603 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29604 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29605 inhibit_menubar_update
= 0;
29607 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29608 doc
: /* Prefix prepended to all continuation lines at display time.
29609 The value may be a string, an image, or a stretch-glyph; it is
29610 interpreted in the same way as the value of a `display' text property.
29612 This variable is overridden by any `wrap-prefix' text or overlay
29615 To add a prefix to non-continuation lines, use `line-prefix'. */);
29616 Vwrap_prefix
= Qnil
;
29617 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29618 Fmake_variable_buffer_local (Qwrap_prefix
);
29620 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29621 doc
: /* Prefix prepended to all non-continuation lines at display time.
29622 The value may be a string, an image, or a stretch-glyph; it is
29623 interpreted in the same way as the value of a `display' text property.
29625 This variable is overridden by any `line-prefix' text or overlay
29628 To add a prefix to continuation lines, use `wrap-prefix'. */);
29629 Vline_prefix
= Qnil
;
29630 DEFSYM (Qline_prefix
, "line-prefix");
29631 Fmake_variable_buffer_local (Qline_prefix
);
29633 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29634 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29635 inhibit_eval_during_redisplay
= 0;
29637 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29638 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29639 inhibit_free_realized_faces
= 0;
29642 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29643 doc
: /* Inhibit try_window_id display optimization. */);
29644 inhibit_try_window_id
= 0;
29646 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29647 doc
: /* Inhibit try_window_reusing display optimization. */);
29648 inhibit_try_window_reusing
= 0;
29650 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29651 doc
: /* Inhibit try_cursor_movement display optimization. */);
29652 inhibit_try_cursor_movement
= 0;
29653 #endif /* GLYPH_DEBUG */
29655 DEFVAR_INT ("overline-margin", overline_margin
,
29656 doc
: /* Space between overline and text, in pixels.
29657 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29658 margin to the character height. */);
29659 overline_margin
= 2;
29661 DEFVAR_INT ("underline-minimum-offset",
29662 underline_minimum_offset
,
29663 doc
: /* Minimum distance between baseline and underline.
29664 This can improve legibility of underlined text at small font sizes,
29665 particularly when using variable `x-use-underline-position-properties'
29666 with fonts that specify an UNDERLINE_POSITION relatively close to the
29667 baseline. The default value is 1. */);
29668 underline_minimum_offset
= 1;
29670 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29671 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29672 This feature only works when on a window system that can change
29673 cursor shapes. */);
29674 display_hourglass_p
= 1;
29676 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29677 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29678 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29680 #ifdef HAVE_WINDOW_SYSTEM
29681 hourglass_atimer
= NULL
;
29682 hourglass_shown_p
= 0;
29683 #endif /* HAVE_WINDOW_SYSTEM */
29685 DEFSYM (Qglyphless_char
, "glyphless-char");
29686 DEFSYM (Qhex_code
, "hex-code");
29687 DEFSYM (Qempty_box
, "empty-box");
29688 DEFSYM (Qthin_space
, "thin-space");
29689 DEFSYM (Qzero_width
, "zero-width");
29691 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
29692 doc
: /* Function run just before redisplay.
29693 It is called with one argument, which is the set of windows that are to
29694 be redisplayed. This set can be nil (meaning, only the selected window),
29695 or t (meaning all windows). */);
29696 Vpre_redisplay_function
= intern ("ignore");
29698 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29699 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29701 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29702 doc
: /* Char-table defining glyphless characters.
29703 Each element, if non-nil, should be one of the following:
29704 an ASCII acronym string: display this string in a box
29705 `hex-code': display the hexadecimal code of a character in a box
29706 `empty-box': display as an empty box
29707 `thin-space': display as 1-pixel width space
29708 `zero-width': don't display
29709 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29710 display method for graphical terminals and text terminals respectively.
29711 GRAPHICAL and TEXT should each have one of the values listed above.
29713 The char-table has one extra slot to control the display of a character for
29714 which no font is found. This slot only takes effect on graphical terminals.
29715 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29716 `thin-space'. The default is `empty-box'. */);
29717 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29718 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29721 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29722 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29723 Vdebug_on_message
= Qnil
;
29727 /* Initialize this module when Emacs starts. */
29732 CHARPOS (this_line_start_pos
) = 0;
29734 if (!noninteractive
)
29736 struct window
*m
= XWINDOW (minibuf_window
);
29737 Lisp_Object frame
= m
->frame
;
29738 struct frame
*f
= XFRAME (frame
);
29739 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29740 struct window
*r
= XWINDOW (root
);
29743 echo_area_window
= minibuf_window
;
29745 r
->top_line
= FRAME_TOP_MARGIN (f
);
29746 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29747 r
->total_cols
= FRAME_COLS (f
);
29749 m
->top_line
= FRAME_LINES (f
) - 1;
29750 m
->total_lines
= 1;
29751 m
->total_cols
= FRAME_COLS (f
);
29753 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29754 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29755 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29757 /* The default ellipsis glyphs `...'. */
29758 for (i
= 0; i
< 3; ++i
)
29759 default_invis_vector
[i
] = make_number ('.');
29763 /* Allocate the buffer for frame titles.
29764 Also used for `format-mode-line'. */
29766 mode_line_noprop_buf
= xmalloc (size
);
29767 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29768 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29769 mode_line_target
= MODE_LINE_DISPLAY
;
29772 help_echo_showing_p
= 0;
29775 #ifdef HAVE_WINDOW_SYSTEM
29777 /* Platform-independent portion of hourglass implementation. */
29779 /* Cancel a currently active hourglass timer, and start a new one. */
29781 start_hourglass (void)
29783 struct timespec delay
;
29785 cancel_hourglass ();
29787 if (INTEGERP (Vhourglass_delay
)
29788 && XINT (Vhourglass_delay
) > 0)
29789 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29790 TYPE_MAXIMUM (time_t)),
29792 else if (FLOATP (Vhourglass_delay
)
29793 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29794 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29796 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29800 extern void w32_note_current_window (void);
29801 w32_note_current_window ();
29803 #endif /* HAVE_NTGUI */
29805 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29806 show_hourglass
, NULL
);
29810 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29813 cancel_hourglass (void)
29815 if (hourglass_atimer
)
29817 cancel_atimer (hourglass_atimer
);
29818 hourglass_atimer
= NULL
;
29821 if (hourglass_shown_p
)
29825 #endif /* HAVE_WINDOW_SYSTEM */