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.
506 If it has value REDISPLAY_SOME, then only redisplay the mode lines where
507 the `redisplay' bit has been set. Otherwise, redisplay all mode lines
508 (the number used is then only used to track down the cause for this
511 int update_mode_lines
;
513 /* Nonzero if window sizes or contents other than selected-window have changed
514 since last redisplay that finished.
515 If it has value REDISPLAY_SOME, then only redisplay the windows where
516 the `redisplay' bit has been set. Otherwise, redisplay all windows
517 (the number used is then only used to track down the cause for this
520 int windows_or_buffers_changed
;
522 /* Nonzero after display_mode_line if %l was used and it displayed a
525 static bool line_number_displayed
;
527 /* The name of the *Messages* buffer, a string. */
529 static Lisp_Object Vmessages_buffer_name
;
531 /* Current, index 0, and last displayed echo area message. Either
532 buffers from echo_buffers, or nil to indicate no message. */
534 Lisp_Object echo_area_buffer
[2];
536 /* The buffers referenced from echo_area_buffer. */
538 static Lisp_Object echo_buffer
[2];
540 /* A vector saved used in with_area_buffer to reduce consing. */
542 static Lisp_Object Vwith_echo_area_save_vector
;
544 /* Non-zero means display_echo_area should display the last echo area
545 message again. Set by redisplay_preserve_echo_area. */
547 static bool display_last_displayed_message_p
;
549 /* Nonzero if echo area is being used by print; zero if being used by
552 static bool message_buf_print
;
554 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
556 static Lisp_Object Qinhibit_menubar_update
;
557 static Lisp_Object Qmessage_truncate_lines
;
559 /* Set to 1 in clear_message to make redisplay_internal aware
560 of an emptied echo area. */
562 static bool message_cleared_p
;
564 /* A scratch glyph row with contents used for generating truncation
565 glyphs. Also used in direct_output_for_insert. */
567 #define MAX_SCRATCH_GLYPHS 100
568 static struct glyph_row scratch_glyph_row
;
569 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
571 /* Ascent and height of the last line processed by move_it_to. */
573 static int last_height
;
575 /* Non-zero if there's a help-echo in the echo area. */
577 bool help_echo_showing_p
;
579 /* The maximum distance to look ahead for text properties. Values
580 that are too small let us call compute_char_face and similar
581 functions too often which is expensive. Values that are too large
582 let us call compute_char_face and alike too often because we
583 might not be interested in text properties that far away. */
585 #define TEXT_PROP_DISTANCE_LIMIT 100
587 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
588 iterator state and later restore it. This is needed because the
589 bidi iterator on bidi.c keeps a stacked cache of its states, which
590 is really a singleton. When we use scratch iterator objects to
591 move around the buffer, we can cause the bidi cache to be pushed or
592 popped, and therefore we need to restore the cache state when we
593 return to the original iterator. */
594 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
597 bidi_unshelve_cache (CACHE, 1); \
599 CACHE = bidi_shelve_cache (); \
602 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
604 if (pITORIG != pITCOPY) \
605 *(pITORIG) = *(pITCOPY); \
606 bidi_unshelve_cache (CACHE, 0); \
610 /* Functions to mark elements as needing redisplay. */
611 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
614 redisplay_other_windows (void)
616 if (!windows_or_buffers_changed
)
617 windows_or_buffers_changed
= REDISPLAY_SOME
;
621 wset_redisplay (struct window
*w
)
623 redisplay_other_windows ();
628 fset_redisplay (struct frame
*f
)
630 redisplay_other_windows ();
635 bset_redisplay (struct buffer
*b
)
637 int count
= buffer_window_count (b
);
640 /* ... it's visible in other window than selected, */
641 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
642 redisplay_other_windows ();
643 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
644 so that if we later set windows_or_buffers_changed, this buffer will
646 b
->text
->redisplay
= true;
651 bset_update_mode_line (struct buffer
*b
)
653 if (!update_mode_lines
)
654 update_mode_lines
= REDISPLAY_SOME
;
655 b
->text
->redisplay
= true;
660 /* Non-zero means print traces of redisplay if compiled with
661 GLYPH_DEBUG defined. */
663 int trace_redisplay_p
;
665 #endif /* GLYPH_DEBUG */
667 #ifdef DEBUG_TRACE_MOVE
668 /* Non-zero means trace with TRACE_MOVE to stderr. */
671 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
673 #define TRACE_MOVE(x) (void) 0
676 static Lisp_Object Qauto_hscroll_mode
;
678 /* Buffer being redisplayed -- for redisplay_window_error. */
680 static struct buffer
*displayed_buffer
;
682 /* Value returned from text property handlers (see below). */
687 HANDLED_RECOMPUTE_PROPS
,
688 HANDLED_OVERLAY_STRING_CONSUMED
,
692 /* A description of text properties that redisplay is interested
697 /* The name of the property. */
700 /* A unique index for the property. */
703 /* A handler function called to set up iterator IT from the property
704 at IT's current position. Value is used to steer handle_stop. */
705 enum prop_handled (*handler
) (struct it
*it
);
708 static enum prop_handled
handle_face_prop (struct it
*);
709 static enum prop_handled
handle_invisible_prop (struct it
*);
710 static enum prop_handled
handle_display_prop (struct it
*);
711 static enum prop_handled
handle_composition_prop (struct it
*);
712 static enum prop_handled
handle_overlay_change (struct it
*);
713 static enum prop_handled
handle_fontified_prop (struct it
*);
715 /* Properties handled by iterators. */
717 static struct props it_props
[] =
719 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
720 /* Handle `face' before `display' because some sub-properties of
721 `display' need to know the face. */
722 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
723 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
724 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
725 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
729 /* Value is the position described by X. If X is a marker, value is
730 the marker_position of X. Otherwise, value is X. */
732 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
734 /* Enumeration returned by some move_it_.* functions internally. */
738 /* Not used. Undefined value. */
741 /* Move ended at the requested buffer position or ZV. */
742 MOVE_POS_MATCH_OR_ZV
,
744 /* Move ended at the requested X pixel position. */
747 /* Move within a line ended at the end of a line that must be
751 /* Move within a line ended at the end of a line that would
752 be displayed truncated. */
755 /* Move within a line ended at a line end. */
759 /* This counter is used to clear the face cache every once in a while
760 in redisplay_internal. It is incremented for each redisplay.
761 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
764 #define CLEAR_FACE_CACHE_COUNT 500
765 static int clear_face_cache_count
;
767 /* Similarly for the image cache. */
769 #ifdef HAVE_WINDOW_SYSTEM
770 #define CLEAR_IMAGE_CACHE_COUNT 101
771 static int clear_image_cache_count
;
773 /* Null glyph slice */
774 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
777 /* True while redisplay_internal is in progress. */
781 static Lisp_Object Qinhibit_free_realized_faces
;
782 static Lisp_Object Qmode_line_default_help_echo
;
784 /* If a string, XTread_socket generates an event to display that string.
785 (The display is done in read_char.) */
787 Lisp_Object help_echo_string
;
788 Lisp_Object help_echo_window
;
789 Lisp_Object help_echo_object
;
790 ptrdiff_t help_echo_pos
;
792 /* Temporary variable for XTread_socket. */
794 Lisp_Object previous_help_echo_string
;
796 /* Platform-independent portion of hourglass implementation. */
798 #ifdef HAVE_WINDOW_SYSTEM
800 /* Non-zero means an hourglass cursor is currently shown. */
801 bool hourglass_shown_p
;
803 /* If non-null, an asynchronous timer that, when it expires, displays
804 an hourglass cursor on all frames. */
805 struct atimer
*hourglass_atimer
;
807 #endif /* HAVE_WINDOW_SYSTEM */
809 /* Name of the face used to display glyphless characters. */
810 static Lisp_Object Qglyphless_char
;
812 /* Symbol for the purpose of Vglyphless_char_display. */
813 static Lisp_Object Qglyphless_char_display
;
815 /* Method symbols for Vglyphless_char_display. */
816 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
818 /* Default number of seconds to wait before displaying an hourglass
820 #define DEFAULT_HOURGLASS_DELAY 1
822 #ifdef HAVE_WINDOW_SYSTEM
824 /* Default pixel width of `thin-space' display method. */
825 #define THIN_SPACE_WIDTH 1
827 #endif /* HAVE_WINDOW_SYSTEM */
829 /* Function prototypes. */
831 static void setup_for_ellipsis (struct it
*, int);
832 static void set_iterator_to_next (struct it
*, int);
833 static void mark_window_display_accurate_1 (struct window
*, int);
834 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
835 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
836 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
837 static int cursor_row_p (struct glyph_row
*);
838 static int redisplay_mode_lines (Lisp_Object
, bool);
839 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
841 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
843 static void handle_line_prefix (struct it
*);
845 static void pint2str (char *, int, ptrdiff_t);
846 static void pint2hrstr (char *, int, ptrdiff_t);
847 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
849 static int text_outside_line_unchanged_p (struct window
*,
850 ptrdiff_t, ptrdiff_t);
851 static void store_mode_line_noprop_char (char);
852 static int store_mode_line_noprop (const char *, int, int);
853 static void handle_stop (struct it
*);
854 static void handle_stop_backwards (struct it
*, ptrdiff_t);
855 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
856 static void ensure_echo_area_buffers (void);
857 static void unwind_with_echo_area_buffer (Lisp_Object
);
858 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
859 static int with_echo_area_buffer (struct window
*, int,
860 int (*) (ptrdiff_t, Lisp_Object
),
861 ptrdiff_t, Lisp_Object
);
862 static void clear_garbaged_frames (void);
863 static int current_message_1 (ptrdiff_t, Lisp_Object
);
864 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
865 static void set_message (Lisp_Object
);
866 static int set_message_1 (ptrdiff_t, Lisp_Object
);
867 static int display_echo_area (struct window
*);
868 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
869 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
870 static void unwind_redisplay (void);
871 static int string_char_and_length (const unsigned char *, int *);
872 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
874 static int compute_window_start_on_continuation_line (struct window
*);
875 static void insert_left_trunc_glyphs (struct it
*);
876 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
878 static void extend_face_to_end_of_line (struct it
*);
879 static int append_space_for_newline (struct it
*, int);
880 static int cursor_row_fully_visible_p (struct window
*, int, int);
881 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
882 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
883 static int trailing_whitespace_p (ptrdiff_t);
884 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
885 static void push_it (struct it
*, struct text_pos
*);
886 static void iterate_out_of_display_property (struct it
*);
887 static void pop_it (struct it
*);
888 static void sync_frame_with_window_matrix_rows (struct window
*);
889 static void redisplay_internal (void);
890 static int echo_area_display (int);
891 static void redisplay_windows (Lisp_Object
);
892 static void redisplay_window (Lisp_Object
, bool);
893 static Lisp_Object
redisplay_window_error (Lisp_Object
);
894 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
895 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
896 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
897 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
899 static int update_menu_bar (struct frame
*, int, int);
900 static int try_window_reusing_current_matrix (struct window
*);
901 static int try_window_id (struct window
*);
902 static int display_line (struct it
*);
903 static int display_mode_lines (struct window
*);
904 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
905 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
906 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
907 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
908 static void display_menu_bar (struct window
*);
909 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
911 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
912 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
913 static void compute_line_metrics (struct it
*);
914 static void run_redisplay_end_trigger_hook (struct it
*);
915 static int get_overlay_strings (struct it
*, ptrdiff_t);
916 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
917 static void next_overlay_string (struct it
*);
918 static void reseat (struct it
*, struct text_pos
, int);
919 static void reseat_1 (struct it
*, struct text_pos
, int);
920 static void back_to_previous_visible_line_start (struct it
*);
921 static void reseat_at_next_visible_line_start (struct it
*, int);
922 static int next_element_from_ellipsis (struct it
*);
923 static int next_element_from_display_vector (struct it
*);
924 static int next_element_from_string (struct it
*);
925 static int next_element_from_c_string (struct it
*);
926 static int next_element_from_buffer (struct it
*);
927 static int next_element_from_composition (struct it
*);
928 static int next_element_from_image (struct it
*);
929 static int next_element_from_stretch (struct it
*);
930 static void load_overlay_strings (struct it
*, ptrdiff_t);
931 static int init_from_display_pos (struct it
*, struct window
*,
932 struct display_pos
*);
933 static void reseat_to_string (struct it
*, const char *,
934 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
935 static int get_next_display_element (struct it
*);
936 static enum move_it_result
937 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
938 enum move_operation_enum
);
939 static void get_visually_first_element (struct it
*);
940 static void init_to_row_start (struct it
*, struct window
*,
942 static int init_to_row_end (struct it
*, struct window
*,
944 static void back_to_previous_line_start (struct it
*);
945 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
946 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
947 Lisp_Object
, ptrdiff_t);
948 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
949 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
950 static ptrdiff_t number_of_chars (const char *, bool);
951 static void compute_stop_pos (struct it
*);
952 static void compute_string_pos (struct text_pos
*, struct text_pos
,
954 static int face_before_or_after_it_pos (struct it
*, int);
955 static ptrdiff_t next_overlay_change (ptrdiff_t);
956 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
957 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
958 static int handle_single_display_spec (struct it
*, Lisp_Object
,
959 Lisp_Object
, Lisp_Object
,
960 struct text_pos
*, ptrdiff_t, int, int);
961 static int underlying_face_id (struct it
*);
962 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
965 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
966 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
968 #ifdef HAVE_WINDOW_SYSTEM
970 static void x_consider_frame_title (Lisp_Object
);
971 static void update_tool_bar (struct frame
*, int);
972 static int redisplay_tool_bar (struct frame
*);
973 static void notice_overwritten_cursor (struct window
*,
976 static void append_stretch_glyph (struct it
*, Lisp_Object
,
980 #endif /* HAVE_WINDOW_SYSTEM */
982 static void produce_special_glyphs (struct it
*, enum display_element_type
);
983 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
984 static int coords_in_mouse_face_p (struct window
*, int, int);
988 /***********************************************************************
989 Window display dimensions
990 ***********************************************************************/
992 /* Return the bottom boundary y-position for text lines in window W.
993 This is the first y position at which a line cannot start.
994 It is relative to the top of the window.
996 This is the height of W minus the height of a mode line, if any. */
999 window_text_bottom_y (struct window
*w
)
1001 int height
= WINDOW_TOTAL_HEIGHT (w
);
1003 if (WINDOW_WANTS_MODELINE_P (w
))
1004 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1008 /* Return the pixel width of display area AREA of window W.
1009 ANY_AREA means return the total width of W, not including
1010 fringes to the left and right of the window. */
1013 window_box_width (struct window
*w
, enum glyph_row_area area
)
1015 int cols
= w
->total_cols
;
1018 if (!w
->pseudo_window_p
)
1020 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1022 if (area
== TEXT_AREA
)
1024 cols
-= max (0, w
->left_margin_cols
);
1025 cols
-= max (0, w
->right_margin_cols
);
1026 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1028 else if (area
== LEFT_MARGIN_AREA
)
1030 cols
= max (0, w
->left_margin_cols
);
1033 else if (area
== RIGHT_MARGIN_AREA
)
1035 cols
= max (0, w
->right_margin_cols
);
1040 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1044 /* Return the pixel height of the display area of window W, not
1045 including mode lines of W, if any. */
1048 window_box_height (struct window
*w
)
1050 struct frame
*f
= XFRAME (w
->frame
);
1051 int height
= WINDOW_TOTAL_HEIGHT (w
);
1053 eassert (height
>= 0);
1055 /* Note: the code below that determines the mode-line/header-line
1056 height is essentially the same as that contained in the macro
1057 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1058 the appropriate glyph row has its `mode_line_p' flag set,
1059 and if it doesn't, uses estimate_mode_line_height instead. */
1061 if (WINDOW_WANTS_MODELINE_P (w
))
1063 struct glyph_row
*ml_row
1064 = (w
->current_matrix
&& w
->current_matrix
->rows
1065 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1067 if (ml_row
&& ml_row
->mode_line_p
)
1068 height
-= ml_row
->height
;
1070 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1073 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1075 struct glyph_row
*hl_row
1076 = (w
->current_matrix
&& w
->current_matrix
->rows
1077 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1079 if (hl_row
&& hl_row
->mode_line_p
)
1080 height
-= hl_row
->height
;
1082 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1085 /* With a very small font and a mode-line that's taller than
1086 default, we might end up with a negative height. */
1087 return max (0, height
);
1090 /* Return the window-relative coordinate of the left edge of display
1091 area AREA of window W. ANY_AREA means return the left edge of the
1092 whole window, to the right of the left fringe of W. */
1095 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1099 if (w
->pseudo_window_p
)
1102 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1104 if (area
== TEXT_AREA
)
1105 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1106 + window_box_width (w
, LEFT_MARGIN_AREA
));
1107 else if (area
== RIGHT_MARGIN_AREA
)
1108 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1109 + window_box_width (w
, LEFT_MARGIN_AREA
)
1110 + window_box_width (w
, TEXT_AREA
)
1111 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1113 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1114 else if (area
== LEFT_MARGIN_AREA
1115 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1116 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1122 /* Return the window-relative coordinate of the right edge of display
1123 area AREA of window W. ANY_AREA means return the right edge of the
1124 whole window, to the left of the right fringe of W. */
1127 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1129 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1132 /* Return the frame-relative coordinate of the left edge of display
1133 area AREA of window W. ANY_AREA means return the left edge of the
1134 whole window, to the right of the left fringe of W. */
1137 window_box_left (struct window
*w
, enum glyph_row_area area
)
1139 struct frame
*f
= XFRAME (w
->frame
);
1142 if (w
->pseudo_window_p
)
1143 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1145 x
= (WINDOW_LEFT_EDGE_X (w
)
1146 + window_box_left_offset (w
, area
));
1152 /* Return the frame-relative coordinate of the right edge of display
1153 area AREA of window W. ANY_AREA means return the right edge of the
1154 whole window, to the left of the right fringe of W. */
1157 window_box_right (struct window
*w
, enum glyph_row_area area
)
1159 return window_box_left (w
, area
) + window_box_width (w
, area
);
1162 /* Get the bounding box of the display area AREA of window W, without
1163 mode lines, in frame-relative coordinates. ANY_AREA means the
1164 whole window, not including the left and right fringes of
1165 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1166 coordinates of the upper-left corner of the box. Return in
1167 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1170 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1171 int *box_y
, int *box_width
, int *box_height
)
1174 *box_width
= window_box_width (w
, area
);
1176 *box_height
= window_box_height (w
);
1178 *box_x
= window_box_left (w
, area
);
1181 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1182 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1183 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1187 #ifdef HAVE_WINDOW_SYSTEM
1189 /* Get the bounding box of the display area AREA of window W, without
1190 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1191 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1192 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1193 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1197 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1198 int *bottom_right_x
, int *bottom_right_y
)
1200 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1201 bottom_right_x
, bottom_right_y
);
1202 *bottom_right_x
+= *top_left_x
;
1203 *bottom_right_y
+= *top_left_y
;
1206 #endif /* HAVE_WINDOW_SYSTEM */
1208 /***********************************************************************
1210 ***********************************************************************/
1212 /* Return the bottom y-position of the line the iterator IT is in.
1213 This can modify IT's settings. */
1216 line_bottom_y (struct it
*it
)
1218 int line_height
= it
->max_ascent
+ it
->max_descent
;
1219 int line_top_y
= it
->current_y
;
1221 if (line_height
== 0)
1224 line_height
= last_height
;
1225 else if (IT_CHARPOS (*it
) < ZV
)
1227 move_it_by_lines (it
, 1);
1228 line_height
= (it
->max_ascent
|| it
->max_descent
1229 ? it
->max_ascent
+ it
->max_descent
1234 struct glyph_row
*row
= it
->glyph_row
;
1236 /* Use the default character height. */
1237 it
->glyph_row
= NULL
;
1238 it
->what
= IT_CHARACTER
;
1241 PRODUCE_GLYPHS (it
);
1242 line_height
= it
->ascent
+ it
->descent
;
1243 it
->glyph_row
= row
;
1247 return line_top_y
+ line_height
;
1250 DEFUN ("line-pixel-height", Fline_pixel_height
,
1251 Sline_pixel_height
, 0, 0, 0,
1252 doc
: /* Return height in pixels of text line in the selected window.
1254 Value is the height in pixels of the line at point. */)
1259 struct window
*w
= XWINDOW (selected_window
);
1261 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1262 start_display (&it
, w
, pt
);
1263 it
.vpos
= it
.current_y
= 0;
1265 return make_number (line_bottom_y (&it
));
1268 /* Return the default pixel height of text lines in window W. The
1269 value is the canonical height of the W frame's default font, plus
1270 any extra space required by the line-spacing variable or frame
1273 Implementation note: this ignores any line-spacing text properties
1274 put on the newline characters. This is because those properties
1275 only affect the _screen_ line ending in the newline (i.e., in a
1276 continued line, only the last screen line will be affected), which
1277 means only a small number of lines in a buffer can ever use this
1278 feature. Since this function is used to compute the default pixel
1279 equivalent of text lines in a window, we can safely ignore those
1280 few lines. For the same reasons, we ignore the line-height
1283 default_line_pixel_height (struct window
*w
)
1285 struct frame
*f
= WINDOW_XFRAME (w
);
1286 int height
= FRAME_LINE_HEIGHT (f
);
1288 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1290 struct buffer
*b
= XBUFFER (w
->contents
);
1291 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1294 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1297 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1298 height
+= XFASTINT (val
);
1299 else if (FLOATP (val
))
1301 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1308 height
+= f
->extra_line_spacing
;
1314 /* Subroutine of pos_visible_p below. Extracts a display string, if
1315 any, from the display spec given as its argument. */
1317 string_from_display_spec (Lisp_Object spec
)
1321 while (CONSP (spec
))
1323 if (STRINGP (XCAR (spec
)))
1328 else if (VECTORP (spec
))
1332 for (i
= 0; i
< ASIZE (spec
); i
++)
1334 if (STRINGP (AREF (spec
, i
)))
1335 return AREF (spec
, i
);
1344 /* Limit insanely large values of W->hscroll on frame F to the largest
1345 value that will still prevent first_visible_x and last_visible_x of
1346 'struct it' from overflowing an int. */
1348 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1350 ptrdiff_t window_hscroll
= w
->hscroll
;
1351 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1352 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1354 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1355 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1357 return window_hscroll
;
1360 /* Return 1 if position CHARPOS is visible in window W.
1361 CHARPOS < 0 means return info about WINDOW_END position.
1362 If visible, set *X and *Y to pixel coordinates of top left corner.
1363 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1364 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1367 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1368 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1371 void *itdata
= bidi_shelve_cache ();
1372 struct text_pos top
;
1374 struct buffer
*old_buffer
= NULL
;
1376 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1379 if (XBUFFER (w
->contents
) != current_buffer
)
1381 old_buffer
= current_buffer
;
1382 set_buffer_internal_1 (XBUFFER (w
->contents
));
1385 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1386 /* Scrolling a minibuffer window via scroll bar when the echo area
1387 shows long text sometimes resets the minibuffer contents behind
1389 if (CHARPOS (top
) > ZV
)
1390 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1392 /* Compute exact mode line heights. */
1393 if (WINDOW_WANTS_MODELINE_P (w
))
1395 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1396 BVAR (current_buffer
, mode_line_format
));
1398 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1399 w
->header_line_height
1400 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1401 BVAR (current_buffer
, header_line_format
));
1403 start_display (&it
, w
, top
);
1404 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1405 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1408 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1409 && IT_CHARPOS (it
) >= charpos
)
1410 /* When scanning backwards under bidi iteration, move_it_to
1411 stops at or _before_ CHARPOS, because it stops at or to
1412 the _right_ of the character at CHARPOS. */
1413 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1414 && IT_CHARPOS (it
) <= charpos
)))
1416 /* We have reached CHARPOS, or passed it. How the call to
1417 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1418 or covered by a display property, move_it_to stops at the end
1419 of the invisible text, to the right of CHARPOS. (ii) If
1420 CHARPOS is in a display vector, move_it_to stops on its last
1422 int top_x
= it
.current_x
;
1423 int top_y
= it
.current_y
;
1424 /* Calling line_bottom_y may change it.method, it.position, etc. */
1425 enum it_method it_method
= it
.method
;
1426 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1427 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1429 if (top_y
< window_top_y
)
1430 visible_p
= bottom_y
> window_top_y
;
1431 else if (top_y
< it
.last_visible_y
)
1433 if (bottom_y
>= it
.last_visible_y
1434 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1435 && IT_CHARPOS (it
) < charpos
)
1437 /* When the last line of the window is scanned backwards
1438 under bidi iteration, we could be duped into thinking
1439 that we have passed CHARPOS, when in fact move_it_to
1440 simply stopped short of CHARPOS because it reached
1441 last_visible_y. To see if that's what happened, we call
1442 move_it_to again with a slightly larger vertical limit,
1443 and see if it actually moved vertically; if it did, we
1444 didn't really reach CHARPOS, which is beyond window end. */
1445 struct it save_it
= it
;
1446 /* Why 10? because we don't know how many canonical lines
1447 will the height of the next line(s) be. So we guess. */
1448 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1450 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1451 MOVE_TO_POS
| MOVE_TO_Y
);
1452 if (it
.current_y
> top_y
)
1459 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1461 /* We stopped on the last glyph of a display vector.
1462 Try and recompute. Hack alert! */
1463 if (charpos
< 2 || top
.charpos
>= charpos
)
1464 top_x
= it
.glyph_row
->x
;
1467 struct it it2
, it2_prev
;
1468 /* The idea is to get to the previous buffer
1469 position, consume the character there, and use
1470 the pixel coordinates we get after that. But if
1471 the previous buffer position is also displayed
1472 from a display vector, we need to consume all of
1473 the glyphs from that display vector. */
1474 start_display (&it2
, w
, top
);
1475 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1476 /* If we didn't get to CHARPOS - 1, there's some
1477 replacing display property at that position, and
1478 we stopped after it. That is exactly the place
1479 whose coordinates we want. */
1480 if (IT_CHARPOS (it2
) != charpos
- 1)
1484 /* Iterate until we get out of the display
1485 vector that displays the character at
1488 get_next_display_element (&it2
);
1489 PRODUCE_GLYPHS (&it2
);
1491 set_iterator_to_next (&it2
, 1);
1492 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1493 && IT_CHARPOS (it2
) < charpos
);
1495 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1496 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1497 top_x
= it
.glyph_row
->x
;
1500 top_x
= it2_prev
.current_x
;
1501 top_y
= it2_prev
.current_y
;
1505 else if (IT_CHARPOS (it
) != charpos
)
1507 Lisp_Object cpos
= make_number (charpos
);
1508 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1509 Lisp_Object string
= string_from_display_spec (spec
);
1510 struct text_pos tpos
;
1511 int replacing_spec_p
;
1512 bool newline_in_string
1514 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1516 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1519 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1520 charpos
, FRAME_WINDOW_P (it
.f
)));
1521 /* The tricky code below is needed because there's a
1522 discrepancy between move_it_to and how we set cursor
1523 when PT is at the beginning of a portion of text
1524 covered by a display property or an overlay with a
1525 display property, or the display line ends in a
1526 newline from a display string. move_it_to will stop
1527 _after_ such display strings, whereas
1528 set_cursor_from_row conspires with cursor_row_p to
1529 place the cursor on the first glyph produced from the
1532 /* We have overshoot PT because it is covered by a
1533 display property that replaces the text it covers.
1534 If the string includes embedded newlines, we are also
1535 in the wrong display line. Backtrack to the correct
1536 line, where the display property begins. */
1537 if (replacing_spec_p
)
1539 Lisp_Object startpos
, endpos
;
1540 EMACS_INT start
, end
;
1544 /* Find the first and the last buffer positions
1545 covered by the display string. */
1547 Fnext_single_char_property_change (cpos
, Qdisplay
,
1550 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1552 start
= XFASTINT (startpos
);
1553 end
= XFASTINT (endpos
);
1554 /* Move to the last buffer position before the
1555 display property. */
1556 start_display (&it3
, w
, top
);
1557 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1558 /* Move forward one more line if the position before
1559 the display string is a newline or if it is the
1560 rightmost character on a line that is
1561 continued or word-wrapped. */
1562 if (it3
.method
== GET_FROM_BUFFER
1564 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1565 move_it_by_lines (&it3
, 1);
1566 else if (move_it_in_display_line_to (&it3
, -1,
1570 == MOVE_LINE_CONTINUED
)
1572 move_it_by_lines (&it3
, 1);
1573 /* When we are under word-wrap, the #$@%!
1574 move_it_by_lines moves 2 lines, so we need to
1576 if (it3
.line_wrap
== WORD_WRAP
)
1577 move_it_by_lines (&it3
, -1);
1580 /* Record the vertical coordinate of the display
1581 line where we wound up. */
1582 top_y
= it3
.current_y
;
1585 /* When characters are reordered for display,
1586 the character displayed to the left of the
1587 display string could be _after_ the display
1588 property in the logical order. Use the
1589 smallest vertical position of these two. */
1590 start_display (&it3
, w
, top
);
1591 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1592 if (it3
.current_y
< top_y
)
1593 top_y
= it3
.current_y
;
1595 /* Move from the top of the window to the beginning
1596 of the display line where the display string
1598 start_display (&it3
, w
, top
);
1599 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1600 /* If it3_moved stays zero after the 'while' loop
1601 below, that means we already were at a newline
1602 before the loop (e.g., the display string begins
1603 with a newline), so we don't need to (and cannot)
1604 inspect the glyphs of it3.glyph_row, because
1605 PRODUCE_GLYPHS will not produce anything for a
1606 newline, and thus it3.glyph_row stays at its
1607 stale content it got at top of the window. */
1609 /* Finally, advance the iterator until we hit the
1610 first display element whose character position is
1611 CHARPOS, or until the first newline from the
1612 display string, which signals the end of the
1614 while (get_next_display_element (&it3
))
1616 PRODUCE_GLYPHS (&it3
);
1617 if (IT_CHARPOS (it3
) == charpos
1618 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1621 set_iterator_to_next (&it3
, 0);
1623 top_x
= it3
.current_x
- it3
.pixel_width
;
1624 /* Normally, we would exit the above loop because we
1625 found the display element whose character
1626 position is CHARPOS. For the contingency that we
1627 didn't, and stopped at the first newline from the
1628 display string, move back over the glyphs
1629 produced from the string, until we find the
1630 rightmost glyph not from the string. */
1632 && newline_in_string
1633 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1635 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1636 + it3
.glyph_row
->used
[TEXT_AREA
];
1638 while (EQ ((g
- 1)->object
, string
))
1641 top_x
-= g
->pixel_width
;
1643 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1644 + it3
.glyph_row
->used
[TEXT_AREA
]);
1650 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1651 *rtop
= max (0, window_top_y
- top_y
);
1652 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1653 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1654 - max (top_y
, window_top_y
)));
1660 /* We were asked to provide info about WINDOW_END. */
1662 void *it2data
= NULL
;
1664 SAVE_IT (it2
, it
, it2data
);
1665 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1666 move_it_by_lines (&it
, 1);
1667 if (charpos
< IT_CHARPOS (it
)
1668 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1671 RESTORE_IT (&it2
, &it2
, it2data
);
1672 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1674 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1675 *rtop
= max (0, -it2
.current_y
);
1676 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1677 - it
.last_visible_y
));
1678 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1680 - max (it2
.current_y
,
1681 WINDOW_HEADER_LINE_HEIGHT (w
))));
1685 bidi_unshelve_cache (it2data
, 1);
1687 bidi_unshelve_cache (itdata
, 0);
1690 set_buffer_internal_1 (old_buffer
);
1692 if (visible_p
&& w
->hscroll
> 0)
1694 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1695 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1698 /* Debugging code. */
1700 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1701 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1703 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1710 /* Return the next character from STR. Return in *LEN the length of
1711 the character. This is like STRING_CHAR_AND_LENGTH but never
1712 returns an invalid character. If we find one, we return a `?', but
1713 with the length of the invalid character. */
1716 string_char_and_length (const unsigned char *str
, int *len
)
1720 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1721 if (!CHAR_VALID_P (c
))
1722 /* We may not change the length here because other places in Emacs
1723 don't use this function, i.e. they silently accept invalid
1732 /* Given a position POS containing a valid character and byte position
1733 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1735 static struct text_pos
1736 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1738 eassert (STRINGP (string
) && nchars
>= 0);
1740 if (STRING_MULTIBYTE (string
))
1742 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1747 string_char_and_length (p
, &len
);
1750 BYTEPOS (pos
) += len
;
1754 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1760 /* Value is the text position, i.e. character and byte position,
1761 for character position CHARPOS in STRING. */
1763 static struct text_pos
1764 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1766 struct text_pos pos
;
1767 eassert (STRINGP (string
));
1768 eassert (charpos
>= 0);
1769 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1774 /* Value is a text position, i.e. character and byte position, for
1775 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1776 means recognize multibyte characters. */
1778 static struct text_pos
1779 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1781 struct text_pos pos
;
1783 eassert (s
!= NULL
);
1784 eassert (charpos
>= 0);
1790 SET_TEXT_POS (pos
, 0, 0);
1793 string_char_and_length ((const unsigned char *) s
, &len
);
1796 BYTEPOS (pos
) += len
;
1800 SET_TEXT_POS (pos
, charpos
, charpos
);
1806 /* Value is the number of characters in C string S. MULTIBYTE_P
1807 non-zero means recognize multibyte characters. */
1810 number_of_chars (const char *s
, bool multibyte_p
)
1816 ptrdiff_t rest
= strlen (s
);
1818 const unsigned char *p
= (const unsigned char *) s
;
1820 for (nchars
= 0; rest
> 0; ++nchars
)
1822 string_char_and_length (p
, &len
);
1823 rest
-= len
, p
+= len
;
1827 nchars
= strlen (s
);
1833 /* Compute byte position NEWPOS->bytepos corresponding to
1834 NEWPOS->charpos. POS is a known position in string STRING.
1835 NEWPOS->charpos must be >= POS.charpos. */
1838 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1840 eassert (STRINGP (string
));
1841 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1843 if (STRING_MULTIBYTE (string
))
1844 *newpos
= string_pos_nchars_ahead (pos
, string
,
1845 CHARPOS (*newpos
) - CHARPOS (pos
));
1847 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1851 Return an estimation of the pixel height of mode or header lines on
1852 frame F. FACE_ID specifies what line's height to estimate. */
1855 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1857 #ifdef HAVE_WINDOW_SYSTEM
1858 if (FRAME_WINDOW_P (f
))
1860 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1862 /* This function is called so early when Emacs starts that the face
1863 cache and mode line face are not yet initialized. */
1864 if (FRAME_FACE_CACHE (f
))
1866 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1870 height
= FONT_HEIGHT (face
->font
);
1871 if (face
->box_line_width
> 0)
1872 height
+= 2 * face
->box_line_width
;
1883 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1884 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1885 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1886 not force the value into range. */
1889 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1890 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1893 #ifdef HAVE_WINDOW_SYSTEM
1894 if (FRAME_WINDOW_P (f
))
1896 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1897 even for negative values. */
1899 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1901 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1903 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1904 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1907 STORE_NATIVE_RECT (*bounds
,
1908 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1909 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1910 FRAME_COLUMN_WIDTH (f
) - 1,
1911 FRAME_LINE_HEIGHT (f
) - 1);
1917 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1918 pix_x
= FRAME_TOTAL_COLS (f
);
1922 else if (pix_y
> FRAME_LINES (f
))
1923 pix_y
= FRAME_LINES (f
);
1933 /* Find the glyph under window-relative coordinates X/Y in window W.
1934 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1935 strings. Return in *HPOS and *VPOS the row and column number of
1936 the glyph found. Return in *AREA the glyph area containing X.
1937 Value is a pointer to the glyph found or null if X/Y is not on
1938 text, or we can't tell because W's current matrix is not up to
1941 static struct glyph
*
1942 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1943 int *dx
, int *dy
, int *area
)
1945 struct glyph
*glyph
, *end
;
1946 struct glyph_row
*row
= NULL
;
1949 /* Find row containing Y. Give up if some row is not enabled. */
1950 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1952 row
= MATRIX_ROW (w
->current_matrix
, i
);
1953 if (!row
->enabled_p
)
1955 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1962 /* Give up if Y is not in the window. */
1963 if (i
== w
->current_matrix
->nrows
)
1966 /* Get the glyph area containing X. */
1967 if (w
->pseudo_window_p
)
1974 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1976 *area
= LEFT_MARGIN_AREA
;
1977 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1979 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1982 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1986 *area
= RIGHT_MARGIN_AREA
;
1987 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1991 /* Find glyph containing X. */
1992 glyph
= row
->glyphs
[*area
];
1993 end
= glyph
+ row
->used
[*area
];
1995 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1997 x
-= glyph
->pixel_width
;
2007 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
2010 *hpos
= glyph
- row
->glyphs
[*area
];
2014 /* Convert frame-relative x/y to coordinates relative to window W.
2015 Takes pseudo-windows into account. */
2018 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
2020 if (w
->pseudo_window_p
)
2022 /* A pseudo-window is always full-width, and starts at the
2023 left edge of the frame, plus a frame border. */
2024 struct frame
*f
= XFRAME (w
->frame
);
2025 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
2026 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2030 *x
-= WINDOW_LEFT_EDGE_X (w
);
2031 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2035 #ifdef HAVE_WINDOW_SYSTEM
2038 Return in RECTS[] at most N clipping rectangles for glyph string S.
2039 Return the number of stored rectangles. */
2042 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2049 if (s
->row
->full_width_p
)
2051 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2052 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2053 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
2055 /* Unless displaying a mode or menu bar line, which are always
2056 fully visible, clip to the visible part of the row. */
2057 if (s
->w
->pseudo_window_p
)
2058 r
.height
= s
->row
->visible_height
;
2060 r
.height
= s
->height
;
2064 /* This is a text line that may be partially visible. */
2065 r
.x
= window_box_left (s
->w
, s
->area
);
2066 r
.width
= window_box_width (s
->w
, s
->area
);
2067 r
.height
= s
->row
->visible_height
;
2071 if (r
.x
< s
->clip_head
->x
)
2073 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2074 r
.width
-= s
->clip_head
->x
- r
.x
;
2077 r
.x
= s
->clip_head
->x
;
2080 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2082 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2083 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2088 /* If S draws overlapping rows, it's sufficient to use the top and
2089 bottom of the window for clipping because this glyph string
2090 intentionally draws over other lines. */
2091 if (s
->for_overlaps
)
2093 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2094 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2096 /* Alas, the above simple strategy does not work for the
2097 environments with anti-aliased text: if the same text is
2098 drawn onto the same place multiple times, it gets thicker.
2099 If the overlap we are processing is for the erased cursor, we
2100 take the intersection with the rectangle of the cursor. */
2101 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2103 XRectangle rc
, r_save
= r
;
2105 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2106 rc
.y
= s
->w
->phys_cursor
.y
;
2107 rc
.width
= s
->w
->phys_cursor_width
;
2108 rc
.height
= s
->w
->phys_cursor_height
;
2110 x_intersect_rectangles (&r_save
, &rc
, &r
);
2115 /* Don't use S->y for clipping because it doesn't take partially
2116 visible lines into account. For example, it can be negative for
2117 partially visible lines at the top of a window. */
2118 if (!s
->row
->full_width_p
2119 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2120 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2122 r
.y
= max (0, s
->row
->y
);
2125 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2127 /* If drawing the cursor, don't let glyph draw outside its
2128 advertised boundaries. Cleartype does this under some circumstances. */
2129 if (s
->hl
== DRAW_CURSOR
)
2131 struct glyph
*glyph
= s
->first_glyph
;
2136 r
.width
-= s
->x
- r
.x
;
2139 r
.width
= min (r
.width
, glyph
->pixel_width
);
2141 /* If r.y is below window bottom, ensure that we still see a cursor. */
2142 height
= min (glyph
->ascent
+ glyph
->descent
,
2143 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2144 max_y
= window_text_bottom_y (s
->w
) - height
;
2145 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2146 if (s
->ybase
- glyph
->ascent
> max_y
)
2153 /* Don't draw cursor glyph taller than our actual glyph. */
2154 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2155 if (height
< r
.height
)
2157 max_y
= r
.y
+ r
.height
;
2158 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2159 r
.height
= min (max_y
- r
.y
, height
);
2166 XRectangle r_save
= r
;
2168 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2172 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2173 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2175 #ifdef CONVERT_FROM_XRECT
2176 CONVERT_FROM_XRECT (r
, *rects
);
2184 /* If we are processing overlapping and allowed to return
2185 multiple clipping rectangles, we exclude the row of the glyph
2186 string from the clipping rectangle. This is to avoid drawing
2187 the same text on the environment with anti-aliasing. */
2188 #ifdef CONVERT_FROM_XRECT
2191 XRectangle
*rs
= rects
;
2193 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2195 if (s
->for_overlaps
& OVERLAPS_PRED
)
2198 if (r
.y
+ r
.height
> row_y
)
2201 rs
[i
].height
= row_y
- r
.y
;
2207 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2210 if (r
.y
< row_y
+ s
->row
->visible_height
)
2212 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2214 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2215 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2224 #ifdef CONVERT_FROM_XRECT
2225 for (i
= 0; i
< n
; i
++)
2226 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2233 Return in *NR the clipping rectangle for glyph string S. */
2236 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2238 get_glyph_string_clip_rects (s
, nr
, 1);
2243 Return the position and height of the phys cursor in window W.
2244 Set w->phys_cursor_width to width of phys cursor.
2248 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2249 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2251 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2252 int x
, y
, wd
, h
, h0
, y0
;
2254 /* Compute the width of the rectangle to draw. If on a stretch
2255 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2256 rectangle as wide as the glyph, but use a canonical character
2258 wd
= glyph
->pixel_width
- 1;
2259 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2263 x
= w
->phys_cursor
.x
;
2270 if (glyph
->type
== STRETCH_GLYPH
2271 && !x_stretch_cursor_p
)
2272 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2273 w
->phys_cursor_width
= wd
;
2275 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2277 /* If y is below window bottom, ensure that we still see a cursor. */
2278 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2280 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2281 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2283 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2286 h
= max (h
- (y0
- y
) + 1, h0
);
2291 y0
= window_text_bottom_y (w
) - h0
;
2299 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2300 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2305 * Remember which glyph the mouse is over.
2309 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2313 struct glyph_row
*r
, *gr
, *end_row
;
2314 enum window_part part
;
2315 enum glyph_row_area area
;
2316 int x
, y
, width
, height
;
2318 /* Try to determine frame pixel position and size of the glyph under
2319 frame pixel coordinates X/Y on frame F. */
2321 if (!f
->glyphs_initialized_p
2322 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2325 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2326 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2330 w
= XWINDOW (window
);
2331 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2332 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2334 x
= window_relative_x_coord (w
, part
, gx
);
2335 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2337 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2338 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2340 if (w
->pseudo_window_p
)
2343 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2349 case ON_LEFT_MARGIN
:
2350 area
= LEFT_MARGIN_AREA
;
2353 case ON_RIGHT_MARGIN
:
2354 area
= RIGHT_MARGIN_AREA
;
2357 case ON_HEADER_LINE
:
2359 gr
= (part
== ON_HEADER_LINE
2360 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2361 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2364 goto text_glyph_row_found
;
2371 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2372 if (r
->y
+ r
->height
> y
)
2378 text_glyph_row_found
:
2381 struct glyph
*g
= gr
->glyphs
[area
];
2382 struct glyph
*end
= g
+ gr
->used
[area
];
2384 height
= gr
->height
;
2385 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2386 if (gx
+ g
->pixel_width
> x
)
2391 if (g
->type
== IMAGE_GLYPH
)
2393 /* Don't remember when mouse is over image, as
2394 image may have hot-spots. */
2395 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2398 width
= g
->pixel_width
;
2402 /* Use nominal char spacing at end of line. */
2404 gx
+= (x
/ width
) * width
;
2407 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2408 gx
+= window_box_left_offset (w
, area
);
2412 /* Use nominal line height at end of window. */
2413 gx
= (x
/ width
) * width
;
2415 gy
+= (y
/ height
) * height
;
2419 case ON_LEFT_FRINGE
:
2420 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2421 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2422 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2423 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2426 case ON_RIGHT_FRINGE
:
2427 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2428 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2429 : window_box_right_offset (w
, TEXT_AREA
));
2430 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2434 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2436 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2437 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2438 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2440 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2444 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2445 if (r
->y
+ r
->height
> y
)
2452 height
= gr
->height
;
2455 /* Use nominal line height at end of window. */
2457 gy
+= (y
/ height
) * height
;
2464 /* If there is no glyph under the mouse, then we divide the screen
2465 into a grid of the smallest glyph in the frame, and use that
2468 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2469 round down even for negative values. */
2475 gx
= (gx
/ width
) * width
;
2476 gy
= (gy
/ height
) * height
;
2481 gx
+= WINDOW_LEFT_EDGE_X (w
);
2482 gy
+= WINDOW_TOP_EDGE_Y (w
);
2485 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2487 /* Visible feedback for debugging. */
2490 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2491 f
->output_data
.x
->normal_gc
,
2492 gx
, gy
, width
, height
);
2498 #endif /* HAVE_WINDOW_SYSTEM */
2501 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2504 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2505 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2507 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2510 /***********************************************************************
2511 Lisp form evaluation
2512 ***********************************************************************/
2514 /* Error handler for safe_eval and safe_call. */
2517 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2519 add_to_log ("Error during redisplay: %S signaled %S",
2520 Flist (nargs
, args
), arg
);
2524 /* Call function FUNC with the rest of NARGS - 1 arguments
2525 following. Return the result, or nil if something went
2526 wrong. Prevent redisplay during the evaluation. */
2529 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2533 if (inhibit_eval_during_redisplay
)
2539 ptrdiff_t count
= SPECPDL_INDEX ();
2540 struct gcpro gcpro1
;
2541 Lisp_Object
*args
= alloca (nargs
* word_size
);
2544 va_start (ap
, func
);
2545 for (i
= 1; i
< nargs
; i
++)
2546 args
[i
] = va_arg (ap
, Lisp_Object
);
2550 gcpro1
.nvars
= nargs
;
2551 specbind (Qinhibit_redisplay
, Qt
);
2552 /* Use Qt to ensure debugger does not run,
2553 so there is no possibility of wanting to redisplay. */
2554 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2557 val
= unbind_to (count
, val
);
2564 /* Call function FN with one argument ARG.
2565 Return the result, or nil if something went wrong. */
2568 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2570 return safe_call (2, fn
, arg
);
2573 static Lisp_Object Qeval
;
2576 safe_eval (Lisp_Object sexpr
)
2578 return safe_call1 (Qeval
, sexpr
);
2581 /* Call function FN with two arguments ARG1 and ARG2.
2582 Return the result, or nil if something went wrong. */
2585 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2587 return safe_call (3, fn
, arg1
, arg2
);
2592 /***********************************************************************
2594 ***********************************************************************/
2598 /* Define CHECK_IT to perform sanity checks on iterators.
2599 This is for debugging. It is too slow to do unconditionally. */
2602 check_it (struct it
*it
)
2604 if (it
->method
== GET_FROM_STRING
)
2606 eassert (STRINGP (it
->string
));
2607 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2611 eassert (IT_STRING_CHARPOS (*it
) < 0);
2612 if (it
->method
== GET_FROM_BUFFER
)
2614 /* Check that character and byte positions agree. */
2615 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2620 eassert (it
->current
.dpvec_index
>= 0);
2622 eassert (it
->current
.dpvec_index
< 0);
2625 #define CHECK_IT(IT) check_it ((IT))
2629 #define CHECK_IT(IT) (void) 0
2634 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2636 /* Check that the window end of window W is what we expect it
2637 to be---the last row in the current matrix displaying text. */
2640 check_window_end (struct window
*w
)
2642 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2644 struct glyph_row
*row
;
2645 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2647 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2648 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2652 #define CHECK_WINDOW_END(W) check_window_end ((W))
2656 #define CHECK_WINDOW_END(W) (void) 0
2658 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2660 /***********************************************************************
2661 Iterator initialization
2662 ***********************************************************************/
2664 /* Initialize IT for displaying current_buffer in window W, starting
2665 at character position CHARPOS. CHARPOS < 0 means that no buffer
2666 position is specified which is useful when the iterator is assigned
2667 a position later. BYTEPOS is the byte position corresponding to
2670 If ROW is not null, calls to produce_glyphs with IT as parameter
2671 will produce glyphs in that row.
2673 BASE_FACE_ID is the id of a base face to use. It must be one of
2674 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2675 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2676 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2678 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2679 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2680 will be initialized to use the corresponding mode line glyph row of
2681 the desired matrix of W. */
2684 init_iterator (struct it
*it
, struct window
*w
,
2685 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2686 struct glyph_row
*row
, enum face_id base_face_id
)
2688 enum face_id remapped_base_face_id
= base_face_id
;
2690 /* Some precondition checks. */
2691 eassert (w
!= NULL
&& it
!= NULL
);
2692 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2695 /* If face attributes have been changed since the last redisplay,
2696 free realized faces now because they depend on face definitions
2697 that might have changed. Don't free faces while there might be
2698 desired matrices pending which reference these faces. */
2699 if (face_change_count
&& !inhibit_free_realized_faces
)
2701 face_change_count
= 0;
2702 free_all_realized_faces (Qnil
);
2705 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2706 if (! NILP (Vface_remapping_alist
))
2707 remapped_base_face_id
2708 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2710 /* Use one of the mode line rows of W's desired matrix if
2714 if (base_face_id
== MODE_LINE_FACE_ID
2715 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2716 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2717 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2718 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2722 memset (it
, 0, sizeof *it
);
2723 it
->current
.overlay_string_index
= -1;
2724 it
->current
.dpvec_index
= -1;
2725 it
->base_face_id
= remapped_base_face_id
;
2727 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2728 it
->paragraph_embedding
= L2R
;
2729 it
->bidi_it
.string
.lstring
= Qnil
;
2730 it
->bidi_it
.string
.s
= NULL
;
2731 it
->bidi_it
.string
.bufpos
= 0;
2734 /* The window in which we iterate over current_buffer: */
2735 XSETWINDOW (it
->window
, w
);
2737 it
->f
= XFRAME (w
->frame
);
2741 /* Extra space between lines (on window systems only). */
2742 if (base_face_id
== DEFAULT_FACE_ID
2743 && FRAME_WINDOW_P (it
->f
))
2745 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2746 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2747 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2748 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2749 * FRAME_LINE_HEIGHT (it
->f
));
2750 else if (it
->f
->extra_line_spacing
> 0)
2751 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2752 it
->max_extra_line_spacing
= 0;
2755 /* If realized faces have been removed, e.g. because of face
2756 attribute changes of named faces, recompute them. When running
2757 in batch mode, the face cache of the initial frame is null. If
2758 we happen to get called, make a dummy face cache. */
2759 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2760 init_frame_faces (it
->f
);
2761 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2762 recompute_basic_faces (it
->f
);
2764 /* Current value of the `slice', `space-width', and 'height' properties. */
2765 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2766 it
->space_width
= Qnil
;
2767 it
->font_height
= Qnil
;
2768 it
->override_ascent
= -1;
2770 /* Are control characters displayed as `^C'? */
2771 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2773 /* -1 means everything between a CR and the following line end
2774 is invisible. >0 means lines indented more than this value are
2776 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2778 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2780 : (!NILP (BVAR (current_buffer
, selective_display
))
2782 it
->selective_display_ellipsis_p
2783 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2785 /* Display table to use. */
2786 it
->dp
= window_display_table (w
);
2788 /* Are multibyte characters enabled in current_buffer? */
2789 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2791 /* Get the position at which the redisplay_end_trigger hook should
2792 be run, if it is to be run at all. */
2793 if (MARKERP (w
->redisplay_end_trigger
)
2794 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2795 it
->redisplay_end_trigger_charpos
2796 = marker_position (w
->redisplay_end_trigger
);
2797 else if (INTEGERP (w
->redisplay_end_trigger
))
2798 it
->redisplay_end_trigger_charpos
=
2799 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2801 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2803 /* Are lines in the display truncated? */
2804 if (base_face_id
!= DEFAULT_FACE_ID
2806 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2807 && ((!NILP (Vtruncate_partial_width_windows
)
2808 && !INTEGERP (Vtruncate_partial_width_windows
))
2809 || (INTEGERP (Vtruncate_partial_width_windows
)
2810 && (WINDOW_TOTAL_COLS (it
->w
)
2811 < XINT (Vtruncate_partial_width_windows
))))))
2812 it
->line_wrap
= TRUNCATE
;
2813 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2814 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2815 ? WINDOW_WRAP
: WORD_WRAP
;
2817 it
->line_wrap
= TRUNCATE
;
2819 /* Get dimensions of truncation and continuation glyphs. These are
2820 displayed as fringe bitmaps under X, but we need them for such
2821 frames when the fringes are turned off. But leave the dimensions
2822 zero for tooltip frames, as these glyphs look ugly there and also
2823 sabotage calculations of tooltip dimensions in x-show-tip. */
2824 #ifdef HAVE_WINDOW_SYSTEM
2825 if (!(FRAME_WINDOW_P (it
->f
)
2826 && FRAMEP (tip_frame
)
2827 && it
->f
== XFRAME (tip_frame
)))
2830 if (it
->line_wrap
== TRUNCATE
)
2832 /* We will need the truncation glyph. */
2833 eassert (it
->glyph_row
== NULL
);
2834 produce_special_glyphs (it
, IT_TRUNCATION
);
2835 it
->truncation_pixel_width
= it
->pixel_width
;
2839 /* We will need the continuation glyph. */
2840 eassert (it
->glyph_row
== NULL
);
2841 produce_special_glyphs (it
, IT_CONTINUATION
);
2842 it
->continuation_pixel_width
= it
->pixel_width
;
2846 /* Reset these values to zero because the produce_special_glyphs
2847 above has changed them. */
2848 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2849 it
->phys_ascent
= it
->phys_descent
= 0;
2851 /* Set this after getting the dimensions of truncation and
2852 continuation glyphs, so that we don't produce glyphs when calling
2853 produce_special_glyphs, above. */
2854 it
->glyph_row
= row
;
2855 it
->area
= TEXT_AREA
;
2857 /* Forget any previous info about this row being reversed. */
2859 it
->glyph_row
->reversed_p
= 0;
2861 /* Get the dimensions of the display area. The display area
2862 consists of the visible window area plus a horizontally scrolled
2863 part to the left of the window. All x-values are relative to the
2864 start of this total display area. */
2865 if (base_face_id
!= DEFAULT_FACE_ID
)
2867 /* Mode lines, menu bar in terminal frames. */
2868 it
->first_visible_x
= 0;
2869 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2874 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2875 it
->last_visible_x
= (it
->first_visible_x
2876 + window_box_width (w
, TEXT_AREA
));
2878 /* If we truncate lines, leave room for the truncation glyph(s) at
2879 the right margin. Otherwise, leave room for the continuation
2880 glyph(s). Done only if the window has no fringes. Since we
2881 don't know at this point whether there will be any R2L lines in
2882 the window, we reserve space for truncation/continuation glyphs
2883 even if only one of the fringes is absent. */
2884 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2885 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2887 if (it
->line_wrap
== TRUNCATE
)
2888 it
->last_visible_x
-= it
->truncation_pixel_width
;
2890 it
->last_visible_x
-= it
->continuation_pixel_width
;
2893 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2894 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2897 /* Leave room for a border glyph. */
2898 if (!FRAME_WINDOW_P (it
->f
)
2899 && !WINDOW_RIGHTMOST_P (it
->w
))
2900 it
->last_visible_x
-= 1;
2902 it
->last_visible_y
= window_text_bottom_y (w
);
2904 /* For mode lines and alike, arrange for the first glyph having a
2905 left box line if the face specifies a box. */
2906 if (base_face_id
!= DEFAULT_FACE_ID
)
2910 it
->face_id
= remapped_base_face_id
;
2912 /* If we have a boxed mode line, make the first character appear
2913 with a left box line. */
2914 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2915 if (face
->box
!= FACE_NO_BOX
)
2916 it
->start_of_box_run_p
= true;
2919 /* If a buffer position was specified, set the iterator there,
2920 getting overlays and face properties from that position. */
2921 if (charpos
>= BUF_BEG (current_buffer
))
2923 it
->end_charpos
= ZV
;
2924 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2925 IT_CHARPOS (*it
) = charpos
;
2926 IT_BYTEPOS (*it
) = bytepos
;
2928 /* We will rely on `reseat' to set this up properly, via
2929 handle_face_prop. */
2930 it
->face_id
= it
->base_face_id
;
2932 it
->start
= it
->current
;
2933 /* Do we need to reorder bidirectional text? Not if this is a
2934 unibyte buffer: by definition, none of the single-byte
2935 characters are strong R2L, so no reordering is needed. And
2936 bidi.c doesn't support unibyte buffers anyway. Also, don't
2937 reorder while we are loading loadup.el, since the tables of
2938 character properties needed for reordering are not yet
2942 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2945 /* If we are to reorder bidirectional text, init the bidi
2949 /* Note the paragraph direction that this buffer wants to
2951 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2953 it
->paragraph_embedding
= L2R
;
2954 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2956 it
->paragraph_embedding
= R2L
;
2958 it
->paragraph_embedding
= NEUTRAL_DIR
;
2959 bidi_unshelve_cache (NULL
, 0);
2960 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2964 /* Compute faces etc. */
2965 reseat (it
, it
->current
.pos
, 1);
2972 /* Initialize IT for the display of window W with window start POS. */
2975 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2977 struct glyph_row
*row
;
2978 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2980 row
= w
->desired_matrix
->rows
+ first_vpos
;
2981 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2982 it
->first_vpos
= first_vpos
;
2984 /* Don't reseat to previous visible line start if current start
2985 position is in a string or image. */
2986 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2988 int start_at_line_beg_p
;
2989 int first_y
= it
->current_y
;
2991 /* If window start is not at a line start, skip forward to POS to
2992 get the correct continuation lines width. */
2993 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2994 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2995 if (!start_at_line_beg_p
)
2999 reseat_at_previous_visible_line_start (it
);
3000 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3002 new_x
= it
->current_x
+ it
->pixel_width
;
3004 /* If lines are continued, this line may end in the middle
3005 of a multi-glyph character (e.g. a control character
3006 displayed as \003, or in the middle of an overlay
3007 string). In this case move_it_to above will not have
3008 taken us to the start of the continuation line but to the
3009 end of the continued line. */
3010 if (it
->current_x
> 0
3011 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3012 && (/* And glyph doesn't fit on the line. */
3013 new_x
> it
->last_visible_x
3014 /* Or it fits exactly and we're on a window
3016 || (new_x
== it
->last_visible_x
3017 && FRAME_WINDOW_P (it
->f
)
3018 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3019 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3020 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3022 if ((it
->current
.dpvec_index
>= 0
3023 || it
->current
.overlay_string_index
>= 0)
3024 /* If we are on a newline from a display vector or
3025 overlay string, then we are already at the end of
3026 a screen line; no need to go to the next line in
3027 that case, as this line is not really continued.
3028 (If we do go to the next line, C-e will not DTRT.) */
3031 set_iterator_to_next (it
, 1);
3032 move_it_in_display_line_to (it
, -1, -1, 0);
3035 it
->continuation_lines_width
+= it
->current_x
;
3037 /* If the character at POS is displayed via a display
3038 vector, move_it_to above stops at the final glyph of
3039 IT->dpvec. To make the caller redisplay that character
3040 again (a.k.a. start at POS), we need to reset the
3041 dpvec_index to the beginning of IT->dpvec. */
3042 else if (it
->current
.dpvec_index
>= 0)
3043 it
->current
.dpvec_index
= 0;
3045 /* We're starting a new display line, not affected by the
3046 height of the continued line, so clear the appropriate
3047 fields in the iterator structure. */
3048 it
->max_ascent
= it
->max_descent
= 0;
3049 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3051 it
->current_y
= first_y
;
3053 it
->current_x
= it
->hpos
= 0;
3059 /* Return 1 if POS is a position in ellipses displayed for invisible
3060 text. W is the window we display, for text property lookup. */
3063 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3065 Lisp_Object prop
, window
;
3067 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3069 /* If POS specifies a position in a display vector, this might
3070 be for an ellipsis displayed for invisible text. We won't
3071 get the iterator set up for delivering that ellipsis unless
3072 we make sure that it gets aware of the invisible text. */
3073 if (pos
->dpvec_index
>= 0
3074 && pos
->overlay_string_index
< 0
3075 && CHARPOS (pos
->string_pos
) < 0
3077 && (XSETWINDOW (window
, w
),
3078 prop
= Fget_char_property (make_number (charpos
),
3079 Qinvisible
, window
),
3080 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3082 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3084 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3091 /* Initialize IT for stepping through current_buffer in window W,
3092 starting at position POS that includes overlay string and display
3093 vector/ control character translation position information. Value
3094 is zero if there are overlay strings with newlines at POS. */
3097 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3099 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3100 int i
, overlay_strings_with_newlines
= 0;
3102 /* If POS specifies a position in a display vector, this might
3103 be for an ellipsis displayed for invisible text. We won't
3104 get the iterator set up for delivering that ellipsis unless
3105 we make sure that it gets aware of the invisible text. */
3106 if (in_ellipses_for_invisible_text_p (pos
, w
))
3112 /* Keep in mind: the call to reseat in init_iterator skips invisible
3113 text, so we might end up at a position different from POS. This
3114 is only a problem when POS is a row start after a newline and an
3115 overlay starts there with an after-string, and the overlay has an
3116 invisible property. Since we don't skip invisible text in
3117 display_line and elsewhere immediately after consuming the
3118 newline before the row start, such a POS will not be in a string,
3119 but the call to init_iterator below will move us to the
3121 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3123 /* This only scans the current chunk -- it should scan all chunks.
3124 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3125 to 16 in 22.1 to make this a lesser problem. */
3126 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3128 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3129 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3131 while (s
< e
&& *s
!= '\n')
3136 overlay_strings_with_newlines
= 1;
3141 /* If position is within an overlay string, set up IT to the right
3143 if (pos
->overlay_string_index
>= 0)
3147 /* If the first overlay string happens to have a `display'
3148 property for an image, the iterator will be set up for that
3149 image, and we have to undo that setup first before we can
3150 correct the overlay string index. */
3151 if (it
->method
== GET_FROM_IMAGE
)
3154 /* We already have the first chunk of overlay strings in
3155 IT->overlay_strings. Load more until the one for
3156 pos->overlay_string_index is in IT->overlay_strings. */
3157 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3159 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3160 it
->current
.overlay_string_index
= 0;
3163 load_overlay_strings (it
, 0);
3164 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3168 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3169 relative_index
= (it
->current
.overlay_string_index
3170 % OVERLAY_STRING_CHUNK_SIZE
);
3171 it
->string
= it
->overlay_strings
[relative_index
];
3172 eassert (STRINGP (it
->string
));
3173 it
->current
.string_pos
= pos
->string_pos
;
3174 it
->method
= GET_FROM_STRING
;
3175 it
->end_charpos
= SCHARS (it
->string
);
3176 /* Set up the bidi iterator for this overlay string. */
3179 it
->bidi_it
.string
.lstring
= it
->string
;
3180 it
->bidi_it
.string
.s
= NULL
;
3181 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3182 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3183 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3184 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3185 it
->bidi_it
.w
= it
->w
;
3186 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3187 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3189 /* Synchronize the state of the bidi iterator with
3190 pos->string_pos. For any string position other than
3191 zero, this will be done automagically when we resume
3192 iteration over the string and get_visually_first_element
3193 is called. But if string_pos is zero, and the string is
3194 to be reordered for display, we need to resync manually,
3195 since it could be that the iteration state recorded in
3196 pos ended at string_pos of 0 moving backwards in string. */
3197 if (CHARPOS (pos
->string_pos
) == 0)
3199 get_visually_first_element (it
);
3200 if (IT_STRING_CHARPOS (*it
) != 0)
3203 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3204 bidi_move_to_visually_next (&it
->bidi_it
);
3205 } while (it
->bidi_it
.charpos
!= 0);
3207 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3208 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3212 if (CHARPOS (pos
->string_pos
) >= 0)
3214 /* Recorded position is not in an overlay string, but in another
3215 string. This can only be a string from a `display' property.
3216 IT should already be filled with that string. */
3217 it
->current
.string_pos
= pos
->string_pos
;
3218 eassert (STRINGP (it
->string
));
3220 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3221 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3224 /* Restore position in display vector translations, control
3225 character translations or ellipses. */
3226 if (pos
->dpvec_index
>= 0)
3228 if (it
->dpvec
== NULL
)
3229 get_next_display_element (it
);
3230 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3231 it
->current
.dpvec_index
= pos
->dpvec_index
;
3235 return !overlay_strings_with_newlines
;
3239 /* Initialize IT for stepping through current_buffer in window W
3240 starting at ROW->start. */
3243 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3245 init_from_display_pos (it
, w
, &row
->start
);
3246 it
->start
= row
->start
;
3247 it
->continuation_lines_width
= row
->continuation_lines_width
;
3252 /* Initialize IT for stepping through current_buffer in window W
3253 starting in the line following ROW, i.e. starting at ROW->end.
3254 Value is zero if there are overlay strings with newlines at ROW's
3258 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3262 if (init_from_display_pos (it
, w
, &row
->end
))
3264 if (row
->continued_p
)
3265 it
->continuation_lines_width
3266 = row
->continuation_lines_width
+ row
->pixel_width
;
3277 /***********************************************************************
3279 ***********************************************************************/
3281 /* Called when IT reaches IT->stop_charpos. Handle text property and
3282 overlay changes. Set IT->stop_charpos to the next position where
3286 handle_stop (struct it
*it
)
3288 enum prop_handled handled
;
3289 int handle_overlay_change_p
;
3293 it
->current
.dpvec_index
= -1;
3294 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3295 it
->ignore_overlay_strings_at_pos_p
= 0;
3298 /* Use face of preceding text for ellipsis (if invisible) */
3299 if (it
->selective_display_ellipsis_p
)
3300 it
->saved_face_id
= it
->face_id
;
3304 handled
= HANDLED_NORMALLY
;
3306 /* Call text property handlers. */
3307 for (p
= it_props
; p
->handler
; ++p
)
3309 handled
= p
->handler (it
);
3311 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3313 else if (handled
== HANDLED_RETURN
)
3315 /* We still want to show before and after strings from
3316 overlays even if the actual buffer text is replaced. */
3317 if (!handle_overlay_change_p
3319 /* Don't call get_overlay_strings_1 if we already
3320 have overlay strings loaded, because doing so
3321 will load them again and push the iterator state
3322 onto the stack one more time, which is not
3323 expected by the rest of the code that processes
3325 || (it
->current
.overlay_string_index
< 0
3326 ? !get_overlay_strings_1 (it
, 0, 0)
3330 setup_for_ellipsis (it
, 0);
3331 /* When handling a display spec, we might load an
3332 empty string. In that case, discard it here. We
3333 used to discard it in handle_single_display_spec,
3334 but that causes get_overlay_strings_1, above, to
3335 ignore overlay strings that we must check. */
3336 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3340 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3344 it
->ignore_overlay_strings_at_pos_p
= true;
3345 it
->string_from_display_prop_p
= 0;
3346 it
->from_disp_prop_p
= 0;
3347 handle_overlay_change_p
= 0;
3349 handled
= HANDLED_RECOMPUTE_PROPS
;
3352 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3353 handle_overlay_change_p
= 0;
3356 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3358 /* Don't check for overlay strings below when set to deliver
3359 characters from a display vector. */
3360 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3361 handle_overlay_change_p
= 0;
3363 /* Handle overlay changes.
3364 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3365 if it finds overlays. */
3366 if (handle_overlay_change_p
)
3367 handled
= handle_overlay_change (it
);
3372 setup_for_ellipsis (it
, 0);
3376 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3378 /* Determine where to stop next. */
3379 if (handled
== HANDLED_NORMALLY
)
3380 compute_stop_pos (it
);
3384 /* Compute IT->stop_charpos from text property and overlay change
3385 information for IT's current position. */
3388 compute_stop_pos (struct it
*it
)
3390 register INTERVAL iv
, next_iv
;
3391 Lisp_Object object
, limit
, position
;
3392 ptrdiff_t charpos
, bytepos
;
3394 if (STRINGP (it
->string
))
3396 /* Strings are usually short, so don't limit the search for
3398 it
->stop_charpos
= it
->end_charpos
;
3399 object
= it
->string
;
3401 charpos
= IT_STRING_CHARPOS (*it
);
3402 bytepos
= IT_STRING_BYTEPOS (*it
);
3408 /* If end_charpos is out of range for some reason, such as a
3409 misbehaving display function, rationalize it (Bug#5984). */
3410 if (it
->end_charpos
> ZV
)
3411 it
->end_charpos
= ZV
;
3412 it
->stop_charpos
= it
->end_charpos
;
3414 /* If next overlay change is in front of the current stop pos
3415 (which is IT->end_charpos), stop there. Note: value of
3416 next_overlay_change is point-max if no overlay change
3418 charpos
= IT_CHARPOS (*it
);
3419 bytepos
= IT_BYTEPOS (*it
);
3420 pos
= next_overlay_change (charpos
);
3421 if (pos
< it
->stop_charpos
)
3422 it
->stop_charpos
= pos
;
3424 /* Set up variables for computing the stop position from text
3425 property changes. */
3426 XSETBUFFER (object
, current_buffer
);
3427 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3430 /* Get the interval containing IT's position. Value is a null
3431 interval if there isn't such an interval. */
3432 position
= make_number (charpos
);
3433 iv
= validate_interval_range (object
, &position
, &position
, 0);
3436 Lisp_Object values_here
[LAST_PROP_IDX
];
3439 /* Get properties here. */
3440 for (p
= it_props
; p
->handler
; ++p
)
3441 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3443 /* Look for an interval following iv that has different
3445 for (next_iv
= next_interval (iv
);
3448 || XFASTINT (limit
) > next_iv
->position
));
3449 next_iv
= next_interval (next_iv
))
3451 for (p
= it_props
; p
->handler
; ++p
)
3453 Lisp_Object new_value
;
3455 new_value
= textget (next_iv
->plist
, *p
->name
);
3456 if (!EQ (values_here
[p
->idx
], new_value
))
3466 if (INTEGERP (limit
)
3467 && next_iv
->position
>= XFASTINT (limit
))
3468 /* No text property change up to limit. */
3469 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3471 /* Text properties change in next_iv. */
3472 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3476 if (it
->cmp_it
.id
< 0)
3478 ptrdiff_t stoppos
= it
->end_charpos
;
3480 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3482 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3483 stoppos
, it
->string
);
3486 eassert (STRINGP (it
->string
)
3487 || (it
->stop_charpos
>= BEGV
3488 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3492 /* Return the position of the next overlay change after POS in
3493 current_buffer. Value is point-max if no overlay change
3494 follows. This is like `next-overlay-change' but doesn't use
3498 next_overlay_change (ptrdiff_t pos
)
3500 ptrdiff_t i
, noverlays
;
3502 Lisp_Object
*overlays
;
3504 /* Get all overlays at the given position. */
3505 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3507 /* If any of these overlays ends before endpos,
3508 use its ending point instead. */
3509 for (i
= 0; i
< noverlays
; ++i
)
3514 oend
= OVERLAY_END (overlays
[i
]);
3515 oendpos
= OVERLAY_POSITION (oend
);
3516 endpos
= min (endpos
, oendpos
);
3522 /* How many characters forward to search for a display property or
3523 display string. Searching too far forward makes the bidi display
3524 sluggish, especially in small windows. */
3525 #define MAX_DISP_SCAN 250
3527 /* Return the character position of a display string at or after
3528 position specified by POSITION. If no display string exists at or
3529 after POSITION, return ZV. A display string is either an overlay
3530 with `display' property whose value is a string, or a `display'
3531 text property whose value is a string. STRING is data about the
3532 string to iterate; if STRING->lstring is nil, we are iterating a
3533 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3534 on a GUI frame. DISP_PROP is set to zero if we searched
3535 MAX_DISP_SCAN characters forward without finding any display
3536 strings, non-zero otherwise. It is set to 2 if the display string
3537 uses any kind of `(space ...)' spec that will produce a stretch of
3538 white space in the text area. */
3540 compute_display_string_pos (struct text_pos
*position
,
3541 struct bidi_string_data
*string
,
3543 int frame_window_p
, int *disp_prop
)
3545 /* OBJECT = nil means current buffer. */
3546 Lisp_Object object
, object1
;
3547 Lisp_Object pos
, spec
, limpos
;
3548 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3549 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3550 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3551 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3553 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3554 struct text_pos tpos
;
3557 if (string
&& STRINGP (string
->lstring
))
3558 object1
= object
= string
->lstring
;
3559 else if (w
&& !string_p
)
3561 XSETWINDOW (object
, w
);
3565 object1
= object
= Qnil
;
3570 /* We don't support display properties whose values are strings
3571 that have display string properties. */
3572 || string
->from_disp_str
3573 /* C strings cannot have display properties. */
3574 || (string
->s
&& !STRINGP (object
)))
3580 /* If the character at CHARPOS is where the display string begins,
3582 pos
= make_number (charpos
);
3583 if (STRINGP (object
))
3584 bufpos
= string
->bufpos
;
3588 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3590 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3593 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3601 /* Look forward for the first character with a `display' property
3602 that will replace the underlying text when displayed. */
3603 limpos
= make_number (lim
);
3605 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3606 CHARPOS (tpos
) = XFASTINT (pos
);
3607 if (CHARPOS (tpos
) >= lim
)
3612 if (STRINGP (object
))
3613 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3615 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3616 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3617 if (!STRINGP (object
))
3618 bufpos
= CHARPOS (tpos
);
3619 } while (NILP (spec
)
3620 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3621 bufpos
, frame_window_p
)));
3625 return CHARPOS (tpos
);
3628 /* Return the character position of the end of the display string that
3629 started at CHARPOS. If there's no display string at CHARPOS,
3630 return -1. A display string is either an overlay with `display'
3631 property whose value is a string or a `display' text property whose
3632 value is a string. */
3634 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3636 /* OBJECT = nil means current buffer. */
3637 Lisp_Object object
=
3638 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3639 Lisp_Object pos
= make_number (charpos
);
3641 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3643 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3646 /* It could happen that the display property or overlay was removed
3647 since we found it in compute_display_string_pos above. One way
3648 this can happen is if JIT font-lock was called (through
3649 handle_fontified_prop), and jit-lock-functions remove text
3650 properties or overlays from the portion of buffer that includes
3651 CHARPOS. Muse mode is known to do that, for example. In this
3652 case, we return -1 to the caller, to signal that no display
3653 string is actually present at CHARPOS. See bidi_fetch_char for
3654 how this is handled.
3656 An alternative would be to never look for display properties past
3657 it->stop_charpos. But neither compute_display_string_pos nor
3658 bidi_fetch_char that calls it know or care where the next
3660 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3663 /* Look forward for the first character where the `display' property
3665 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3667 return XFASTINT (pos
);
3672 /***********************************************************************
3674 ***********************************************************************/
3676 /* Handle changes in the `fontified' property of the current buffer by
3677 calling hook functions from Qfontification_functions to fontify
3680 static enum prop_handled
3681 handle_fontified_prop (struct it
*it
)
3683 Lisp_Object prop
, pos
;
3684 enum prop_handled handled
= HANDLED_NORMALLY
;
3686 if (!NILP (Vmemory_full
))
3689 /* Get the value of the `fontified' property at IT's current buffer
3690 position. (The `fontified' property doesn't have a special
3691 meaning in strings.) If the value is nil, call functions from
3692 Qfontification_functions. */
3693 if (!STRINGP (it
->string
)
3695 && !NILP (Vfontification_functions
)
3696 && !NILP (Vrun_hooks
)
3697 && (pos
= make_number (IT_CHARPOS (*it
)),
3698 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3699 /* Ignore the special cased nil value always present at EOB since
3700 no amount of fontifying will be able to change it. */
3701 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3703 ptrdiff_t count
= SPECPDL_INDEX ();
3705 struct buffer
*obuf
= current_buffer
;
3706 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3707 bool old_clip_changed
= current_buffer
->clip_changed
;
3709 val
= Vfontification_functions
;
3710 specbind (Qfontification_functions
, Qnil
);
3712 eassert (it
->end_charpos
== ZV
);
3714 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3715 safe_call1 (val
, pos
);
3718 Lisp_Object fns
, fn
;
3719 struct gcpro gcpro1
, gcpro2
;
3724 for (; CONSP (val
); val
= XCDR (val
))
3730 /* A value of t indicates this hook has a local
3731 binding; it means to run the global binding too.
3732 In a global value, t should not occur. If it
3733 does, we must ignore it to avoid an endless
3735 for (fns
= Fdefault_value (Qfontification_functions
);
3741 safe_call1 (fn
, pos
);
3745 safe_call1 (fn
, pos
);
3751 unbind_to (count
, Qnil
);
3753 /* Fontification functions routinely call `save-restriction'.
3754 Normally, this tags clip_changed, which can confuse redisplay
3755 (see discussion in Bug#6671). Since we don't perform any
3756 special handling of fontification changes in the case where
3757 `save-restriction' isn't called, there's no point doing so in
3758 this case either. So, if the buffer's restrictions are
3759 actually left unchanged, reset clip_changed. */
3760 if (obuf
== current_buffer
)
3762 if (begv
== BEGV
&& zv
== ZV
)
3763 current_buffer
->clip_changed
= old_clip_changed
;
3765 /* There isn't much we can reasonably do to protect against
3766 misbehaving fontification, but here's a fig leaf. */
3767 else if (BUFFER_LIVE_P (obuf
))
3768 set_buffer_internal_1 (obuf
);
3770 /* The fontification code may have added/removed text.
3771 It could do even a lot worse, but let's at least protect against
3772 the most obvious case where only the text past `pos' gets changed',
3773 as is/was done in grep.el where some escapes sequences are turned
3774 into face properties (bug#7876). */
3775 it
->end_charpos
= ZV
;
3777 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3778 something. This avoids an endless loop if they failed to
3779 fontify the text for which reason ever. */
3780 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3781 handled
= HANDLED_RECOMPUTE_PROPS
;
3789 /***********************************************************************
3791 ***********************************************************************/
3793 /* Set up iterator IT from face properties at its current position.
3794 Called from handle_stop. */
3796 static enum prop_handled
3797 handle_face_prop (struct it
*it
)
3800 ptrdiff_t next_stop
;
3802 if (!STRINGP (it
->string
))
3805 = face_at_buffer_position (it
->w
,
3809 + TEXT_PROP_DISTANCE_LIMIT
),
3810 0, it
->base_face_id
);
3812 /* Is this a start of a run of characters with box face?
3813 Caveat: this can be called for a freshly initialized
3814 iterator; face_id is -1 in this case. We know that the new
3815 face will not change until limit, i.e. if the new face has a
3816 box, all characters up to limit will have one. But, as
3817 usual, we don't know whether limit is really the end. */
3818 if (new_face_id
!= it
->face_id
)
3820 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3821 /* If it->face_id is -1, old_face below will be NULL, see
3822 the definition of FACE_FROM_ID. This will happen if this
3823 is the initial call that gets the face. */
3824 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3826 /* If the value of face_id of the iterator is -1, we have to
3827 look in front of IT's position and see whether there is a
3828 face there that's different from new_face_id. */
3829 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3831 int prev_face_id
= face_before_it_pos (it
);
3833 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3836 /* If the new face has a box, but the old face does not,
3837 this is the start of a run of characters with box face,
3838 i.e. this character has a shadow on the left side. */
3839 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3840 && (old_face
== NULL
|| !old_face
->box
));
3841 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3849 Lisp_Object from_overlay
3850 = (it
->current
.overlay_string_index
>= 0
3851 ? it
->string_overlays
[it
->current
.overlay_string_index
3852 % OVERLAY_STRING_CHUNK_SIZE
]
3855 /* See if we got to this string directly or indirectly from
3856 an overlay property. That includes the before-string or
3857 after-string of an overlay, strings in display properties
3858 provided by an overlay, their text properties, etc.
3860 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3861 if (! NILP (from_overlay
))
3862 for (i
= it
->sp
- 1; i
>= 0; i
--)
3864 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3866 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3867 % OVERLAY_STRING_CHUNK_SIZE
];
3868 else if (! NILP (it
->stack
[i
].from_overlay
))
3869 from_overlay
= it
->stack
[i
].from_overlay
;
3871 if (!NILP (from_overlay
))
3875 if (! NILP (from_overlay
))
3877 bufpos
= IT_CHARPOS (*it
);
3878 /* For a string from an overlay, the base face depends
3879 only on text properties and ignores overlays. */
3881 = face_for_overlay_string (it
->w
,
3885 + TEXT_PROP_DISTANCE_LIMIT
),
3893 /* For strings from a `display' property, use the face at
3894 IT's current buffer position as the base face to merge
3895 with, so that overlay strings appear in the same face as
3896 surrounding text, unless they specify their own faces.
3897 For strings from wrap-prefix and line-prefix properties,
3898 use the default face, possibly remapped via
3899 Vface_remapping_alist. */
3900 base_face_id
= it
->string_from_prefix_prop_p
3901 ? (!NILP (Vface_remapping_alist
)
3902 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3904 : underlying_face_id (it
);
3907 new_face_id
= face_at_string_position (it
->w
,
3909 IT_STRING_CHARPOS (*it
),
3914 /* Is this a start of a run of characters with box? Caveat:
3915 this can be called for a freshly allocated iterator; face_id
3916 is -1 is this case. We know that the new face will not
3917 change until the next check pos, i.e. if the new face has a
3918 box, all characters up to that position will have a
3919 box. But, as usual, we don't know whether that position
3920 is really the end. */
3921 if (new_face_id
!= it
->face_id
)
3923 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3924 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3926 /* If new face has a box but old face hasn't, this is the
3927 start of a run of characters with box, i.e. it has a
3928 shadow on the left side. */
3929 it
->start_of_box_run_p
3930 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3931 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3935 it
->face_id
= new_face_id
;
3936 return HANDLED_NORMALLY
;
3940 /* Return the ID of the face ``underlying'' IT's current position,
3941 which is in a string. If the iterator is associated with a
3942 buffer, return the face at IT's current buffer position.
3943 Otherwise, use the iterator's base_face_id. */
3946 underlying_face_id (struct it
*it
)
3948 int face_id
= it
->base_face_id
, i
;
3950 eassert (STRINGP (it
->string
));
3952 for (i
= it
->sp
- 1; i
>= 0; --i
)
3953 if (NILP (it
->stack
[i
].string
))
3954 face_id
= it
->stack
[i
].face_id
;
3960 /* Compute the face one character before or after the current position
3961 of IT, in the visual order. BEFORE_P non-zero means get the face
3962 in front (to the left in L2R paragraphs, to the right in R2L
3963 paragraphs) of IT's screen position. Value is the ID of the face. */
3966 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3969 ptrdiff_t next_check_charpos
;
3971 void *it_copy_data
= NULL
;
3973 eassert (it
->s
== NULL
);
3975 if (STRINGP (it
->string
))
3977 ptrdiff_t bufpos
, charpos
;
3980 /* No face change past the end of the string (for the case
3981 we are padding with spaces). No face change before the
3983 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3984 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3989 /* Set charpos to the position before or after IT's current
3990 position, in the logical order, which in the non-bidi
3991 case is the same as the visual order. */
3993 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3994 else if (it
->what
== IT_COMPOSITION
)
3995 /* For composition, we must check the character after the
3997 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3999 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4005 /* With bidi iteration, the character before the current
4006 in the visual order cannot be found by simple
4007 iteration, because "reverse" reordering is not
4008 supported. Instead, we need to use the move_it_*
4009 family of functions. */
4010 /* Ignore face changes before the first visible
4011 character on this display line. */
4012 if (it
->current_x
<= it
->first_visible_x
)
4014 SAVE_IT (it_copy
, *it
, it_copy_data
);
4015 /* Implementation note: Since move_it_in_display_line
4016 works in the iterator geometry, and thinks the first
4017 character is always the leftmost, even in R2L lines,
4018 we don't need to distinguish between the R2L and L2R
4020 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4021 it_copy
.current_x
- 1, MOVE_TO_X
);
4022 charpos
= IT_STRING_CHARPOS (it_copy
);
4023 RESTORE_IT (it
, it
, it_copy_data
);
4027 /* Set charpos to the string position of the character
4028 that comes after IT's current position in the visual
4030 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4034 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4036 charpos
= it_copy
.bidi_it
.charpos
;
4039 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4041 if (it
->current
.overlay_string_index
>= 0)
4042 bufpos
= IT_CHARPOS (*it
);
4046 base_face_id
= underlying_face_id (it
);
4048 /* Get the face for ASCII, or unibyte. */
4049 face_id
= face_at_string_position (it
->w
,
4053 &next_check_charpos
,
4056 /* Correct the face for charsets different from ASCII. Do it
4057 for the multibyte case only. The face returned above is
4058 suitable for unibyte text if IT->string is unibyte. */
4059 if (STRING_MULTIBYTE (it
->string
))
4061 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4062 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4064 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4066 c
= string_char_and_length (p
, &len
);
4067 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4072 struct text_pos pos
;
4074 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4075 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4078 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4079 pos
= it
->current
.pos
;
4084 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4087 if (it
->what
== IT_COMPOSITION
)
4089 /* For composition, we must check the position after
4091 pos
.charpos
+= it
->cmp_it
.nchars
;
4092 pos
.bytepos
+= it
->len
;
4095 INC_TEXT_POS (pos
, it
->multibyte_p
);
4102 /* With bidi iteration, the character before the current
4103 in the visual order cannot be found by simple
4104 iteration, because "reverse" reordering is not
4105 supported. Instead, we need to use the move_it_*
4106 family of functions. */
4107 /* Ignore face changes before the first visible
4108 character on this display line. */
4109 if (it
->current_x
<= it
->first_visible_x
)
4111 SAVE_IT (it_copy
, *it
, it_copy_data
);
4112 /* Implementation note: Since move_it_in_display_line
4113 works in the iterator geometry, and thinks the first
4114 character is always the leftmost, even in R2L lines,
4115 we don't need to distinguish between the R2L and L2R
4117 move_it_in_display_line (&it_copy
, ZV
,
4118 it_copy
.current_x
- 1, MOVE_TO_X
);
4119 pos
= it_copy
.current
.pos
;
4120 RESTORE_IT (it
, it
, it_copy_data
);
4124 /* Set charpos to the buffer position of the character
4125 that comes after IT's current position in the visual
4127 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4131 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4134 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4137 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4139 /* Determine face for CHARSET_ASCII, or unibyte. */
4140 face_id
= face_at_buffer_position (it
->w
,
4142 &next_check_charpos
,
4145 /* Correct the face for charsets different from ASCII. Do it
4146 for the multibyte case only. The face returned above is
4147 suitable for unibyte text if current_buffer is unibyte. */
4148 if (it
->multibyte_p
)
4150 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4151 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4152 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4161 /***********************************************************************
4163 ***********************************************************************/
4165 /* Set up iterator IT from invisible properties at its current
4166 position. Called from handle_stop. */
4168 static enum prop_handled
4169 handle_invisible_prop (struct it
*it
)
4171 enum prop_handled handled
= HANDLED_NORMALLY
;
4175 if (STRINGP (it
->string
))
4177 Lisp_Object end_charpos
, limit
, charpos
;
4179 /* Get the value of the invisible text property at the
4180 current position. Value will be nil if there is no such
4182 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4183 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4184 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4186 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4188 /* Record whether we have to display an ellipsis for the
4190 int display_ellipsis_p
= (invis_p
== 2);
4191 ptrdiff_t len
, endpos
;
4193 handled
= HANDLED_RECOMPUTE_PROPS
;
4195 /* Get the position at which the next visible text can be
4196 found in IT->string, if any. */
4197 endpos
= len
= SCHARS (it
->string
);
4198 XSETINT (limit
, len
);
4201 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4203 if (INTEGERP (end_charpos
))
4205 endpos
= XFASTINT (end_charpos
);
4206 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4207 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4209 display_ellipsis_p
= true;
4212 while (invis_p
&& endpos
< len
);
4214 if (display_ellipsis_p
)
4215 it
->ellipsis_p
= true;
4219 /* Text at END_CHARPOS is visible. Move IT there. */
4220 struct text_pos old
;
4223 old
= it
->current
.string_pos
;
4224 oldpos
= CHARPOS (old
);
4227 if (it
->bidi_it
.first_elt
4228 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4229 bidi_paragraph_init (it
->paragraph_embedding
,
4231 /* Bidi-iterate out of the invisible text. */
4234 bidi_move_to_visually_next (&it
->bidi_it
);
4236 while (oldpos
<= it
->bidi_it
.charpos
4237 && it
->bidi_it
.charpos
< endpos
);
4239 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4240 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4241 if (IT_CHARPOS (*it
) >= endpos
)
4242 it
->prev_stop
= endpos
;
4246 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4247 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4252 /* The rest of the string is invisible. If this is an
4253 overlay string, proceed with the next overlay string
4254 or whatever comes and return a character from there. */
4255 if (it
->current
.overlay_string_index
>= 0
4256 && !display_ellipsis_p
)
4258 next_overlay_string (it
);
4259 /* Don't check for overlay strings when we just
4260 finished processing them. */
4261 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4265 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4266 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4273 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4274 Lisp_Object pos
, overlay
;
4276 /* First of all, is there invisible text at this position? */
4277 tem
= start_charpos
= IT_CHARPOS (*it
);
4278 pos
= make_number (tem
);
4279 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4281 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4283 /* If we are on invisible text, skip over it. */
4284 if (invis_p
&& start_charpos
< it
->end_charpos
)
4286 /* Record whether we have to display an ellipsis for the
4288 int display_ellipsis_p
= invis_p
== 2;
4290 handled
= HANDLED_RECOMPUTE_PROPS
;
4292 /* Loop skipping over invisible text. The loop is left at
4293 ZV or with IT on the first char being visible again. */
4296 /* Try to skip some invisible text. Return value is the
4297 position reached which can be equal to where we start
4298 if there is nothing invisible there. This skips both
4299 over invisible text properties and overlays with
4300 invisible property. */
4301 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4303 /* If we skipped nothing at all we weren't at invisible
4304 text in the first place. If everything to the end of
4305 the buffer was skipped, end the loop. */
4306 if (newpos
== tem
|| newpos
>= ZV
)
4310 /* We skipped some characters but not necessarily
4311 all there are. Check if we ended up on visible
4312 text. Fget_char_property returns the property of
4313 the char before the given position, i.e. if we
4314 get invis_p = 0, this means that the char at
4315 newpos is visible. */
4316 pos
= make_number (newpos
);
4317 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4318 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4321 /* If we ended up on invisible text, proceed to
4322 skip starting with next_stop. */
4326 /* If there are adjacent invisible texts, don't lose the
4327 second one's ellipsis. */
4329 display_ellipsis_p
= true;
4333 /* The position newpos is now either ZV or on visible text. */
4336 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4338 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4340 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4342 /* If the invisible text ends on a newline or on a
4343 character after a newline, we can avoid the costly,
4344 character by character, bidi iteration to NEWPOS, and
4345 instead simply reseat the iterator there. That's
4346 because all bidi reordering information is tossed at
4347 the newline. This is a big win for modes that hide
4348 complete lines, like Outline, Org, etc. */
4349 if (on_newline
|| after_newline
)
4351 struct text_pos tpos
;
4352 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4354 SET_TEXT_POS (tpos
, newpos
, bpos
);
4355 reseat_1 (it
, tpos
, 0);
4356 /* If we reseat on a newline/ZV, we need to prep the
4357 bidi iterator for advancing to the next character
4358 after the newline/EOB, keeping the current paragraph
4359 direction (so that PRODUCE_GLYPHS does TRT wrt
4360 prepending/appending glyphs to a glyph row). */
4363 it
->bidi_it
.first_elt
= 0;
4364 it
->bidi_it
.paragraph_dir
= pdir
;
4365 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4366 it
->bidi_it
.nchars
= 1;
4367 it
->bidi_it
.ch_len
= 1;
4370 else /* Must use the slow method. */
4372 /* With bidi iteration, the region of invisible text
4373 could start and/or end in the middle of a
4374 non-base embedding level. Therefore, we need to
4375 skip invisible text using the bidi iterator,
4376 starting at IT's current position, until we find
4377 ourselves outside of the invisible text.
4378 Skipping invisible text _after_ bidi iteration
4379 avoids affecting the visual order of the
4380 displayed text when invisible properties are
4381 added or removed. */
4382 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4384 /* If we were `reseat'ed to a new paragraph,
4385 determine the paragraph base direction. We
4386 need to do it now because
4387 next_element_from_buffer may not have a
4388 chance to do it, if we are going to skip any
4389 text at the beginning, which resets the
4391 bidi_paragraph_init (it
->paragraph_embedding
,
4396 bidi_move_to_visually_next (&it
->bidi_it
);
4398 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4399 && it
->bidi_it
.charpos
< newpos
);
4400 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4401 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4402 /* If we overstepped NEWPOS, record its position in
4403 the iterator, so that we skip invisible text if
4404 later the bidi iteration lands us in the
4405 invisible region again. */
4406 if (IT_CHARPOS (*it
) >= newpos
)
4407 it
->prev_stop
= newpos
;
4412 IT_CHARPOS (*it
) = newpos
;
4413 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4416 /* If there are before-strings at the start of invisible
4417 text, and the text is invisible because of a text
4418 property, arrange to show before-strings because 20.x did
4419 it that way. (If the text is invisible because of an
4420 overlay property instead of a text property, this is
4421 already handled in the overlay code.) */
4423 && get_overlay_strings (it
, it
->stop_charpos
))
4425 handled
= HANDLED_RECOMPUTE_PROPS
;
4426 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4428 else if (display_ellipsis_p
)
4430 /* Make sure that the glyphs of the ellipsis will get
4431 correct `charpos' values. If we would not update
4432 it->position here, the glyphs would belong to the
4433 last visible character _before_ the invisible
4434 text, which confuses `set_cursor_from_row'.
4436 We use the last invisible position instead of the
4437 first because this way the cursor is always drawn on
4438 the first "." of the ellipsis, whenever PT is inside
4439 the invisible text. Otherwise the cursor would be
4440 placed _after_ the ellipsis when the point is after the
4441 first invisible character. */
4442 if (!STRINGP (it
->object
))
4444 it
->position
.charpos
= newpos
- 1;
4445 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4447 it
->ellipsis_p
= true;
4448 /* Let the ellipsis display before
4449 considering any properties of the following char.
4450 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4451 handled
= HANDLED_RETURN
;
4460 /* Make iterator IT return `...' next.
4461 Replaces LEN characters from buffer. */
4464 setup_for_ellipsis (struct it
*it
, int len
)
4466 /* Use the display table definition for `...'. Invalid glyphs
4467 will be handled by the method returning elements from dpvec. */
4468 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4470 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4471 it
->dpvec
= v
->contents
;
4472 it
->dpend
= v
->contents
+ v
->header
.size
;
4476 /* Default `...'. */
4477 it
->dpvec
= default_invis_vector
;
4478 it
->dpend
= default_invis_vector
+ 3;
4481 it
->dpvec_char_len
= len
;
4482 it
->current
.dpvec_index
= 0;
4483 it
->dpvec_face_id
= -1;
4485 /* Remember the current face id in case glyphs specify faces.
4486 IT's face is restored in set_iterator_to_next.
4487 saved_face_id was set to preceding char's face in handle_stop. */
4488 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4489 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4491 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4492 it
->ellipsis_p
= true;
4497 /***********************************************************************
4499 ***********************************************************************/
4501 /* Set up iterator IT from `display' property at its current position.
4502 Called from handle_stop.
4503 We return HANDLED_RETURN if some part of the display property
4504 overrides the display of the buffer text itself.
4505 Otherwise we return HANDLED_NORMALLY. */
4507 static enum prop_handled
4508 handle_display_prop (struct it
*it
)
4510 Lisp_Object propval
, object
, overlay
;
4511 struct text_pos
*position
;
4513 /* Nonzero if some property replaces the display of the text itself. */
4514 int display_replaced_p
= 0;
4516 if (STRINGP (it
->string
))
4518 object
= it
->string
;
4519 position
= &it
->current
.string_pos
;
4520 bufpos
= CHARPOS (it
->current
.pos
);
4524 XSETWINDOW (object
, it
->w
);
4525 position
= &it
->current
.pos
;
4526 bufpos
= CHARPOS (*position
);
4529 /* Reset those iterator values set from display property values. */
4530 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4531 it
->space_width
= Qnil
;
4532 it
->font_height
= Qnil
;
4535 /* We don't support recursive `display' properties, i.e. string
4536 values that have a string `display' property, that have a string
4537 `display' property etc. */
4538 if (!it
->string_from_display_prop_p
)
4539 it
->area
= TEXT_AREA
;
4541 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4542 Qdisplay
, object
, &overlay
);
4544 return HANDLED_NORMALLY
;
4545 /* Now OVERLAY is the overlay that gave us this property, or nil
4546 if it was a text property. */
4548 if (!STRINGP (it
->string
))
4549 object
= it
->w
->contents
;
4551 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4553 FRAME_WINDOW_P (it
->f
));
4555 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4558 /* Subroutine of handle_display_prop. Returns non-zero if the display
4559 specification in SPEC is a replacing specification, i.e. it would
4560 replace the text covered by `display' property with something else,
4561 such as an image or a display string. If SPEC includes any kind or
4562 `(space ...) specification, the value is 2; this is used by
4563 compute_display_string_pos, which see.
4565 See handle_single_display_spec for documentation of arguments.
4566 frame_window_p is non-zero if the window being redisplayed is on a
4567 GUI frame; this argument is used only if IT is NULL, see below.
4569 IT can be NULL, if this is called by the bidi reordering code
4570 through compute_display_string_pos, which see. In that case, this
4571 function only examines SPEC, but does not otherwise "handle" it, in
4572 the sense that it doesn't set up members of IT from the display
4575 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4576 Lisp_Object overlay
, struct text_pos
*position
,
4577 ptrdiff_t bufpos
, int frame_window_p
)
4579 int replacing_p
= 0;
4583 /* Simple specifications. */
4584 && !EQ (XCAR (spec
), Qimage
)
4585 && !EQ (XCAR (spec
), Qspace
)
4586 && !EQ (XCAR (spec
), Qwhen
)
4587 && !EQ (XCAR (spec
), Qslice
)
4588 && !EQ (XCAR (spec
), Qspace_width
)
4589 && !EQ (XCAR (spec
), Qheight
)
4590 && !EQ (XCAR (spec
), Qraise
)
4591 /* Marginal area specifications. */
4592 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4593 && !EQ (XCAR (spec
), Qleft_fringe
)
4594 && !EQ (XCAR (spec
), Qright_fringe
)
4595 && !NILP (XCAR (spec
)))
4597 for (; CONSP (spec
); spec
= XCDR (spec
))
4599 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4600 overlay
, position
, bufpos
,
4601 replacing_p
, frame_window_p
)))
4604 /* If some text in a string is replaced, `position' no
4605 longer points to the position of `object'. */
4606 if (!it
|| STRINGP (object
))
4611 else if (VECTORP (spec
))
4614 for (i
= 0; i
< ASIZE (spec
); ++i
)
4615 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4616 overlay
, position
, bufpos
,
4617 replacing_p
, frame_window_p
)))
4620 /* If some text in a string is replaced, `position' no
4621 longer points to the position of `object'. */
4622 if (!it
|| STRINGP (object
))
4628 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4629 position
, bufpos
, 0,
4637 /* Value is the position of the end of the `display' property starting
4638 at START_POS in OBJECT. */
4640 static struct text_pos
4641 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4644 struct text_pos end_pos
;
4646 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4647 Qdisplay
, object
, Qnil
);
4648 CHARPOS (end_pos
) = XFASTINT (end
);
4649 if (STRINGP (object
))
4650 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4652 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4658 /* Set up IT from a single `display' property specification SPEC. OBJECT
4659 is the object in which the `display' property was found. *POSITION
4660 is the position in OBJECT at which the `display' property was found.
4661 BUFPOS is the buffer position of OBJECT (different from POSITION if
4662 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4663 previously saw a display specification which already replaced text
4664 display with something else, for example an image; we ignore such
4665 properties after the first one has been processed.
4667 OVERLAY is the overlay this `display' property came from,
4668 or nil if it was a text property.
4670 If SPEC is a `space' or `image' specification, and in some other
4671 cases too, set *POSITION to the position where the `display'
4674 If IT is NULL, only examine the property specification in SPEC, but
4675 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4676 is intended to be displayed in a window on a GUI frame.
4678 Value is non-zero if something was found which replaces the display
4679 of buffer or string text. */
4682 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4683 Lisp_Object overlay
, struct text_pos
*position
,
4684 ptrdiff_t bufpos
, int display_replaced_p
,
4688 Lisp_Object location
, value
;
4689 struct text_pos start_pos
= *position
;
4692 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4693 If the result is non-nil, use VALUE instead of SPEC. */
4695 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4704 if (!NILP (form
) && !EQ (form
, Qt
))
4706 ptrdiff_t count
= SPECPDL_INDEX ();
4707 struct gcpro gcpro1
;
4709 /* Bind `object' to the object having the `display' property, a
4710 buffer or string. Bind `position' to the position in the
4711 object where the property was found, and `buffer-position'
4712 to the current position in the buffer. */
4715 XSETBUFFER (object
, current_buffer
);
4716 specbind (Qobject
, object
);
4717 specbind (Qposition
, make_number (CHARPOS (*position
)));
4718 specbind (Qbuffer_position
, make_number (bufpos
));
4720 form
= safe_eval (form
);
4722 unbind_to (count
, Qnil
);
4728 /* Handle `(height HEIGHT)' specifications. */
4730 && EQ (XCAR (spec
), Qheight
)
4731 && CONSP (XCDR (spec
)))
4735 if (!FRAME_WINDOW_P (it
->f
))
4738 it
->font_height
= XCAR (XCDR (spec
));
4739 if (!NILP (it
->font_height
))
4741 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4742 int new_height
= -1;
4744 if (CONSP (it
->font_height
)
4745 && (EQ (XCAR (it
->font_height
), Qplus
)
4746 || EQ (XCAR (it
->font_height
), Qminus
))
4747 && CONSP (XCDR (it
->font_height
))
4748 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4750 /* `(+ N)' or `(- N)' where N is an integer. */
4751 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4752 if (EQ (XCAR (it
->font_height
), Qplus
))
4754 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4756 else if (FUNCTIONP (it
->font_height
))
4758 /* Call function with current height as argument.
4759 Value is the new height. */
4761 height
= safe_call1 (it
->font_height
,
4762 face
->lface
[LFACE_HEIGHT_INDEX
]);
4763 if (NUMBERP (height
))
4764 new_height
= XFLOATINT (height
);
4766 else if (NUMBERP (it
->font_height
))
4768 /* Value is a multiple of the canonical char height. */
4771 f
= FACE_FROM_ID (it
->f
,
4772 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4773 new_height
= (XFLOATINT (it
->font_height
)
4774 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4778 /* Evaluate IT->font_height with `height' bound to the
4779 current specified height to get the new height. */
4780 ptrdiff_t count
= SPECPDL_INDEX ();
4782 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4783 value
= safe_eval (it
->font_height
);
4784 unbind_to (count
, Qnil
);
4786 if (NUMBERP (value
))
4787 new_height
= XFLOATINT (value
);
4791 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4798 /* Handle `(space-width WIDTH)'. */
4800 && EQ (XCAR (spec
), Qspace_width
)
4801 && CONSP (XCDR (spec
)))
4805 if (!FRAME_WINDOW_P (it
->f
))
4808 value
= XCAR (XCDR (spec
));
4809 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4810 it
->space_width
= value
;
4816 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4818 && EQ (XCAR (spec
), Qslice
))
4824 if (!FRAME_WINDOW_P (it
->f
))
4827 if (tem
= XCDR (spec
), CONSP (tem
))
4829 it
->slice
.x
= XCAR (tem
);
4830 if (tem
= XCDR (tem
), CONSP (tem
))
4832 it
->slice
.y
= XCAR (tem
);
4833 if (tem
= XCDR (tem
), CONSP (tem
))
4835 it
->slice
.width
= XCAR (tem
);
4836 if (tem
= XCDR (tem
), CONSP (tem
))
4837 it
->slice
.height
= XCAR (tem
);
4846 /* Handle `(raise FACTOR)'. */
4848 && EQ (XCAR (spec
), Qraise
)
4849 && CONSP (XCDR (spec
)))
4853 if (!FRAME_WINDOW_P (it
->f
))
4856 #ifdef HAVE_WINDOW_SYSTEM
4857 value
= XCAR (XCDR (spec
));
4858 if (NUMBERP (value
))
4860 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4861 it
->voffset
= - (XFLOATINT (value
)
4862 * (FONT_HEIGHT (face
->font
)));
4864 #endif /* HAVE_WINDOW_SYSTEM */
4870 /* Don't handle the other kinds of display specifications
4871 inside a string that we got from a `display' property. */
4872 if (it
&& it
->string_from_display_prop_p
)
4875 /* Characters having this form of property are not displayed, so
4876 we have to find the end of the property. */
4879 start_pos
= *position
;
4880 *position
= display_prop_end (it
, object
, start_pos
);
4884 /* Stop the scan at that end position--we assume that all
4885 text properties change there. */
4887 it
->stop_charpos
= position
->charpos
;
4889 /* Handle `(left-fringe BITMAP [FACE])'
4890 and `(right-fringe BITMAP [FACE])'. */
4892 && (EQ (XCAR (spec
), Qleft_fringe
)
4893 || EQ (XCAR (spec
), Qright_fringe
))
4894 && CONSP (XCDR (spec
)))
4900 if (!FRAME_WINDOW_P (it
->f
))
4901 /* If we return here, POSITION has been advanced
4902 across the text with this property. */
4904 /* Synchronize the bidi iterator with POSITION. This is
4905 needed because we are not going to push the iterator
4906 on behalf of this display property, so there will be
4907 no pop_it call to do this synchronization for us. */
4910 it
->position
= *position
;
4911 iterate_out_of_display_property (it
);
4912 *position
= it
->position
;
4917 else if (!frame_window_p
)
4920 #ifdef HAVE_WINDOW_SYSTEM
4921 value
= XCAR (XCDR (spec
));
4922 if (!SYMBOLP (value
)
4923 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4924 /* If we return here, POSITION has been advanced
4925 across the text with this property. */
4927 if (it
&& it
->bidi_p
)
4929 it
->position
= *position
;
4930 iterate_out_of_display_property (it
);
4931 *position
= it
->position
;
4938 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4940 if (CONSP (XCDR (XCDR (spec
))))
4942 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4943 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4949 /* Save current settings of IT so that we can restore them
4950 when we are finished with the glyph property value. */
4951 push_it (it
, position
);
4953 it
->area
= TEXT_AREA
;
4954 it
->what
= IT_IMAGE
;
4955 it
->image_id
= -1; /* no image */
4956 it
->position
= start_pos
;
4957 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4958 it
->method
= GET_FROM_IMAGE
;
4959 it
->from_overlay
= Qnil
;
4960 it
->face_id
= face_id
;
4961 it
->from_disp_prop_p
= true;
4963 /* Say that we haven't consumed the characters with
4964 `display' property yet. The call to pop_it in
4965 set_iterator_to_next will clean this up. */
4966 *position
= start_pos
;
4968 if (EQ (XCAR (spec
), Qleft_fringe
))
4970 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4971 it
->left_user_fringe_face_id
= face_id
;
4975 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4976 it
->right_user_fringe_face_id
= face_id
;
4979 #endif /* HAVE_WINDOW_SYSTEM */
4983 /* Prepare to handle `((margin left-margin) ...)',
4984 `((margin right-margin) ...)' and `((margin nil) ...)'
4985 prefixes for display specifications. */
4986 location
= Qunbound
;
4987 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4991 value
= XCDR (spec
);
4993 value
= XCAR (value
);
4996 if (EQ (XCAR (tem
), Qmargin
)
4997 && (tem
= XCDR (tem
),
4998 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5000 || EQ (tem
, Qleft_margin
)
5001 || EQ (tem
, Qright_margin
))))
5005 if (EQ (location
, Qunbound
))
5011 /* After this point, VALUE is the property after any
5012 margin prefix has been stripped. It must be a string,
5013 an image specification, or `(space ...)'.
5015 LOCATION specifies where to display: `left-margin',
5016 `right-margin' or nil. */
5018 valid_p
= (STRINGP (value
)
5019 #ifdef HAVE_WINDOW_SYSTEM
5020 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5021 && valid_image_p (value
))
5022 #endif /* not HAVE_WINDOW_SYSTEM */
5023 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5025 if (valid_p
&& !display_replaced_p
)
5031 /* Callers need to know whether the display spec is any kind
5032 of `(space ...)' spec that is about to affect text-area
5034 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5039 /* Save current settings of IT so that we can restore them
5040 when we are finished with the glyph property value. */
5041 push_it (it
, position
);
5042 it
->from_overlay
= overlay
;
5043 it
->from_disp_prop_p
= true;
5045 if (NILP (location
))
5046 it
->area
= TEXT_AREA
;
5047 else if (EQ (location
, Qleft_margin
))
5048 it
->area
= LEFT_MARGIN_AREA
;
5050 it
->area
= RIGHT_MARGIN_AREA
;
5052 if (STRINGP (value
))
5055 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5056 it
->current
.overlay_string_index
= -1;
5057 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5058 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5059 it
->method
= GET_FROM_STRING
;
5060 it
->stop_charpos
= 0;
5062 it
->base_level_stop
= 0;
5063 it
->string_from_display_prop_p
= true;
5064 /* Say that we haven't consumed the characters with
5065 `display' property yet. The call to pop_it in
5066 set_iterator_to_next will clean this up. */
5067 if (BUFFERP (object
))
5068 *position
= start_pos
;
5070 /* Force paragraph direction to be that of the parent
5071 object. If the parent object's paragraph direction is
5072 not yet determined, default to L2R. */
5073 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5074 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5076 it
->paragraph_embedding
= L2R
;
5078 /* Set up the bidi iterator for this display string. */
5081 it
->bidi_it
.string
.lstring
= it
->string
;
5082 it
->bidi_it
.string
.s
= NULL
;
5083 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5084 it
->bidi_it
.string
.bufpos
= bufpos
;
5085 it
->bidi_it
.string
.from_disp_str
= 1;
5086 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5087 it
->bidi_it
.w
= it
->w
;
5088 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5091 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5093 it
->method
= GET_FROM_STRETCH
;
5095 *position
= it
->position
= start_pos
;
5096 retval
= 1 + (it
->area
== TEXT_AREA
);
5098 #ifdef HAVE_WINDOW_SYSTEM
5101 it
->what
= IT_IMAGE
;
5102 it
->image_id
= lookup_image (it
->f
, value
);
5103 it
->position
= start_pos
;
5104 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5105 it
->method
= GET_FROM_IMAGE
;
5107 /* Say that we haven't consumed the characters with
5108 `display' property yet. The call to pop_it in
5109 set_iterator_to_next will clean this up. */
5110 *position
= start_pos
;
5112 #endif /* HAVE_WINDOW_SYSTEM */
5117 /* Invalid property or property not supported. Restore
5118 POSITION to what it was before. */
5119 *position
= start_pos
;
5123 /* Check if PROP is a display property value whose text should be
5124 treated as intangible. OVERLAY is the overlay from which PROP
5125 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5126 specify the buffer position covered by PROP. */
5129 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5130 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5132 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5133 struct text_pos position
;
5135 SET_TEXT_POS (position
, charpos
, bytepos
);
5136 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5137 &position
, charpos
, frame_window_p
);
5141 /* Return 1 if PROP is a display sub-property value containing STRING.
5143 Implementation note: this and the following function are really
5144 special cases of handle_display_spec and
5145 handle_single_display_spec, and should ideally use the same code.
5146 Until they do, these two pairs must be consistent and must be
5147 modified in sync. */
5150 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5152 if (EQ (string
, prop
))
5155 /* Skip over `when FORM'. */
5156 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5161 /* Actually, the condition following `when' should be eval'ed,
5162 like handle_single_display_spec does, and we should return
5163 zero if it evaluates to nil. However, this function is
5164 called only when the buffer was already displayed and some
5165 glyph in the glyph matrix was found to come from a display
5166 string. Therefore, the condition was already evaluated, and
5167 the result was non-nil, otherwise the display string wouldn't
5168 have been displayed and we would have never been called for
5169 this property. Thus, we can skip the evaluation and assume
5170 its result is non-nil. */
5175 /* Skip over `margin LOCATION'. */
5176 if (EQ (XCAR (prop
), Qmargin
))
5187 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5191 /* Return 1 if STRING appears in the `display' property PROP. */
5194 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5197 && !EQ (XCAR (prop
), Qwhen
)
5198 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5200 /* A list of sub-properties. */
5201 while (CONSP (prop
))
5203 if (single_display_spec_string_p (XCAR (prop
), string
))
5208 else if (VECTORP (prop
))
5210 /* A vector of sub-properties. */
5212 for (i
= 0; i
< ASIZE (prop
); ++i
)
5213 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5217 return single_display_spec_string_p (prop
, string
);
5222 /* Look for STRING in overlays and text properties in the current
5223 buffer, between character positions FROM and TO (excluding TO).
5224 BACK_P non-zero means look back (in this case, TO is supposed to be
5226 Value is the first character position where STRING was found, or
5227 zero if it wasn't found before hitting TO.
5229 This function may only use code that doesn't eval because it is
5230 called asynchronously from note_mouse_highlight. */
5233 string_buffer_position_lim (Lisp_Object string
,
5234 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5236 Lisp_Object limit
, prop
, pos
;
5239 pos
= make_number (max (from
, BEGV
));
5241 if (!back_p
) /* looking forward */
5243 limit
= make_number (min (to
, ZV
));
5244 while (!found
&& !EQ (pos
, limit
))
5246 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5247 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5250 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5254 else /* looking back */
5256 limit
= make_number (max (to
, BEGV
));
5257 while (!found
&& !EQ (pos
, limit
))
5259 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5260 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5263 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5268 return found
? XINT (pos
) : 0;
5271 /* Determine which buffer position in current buffer STRING comes from.
5272 AROUND_CHARPOS is an approximate position where it could come from.
5273 Value is the buffer position or 0 if it couldn't be determined.
5275 This function is necessary because we don't record buffer positions
5276 in glyphs generated from strings (to keep struct glyph small).
5277 This function may only use code that doesn't eval because it is
5278 called asynchronously from note_mouse_highlight. */
5281 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5283 const int MAX_DISTANCE
= 1000;
5284 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5285 around_charpos
+ MAX_DISTANCE
,
5289 found
= string_buffer_position_lim (string
, around_charpos
,
5290 around_charpos
- MAX_DISTANCE
, 1);
5296 /***********************************************************************
5297 `composition' property
5298 ***********************************************************************/
5300 /* Set up iterator IT from `composition' property at its current
5301 position. Called from handle_stop. */
5303 static enum prop_handled
5304 handle_composition_prop (struct it
*it
)
5306 Lisp_Object prop
, string
;
5307 ptrdiff_t pos
, pos_byte
, start
, end
;
5309 if (STRINGP (it
->string
))
5313 pos
= IT_STRING_CHARPOS (*it
);
5314 pos_byte
= IT_STRING_BYTEPOS (*it
);
5315 string
= it
->string
;
5316 s
= SDATA (string
) + pos_byte
;
5317 it
->c
= STRING_CHAR (s
);
5321 pos
= IT_CHARPOS (*it
);
5322 pos_byte
= IT_BYTEPOS (*it
);
5324 it
->c
= FETCH_CHAR (pos_byte
);
5327 /* If there's a valid composition and point is not inside of the
5328 composition (in the case that the composition is from the current
5329 buffer), draw a glyph composed from the composition components. */
5330 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5331 && composition_valid_p (start
, end
, prop
)
5332 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5335 /* As we can't handle this situation (perhaps font-lock added
5336 a new composition), we just return here hoping that next
5337 redisplay will detect this composition much earlier. */
5338 return HANDLED_NORMALLY
;
5341 if (STRINGP (it
->string
))
5342 pos_byte
= string_char_to_byte (it
->string
, start
);
5344 pos_byte
= CHAR_TO_BYTE (start
);
5346 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5349 if (it
->cmp_it
.id
>= 0)
5352 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5353 it
->cmp_it
.nglyphs
= -1;
5357 return HANDLED_NORMALLY
;
5362 /***********************************************************************
5364 ***********************************************************************/
5366 /* The following structure is used to record overlay strings for
5367 later sorting in load_overlay_strings. */
5369 struct overlay_entry
5371 Lisp_Object overlay
;
5378 /* Set up iterator IT from overlay strings at its current position.
5379 Called from handle_stop. */
5381 static enum prop_handled
5382 handle_overlay_change (struct it
*it
)
5384 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5385 return HANDLED_RECOMPUTE_PROPS
;
5387 return HANDLED_NORMALLY
;
5391 /* Set up the next overlay string for delivery by IT, if there is an
5392 overlay string to deliver. Called by set_iterator_to_next when the
5393 end of the current overlay string is reached. If there are more
5394 overlay strings to display, IT->string and
5395 IT->current.overlay_string_index are set appropriately here.
5396 Otherwise IT->string is set to nil. */
5399 next_overlay_string (struct it
*it
)
5401 ++it
->current
.overlay_string_index
;
5402 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5404 /* No more overlay strings. Restore IT's settings to what
5405 they were before overlay strings were processed, and
5406 continue to deliver from current_buffer. */
5408 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5411 || (NILP (it
->string
)
5412 && it
->method
== GET_FROM_BUFFER
5413 && it
->stop_charpos
>= BEGV
5414 && it
->stop_charpos
<= it
->end_charpos
));
5415 it
->current
.overlay_string_index
= -1;
5416 it
->n_overlay_strings
= 0;
5417 it
->overlay_strings_charpos
= -1;
5418 /* If there's an empty display string on the stack, pop the
5419 stack, to resync the bidi iterator with IT's position. Such
5420 empty strings are pushed onto the stack in
5421 get_overlay_strings_1. */
5422 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5425 /* If we're at the end of the buffer, record that we have
5426 processed the overlay strings there already, so that
5427 next_element_from_buffer doesn't try it again. */
5428 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5429 it
->overlay_strings_at_end_processed_p
= true;
5433 /* There are more overlay strings to process. If
5434 IT->current.overlay_string_index has advanced to a position
5435 where we must load IT->overlay_strings with more strings, do
5436 it. We must load at the IT->overlay_strings_charpos where
5437 IT->n_overlay_strings was originally computed; when invisible
5438 text is present, this might not be IT_CHARPOS (Bug#7016). */
5439 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5441 if (it
->current
.overlay_string_index
&& i
== 0)
5442 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5444 /* Initialize IT to deliver display elements from the overlay
5446 it
->string
= it
->overlay_strings
[i
];
5447 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5448 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5449 it
->method
= GET_FROM_STRING
;
5450 it
->stop_charpos
= 0;
5451 it
->end_charpos
= SCHARS (it
->string
);
5452 if (it
->cmp_it
.stop_pos
>= 0)
5453 it
->cmp_it
.stop_pos
= 0;
5455 it
->base_level_stop
= 0;
5457 /* Set up the bidi iterator for this overlay string. */
5460 it
->bidi_it
.string
.lstring
= it
->string
;
5461 it
->bidi_it
.string
.s
= NULL
;
5462 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5463 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5464 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5465 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5466 it
->bidi_it
.w
= it
->w
;
5467 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5475 /* Compare two overlay_entry structures E1 and E2. Used as a
5476 comparison function for qsort in load_overlay_strings. Overlay
5477 strings for the same position are sorted so that
5479 1. All after-strings come in front of before-strings, except
5480 when they come from the same overlay.
5482 2. Within after-strings, strings are sorted so that overlay strings
5483 from overlays with higher priorities come first.
5485 2. Within before-strings, strings are sorted so that overlay
5486 strings from overlays with higher priorities come last.
5488 Value is analogous to strcmp. */
5492 compare_overlay_entries (const void *e1
, const void *e2
)
5494 struct overlay_entry
const *entry1
= e1
;
5495 struct overlay_entry
const *entry2
= e2
;
5498 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5500 /* Let after-strings appear in front of before-strings if
5501 they come from different overlays. */
5502 if (EQ (entry1
->overlay
, entry2
->overlay
))
5503 result
= entry1
->after_string_p
? 1 : -1;
5505 result
= entry1
->after_string_p
? -1 : 1;
5507 else if (entry1
->priority
!= entry2
->priority
)
5509 if (entry1
->after_string_p
)
5510 /* After-strings sorted in order of decreasing priority. */
5511 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5513 /* Before-strings sorted in order of increasing priority. */
5514 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5523 /* Load the vector IT->overlay_strings with overlay strings from IT's
5524 current buffer position, or from CHARPOS if that is > 0. Set
5525 IT->n_overlays to the total number of overlay strings found.
5527 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5528 a time. On entry into load_overlay_strings,
5529 IT->current.overlay_string_index gives the number of overlay
5530 strings that have already been loaded by previous calls to this
5533 IT->add_overlay_start contains an additional overlay start
5534 position to consider for taking overlay strings from, if non-zero.
5535 This position comes into play when the overlay has an `invisible'
5536 property, and both before and after-strings. When we've skipped to
5537 the end of the overlay, because of its `invisible' property, we
5538 nevertheless want its before-string to appear.
5539 IT->add_overlay_start will contain the overlay start position
5542 Overlay strings are sorted so that after-string strings come in
5543 front of before-string strings. Within before and after-strings,
5544 strings are sorted by overlay priority. See also function
5545 compare_overlay_entries. */
5548 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5550 Lisp_Object overlay
, window
, str
, invisible
;
5551 struct Lisp_Overlay
*ov
;
5552 ptrdiff_t start
, end
;
5553 ptrdiff_t size
= 20;
5554 ptrdiff_t n
= 0, i
, j
;
5556 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5560 charpos
= IT_CHARPOS (*it
);
5562 /* Append the overlay string STRING of overlay OVERLAY to vector
5563 `entries' which has size `size' and currently contains `n'
5564 elements. AFTER_P non-zero means STRING is an after-string of
5566 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5569 Lisp_Object priority; \
5573 struct overlay_entry *old = entries; \
5574 SAFE_NALLOCA (entries, 2, size); \
5575 memcpy (entries, old, size * sizeof *entries); \
5579 entries[n].string = (STRING); \
5580 entries[n].overlay = (OVERLAY); \
5581 priority = Foverlay_get ((OVERLAY), Qpriority); \
5582 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5583 entries[n].after_string_p = (AFTER_P); \
5588 /* Process overlay before the overlay center. */
5589 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5591 XSETMISC (overlay
, ov
);
5592 eassert (OVERLAYP (overlay
));
5593 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5594 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5599 /* Skip this overlay if it doesn't start or end at IT's current
5601 if (end
!= charpos
&& start
!= charpos
)
5604 /* Skip this overlay if it doesn't apply to IT->w. */
5605 window
= Foverlay_get (overlay
, Qwindow
);
5606 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5609 /* If the text ``under'' the overlay is invisible, both before-
5610 and after-strings from this overlay are visible; start and
5611 end position are indistinguishable. */
5612 invisible
= Foverlay_get (overlay
, Qinvisible
);
5613 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5615 /* If overlay has a non-empty before-string, record it. */
5616 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5617 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5619 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5621 /* If overlay has a non-empty after-string, record it. */
5622 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5623 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5625 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5628 /* Process overlays after the overlay center. */
5629 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5631 XSETMISC (overlay
, ov
);
5632 eassert (OVERLAYP (overlay
));
5633 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5634 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5636 if (start
> charpos
)
5639 /* Skip this overlay if it doesn't start or end at IT's current
5641 if (end
!= charpos
&& start
!= charpos
)
5644 /* Skip this overlay if it doesn't apply to IT->w. */
5645 window
= Foverlay_get (overlay
, Qwindow
);
5646 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5649 /* If the text ``under'' the overlay is invisible, it has a zero
5650 dimension, and both before- and after-strings apply. */
5651 invisible
= Foverlay_get (overlay
, Qinvisible
);
5652 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5654 /* If overlay has a non-empty before-string, record it. */
5655 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5656 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5658 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5660 /* If overlay has a non-empty after-string, record it. */
5661 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5662 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5664 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5667 #undef RECORD_OVERLAY_STRING
5671 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5673 /* Record number of overlay strings, and where we computed it. */
5674 it
->n_overlay_strings
= n
;
5675 it
->overlay_strings_charpos
= charpos
;
5677 /* IT->current.overlay_string_index is the number of overlay strings
5678 that have already been consumed by IT. Copy some of the
5679 remaining overlay strings to IT->overlay_strings. */
5681 j
= it
->current
.overlay_string_index
;
5682 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5684 it
->overlay_strings
[i
] = entries
[j
].string
;
5685 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5693 /* Get the first chunk of overlay strings at IT's current buffer
5694 position, or at CHARPOS if that is > 0. Value is non-zero if at
5695 least one overlay string was found. */
5698 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5700 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5701 process. This fills IT->overlay_strings with strings, and sets
5702 IT->n_overlay_strings to the total number of strings to process.
5703 IT->pos.overlay_string_index has to be set temporarily to zero
5704 because load_overlay_strings needs this; it must be set to -1
5705 when no overlay strings are found because a zero value would
5706 indicate a position in the first overlay string. */
5707 it
->current
.overlay_string_index
= 0;
5708 load_overlay_strings (it
, charpos
);
5710 /* If we found overlay strings, set up IT to deliver display
5711 elements from the first one. Otherwise set up IT to deliver
5712 from current_buffer. */
5713 if (it
->n_overlay_strings
)
5715 /* Make sure we know settings in current_buffer, so that we can
5716 restore meaningful values when we're done with the overlay
5719 compute_stop_pos (it
);
5720 eassert (it
->face_id
>= 0);
5722 /* Save IT's settings. They are restored after all overlay
5723 strings have been processed. */
5724 eassert (!compute_stop_p
|| it
->sp
== 0);
5726 /* When called from handle_stop, there might be an empty display
5727 string loaded. In that case, don't bother saving it. But
5728 don't use this optimization with the bidi iterator, since we
5729 need the corresponding pop_it call to resync the bidi
5730 iterator's position with IT's position, after we are done
5731 with the overlay strings. (The corresponding call to pop_it
5732 in case of an empty display string is in
5733 next_overlay_string.) */
5735 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5738 /* Set up IT to deliver display elements from the first overlay
5740 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5741 it
->string
= it
->overlay_strings
[0];
5742 it
->from_overlay
= Qnil
;
5743 it
->stop_charpos
= 0;
5744 eassert (STRINGP (it
->string
));
5745 it
->end_charpos
= SCHARS (it
->string
);
5747 it
->base_level_stop
= 0;
5748 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5749 it
->method
= GET_FROM_STRING
;
5750 it
->from_disp_prop_p
= 0;
5752 /* Force paragraph direction to be that of the parent
5754 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5755 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5757 it
->paragraph_embedding
= L2R
;
5759 /* Set up the bidi iterator for this overlay string. */
5762 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5764 it
->bidi_it
.string
.lstring
= it
->string
;
5765 it
->bidi_it
.string
.s
= NULL
;
5766 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5767 it
->bidi_it
.string
.bufpos
= pos
;
5768 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5769 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5770 it
->bidi_it
.w
= it
->w
;
5771 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5776 it
->current
.overlay_string_index
= -1;
5781 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5784 it
->method
= GET_FROM_BUFFER
;
5786 (void) get_overlay_strings_1 (it
, charpos
, 1);
5790 /* Value is non-zero if we found at least one overlay string. */
5791 return STRINGP (it
->string
);
5796 /***********************************************************************
5797 Saving and restoring state
5798 ***********************************************************************/
5800 /* Save current settings of IT on IT->stack. Called, for example,
5801 before setting up IT for an overlay string, to be able to restore
5802 IT's settings to what they were after the overlay string has been
5803 processed. If POSITION is non-NULL, it is the position to save on
5804 the stack instead of IT->position. */
5807 push_it (struct it
*it
, struct text_pos
*position
)
5809 struct iterator_stack_entry
*p
;
5811 eassert (it
->sp
< IT_STACK_SIZE
);
5812 p
= it
->stack
+ it
->sp
;
5814 p
->stop_charpos
= it
->stop_charpos
;
5815 p
->prev_stop
= it
->prev_stop
;
5816 p
->base_level_stop
= it
->base_level_stop
;
5817 p
->cmp_it
= it
->cmp_it
;
5818 eassert (it
->face_id
>= 0);
5819 p
->face_id
= it
->face_id
;
5820 p
->string
= it
->string
;
5821 p
->method
= it
->method
;
5822 p
->from_overlay
= it
->from_overlay
;
5825 case GET_FROM_IMAGE
:
5826 p
->u
.image
.object
= it
->object
;
5827 p
->u
.image
.image_id
= it
->image_id
;
5828 p
->u
.image
.slice
= it
->slice
;
5830 case GET_FROM_STRETCH
:
5831 p
->u
.stretch
.object
= it
->object
;
5834 p
->position
= position
? *position
: it
->position
;
5835 p
->current
= it
->current
;
5836 p
->end_charpos
= it
->end_charpos
;
5837 p
->string_nchars
= it
->string_nchars
;
5839 p
->multibyte_p
= it
->multibyte_p
;
5840 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5841 p
->space_width
= it
->space_width
;
5842 p
->font_height
= it
->font_height
;
5843 p
->voffset
= it
->voffset
;
5844 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5845 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5846 p
->display_ellipsis_p
= 0;
5847 p
->line_wrap
= it
->line_wrap
;
5848 p
->bidi_p
= it
->bidi_p
;
5849 p
->paragraph_embedding
= it
->paragraph_embedding
;
5850 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5853 /* Save the state of the bidi iterator as well. */
5855 bidi_push_it (&it
->bidi_it
);
5859 iterate_out_of_display_property (struct it
*it
)
5861 int buffer_p
= !STRINGP (it
->string
);
5862 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5863 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5865 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5867 /* Maybe initialize paragraph direction. If we are at the beginning
5868 of a new paragraph, next_element_from_buffer may not have a
5869 chance to do that. */
5870 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5871 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5872 /* prev_stop can be zero, so check against BEGV as well. */
5873 while (it
->bidi_it
.charpos
>= bob
5874 && it
->prev_stop
<= it
->bidi_it
.charpos
5875 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5876 && it
->bidi_it
.charpos
< eob
)
5877 bidi_move_to_visually_next (&it
->bidi_it
);
5878 /* Record the stop_pos we just crossed, for when we cross it
5880 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5881 it
->prev_stop
= CHARPOS (it
->position
);
5882 /* If we ended up not where pop_it put us, resync IT's
5883 positional members with the bidi iterator. */
5884 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5885 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5887 it
->current
.pos
= it
->position
;
5889 it
->current
.string_pos
= it
->position
;
5892 /* Restore IT's settings from IT->stack. Called, for example, when no
5893 more overlay strings must be processed, and we return to delivering
5894 display elements from a buffer, or when the end of a string from a
5895 `display' property is reached and we return to delivering display
5896 elements from an overlay string, or from a buffer. */
5899 pop_it (struct it
*it
)
5901 struct iterator_stack_entry
*p
;
5902 int from_display_prop
= it
->from_disp_prop_p
;
5904 eassert (it
->sp
> 0);
5906 p
= it
->stack
+ it
->sp
;
5907 it
->stop_charpos
= p
->stop_charpos
;
5908 it
->prev_stop
= p
->prev_stop
;
5909 it
->base_level_stop
= p
->base_level_stop
;
5910 it
->cmp_it
= p
->cmp_it
;
5911 it
->face_id
= p
->face_id
;
5912 it
->current
= p
->current
;
5913 it
->position
= p
->position
;
5914 it
->string
= p
->string
;
5915 it
->from_overlay
= p
->from_overlay
;
5916 if (NILP (it
->string
))
5917 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5918 it
->method
= p
->method
;
5921 case GET_FROM_IMAGE
:
5922 it
->image_id
= p
->u
.image
.image_id
;
5923 it
->object
= p
->u
.image
.object
;
5924 it
->slice
= p
->u
.image
.slice
;
5926 case GET_FROM_STRETCH
:
5927 it
->object
= p
->u
.stretch
.object
;
5929 case GET_FROM_BUFFER
:
5930 it
->object
= it
->w
->contents
;
5932 case GET_FROM_STRING
:
5933 it
->object
= it
->string
;
5935 case GET_FROM_DISPLAY_VECTOR
:
5937 it
->method
= GET_FROM_C_STRING
;
5938 else if (STRINGP (it
->string
))
5939 it
->method
= GET_FROM_STRING
;
5942 it
->method
= GET_FROM_BUFFER
;
5943 it
->object
= it
->w
->contents
;
5946 it
->end_charpos
= p
->end_charpos
;
5947 it
->string_nchars
= p
->string_nchars
;
5949 it
->multibyte_p
= p
->multibyte_p
;
5950 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5951 it
->space_width
= p
->space_width
;
5952 it
->font_height
= p
->font_height
;
5953 it
->voffset
= p
->voffset
;
5954 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5955 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5956 it
->line_wrap
= p
->line_wrap
;
5957 it
->bidi_p
= p
->bidi_p
;
5958 it
->paragraph_embedding
= p
->paragraph_embedding
;
5959 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5962 bidi_pop_it (&it
->bidi_it
);
5963 /* Bidi-iterate until we get out of the portion of text, if any,
5964 covered by a `display' text property or by an overlay with
5965 `display' property. (We cannot just jump there, because the
5966 internal coherency of the bidi iterator state can not be
5967 preserved across such jumps.) We also must determine the
5968 paragraph base direction if the overlay we just processed is
5969 at the beginning of a new paragraph. */
5970 if (from_display_prop
5971 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5972 iterate_out_of_display_property (it
);
5974 eassert ((BUFFERP (it
->object
)
5975 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5976 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5977 || (STRINGP (it
->object
)
5978 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5979 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5980 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5986 /***********************************************************************
5988 ***********************************************************************/
5990 /* Set IT's current position to the previous line start. */
5993 back_to_previous_line_start (struct it
*it
)
5995 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
5998 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6002 /* Move IT to the next line start.
6004 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6005 we skipped over part of the text (as opposed to moving the iterator
6006 continuously over the text). Otherwise, don't change the value
6009 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6010 iterator on the newline, if it was found.
6012 Newlines may come from buffer text, overlay strings, or strings
6013 displayed via the `display' property. That's the reason we can't
6014 simply use find_newline_no_quit.
6016 Note that this function may not skip over invisible text that is so
6017 because of text properties and immediately follows a newline. If
6018 it would, function reseat_at_next_visible_line_start, when called
6019 from set_iterator_to_next, would effectively make invisible
6020 characters following a newline part of the wrong glyph row, which
6021 leads to wrong cursor motion. */
6024 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6025 struct bidi_it
*bidi_it_prev
)
6027 ptrdiff_t old_selective
;
6028 int newline_found_p
, n
;
6029 const int MAX_NEWLINE_DISTANCE
= 500;
6031 /* If already on a newline, just consume it to avoid unintended
6032 skipping over invisible text below. */
6033 if (it
->what
== IT_CHARACTER
6035 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6037 if (it
->bidi_p
&& bidi_it_prev
)
6038 *bidi_it_prev
= it
->bidi_it
;
6039 set_iterator_to_next (it
, 0);
6044 /* Don't handle selective display in the following. It's (a)
6045 unnecessary because it's done by the caller, and (b) leads to an
6046 infinite recursion because next_element_from_ellipsis indirectly
6047 calls this function. */
6048 old_selective
= it
->selective
;
6051 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6052 from buffer text. */
6053 for (n
= newline_found_p
= 0;
6054 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6055 n
+= STRINGP (it
->string
) ? 0 : 1)
6057 if (!get_next_display_element (it
))
6059 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6060 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6061 *bidi_it_prev
= it
->bidi_it
;
6062 set_iterator_to_next (it
, 0);
6065 /* If we didn't find a newline near enough, see if we can use a
6067 if (!newline_found_p
)
6069 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6070 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6074 eassert (!STRINGP (it
->string
));
6076 /* If there isn't any `display' property in sight, and no
6077 overlays, we can just use the position of the newline in
6079 if (it
->stop_charpos
>= limit
6080 || ((pos
= Fnext_single_property_change (make_number (start
),
6082 make_number (limit
)),
6084 && next_overlay_change (start
) == ZV
))
6088 IT_CHARPOS (*it
) = limit
;
6089 IT_BYTEPOS (*it
) = bytepos
;
6093 struct bidi_it bprev
;
6095 /* Help bidi.c avoid expensive searches for display
6096 properties and overlays, by telling it that there are
6097 none up to `limit'. */
6098 if (it
->bidi_it
.disp_pos
< limit
)
6100 it
->bidi_it
.disp_pos
= limit
;
6101 it
->bidi_it
.disp_prop
= 0;
6104 bprev
= it
->bidi_it
;
6105 bidi_move_to_visually_next (&it
->bidi_it
);
6106 } while (it
->bidi_it
.charpos
!= limit
);
6107 IT_CHARPOS (*it
) = limit
;
6108 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6110 *bidi_it_prev
= bprev
;
6112 *skipped_p
= newline_found_p
= true;
6116 while (get_next_display_element (it
)
6117 && !newline_found_p
)
6119 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6120 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6121 *bidi_it_prev
= it
->bidi_it
;
6122 set_iterator_to_next (it
, 0);
6127 it
->selective
= old_selective
;
6128 return newline_found_p
;
6132 /* Set IT's current position to the previous visible line start. Skip
6133 invisible text that is so either due to text properties or due to
6134 selective display. Caution: this does not change IT->current_x and
6138 back_to_previous_visible_line_start (struct it
*it
)
6140 while (IT_CHARPOS (*it
) > BEGV
)
6142 back_to_previous_line_start (it
);
6144 if (IT_CHARPOS (*it
) <= BEGV
)
6147 /* If selective > 0, then lines indented more than its value are
6149 if (it
->selective
> 0
6150 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6154 /* Check the newline before point for invisibility. */
6157 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6158 Qinvisible
, it
->window
);
6159 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6163 if (IT_CHARPOS (*it
) <= BEGV
)
6168 void *it2data
= NULL
;
6171 Lisp_Object val
, overlay
;
6173 SAVE_IT (it2
, *it
, it2data
);
6175 /* If newline is part of a composition, continue from start of composition */
6176 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6177 && beg
< IT_CHARPOS (*it
))
6180 /* If newline is replaced by a display property, find start of overlay
6181 or interval and continue search from that point. */
6182 pos
= --IT_CHARPOS (it2
);
6185 bidi_unshelve_cache (NULL
, 0);
6186 it2
.string_from_display_prop_p
= 0;
6187 it2
.from_disp_prop_p
= 0;
6188 if (handle_display_prop (&it2
) == HANDLED_RETURN
6189 && !NILP (val
= get_char_property_and_overlay
6190 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6191 && (OVERLAYP (overlay
)
6192 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6193 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6195 RESTORE_IT (it
, it
, it2data
);
6199 /* Newline is not replaced by anything -- so we are done. */
6200 RESTORE_IT (it
, it
, it2data
);
6206 IT_CHARPOS (*it
) = beg
;
6207 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6211 it
->continuation_lines_width
= 0;
6213 eassert (IT_CHARPOS (*it
) >= BEGV
);
6214 eassert (IT_CHARPOS (*it
) == BEGV
6215 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6220 /* Reseat iterator IT at the previous visible line start. Skip
6221 invisible text that is so either due to text properties or due to
6222 selective display. At the end, update IT's overlay information,
6223 face information etc. */
6226 reseat_at_previous_visible_line_start (struct it
*it
)
6228 back_to_previous_visible_line_start (it
);
6229 reseat (it
, it
->current
.pos
, 1);
6234 /* Reseat iterator IT on the next visible line start in the current
6235 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6236 preceding the line start. Skip over invisible text that is so
6237 because of selective display. Compute faces, overlays etc at the
6238 new position. Note that this function does not skip over text that
6239 is invisible because of text properties. */
6242 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6244 int newline_found_p
, skipped_p
= 0;
6245 struct bidi_it bidi_it_prev
;
6247 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6249 /* Skip over lines that are invisible because they are indented
6250 more than the value of IT->selective. */
6251 if (it
->selective
> 0)
6252 while (IT_CHARPOS (*it
) < ZV
6253 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6256 eassert (IT_BYTEPOS (*it
) == BEGV
6257 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6259 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6262 /* Position on the newline if that's what's requested. */
6263 if (on_newline_p
&& newline_found_p
)
6265 if (STRINGP (it
->string
))
6267 if (IT_STRING_CHARPOS (*it
) > 0)
6271 --IT_STRING_CHARPOS (*it
);
6272 --IT_STRING_BYTEPOS (*it
);
6276 /* We need to restore the bidi iterator to the state
6277 it had on the newline, and resync the IT's
6278 position with that. */
6279 it
->bidi_it
= bidi_it_prev
;
6280 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6281 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6285 else if (IT_CHARPOS (*it
) > BEGV
)
6294 /* We need to restore the bidi iterator to the state it
6295 had on the newline and resync IT with that. */
6296 it
->bidi_it
= bidi_it_prev
;
6297 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6298 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6300 reseat (it
, it
->current
.pos
, 0);
6304 reseat (it
, it
->current
.pos
, 0);
6311 /***********************************************************************
6312 Changing an iterator's position
6313 ***********************************************************************/
6315 /* Change IT's current position to POS in current_buffer. If FORCE_P
6316 is non-zero, always check for text properties at the new position.
6317 Otherwise, text properties are only looked up if POS >=
6318 IT->check_charpos of a property. */
6321 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6323 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6325 reseat_1 (it
, pos
, 0);
6327 /* Determine where to check text properties. Avoid doing it
6328 where possible because text property lookup is very expensive. */
6330 || CHARPOS (pos
) > it
->stop_charpos
6331 || CHARPOS (pos
) < original_pos
)
6335 /* For bidi iteration, we need to prime prev_stop and
6336 base_level_stop with our best estimations. */
6337 /* Implementation note: Of course, POS is not necessarily a
6338 stop position, so assigning prev_pos to it is a lie; we
6339 should have called compute_stop_backwards. However, if
6340 the current buffer does not include any R2L characters,
6341 that call would be a waste of cycles, because the
6342 iterator will never move back, and thus never cross this
6343 "fake" stop position. So we delay that backward search
6344 until the time we really need it, in next_element_from_buffer. */
6345 if (CHARPOS (pos
) != it
->prev_stop
)
6346 it
->prev_stop
= CHARPOS (pos
);
6347 if (CHARPOS (pos
) < it
->base_level_stop
)
6348 it
->base_level_stop
= 0; /* meaning it's unknown */
6354 it
->prev_stop
= it
->base_level_stop
= 0;
6363 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6364 IT->stop_pos to POS, also. */
6367 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6369 /* Don't call this function when scanning a C string. */
6370 eassert (it
->s
== NULL
);
6372 /* POS must be a reasonable value. */
6373 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6375 it
->current
.pos
= it
->position
= pos
;
6376 it
->end_charpos
= ZV
;
6378 it
->current
.dpvec_index
= -1;
6379 it
->current
.overlay_string_index
= -1;
6380 IT_STRING_CHARPOS (*it
) = -1;
6381 IT_STRING_BYTEPOS (*it
) = -1;
6383 it
->method
= GET_FROM_BUFFER
;
6384 it
->object
= it
->w
->contents
;
6385 it
->area
= TEXT_AREA
;
6386 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6388 it
->string_from_display_prop_p
= 0;
6389 it
->string_from_prefix_prop_p
= 0;
6391 it
->from_disp_prop_p
= 0;
6392 it
->face_before_selective_p
= 0;
6395 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6397 bidi_unshelve_cache (NULL
, 0);
6398 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6399 it
->bidi_it
.string
.s
= NULL
;
6400 it
->bidi_it
.string
.lstring
= Qnil
;
6401 it
->bidi_it
.string
.bufpos
= 0;
6402 it
->bidi_it
.string
.unibyte
= 0;
6403 it
->bidi_it
.w
= it
->w
;
6408 it
->stop_charpos
= CHARPOS (pos
);
6409 it
->base_level_stop
= CHARPOS (pos
);
6411 /* This make the information stored in it->cmp_it invalidate. */
6416 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6417 If S is non-null, it is a C string to iterate over. Otherwise,
6418 STRING gives a Lisp string to iterate over.
6420 If PRECISION > 0, don't return more then PRECISION number of
6421 characters from the string.
6423 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6424 characters have been returned. FIELD_WIDTH < 0 means an infinite
6427 MULTIBYTE = 0 means disable processing of multibyte characters,
6428 MULTIBYTE > 0 means enable it,
6429 MULTIBYTE < 0 means use IT->multibyte_p.
6431 IT must be initialized via a prior call to init_iterator before
6432 calling this function. */
6435 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6436 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6439 /* No text property checks performed by default, but see below. */
6440 it
->stop_charpos
= -1;
6442 /* Set iterator position and end position. */
6443 memset (&it
->current
, 0, sizeof it
->current
);
6444 it
->current
.overlay_string_index
= -1;
6445 it
->current
.dpvec_index
= -1;
6446 eassert (charpos
>= 0);
6448 /* If STRING is specified, use its multibyteness, otherwise use the
6449 setting of MULTIBYTE, if specified. */
6451 it
->multibyte_p
= multibyte
> 0;
6453 /* Bidirectional reordering of strings is controlled by the default
6454 value of bidi-display-reordering. Don't try to reorder while
6455 loading loadup.el, as the necessary character property tables are
6456 not yet available. */
6459 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6463 eassert (STRINGP (string
));
6464 it
->string
= string
;
6466 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6467 it
->method
= GET_FROM_STRING
;
6468 it
->current
.string_pos
= string_pos (charpos
, string
);
6472 it
->bidi_it
.string
.lstring
= string
;
6473 it
->bidi_it
.string
.s
= NULL
;
6474 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6475 it
->bidi_it
.string
.bufpos
= 0;
6476 it
->bidi_it
.string
.from_disp_str
= 0;
6477 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6478 it
->bidi_it
.w
= it
->w
;
6479 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6480 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6485 it
->s
= (const unsigned char *) s
;
6488 /* Note that we use IT->current.pos, not it->current.string_pos,
6489 for displaying C strings. */
6490 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6491 if (it
->multibyte_p
)
6493 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6494 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6498 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6499 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6504 it
->bidi_it
.string
.lstring
= Qnil
;
6505 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6506 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6507 it
->bidi_it
.string
.bufpos
= 0;
6508 it
->bidi_it
.string
.from_disp_str
= 0;
6509 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6510 it
->bidi_it
.w
= it
->w
;
6511 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6514 it
->method
= GET_FROM_C_STRING
;
6517 /* PRECISION > 0 means don't return more than PRECISION characters
6519 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6521 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6523 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6526 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6527 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6528 FIELD_WIDTH < 0 means infinite field width. This is useful for
6529 padding with `-' at the end of a mode line. */
6530 if (field_width
< 0)
6531 field_width
= INFINITY
;
6532 /* Implementation note: We deliberately don't enlarge
6533 it->bidi_it.string.schars here to fit it->end_charpos, because
6534 the bidi iterator cannot produce characters out of thin air. */
6535 if (field_width
> it
->end_charpos
- charpos
)
6536 it
->end_charpos
= charpos
+ field_width
;
6538 /* Use the standard display table for displaying strings. */
6539 if (DISP_TABLE_P (Vstandard_display_table
))
6540 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6542 it
->stop_charpos
= charpos
;
6543 it
->prev_stop
= charpos
;
6544 it
->base_level_stop
= 0;
6547 it
->bidi_it
.first_elt
= 1;
6548 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6549 it
->bidi_it
.disp_pos
= -1;
6551 if (s
== NULL
&& it
->multibyte_p
)
6553 ptrdiff_t endpos
= SCHARS (it
->string
);
6554 if (endpos
> it
->end_charpos
)
6555 endpos
= it
->end_charpos
;
6556 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6564 /***********************************************************************
6566 ***********************************************************************/
6568 /* Map enum it_method value to corresponding next_element_from_* function. */
6570 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6572 next_element_from_buffer
,
6573 next_element_from_display_vector
,
6574 next_element_from_string
,
6575 next_element_from_c_string
,
6576 next_element_from_image
,
6577 next_element_from_stretch
6580 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6583 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6584 (possibly with the following characters). */
6586 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6587 ((IT)->cmp_it.id >= 0 \
6588 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6589 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6590 END_CHARPOS, (IT)->w, \
6591 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6595 /* Lookup the char-table Vglyphless_char_display for character C (-1
6596 if we want information for no-font case), and return the display
6597 method symbol. By side-effect, update it->what and
6598 it->glyphless_method. This function is called from
6599 get_next_display_element for each character element, and from
6600 x_produce_glyphs when no suitable font was found. */
6603 lookup_glyphless_char_display (int c
, struct it
*it
)
6605 Lisp_Object glyphless_method
= Qnil
;
6607 if (CHAR_TABLE_P (Vglyphless_char_display
)
6608 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6612 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6613 if (CONSP (glyphless_method
))
6614 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6615 ? XCAR (glyphless_method
)
6616 : XCDR (glyphless_method
);
6619 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6623 if (NILP (glyphless_method
))
6626 /* The default is to display the character by a proper font. */
6628 /* The default for the no-font case is to display an empty box. */
6629 glyphless_method
= Qempty_box
;
6631 if (EQ (glyphless_method
, Qzero_width
))
6634 return glyphless_method
;
6635 /* This method can't be used for the no-font case. */
6636 glyphless_method
= Qempty_box
;
6638 if (EQ (glyphless_method
, Qthin_space
))
6639 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6640 else if (EQ (glyphless_method
, Qempty_box
))
6641 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6642 else if (EQ (glyphless_method
, Qhex_code
))
6643 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6644 else if (STRINGP (glyphless_method
))
6645 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6648 /* Invalid value. We use the default method. */
6649 glyphless_method
= Qnil
;
6652 it
->what
= IT_GLYPHLESS
;
6653 return glyphless_method
;
6656 /* Merge escape glyph face and cache the result. */
6658 static struct frame
*last_escape_glyph_frame
= NULL
;
6659 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6660 static int last_escape_glyph_merged_face_id
= 0;
6663 merge_escape_glyph_face (struct it
*it
)
6667 if (it
->f
== last_escape_glyph_frame
6668 && it
->face_id
== last_escape_glyph_face_id
)
6669 face_id
= last_escape_glyph_merged_face_id
;
6672 /* Merge the `escape-glyph' face into the current face. */
6673 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6674 last_escape_glyph_frame
= it
->f
;
6675 last_escape_glyph_face_id
= it
->face_id
;
6676 last_escape_glyph_merged_face_id
= face_id
;
6681 /* Likewise for glyphless glyph face. */
6683 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6684 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6685 static int last_glyphless_glyph_merged_face_id
= 0;
6688 merge_glyphless_glyph_face (struct it
*it
)
6692 if (it
->f
== last_glyphless_glyph_frame
6693 && it
->face_id
== last_glyphless_glyph_face_id
)
6694 face_id
= last_glyphless_glyph_merged_face_id
;
6697 /* Merge the `glyphless-char' face into the current face. */
6698 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6699 last_glyphless_glyph_frame
= it
->f
;
6700 last_glyphless_glyph_face_id
= it
->face_id
;
6701 last_glyphless_glyph_merged_face_id
= face_id
;
6706 /* Load IT's display element fields with information about the next
6707 display element from the current position of IT. Value is zero if
6708 end of buffer (or C string) is reached. */
6711 get_next_display_element (struct it
*it
)
6713 /* Non-zero means that we found a display element. Zero means that
6714 we hit the end of what we iterate over. Performance note: the
6715 function pointer `method' used here turns out to be faster than
6716 using a sequence of if-statements. */
6720 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6722 if (it
->what
== IT_CHARACTER
)
6724 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6725 and only if (a) the resolved directionality of that character
6727 /* FIXME: Do we need an exception for characters from display
6729 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6730 it
->c
= bidi_mirror_char (it
->c
);
6731 /* Map via display table or translate control characters.
6732 IT->c, IT->len etc. have been set to the next character by
6733 the function call above. If we have a display table, and it
6734 contains an entry for IT->c, translate it. Don't do this if
6735 IT->c itself comes from a display table, otherwise we could
6736 end up in an infinite recursion. (An alternative could be to
6737 count the recursion depth of this function and signal an
6738 error when a certain maximum depth is reached.) Is it worth
6740 if (success_p
&& it
->dpvec
== NULL
)
6743 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6744 int nonascii_space_p
= 0;
6745 int nonascii_hyphen_p
= 0;
6746 int c
= it
->c
; /* This is the character to display. */
6748 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6750 eassert (SINGLE_BYTE_CHAR_P (c
));
6751 if (unibyte_display_via_language_environment
)
6753 c
= DECODE_CHAR (unibyte
, c
);
6755 c
= BYTE8_TO_CHAR (it
->c
);
6758 c
= BYTE8_TO_CHAR (it
->c
);
6762 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6765 struct Lisp_Vector
*v
= XVECTOR (dv
);
6767 /* Return the first character from the display table
6768 entry, if not empty. If empty, don't display the
6769 current character. */
6772 it
->dpvec_char_len
= it
->len
;
6773 it
->dpvec
= v
->contents
;
6774 it
->dpend
= v
->contents
+ v
->header
.size
;
6775 it
->current
.dpvec_index
= 0;
6776 it
->dpvec_face_id
= -1;
6777 it
->saved_face_id
= it
->face_id
;
6778 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6783 set_iterator_to_next (it
, 0);
6788 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6790 if (it
->what
== IT_GLYPHLESS
)
6792 /* Don't display this character. */
6793 set_iterator_to_next (it
, 0);
6797 /* If `nobreak-char-display' is non-nil, we display
6798 non-ASCII spaces and hyphens specially. */
6799 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6802 nonascii_space_p
= true;
6803 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6804 nonascii_hyphen_p
= true;
6807 /* Translate control characters into `\003' or `^C' form.
6808 Control characters coming from a display table entry are
6809 currently not translated because we use IT->dpvec to hold
6810 the translation. This could easily be changed but I
6811 don't believe that it is worth doing.
6813 The characters handled by `nobreak-char-display' must be
6816 Non-printable characters and raw-byte characters are also
6817 translated to octal form. */
6818 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6819 ? (it
->area
!= TEXT_AREA
6820 /* In mode line, treat \n, \t like other crl chars. */
6823 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6824 || (c
!= '\n' && c
!= '\t'))
6826 || nonascii_hyphen_p
6828 || ! CHAR_PRINTABLE_P (c
))))
6830 /* C is a control character, non-ASCII space/hyphen,
6831 raw-byte, or a non-printable character which must be
6832 displayed either as '\003' or as `^C' where the '\\'
6833 and '^' can be defined in the display table. Fill
6834 IT->ctl_chars with glyphs for what we have to
6835 display. Then, set IT->dpvec to these glyphs. */
6842 /* Handle control characters with ^. */
6844 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6848 g
= '^'; /* default glyph for Control */
6849 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6851 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6853 g
= GLYPH_CODE_CHAR (gc
);
6854 lface_id
= GLYPH_CODE_FACE (gc
);
6858 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6859 : merge_escape_glyph_face (it
));
6861 XSETINT (it
->ctl_chars
[0], g
);
6862 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6864 goto display_control
;
6867 /* Handle non-ascii space in the mode where it only gets
6870 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6872 /* Merge `nobreak-space' into the current face. */
6873 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6875 XSETINT (it
->ctl_chars
[0], ' ');
6877 goto display_control
;
6880 /* Handle sequences that start with the "escape glyph". */
6882 /* the default escape glyph is \. */
6883 escape_glyph
= '\\';
6886 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6888 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6889 lface_id
= GLYPH_CODE_FACE (gc
);
6893 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6894 : merge_escape_glyph_face (it
));
6896 /* Draw non-ASCII hyphen with just highlighting: */
6898 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6900 XSETINT (it
->ctl_chars
[0], '-');
6902 goto display_control
;
6905 /* Draw non-ASCII space/hyphen with escape glyph: */
6907 if (nonascii_space_p
|| nonascii_hyphen_p
)
6909 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6910 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6912 goto display_control
;
6919 if (CHAR_BYTE8_P (c
))
6920 /* Display \200 instead of \17777600. */
6921 c
= CHAR_TO_BYTE8 (c
);
6922 len
= sprintf (str
, "%03o", c
);
6924 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6925 for (i
= 0; i
< len
; i
++)
6926 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6931 /* Set up IT->dpvec and return first character from it. */
6932 it
->dpvec_char_len
= it
->len
;
6933 it
->dpvec
= it
->ctl_chars
;
6934 it
->dpend
= it
->dpvec
+ ctl_len
;
6935 it
->current
.dpvec_index
= 0;
6936 it
->dpvec_face_id
= face_id
;
6937 it
->saved_face_id
= it
->face_id
;
6938 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6942 it
->char_to_display
= c
;
6946 it
->char_to_display
= it
->c
;
6950 #ifdef HAVE_WINDOW_SYSTEM
6951 /* Adjust face id for a multibyte character. There are no multibyte
6952 character in unibyte text. */
6953 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6956 && FRAME_WINDOW_P (it
->f
))
6958 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6960 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6962 /* Automatic composition with glyph-string. */
6963 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6965 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6969 ptrdiff_t pos
= (it
->s
? -1
6970 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6971 : IT_CHARPOS (*it
));
6974 if (it
->what
== IT_CHARACTER
)
6975 c
= it
->char_to_display
;
6978 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6982 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6983 /* TAB in a composition means display glyphs with
6984 padding space on the left or right. */
6985 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6988 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6991 #endif /* HAVE_WINDOW_SYSTEM */
6994 /* Is this character the last one of a run of characters with
6995 box? If yes, set IT->end_of_box_run_p to 1. */
6999 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7001 int face_id
= underlying_face_id (it
);
7002 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7006 if (face
->box
== FACE_NO_BOX
)
7008 /* If the box comes from face properties in a
7009 display string, check faces in that string. */
7010 int string_face_id
= face_after_it_pos (it
);
7011 it
->end_of_box_run_p
7012 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7015 /* Otherwise, the box comes from the underlying face.
7016 If this is the last string character displayed, check
7017 the next buffer location. */
7018 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7019 && (it
->current
.overlay_string_index
7020 == it
->n_overlay_strings
- 1))
7024 struct text_pos pos
= it
->current
.pos
;
7025 INC_TEXT_POS (pos
, it
->multibyte_p
);
7027 next_face_id
= face_at_buffer_position
7028 (it
->w
, CHARPOS (pos
), &ignore
,
7029 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7031 it
->end_of_box_run_p
7032 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7037 /* next_element_from_display_vector sets this flag according to
7038 faces of the display vector glyphs, see there. */
7039 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7041 int face_id
= face_after_it_pos (it
);
7042 it
->end_of_box_run_p
7043 = (face_id
!= it
->face_id
7044 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7047 /* If we reached the end of the object we've been iterating (e.g., a
7048 display string or an overlay string), and there's something on
7049 IT->stack, proceed with what's on the stack. It doesn't make
7050 sense to return zero if there's unprocessed stuff on the stack,
7051 because otherwise that stuff will never be displayed. */
7052 if (!success_p
&& it
->sp
> 0)
7054 set_iterator_to_next (it
, 0);
7055 success_p
= get_next_display_element (it
);
7058 /* Value is 0 if end of buffer or string reached. */
7063 /* Move IT to the next display element.
7065 RESEAT_P non-zero means if called on a newline in buffer text,
7066 skip to the next visible line start.
7068 Functions get_next_display_element and set_iterator_to_next are
7069 separate because I find this arrangement easier to handle than a
7070 get_next_display_element function that also increments IT's
7071 position. The way it is we can first look at an iterator's current
7072 display element, decide whether it fits on a line, and if it does,
7073 increment the iterator position. The other way around we probably
7074 would either need a flag indicating whether the iterator has to be
7075 incremented the next time, or we would have to implement a
7076 decrement position function which would not be easy to write. */
7079 set_iterator_to_next (struct it
*it
, int reseat_p
)
7081 /* Reset flags indicating start and end of a sequence of characters
7082 with box. Reset them at the start of this function because
7083 moving the iterator to a new position might set them. */
7084 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7088 case GET_FROM_BUFFER
:
7089 /* The current display element of IT is a character from
7090 current_buffer. Advance in the buffer, and maybe skip over
7091 invisible lines that are so because of selective display. */
7092 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7093 reseat_at_next_visible_line_start (it
, 0);
7094 else if (it
->cmp_it
.id
>= 0)
7096 /* We are currently getting glyphs from a composition. */
7101 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7102 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7103 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7105 it
->cmp_it
.from
= it
->cmp_it
.to
;
7110 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7112 it
->end_charpos
, Qnil
);
7115 else if (! it
->cmp_it
.reversed_p
)
7117 /* Composition created while scanning forward. */
7118 /* Update IT's char/byte positions to point to the first
7119 character of the next grapheme cluster, or to the
7120 character visually after the current composition. */
7121 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7122 bidi_move_to_visually_next (&it
->bidi_it
);
7123 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7124 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7126 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7128 /* Proceed to the next grapheme cluster. */
7129 it
->cmp_it
.from
= it
->cmp_it
.to
;
7133 /* No more grapheme clusters in this composition.
7134 Find the next stop position. */
7135 ptrdiff_t stop
= it
->end_charpos
;
7136 if (it
->bidi_it
.scan_dir
< 0)
7137 /* Now we are scanning backward and don't know
7140 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7141 IT_BYTEPOS (*it
), stop
, Qnil
);
7146 /* Composition created while scanning backward. */
7147 /* Update IT's char/byte positions to point to the last
7148 character of the previous grapheme cluster, or the
7149 character visually after the current composition. */
7150 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7151 bidi_move_to_visually_next (&it
->bidi_it
);
7152 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7153 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7154 if (it
->cmp_it
.from
> 0)
7156 /* Proceed to the previous grapheme cluster. */
7157 it
->cmp_it
.to
= it
->cmp_it
.from
;
7161 /* No more grapheme clusters in this composition.
7162 Find the next stop position. */
7163 ptrdiff_t stop
= it
->end_charpos
;
7164 if (it
->bidi_it
.scan_dir
< 0)
7165 /* Now we are scanning backward and don't know
7168 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7169 IT_BYTEPOS (*it
), stop
, Qnil
);
7175 eassert (it
->len
!= 0);
7179 IT_BYTEPOS (*it
) += it
->len
;
7180 IT_CHARPOS (*it
) += 1;
7184 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7185 /* If this is a new paragraph, determine its base
7186 direction (a.k.a. its base embedding level). */
7187 if (it
->bidi_it
.new_paragraph
)
7188 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7189 bidi_move_to_visually_next (&it
->bidi_it
);
7190 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7191 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7192 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7194 /* As the scan direction was changed, we must
7195 re-compute the stop position for composition. */
7196 ptrdiff_t stop
= it
->end_charpos
;
7197 if (it
->bidi_it
.scan_dir
< 0)
7199 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7200 IT_BYTEPOS (*it
), stop
, Qnil
);
7203 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7207 case GET_FROM_C_STRING
:
7208 /* Current display element of IT is from a C string. */
7210 /* If the string position is beyond string's end, it means
7211 next_element_from_c_string is padding the string with
7212 blanks, in which case we bypass the bidi iterator,
7213 because it cannot deal with such virtual characters. */
7214 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7216 IT_BYTEPOS (*it
) += it
->len
;
7217 IT_CHARPOS (*it
) += 1;
7221 bidi_move_to_visually_next (&it
->bidi_it
);
7222 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7223 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7227 case GET_FROM_DISPLAY_VECTOR
:
7228 /* Current display element of IT is from a display table entry.
7229 Advance in the display table definition. Reset it to null if
7230 end reached, and continue with characters from buffers/
7232 ++it
->current
.dpvec_index
;
7234 /* Restore face of the iterator to what they were before the
7235 display vector entry (these entries may contain faces). */
7236 it
->face_id
= it
->saved_face_id
;
7238 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7240 int recheck_faces
= it
->ellipsis_p
;
7243 it
->method
= GET_FROM_C_STRING
;
7244 else if (STRINGP (it
->string
))
7245 it
->method
= GET_FROM_STRING
;
7248 it
->method
= GET_FROM_BUFFER
;
7249 it
->object
= it
->w
->contents
;
7253 it
->current
.dpvec_index
= -1;
7255 /* Skip over characters which were displayed via IT->dpvec. */
7256 if (it
->dpvec_char_len
< 0)
7257 reseat_at_next_visible_line_start (it
, 1);
7258 else if (it
->dpvec_char_len
> 0)
7260 if (it
->method
== GET_FROM_STRING
7261 && it
->current
.overlay_string_index
>= 0
7262 && it
->n_overlay_strings
> 0)
7263 it
->ignore_overlay_strings_at_pos_p
= true;
7264 it
->len
= it
->dpvec_char_len
;
7265 set_iterator_to_next (it
, reseat_p
);
7268 /* Maybe recheck faces after display vector. */
7270 it
->stop_charpos
= IT_CHARPOS (*it
);
7274 case GET_FROM_STRING
:
7275 /* Current display element is a character from a Lisp string. */
7276 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7277 /* Don't advance past string end. These conditions are true
7278 when set_iterator_to_next is called at the end of
7279 get_next_display_element, in which case the Lisp string is
7280 already exhausted, and all we want is pop the iterator
7282 if (it
->current
.overlay_string_index
>= 0)
7284 /* This is an overlay string, so there's no padding with
7285 spaces, and the number of characters in the string is
7286 where the string ends. */
7287 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7288 goto consider_string_end
;
7292 /* Not an overlay string. There could be padding, so test
7293 against it->end_charpos. */
7294 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7295 goto consider_string_end
;
7297 if (it
->cmp_it
.id
>= 0)
7303 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7304 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7305 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7306 it
->cmp_it
.from
= it
->cmp_it
.to
;
7310 composition_compute_stop_pos (&it
->cmp_it
,
7311 IT_STRING_CHARPOS (*it
),
7312 IT_STRING_BYTEPOS (*it
),
7313 it
->end_charpos
, it
->string
);
7316 else if (! it
->cmp_it
.reversed_p
)
7318 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7319 bidi_move_to_visually_next (&it
->bidi_it
);
7320 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7321 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7323 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7324 it
->cmp_it
.from
= it
->cmp_it
.to
;
7327 ptrdiff_t stop
= it
->end_charpos
;
7328 if (it
->bidi_it
.scan_dir
< 0)
7330 composition_compute_stop_pos (&it
->cmp_it
,
7331 IT_STRING_CHARPOS (*it
),
7332 IT_STRING_BYTEPOS (*it
), stop
,
7338 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7339 bidi_move_to_visually_next (&it
->bidi_it
);
7340 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7341 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7342 if (it
->cmp_it
.from
> 0)
7343 it
->cmp_it
.to
= it
->cmp_it
.from
;
7346 ptrdiff_t stop
= it
->end_charpos
;
7347 if (it
->bidi_it
.scan_dir
< 0)
7349 composition_compute_stop_pos (&it
->cmp_it
,
7350 IT_STRING_CHARPOS (*it
),
7351 IT_STRING_BYTEPOS (*it
), stop
,
7359 /* If the string position is beyond string's end, it
7360 means next_element_from_string is padding the string
7361 with blanks, in which case we bypass the bidi
7362 iterator, because it cannot deal with such virtual
7364 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7366 IT_STRING_BYTEPOS (*it
) += it
->len
;
7367 IT_STRING_CHARPOS (*it
) += 1;
7371 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7373 bidi_move_to_visually_next (&it
->bidi_it
);
7374 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7375 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7376 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7378 ptrdiff_t stop
= it
->end_charpos
;
7380 if (it
->bidi_it
.scan_dir
< 0)
7382 composition_compute_stop_pos (&it
->cmp_it
,
7383 IT_STRING_CHARPOS (*it
),
7384 IT_STRING_BYTEPOS (*it
), stop
,
7390 consider_string_end
:
7392 if (it
->current
.overlay_string_index
>= 0)
7394 /* IT->string is an overlay string. Advance to the
7395 next, if there is one. */
7396 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7399 next_overlay_string (it
);
7401 setup_for_ellipsis (it
, 0);
7406 /* IT->string is not an overlay string. If we reached
7407 its end, and there is something on IT->stack, proceed
7408 with what is on the stack. This can be either another
7409 string, this time an overlay string, or a buffer. */
7410 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7414 if (it
->method
== GET_FROM_STRING
)
7415 goto consider_string_end
;
7420 case GET_FROM_IMAGE
:
7421 case GET_FROM_STRETCH
:
7422 /* The position etc with which we have to proceed are on
7423 the stack. The position may be at the end of a string,
7424 if the `display' property takes up the whole string. */
7425 eassert (it
->sp
> 0);
7427 if (it
->method
== GET_FROM_STRING
)
7428 goto consider_string_end
;
7432 /* There are no other methods defined, so this should be a bug. */
7436 eassert (it
->method
!= GET_FROM_STRING
7437 || (STRINGP (it
->string
)
7438 && IT_STRING_CHARPOS (*it
) >= 0));
7441 /* Load IT's display element fields with information about the next
7442 display element which comes from a display table entry or from the
7443 result of translating a control character to one of the forms `^C'
7446 IT->dpvec holds the glyphs to return as characters.
7447 IT->saved_face_id holds the face id before the display vector--it
7448 is restored into IT->face_id in set_iterator_to_next. */
7451 next_element_from_display_vector (struct it
*it
)
7454 int prev_face_id
= it
->face_id
;
7458 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7460 it
->face_id
= it
->saved_face_id
;
7462 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7463 That seemed totally bogus - so I changed it... */
7464 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7466 if (GLYPH_CODE_P (gc
))
7468 struct face
*this_face
, *prev_face
, *next_face
;
7470 it
->c
= GLYPH_CODE_CHAR (gc
);
7471 it
->len
= CHAR_BYTES (it
->c
);
7473 /* The entry may contain a face id to use. Such a face id is
7474 the id of a Lisp face, not a realized face. A face id of
7475 zero means no face is specified. */
7476 if (it
->dpvec_face_id
>= 0)
7477 it
->face_id
= it
->dpvec_face_id
;
7480 int lface_id
= GLYPH_CODE_FACE (gc
);
7482 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7486 /* Glyphs in the display vector could have the box face, so we
7487 need to set the related flags in the iterator, as
7489 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7490 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7492 /* Is this character the first character of a box-face run? */
7493 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7495 || prev_face
->box
== FACE_NO_BOX
));
7497 /* For the last character of the box-face run, we need to look
7498 either at the next glyph from the display vector, or at the
7499 face we saw before the display vector. */
7500 next_face_id
= it
->saved_face_id
;
7501 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7503 if (it
->dpvec_face_id
>= 0)
7504 next_face_id
= it
->dpvec_face_id
;
7508 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7511 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7515 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7516 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7518 || next_face
->box
== FACE_NO_BOX
));
7519 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7522 /* Display table entry is invalid. Return a space. */
7523 it
->c
= ' ', it
->len
= 1;
7525 /* Don't change position and object of the iterator here. They are
7526 still the values of the character that had this display table
7527 entry or was translated, and that's what we want. */
7528 it
->what
= IT_CHARACTER
;
7532 /* Get the first element of string/buffer in the visual order, after
7533 being reseated to a new position in a string or a buffer. */
7535 get_visually_first_element (struct it
*it
)
7537 int string_p
= STRINGP (it
->string
) || it
->s
;
7538 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7539 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7541 if (STRINGP (it
->string
))
7543 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7544 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7548 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7549 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7552 if (it
->bidi_it
.charpos
== eob
)
7554 /* Nothing to do, but reset the FIRST_ELT flag, like
7555 bidi_paragraph_init does, because we are not going to
7557 it
->bidi_it
.first_elt
= 0;
7559 else if (it
->bidi_it
.charpos
== bob
7561 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7562 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7564 /* If we are at the beginning of a line/string, we can produce
7565 the next element right away. */
7566 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7567 bidi_move_to_visually_next (&it
->bidi_it
);
7571 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7573 /* We need to prime the bidi iterator starting at the line's or
7574 string's beginning, before we will be able to produce the
7577 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7579 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7580 IT_BYTEPOS (*it
), -1,
7581 &it
->bidi_it
.bytepos
);
7582 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7585 /* Now return to buffer/string position where we were asked
7586 to get the next display element, and produce that. */
7587 bidi_move_to_visually_next (&it
->bidi_it
);
7589 while (it
->bidi_it
.bytepos
!= orig_bytepos
7590 && it
->bidi_it
.charpos
< eob
);
7593 /* Adjust IT's position information to where we ended up. */
7594 if (STRINGP (it
->string
))
7596 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7597 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7601 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7602 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7605 if (STRINGP (it
->string
) || !it
->s
)
7607 ptrdiff_t stop
, charpos
, bytepos
;
7609 if (STRINGP (it
->string
))
7612 stop
= SCHARS (it
->string
);
7613 if (stop
> it
->end_charpos
)
7614 stop
= it
->end_charpos
;
7615 charpos
= IT_STRING_CHARPOS (*it
);
7616 bytepos
= IT_STRING_BYTEPOS (*it
);
7620 stop
= it
->end_charpos
;
7621 charpos
= IT_CHARPOS (*it
);
7622 bytepos
= IT_BYTEPOS (*it
);
7624 if (it
->bidi_it
.scan_dir
< 0)
7626 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7631 /* Load IT with the next display element from Lisp string IT->string.
7632 IT->current.string_pos is the current position within the string.
7633 If IT->current.overlay_string_index >= 0, the Lisp string is an
7637 next_element_from_string (struct it
*it
)
7639 struct text_pos position
;
7641 eassert (STRINGP (it
->string
));
7642 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7643 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7644 position
= it
->current
.string_pos
;
7646 /* With bidi reordering, the character to display might not be the
7647 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7648 that we were reseat()ed to a new string, whose paragraph
7649 direction is not known. */
7650 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7652 get_visually_first_element (it
);
7653 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7656 /* Time to check for invisible text? */
7657 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7659 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7662 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7663 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7665 /* With bidi non-linear iteration, we could find
7666 ourselves far beyond the last computed stop_charpos,
7667 with several other stop positions in between that we
7668 missed. Scan them all now, in buffer's logical
7669 order, until we find and handle the last stop_charpos
7670 that precedes our current position. */
7671 handle_stop_backwards (it
, it
->stop_charpos
);
7672 return GET_NEXT_DISPLAY_ELEMENT (it
);
7678 /* Take note of the stop position we just moved
7679 across, for when we will move back across it. */
7680 it
->prev_stop
= it
->stop_charpos
;
7681 /* If we are at base paragraph embedding level, take
7682 note of the last stop position seen at this
7684 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7685 it
->base_level_stop
= it
->stop_charpos
;
7689 /* Since a handler may have changed IT->method, we must
7691 return GET_NEXT_DISPLAY_ELEMENT (it
);
7695 /* If we are before prev_stop, we may have overstepped
7696 on our way backwards a stop_pos, and if so, we need
7697 to handle that stop_pos. */
7698 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7699 /* We can sometimes back up for reasons that have nothing
7700 to do with bidi reordering. E.g., compositions. The
7701 code below is only needed when we are above the base
7702 embedding level, so test for that explicitly. */
7703 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7705 /* If we lost track of base_level_stop, we have no better
7706 place for handle_stop_backwards to start from than string
7707 beginning. This happens, e.g., when we were reseated to
7708 the previous screenful of text by vertical-motion. */
7709 if (it
->base_level_stop
<= 0
7710 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7711 it
->base_level_stop
= 0;
7712 handle_stop_backwards (it
, it
->base_level_stop
);
7713 return GET_NEXT_DISPLAY_ELEMENT (it
);
7717 if (it
->current
.overlay_string_index
>= 0)
7719 /* Get the next character from an overlay string. In overlay
7720 strings, there is no field width or padding with spaces to
7722 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7727 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7728 IT_STRING_BYTEPOS (*it
),
7729 it
->bidi_it
.scan_dir
< 0
7731 : SCHARS (it
->string
))
7732 && next_element_from_composition (it
))
7736 else if (STRING_MULTIBYTE (it
->string
))
7738 const unsigned char *s
= (SDATA (it
->string
)
7739 + IT_STRING_BYTEPOS (*it
));
7740 it
->c
= string_char_and_length (s
, &it
->len
);
7744 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7750 /* Get the next character from a Lisp string that is not an
7751 overlay string. Such strings come from the mode line, for
7752 example. We may have to pad with spaces, or truncate the
7753 string. See also next_element_from_c_string. */
7754 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7759 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7761 /* Pad with spaces. */
7762 it
->c
= ' ', it
->len
= 1;
7763 CHARPOS (position
) = BYTEPOS (position
) = -1;
7765 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7766 IT_STRING_BYTEPOS (*it
),
7767 it
->bidi_it
.scan_dir
< 0
7769 : it
->string_nchars
)
7770 && next_element_from_composition (it
))
7774 else if (STRING_MULTIBYTE (it
->string
))
7776 const unsigned char *s
= (SDATA (it
->string
)
7777 + IT_STRING_BYTEPOS (*it
));
7778 it
->c
= string_char_and_length (s
, &it
->len
);
7782 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7787 /* Record what we have and where it came from. */
7788 it
->what
= IT_CHARACTER
;
7789 it
->object
= it
->string
;
7790 it
->position
= position
;
7795 /* Load IT with next display element from C string IT->s.
7796 IT->string_nchars is the maximum number of characters to return
7797 from the string. IT->end_charpos may be greater than
7798 IT->string_nchars when this function is called, in which case we
7799 may have to return padding spaces. Value is zero if end of string
7800 reached, including padding spaces. */
7803 next_element_from_c_string (struct it
*it
)
7805 bool success_p
= true;
7808 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7809 it
->what
= IT_CHARACTER
;
7810 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7813 /* With bidi reordering, the character to display might not be the
7814 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7815 we were reseated to a new string, whose paragraph direction is
7817 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7818 get_visually_first_element (it
);
7820 /* IT's position can be greater than IT->string_nchars in case a
7821 field width or precision has been specified when the iterator was
7823 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7825 /* End of the game. */
7829 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7831 /* Pad with spaces. */
7832 it
->c
= ' ', it
->len
= 1;
7833 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7835 else if (it
->multibyte_p
)
7836 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7838 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7844 /* Set up IT to return characters from an ellipsis, if appropriate.
7845 The definition of the ellipsis glyphs may come from a display table
7846 entry. This function fills IT with the first glyph from the
7847 ellipsis if an ellipsis is to be displayed. */
7850 next_element_from_ellipsis (struct it
*it
)
7852 if (it
->selective_display_ellipsis_p
)
7853 setup_for_ellipsis (it
, it
->len
);
7856 /* The face at the current position may be different from the
7857 face we find after the invisible text. Remember what it
7858 was in IT->saved_face_id, and signal that it's there by
7859 setting face_before_selective_p. */
7860 it
->saved_face_id
= it
->face_id
;
7861 it
->method
= GET_FROM_BUFFER
;
7862 it
->object
= it
->w
->contents
;
7863 reseat_at_next_visible_line_start (it
, 1);
7864 it
->face_before_selective_p
= true;
7867 return GET_NEXT_DISPLAY_ELEMENT (it
);
7871 /* Deliver an image display element. The iterator IT is already
7872 filled with image information (done in handle_display_prop). Value
7877 next_element_from_image (struct it
*it
)
7879 it
->what
= IT_IMAGE
;
7880 it
->ignore_overlay_strings_at_pos_p
= 0;
7885 /* Fill iterator IT with next display element from a stretch glyph
7886 property. IT->object is the value of the text property. Value is
7890 next_element_from_stretch (struct it
*it
)
7892 it
->what
= IT_STRETCH
;
7896 /* Scan backwards from IT's current position until we find a stop
7897 position, or until BEGV. This is called when we find ourself
7898 before both the last known prev_stop and base_level_stop while
7899 reordering bidirectional text. */
7902 compute_stop_pos_backwards (struct it
*it
)
7904 const int SCAN_BACK_LIMIT
= 1000;
7905 struct text_pos pos
;
7906 struct display_pos save_current
= it
->current
;
7907 struct text_pos save_position
= it
->position
;
7908 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7909 ptrdiff_t where_we_are
= charpos
;
7910 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7911 ptrdiff_t save_end_pos
= it
->end_charpos
;
7913 eassert (NILP (it
->string
) && !it
->s
);
7914 eassert (it
->bidi_p
);
7918 it
->end_charpos
= min (charpos
+ 1, ZV
);
7919 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7920 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7921 reseat_1 (it
, pos
, 0);
7922 compute_stop_pos (it
);
7923 /* We must advance forward, right? */
7924 if (it
->stop_charpos
<= charpos
)
7927 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7929 if (it
->stop_charpos
<= where_we_are
)
7930 it
->prev_stop
= it
->stop_charpos
;
7932 it
->prev_stop
= BEGV
;
7934 it
->current
= save_current
;
7935 it
->position
= save_position
;
7936 it
->stop_charpos
= save_stop_pos
;
7937 it
->end_charpos
= save_end_pos
;
7940 /* Scan forward from CHARPOS in the current buffer/string, until we
7941 find a stop position > current IT's position. Then handle the stop
7942 position before that. This is called when we bump into a stop
7943 position while reordering bidirectional text. CHARPOS should be
7944 the last previously processed stop_pos (or BEGV/0, if none were
7945 processed yet) whose position is less that IT's current
7949 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7951 int bufp
= !STRINGP (it
->string
);
7952 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7953 struct display_pos save_current
= it
->current
;
7954 struct text_pos save_position
= it
->position
;
7955 struct text_pos pos1
;
7956 ptrdiff_t next_stop
;
7958 /* Scan in strict logical order. */
7959 eassert (it
->bidi_p
);
7963 it
->prev_stop
= charpos
;
7966 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7967 reseat_1 (it
, pos1
, 0);
7970 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7971 compute_stop_pos (it
);
7972 /* We must advance forward, right? */
7973 if (it
->stop_charpos
<= it
->prev_stop
)
7975 charpos
= it
->stop_charpos
;
7977 while (charpos
<= where_we_are
);
7980 it
->current
= save_current
;
7981 it
->position
= save_position
;
7982 next_stop
= it
->stop_charpos
;
7983 it
->stop_charpos
= it
->prev_stop
;
7985 it
->stop_charpos
= next_stop
;
7988 /* Load IT with the next display element from current_buffer. Value
7989 is zero if end of buffer reached. IT->stop_charpos is the next
7990 position at which to stop and check for text properties or buffer
7994 next_element_from_buffer (struct it
*it
)
7996 bool success_p
= true;
7998 eassert (IT_CHARPOS (*it
) >= BEGV
);
7999 eassert (NILP (it
->string
) && !it
->s
);
8000 eassert (!it
->bidi_p
8001 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8002 && it
->bidi_it
.string
.s
== NULL
));
8004 /* With bidi reordering, the character to display might not be the
8005 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8006 we were reseat()ed to a new buffer position, which is potentially
8007 a different paragraph. */
8008 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8010 get_visually_first_element (it
);
8011 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8014 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8016 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8018 int overlay_strings_follow_p
;
8020 /* End of the game, except when overlay strings follow that
8021 haven't been returned yet. */
8022 if (it
->overlay_strings_at_end_processed_p
)
8023 overlay_strings_follow_p
= 0;
8026 it
->overlay_strings_at_end_processed_p
= true;
8027 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8030 if (overlay_strings_follow_p
)
8031 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8035 it
->position
= it
->current
.pos
;
8039 else if (!(!it
->bidi_p
8040 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8041 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8043 /* With bidi non-linear iteration, we could find ourselves
8044 far beyond the last computed stop_charpos, with several
8045 other stop positions in between that we missed. Scan
8046 them all now, in buffer's logical order, until we find
8047 and handle the last stop_charpos that precedes our
8048 current position. */
8049 handle_stop_backwards (it
, it
->stop_charpos
);
8050 return GET_NEXT_DISPLAY_ELEMENT (it
);
8056 /* Take note of the stop position we just moved across,
8057 for when we will move back across it. */
8058 it
->prev_stop
= it
->stop_charpos
;
8059 /* If we are at base paragraph embedding level, take
8060 note of the last stop position seen at this
8062 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8063 it
->base_level_stop
= it
->stop_charpos
;
8066 return GET_NEXT_DISPLAY_ELEMENT (it
);
8070 /* If we are before prev_stop, we may have overstepped on
8071 our way backwards a stop_pos, and if so, we need to
8072 handle that stop_pos. */
8073 && IT_CHARPOS (*it
) < it
->prev_stop
8074 /* We can sometimes back up for reasons that have nothing
8075 to do with bidi reordering. E.g., compositions. The
8076 code below is only needed when we are above the base
8077 embedding level, so test for that explicitly. */
8078 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8080 if (it
->base_level_stop
<= 0
8081 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8083 /* If we lost track of base_level_stop, we need to find
8084 prev_stop by looking backwards. This happens, e.g., when
8085 we were reseated to the previous screenful of text by
8087 it
->base_level_stop
= BEGV
;
8088 compute_stop_pos_backwards (it
);
8089 handle_stop_backwards (it
, it
->prev_stop
);
8092 handle_stop_backwards (it
, it
->base_level_stop
);
8093 return GET_NEXT_DISPLAY_ELEMENT (it
);
8097 /* No face changes, overlays etc. in sight, so just return a
8098 character from current_buffer. */
8102 /* Maybe run the redisplay end trigger hook. Performance note:
8103 This doesn't seem to cost measurable time. */
8104 if (it
->redisplay_end_trigger_charpos
8106 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8107 run_redisplay_end_trigger_hook (it
);
8109 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8110 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8112 && next_element_from_composition (it
))
8117 /* Get the next character, maybe multibyte. */
8118 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8119 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8120 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8122 it
->c
= *p
, it
->len
= 1;
8124 /* Record what we have and where it came from. */
8125 it
->what
= IT_CHARACTER
;
8126 it
->object
= it
->w
->contents
;
8127 it
->position
= it
->current
.pos
;
8129 /* Normally we return the character found above, except when we
8130 really want to return an ellipsis for selective display. */
8135 /* A value of selective > 0 means hide lines indented more
8136 than that number of columns. */
8137 if (it
->selective
> 0
8138 && IT_CHARPOS (*it
) + 1 < ZV
8139 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8140 IT_BYTEPOS (*it
) + 1,
8143 success_p
= next_element_from_ellipsis (it
);
8144 it
->dpvec_char_len
= -1;
8147 else if (it
->c
== '\r' && it
->selective
== -1)
8149 /* A value of selective == -1 means that everything from the
8150 CR to the end of the line is invisible, with maybe an
8151 ellipsis displayed for it. */
8152 success_p
= next_element_from_ellipsis (it
);
8153 it
->dpvec_char_len
= -1;
8158 /* Value is zero if end of buffer reached. */
8159 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8164 /* Run the redisplay end trigger hook for IT. */
8167 run_redisplay_end_trigger_hook (struct it
*it
)
8169 Lisp_Object args
[3];
8171 /* IT->glyph_row should be non-null, i.e. we should be actually
8172 displaying something, or otherwise we should not run the hook. */
8173 eassert (it
->glyph_row
);
8175 /* Set up hook arguments. */
8176 args
[0] = Qredisplay_end_trigger_functions
;
8177 args
[1] = it
->window
;
8178 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8179 it
->redisplay_end_trigger_charpos
= 0;
8181 /* Since we are *trying* to run these functions, don't try to run
8182 them again, even if they get an error. */
8183 wset_redisplay_end_trigger (it
->w
, Qnil
);
8184 Frun_hook_with_args (3, args
);
8186 /* Notice if it changed the face of the character we are on. */
8187 handle_face_prop (it
);
8191 /* Deliver a composition display element. Unlike the other
8192 next_element_from_XXX, this function is not registered in the array
8193 get_next_element[]. It is called from next_element_from_buffer and
8194 next_element_from_string when necessary. */
8197 next_element_from_composition (struct it
*it
)
8199 it
->what
= IT_COMPOSITION
;
8200 it
->len
= it
->cmp_it
.nbytes
;
8201 if (STRINGP (it
->string
))
8205 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8206 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8209 it
->position
= it
->current
.string_pos
;
8210 it
->object
= it
->string
;
8211 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8212 IT_STRING_BYTEPOS (*it
), it
->string
);
8218 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8219 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8222 if (it
->bidi_it
.new_paragraph
)
8223 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8224 /* Resync the bidi iterator with IT's new position.
8225 FIXME: this doesn't support bidirectional text. */
8226 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8227 bidi_move_to_visually_next (&it
->bidi_it
);
8231 it
->position
= it
->current
.pos
;
8232 it
->object
= it
->w
->contents
;
8233 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8234 IT_BYTEPOS (*it
), Qnil
);
8241 /***********************************************************************
8242 Moving an iterator without producing glyphs
8243 ***********************************************************************/
8245 /* Check if iterator is at a position corresponding to a valid buffer
8246 position after some move_it_ call. */
8248 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8249 ((it)->method == GET_FROM_STRING \
8250 ? IT_STRING_CHARPOS (*it) == 0 \
8254 /* Move iterator IT to a specified buffer or X position within one
8255 line on the display without producing glyphs.
8257 OP should be a bit mask including some or all of these bits:
8258 MOVE_TO_X: Stop upon reaching x-position TO_X.
8259 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8260 Regardless of OP's value, stop upon reaching the end of the display line.
8262 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8263 This means, in particular, that TO_X includes window's horizontal
8266 The return value has several possible values that
8267 say what condition caused the scan to stop:
8269 MOVE_POS_MATCH_OR_ZV
8270 - when TO_POS or ZV was reached.
8273 -when TO_X was reached before TO_POS or ZV were reached.
8276 - when we reached the end of the display area and the line must
8280 - when we reached the end of the display area and the line is
8284 - when we stopped at a line end, i.e. a newline or a CR and selective
8287 static enum move_it_result
8288 move_it_in_display_line_to (struct it
*it
,
8289 ptrdiff_t to_charpos
, int to_x
,
8290 enum move_operation_enum op
)
8292 enum move_it_result result
= MOVE_UNDEFINED
;
8293 struct glyph_row
*saved_glyph_row
;
8294 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8295 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8296 void *ppos_data
= NULL
;
8298 enum it_method prev_method
= it
->method
;
8299 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8300 int saw_smaller_pos
= prev_pos
< to_charpos
;
8302 /* Don't produce glyphs in produce_glyphs. */
8303 saved_glyph_row
= it
->glyph_row
;
8304 it
->glyph_row
= NULL
;
8306 /* Use wrap_it to save a copy of IT wherever a word wrap could
8307 occur. Use atpos_it to save a copy of IT at the desired buffer
8308 position, if found, so that we can scan ahead and check if the
8309 word later overshoots the window edge. Use atx_it similarly, for
8315 /* Use ppos_it under bidi reordering to save a copy of IT for the
8316 position > CHARPOS that is the closest to CHARPOS. We restore
8317 that position in IT when we have scanned the entire display line
8318 without finding a match for CHARPOS and all the character
8319 positions are greater than CHARPOS. */
8322 SAVE_IT (ppos_it
, *it
, ppos_data
);
8323 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8324 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8325 SAVE_IT (ppos_it
, *it
, ppos_data
);
8328 #define BUFFER_POS_REACHED_P() \
8329 ((op & MOVE_TO_POS) != 0 \
8330 && BUFFERP (it->object) \
8331 && (IT_CHARPOS (*it) == to_charpos \
8333 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8334 && IT_CHARPOS (*it) > to_charpos) \
8335 || (it->what == IT_COMPOSITION \
8336 && ((IT_CHARPOS (*it) > to_charpos \
8337 && to_charpos >= it->cmp_it.charpos) \
8338 || (IT_CHARPOS (*it) < to_charpos \
8339 && to_charpos <= it->cmp_it.charpos)))) \
8340 && (it->method == GET_FROM_BUFFER \
8341 || (it->method == GET_FROM_DISPLAY_VECTOR \
8342 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8344 /* If there's a line-/wrap-prefix, handle it. */
8345 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8346 && it
->current_y
< it
->last_visible_y
)
8347 handle_line_prefix (it
);
8349 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8350 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8354 int x
, i
, ascent
= 0, descent
= 0;
8356 /* Utility macro to reset an iterator with x, ascent, and descent. */
8357 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8358 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8359 (IT)->max_descent = descent)
8361 /* Stop if we move beyond TO_CHARPOS (after an image or a
8362 display string or stretch glyph). */
8363 if ((op
& MOVE_TO_POS
) != 0
8364 && BUFFERP (it
->object
)
8365 && it
->method
== GET_FROM_BUFFER
8367 /* When the iterator is at base embedding level, we
8368 are guaranteed that characters are delivered for
8369 display in strictly increasing order of their
8370 buffer positions. */
8371 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8372 && IT_CHARPOS (*it
) > to_charpos
)
8374 && (prev_method
== GET_FROM_IMAGE
8375 || prev_method
== GET_FROM_STRETCH
8376 || prev_method
== GET_FROM_STRING
)
8377 /* Passed TO_CHARPOS from left to right. */
8378 && ((prev_pos
< to_charpos
8379 && IT_CHARPOS (*it
) > to_charpos
)
8380 /* Passed TO_CHARPOS from right to left. */
8381 || (prev_pos
> to_charpos
8382 && IT_CHARPOS (*it
) < to_charpos
)))))
8384 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8386 result
= MOVE_POS_MATCH_OR_ZV
;
8389 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8390 /* If wrap_it is valid, the current position might be in a
8391 word that is wrapped. So, save the iterator in
8392 atpos_it and continue to see if wrapping happens. */
8393 SAVE_IT (atpos_it
, *it
, atpos_data
);
8396 /* Stop when ZV reached.
8397 We used to stop here when TO_CHARPOS reached as well, but that is
8398 too soon if this glyph does not fit on this line. So we handle it
8399 explicitly below. */
8400 if (!get_next_display_element (it
))
8402 result
= MOVE_POS_MATCH_OR_ZV
;
8406 if (it
->line_wrap
== TRUNCATE
)
8408 if (BUFFER_POS_REACHED_P ())
8410 result
= MOVE_POS_MATCH_OR_ZV
;
8416 if (it
->line_wrap
== WORD_WRAP
)
8418 if (IT_DISPLAYING_WHITESPACE (it
))
8422 /* We have reached a glyph that follows one or more
8423 whitespace characters. If the position is
8424 already found, we are done. */
8425 if (atpos_it
.sp
>= 0)
8427 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8428 result
= MOVE_POS_MATCH_OR_ZV
;
8433 RESTORE_IT (it
, &atx_it
, atx_data
);
8434 result
= MOVE_X_REACHED
;
8437 /* Otherwise, we can wrap here. */
8438 SAVE_IT (wrap_it
, *it
, wrap_data
);
8444 /* Remember the line height for the current line, in case
8445 the next element doesn't fit on the line. */
8446 ascent
= it
->max_ascent
;
8447 descent
= it
->max_descent
;
8449 /* The call to produce_glyphs will get the metrics of the
8450 display element IT is loaded with. Record the x-position
8451 before this display element, in case it doesn't fit on the
8455 PRODUCE_GLYPHS (it
);
8457 if (it
->area
!= TEXT_AREA
)
8459 prev_method
= it
->method
;
8460 if (it
->method
== GET_FROM_BUFFER
)
8461 prev_pos
= IT_CHARPOS (*it
);
8462 set_iterator_to_next (it
, 1);
8463 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8464 SET_TEXT_POS (this_line_min_pos
,
8465 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8467 && (op
& MOVE_TO_POS
)
8468 && IT_CHARPOS (*it
) > to_charpos
8469 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8470 SAVE_IT (ppos_it
, *it
, ppos_data
);
8474 /* The number of glyphs we get back in IT->nglyphs will normally
8475 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8476 character on a terminal frame, or (iii) a line end. For the
8477 second case, IT->nglyphs - 1 padding glyphs will be present.
8478 (On X frames, there is only one glyph produced for a
8479 composite character.)
8481 The behavior implemented below means, for continuation lines,
8482 that as many spaces of a TAB as fit on the current line are
8483 displayed there. For terminal frames, as many glyphs of a
8484 multi-glyph character are displayed in the current line, too.
8485 This is what the old redisplay code did, and we keep it that
8486 way. Under X, the whole shape of a complex character must
8487 fit on the line or it will be completely displayed in the
8490 Note that both for tabs and padding glyphs, all glyphs have
8494 /* More than one glyph or glyph doesn't fit on line. All
8495 glyphs have the same width. */
8496 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8498 int x_before_this_char
= x
;
8499 int hpos_before_this_char
= it
->hpos
;
8501 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8503 new_x
= x
+ single_glyph_width
;
8505 /* We want to leave anything reaching TO_X to the caller. */
8506 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8508 if (BUFFER_POS_REACHED_P ())
8510 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8511 goto buffer_pos_reached
;
8512 if (atpos_it
.sp
< 0)
8514 SAVE_IT (atpos_it
, *it
, atpos_data
);
8515 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8520 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8523 result
= MOVE_X_REACHED
;
8528 SAVE_IT (atx_it
, *it
, atx_data
);
8529 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8534 if (/* Lines are continued. */
8535 it
->line_wrap
!= TRUNCATE
8536 && (/* And glyph doesn't fit on the line. */
8537 new_x
> it
->last_visible_x
8538 /* Or it fits exactly and we're on a window
8540 || (new_x
== it
->last_visible_x
8541 && FRAME_WINDOW_P (it
->f
)
8542 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8543 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8544 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8546 if (/* IT->hpos == 0 means the very first glyph
8547 doesn't fit on the line, e.g. a wide image. */
8549 || (new_x
== it
->last_visible_x
8550 && FRAME_WINDOW_P (it
->f
)))
8553 it
->current_x
= new_x
;
8555 /* The character's last glyph just barely fits
8557 if (i
== it
->nglyphs
- 1)
8559 /* If this is the destination position,
8560 return a position *before* it in this row,
8561 now that we know it fits in this row. */
8562 if (BUFFER_POS_REACHED_P ())
8564 if (it
->line_wrap
!= WORD_WRAP
8567 it
->hpos
= hpos_before_this_char
;
8568 it
->current_x
= x_before_this_char
;
8569 result
= MOVE_POS_MATCH_OR_ZV
;
8572 if (it
->line_wrap
== WORD_WRAP
8575 SAVE_IT (atpos_it
, *it
, atpos_data
);
8576 atpos_it
.current_x
= x_before_this_char
;
8577 atpos_it
.hpos
= hpos_before_this_char
;
8581 prev_method
= it
->method
;
8582 if (it
->method
== GET_FROM_BUFFER
)
8583 prev_pos
= IT_CHARPOS (*it
);
8584 set_iterator_to_next (it
, 1);
8585 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8586 SET_TEXT_POS (this_line_min_pos
,
8587 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8588 /* On graphical terminals, newlines may
8589 "overflow" into the fringe if
8590 overflow-newline-into-fringe is non-nil.
8591 On text terminals, and on graphical
8592 terminals with no right margin, newlines
8593 may overflow into the last glyph on the
8595 if (!FRAME_WINDOW_P (it
->f
)
8597 && it
->bidi_it
.paragraph_dir
== R2L
)
8598 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8599 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8600 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8602 if (!get_next_display_element (it
))
8604 result
= MOVE_POS_MATCH_OR_ZV
;
8607 if (BUFFER_POS_REACHED_P ())
8609 if (ITERATOR_AT_END_OF_LINE_P (it
))
8610 result
= MOVE_POS_MATCH_OR_ZV
;
8612 result
= MOVE_LINE_CONTINUED
;
8615 if (ITERATOR_AT_END_OF_LINE_P (it
)
8616 && (it
->line_wrap
!= WORD_WRAP
8619 result
= MOVE_NEWLINE_OR_CR
;
8626 IT_RESET_X_ASCENT_DESCENT (it
);
8628 if (wrap_it
.sp
>= 0)
8630 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8635 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8637 result
= MOVE_LINE_CONTINUED
;
8641 if (BUFFER_POS_REACHED_P ())
8643 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8644 goto buffer_pos_reached
;
8645 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8647 SAVE_IT (atpos_it
, *it
, atpos_data
);
8648 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8652 if (new_x
> it
->first_visible_x
)
8654 /* Glyph is visible. Increment number of glyphs that
8655 would be displayed. */
8660 if (result
!= MOVE_UNDEFINED
)
8663 else if (BUFFER_POS_REACHED_P ())
8666 IT_RESET_X_ASCENT_DESCENT (it
);
8667 result
= MOVE_POS_MATCH_OR_ZV
;
8670 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8672 /* Stop when TO_X specified and reached. This check is
8673 necessary here because of lines consisting of a line end,
8674 only. The line end will not produce any glyphs and we
8675 would never get MOVE_X_REACHED. */
8676 eassert (it
->nglyphs
== 0);
8677 result
= MOVE_X_REACHED
;
8681 /* Is this a line end? If yes, we're done. */
8682 if (ITERATOR_AT_END_OF_LINE_P (it
))
8684 /* If we are past TO_CHARPOS, but never saw any character
8685 positions smaller than TO_CHARPOS, return
8686 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8688 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8690 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8692 if (IT_CHARPOS (ppos_it
) < ZV
)
8694 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8695 result
= MOVE_POS_MATCH_OR_ZV
;
8698 goto buffer_pos_reached
;
8700 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8701 && IT_CHARPOS (*it
) > to_charpos
)
8702 goto buffer_pos_reached
;
8704 result
= MOVE_NEWLINE_OR_CR
;
8707 result
= MOVE_NEWLINE_OR_CR
;
8711 prev_method
= it
->method
;
8712 if (it
->method
== GET_FROM_BUFFER
)
8713 prev_pos
= IT_CHARPOS (*it
);
8714 /* The current display element has been consumed. Advance
8716 set_iterator_to_next (it
, 1);
8717 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8718 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8719 if (IT_CHARPOS (*it
) < to_charpos
)
8720 saw_smaller_pos
= 1;
8722 && (op
& MOVE_TO_POS
)
8723 && IT_CHARPOS (*it
) >= to_charpos
8724 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8725 SAVE_IT (ppos_it
, *it
, ppos_data
);
8727 /* Stop if lines are truncated and IT's current x-position is
8728 past the right edge of the window now. */
8729 if (it
->line_wrap
== TRUNCATE
8730 && it
->current_x
>= it
->last_visible_x
)
8732 if (!FRAME_WINDOW_P (it
->f
)
8733 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8734 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8735 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8736 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8740 if ((at_eob_p
= !get_next_display_element (it
))
8741 || BUFFER_POS_REACHED_P ()
8742 /* If we are past TO_CHARPOS, but never saw any
8743 character positions smaller than TO_CHARPOS,
8744 return MOVE_POS_MATCH_OR_ZV, like the
8745 unidirectional display did. */
8746 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8748 && IT_CHARPOS (*it
) > to_charpos
))
8751 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8752 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8753 result
= MOVE_POS_MATCH_OR_ZV
;
8756 if (ITERATOR_AT_END_OF_LINE_P (it
))
8758 result
= MOVE_NEWLINE_OR_CR
;
8762 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8764 && IT_CHARPOS (*it
) > to_charpos
)
8766 if (IT_CHARPOS (ppos_it
) < ZV
)
8767 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8768 result
= MOVE_POS_MATCH_OR_ZV
;
8771 result
= MOVE_LINE_TRUNCATED
;
8774 #undef IT_RESET_X_ASCENT_DESCENT
8777 #undef BUFFER_POS_REACHED_P
8779 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8780 restore the saved iterator. */
8781 if (atpos_it
.sp
>= 0)
8782 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8783 else if (atx_it
.sp
>= 0)
8784 RESTORE_IT (it
, &atx_it
, atx_data
);
8789 bidi_unshelve_cache (atpos_data
, 1);
8791 bidi_unshelve_cache (atx_data
, 1);
8793 bidi_unshelve_cache (wrap_data
, 1);
8795 bidi_unshelve_cache (ppos_data
, 1);
8797 /* Restore the iterator settings altered at the beginning of this
8799 it
->glyph_row
= saved_glyph_row
;
8803 /* For external use. */
8805 move_it_in_display_line (struct it
*it
,
8806 ptrdiff_t to_charpos
, int to_x
,
8807 enum move_operation_enum op
)
8809 if (it
->line_wrap
== WORD_WRAP
8810 && (op
& MOVE_TO_X
))
8813 void *save_data
= NULL
;
8816 SAVE_IT (save_it
, *it
, save_data
);
8817 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8818 /* When word-wrap is on, TO_X may lie past the end
8819 of a wrapped line. Then it->current is the
8820 character on the next line, so backtrack to the
8821 space before the wrap point. */
8822 if (skip
== MOVE_LINE_CONTINUED
)
8824 int prev_x
= max (it
->current_x
- 1, 0);
8825 RESTORE_IT (it
, &save_it
, save_data
);
8826 move_it_in_display_line_to
8827 (it
, -1, prev_x
, MOVE_TO_X
);
8830 bidi_unshelve_cache (save_data
, 1);
8833 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8837 /* Move IT forward until it satisfies one or more of the criteria in
8838 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8840 OP is a bit-mask that specifies where to stop, and in particular,
8841 which of those four position arguments makes a difference. See the
8842 description of enum move_operation_enum.
8844 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8845 screen line, this function will set IT to the next position that is
8846 displayed to the right of TO_CHARPOS on the screen. */
8849 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8851 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8852 int line_height
, line_start_x
= 0, reached
= 0;
8853 void *backup_data
= NULL
;
8857 if (op
& MOVE_TO_VPOS
)
8859 /* If no TO_CHARPOS and no TO_X specified, stop at the
8860 start of the line TO_VPOS. */
8861 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8863 if (it
->vpos
== to_vpos
)
8869 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8873 /* TO_VPOS >= 0 means stop at TO_X in the line at
8874 TO_VPOS, or at TO_POS, whichever comes first. */
8875 if (it
->vpos
== to_vpos
)
8881 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8883 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8888 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8890 /* We have reached TO_X but not in the line we want. */
8891 skip
= move_it_in_display_line_to (it
, to_charpos
,
8893 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8901 else if (op
& MOVE_TO_Y
)
8903 struct it it_backup
;
8905 if (it
->line_wrap
== WORD_WRAP
)
8906 SAVE_IT (it_backup
, *it
, backup_data
);
8908 /* TO_Y specified means stop at TO_X in the line containing
8909 TO_Y---or at TO_CHARPOS if this is reached first. The
8910 problem is that we can't really tell whether the line
8911 contains TO_Y before we have completely scanned it, and
8912 this may skip past TO_X. What we do is to first scan to
8915 If TO_X is not specified, use a TO_X of zero. The reason
8916 is to make the outcome of this function more predictable.
8917 If we didn't use TO_X == 0, we would stop at the end of
8918 the line which is probably not what a caller would expect
8920 skip
= move_it_in_display_line_to
8921 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8922 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8924 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8925 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8927 else if (skip
== MOVE_X_REACHED
)
8929 /* If TO_X was reached, we want to know whether TO_Y is
8930 in the line. We know this is the case if the already
8931 scanned glyphs make the line tall enough. Otherwise,
8932 we must check by scanning the rest of the line. */
8933 line_height
= it
->max_ascent
+ it
->max_descent
;
8934 if (to_y
>= it
->current_y
8935 && to_y
< it
->current_y
+ line_height
)
8940 SAVE_IT (it_backup
, *it
, backup_data
);
8941 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8942 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8944 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8945 line_height
= it
->max_ascent
+ it
->max_descent
;
8946 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8948 if (to_y
>= it
->current_y
8949 && to_y
< it
->current_y
+ line_height
)
8951 /* If TO_Y is in this line and TO_X was reached
8952 above, we scanned too far. We have to restore
8953 IT's settings to the ones before skipping. But
8954 keep the more accurate values of max_ascent and
8955 max_descent we've found while skipping the rest
8956 of the line, for the sake of callers, such as
8957 pos_visible_p, that need to know the line
8959 int max_ascent
= it
->max_ascent
;
8960 int max_descent
= it
->max_descent
;
8962 RESTORE_IT (it
, &it_backup
, backup_data
);
8963 it
->max_ascent
= max_ascent
;
8964 it
->max_descent
= max_descent
;
8970 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8976 /* Check whether TO_Y is in this line. */
8977 line_height
= it
->max_ascent
+ it
->max_descent
;
8978 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8980 if (to_y
>= it
->current_y
8981 && to_y
< it
->current_y
+ line_height
)
8983 /* When word-wrap is on, TO_X may lie past the end
8984 of a wrapped line. Then it->current is the
8985 character on the next line, so backtrack to the
8986 space before the wrap point. */
8987 if (skip
== MOVE_LINE_CONTINUED
8988 && it
->line_wrap
== WORD_WRAP
)
8990 int prev_x
= max (it
->current_x
- 1, 0);
8991 RESTORE_IT (it
, &it_backup
, backup_data
);
8992 skip
= move_it_in_display_line_to
8993 (it
, -1, prev_x
, MOVE_TO_X
);
9002 else if (BUFFERP (it
->object
)
9003 && (it
->method
== GET_FROM_BUFFER
9004 || it
->method
== GET_FROM_STRETCH
)
9005 && IT_CHARPOS (*it
) >= to_charpos
9006 /* Under bidi iteration, a call to set_iterator_to_next
9007 can scan far beyond to_charpos if the initial
9008 portion of the next line needs to be reordered. In
9009 that case, give move_it_in_display_line_to another
9012 && it
->bidi_it
.scan_dir
== -1))
9013 skip
= MOVE_POS_MATCH_OR_ZV
;
9015 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9019 case MOVE_POS_MATCH_OR_ZV
:
9023 case MOVE_NEWLINE_OR_CR
:
9024 set_iterator_to_next (it
, 1);
9025 it
->continuation_lines_width
= 0;
9028 case MOVE_LINE_TRUNCATED
:
9029 it
->continuation_lines_width
= 0;
9030 reseat_at_next_visible_line_start (it
, 0);
9031 if ((op
& MOVE_TO_POS
) != 0
9032 && IT_CHARPOS (*it
) > to_charpos
)
9039 case MOVE_LINE_CONTINUED
:
9040 /* For continued lines ending in a tab, some of the glyphs
9041 associated with the tab are displayed on the current
9042 line. Since it->current_x does not include these glyphs,
9043 we use it->last_visible_x instead. */
9046 it
->continuation_lines_width
+= it
->last_visible_x
;
9047 /* When moving by vpos, ensure that the iterator really
9048 advances to the next line (bug#847, bug#969). Fixme:
9049 do we need to do this in other circumstances? */
9050 if (it
->current_x
!= it
->last_visible_x
9051 && (op
& MOVE_TO_VPOS
)
9052 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9054 line_start_x
= it
->current_x
+ it
->pixel_width
9055 - it
->last_visible_x
;
9056 set_iterator_to_next (it
, 0);
9060 it
->continuation_lines_width
+= it
->current_x
;
9067 /* Reset/increment for the next run. */
9068 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9069 it
->current_x
= line_start_x
;
9072 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9074 last_height
= it
->max_ascent
+ it
->max_descent
;
9075 it
->max_ascent
= it
->max_descent
= 0;
9080 /* On text terminals, we may stop at the end of a line in the middle
9081 of a multi-character glyph. If the glyph itself is continued,
9082 i.e. it is actually displayed on the next line, don't treat this
9083 stopping point as valid; move to the next line instead (unless
9084 that brings us offscreen). */
9085 if (!FRAME_WINDOW_P (it
->f
)
9087 && IT_CHARPOS (*it
) == to_charpos
9088 && it
->what
== IT_CHARACTER
9090 && it
->line_wrap
== WINDOW_WRAP
9091 && it
->current_x
== it
->last_visible_x
- 1
9094 && it
->vpos
< it
->w
->window_end_vpos
)
9096 it
->continuation_lines_width
+= it
->current_x
;
9097 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9098 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9100 last_height
= it
->max_ascent
+ it
->max_descent
;
9104 bidi_unshelve_cache (backup_data
, 1);
9106 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9110 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9112 If DY > 0, move IT backward at least that many pixels. DY = 0
9113 means move IT backward to the preceding line start or BEGV. This
9114 function may move over more than DY pixels if IT->current_y - DY
9115 ends up in the middle of a line; in this case IT->current_y will be
9116 set to the top of the line moved to. */
9119 move_it_vertically_backward (struct it
*it
, int dy
)
9123 void *it2data
= NULL
, *it3data
= NULL
;
9124 ptrdiff_t start_pos
;
9126 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9127 ptrdiff_t pos_limit
;
9132 start_pos
= IT_CHARPOS (*it
);
9134 /* Estimate how many newlines we must move back. */
9135 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9136 if (it
->line_wrap
== TRUNCATE
)
9139 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9141 /* Set the iterator's position that many lines back. But don't go
9142 back more than NLINES full screen lines -- this wins a day with
9143 buffers which have very long lines. */
9144 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9145 back_to_previous_visible_line_start (it
);
9147 /* Reseat the iterator here. When moving backward, we don't want
9148 reseat to skip forward over invisible text, set up the iterator
9149 to deliver from overlay strings at the new position etc. So,
9150 use reseat_1 here. */
9151 reseat_1 (it
, it
->current
.pos
, 1);
9153 /* We are now surely at a line start. */
9154 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9155 reordering is in effect. */
9156 it
->continuation_lines_width
= 0;
9158 /* Move forward and see what y-distance we moved. First move to the
9159 start of the next line so that we get its height. We need this
9160 height to be able to tell whether we reached the specified
9162 SAVE_IT (it2
, *it
, it2data
);
9163 it2
.max_ascent
= it2
.max_descent
= 0;
9166 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9167 MOVE_TO_POS
| MOVE_TO_VPOS
);
9169 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9170 /* If we are in a display string which starts at START_POS,
9171 and that display string includes a newline, and we are
9172 right after that newline (i.e. at the beginning of a
9173 display line), exit the loop, because otherwise we will
9174 infloop, since move_it_to will see that it is already at
9175 START_POS and will not move. */
9176 || (it2
.method
== GET_FROM_STRING
9177 && IT_CHARPOS (it2
) == start_pos
9178 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9179 eassert (IT_CHARPOS (*it
) >= BEGV
);
9180 SAVE_IT (it3
, it2
, it3data
);
9182 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9183 eassert (IT_CHARPOS (*it
) >= BEGV
);
9184 /* H is the actual vertical distance from the position in *IT
9185 and the starting position. */
9186 h
= it2
.current_y
- it
->current_y
;
9187 /* NLINES is the distance in number of lines. */
9188 nlines
= it2
.vpos
- it
->vpos
;
9190 /* Correct IT's y and vpos position
9191 so that they are relative to the starting point. */
9197 /* DY == 0 means move to the start of the screen line. The
9198 value of nlines is > 0 if continuation lines were involved,
9199 or if the original IT position was at start of a line. */
9200 RESTORE_IT (it
, it
, it2data
);
9202 move_it_by_lines (it
, nlines
);
9203 /* The above code moves us to some position NLINES down,
9204 usually to its first glyph (leftmost in an L2R line), but
9205 that's not necessarily the start of the line, under bidi
9206 reordering. We want to get to the character position
9207 that is immediately after the newline of the previous
9210 && !it
->continuation_lines_width
9211 && !STRINGP (it
->string
)
9212 && IT_CHARPOS (*it
) > BEGV
9213 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9215 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9218 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9219 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9221 bidi_unshelve_cache (it3data
, 1);
9225 /* The y-position we try to reach, relative to *IT.
9226 Note that H has been subtracted in front of the if-statement. */
9227 int target_y
= it
->current_y
+ h
- dy
;
9228 int y0
= it3
.current_y
;
9232 RESTORE_IT (&it3
, &it3
, it3data
);
9233 y1
= line_bottom_y (&it3
);
9234 line_height
= y1
- y0
;
9235 RESTORE_IT (it
, it
, it2data
);
9236 /* If we did not reach target_y, try to move further backward if
9237 we can. If we moved too far backward, try to move forward. */
9238 if (target_y
< it
->current_y
9239 /* This is heuristic. In a window that's 3 lines high, with
9240 a line height of 13 pixels each, recentering with point
9241 on the bottom line will try to move -39/2 = 19 pixels
9242 backward. Try to avoid moving into the first line. */
9243 && (it
->current_y
- target_y
9244 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9245 && IT_CHARPOS (*it
) > BEGV
)
9247 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9248 target_y
- it
->current_y
));
9249 dy
= it
->current_y
- target_y
;
9250 goto move_further_back
;
9252 else if (target_y
>= it
->current_y
+ line_height
9253 && IT_CHARPOS (*it
) < ZV
)
9255 /* Should move forward by at least one line, maybe more.
9257 Note: Calling move_it_by_lines can be expensive on
9258 terminal frames, where compute_motion is used (via
9259 vmotion) to do the job, when there are very long lines
9260 and truncate-lines is nil. That's the reason for
9261 treating terminal frames specially here. */
9263 if (!FRAME_WINDOW_P (it
->f
))
9264 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9269 move_it_by_lines (it
, 1);
9271 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9278 /* Move IT by a specified amount of pixel lines DY. DY negative means
9279 move backwards. DY = 0 means move to start of screen line. At the
9280 end, IT will be on the start of a screen line. */
9283 move_it_vertically (struct it
*it
, int dy
)
9286 move_it_vertically_backward (it
, -dy
);
9289 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9290 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9291 MOVE_TO_POS
| MOVE_TO_Y
);
9292 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9294 /* If buffer ends in ZV without a newline, move to the start of
9295 the line to satisfy the post-condition. */
9296 if (IT_CHARPOS (*it
) == ZV
9298 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9299 move_it_by_lines (it
, 0);
9304 /* Move iterator IT past the end of the text line it is in. */
9307 move_it_past_eol (struct it
*it
)
9309 enum move_it_result rc
;
9311 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9312 if (rc
== MOVE_NEWLINE_OR_CR
)
9313 set_iterator_to_next (it
, 0);
9317 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9318 negative means move up. DVPOS == 0 means move to the start of the
9321 Optimization idea: If we would know that IT->f doesn't use
9322 a face with proportional font, we could be faster for
9323 truncate-lines nil. */
9326 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9329 /* The commented-out optimization uses vmotion on terminals. This
9330 gives bad results, because elements like it->what, on which
9331 callers such as pos_visible_p rely, aren't updated. */
9332 /* struct position pos;
9333 if (!FRAME_WINDOW_P (it->f))
9335 struct text_pos textpos;
9337 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9338 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9339 reseat (it, textpos, 1);
9340 it->vpos += pos.vpos;
9341 it->current_y += pos.vpos;
9347 /* DVPOS == 0 means move to the start of the screen line. */
9348 move_it_vertically_backward (it
, 0);
9349 /* Let next call to line_bottom_y calculate real line height. */
9354 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9355 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9357 /* Only move to the next buffer position if we ended up in a
9358 string from display property, not in an overlay string
9359 (before-string or after-string). That is because the
9360 latter don't conceal the underlying buffer position, so
9361 we can ask to move the iterator to the exact position we
9362 are interested in. Note that, even if we are already at
9363 IT_CHARPOS (*it), the call below is not a no-op, as it
9364 will detect that we are at the end of the string, pop the
9365 iterator, and compute it->current_x and it->hpos
9367 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9368 -1, -1, -1, MOVE_TO_POS
);
9374 void *it2data
= NULL
;
9375 ptrdiff_t start_charpos
, i
;
9377 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9378 ptrdiff_t pos_limit
;
9380 /* Start at the beginning of the screen line containing IT's
9381 position. This may actually move vertically backwards,
9382 in case of overlays, so adjust dvpos accordingly. */
9384 move_it_vertically_backward (it
, 0);
9387 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9388 screen lines, and reseat the iterator there. */
9389 start_charpos
= IT_CHARPOS (*it
);
9390 if (it
->line_wrap
== TRUNCATE
)
9393 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9394 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9395 back_to_previous_visible_line_start (it
);
9396 reseat (it
, it
->current
.pos
, 1);
9398 /* Move further back if we end up in a string or an image. */
9399 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9401 /* First try to move to start of display line. */
9403 move_it_vertically_backward (it
, 0);
9405 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9407 /* If start of line is still in string or image,
9408 move further back. */
9409 back_to_previous_visible_line_start (it
);
9410 reseat (it
, it
->current
.pos
, 1);
9414 it
->current_x
= it
->hpos
= 0;
9416 /* Above call may have moved too far if continuation lines
9417 are involved. Scan forward and see if it did. */
9418 SAVE_IT (it2
, *it
, it2data
);
9419 it2
.vpos
= it2
.current_y
= 0;
9420 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9421 it
->vpos
-= it2
.vpos
;
9422 it
->current_y
-= it2
.current_y
;
9423 it
->current_x
= it
->hpos
= 0;
9425 /* If we moved too far back, move IT some lines forward. */
9426 if (it2
.vpos
> -dvpos
)
9428 int delta
= it2
.vpos
+ dvpos
;
9430 RESTORE_IT (&it2
, &it2
, it2data
);
9431 SAVE_IT (it2
, *it
, it2data
);
9432 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9433 /* Move back again if we got too far ahead. */
9434 if (IT_CHARPOS (*it
) >= start_charpos
)
9435 RESTORE_IT (it
, &it2
, it2data
);
9437 bidi_unshelve_cache (it2data
, 1);
9440 RESTORE_IT (it
, it
, it2data
);
9444 /* Return 1 if IT points into the middle of a display vector. */
9447 in_display_vector_p (struct it
*it
)
9449 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9450 && it
->current
.dpvec_index
> 0
9451 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9455 /***********************************************************************
9457 ***********************************************************************/
9460 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9464 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9466 Lisp_Object args
[3];
9467 Lisp_Object msg
, fmt
;
9470 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9474 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9476 args
[0] = fmt
= build_string (format
);
9479 msg
= Fformat (3, args
);
9481 len
= SBYTES (msg
) + 1;
9482 buffer
= SAFE_ALLOCA (len
);
9483 memcpy (buffer
, SDATA (msg
), len
);
9485 message_dolog (buffer
, len
- 1, 1, 0);
9492 /* Output a newline in the *Messages* buffer if "needs" one. */
9495 message_log_maybe_newline (void)
9497 if (message_log_need_newline
)
9498 message_dolog ("", 0, 1, 0);
9502 /* Add a string M of length NBYTES to the message log, optionally
9503 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9504 true, means interpret the contents of M as multibyte. This
9505 function calls low-level routines in order to bypass text property
9506 hooks, etc. which might not be safe to run.
9508 This may GC (insert may run before/after change hooks),
9509 so the buffer M must NOT point to a Lisp string. */
9512 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9514 const unsigned char *msg
= (const unsigned char *) m
;
9516 if (!NILP (Vmemory_full
))
9519 if (!NILP (Vmessage_log_max
))
9521 struct buffer
*oldbuf
;
9522 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9523 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9524 ptrdiff_t point_at_end
= 0;
9525 ptrdiff_t zv_at_end
= 0;
9526 Lisp_Object old_deactivate_mark
;
9527 struct gcpro gcpro1
;
9529 old_deactivate_mark
= Vdeactivate_mark
;
9530 oldbuf
= current_buffer
;
9532 /* Ensure the Messages buffer exists, and switch to it.
9533 If we created it, set the major-mode. */
9536 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9538 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9541 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9542 call0 (intern ("messages-buffer-mode"));
9545 bset_undo_list (current_buffer
, Qt
);
9546 bset_cache_long_scans (current_buffer
, Qnil
);
9548 oldpoint
= message_dolog_marker1
;
9549 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9550 oldbegv
= message_dolog_marker2
;
9551 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9552 oldzv
= message_dolog_marker3
;
9553 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9554 GCPRO1 (old_deactivate_mark
);
9562 BEGV_BYTE
= BEG_BYTE
;
9565 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9567 /* Insert the string--maybe converting multibyte to single byte
9568 or vice versa, so that all the text fits the buffer. */
9570 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9576 /* Convert a multibyte string to single-byte
9577 for the *Message* buffer. */
9578 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9580 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9581 work
[0] = (ASCII_CHAR_P (c
)
9583 : multibyte_char_to_unibyte (c
));
9584 insert_1_both (work
, 1, 1, 1, 0, 0);
9587 else if (! multibyte
9588 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9592 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9593 /* Convert a single-byte string to multibyte
9594 for the *Message* buffer. */
9595 for (i
= 0; i
< nbytes
; i
++)
9598 MAKE_CHAR_MULTIBYTE (c
);
9599 char_bytes
= CHAR_STRING (c
, str
);
9600 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9604 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9608 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9611 insert_1_both ("\n", 1, 1, 1, 0, 0);
9613 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9615 this_bol_byte
= PT_BYTE
;
9617 /* See if this line duplicates the previous one.
9618 If so, combine duplicates. */
9621 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9623 prev_bol_byte
= PT_BYTE
;
9625 dups
= message_log_check_duplicate (prev_bol_byte
,
9629 del_range_both (prev_bol
, prev_bol_byte
,
9630 this_bol
, this_bol_byte
, 0);
9633 char dupstr
[sizeof " [ times]"
9634 + INT_STRLEN_BOUND (printmax_t
)];
9636 /* If you change this format, don't forget to also
9637 change message_log_check_duplicate. */
9638 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9639 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9640 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9645 /* If we have more than the desired maximum number of lines
9646 in the *Messages* buffer now, delete the oldest ones.
9647 This is safe because we don't have undo in this buffer. */
9649 if (NATNUMP (Vmessage_log_max
))
9651 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9652 -XFASTINT (Vmessage_log_max
) - 1, 0);
9653 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9656 BEGV
= marker_position (oldbegv
);
9657 BEGV_BYTE
= marker_byte_position (oldbegv
);
9666 ZV
= marker_position (oldzv
);
9667 ZV_BYTE
= marker_byte_position (oldzv
);
9671 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9673 /* We can't do Fgoto_char (oldpoint) because it will run some
9675 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9676 marker_byte_position (oldpoint
));
9679 unchain_marker (XMARKER (oldpoint
));
9680 unchain_marker (XMARKER (oldbegv
));
9681 unchain_marker (XMARKER (oldzv
));
9683 /* We called insert_1_both above with its 5th argument (PREPARE)
9684 zero, which prevents insert_1_both from calling
9685 prepare_to_modify_buffer, which in turns prevents us from
9686 incrementing windows_or_buffers_changed even if *Messages* is
9687 shown in some window. So we must manually set
9688 windows_or_buffers_changed here to make up for that. */
9689 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9690 bset_redisplay (current_buffer
);
9692 set_buffer_internal (oldbuf
);
9694 message_log_need_newline
= !nlflag
;
9695 Vdeactivate_mark
= old_deactivate_mark
;
9700 /* We are at the end of the buffer after just having inserted a newline.
9701 (Note: We depend on the fact we won't be crossing the gap.)
9702 Check to see if the most recent message looks a lot like the previous one.
9703 Return 0 if different, 1 if the new one should just replace it, or a
9704 value N > 1 if we should also append " [N times]". */
9707 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9710 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9712 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9713 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9715 for (i
= 0; i
< len
; i
++)
9717 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9725 if (*p1
++ == ' ' && *p1
++ == '[')
9728 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9729 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9736 /* Display an echo area message M with a specified length of NBYTES
9737 bytes. The string may include null characters. If M is not a
9738 string, clear out any existing message, and let the mini-buffer
9741 This function cancels echoing. */
9744 message3 (Lisp_Object m
)
9746 struct gcpro gcpro1
;
9749 clear_message (true, true);
9752 /* First flush out any partial line written with print. */
9753 message_log_maybe_newline ();
9756 ptrdiff_t nbytes
= SBYTES (m
);
9757 bool multibyte
= STRING_MULTIBYTE (m
);
9759 char *buffer
= SAFE_ALLOCA (nbytes
);
9760 memcpy (buffer
, SDATA (m
), nbytes
);
9761 message_dolog (buffer
, nbytes
, 1, multibyte
);
9770 /* The non-logging version of message3.
9771 This does not cancel echoing, because it is used for echoing.
9772 Perhaps we need to make a separate function for echoing
9773 and make this cancel echoing. */
9776 message3_nolog (Lisp_Object m
)
9778 struct frame
*sf
= SELECTED_FRAME ();
9780 if (FRAME_INITIAL_P (sf
))
9782 if (noninteractive_need_newline
)
9783 putc ('\n', stderr
);
9784 noninteractive_need_newline
= 0;
9787 Lisp_Object s
= ENCODE_SYSTEM (m
);
9789 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9791 if (cursor_in_echo_area
== 0)
9792 fprintf (stderr
, "\n");
9795 /* Error messages get reported properly by cmd_error, so this must be just an
9796 informative message; if the frame hasn't really been initialized yet, just
9798 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9800 /* Get the frame containing the mini-buffer
9801 that the selected frame is using. */
9802 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9803 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9804 struct frame
*f
= XFRAME (frame
);
9806 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9807 Fmake_frame_visible (frame
);
9809 if (STRINGP (m
) && SCHARS (m
) > 0)
9812 if (minibuffer_auto_raise
)
9813 Fraise_frame (frame
);
9814 /* Assume we are not echoing.
9815 (If we are, echo_now will override this.) */
9816 echo_message_buffer
= Qnil
;
9819 clear_message (true, true);
9821 do_pending_window_change (0);
9822 echo_area_display (1);
9823 do_pending_window_change (0);
9824 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9825 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9830 /* Display a null-terminated echo area message M. If M is 0, clear
9831 out any existing message, and let the mini-buffer text show through.
9833 The buffer M must continue to exist until after the echo area gets
9834 cleared or some other message gets displayed there. Do not pass
9835 text that is stored in a Lisp string. Do not pass text in a buffer
9836 that was alloca'd. */
9839 message1 (const char *m
)
9841 message3 (m
? build_unibyte_string (m
) : Qnil
);
9845 /* The non-logging counterpart of message1. */
9848 message1_nolog (const char *m
)
9850 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9853 /* Display a message M which contains a single %s
9854 which gets replaced with STRING. */
9857 message_with_string (const char *m
, Lisp_Object string
, int log
)
9859 CHECK_STRING (string
);
9865 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
9866 String whose data pointer might be passed to us in M. So
9867 we use a local copy. */
9868 char *fmt
= xstrdup (m
);
9870 if (noninteractive_need_newline
)
9871 putc ('\n', stderr
);
9872 noninteractive_need_newline
= 0;
9873 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
9874 if (!cursor_in_echo_area
)
9875 fprintf (stderr
, "\n");
9880 else if (INTERACTIVE
)
9882 /* The frame whose minibuffer we're going to display the message on.
9883 It may be larger than the selected frame, so we need
9884 to use its buffer, not the selected frame's buffer. */
9885 Lisp_Object mini_window
;
9886 struct frame
*f
, *sf
= SELECTED_FRAME ();
9888 /* Get the frame containing the minibuffer
9889 that the selected frame is using. */
9890 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9891 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9893 /* Error messages get reported properly by cmd_error, so this must be
9894 just an informative message; if the frame hasn't really been
9895 initialized yet, just toss it. */
9896 if (f
->glyphs_initialized_p
)
9898 Lisp_Object args
[2], msg
;
9899 struct gcpro gcpro1
, gcpro2
;
9901 args
[0] = build_string (m
);
9902 args
[1] = msg
= string
;
9903 GCPRO2 (args
[0], msg
);
9906 msg
= Fformat (2, args
);
9911 message3_nolog (msg
);
9915 /* Print should start at the beginning of the message
9916 buffer next time. */
9917 message_buf_print
= 0;
9923 /* Dump an informative message to the minibuf. If M is 0, clear out
9924 any existing message, and let the mini-buffer text show through. */
9927 vmessage (const char *m
, va_list ap
)
9933 if (noninteractive_need_newline
)
9934 putc ('\n', stderr
);
9935 noninteractive_need_newline
= 0;
9936 vfprintf (stderr
, m
, ap
);
9937 if (cursor_in_echo_area
== 0)
9938 fprintf (stderr
, "\n");
9942 else if (INTERACTIVE
)
9944 /* The frame whose mini-buffer we're going to display the message
9945 on. It may be larger than the selected frame, so we need to
9946 use its buffer, not the selected frame's buffer. */
9947 Lisp_Object mini_window
;
9948 struct frame
*f
, *sf
= SELECTED_FRAME ();
9950 /* Get the frame containing the mini-buffer
9951 that the selected frame is using. */
9952 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9953 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9955 /* Error messages get reported properly by cmd_error, so this must be
9956 just an informative message; if the frame hasn't really been
9957 initialized yet, just toss it. */
9958 if (f
->glyphs_initialized_p
)
9963 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9964 char *message_buf
= alloca (maxsize
+ 1);
9966 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9968 message3 (make_string (message_buf
, len
));
9973 /* Print should start at the beginning of the message
9974 buffer next time. */
9975 message_buf_print
= 0;
9981 message (const char *m
, ...)
9991 /* The non-logging version of message. */
9994 message_nolog (const char *m
, ...)
9996 Lisp_Object old_log_max
;
9999 old_log_max
= Vmessage_log_max
;
10000 Vmessage_log_max
= Qnil
;
10002 Vmessage_log_max
= old_log_max
;
10008 /* Display the current message in the current mini-buffer. This is
10009 only called from error handlers in process.c, and is not time
10013 update_echo_area (void)
10015 if (!NILP (echo_area_buffer
[0]))
10017 Lisp_Object string
;
10018 string
= Fcurrent_message ();
10024 /* Make sure echo area buffers in `echo_buffers' are live.
10025 If they aren't, make new ones. */
10028 ensure_echo_area_buffers (void)
10032 for (i
= 0; i
< 2; ++i
)
10033 if (!BUFFERP (echo_buffer
[i
])
10034 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10037 Lisp_Object old_buffer
;
10040 old_buffer
= echo_buffer
[i
];
10041 echo_buffer
[i
] = Fget_buffer_create
10042 (make_formatted_string (name
, " *Echo Area %d*", i
));
10043 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10044 /* to force word wrap in echo area -
10045 it was decided to postpone this*/
10046 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10048 for (j
= 0; j
< 2; ++j
)
10049 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10050 echo_area_buffer
[j
] = echo_buffer
[i
];
10055 /* Call FN with args A1..A2 with either the current or last displayed
10056 echo_area_buffer as current buffer.
10058 WHICH zero means use the current message buffer
10059 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10060 from echo_buffer[] and clear it.
10062 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10063 suitable buffer from echo_buffer[] and clear it.
10065 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10066 that the current message becomes the last displayed one, make
10067 choose a suitable buffer for echo_area_buffer[0], and clear it.
10069 Value is what FN returns. */
10072 with_echo_area_buffer (struct window
*w
, int which
,
10073 int (*fn
) (ptrdiff_t, Lisp_Object
),
10074 ptrdiff_t a1
, Lisp_Object a2
)
10076 Lisp_Object buffer
;
10077 int this_one
, the_other
, clear_buffer_p
, rc
;
10078 ptrdiff_t count
= SPECPDL_INDEX ();
10080 /* If buffers aren't live, make new ones. */
10081 ensure_echo_area_buffers ();
10083 clear_buffer_p
= 0;
10086 this_one
= 0, the_other
= 1;
10087 else if (which
> 0)
10088 this_one
= 1, the_other
= 0;
10091 this_one
= 0, the_other
= 1;
10092 clear_buffer_p
= true;
10094 /* We need a fresh one in case the current echo buffer equals
10095 the one containing the last displayed echo area message. */
10096 if (!NILP (echo_area_buffer
[this_one
])
10097 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10098 echo_area_buffer
[this_one
] = Qnil
;
10101 /* Choose a suitable buffer from echo_buffer[] is we don't
10103 if (NILP (echo_area_buffer
[this_one
]))
10105 echo_area_buffer
[this_one
]
10106 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10107 ? echo_buffer
[the_other
]
10108 : echo_buffer
[this_one
]);
10109 clear_buffer_p
= true;
10112 buffer
= echo_area_buffer
[this_one
];
10114 /* Don't get confused by reusing the buffer used for echoing
10115 for a different purpose. */
10116 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10119 record_unwind_protect (unwind_with_echo_area_buffer
,
10120 with_echo_area_buffer_unwind_data (w
));
10122 /* Make the echo area buffer current. Note that for display
10123 purposes, it is not necessary that the displayed window's buffer
10124 == current_buffer, except for text property lookup. So, let's
10125 only set that buffer temporarily here without doing a full
10126 Fset_window_buffer. We must also change w->pointm, though,
10127 because otherwise an assertions in unshow_buffer fails, and Emacs
10129 set_buffer_internal_1 (XBUFFER (buffer
));
10132 wset_buffer (w
, buffer
);
10133 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10136 bset_undo_list (current_buffer
, Qt
);
10137 bset_read_only (current_buffer
, Qnil
);
10138 specbind (Qinhibit_read_only
, Qt
);
10139 specbind (Qinhibit_modification_hooks
, Qt
);
10141 if (clear_buffer_p
&& Z
> BEG
)
10142 del_range (BEG
, Z
);
10144 eassert (BEGV
>= BEG
);
10145 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10149 eassert (BEGV
>= BEG
);
10150 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10152 unbind_to (count
, Qnil
);
10157 /* Save state that should be preserved around the call to the function
10158 FN called in with_echo_area_buffer. */
10161 with_echo_area_buffer_unwind_data (struct window
*w
)
10164 Lisp_Object vector
, tmp
;
10166 /* Reduce consing by keeping one vector in
10167 Vwith_echo_area_save_vector. */
10168 vector
= Vwith_echo_area_save_vector
;
10169 Vwith_echo_area_save_vector
= Qnil
;
10172 vector
= Fmake_vector (make_number (9), Qnil
);
10174 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10175 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10176 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10180 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10181 ASET (vector
, i
, w
->contents
); ++i
;
10182 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10183 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10184 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10185 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10190 for (; i
< end
; ++i
)
10191 ASET (vector
, i
, Qnil
);
10194 eassert (i
== ASIZE (vector
));
10199 /* Restore global state from VECTOR which was created by
10200 with_echo_area_buffer_unwind_data. */
10203 unwind_with_echo_area_buffer (Lisp_Object vector
)
10205 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10206 Vdeactivate_mark
= AREF (vector
, 1);
10207 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10209 if (WINDOWP (AREF (vector
, 3)))
10212 Lisp_Object buffer
;
10214 w
= XWINDOW (AREF (vector
, 3));
10215 buffer
= AREF (vector
, 4);
10217 wset_buffer (w
, buffer
);
10218 set_marker_both (w
->pointm
, buffer
,
10219 XFASTINT (AREF (vector
, 5)),
10220 XFASTINT (AREF (vector
, 6)));
10221 set_marker_both (w
->start
, buffer
,
10222 XFASTINT (AREF (vector
, 7)),
10223 XFASTINT (AREF (vector
, 8)));
10226 Vwith_echo_area_save_vector
= vector
;
10230 /* Set up the echo area for use by print functions. MULTIBYTE_P
10231 non-zero means we will print multibyte. */
10234 setup_echo_area_for_printing (int multibyte_p
)
10236 /* If we can't find an echo area any more, exit. */
10237 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10238 Fkill_emacs (Qnil
);
10240 ensure_echo_area_buffers ();
10242 if (!message_buf_print
)
10244 /* A message has been output since the last time we printed.
10245 Choose a fresh echo area buffer. */
10246 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10247 echo_area_buffer
[0] = echo_buffer
[1];
10249 echo_area_buffer
[0] = echo_buffer
[0];
10251 /* Switch to that buffer and clear it. */
10252 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10253 bset_truncate_lines (current_buffer
, Qnil
);
10257 ptrdiff_t count
= SPECPDL_INDEX ();
10258 specbind (Qinhibit_read_only
, Qt
);
10259 /* Note that undo recording is always disabled. */
10260 del_range (BEG
, Z
);
10261 unbind_to (count
, Qnil
);
10263 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10265 /* Set up the buffer for the multibyteness we need. */
10267 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10268 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10270 /* Raise the frame containing the echo area. */
10271 if (minibuffer_auto_raise
)
10273 struct frame
*sf
= SELECTED_FRAME ();
10274 Lisp_Object mini_window
;
10275 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10276 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10279 message_log_maybe_newline ();
10280 message_buf_print
= 1;
10284 if (NILP (echo_area_buffer
[0]))
10286 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10287 echo_area_buffer
[0] = echo_buffer
[1];
10289 echo_area_buffer
[0] = echo_buffer
[0];
10292 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10294 /* Someone switched buffers between print requests. */
10295 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10296 bset_truncate_lines (current_buffer
, Qnil
);
10302 /* Display an echo area message in window W. Value is non-zero if W's
10303 height is changed. If display_last_displayed_message_p is
10304 non-zero, display the message that was last displayed, otherwise
10305 display the current message. */
10308 display_echo_area (struct window
*w
)
10310 int i
, no_message_p
, window_height_changed_p
;
10312 /* Temporarily disable garbage collections while displaying the echo
10313 area. This is done because a GC can print a message itself.
10314 That message would modify the echo area buffer's contents while a
10315 redisplay of the buffer is going on, and seriously confuse
10317 ptrdiff_t count
= inhibit_garbage_collection ();
10319 /* If there is no message, we must call display_echo_area_1
10320 nevertheless because it resizes the window. But we will have to
10321 reset the echo_area_buffer in question to nil at the end because
10322 with_echo_area_buffer will sets it to an empty buffer. */
10323 i
= display_last_displayed_message_p
? 1 : 0;
10324 no_message_p
= NILP (echo_area_buffer
[i
]);
10326 window_height_changed_p
10327 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10328 display_echo_area_1
,
10329 (intptr_t) w
, Qnil
);
10332 echo_area_buffer
[i
] = Qnil
;
10334 unbind_to (count
, Qnil
);
10335 return window_height_changed_p
;
10339 /* Helper for display_echo_area. Display the current buffer which
10340 contains the current echo area message in window W, a mini-window,
10341 a pointer to which is passed in A1. A2..A4 are currently not used.
10342 Change the height of W so that all of the message is displayed.
10343 Value is non-zero if height of W was changed. */
10346 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10349 struct window
*w
= (struct window
*) i1
;
10350 Lisp_Object window
;
10351 struct text_pos start
;
10352 int window_height_changed_p
= 0;
10354 /* Do this before displaying, so that we have a large enough glyph
10355 matrix for the display. If we can't get enough space for the
10356 whole text, display the last N lines. That works by setting w->start. */
10357 window_height_changed_p
= resize_mini_window (w
, 0);
10359 /* Use the starting position chosen by resize_mini_window. */
10360 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10363 clear_glyph_matrix (w
->desired_matrix
);
10364 XSETWINDOW (window
, w
);
10365 try_window (window
, start
, 0);
10367 return window_height_changed_p
;
10371 /* Resize the echo area window to exactly the size needed for the
10372 currently displayed message, if there is one. If a mini-buffer
10373 is active, don't shrink it. */
10376 resize_echo_area_exactly (void)
10378 if (BUFFERP (echo_area_buffer
[0])
10379 && WINDOWP (echo_area_window
))
10381 struct window
*w
= XWINDOW (echo_area_window
);
10382 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10383 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10384 (intptr_t) w
, resize_exactly
);
10387 windows_or_buffers_changed
= 42;
10388 update_mode_lines
= 30;
10389 redisplay_internal ();
10395 /* Callback function for with_echo_area_buffer, when used from
10396 resize_echo_area_exactly. A1 contains a pointer to the window to
10397 resize, EXACTLY non-nil means resize the mini-window exactly to the
10398 size of the text displayed. A3 and A4 are not used. Value is what
10399 resize_mini_window returns. */
10402 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10405 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10409 /* Resize mini-window W to fit the size of its contents. EXACT_P
10410 means size the window exactly to the size needed. Otherwise, it's
10411 only enlarged until W's buffer is empty.
10413 Set W->start to the right place to begin display. If the whole
10414 contents fit, start at the beginning. Otherwise, start so as
10415 to make the end of the contents appear. This is particularly
10416 important for y-or-n-p, but seems desirable generally.
10418 Value is non-zero if the window height has been changed. */
10421 resize_mini_window (struct window
*w
, int exact_p
)
10423 struct frame
*f
= XFRAME (w
->frame
);
10424 int window_height_changed_p
= 0;
10426 eassert (MINI_WINDOW_P (w
));
10428 /* By default, start display at the beginning. */
10429 set_marker_both (w
->start
, w
->contents
,
10430 BUF_BEGV (XBUFFER (w
->contents
)),
10431 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10433 /* Don't resize windows while redisplaying a window; it would
10434 confuse redisplay functions when the size of the window they are
10435 displaying changes from under them. Such a resizing can happen,
10436 for instance, when which-func prints a long message while
10437 we are running fontification-functions. We're running these
10438 functions with safe_call which binds inhibit-redisplay to t. */
10439 if (!NILP (Vinhibit_redisplay
))
10442 /* Nil means don't try to resize. */
10443 if (NILP (Vresize_mini_windows
)
10444 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10447 if (!FRAME_MINIBUF_ONLY_P (f
))
10450 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10451 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10453 EMACS_INT max_height
;
10454 int unit
= FRAME_LINE_HEIGHT (f
);
10455 struct text_pos start
;
10456 struct buffer
*old_current_buffer
= NULL
;
10458 if (current_buffer
!= XBUFFER (w
->contents
))
10460 old_current_buffer
= current_buffer
;
10461 set_buffer_internal (XBUFFER (w
->contents
));
10464 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10466 /* Compute the max. number of lines specified by the user. */
10467 if (FLOATP (Vmax_mini_window_height
))
10468 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10469 else if (INTEGERP (Vmax_mini_window_height
))
10470 max_height
= XINT (Vmax_mini_window_height
);
10472 max_height
= total_height
/ 4;
10474 /* Correct that max. height if it's bogus. */
10475 max_height
= clip_to_bounds (1, max_height
, total_height
);
10477 /* Find out the height of the text in the window. */
10478 if (it
.line_wrap
== TRUNCATE
)
10483 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10484 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10485 height
= it
.current_y
+ last_height
;
10487 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10488 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10489 height
= (height
+ unit
- 1) / unit
;
10492 /* Compute a suitable window start. */
10493 if (height
> max_height
)
10495 height
= max_height
;
10496 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10497 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10498 start
= it
.current
.pos
;
10501 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10502 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10504 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10506 /* Let it grow only, until we display an empty message, in which
10507 case the window shrinks again. */
10508 if (height
> WINDOW_TOTAL_LINES (w
))
10510 int old_height
= WINDOW_TOTAL_LINES (w
);
10512 FRAME_WINDOWS_FROZEN (f
) = 1;
10513 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10514 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10516 else if (height
< WINDOW_TOTAL_LINES (w
)
10517 && (exact_p
|| BEGV
== ZV
))
10519 int old_height
= WINDOW_TOTAL_LINES (w
);
10521 FRAME_WINDOWS_FROZEN (f
) = 0;
10522 shrink_mini_window (w
);
10523 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10528 /* Always resize to exact size needed. */
10529 if (height
> WINDOW_TOTAL_LINES (w
))
10531 int old_height
= WINDOW_TOTAL_LINES (w
);
10533 FRAME_WINDOWS_FROZEN (f
) = 1;
10534 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10535 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10537 else if (height
< WINDOW_TOTAL_LINES (w
))
10539 int old_height
= WINDOW_TOTAL_LINES (w
);
10541 FRAME_WINDOWS_FROZEN (f
) = 0;
10542 shrink_mini_window (w
);
10546 FRAME_WINDOWS_FROZEN (f
) = 1;
10547 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10550 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10554 if (old_current_buffer
)
10555 set_buffer_internal (old_current_buffer
);
10558 return window_height_changed_p
;
10562 /* Value is the current message, a string, or nil if there is no
10563 current message. */
10566 current_message (void)
10570 if (!BUFFERP (echo_area_buffer
[0]))
10574 with_echo_area_buffer (0, 0, current_message_1
,
10575 (intptr_t) &msg
, Qnil
);
10577 echo_area_buffer
[0] = Qnil
;
10585 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10588 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10591 *msg
= make_buffer_string (BEG
, Z
, 1);
10598 /* Push the current message on Vmessage_stack for later restoration
10599 by restore_message. Value is non-zero if the current message isn't
10600 empty. This is a relatively infrequent operation, so it's not
10601 worth optimizing. */
10604 push_message (void)
10606 Lisp_Object msg
= current_message ();
10607 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10608 return STRINGP (msg
);
10612 /* Restore message display from the top of Vmessage_stack. */
10615 restore_message (void)
10617 eassert (CONSP (Vmessage_stack
));
10618 message3_nolog (XCAR (Vmessage_stack
));
10622 /* Handler for unwind-protect calling pop_message. */
10625 pop_message_unwind (void)
10627 /* Pop the top-most entry off Vmessage_stack. */
10628 eassert (CONSP (Vmessage_stack
));
10629 Vmessage_stack
= XCDR (Vmessage_stack
);
10633 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10634 exits. If the stack is not empty, we have a missing pop_message
10638 check_message_stack (void)
10640 if (!NILP (Vmessage_stack
))
10645 /* Truncate to NCHARS what will be displayed in the echo area the next
10646 time we display it---but don't redisplay it now. */
10649 truncate_echo_area (ptrdiff_t nchars
)
10652 echo_area_buffer
[0] = Qnil
;
10653 else if (!noninteractive
10655 && !NILP (echo_area_buffer
[0]))
10657 struct frame
*sf
= SELECTED_FRAME ();
10658 /* Error messages get reported properly by cmd_error, so this must be
10659 just an informative message; if the frame hasn't really been
10660 initialized yet, just toss it. */
10661 if (sf
->glyphs_initialized_p
)
10662 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10667 /* Helper function for truncate_echo_area. Truncate the current
10668 message to at most NCHARS characters. */
10671 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10673 if (BEG
+ nchars
< Z
)
10674 del_range (BEG
+ nchars
, Z
);
10676 echo_area_buffer
[0] = Qnil
;
10680 /* Set the current message to STRING. */
10683 set_message (Lisp_Object string
)
10685 eassert (STRINGP (string
));
10687 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10689 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10690 message_buf_print
= 0;
10691 help_echo_showing_p
= 0;
10693 if (STRINGP (Vdebug_on_message
)
10694 && STRINGP (string
)
10695 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10696 call_debugger (list2 (Qerror
, string
));
10700 /* Helper function for set_message. First argument is ignored and second
10701 argument has the same meaning as for set_message.
10702 This function is called with the echo area buffer being current. */
10705 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10707 eassert (STRINGP (string
));
10709 /* Change multibyteness of the echo buffer appropriately. */
10710 if (message_enable_multibyte
10711 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10712 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10714 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10715 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10716 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10718 /* Insert new message at BEG. */
10719 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10721 /* This function takes care of single/multibyte conversion.
10722 We just have to ensure that the echo area buffer has the right
10723 setting of enable_multibyte_characters. */
10724 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10730 /* Clear messages. CURRENT_P non-zero means clear the current
10731 message. LAST_DISPLAYED_P non-zero means clear the message
10735 clear_message (bool current_p
, bool last_displayed_p
)
10739 echo_area_buffer
[0] = Qnil
;
10740 message_cleared_p
= true;
10743 if (last_displayed_p
)
10744 echo_area_buffer
[1] = Qnil
;
10746 message_buf_print
= 0;
10749 /* Clear garbaged frames.
10751 This function is used where the old redisplay called
10752 redraw_garbaged_frames which in turn called redraw_frame which in
10753 turn called clear_frame. The call to clear_frame was a source of
10754 flickering. I believe a clear_frame is not necessary. It should
10755 suffice in the new redisplay to invalidate all current matrices,
10756 and ensure a complete redisplay of all windows. */
10759 clear_garbaged_frames (void)
10761 if (frame_garbaged
)
10763 Lisp_Object tail
, frame
;
10765 FOR_EACH_FRAME (tail
, frame
)
10767 struct frame
*f
= XFRAME (frame
);
10769 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10774 clear_current_matrices (f
);
10775 fset_redisplay (f
);
10776 f
->garbaged
= false;
10777 f
->resized_p
= false;
10781 frame_garbaged
= false;
10786 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10787 is non-zero update selected_frame. Value is non-zero if the
10788 mini-windows height has been changed. */
10791 echo_area_display (int update_frame_p
)
10793 Lisp_Object mini_window
;
10796 int window_height_changed_p
= 0;
10797 struct frame
*sf
= SELECTED_FRAME ();
10799 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10800 w
= XWINDOW (mini_window
);
10801 f
= XFRAME (WINDOW_FRAME (w
));
10803 /* Don't display if frame is invisible or not yet initialized. */
10804 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10807 #ifdef HAVE_WINDOW_SYSTEM
10808 /* When Emacs starts, selected_frame may be the initial terminal
10809 frame. If we let this through, a message would be displayed on
10811 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10813 #endif /* HAVE_WINDOW_SYSTEM */
10815 /* Redraw garbaged frames. */
10816 clear_garbaged_frames ();
10818 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10820 echo_area_window
= mini_window
;
10821 window_height_changed_p
= display_echo_area (w
);
10822 w
->must_be_updated_p
= true;
10824 /* Update the display, unless called from redisplay_internal.
10825 Also don't update the screen during redisplay itself. The
10826 update will happen at the end of redisplay, and an update
10827 here could cause confusion. */
10828 if (update_frame_p
&& !redisplaying_p
)
10832 /* If the display update has been interrupted by pending
10833 input, update mode lines in the frame. Due to the
10834 pending input, it might have been that redisplay hasn't
10835 been called, so that mode lines above the echo area are
10836 garbaged. This looks odd, so we prevent it here. */
10837 if (!display_completed
)
10838 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
10840 if (window_height_changed_p
10841 /* Don't do this if Emacs is shutting down. Redisplay
10842 needs to run hooks. */
10843 && !NILP (Vrun_hooks
))
10845 /* Must update other windows. Likewise as in other
10846 cases, don't let this update be interrupted by
10848 ptrdiff_t count
= SPECPDL_INDEX ();
10849 specbind (Qredisplay_dont_pause
, Qt
);
10850 windows_or_buffers_changed
= 44;
10851 redisplay_internal ();
10852 unbind_to (count
, Qnil
);
10854 else if (FRAME_WINDOW_P (f
) && n
== 0)
10856 /* Window configuration is the same as before.
10857 Can do with a display update of the echo area,
10858 unless we displayed some mode lines. */
10859 update_single_window (w
, 1);
10863 update_frame (f
, 1, 1);
10865 /* If cursor is in the echo area, make sure that the next
10866 redisplay displays the minibuffer, so that the cursor will
10867 be replaced with what the minibuffer wants. */
10868 if (cursor_in_echo_area
)
10869 wset_redisplay (XWINDOW (mini_window
));
10872 else if (!EQ (mini_window
, selected_window
))
10873 wset_redisplay (XWINDOW (mini_window
));
10875 /* Last displayed message is now the current message. */
10876 echo_area_buffer
[1] = echo_area_buffer
[0];
10877 /* Inform read_char that we're not echoing. */
10878 echo_message_buffer
= Qnil
;
10880 /* Prevent redisplay optimization in redisplay_internal by resetting
10881 this_line_start_pos. This is done because the mini-buffer now
10882 displays the message instead of its buffer text. */
10883 if (EQ (mini_window
, selected_window
))
10884 CHARPOS (this_line_start_pos
) = 0;
10886 return window_height_changed_p
;
10889 /* Nonzero if W's buffer was changed but not saved. */
10892 window_buffer_changed (struct window
*w
)
10894 struct buffer
*b
= XBUFFER (w
->contents
);
10896 eassert (BUFFER_LIVE_P (b
));
10898 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
10901 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10904 mode_line_update_needed (struct window
*w
)
10906 return (w
->column_number_displayed
!= -1
10907 && !(PT
== w
->last_point
&& !window_outdated (w
))
10908 && (w
->column_number_displayed
!= current_column ()));
10911 /* Nonzero if window start of W is frozen and may not be changed during
10915 window_frozen_p (struct window
*w
)
10917 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10919 Lisp_Object window
;
10921 XSETWINDOW (window
, w
);
10922 if (MINI_WINDOW_P (w
))
10924 else if (EQ (window
, selected_window
))
10926 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10927 && EQ (window
, Vminibuf_scroll_window
))
10928 /* This special window can't be frozen too. */
10936 /***********************************************************************
10937 Mode Lines and Frame Titles
10938 ***********************************************************************/
10940 /* A buffer for constructing non-propertized mode-line strings and
10941 frame titles in it; allocated from the heap in init_xdisp and
10942 resized as needed in store_mode_line_noprop_char. */
10944 static char *mode_line_noprop_buf
;
10946 /* The buffer's end, and a current output position in it. */
10948 static char *mode_line_noprop_buf_end
;
10949 static char *mode_line_noprop_ptr
;
10951 #define MODE_LINE_NOPROP_LEN(start) \
10952 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10955 MODE_LINE_DISPLAY
= 0,
10959 } mode_line_target
;
10961 /* Alist that caches the results of :propertize.
10962 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10963 static Lisp_Object mode_line_proptrans_alist
;
10965 /* List of strings making up the mode-line. */
10966 static Lisp_Object mode_line_string_list
;
10968 /* Base face property when building propertized mode line string. */
10969 static Lisp_Object mode_line_string_face
;
10970 static Lisp_Object mode_line_string_face_prop
;
10973 /* Unwind data for mode line strings */
10975 static Lisp_Object Vmode_line_unwind_vector
;
10978 format_mode_line_unwind_data (struct frame
*target_frame
,
10979 struct buffer
*obuf
,
10981 int save_proptrans
)
10983 Lisp_Object vector
, tmp
;
10985 /* Reduce consing by keeping one vector in
10986 Vwith_echo_area_save_vector. */
10987 vector
= Vmode_line_unwind_vector
;
10988 Vmode_line_unwind_vector
= Qnil
;
10991 vector
= Fmake_vector (make_number (10), Qnil
);
10993 ASET (vector
, 0, make_number (mode_line_target
));
10994 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10995 ASET (vector
, 2, mode_line_string_list
);
10996 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10997 ASET (vector
, 4, mode_line_string_face
);
10998 ASET (vector
, 5, mode_line_string_face_prop
);
11001 XSETBUFFER (tmp
, obuf
);
11004 ASET (vector
, 6, tmp
);
11005 ASET (vector
, 7, owin
);
11008 /* Similarly to `with-selected-window', if the operation selects
11009 a window on another frame, we must restore that frame's
11010 selected window, and (for a tty) the top-frame. */
11011 ASET (vector
, 8, target_frame
->selected_window
);
11012 if (FRAME_TERMCAP_P (target_frame
))
11013 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11020 unwind_format_mode_line (Lisp_Object vector
)
11022 Lisp_Object old_window
= AREF (vector
, 7);
11023 Lisp_Object target_frame_window
= AREF (vector
, 8);
11024 Lisp_Object old_top_frame
= AREF (vector
, 9);
11026 mode_line_target
= XINT (AREF (vector
, 0));
11027 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11028 mode_line_string_list
= AREF (vector
, 2);
11029 if (! EQ (AREF (vector
, 3), Qt
))
11030 mode_line_proptrans_alist
= AREF (vector
, 3);
11031 mode_line_string_face
= AREF (vector
, 4);
11032 mode_line_string_face_prop
= AREF (vector
, 5);
11034 /* Select window before buffer, since it may change the buffer. */
11035 if (!NILP (old_window
))
11037 /* If the operation that we are unwinding had selected a window
11038 on a different frame, reset its frame-selected-window. For a
11039 text terminal, reset its top-frame if necessary. */
11040 if (!NILP (target_frame_window
))
11043 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11045 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11046 Fselect_window (target_frame_window
, Qt
);
11048 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11049 Fselect_frame (old_top_frame
, Qt
);
11052 Fselect_window (old_window
, Qt
);
11055 if (!NILP (AREF (vector
, 6)))
11057 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11058 ASET (vector
, 6, Qnil
);
11061 Vmode_line_unwind_vector
= vector
;
11065 /* Store a single character C for the frame title in mode_line_noprop_buf.
11066 Re-allocate mode_line_noprop_buf if necessary. */
11069 store_mode_line_noprop_char (char c
)
11071 /* If output position has reached the end of the allocated buffer,
11072 increase the buffer's size. */
11073 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11075 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11076 ptrdiff_t size
= len
;
11077 mode_line_noprop_buf
=
11078 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11079 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11080 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11083 *mode_line_noprop_ptr
++ = c
;
11087 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11088 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11089 characters that yield more columns than PRECISION; PRECISION <= 0
11090 means copy the whole string. Pad with spaces until FIELD_WIDTH
11091 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11092 pad. Called from display_mode_element when it is used to build a
11096 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11098 const unsigned char *str
= (const unsigned char *) string
;
11100 ptrdiff_t dummy
, nbytes
;
11102 /* Copy at most PRECISION chars from STR. */
11103 nbytes
= strlen (string
);
11104 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11106 store_mode_line_noprop_char (*str
++);
11108 /* Fill up with spaces until FIELD_WIDTH reached. */
11109 while (field_width
> 0
11110 && n
< field_width
)
11112 store_mode_line_noprop_char (' ');
11119 /***********************************************************************
11121 ***********************************************************************/
11123 #ifdef HAVE_WINDOW_SYSTEM
11125 /* Set the title of FRAME, if it has changed. The title format is
11126 Vicon_title_format if FRAME is iconified, otherwise it is
11127 frame_title_format. */
11130 x_consider_frame_title (Lisp_Object frame
)
11132 struct frame
*f
= XFRAME (frame
);
11134 if (FRAME_WINDOW_P (f
)
11135 || FRAME_MINIBUF_ONLY_P (f
)
11136 || f
->explicit_name
)
11138 /* Do we have more than one visible frame on this X display? */
11139 Lisp_Object tail
, other_frame
, fmt
;
11140 ptrdiff_t title_start
;
11144 ptrdiff_t count
= SPECPDL_INDEX ();
11146 FOR_EACH_FRAME (tail
, other_frame
)
11148 struct frame
*tf
= XFRAME (other_frame
);
11151 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11152 && !FRAME_MINIBUF_ONLY_P (tf
)
11153 && !EQ (other_frame
, tip_frame
)
11154 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11158 /* Set global variable indicating that multiple frames exist. */
11159 multiple_frames
= CONSP (tail
);
11161 /* Switch to the buffer of selected window of the frame. Set up
11162 mode_line_target so that display_mode_element will output into
11163 mode_line_noprop_buf; then display the title. */
11164 record_unwind_protect (unwind_format_mode_line
,
11165 format_mode_line_unwind_data
11166 (f
, current_buffer
, selected_window
, 0));
11168 Fselect_window (f
->selected_window
, Qt
);
11169 set_buffer_internal_1
11170 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11171 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11173 mode_line_target
= MODE_LINE_TITLE
;
11174 title_start
= MODE_LINE_NOPROP_LEN (0);
11175 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11176 NULL
, DEFAULT_FACE_ID
);
11177 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11178 len
= MODE_LINE_NOPROP_LEN (title_start
);
11179 title
= mode_line_noprop_buf
+ title_start
;
11180 unbind_to (count
, Qnil
);
11182 /* Set the title only if it's changed. This avoids consing in
11183 the common case where it hasn't. (If it turns out that we've
11184 already wasted too much time by walking through the list with
11185 display_mode_element, then we might need to optimize at a
11186 higher level than this.) */
11187 if (! STRINGP (f
->name
)
11188 || SBYTES (f
->name
) != len
11189 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11190 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11194 #endif /* not HAVE_WINDOW_SYSTEM */
11197 /***********************************************************************
11199 ***********************************************************************/
11201 /* Non-zero if we will not redisplay all visible windows. */
11202 #define REDISPLAY_SOME_P() \
11203 ((windows_or_buffers_changed == 0 \
11204 || windows_or_buffers_changed == REDISPLAY_SOME) \
11205 && (update_mode_lines == 0 \
11206 || update_mode_lines == REDISPLAY_SOME))
11208 /* Prepare for redisplay by updating menu-bar item lists when
11209 appropriate. This can call eval. */
11212 prepare_menu_bars (void)
11214 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11215 bool some_windows
= REDISPLAY_SOME_P ();
11216 struct gcpro gcpro1
, gcpro2
;
11217 Lisp_Object tooltip_frame
;
11219 #ifdef HAVE_WINDOW_SYSTEM
11220 tooltip_frame
= tip_frame
;
11222 tooltip_frame
= Qnil
;
11225 if (FUNCTIONP (Vpre_redisplay_function
))
11227 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11228 if (all_windows
&& some_windows
)
11230 Lisp_Object ws
= window_list ();
11231 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11233 Lisp_Object
this = XCAR (ws
);
11234 struct window
*w
= XWINDOW (this);
11236 || XFRAME (w
->frame
)->redisplay
11237 || XBUFFER (w
->contents
)->text
->redisplay
)
11239 windows
= Fcons (this, windows
);
11243 safe_call1 (Vpre_redisplay_function
, windows
);
11246 /* Update all frame titles based on their buffer names, etc. We do
11247 this before the menu bars so that the buffer-menu will show the
11248 up-to-date frame titles. */
11249 #ifdef HAVE_WINDOW_SYSTEM
11252 Lisp_Object tail
, frame
;
11254 FOR_EACH_FRAME (tail
, frame
)
11256 struct frame
*f
= XFRAME (frame
);
11257 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11261 && !XBUFFER (w
->contents
)->text
->redisplay
)
11264 if (!EQ (frame
, tooltip_frame
)
11265 && (FRAME_ICONIFIED_P (f
)
11266 || FRAME_VISIBLE_P (f
) == 1
11267 /* Exclude TTY frames that are obscured because they
11268 are not the top frame on their console. This is
11269 because x_consider_frame_title actually switches
11270 to the frame, which for TTY frames means it is
11271 marked as garbaged, and will be completely
11272 redrawn on the next redisplay cycle. This causes
11273 TTY frames to be completely redrawn, when there
11274 are more than one of them, even though nothing
11275 should be changed on display. */
11276 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11277 x_consider_frame_title (frame
);
11280 #endif /* HAVE_WINDOW_SYSTEM */
11282 /* Update the menu bar item lists, if appropriate. This has to be
11283 done before any actual redisplay or generation of display lines. */
11287 Lisp_Object tail
, frame
;
11288 ptrdiff_t count
= SPECPDL_INDEX ();
11289 /* 1 means that update_menu_bar has run its hooks
11290 so any further calls to update_menu_bar shouldn't do so again. */
11291 int menu_bar_hooks_run
= 0;
11293 record_unwind_save_match_data ();
11295 FOR_EACH_FRAME (tail
, frame
)
11297 struct frame
*f
= XFRAME (frame
);
11298 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11300 /* Ignore tooltip frame. */
11301 if (EQ (frame
, tooltip_frame
))
11307 && !XBUFFER (w
->contents
)->text
->redisplay
)
11310 /* If a window on this frame changed size, report that to
11311 the user and clear the size-change flag. */
11312 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11314 Lisp_Object functions
;
11316 /* Clear flag first in case we get an error below. */
11317 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11318 functions
= Vwindow_size_change_functions
;
11319 GCPRO2 (tail
, functions
);
11321 while (CONSP (functions
))
11323 if (!EQ (XCAR (functions
), Qt
))
11324 call1 (XCAR (functions
), frame
);
11325 functions
= XCDR (functions
);
11331 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11332 #ifdef HAVE_WINDOW_SYSTEM
11333 update_tool_bar (f
, 0);
11336 if (windows_or_buffers_changed
11339 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11344 unbind_to (count
, Qnil
);
11348 struct frame
*sf
= SELECTED_FRAME ();
11349 update_menu_bar (sf
, 1, 0);
11350 #ifdef HAVE_WINDOW_SYSTEM
11351 update_tool_bar (sf
, 1);
11357 /* Update the menu bar item list for frame F. This has to be done
11358 before we start to fill in any display lines, because it can call
11361 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11363 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11364 already ran the menu bar hooks for this redisplay, so there
11365 is no need to run them again. The return value is the
11366 updated value of this flag, to pass to the next call. */
11369 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11371 Lisp_Object window
;
11372 register struct window
*w
;
11374 /* If called recursively during a menu update, do nothing. This can
11375 happen when, for instance, an activate-menubar-hook causes a
11377 if (inhibit_menubar_update
)
11380 window
= FRAME_SELECTED_WINDOW (f
);
11381 w
= XWINDOW (window
);
11383 if (FRAME_WINDOW_P (f
)
11385 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11386 || defined (HAVE_NS) || defined (USE_GTK)
11387 FRAME_EXTERNAL_MENU_BAR (f
)
11389 FRAME_MENU_BAR_LINES (f
) > 0
11391 : FRAME_MENU_BAR_LINES (f
) > 0)
11393 /* If the user has switched buffers or windows, we need to
11394 recompute to reflect the new bindings. But we'll
11395 recompute when update_mode_lines is set too; that means
11396 that people can use force-mode-line-update to request
11397 that the menu bar be recomputed. The adverse effect on
11398 the rest of the redisplay algorithm is about the same as
11399 windows_or_buffers_changed anyway. */
11400 if (windows_or_buffers_changed
11401 /* This used to test w->update_mode_line, but we believe
11402 there is no need to recompute the menu in that case. */
11403 || update_mode_lines
11404 || window_buffer_changed (w
))
11406 struct buffer
*prev
= current_buffer
;
11407 ptrdiff_t count
= SPECPDL_INDEX ();
11409 specbind (Qinhibit_menubar_update
, Qt
);
11411 set_buffer_internal_1 (XBUFFER (w
->contents
));
11412 if (save_match_data
)
11413 record_unwind_save_match_data ();
11414 if (NILP (Voverriding_local_map_menu_flag
))
11416 specbind (Qoverriding_terminal_local_map
, Qnil
);
11417 specbind (Qoverriding_local_map
, Qnil
);
11422 /* Run the Lucid hook. */
11423 safe_run_hooks (Qactivate_menubar_hook
);
11425 /* If it has changed current-menubar from previous value,
11426 really recompute the menu-bar from the value. */
11427 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11428 call0 (Qrecompute_lucid_menubar
);
11430 safe_run_hooks (Qmenu_bar_update_hook
);
11435 XSETFRAME (Vmenu_updating_frame
, f
);
11436 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11438 /* Redisplay the menu bar in case we changed it. */
11439 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11440 || defined (HAVE_NS) || defined (USE_GTK)
11441 if (FRAME_WINDOW_P (f
))
11443 #if defined (HAVE_NS)
11444 /* All frames on Mac OS share the same menubar. So only
11445 the selected frame should be allowed to set it. */
11446 if (f
== SELECTED_FRAME ())
11448 set_frame_menubar (f
, 0, 0);
11451 /* On a terminal screen, the menu bar is an ordinary screen
11452 line, and this makes it get updated. */
11453 w
->update_mode_line
= 1;
11454 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11455 /* In the non-toolkit version, the menu bar is an ordinary screen
11456 line, and this makes it get updated. */
11457 w
->update_mode_line
= 1;
11458 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11460 unbind_to (count
, Qnil
);
11461 set_buffer_internal_1 (prev
);
11468 /***********************************************************************
11470 ***********************************************************************/
11472 #ifdef HAVE_WINDOW_SYSTEM
11474 /* Tool-bar item index of the item on which a mouse button was pressed
11477 int last_tool_bar_item
;
11479 /* Select `frame' temporarily without running all the code in
11481 FIXME: Maybe do_switch_frame should be trimmed down similarly
11482 when `norecord' is set. */
11484 fast_set_selected_frame (Lisp_Object frame
)
11486 if (!EQ (selected_frame
, frame
))
11488 selected_frame
= frame
;
11489 selected_window
= XFRAME (frame
)->selected_window
;
11493 /* Update the tool-bar item list for frame F. This has to be done
11494 before we start to fill in any display lines. Called from
11495 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11496 and restore it here. */
11499 update_tool_bar (struct frame
*f
, int save_match_data
)
11501 #if defined (USE_GTK) || defined (HAVE_NS)
11502 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11504 int do_update
= WINDOWP (f
->tool_bar_window
)
11505 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11510 Lisp_Object window
;
11513 window
= FRAME_SELECTED_WINDOW (f
);
11514 w
= XWINDOW (window
);
11516 /* If the user has switched buffers or windows, we need to
11517 recompute to reflect the new bindings. But we'll
11518 recompute when update_mode_lines is set too; that means
11519 that people can use force-mode-line-update to request
11520 that the menu bar be recomputed. The adverse effect on
11521 the rest of the redisplay algorithm is about the same as
11522 windows_or_buffers_changed anyway. */
11523 if (windows_or_buffers_changed
11524 || w
->update_mode_line
11525 || update_mode_lines
11526 || window_buffer_changed (w
))
11528 struct buffer
*prev
= current_buffer
;
11529 ptrdiff_t count
= SPECPDL_INDEX ();
11530 Lisp_Object frame
, new_tool_bar
;
11531 int new_n_tool_bar
;
11532 struct gcpro gcpro1
;
11534 /* Set current_buffer to the buffer of the selected
11535 window of the frame, so that we get the right local
11537 set_buffer_internal_1 (XBUFFER (w
->contents
));
11539 /* Save match data, if we must. */
11540 if (save_match_data
)
11541 record_unwind_save_match_data ();
11543 /* Make sure that we don't accidentally use bogus keymaps. */
11544 if (NILP (Voverriding_local_map_menu_flag
))
11546 specbind (Qoverriding_terminal_local_map
, Qnil
);
11547 specbind (Qoverriding_local_map
, Qnil
);
11550 GCPRO1 (new_tool_bar
);
11552 /* We must temporarily set the selected frame to this frame
11553 before calling tool_bar_items, because the calculation of
11554 the tool-bar keymap uses the selected frame (see
11555 `tool-bar-make-keymap' in tool-bar.el). */
11556 eassert (EQ (selected_window
,
11557 /* Since we only explicitly preserve selected_frame,
11558 check that selected_window would be redundant. */
11559 XFRAME (selected_frame
)->selected_window
));
11560 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11561 XSETFRAME (frame
, f
);
11562 fast_set_selected_frame (frame
);
11564 /* Build desired tool-bar items from keymaps. */
11566 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11569 /* Redisplay the tool-bar if we changed it. */
11570 if (new_n_tool_bar
!= f
->n_tool_bar_items
11571 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11573 /* Redisplay that happens asynchronously due to an expose event
11574 may access f->tool_bar_items. Make sure we update both
11575 variables within BLOCK_INPUT so no such event interrupts. */
11577 fset_tool_bar_items (f
, new_tool_bar
);
11578 f
->n_tool_bar_items
= new_n_tool_bar
;
11579 w
->update_mode_line
= 1;
11585 unbind_to (count
, Qnil
);
11586 set_buffer_internal_1 (prev
);
11591 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11593 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11594 F's desired tool-bar contents. F->tool_bar_items must have
11595 been set up previously by calling prepare_menu_bars. */
11598 build_desired_tool_bar_string (struct frame
*f
)
11600 int i
, size
, size_needed
;
11601 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11602 Lisp_Object image
, plist
, props
;
11604 image
= plist
= props
= Qnil
;
11605 GCPRO3 (image
, plist
, props
);
11607 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11608 Otherwise, make a new string. */
11610 /* The size of the string we might be able to reuse. */
11611 size
= (STRINGP (f
->desired_tool_bar_string
)
11612 ? SCHARS (f
->desired_tool_bar_string
)
11615 /* We need one space in the string for each image. */
11616 size_needed
= f
->n_tool_bar_items
;
11618 /* Reuse f->desired_tool_bar_string, if possible. */
11619 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11620 fset_desired_tool_bar_string
11621 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11624 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11625 Fremove_text_properties (make_number (0), make_number (size
),
11626 props
, f
->desired_tool_bar_string
);
11629 /* Put a `display' property on the string for the images to display,
11630 put a `menu_item' property on tool-bar items with a value that
11631 is the index of the item in F's tool-bar item vector. */
11632 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11634 #define PROP(IDX) \
11635 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11637 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11638 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11639 int hmargin
, vmargin
, relief
, idx
, end
;
11641 /* If image is a vector, choose the image according to the
11643 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11644 if (VECTORP (image
))
11648 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11649 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11652 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11653 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11655 eassert (ASIZE (image
) >= idx
);
11656 image
= AREF (image
, idx
);
11661 /* Ignore invalid image specifications. */
11662 if (!valid_image_p (image
))
11665 /* Display the tool-bar button pressed, or depressed. */
11666 plist
= Fcopy_sequence (XCDR (image
));
11668 /* Compute margin and relief to draw. */
11669 relief
= (tool_bar_button_relief
>= 0
11670 ? tool_bar_button_relief
11671 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11672 hmargin
= vmargin
= relief
;
11674 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11675 INT_MAX
- max (hmargin
, vmargin
)))
11677 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11678 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11680 else if (CONSP (Vtool_bar_button_margin
))
11682 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11683 INT_MAX
- hmargin
))
11684 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11686 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11687 INT_MAX
- vmargin
))
11688 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11691 if (auto_raise_tool_bar_buttons_p
)
11693 /* Add a `:relief' property to the image spec if the item is
11697 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11704 /* If image is selected, display it pressed, i.e. with a
11705 negative relief. If it's not selected, display it with a
11707 plist
= Fplist_put (plist
, QCrelief
,
11709 ? make_number (-relief
)
11710 : make_number (relief
)));
11715 /* Put a margin around the image. */
11716 if (hmargin
|| vmargin
)
11718 if (hmargin
== vmargin
)
11719 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11721 plist
= Fplist_put (plist
, QCmargin
,
11722 Fcons (make_number (hmargin
),
11723 make_number (vmargin
)));
11726 /* If button is not enabled, and we don't have special images
11727 for the disabled state, make the image appear disabled by
11728 applying an appropriate algorithm to it. */
11729 if (!enabled_p
&& idx
< 0)
11730 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11732 /* Put a `display' text property on the string for the image to
11733 display. Put a `menu-item' property on the string that gives
11734 the start of this item's properties in the tool-bar items
11736 image
= Fcons (Qimage
, plist
);
11737 props
= list4 (Qdisplay
, image
,
11738 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11740 /* Let the last image hide all remaining spaces in the tool bar
11741 string. The string can be longer than needed when we reuse a
11742 previous string. */
11743 if (i
+ 1 == f
->n_tool_bar_items
)
11744 end
= SCHARS (f
->desired_tool_bar_string
);
11747 Fadd_text_properties (make_number (i
), make_number (end
),
11748 props
, f
->desired_tool_bar_string
);
11756 /* Display one line of the tool-bar of frame IT->f.
11758 HEIGHT specifies the desired height of the tool-bar line.
11759 If the actual height of the glyph row is less than HEIGHT, the
11760 row's height is increased to HEIGHT, and the icons are centered
11761 vertically in the new height.
11763 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11764 count a final empty row in case the tool-bar width exactly matches
11769 display_tool_bar_line (struct it
*it
, int height
)
11771 struct glyph_row
*row
= it
->glyph_row
;
11772 int max_x
= it
->last_visible_x
;
11773 struct glyph
*last
;
11775 prepare_desired_row (row
);
11776 row
->y
= it
->current_y
;
11778 /* Note that this isn't made use of if the face hasn't a box,
11779 so there's no need to check the face here. */
11780 it
->start_of_box_run_p
= 1;
11782 while (it
->current_x
< max_x
)
11784 int x
, n_glyphs_before
, i
, nglyphs
;
11785 struct it it_before
;
11787 /* Get the next display element. */
11788 if (!get_next_display_element (it
))
11790 /* Don't count empty row if we are counting needed tool-bar lines. */
11791 if (height
< 0 && !it
->hpos
)
11796 /* Produce glyphs. */
11797 n_glyphs_before
= row
->used
[TEXT_AREA
];
11800 PRODUCE_GLYPHS (it
);
11802 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11804 x
= it_before
.current_x
;
11805 while (i
< nglyphs
)
11807 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11809 if (x
+ glyph
->pixel_width
> max_x
)
11811 /* Glyph doesn't fit on line. Backtrack. */
11812 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11814 /* If this is the only glyph on this line, it will never fit on the
11815 tool-bar, so skip it. But ensure there is at least one glyph,
11816 so we don't accidentally disable the tool-bar. */
11817 if (n_glyphs_before
== 0
11818 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11824 x
+= glyph
->pixel_width
;
11828 /* Stop at line end. */
11829 if (ITERATOR_AT_END_OF_LINE_P (it
))
11832 set_iterator_to_next (it
, 1);
11837 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11839 /* Use default face for the border below the tool bar.
11841 FIXME: When auto-resize-tool-bars is grow-only, there is
11842 no additional border below the possibly empty tool-bar lines.
11843 So to make the extra empty lines look "normal", we have to
11844 use the tool-bar face for the border too. */
11845 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11846 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11847 it
->face_id
= DEFAULT_FACE_ID
;
11849 extend_face_to_end_of_line (it
);
11850 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11851 last
->right_box_line_p
= 1;
11852 if (last
== row
->glyphs
[TEXT_AREA
])
11853 last
->left_box_line_p
= 1;
11855 /* Make line the desired height and center it vertically. */
11856 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11858 /* Don't add more than one line height. */
11859 height
%= FRAME_LINE_HEIGHT (it
->f
);
11860 it
->max_ascent
+= height
/ 2;
11861 it
->max_descent
+= (height
+ 1) / 2;
11864 compute_line_metrics (it
);
11866 /* If line is empty, make it occupy the rest of the tool-bar. */
11867 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11869 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11870 row
->visible_height
= row
->height
;
11871 row
->ascent
= row
->phys_ascent
= 0;
11872 row
->extra_line_spacing
= 0;
11875 row
->full_width_p
= 1;
11876 row
->continued_p
= 0;
11877 row
->truncated_on_left_p
= 0;
11878 row
->truncated_on_right_p
= 0;
11880 it
->current_x
= it
->hpos
= 0;
11881 it
->current_y
+= row
->height
;
11887 /* Max tool-bar height. */
11889 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11890 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11892 /* Value is the number of screen lines needed to make all tool-bar
11893 items of frame F visible. The number of actual rows needed is
11894 returned in *N_ROWS if non-NULL. */
11897 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11899 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11901 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11902 the desired matrix, so use (unused) mode-line row as temporary row to
11903 avoid destroying the first tool-bar row. */
11904 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11906 /* Initialize an iterator for iteration over
11907 F->desired_tool_bar_string in the tool-bar window of frame F. */
11908 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11909 it
.first_visible_x
= 0;
11910 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11911 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11912 it
.paragraph_embedding
= L2R
;
11914 while (!ITERATOR_AT_END_P (&it
))
11916 clear_glyph_row (temp_row
);
11917 it
.glyph_row
= temp_row
;
11918 display_tool_bar_line (&it
, -1);
11920 clear_glyph_row (temp_row
);
11922 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11924 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11926 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11929 #endif /* !USE_GTK && !HAVE_NS */
11931 #if defined USE_GTK || defined HAVE_NS
11932 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
11935 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11937 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11938 If FRAME is nil or omitted, use the selected frame. */)
11939 (Lisp_Object frame
)
11942 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11943 struct frame
*f
= decode_any_frame (frame
);
11946 if (WINDOWP (f
->tool_bar_window
)
11947 && (w
= XWINDOW (f
->tool_bar_window
),
11948 WINDOW_TOTAL_LINES (w
) > 0))
11950 update_tool_bar (f
, 1);
11951 if (f
->n_tool_bar_items
)
11953 build_desired_tool_bar_string (f
);
11954 nlines
= tool_bar_lines_needed (f
, NULL
);
11958 return make_number (nlines
);
11962 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11963 height should be changed. */
11966 redisplay_tool_bar (struct frame
*f
)
11968 #if defined (USE_GTK) || defined (HAVE_NS)
11970 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11971 update_frame_tool_bar (f
);
11974 #else /* !USE_GTK && !HAVE_NS */
11978 struct glyph_row
*row
;
11980 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11981 do anything. This means you must start with tool-bar-lines
11982 non-zero to get the auto-sizing effect. Or in other words, you
11983 can turn off tool-bars by specifying tool-bar-lines zero. */
11984 if (!WINDOWP (f
->tool_bar_window
)
11985 || (w
= XWINDOW (f
->tool_bar_window
),
11986 WINDOW_TOTAL_LINES (w
) == 0))
11989 /* Set up an iterator for the tool-bar window. */
11990 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11991 it
.first_visible_x
= 0;
11992 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11993 row
= it
.glyph_row
;
11995 /* Build a string that represents the contents of the tool-bar. */
11996 build_desired_tool_bar_string (f
);
11997 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11998 /* FIXME: This should be controlled by a user option. But it
11999 doesn't make sense to have an R2L tool bar if the menu bar cannot
12000 be drawn also R2L, and making the menu bar R2L is tricky due
12001 toolkit-specific code that implements it. If an R2L tool bar is
12002 ever supported, display_tool_bar_line should also be augmented to
12003 call unproduce_glyphs like display_line and display_string
12005 it
.paragraph_embedding
= L2R
;
12007 if (f
->n_tool_bar_rows
== 0)
12011 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12012 nlines
!= WINDOW_TOTAL_LINES (w
)))
12015 int old_height
= WINDOW_TOTAL_LINES (w
);
12017 XSETFRAME (frame
, f
);
12018 Fmodify_frame_parameters (frame
,
12019 list1 (Fcons (Qtool_bar_lines
,
12020 make_number (nlines
))));
12021 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12023 clear_glyph_matrix (w
->desired_matrix
);
12024 f
->fonts_changed
= 1;
12030 /* Display as many lines as needed to display all tool-bar items. */
12032 if (f
->n_tool_bar_rows
> 0)
12034 int border
, rows
, height
, extra
;
12036 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12037 border
= XINT (Vtool_bar_border
);
12038 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12039 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12040 else if (EQ (Vtool_bar_border
, Qborder_width
))
12041 border
= f
->border_width
;
12047 rows
= f
->n_tool_bar_rows
;
12048 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12049 extra
= it
.last_visible_y
- border
- height
* rows
;
12051 while (it
.current_y
< it
.last_visible_y
)
12054 if (extra
> 0 && rows
-- > 0)
12056 h
= (extra
+ rows
- 1) / rows
;
12059 display_tool_bar_line (&it
, height
+ h
);
12064 while (it
.current_y
< it
.last_visible_y
)
12065 display_tool_bar_line (&it
, 0);
12068 /* It doesn't make much sense to try scrolling in the tool-bar
12069 window, so don't do it. */
12070 w
->desired_matrix
->no_scrolling_p
= 1;
12071 w
->must_be_updated_p
= 1;
12073 if (!NILP (Vauto_resize_tool_bars
))
12075 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12076 int change_height_p
= 0;
12078 /* If we couldn't display everything, change the tool-bar's
12079 height if there is room for more. */
12080 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12081 && it
.current_y
< max_tool_bar_height
)
12082 change_height_p
= 1;
12084 row
= it
.glyph_row
- 1;
12086 /* If there are blank lines at the end, except for a partially
12087 visible blank line at the end that is smaller than
12088 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12089 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12090 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12091 change_height_p
= 1;
12093 /* If row displays tool-bar items, but is partially visible,
12094 change the tool-bar's height. */
12095 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12096 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12097 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12098 change_height_p
= 1;
12100 /* Resize windows as needed by changing the `tool-bar-lines'
12101 frame parameter. */
12102 if (change_height_p
)
12105 int old_height
= WINDOW_TOTAL_LINES (w
);
12107 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12109 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12110 && !f
->minimize_tool_bar_window_p
)
12111 ? (nlines
> old_height
)
12112 : (nlines
!= old_height
));
12113 f
->minimize_tool_bar_window_p
= 0;
12115 if (change_height_p
)
12117 XSETFRAME (frame
, f
);
12118 Fmodify_frame_parameters (frame
,
12119 list1 (Fcons (Qtool_bar_lines
,
12120 make_number (nlines
))));
12121 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12123 clear_glyph_matrix (w
->desired_matrix
);
12124 f
->n_tool_bar_rows
= nrows
;
12125 f
->fonts_changed
= 1;
12132 f
->minimize_tool_bar_window_p
= 0;
12135 #endif /* USE_GTK || HAVE_NS */
12138 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12140 /* Get information about the tool-bar item which is displayed in GLYPH
12141 on frame F. Return in *PROP_IDX the index where tool-bar item
12142 properties start in F->tool_bar_items. Value is zero if
12143 GLYPH doesn't display a tool-bar item. */
12146 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12152 /* This function can be called asynchronously, which means we must
12153 exclude any possibility that Fget_text_property signals an
12155 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12156 charpos
= max (0, charpos
);
12158 /* Get the text property `menu-item' at pos. The value of that
12159 property is the start index of this item's properties in
12160 F->tool_bar_items. */
12161 prop
= Fget_text_property (make_number (charpos
),
12162 Qmenu_item
, f
->current_tool_bar_string
);
12163 if (INTEGERP (prop
))
12165 *prop_idx
= XINT (prop
);
12175 /* Get information about the tool-bar item at position X/Y on frame F.
12176 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12177 the current matrix of the tool-bar window of F, or NULL if not
12178 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12179 item in F->tool_bar_items. Value is
12181 -1 if X/Y is not on a tool-bar item
12182 0 if X/Y is on the same item that was highlighted before.
12186 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12187 int *hpos
, int *vpos
, int *prop_idx
)
12189 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12190 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12193 /* Find the glyph under X/Y. */
12194 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12195 if (*glyph
== NULL
)
12198 /* Get the start of this tool-bar item's properties in
12199 f->tool_bar_items. */
12200 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12203 /* Is mouse on the highlighted item? */
12204 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12205 && *vpos
>= hlinfo
->mouse_face_beg_row
12206 && *vpos
<= hlinfo
->mouse_face_end_row
12207 && (*vpos
> hlinfo
->mouse_face_beg_row
12208 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12209 && (*vpos
< hlinfo
->mouse_face_end_row
12210 || *hpos
< hlinfo
->mouse_face_end_col
12211 || hlinfo
->mouse_face_past_end
))
12219 Handle mouse button event on the tool-bar of frame F, at
12220 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12221 0 for button release. MODIFIERS is event modifiers for button
12225 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12228 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12229 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12230 int hpos
, vpos
, prop_idx
;
12231 struct glyph
*glyph
;
12232 Lisp_Object enabled_p
;
12235 /* If not on the highlighted tool-bar item, and mouse-highlight is
12236 non-nil, return. This is so we generate the tool-bar button
12237 click only when the mouse button is released on the same item as
12238 where it was pressed. However, when mouse-highlight is disabled,
12239 generate the click when the button is released regardless of the
12240 highlight, since tool-bar items are not highlighted in that
12242 frame_to_window_pixel_xy (w
, &x
, &y
);
12243 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12245 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12248 /* When mouse-highlight is off, generate the click for the item
12249 where the button was pressed, disregarding where it was
12251 if (NILP (Vmouse_highlight
) && !down_p
)
12252 prop_idx
= last_tool_bar_item
;
12254 /* If item is disabled, do nothing. */
12255 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12256 if (NILP (enabled_p
))
12261 /* Show item in pressed state. */
12262 if (!NILP (Vmouse_highlight
))
12263 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12264 last_tool_bar_item
= prop_idx
;
12268 Lisp_Object key
, frame
;
12269 struct input_event event
;
12270 EVENT_INIT (event
);
12272 /* Show item in released state. */
12273 if (!NILP (Vmouse_highlight
))
12274 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12276 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12278 XSETFRAME (frame
, f
);
12279 event
.kind
= TOOL_BAR_EVENT
;
12280 event
.frame_or_window
= frame
;
12282 kbd_buffer_store_event (&event
);
12284 event
.kind
= TOOL_BAR_EVENT
;
12285 event
.frame_or_window
= frame
;
12287 event
.modifiers
= modifiers
;
12288 kbd_buffer_store_event (&event
);
12289 last_tool_bar_item
= -1;
12294 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12295 tool-bar window-relative coordinates X/Y. Called from
12296 note_mouse_highlight. */
12299 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12301 Lisp_Object window
= f
->tool_bar_window
;
12302 struct window
*w
= XWINDOW (window
);
12303 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12304 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12306 struct glyph
*glyph
;
12307 struct glyph_row
*row
;
12309 Lisp_Object enabled_p
;
12311 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12312 int mouse_down_p
, rc
;
12314 /* Function note_mouse_highlight is called with negative X/Y
12315 values when mouse moves outside of the frame. */
12316 if (x
<= 0 || y
<= 0)
12318 clear_mouse_face (hlinfo
);
12322 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12325 /* Not on tool-bar item. */
12326 clear_mouse_face (hlinfo
);
12330 /* On same tool-bar item as before. */
12331 goto set_help_echo
;
12333 clear_mouse_face (hlinfo
);
12335 /* Mouse is down, but on different tool-bar item? */
12336 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12337 && f
== dpyinfo
->last_mouse_frame
);
12340 && last_tool_bar_item
!= prop_idx
)
12343 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12345 /* If tool-bar item is not enabled, don't highlight it. */
12346 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12347 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12349 /* Compute the x-position of the glyph. In front and past the
12350 image is a space. We include this in the highlighted area. */
12351 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12352 for (i
= x
= 0; i
< hpos
; ++i
)
12353 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12355 /* Record this as the current active region. */
12356 hlinfo
->mouse_face_beg_col
= hpos
;
12357 hlinfo
->mouse_face_beg_row
= vpos
;
12358 hlinfo
->mouse_face_beg_x
= x
;
12359 hlinfo
->mouse_face_past_end
= 0;
12361 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12362 hlinfo
->mouse_face_end_row
= vpos
;
12363 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12364 hlinfo
->mouse_face_window
= window
;
12365 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12367 /* Display it as active. */
12368 show_mouse_face (hlinfo
, draw
);
12373 /* Set help_echo_string to a help string to display for this tool-bar item.
12374 XTread_socket does the rest. */
12375 help_echo_object
= help_echo_window
= Qnil
;
12376 help_echo_pos
= -1;
12377 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12378 if (NILP (help_echo_string
))
12379 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12382 #endif /* !USE_GTK && !HAVE_NS */
12384 #endif /* HAVE_WINDOW_SYSTEM */
12388 /************************************************************************
12389 Horizontal scrolling
12390 ************************************************************************/
12392 static int hscroll_window_tree (Lisp_Object
);
12393 static int hscroll_windows (Lisp_Object
);
12395 /* For all leaf windows in the window tree rooted at WINDOW, set their
12396 hscroll value so that PT is (i) visible in the window, and (ii) so
12397 that it is not within a certain margin at the window's left and
12398 right border. Value is non-zero if any window's hscroll has been
12402 hscroll_window_tree (Lisp_Object window
)
12404 int hscrolled_p
= 0;
12405 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12406 int hscroll_step_abs
= 0;
12407 double hscroll_step_rel
= 0;
12409 if (hscroll_relative_p
)
12411 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12412 if (hscroll_step_rel
< 0)
12414 hscroll_relative_p
= 0;
12415 hscroll_step_abs
= 0;
12418 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12420 hscroll_step_abs
= XINT (Vhscroll_step
);
12421 if (hscroll_step_abs
< 0)
12422 hscroll_step_abs
= 0;
12425 hscroll_step_abs
= 0;
12427 while (WINDOWP (window
))
12429 struct window
*w
= XWINDOW (window
);
12431 if (WINDOWP (w
->contents
))
12432 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12433 else if (w
->cursor
.vpos
>= 0)
12436 int text_area_width
;
12437 struct glyph_row
*current_cursor_row
12438 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12439 struct glyph_row
*desired_cursor_row
12440 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12441 struct glyph_row
*cursor_row
12442 = (desired_cursor_row
->enabled_p
12443 ? desired_cursor_row
12444 : current_cursor_row
);
12445 int row_r2l_p
= cursor_row
->reversed_p
;
12447 text_area_width
= window_box_width (w
, TEXT_AREA
);
12449 /* Scroll when cursor is inside this scroll margin. */
12450 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12452 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12453 /* For left-to-right rows, hscroll when cursor is either
12454 (i) inside the right hscroll margin, or (ii) if it is
12455 inside the left margin and the window is already
12459 && w
->cursor
.x
<= h_margin
)
12460 || (cursor_row
->enabled_p
12461 && cursor_row
->truncated_on_right_p
12462 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12463 /* For right-to-left rows, the logic is similar,
12464 except that rules for scrolling to left and right
12465 are reversed. E.g., if cursor.x <= h_margin, we
12466 need to hscroll "to the right" unconditionally,
12467 and that will scroll the screen to the left so as
12468 to reveal the next portion of the row. */
12470 && ((cursor_row
->enabled_p
12471 /* FIXME: It is confusing to set the
12472 truncated_on_right_p flag when R2L rows
12473 are actually truncated on the left. */
12474 && cursor_row
->truncated_on_right_p
12475 && w
->cursor
.x
<= h_margin
)
12477 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12481 struct buffer
*saved_current_buffer
;
12485 /* Find point in a display of infinite width. */
12486 saved_current_buffer
= current_buffer
;
12487 current_buffer
= XBUFFER (w
->contents
);
12489 if (w
== XWINDOW (selected_window
))
12492 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12494 /* Move iterator to pt starting at cursor_row->start in
12495 a line with infinite width. */
12496 init_to_row_start (&it
, w
, cursor_row
);
12497 it
.last_visible_x
= INFINITY
;
12498 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12499 current_buffer
= saved_current_buffer
;
12501 /* Position cursor in window. */
12502 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12503 hscroll
= max (0, (it
.current_x
12504 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12505 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12506 : (text_area_width
/ 2))))
12507 / FRAME_COLUMN_WIDTH (it
.f
);
12508 else if ((!row_r2l_p
12509 && w
->cursor
.x
>= text_area_width
- h_margin
)
12510 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12512 if (hscroll_relative_p
)
12513 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12516 wanted_x
= text_area_width
12517 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12520 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12524 if (hscroll_relative_p
)
12525 wanted_x
= text_area_width
* hscroll_step_rel
12528 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12531 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12533 hscroll
= max (hscroll
, w
->min_hscroll
);
12535 /* Don't prevent redisplay optimizations if hscroll
12536 hasn't changed, as it will unnecessarily slow down
12538 if (w
->hscroll
!= hscroll
)
12540 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12541 w
->hscroll
= hscroll
;
12550 /* Value is non-zero if hscroll of any leaf window has been changed. */
12551 return hscrolled_p
;
12555 /* Set hscroll so that cursor is visible and not inside horizontal
12556 scroll margins for all windows in the tree rooted at WINDOW. See
12557 also hscroll_window_tree above. Value is non-zero if any window's
12558 hscroll has been changed. If it has, desired matrices on the frame
12559 of WINDOW are cleared. */
12562 hscroll_windows (Lisp_Object window
)
12564 int hscrolled_p
= hscroll_window_tree (window
);
12566 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12567 return hscrolled_p
;
12572 /************************************************************************
12574 ************************************************************************/
12576 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12577 to a non-zero value. This is sometimes handy to have in a debugger
12582 /* First and last unchanged row for try_window_id. */
12584 static int debug_first_unchanged_at_end_vpos
;
12585 static int debug_last_unchanged_at_beg_vpos
;
12587 /* Delta vpos and y. */
12589 static int debug_dvpos
, debug_dy
;
12591 /* Delta in characters and bytes for try_window_id. */
12593 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12595 /* Values of window_end_pos and window_end_vpos at the end of
12598 static ptrdiff_t debug_end_vpos
;
12600 /* Append a string to W->desired_matrix->method. FMT is a printf
12601 format string. If trace_redisplay_p is non-zero also printf the
12602 resulting string to stderr. */
12604 static void debug_method_add (struct window
*, char const *, ...)
12605 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12608 debug_method_add (struct window
*w
, char const *fmt
, ...)
12611 char *method
= w
->desired_matrix
->method
;
12612 int len
= strlen (method
);
12613 int size
= sizeof w
->desired_matrix
->method
;
12614 int remaining
= size
- len
- 1;
12617 if (len
&& remaining
)
12620 --remaining
, ++len
;
12623 va_start (ap
, fmt
);
12624 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12627 if (trace_redisplay_p
)
12628 fprintf (stderr
, "%p (%s): %s\n",
12630 ((BUFFERP (w
->contents
)
12631 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12632 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12637 #endif /* GLYPH_DEBUG */
12640 /* Value is non-zero if all changes in window W, which displays
12641 current_buffer, are in the text between START and END. START is a
12642 buffer position, END is given as a distance from Z. Used in
12643 redisplay_internal for display optimization. */
12646 text_outside_line_unchanged_p (struct window
*w
,
12647 ptrdiff_t start
, ptrdiff_t end
)
12649 int unchanged_p
= 1;
12651 /* If text or overlays have changed, see where. */
12652 if (window_outdated (w
))
12654 /* Gap in the line? */
12655 if (GPT
< start
|| Z
- GPT
< end
)
12658 /* Changes start in front of the line, or end after it? */
12660 && (BEG_UNCHANGED
< start
- 1
12661 || END_UNCHANGED
< end
))
12664 /* If selective display, can't optimize if changes start at the
12665 beginning of the line. */
12667 && INTEGERP (BVAR (current_buffer
, selective_display
))
12668 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12669 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12672 /* If there are overlays at the start or end of the line, these
12673 may have overlay strings with newlines in them. A change at
12674 START, for instance, may actually concern the display of such
12675 overlay strings as well, and they are displayed on different
12676 lines. So, quickly rule out this case. (For the future, it
12677 might be desirable to implement something more telling than
12678 just BEG/END_UNCHANGED.) */
12681 if (BEG
+ BEG_UNCHANGED
== start
12682 && overlay_touches_p (start
))
12684 if (END_UNCHANGED
== end
12685 && overlay_touches_p (Z
- end
))
12689 /* Under bidi reordering, adding or deleting a character in the
12690 beginning of a paragraph, before the first strong directional
12691 character, can change the base direction of the paragraph (unless
12692 the buffer specifies a fixed paragraph direction), which will
12693 require to redisplay the whole paragraph. It might be worthwhile
12694 to find the paragraph limits and widen the range of redisplayed
12695 lines to that, but for now just give up this optimization. */
12696 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12697 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12701 return unchanged_p
;
12705 /* Do a frame update, taking possible shortcuts into account. This is
12706 the main external entry point for redisplay.
12708 If the last redisplay displayed an echo area message and that message
12709 is no longer requested, we clear the echo area or bring back the
12710 mini-buffer if that is in use. */
12715 redisplay_internal ();
12720 overlay_arrow_string_or_property (Lisp_Object var
)
12724 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12727 return Voverlay_arrow_string
;
12730 /* Return 1 if there are any overlay-arrows in current_buffer. */
12732 overlay_arrow_in_current_buffer_p (void)
12736 for (vlist
= Voverlay_arrow_variable_list
;
12738 vlist
= XCDR (vlist
))
12740 Lisp_Object var
= XCAR (vlist
);
12743 if (!SYMBOLP (var
))
12745 val
= find_symbol_value (var
);
12747 && current_buffer
== XMARKER (val
)->buffer
)
12754 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12758 overlay_arrows_changed_p (void)
12762 for (vlist
= Voverlay_arrow_variable_list
;
12764 vlist
= XCDR (vlist
))
12766 Lisp_Object var
= XCAR (vlist
);
12767 Lisp_Object val
, pstr
;
12769 if (!SYMBOLP (var
))
12771 val
= find_symbol_value (var
);
12772 if (!MARKERP (val
))
12774 if (! EQ (COERCE_MARKER (val
),
12775 Fget (var
, Qlast_arrow_position
))
12776 || ! (pstr
= overlay_arrow_string_or_property (var
),
12777 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12783 /* Mark overlay arrows to be updated on next redisplay. */
12786 update_overlay_arrows (int up_to_date
)
12790 for (vlist
= Voverlay_arrow_variable_list
;
12792 vlist
= XCDR (vlist
))
12794 Lisp_Object var
= XCAR (vlist
);
12796 if (!SYMBOLP (var
))
12799 if (up_to_date
> 0)
12801 Lisp_Object val
= find_symbol_value (var
);
12802 Fput (var
, Qlast_arrow_position
,
12803 COERCE_MARKER (val
));
12804 Fput (var
, Qlast_arrow_string
,
12805 overlay_arrow_string_or_property (var
));
12807 else if (up_to_date
< 0
12808 || !NILP (Fget (var
, Qlast_arrow_position
)))
12810 Fput (var
, Qlast_arrow_position
, Qt
);
12811 Fput (var
, Qlast_arrow_string
, Qt
);
12817 /* Return overlay arrow string to display at row.
12818 Return integer (bitmap number) for arrow bitmap in left fringe.
12819 Return nil if no overlay arrow. */
12822 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12826 for (vlist
= Voverlay_arrow_variable_list
;
12828 vlist
= XCDR (vlist
))
12830 Lisp_Object var
= XCAR (vlist
);
12833 if (!SYMBOLP (var
))
12836 val
= find_symbol_value (var
);
12839 && current_buffer
== XMARKER (val
)->buffer
12840 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12842 if (FRAME_WINDOW_P (it
->f
)
12843 /* FIXME: if ROW->reversed_p is set, this should test
12844 the right fringe, not the left one. */
12845 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12847 #ifdef HAVE_WINDOW_SYSTEM
12848 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12851 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12852 return make_number (fringe_bitmap
);
12855 return make_number (-1); /* Use default arrow bitmap. */
12857 return overlay_arrow_string_or_property (var
);
12864 /* Return 1 if point moved out of or into a composition. Otherwise
12865 return 0. PREV_BUF and PREV_PT are the last point buffer and
12866 position. BUF and PT are the current point buffer and position. */
12869 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12870 struct buffer
*buf
, ptrdiff_t pt
)
12872 ptrdiff_t start
, end
;
12874 Lisp_Object buffer
;
12876 XSETBUFFER (buffer
, buf
);
12877 /* Check a composition at the last point if point moved within the
12879 if (prev_buf
== buf
)
12882 /* Point didn't move. */
12885 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12886 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12887 && composition_valid_p (start
, end
, prop
)
12888 && start
< prev_pt
&& end
> prev_pt
)
12889 /* The last point was within the composition. Return 1 iff
12890 point moved out of the composition. */
12891 return (pt
<= start
|| pt
>= end
);
12894 /* Check a composition at the current point. */
12895 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12896 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12897 && composition_valid_p (start
, end
, prop
)
12898 && start
< pt
&& end
> pt
);
12901 /* Reconsider the clip changes of buffer which is displayed in W. */
12904 reconsider_clip_changes (struct window
*w
)
12906 struct buffer
*b
= XBUFFER (w
->contents
);
12908 if (b
->clip_changed
12909 && w
->window_end_valid
12910 && w
->current_matrix
->buffer
== b
12911 && w
->current_matrix
->zv
== BUF_ZV (b
)
12912 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12913 b
->clip_changed
= 0;
12915 /* If display wasn't paused, and W is not a tool bar window, see if
12916 point has been moved into or out of a composition. In that case,
12917 we set b->clip_changed to 1 to force updating the screen. If
12918 b->clip_changed has already been set to 1, we can skip this
12920 if (!b
->clip_changed
&& w
->window_end_valid
)
12922 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12923 ? PT
: marker_position (w
->pointm
));
12925 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12926 && check_point_in_composition (w
->current_matrix
->buffer
,
12927 w
->last_point
, b
, pt
))
12928 b
->clip_changed
= 1;
12933 propagate_buffer_redisplay (void)
12934 { /* Resetting b->text->redisplay is problematic!
12935 We can't just reset it in the case that some window that displays
12936 it has not been redisplayed; and such a window can stay
12937 unredisplayed for a long time if it's currently invisible.
12938 But we do want to reset it at the end of redisplay otherwise
12939 its displayed windows will keep being redisplayed over and over
12941 So we copy all b->text->redisplay flags up to their windows here,
12942 such that mark_window_display_accurate can safely reset
12943 b->text->redisplay. */
12944 Lisp_Object ws
= window_list ();
12945 for (; CONSP (ws
); ws
= XCDR (ws
))
12947 struct window
*thisw
= XWINDOW (XCAR (ws
));
12948 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
12949 if (thisb
->text
->redisplay
)
12950 thisw
->redisplay
= true;
12954 #define STOP_POLLING \
12955 do { if (! polling_stopped_here) stop_polling (); \
12956 polling_stopped_here = 1; } while (0)
12958 #define RESUME_POLLING \
12959 do { if (polling_stopped_here) start_polling (); \
12960 polling_stopped_here = 0; } while (0)
12963 /* Perhaps in the future avoid recentering windows if it
12964 is not necessary; currently that causes some problems. */
12967 redisplay_internal (void)
12969 struct window
*w
= XWINDOW (selected_window
);
12973 bool must_finish
= 0, match_p
;
12974 struct text_pos tlbufpos
, tlendpos
;
12975 int number_of_visible_frames
;
12978 int polling_stopped_here
= 0;
12979 Lisp_Object tail
, frame
;
12981 /* True means redisplay has to consider all windows on all
12982 frames. False, only selected_window is considered. */
12983 bool consider_all_windows_p
;
12985 /* True means redisplay has to redisplay the miniwindow. */
12986 bool update_miniwindow_p
= false;
12988 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12990 /* No redisplay if running in batch mode or frame is not yet fully
12991 initialized, or redisplay is explicitly turned off by setting
12992 Vinhibit_redisplay. */
12993 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12994 || !NILP (Vinhibit_redisplay
))
12997 /* Don't examine these until after testing Vinhibit_redisplay.
12998 When Emacs is shutting down, perhaps because its connection to
12999 X has dropped, we should not look at them at all. */
13000 fr
= XFRAME (w
->frame
);
13001 sf
= SELECTED_FRAME ();
13003 if (!fr
->glyphs_initialized_p
)
13006 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13007 if (popup_activated ())
13011 /* I don't think this happens but let's be paranoid. */
13012 if (redisplaying_p
)
13015 /* Record a function that clears redisplaying_p
13016 when we leave this function. */
13017 count
= SPECPDL_INDEX ();
13018 record_unwind_protect_void (unwind_redisplay
);
13019 redisplaying_p
= 1;
13020 specbind (Qinhibit_free_realized_faces
, Qnil
);
13022 /* Record this function, so it appears on the profiler's backtraces. */
13023 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13025 FOR_EACH_FRAME (tail
, frame
)
13026 XFRAME (frame
)->already_hscrolled_p
= 0;
13029 /* Remember the currently selected window. */
13033 last_escape_glyph_frame
= NULL
;
13034 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13035 last_glyphless_glyph_frame
= NULL
;
13036 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13038 /* If face_change_count is non-zero, init_iterator will free all
13039 realized faces, which includes the faces referenced from current
13040 matrices. So, we can't reuse current matrices in this case. */
13041 if (face_change_count
)
13042 windows_or_buffers_changed
= 47;
13044 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13045 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13047 /* Since frames on a single ASCII terminal share the same
13048 display area, displaying a different frame means redisplay
13049 the whole thing. */
13050 SET_FRAME_GARBAGED (sf
);
13052 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13054 FRAME_TTY (sf
)->previous_frame
= sf
;
13057 /* Set the visible flags for all frames. Do this before checking for
13058 resized or garbaged frames; they want to know if their frames are
13059 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13060 number_of_visible_frames
= 0;
13062 FOR_EACH_FRAME (tail
, frame
)
13064 struct frame
*f
= XFRAME (frame
);
13066 if (FRAME_VISIBLE_P (f
))
13068 ++number_of_visible_frames
;
13069 /* Adjust matrices for visible frames only. */
13070 if (f
->fonts_changed
)
13072 adjust_frame_glyphs (f
);
13073 f
->fonts_changed
= 0;
13075 /* If cursor type has been changed on the frame
13076 other than selected, consider all frames. */
13077 if (f
!= sf
&& f
->cursor_type_changed
)
13078 update_mode_lines
= 31;
13080 clear_desired_matrices (f
);
13083 /* Notice any pending interrupt request to change frame size. */
13084 do_pending_window_change (1);
13086 /* do_pending_window_change could change the selected_window due to
13087 frame resizing which makes the selected window too small. */
13088 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13091 /* Clear frames marked as garbaged. */
13092 clear_garbaged_frames ();
13094 /* Build menubar and tool-bar items. */
13095 if (NILP (Vmemory_full
))
13096 prepare_menu_bars ();
13098 reconsider_clip_changes (w
);
13100 /* In most cases selected window displays current buffer. */
13101 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13104 /* Detect case that we need to write or remove a star in the mode line. */
13105 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13106 w
->update_mode_line
= 1;
13108 if (mode_line_update_needed (w
))
13109 w
->update_mode_line
= 1;
13112 /* Normally the message* functions will have already displayed and
13113 updated the echo area, but the frame may have been trashed, or
13114 the update may have been preempted, so display the echo area
13115 again here. Checking message_cleared_p captures the case that
13116 the echo area should be cleared. */
13117 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13118 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13119 || (message_cleared_p
13120 && minibuf_level
== 0
13121 /* If the mini-window is currently selected, this means the
13122 echo-area doesn't show through. */
13123 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13125 int window_height_changed_p
= echo_area_display (0);
13127 if (message_cleared_p
)
13128 update_miniwindow_p
= true;
13132 /* If we don't display the current message, don't clear the
13133 message_cleared_p flag, because, if we did, we wouldn't clear
13134 the echo area in the next redisplay which doesn't preserve
13136 if (!display_last_displayed_message_p
)
13137 message_cleared_p
= 0;
13139 if (window_height_changed_p
)
13141 windows_or_buffers_changed
= 50;
13143 /* If window configuration was changed, frames may have been
13144 marked garbaged. Clear them or we will experience
13145 surprises wrt scrolling. */
13146 clear_garbaged_frames ();
13149 else if (EQ (selected_window
, minibuf_window
)
13150 && (current_buffer
->clip_changed
|| window_outdated (w
))
13151 && resize_mini_window (w
, 0))
13153 /* Resized active mini-window to fit the size of what it is
13154 showing if its contents might have changed. */
13157 /* If window configuration was changed, frames may have been
13158 marked garbaged. Clear them or we will experience
13159 surprises wrt scrolling. */
13160 clear_garbaged_frames ();
13163 if (windows_or_buffers_changed
&& !update_mode_lines
)
13164 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13165 only the windows's contents needs to be refreshed, or whether the
13166 mode-lines also need a refresh. */
13167 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13168 ? REDISPLAY_SOME
: 32);
13170 /* If specs for an arrow have changed, do thorough redisplay
13171 to ensure we remove any arrow that should no longer exist. */
13172 if (overlay_arrows_changed_p ())
13173 /* Apparently, this is the only case where we update other windows,
13174 without updating other mode-lines. */
13175 windows_or_buffers_changed
= 49;
13177 consider_all_windows_p
= (update_mode_lines
13178 || windows_or_buffers_changed
);
13180 #define AINC(a,i) \
13181 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13182 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13184 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13185 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13187 /* Optimize the case that only the line containing the cursor in the
13188 selected window has changed. Variables starting with this_ are
13189 set in display_line and record information about the line
13190 containing the cursor. */
13191 tlbufpos
= this_line_start_pos
;
13192 tlendpos
= this_line_end_pos
;
13193 if (!consider_all_windows_p
13194 && CHARPOS (tlbufpos
) > 0
13195 && !w
->update_mode_line
13196 && !current_buffer
->clip_changed
13197 && !current_buffer
->prevent_redisplay_optimizations_p
13198 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13199 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13200 && !XFRAME (w
->frame
)->cursor_type_changed
13201 /* Make sure recorded data applies to current buffer, etc. */
13202 && this_line_buffer
== current_buffer
13205 && !w
->optional_new_start
13206 /* Point must be on the line that we have info recorded about. */
13207 && PT
>= CHARPOS (tlbufpos
)
13208 && PT
<= Z
- CHARPOS (tlendpos
)
13209 /* All text outside that line, including its final newline,
13210 must be unchanged. */
13211 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13212 CHARPOS (tlendpos
)))
13214 if (CHARPOS (tlbufpos
) > BEGV
13215 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13216 && (CHARPOS (tlbufpos
) == ZV
13217 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13218 /* Former continuation line has disappeared by becoming empty. */
13220 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13222 /* We have to handle the case of continuation around a
13223 wide-column character (see the comment in indent.c around
13226 For instance, in the following case:
13228 -------- Insert --------
13229 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13230 J_I_ ==> J_I_ `^^' are cursors.
13234 As we have to redraw the line above, we cannot use this
13238 int line_height_before
= this_line_pixel_height
;
13240 /* Note that start_display will handle the case that the
13241 line starting at tlbufpos is a continuation line. */
13242 start_display (&it
, w
, tlbufpos
);
13244 /* Implementation note: It this still necessary? */
13245 if (it
.current_x
!= this_line_start_x
)
13248 TRACE ((stderr
, "trying display optimization 1\n"));
13249 w
->cursor
.vpos
= -1;
13250 overlay_arrow_seen
= 0;
13251 it
.vpos
= this_line_vpos
;
13252 it
.current_y
= this_line_y
;
13253 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13254 display_line (&it
);
13256 /* If line contains point, is not continued,
13257 and ends at same distance from eob as before, we win. */
13258 if (w
->cursor
.vpos
>= 0
13259 /* Line is not continued, otherwise this_line_start_pos
13260 would have been set to 0 in display_line. */
13261 && CHARPOS (this_line_start_pos
)
13262 /* Line ends as before. */
13263 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13264 /* Line has same height as before. Otherwise other lines
13265 would have to be shifted up or down. */
13266 && this_line_pixel_height
== line_height_before
)
13268 /* If this is not the window's last line, we must adjust
13269 the charstarts of the lines below. */
13270 if (it
.current_y
< it
.last_visible_y
)
13272 struct glyph_row
*row
13273 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13274 ptrdiff_t delta
, delta_bytes
;
13276 /* We used to distinguish between two cases here,
13277 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13278 when the line ends in a newline or the end of the
13279 buffer's accessible portion. But both cases did
13280 the same, so they were collapsed. */
13282 - CHARPOS (tlendpos
)
13283 - MATRIX_ROW_START_CHARPOS (row
));
13284 delta_bytes
= (Z_BYTE
13285 - BYTEPOS (tlendpos
)
13286 - MATRIX_ROW_START_BYTEPOS (row
));
13288 increment_matrix_positions (w
->current_matrix
,
13289 this_line_vpos
+ 1,
13290 w
->current_matrix
->nrows
,
13291 delta
, delta_bytes
);
13294 /* If this row displays text now but previously didn't,
13295 or vice versa, w->window_end_vpos may have to be
13297 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13299 if (w
->window_end_vpos
< this_line_vpos
)
13300 w
->window_end_vpos
= this_line_vpos
;
13302 else if (w
->window_end_vpos
== this_line_vpos
13303 && this_line_vpos
> 0)
13304 w
->window_end_vpos
= this_line_vpos
- 1;
13305 w
->window_end_valid
= 0;
13307 /* Update hint: No need to try to scroll in update_window. */
13308 w
->desired_matrix
->no_scrolling_p
= 1;
13311 *w
->desired_matrix
->method
= 0;
13312 debug_method_add (w
, "optimization 1");
13314 #ifdef HAVE_WINDOW_SYSTEM
13315 update_window_fringes (w
, 0);
13322 else if (/* Cursor position hasn't changed. */
13323 PT
== w
->last_point
13324 /* Make sure the cursor was last displayed
13325 in this window. Otherwise we have to reposition it. */
13326 && 0 <= w
->cursor
.vpos
13327 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13331 do_pending_window_change (1);
13332 /* If selected_window changed, redisplay again. */
13333 if (WINDOWP (selected_window
)
13334 && (w
= XWINDOW (selected_window
)) != sw
)
13337 /* We used to always goto end_of_redisplay here, but this
13338 isn't enough if we have a blinking cursor. */
13339 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13340 goto end_of_redisplay
;
13344 /* If highlighting the region, or if the cursor is in the echo area,
13345 then we can't just move the cursor. */
13346 else if (NILP (Vshow_trailing_whitespace
)
13347 && !cursor_in_echo_area
)
13350 struct glyph_row
*row
;
13352 /* Skip from tlbufpos to PT and see where it is. Note that
13353 PT may be in invisible text. If so, we will end at the
13354 next visible position. */
13355 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13356 NULL
, DEFAULT_FACE_ID
);
13357 it
.current_x
= this_line_start_x
;
13358 it
.current_y
= this_line_y
;
13359 it
.vpos
= this_line_vpos
;
13361 /* The call to move_it_to stops in front of PT, but
13362 moves over before-strings. */
13363 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13365 if (it
.vpos
== this_line_vpos
13366 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13369 eassert (this_line_vpos
== it
.vpos
);
13370 eassert (this_line_y
== it
.current_y
);
13371 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13373 *w
->desired_matrix
->method
= 0;
13374 debug_method_add (w
, "optimization 3");
13383 /* Text changed drastically or point moved off of line. */
13384 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13387 CHARPOS (this_line_start_pos
) = 0;
13388 ++clear_face_cache_count
;
13389 #ifdef HAVE_WINDOW_SYSTEM
13390 ++clear_image_cache_count
;
13393 /* Build desired matrices, and update the display. If
13394 consider_all_windows_p is non-zero, do it for all windows on all
13395 frames. Otherwise do it for selected_window, only. */
13397 if (consider_all_windows_p
)
13399 FOR_EACH_FRAME (tail
, frame
)
13400 XFRAME (frame
)->updated_p
= 0;
13402 propagate_buffer_redisplay ();
13404 FOR_EACH_FRAME (tail
, frame
)
13406 struct frame
*f
= XFRAME (frame
);
13408 /* We don't have to do anything for unselected terminal
13410 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13411 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13416 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13419 /* Only GC scollbars when we redisplay the whole frame. */
13420 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13421 /* Mark all the scroll bars to be removed; we'll redeem
13422 the ones we want when we redisplay their windows. */
13423 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13424 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13426 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13427 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13428 /* Remember that the invisible frames need to be redisplayed next
13429 time they're visible. */
13430 else if (!REDISPLAY_SOME_P ())
13431 f
->redisplay
= true;
13433 /* The X error handler may have deleted that frame. */
13434 if (!FRAME_LIVE_P (f
))
13437 /* Any scroll bars which redisplay_windows should have
13438 nuked should now go away. */
13439 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13440 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13442 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13444 /* If fonts changed on visible frame, display again. */
13445 if (f
->fonts_changed
)
13447 adjust_frame_glyphs (f
);
13448 f
->fonts_changed
= 0;
13452 /* See if we have to hscroll. */
13453 if (!f
->already_hscrolled_p
)
13455 f
->already_hscrolled_p
= 1;
13456 if (hscroll_windows (f
->root_window
))
13460 /* Prevent various kinds of signals during display
13461 update. stdio is not robust about handling
13462 signals, which can cause an apparent I/O error. */
13463 if (interrupt_input
)
13464 unrequest_sigio ();
13467 pending
|= update_frame (f
, 0, 0);
13468 f
->cursor_type_changed
= 0;
13474 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13478 /* Do the mark_window_display_accurate after all windows have
13479 been redisplayed because this call resets flags in buffers
13480 which are needed for proper redisplay. */
13481 FOR_EACH_FRAME (tail
, frame
)
13483 struct frame
*f
= XFRAME (frame
);
13486 f
->redisplay
= false;
13487 mark_window_display_accurate (f
->root_window
, 1);
13488 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13489 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13494 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13496 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13497 struct frame
*mini_frame
;
13499 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13500 /* Use list_of_error, not Qerror, so that
13501 we catch only errors and don't run the debugger. */
13502 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13504 redisplay_window_error
);
13505 if (update_miniwindow_p
)
13506 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13508 redisplay_window_error
);
13510 /* Compare desired and current matrices, perform output. */
13513 /* If fonts changed, display again. */
13514 if (sf
->fonts_changed
)
13517 /* Prevent various kinds of signals during display update.
13518 stdio is not robust about handling signals,
13519 which can cause an apparent I/O error. */
13520 if (interrupt_input
)
13521 unrequest_sigio ();
13524 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13526 if (hscroll_windows (selected_window
))
13529 XWINDOW (selected_window
)->must_be_updated_p
= true;
13530 pending
= update_frame (sf
, 0, 0);
13531 sf
->cursor_type_changed
= 0;
13534 /* We may have called echo_area_display at the top of this
13535 function. If the echo area is on another frame, that may
13536 have put text on a frame other than the selected one, so the
13537 above call to update_frame would not have caught it. Catch
13539 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13540 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13542 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13544 XWINDOW (mini_window
)->must_be_updated_p
= true;
13545 pending
|= update_frame (mini_frame
, 0, 0);
13546 mini_frame
->cursor_type_changed
= 0;
13547 if (!pending
&& hscroll_windows (mini_window
))
13552 /* If display was paused because of pending input, make sure we do a
13553 thorough update the next time. */
13556 /* Prevent the optimization at the beginning of
13557 redisplay_internal that tries a single-line update of the
13558 line containing the cursor in the selected window. */
13559 CHARPOS (this_line_start_pos
) = 0;
13561 /* Let the overlay arrow be updated the next time. */
13562 update_overlay_arrows (0);
13564 /* If we pause after scrolling, some rows in the current
13565 matrices of some windows are not valid. */
13566 if (!WINDOW_FULL_WIDTH_P (w
)
13567 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13568 update_mode_lines
= 36;
13572 if (!consider_all_windows_p
)
13574 /* This has already been done above if
13575 consider_all_windows_p is set. */
13576 if (XBUFFER (w
->contents
)->text
->redisplay
13577 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13578 /* This can happen if b->text->redisplay was set during
13580 propagate_buffer_redisplay ();
13581 mark_window_display_accurate_1 (w
, 1);
13583 /* Say overlay arrows are up to date. */
13584 update_overlay_arrows (1);
13586 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13587 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13590 update_mode_lines
= 0;
13591 windows_or_buffers_changed
= 0;
13594 /* Start SIGIO interrupts coming again. Having them off during the
13595 code above makes it less likely one will discard output, but not
13596 impossible, since there might be stuff in the system buffer here.
13597 But it is much hairier to try to do anything about that. */
13598 if (interrupt_input
)
13602 /* If a frame has become visible which was not before, redisplay
13603 again, so that we display it. Expose events for such a frame
13604 (which it gets when becoming visible) don't call the parts of
13605 redisplay constructing glyphs, so simply exposing a frame won't
13606 display anything in this case. So, we have to display these
13607 frames here explicitly. */
13612 FOR_EACH_FRAME (tail
, frame
)
13614 if (XFRAME (frame
)->visible
)
13618 if (new_count
!= number_of_visible_frames
)
13619 windows_or_buffers_changed
= 52;
13622 /* Change frame size now if a change is pending. */
13623 do_pending_window_change (1);
13625 /* If we just did a pending size change, or have additional
13626 visible frames, or selected_window changed, redisplay again. */
13627 if ((windows_or_buffers_changed
&& !pending
)
13628 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13631 /* Clear the face and image caches.
13633 We used to do this only if consider_all_windows_p. But the cache
13634 needs to be cleared if a timer creates images in the current
13635 buffer (e.g. the test case in Bug#6230). */
13637 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13639 clear_face_cache (0);
13640 clear_face_cache_count
= 0;
13643 #ifdef HAVE_WINDOW_SYSTEM
13644 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13646 clear_image_caches (Qnil
);
13647 clear_image_cache_count
= 0;
13649 #endif /* HAVE_WINDOW_SYSTEM */
13652 unbind_to (count
, Qnil
);
13657 /* Redisplay, but leave alone any recent echo area message unless
13658 another message has been requested in its place.
13660 This is useful in situations where you need to redisplay but no
13661 user action has occurred, making it inappropriate for the message
13662 area to be cleared. See tracking_off and
13663 wait_reading_process_output for examples of these situations.
13665 FROM_WHERE is an integer saying from where this function was
13666 called. This is useful for debugging. */
13669 redisplay_preserve_echo_area (int from_where
)
13671 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13673 if (!NILP (echo_area_buffer
[1]))
13675 /* We have a previously displayed message, but no current
13676 message. Redisplay the previous message. */
13677 display_last_displayed_message_p
= 1;
13678 redisplay_internal ();
13679 display_last_displayed_message_p
= 0;
13682 redisplay_internal ();
13684 flush_frame (SELECTED_FRAME ());
13688 /* Function registered with record_unwind_protect in redisplay_internal. */
13691 unwind_redisplay (void)
13693 redisplaying_p
= 0;
13697 /* Mark the display of leaf window W as accurate or inaccurate.
13698 If ACCURATE_P is non-zero mark display of W as accurate. If
13699 ACCURATE_P is zero, arrange for W to be redisplayed the next
13700 time redisplay_internal is called. */
13703 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13705 struct buffer
*b
= XBUFFER (w
->contents
);
13707 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13708 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13709 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13713 b
->clip_changed
= false;
13714 b
->prevent_redisplay_optimizations_p
= false;
13715 eassert (buffer_window_count (b
) > 0);
13716 /* Resetting b->text->redisplay is problematic!
13717 In order to make it safer to do it here, redisplay_internal must
13718 have copied all b->text->redisplay to their respective windows. */
13719 b
->text
->redisplay
= false;
13721 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13722 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13723 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13724 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13726 w
->current_matrix
->buffer
= b
;
13727 w
->current_matrix
->begv
= BUF_BEGV (b
);
13728 w
->current_matrix
->zv
= BUF_ZV (b
);
13730 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13731 w
->last_cursor_off_p
= w
->cursor_off_p
;
13733 if (w
== XWINDOW (selected_window
))
13734 w
->last_point
= BUF_PT (b
);
13736 w
->last_point
= marker_position (w
->pointm
);
13738 w
->window_end_valid
= true;
13739 w
->update_mode_line
= false;
13742 w
->redisplay
= !accurate_p
;
13746 /* Mark the display of windows in the window tree rooted at WINDOW as
13747 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13748 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13749 be redisplayed the next time redisplay_internal is called. */
13752 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13756 for (; !NILP (window
); window
= w
->next
)
13758 w
= XWINDOW (window
);
13759 if (WINDOWP (w
->contents
))
13760 mark_window_display_accurate (w
->contents
, accurate_p
);
13762 mark_window_display_accurate_1 (w
, accurate_p
);
13766 update_overlay_arrows (1);
13768 /* Force a thorough redisplay the next time by setting
13769 last_arrow_position and last_arrow_string to t, which is
13770 unequal to any useful value of Voverlay_arrow_... */
13771 update_overlay_arrows (-1);
13775 /* Return value in display table DP (Lisp_Char_Table *) for character
13776 C. Since a display table doesn't have any parent, we don't have to
13777 follow parent. Do not call this function directly but use the
13778 macro DISP_CHAR_VECTOR. */
13781 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13785 if (ASCII_CHAR_P (c
))
13788 if (SUB_CHAR_TABLE_P (val
))
13789 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13795 XSETCHAR_TABLE (table
, dp
);
13796 val
= char_table_ref (table
, c
);
13805 /***********************************************************************
13807 ***********************************************************************/
13809 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13812 redisplay_windows (Lisp_Object window
)
13814 while (!NILP (window
))
13816 struct window
*w
= XWINDOW (window
);
13818 if (WINDOWP (w
->contents
))
13819 redisplay_windows (w
->contents
);
13820 else if (BUFFERP (w
->contents
))
13822 displayed_buffer
= XBUFFER (w
->contents
);
13823 /* Use list_of_error, not Qerror, so that
13824 we catch only errors and don't run the debugger. */
13825 internal_condition_case_1 (redisplay_window_0
, window
,
13827 redisplay_window_error
);
13835 redisplay_window_error (Lisp_Object ignore
)
13837 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13842 redisplay_window_0 (Lisp_Object window
)
13844 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13845 redisplay_window (window
, false);
13850 redisplay_window_1 (Lisp_Object window
)
13852 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13853 redisplay_window (window
, true);
13858 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13859 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13860 which positions recorded in ROW differ from current buffer
13863 Return 0 if cursor is not on this row, 1 otherwise. */
13866 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13867 struct glyph_matrix
*matrix
,
13868 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13871 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13872 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13873 struct glyph
*cursor
= NULL
;
13874 /* The last known character position in row. */
13875 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13877 ptrdiff_t pt_old
= PT
- delta
;
13878 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13879 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13880 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13881 /* A glyph beyond the edge of TEXT_AREA which we should never
13883 struct glyph
*glyphs_end
= end
;
13884 /* Non-zero means we've found a match for cursor position, but that
13885 glyph has the avoid_cursor_p flag set. */
13886 int match_with_avoid_cursor
= 0;
13887 /* Non-zero means we've seen at least one glyph that came from a
13889 int string_seen
= 0;
13890 /* Largest and smallest buffer positions seen so far during scan of
13892 ptrdiff_t bpos_max
= pos_before
;
13893 ptrdiff_t bpos_min
= pos_after
;
13894 /* Last buffer position covered by an overlay string with an integer
13895 `cursor' property. */
13896 ptrdiff_t bpos_covered
= 0;
13897 /* Non-zero means the display string on which to display the cursor
13898 comes from a text property, not from an overlay. */
13899 int string_from_text_prop
= 0;
13901 /* Don't even try doing anything if called for a mode-line or
13902 header-line row, since the rest of the code isn't prepared to
13903 deal with such calamities. */
13904 eassert (!row
->mode_line_p
);
13905 if (row
->mode_line_p
)
13908 /* Skip over glyphs not having an object at the start and the end of
13909 the row. These are special glyphs like truncation marks on
13910 terminal frames. */
13911 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13913 if (!row
->reversed_p
)
13916 && INTEGERP (glyph
->object
)
13917 && glyph
->charpos
< 0)
13919 x
+= glyph
->pixel_width
;
13923 && INTEGERP ((end
- 1)->object
)
13924 /* CHARPOS is zero for blanks and stretch glyphs
13925 inserted by extend_face_to_end_of_line. */
13926 && (end
- 1)->charpos
<= 0)
13928 glyph_before
= glyph
- 1;
13935 /* If the glyph row is reversed, we need to process it from back
13936 to front, so swap the edge pointers. */
13937 glyphs_end
= end
= glyph
- 1;
13938 glyph
+= row
->used
[TEXT_AREA
] - 1;
13940 while (glyph
> end
+ 1
13941 && INTEGERP (glyph
->object
)
13942 && glyph
->charpos
< 0)
13945 x
-= glyph
->pixel_width
;
13947 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13949 /* By default, in reversed rows we put the cursor on the
13950 rightmost (first in the reading order) glyph. */
13951 for (g
= end
+ 1; g
< glyph
; g
++)
13952 x
+= g
->pixel_width
;
13954 && INTEGERP ((end
+ 1)->object
)
13955 && (end
+ 1)->charpos
<= 0)
13957 glyph_before
= glyph
+ 1;
13961 else if (row
->reversed_p
)
13963 /* In R2L rows that don't display text, put the cursor on the
13964 rightmost glyph. Case in point: an empty last line that is
13965 part of an R2L paragraph. */
13967 /* Avoid placing the cursor on the last glyph of the row, where
13968 on terminal frames we hold the vertical border between
13969 adjacent windows. */
13970 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13971 && !WINDOW_RIGHTMOST_P (w
)
13972 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13974 x
= -1; /* will be computed below, at label compute_x */
13977 /* Step 1: Try to find the glyph whose character position
13978 corresponds to point. If that's not possible, find 2 glyphs
13979 whose character positions are the closest to point, one before
13980 point, the other after it. */
13981 if (!row
->reversed_p
)
13982 while (/* not marched to end of glyph row */
13984 /* glyph was not inserted by redisplay for internal purposes */
13985 && !INTEGERP (glyph
->object
))
13987 if (BUFFERP (glyph
->object
))
13989 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13991 if (glyph
->charpos
> bpos_max
)
13992 bpos_max
= glyph
->charpos
;
13993 if (glyph
->charpos
< bpos_min
)
13994 bpos_min
= glyph
->charpos
;
13995 if (!glyph
->avoid_cursor_p
)
13997 /* If we hit point, we've found the glyph on which to
13998 display the cursor. */
14001 match_with_avoid_cursor
= 0;
14004 /* See if we've found a better approximation to
14005 POS_BEFORE or to POS_AFTER. */
14006 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14008 pos_before
= glyph
->charpos
;
14009 glyph_before
= glyph
;
14011 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14013 pos_after
= glyph
->charpos
;
14014 glyph_after
= glyph
;
14017 else if (dpos
== 0)
14018 match_with_avoid_cursor
= 1;
14020 else if (STRINGP (glyph
->object
))
14022 Lisp_Object chprop
;
14023 ptrdiff_t glyph_pos
= glyph
->charpos
;
14025 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14027 if (!NILP (chprop
))
14029 /* If the string came from a `display' text property,
14030 look up the buffer position of that property and
14031 use that position to update bpos_max, as if we
14032 actually saw such a position in one of the row's
14033 glyphs. This helps with supporting integer values
14034 of `cursor' property on the display string in
14035 situations where most or all of the row's buffer
14036 text is completely covered by display properties,
14037 so that no glyph with valid buffer positions is
14038 ever seen in the row. */
14039 ptrdiff_t prop_pos
=
14040 string_buffer_position_lim (glyph
->object
, pos_before
,
14043 if (prop_pos
>= pos_before
)
14044 bpos_max
= prop_pos
- 1;
14046 if (INTEGERP (chprop
))
14048 bpos_covered
= bpos_max
+ XINT (chprop
);
14049 /* If the `cursor' property covers buffer positions up
14050 to and including point, we should display cursor on
14051 this glyph. Note that, if a `cursor' property on one
14052 of the string's characters has an integer value, we
14053 will break out of the loop below _before_ we get to
14054 the position match above. IOW, integer values of
14055 the `cursor' property override the "exact match for
14056 point" strategy of positioning the cursor. */
14057 /* Implementation note: bpos_max == pt_old when, e.g.,
14058 we are in an empty line, where bpos_max is set to
14059 MATRIX_ROW_START_CHARPOS, see above. */
14060 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14069 x
+= glyph
->pixel_width
;
14072 else if (glyph
> end
) /* row is reversed */
14073 while (!INTEGERP (glyph
->object
))
14075 if (BUFFERP (glyph
->object
))
14077 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14079 if (glyph
->charpos
> bpos_max
)
14080 bpos_max
= glyph
->charpos
;
14081 if (glyph
->charpos
< bpos_min
)
14082 bpos_min
= glyph
->charpos
;
14083 if (!glyph
->avoid_cursor_p
)
14087 match_with_avoid_cursor
= 0;
14090 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14092 pos_before
= glyph
->charpos
;
14093 glyph_before
= glyph
;
14095 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14097 pos_after
= glyph
->charpos
;
14098 glyph_after
= glyph
;
14101 else if (dpos
== 0)
14102 match_with_avoid_cursor
= 1;
14104 else if (STRINGP (glyph
->object
))
14106 Lisp_Object chprop
;
14107 ptrdiff_t glyph_pos
= glyph
->charpos
;
14109 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14111 if (!NILP (chprop
))
14113 ptrdiff_t prop_pos
=
14114 string_buffer_position_lim (glyph
->object
, pos_before
,
14117 if (prop_pos
>= pos_before
)
14118 bpos_max
= prop_pos
- 1;
14120 if (INTEGERP (chprop
))
14122 bpos_covered
= bpos_max
+ XINT (chprop
);
14123 /* If the `cursor' property covers buffer positions up
14124 to and including point, we should display cursor on
14126 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14135 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14137 x
--; /* can't use any pixel_width */
14140 x
-= glyph
->pixel_width
;
14143 /* Step 2: If we didn't find an exact match for point, we need to
14144 look for a proper place to put the cursor among glyphs between
14145 GLYPH_BEFORE and GLYPH_AFTER. */
14146 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14147 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14148 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14150 /* An empty line has a single glyph whose OBJECT is zero and
14151 whose CHARPOS is the position of a newline on that line.
14152 Note that on a TTY, there are more glyphs after that, which
14153 were produced by extend_face_to_end_of_line, but their
14154 CHARPOS is zero or negative. */
14156 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14157 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14158 /* On a TTY, continued and truncated rows also have a glyph at
14159 their end whose OBJECT is zero and whose CHARPOS is
14160 positive (the continuation and truncation glyphs), but such
14161 rows are obviously not "empty". */
14162 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14164 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14166 ptrdiff_t ellipsis_pos
;
14168 /* Scan back over the ellipsis glyphs. */
14169 if (!row
->reversed_p
)
14171 ellipsis_pos
= (glyph
- 1)->charpos
;
14172 while (glyph
> row
->glyphs
[TEXT_AREA
]
14173 && (glyph
- 1)->charpos
== ellipsis_pos
)
14174 glyph
--, x
-= glyph
->pixel_width
;
14175 /* That loop always goes one position too far, including
14176 the glyph before the ellipsis. So scan forward over
14178 x
+= glyph
->pixel_width
;
14181 else /* row is reversed */
14183 ellipsis_pos
= (glyph
+ 1)->charpos
;
14184 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14185 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14186 glyph
++, x
+= glyph
->pixel_width
;
14187 x
-= glyph
->pixel_width
;
14191 else if (match_with_avoid_cursor
)
14193 cursor
= glyph_after
;
14196 else if (string_seen
)
14198 int incr
= row
->reversed_p
? -1 : +1;
14200 /* Need to find the glyph that came out of a string which is
14201 present at point. That glyph is somewhere between
14202 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14203 positioned between POS_BEFORE and POS_AFTER in the
14205 struct glyph
*start
, *stop
;
14206 ptrdiff_t pos
= pos_before
;
14210 /* If the row ends in a newline from a display string,
14211 reordering could have moved the glyphs belonging to the
14212 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14213 in this case we extend the search to the last glyph in
14214 the row that was not inserted by redisplay. */
14215 if (row
->ends_in_newline_from_string_p
)
14218 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14221 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14222 correspond to POS_BEFORE and POS_AFTER, respectively. We
14223 need START and STOP in the order that corresponds to the
14224 row's direction as given by its reversed_p flag. If the
14225 directionality of characters between POS_BEFORE and
14226 POS_AFTER is the opposite of the row's base direction,
14227 these characters will have been reordered for display,
14228 and we need to reverse START and STOP. */
14229 if (!row
->reversed_p
)
14231 start
= min (glyph_before
, glyph_after
);
14232 stop
= max (glyph_before
, glyph_after
);
14236 start
= max (glyph_before
, glyph_after
);
14237 stop
= min (glyph_before
, glyph_after
);
14239 for (glyph
= start
+ incr
;
14240 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14243 /* Any glyphs that come from the buffer are here because
14244 of bidi reordering. Skip them, and only pay
14245 attention to glyphs that came from some string. */
14246 if (STRINGP (glyph
->object
))
14250 /* If the display property covers the newline, we
14251 need to search for it one position farther. */
14252 ptrdiff_t lim
= pos_after
14253 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14255 string_from_text_prop
= 0;
14256 str
= glyph
->object
;
14257 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14258 if (tem
== 0 /* from overlay */
14261 /* If the string from which this glyph came is
14262 found in the buffer at point, or at position
14263 that is closer to point than pos_after, then
14264 we've found the glyph we've been looking for.
14265 If it comes from an overlay (tem == 0), and
14266 it has the `cursor' property on one of its
14267 glyphs, record that glyph as a candidate for
14268 displaying the cursor. (As in the
14269 unidirectional version, we will display the
14270 cursor on the last candidate we find.) */
14273 || (tem
- pt_old
> 0 && tem
< pos_after
))
14275 /* The glyphs from this string could have
14276 been reordered. Find the one with the
14277 smallest string position. Or there could
14278 be a character in the string with the
14279 `cursor' property, which means display
14280 cursor on that character's glyph. */
14281 ptrdiff_t strpos
= glyph
->charpos
;
14286 string_from_text_prop
= 1;
14289 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14290 && EQ (glyph
->object
, str
);
14294 ptrdiff_t gpos
= glyph
->charpos
;
14296 cprop
= Fget_char_property (make_number (gpos
),
14304 if (tem
&& glyph
->charpos
< strpos
)
14306 strpos
= glyph
->charpos
;
14312 || (tem
- pt_old
> 0 && tem
< pos_after
))
14316 pos
= tem
+ 1; /* don't find previous instances */
14318 /* This string is not what we want; skip all of the
14319 glyphs that came from it. */
14320 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14321 && EQ (glyph
->object
, str
))
14328 /* If we reached the end of the line, and END was from a string,
14329 the cursor is not on this line. */
14331 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14332 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14333 && STRINGP (end
->object
)
14334 && row
->continued_p
)
14337 /* A truncated row may not include PT among its character positions.
14338 Setting the cursor inside the scroll margin will trigger
14339 recalculation of hscroll in hscroll_window_tree. But if a
14340 display string covers point, defer to the string-handling
14341 code below to figure this out. */
14342 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14344 cursor
= glyph_before
;
14347 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14348 /* Zero-width characters produce no glyphs. */
14350 && (row
->reversed_p
14351 ? glyph_after
> glyphs_end
14352 : glyph_after
< glyphs_end
)))
14354 cursor
= glyph_after
;
14360 if (cursor
!= NULL
)
14362 else if (glyph
== glyphs_end
14363 && pos_before
== pos_after
14364 && STRINGP ((row
->reversed_p
14365 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14366 : row
->glyphs
[TEXT_AREA
])->object
))
14368 /* If all the glyphs of this row came from strings, put the
14369 cursor on the first glyph of the row. This avoids having the
14370 cursor outside of the text area in this very rare and hard
14374 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14375 : row
->glyphs
[TEXT_AREA
];
14381 /* Need to compute x that corresponds to GLYPH. */
14382 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14384 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14386 x
+= g
->pixel_width
;
14390 /* ROW could be part of a continued line, which, under bidi
14391 reordering, might have other rows whose start and end charpos
14392 occlude point. Only set w->cursor if we found a better
14393 approximation to the cursor position than we have from previously
14394 examined candidate rows belonging to the same continued line. */
14395 if (/* We already have a candidate row. */
14396 w
->cursor
.vpos
>= 0
14397 /* That candidate is not the row we are processing. */
14398 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14399 /* Make sure cursor.vpos specifies a row whose start and end
14400 charpos occlude point, and it is valid candidate for being a
14401 cursor-row. This is because some callers of this function
14402 leave cursor.vpos at the row where the cursor was displayed
14403 during the last redisplay cycle. */
14404 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14405 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14406 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14409 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14411 /* Don't consider glyphs that are outside TEXT_AREA. */
14412 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14414 /* Keep the candidate whose buffer position is the closest to
14415 point or has the `cursor' property. */
14416 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14417 w
->cursor
.hpos
>= 0
14418 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14419 && ((BUFFERP (g1
->object
)
14420 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14421 || (BUFFERP (glyph
->object
)
14422 && eabs (g1
->charpos
- pt_old
)
14423 < eabs (glyph
->charpos
- pt_old
))))
14424 /* Previous candidate is a glyph from a string that has
14425 a non-nil `cursor' property. */
14426 || (STRINGP (g1
->object
)
14427 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14428 Qcursor
, g1
->object
))
14429 /* Previous candidate is from the same display
14430 string as this one, and the display string
14431 came from a text property. */
14432 || (EQ (g1
->object
, glyph
->object
)
14433 && string_from_text_prop
)
14434 /* this candidate is from newline and its
14435 position is not an exact match */
14436 || (INTEGERP (glyph
->object
)
14437 && glyph
->charpos
!= pt_old
)))))
14439 /* If this candidate gives an exact match, use that. */
14440 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14441 /* If this candidate is a glyph created for the
14442 terminating newline of a line, and point is on that
14443 newline, it wins because it's an exact match. */
14444 || (!row
->continued_p
14445 && INTEGERP (glyph
->object
)
14446 && glyph
->charpos
== 0
14447 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14448 /* Otherwise, keep the candidate that comes from a row
14449 spanning less buffer positions. This may win when one or
14450 both candidate positions are on glyphs that came from
14451 display strings, for which we cannot compare buffer
14453 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14454 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14455 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14458 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14460 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14461 w
->cursor
.y
= row
->y
+ dy
;
14463 if (w
== XWINDOW (selected_window
))
14465 if (!row
->continued_p
14466 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14469 this_line_buffer
= XBUFFER (w
->contents
);
14471 CHARPOS (this_line_start_pos
)
14472 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14473 BYTEPOS (this_line_start_pos
)
14474 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14476 CHARPOS (this_line_end_pos
)
14477 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14478 BYTEPOS (this_line_end_pos
)
14479 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14481 this_line_y
= w
->cursor
.y
;
14482 this_line_pixel_height
= row
->height
;
14483 this_line_vpos
= w
->cursor
.vpos
;
14484 this_line_start_x
= row
->x
;
14487 CHARPOS (this_line_start_pos
) = 0;
14494 /* Run window scroll functions, if any, for WINDOW with new window
14495 start STARTP. Sets the window start of WINDOW to that position.
14497 We assume that the window's buffer is really current. */
14499 static struct text_pos
14500 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14502 struct window
*w
= XWINDOW (window
);
14503 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14505 eassert (current_buffer
== XBUFFER (w
->contents
));
14507 if (!NILP (Vwindow_scroll_functions
))
14509 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14510 make_number (CHARPOS (startp
)));
14511 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14512 /* In case the hook functions switch buffers. */
14513 set_buffer_internal (XBUFFER (w
->contents
));
14520 /* Make sure the line containing the cursor is fully visible.
14521 A value of 1 means there is nothing to be done.
14522 (Either the line is fully visible, or it cannot be made so,
14523 or we cannot tell.)
14525 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14526 is higher than window.
14528 A value of 0 means the caller should do scrolling
14529 as if point had gone off the screen. */
14532 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14534 struct glyph_matrix
*matrix
;
14535 struct glyph_row
*row
;
14538 if (!make_cursor_line_fully_visible_p
)
14541 /* It's not always possible to find the cursor, e.g, when a window
14542 is full of overlay strings. Don't do anything in that case. */
14543 if (w
->cursor
.vpos
< 0)
14546 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14547 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14549 /* If the cursor row is not partially visible, there's nothing to do. */
14550 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14553 /* If the row the cursor is in is taller than the window's height,
14554 it's not clear what to do, so do nothing. */
14555 window_height
= window_box_height (w
);
14556 if (row
->height
>= window_height
)
14558 if (!force_p
|| MINI_WINDOW_P (w
)
14559 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14566 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14567 non-zero means only WINDOW is redisplayed in redisplay_internal.
14568 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14569 in redisplay_window to bring a partially visible line into view in
14570 the case that only the cursor has moved.
14572 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14573 last screen line's vertical height extends past the end of the screen.
14577 1 if scrolling succeeded
14579 0 if scrolling didn't find point.
14581 -1 if new fonts have been loaded so that we must interrupt
14582 redisplay, adjust glyph matrices, and try again. */
14588 SCROLLING_NEED_LARGER_MATRICES
14591 /* If scroll-conservatively is more than this, never recenter.
14593 If you change this, don't forget to update the doc string of
14594 `scroll-conservatively' and the Emacs manual. */
14595 #define SCROLL_LIMIT 100
14598 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14599 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14600 int temp_scroll_step
, int last_line_misfit
)
14602 struct window
*w
= XWINDOW (window
);
14603 struct frame
*f
= XFRAME (w
->frame
);
14604 struct text_pos pos
, startp
;
14606 int this_scroll_margin
, scroll_max
, rc
, height
;
14607 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14608 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14609 Lisp_Object aggressive
;
14610 /* We will never try scrolling more than this number of lines. */
14611 int scroll_limit
= SCROLL_LIMIT
;
14612 int frame_line_height
= default_line_pixel_height (w
);
14613 int window_total_lines
14614 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14617 debug_method_add (w
, "try_scrolling");
14620 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14622 /* Compute scroll margin height in pixels. We scroll when point is
14623 within this distance from the top or bottom of the window. */
14624 if (scroll_margin
> 0)
14625 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14626 * frame_line_height
;
14628 this_scroll_margin
= 0;
14630 /* Force arg_scroll_conservatively to have a reasonable value, to
14631 avoid scrolling too far away with slow move_it_* functions. Note
14632 that the user can supply scroll-conservatively equal to
14633 `most-positive-fixnum', which can be larger than INT_MAX. */
14634 if (arg_scroll_conservatively
> scroll_limit
)
14636 arg_scroll_conservatively
= scroll_limit
+ 1;
14637 scroll_max
= scroll_limit
* frame_line_height
;
14639 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14640 /* Compute how much we should try to scroll maximally to bring
14641 point into view. */
14642 scroll_max
= (max (scroll_step
,
14643 max (arg_scroll_conservatively
, temp_scroll_step
))
14644 * frame_line_height
);
14645 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14646 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14647 /* We're trying to scroll because of aggressive scrolling but no
14648 scroll_step is set. Choose an arbitrary one. */
14649 scroll_max
= 10 * frame_line_height
;
14655 /* Decide whether to scroll down. */
14656 if (PT
> CHARPOS (startp
))
14658 int scroll_margin_y
;
14660 /* Compute the pixel ypos of the scroll margin, then move IT to
14661 either that ypos or PT, whichever comes first. */
14662 start_display (&it
, w
, startp
);
14663 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14664 - frame_line_height
* extra_scroll_margin_lines
;
14665 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14666 (MOVE_TO_POS
| MOVE_TO_Y
));
14668 if (PT
> CHARPOS (it
.current
.pos
))
14670 int y0
= line_bottom_y (&it
);
14671 /* Compute how many pixels below window bottom to stop searching
14672 for PT. This avoids costly search for PT that is far away if
14673 the user limited scrolling by a small number of lines, but
14674 always finds PT if scroll_conservatively is set to a large
14675 number, such as most-positive-fixnum. */
14676 int slack
= max (scroll_max
, 10 * frame_line_height
);
14677 int y_to_move
= it
.last_visible_y
+ slack
;
14679 /* Compute the distance from the scroll margin to PT or to
14680 the scroll limit, whichever comes first. This should
14681 include the height of the cursor line, to make that line
14683 move_it_to (&it
, PT
, -1, y_to_move
,
14684 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14685 dy
= line_bottom_y (&it
) - y0
;
14687 if (dy
> scroll_max
)
14688 return SCROLLING_FAILED
;
14697 /* Point is in or below the bottom scroll margin, so move the
14698 window start down. If scrolling conservatively, move it just
14699 enough down to make point visible. If scroll_step is set,
14700 move it down by scroll_step. */
14701 if (arg_scroll_conservatively
)
14703 = min (max (dy
, frame_line_height
),
14704 frame_line_height
* arg_scroll_conservatively
);
14705 else if (scroll_step
|| temp_scroll_step
)
14706 amount_to_scroll
= scroll_max
;
14709 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14710 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14711 if (NUMBERP (aggressive
))
14713 double float_amount
= XFLOATINT (aggressive
) * height
;
14714 int aggressive_scroll
= float_amount
;
14715 if (aggressive_scroll
== 0 && float_amount
> 0)
14716 aggressive_scroll
= 1;
14717 /* Don't let point enter the scroll margin near top of
14718 the window. This could happen if the value of
14719 scroll_up_aggressively is too large and there are
14720 non-zero margins, because scroll_up_aggressively
14721 means put point that fraction of window height
14722 _from_the_bottom_margin_. */
14723 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14724 aggressive_scroll
= height
- 2*this_scroll_margin
;
14725 amount_to_scroll
= dy
+ aggressive_scroll
;
14729 if (amount_to_scroll
<= 0)
14730 return SCROLLING_FAILED
;
14732 start_display (&it
, w
, startp
);
14733 if (arg_scroll_conservatively
<= scroll_limit
)
14734 move_it_vertically (&it
, amount_to_scroll
);
14737 /* Extra precision for users who set scroll-conservatively
14738 to a large number: make sure the amount we scroll
14739 the window start is never less than amount_to_scroll,
14740 which was computed as distance from window bottom to
14741 point. This matters when lines at window top and lines
14742 below window bottom have different height. */
14744 void *it1data
= NULL
;
14745 /* We use a temporary it1 because line_bottom_y can modify
14746 its argument, if it moves one line down; see there. */
14749 SAVE_IT (it1
, it
, it1data
);
14750 start_y
= line_bottom_y (&it1
);
14752 RESTORE_IT (&it
, &it
, it1data
);
14753 move_it_by_lines (&it
, 1);
14754 SAVE_IT (it1
, it
, it1data
);
14755 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14758 /* If STARTP is unchanged, move it down another screen line. */
14759 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14760 move_it_by_lines (&it
, 1);
14761 startp
= it
.current
.pos
;
14765 struct text_pos scroll_margin_pos
= startp
;
14768 /* See if point is inside the scroll margin at the top of the
14770 if (this_scroll_margin
)
14774 start_display (&it
, w
, startp
);
14775 y_start
= it
.current_y
;
14776 move_it_vertically (&it
, this_scroll_margin
);
14777 scroll_margin_pos
= it
.current
.pos
;
14778 /* If we didn't move enough before hitting ZV, request
14779 additional amount of scroll, to move point out of the
14781 if (IT_CHARPOS (it
) == ZV
14782 && it
.current_y
- y_start
< this_scroll_margin
)
14783 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14786 if (PT
< CHARPOS (scroll_margin_pos
))
14788 /* Point is in the scroll margin at the top of the window or
14789 above what is displayed in the window. */
14792 /* Compute the vertical distance from PT to the scroll
14793 margin position. Move as far as scroll_max allows, or
14794 one screenful, or 10 screen lines, whichever is largest.
14795 Give up if distance is greater than scroll_max or if we
14796 didn't reach the scroll margin position. */
14797 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14798 start_display (&it
, w
, pos
);
14800 y_to_move
= max (it
.last_visible_y
,
14801 max (scroll_max
, 10 * frame_line_height
));
14802 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14804 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14805 dy
= it
.current_y
- y0
;
14806 if (dy
> scroll_max
14807 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14808 return SCROLLING_FAILED
;
14810 /* Additional scroll for when ZV was too close to point. */
14813 /* Compute new window start. */
14814 start_display (&it
, w
, startp
);
14816 if (arg_scroll_conservatively
)
14817 amount_to_scroll
= max (dy
, frame_line_height
*
14818 max (scroll_step
, temp_scroll_step
));
14819 else if (scroll_step
|| temp_scroll_step
)
14820 amount_to_scroll
= scroll_max
;
14823 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14824 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14825 if (NUMBERP (aggressive
))
14827 double float_amount
= XFLOATINT (aggressive
) * height
;
14828 int aggressive_scroll
= float_amount
;
14829 if (aggressive_scroll
== 0 && float_amount
> 0)
14830 aggressive_scroll
= 1;
14831 /* Don't let point enter the scroll margin near
14832 bottom of the window, if the value of
14833 scroll_down_aggressively happens to be too
14835 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14836 aggressive_scroll
= height
- 2*this_scroll_margin
;
14837 amount_to_scroll
= dy
+ aggressive_scroll
;
14841 if (amount_to_scroll
<= 0)
14842 return SCROLLING_FAILED
;
14844 move_it_vertically_backward (&it
, amount_to_scroll
);
14845 startp
= it
.current
.pos
;
14849 /* Run window scroll functions. */
14850 startp
= run_window_scroll_functions (window
, startp
);
14852 /* Display the window. Give up if new fonts are loaded, or if point
14854 if (!try_window (window
, startp
, 0))
14855 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14856 else if (w
->cursor
.vpos
< 0)
14858 clear_glyph_matrix (w
->desired_matrix
);
14859 rc
= SCROLLING_FAILED
;
14863 /* Maybe forget recorded base line for line number display. */
14864 if (!just_this_one_p
14865 || current_buffer
->clip_changed
14866 || BEG_UNCHANGED
< CHARPOS (startp
))
14867 w
->base_line_number
= 0;
14869 /* If cursor ends up on a partially visible line,
14870 treat that as being off the bottom of the screen. */
14871 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14872 /* It's possible that the cursor is on the first line of the
14873 buffer, which is partially obscured due to a vscroll
14874 (Bug#7537). In that case, avoid looping forever . */
14875 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14877 clear_glyph_matrix (w
->desired_matrix
);
14878 ++extra_scroll_margin_lines
;
14881 rc
= SCROLLING_SUCCESS
;
14888 /* Compute a suitable window start for window W if display of W starts
14889 on a continuation line. Value is non-zero if a new window start
14892 The new window start will be computed, based on W's width, starting
14893 from the start of the continued line. It is the start of the
14894 screen line with the minimum distance from the old start W->start. */
14897 compute_window_start_on_continuation_line (struct window
*w
)
14899 struct text_pos pos
, start_pos
;
14900 int window_start_changed_p
= 0;
14902 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14904 /* If window start is on a continuation line... Window start may be
14905 < BEGV in case there's invisible text at the start of the
14906 buffer (M-x rmail, for example). */
14907 if (CHARPOS (start_pos
) > BEGV
14908 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14911 struct glyph_row
*row
;
14913 /* Handle the case that the window start is out of range. */
14914 if (CHARPOS (start_pos
) < BEGV
)
14915 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14916 else if (CHARPOS (start_pos
) > ZV
)
14917 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14919 /* Find the start of the continued line. This should be fast
14920 because find_newline is fast (newline cache). */
14921 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14922 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14923 row
, DEFAULT_FACE_ID
);
14924 reseat_at_previous_visible_line_start (&it
);
14926 /* If the line start is "too far" away from the window start,
14927 say it takes too much time to compute a new window start. */
14928 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14929 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14931 int min_distance
, distance
;
14933 /* Move forward by display lines to find the new window
14934 start. If window width was enlarged, the new start can
14935 be expected to be > the old start. If window width was
14936 decreased, the new window start will be < the old start.
14937 So, we're looking for the display line start with the
14938 minimum distance from the old window start. */
14939 pos
= it
.current
.pos
;
14940 min_distance
= INFINITY
;
14941 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14942 distance
< min_distance
)
14944 min_distance
= distance
;
14945 pos
= it
.current
.pos
;
14946 if (it
.line_wrap
== WORD_WRAP
)
14948 /* Under WORD_WRAP, move_it_by_lines is likely to
14949 overshoot and stop not at the first, but the
14950 second character from the left margin. So in
14951 that case, we need a more tight control on the X
14952 coordinate of the iterator than move_it_by_lines
14953 promises in its contract. The method is to first
14954 go to the last (rightmost) visible character of a
14955 line, then move to the leftmost character on the
14956 next line in a separate call. */
14957 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14958 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14959 move_it_to (&it
, ZV
, 0,
14960 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14961 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14964 move_it_by_lines (&it
, 1);
14967 /* Set the window start there. */
14968 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14969 window_start_changed_p
= 1;
14973 return window_start_changed_p
;
14977 /* Try cursor movement in case text has not changed in window WINDOW,
14978 with window start STARTP. Value is
14980 CURSOR_MOVEMENT_SUCCESS if successful
14982 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14984 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14985 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14986 we want to scroll as if scroll-step were set to 1. See the code.
14988 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14989 which case we have to abort this redisplay, and adjust matrices
14994 CURSOR_MOVEMENT_SUCCESS
,
14995 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14996 CURSOR_MOVEMENT_MUST_SCROLL
,
14997 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15001 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15003 struct window
*w
= XWINDOW (window
);
15004 struct frame
*f
= XFRAME (w
->frame
);
15005 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15008 if (inhibit_try_cursor_movement
)
15012 /* Previously, there was a check for Lisp integer in the
15013 if-statement below. Now, this field is converted to
15014 ptrdiff_t, thus zero means invalid position in a buffer. */
15015 eassert (w
->last_point
> 0);
15016 /* Likewise there was a check whether window_end_vpos is nil or larger
15017 than the window. Now window_end_vpos is int and so never nil, but
15018 let's leave eassert to check whether it fits in the window. */
15019 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15021 /* Handle case where text has not changed, only point, and it has
15022 not moved off the frame. */
15023 if (/* Point may be in this window. */
15024 PT
>= CHARPOS (startp
)
15025 /* Selective display hasn't changed. */
15026 && !current_buffer
->clip_changed
15027 /* Function force-mode-line-update is used to force a thorough
15028 redisplay. It sets either windows_or_buffers_changed or
15029 update_mode_lines. So don't take a shortcut here for these
15031 && !update_mode_lines
15032 && !windows_or_buffers_changed
15033 && !f
->cursor_type_changed
15034 && NILP (Vshow_trailing_whitespace
)
15035 /* This code is not used for mini-buffer for the sake of the case
15036 of redisplaying to replace an echo area message; since in
15037 that case the mini-buffer contents per se are usually
15038 unchanged. This code is of no real use in the mini-buffer
15039 since the handling of this_line_start_pos, etc., in redisplay
15040 handles the same cases. */
15041 && !EQ (window
, minibuf_window
)
15042 && (FRAME_WINDOW_P (f
)
15043 || !overlay_arrow_in_current_buffer_p ()))
15045 int this_scroll_margin
, top_scroll_margin
;
15046 struct glyph_row
*row
= NULL
;
15047 int frame_line_height
= default_line_pixel_height (w
);
15048 int window_total_lines
15049 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15052 debug_method_add (w
, "cursor movement");
15055 /* Scroll if point within this distance from the top or bottom
15056 of the window. This is a pixel value. */
15057 if (scroll_margin
> 0)
15059 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15060 this_scroll_margin
*= frame_line_height
;
15063 this_scroll_margin
= 0;
15065 top_scroll_margin
= this_scroll_margin
;
15066 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15067 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15069 /* Start with the row the cursor was displayed during the last
15070 not paused redisplay. Give up if that row is not valid. */
15071 if (w
->last_cursor_vpos
< 0
15072 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15073 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15076 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15077 if (row
->mode_line_p
)
15079 if (!row
->enabled_p
)
15080 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15083 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15085 int scroll_p
= 0, must_scroll
= 0;
15086 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15088 if (PT
> w
->last_point
)
15090 /* Point has moved forward. */
15091 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15092 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15094 eassert (row
->enabled_p
);
15098 /* If the end position of a row equals the start
15099 position of the next row, and PT is at that position,
15100 we would rather display cursor in the next line. */
15101 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15102 && MATRIX_ROW_END_CHARPOS (row
) == PT
15103 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15104 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15105 && !cursor_row_p (row
))
15108 /* If within the scroll margin, scroll. Note that
15109 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15110 the next line would be drawn, and that
15111 this_scroll_margin can be zero. */
15112 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15113 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15114 /* Line is completely visible last line in window
15115 and PT is to be set in the next line. */
15116 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15117 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15118 && !row
->ends_at_zv_p
15119 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15122 else if (PT
< w
->last_point
)
15124 /* Cursor has to be moved backward. Note that PT >=
15125 CHARPOS (startp) because of the outer if-statement. */
15126 while (!row
->mode_line_p
15127 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15128 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15129 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15130 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15131 row
> w
->current_matrix
->rows
15132 && (row
-1)->ends_in_newline_from_string_p
))))
15133 && (row
->y
> top_scroll_margin
15134 || CHARPOS (startp
) == BEGV
))
15136 eassert (row
->enabled_p
);
15140 /* Consider the following case: Window starts at BEGV,
15141 there is invisible, intangible text at BEGV, so that
15142 display starts at some point START > BEGV. It can
15143 happen that we are called with PT somewhere between
15144 BEGV and START. Try to handle that case. */
15145 if (row
< w
->current_matrix
->rows
15146 || row
->mode_line_p
)
15148 row
= w
->current_matrix
->rows
;
15149 if (row
->mode_line_p
)
15153 /* Due to newlines in overlay strings, we may have to
15154 skip forward over overlay strings. */
15155 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15156 && MATRIX_ROW_END_CHARPOS (row
) == PT
15157 && !cursor_row_p (row
))
15160 /* If within the scroll margin, scroll. */
15161 if (row
->y
< top_scroll_margin
15162 && CHARPOS (startp
) != BEGV
)
15167 /* Cursor did not move. So don't scroll even if cursor line
15168 is partially visible, as it was so before. */
15169 rc
= CURSOR_MOVEMENT_SUCCESS
;
15172 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15173 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15175 /* if PT is not in the glyph row, give up. */
15176 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15179 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15180 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15182 struct glyph_row
*row1
;
15184 /* If rows are bidi-reordered and point moved, back up
15185 until we find a row that does not belong to a
15186 continuation line. This is because we must consider
15187 all rows of a continued line as candidates for the
15188 new cursor positioning, since row start and end
15189 positions change non-linearly with vertical position
15191 /* FIXME: Revisit this when glyph ``spilling'' in
15192 continuation lines' rows is implemented for
15193 bidi-reordered rows. */
15194 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15195 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15198 /* If we hit the beginning of the displayed portion
15199 without finding the first row of a continued
15203 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15206 eassert (row
->enabled_p
);
15211 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15212 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15213 /* Make sure this isn't a header line by any chance, since
15214 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15215 && !row
->mode_line_p
15216 && make_cursor_line_fully_visible_p
)
15218 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15219 && !row
->ends_at_zv_p
15220 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15221 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15222 else if (row
->height
> window_box_height (w
))
15224 /* If we end up in a partially visible line, let's
15225 make it fully visible, except when it's taller
15226 than the window, in which case we can't do much
15229 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15233 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15234 if (!cursor_row_fully_visible_p (w
, 0, 1))
15235 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15237 rc
= CURSOR_MOVEMENT_SUCCESS
;
15241 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15242 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15243 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15245 /* With bidi-reordered rows, there could be more than
15246 one candidate row whose start and end positions
15247 occlude point. We need to let set_cursor_from_row
15248 find the best candidate. */
15249 /* FIXME: Revisit this when glyph ``spilling'' in
15250 continuation lines' rows is implemented for
15251 bidi-reordered rows. */
15256 int at_zv_p
= 0, exact_match_p
= 0;
15258 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15259 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15260 && cursor_row_p (row
))
15261 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15263 /* As soon as we've found the exact match for point,
15264 or the first suitable row whose ends_at_zv_p flag
15265 is set, we are done. */
15267 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15269 && w
->cursor
.hpos
>= 0
15270 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15273 struct glyph_row
*candidate
=
15274 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15276 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15277 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15280 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15281 || (INTEGERP (g
->object
)
15282 && (g
->charpos
== PT
15283 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15285 if (rv
&& (at_zv_p
|| exact_match_p
))
15287 rc
= CURSOR_MOVEMENT_SUCCESS
;
15290 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15294 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15295 || row
->continued_p
)
15296 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15297 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15298 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15299 /* If we didn't find any candidate rows, or exited the
15300 loop before all the candidates were examined, signal
15301 to the caller that this method failed. */
15302 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15304 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15305 && !row
->continued_p
))
15306 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15308 rc
= CURSOR_MOVEMENT_SUCCESS
;
15314 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15316 rc
= CURSOR_MOVEMENT_SUCCESS
;
15321 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15322 && MATRIX_ROW_START_CHARPOS (row
) == PT
15323 && cursor_row_p (row
));
15331 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15335 set_vertical_scroll_bar (struct window
*w
)
15337 ptrdiff_t start
, end
, whole
;
15339 /* Calculate the start and end positions for the current window.
15340 At some point, it would be nice to choose between scrollbars
15341 which reflect the whole buffer size, with special markers
15342 indicating narrowing, and scrollbars which reflect only the
15345 Note that mini-buffers sometimes aren't displaying any text. */
15346 if (!MINI_WINDOW_P (w
)
15347 || (w
== XWINDOW (minibuf_window
)
15348 && NILP (echo_area_buffer
[0])))
15350 struct buffer
*buf
= XBUFFER (w
->contents
);
15351 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15352 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15353 /* I don't think this is guaranteed to be right. For the
15354 moment, we'll pretend it is. */
15355 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15359 if (whole
< (end
- start
))
15360 whole
= end
- start
;
15363 start
= end
= whole
= 0;
15365 /* Indicate what this scroll bar ought to be displaying now. */
15366 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15367 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15368 (w
, end
- start
, whole
, start
);
15372 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15373 selected_window is redisplayed.
15375 We can return without actually redisplaying the window if fonts has been
15376 changed on window's frame. In that case, redisplay_internal will retry. */
15379 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15381 struct window
*w
= XWINDOW (window
);
15382 struct frame
*f
= XFRAME (w
->frame
);
15383 struct buffer
*buffer
= XBUFFER (w
->contents
);
15384 struct buffer
*old
= current_buffer
;
15385 struct text_pos lpoint
, opoint
, startp
;
15386 int update_mode_line
;
15389 /* Record it now because it's overwritten. */
15390 bool current_matrix_up_to_date_p
= false;
15391 bool used_current_matrix_p
= false;
15392 /* This is less strict than current_matrix_up_to_date_p.
15393 It indicates that the buffer contents and narrowing are unchanged. */
15394 bool buffer_unchanged_p
= false;
15395 int temp_scroll_step
= 0;
15396 ptrdiff_t count
= SPECPDL_INDEX ();
15398 int centering_position
= -1;
15399 int last_line_misfit
= 0;
15400 ptrdiff_t beg_unchanged
, end_unchanged
;
15401 int frame_line_height
;
15403 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15407 *w
->desired_matrix
->method
= 0;
15410 if (!just_this_one_p
15411 && REDISPLAY_SOME_P ()
15414 && !buffer
->text
->redisplay
)
15417 /* Make sure that both W's markers are valid. */
15418 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15419 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15422 reconsider_clip_changes (w
);
15423 frame_line_height
= default_line_pixel_height (w
);
15425 /* Has the mode line to be updated? */
15426 update_mode_line
= (w
->update_mode_line
15427 || update_mode_lines
15428 || buffer
->clip_changed
15429 || buffer
->prevent_redisplay_optimizations_p
);
15431 if (!just_this_one_p
)
15432 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15433 cleverly elsewhere. */
15434 w
->must_be_updated_p
= true;
15436 if (MINI_WINDOW_P (w
))
15438 if (w
== XWINDOW (echo_area_window
)
15439 && !NILP (echo_area_buffer
[0]))
15441 if (update_mode_line
)
15442 /* We may have to update a tty frame's menu bar or a
15443 tool-bar. Example `M-x C-h C-h C-g'. */
15444 goto finish_menu_bars
;
15446 /* We've already displayed the echo area glyphs in this window. */
15447 goto finish_scroll_bars
;
15449 else if ((w
!= XWINDOW (minibuf_window
)
15450 || minibuf_level
== 0)
15451 /* When buffer is nonempty, redisplay window normally. */
15452 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15453 /* Quail displays non-mini buffers in minibuffer window.
15454 In that case, redisplay the window normally. */
15455 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15457 /* W is a mini-buffer window, but it's not active, so clear
15459 int yb
= window_text_bottom_y (w
);
15460 struct glyph_row
*row
;
15463 for (y
= 0, row
= w
->desired_matrix
->rows
;
15465 y
+= row
->height
, ++row
)
15466 blank_row (w
, row
, y
);
15467 goto finish_scroll_bars
;
15470 clear_glyph_matrix (w
->desired_matrix
);
15473 /* Otherwise set up data on this window; select its buffer and point
15475 /* Really select the buffer, for the sake of buffer-local
15477 set_buffer_internal_1 (XBUFFER (w
->contents
));
15479 current_matrix_up_to_date_p
15480 = (w
->window_end_valid
15481 && !current_buffer
->clip_changed
15482 && !current_buffer
->prevent_redisplay_optimizations_p
15483 && !window_outdated (w
));
15485 /* Run the window-bottom-change-functions
15486 if it is possible that the text on the screen has changed
15487 (either due to modification of the text, or any other reason). */
15488 if (!current_matrix_up_to_date_p
15489 && !NILP (Vwindow_text_change_functions
))
15491 safe_run_hooks (Qwindow_text_change_functions
);
15495 beg_unchanged
= BEG_UNCHANGED
;
15496 end_unchanged
= END_UNCHANGED
;
15498 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15500 specbind (Qinhibit_point_motion_hooks
, Qt
);
15503 = (w
->window_end_valid
15504 && !current_buffer
->clip_changed
15505 && !window_outdated (w
));
15507 /* When windows_or_buffers_changed is non-zero, we can't rely
15508 on the window end being valid, so set it to zero there. */
15509 if (windows_or_buffers_changed
)
15511 /* If window starts on a continuation line, maybe adjust the
15512 window start in case the window's width changed. */
15513 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15514 compute_window_start_on_continuation_line (w
);
15516 w
->window_end_valid
= false;
15517 /* If so, we also can't rely on current matrix
15518 and should not fool try_cursor_movement below. */
15519 current_matrix_up_to_date_p
= false;
15522 /* Some sanity checks. */
15523 CHECK_WINDOW_END (w
);
15524 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15526 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15529 if (mode_line_update_needed (w
))
15530 update_mode_line
= 1;
15532 /* Point refers normally to the selected window. For any other
15533 window, set up appropriate value. */
15534 if (!EQ (window
, selected_window
))
15536 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15537 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15541 new_pt_byte
= BEGV_BYTE
;
15542 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15544 else if (new_pt
> (ZV
- 1))
15547 new_pt_byte
= ZV_BYTE
;
15548 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15551 /* We don't use SET_PT so that the point-motion hooks don't run. */
15552 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15555 /* If any of the character widths specified in the display table
15556 have changed, invalidate the width run cache. It's true that
15557 this may be a bit late to catch such changes, but the rest of
15558 redisplay goes (non-fatally) haywire when the display table is
15559 changed, so why should we worry about doing any better? */
15560 if (current_buffer
->width_run_cache
)
15562 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15564 if (! disptab_matches_widthtab
15565 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15567 invalidate_region_cache (current_buffer
,
15568 current_buffer
->width_run_cache
,
15570 recompute_width_table (current_buffer
, disptab
);
15574 /* If window-start is screwed up, choose a new one. */
15575 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15578 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15580 /* If someone specified a new starting point but did not insist,
15581 check whether it can be used. */
15582 if (w
->optional_new_start
15583 && CHARPOS (startp
) >= BEGV
15584 && CHARPOS (startp
) <= ZV
)
15586 w
->optional_new_start
= 0;
15587 start_display (&it
, w
, startp
);
15588 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15589 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15590 if (IT_CHARPOS (it
) == PT
)
15591 w
->force_start
= 1;
15592 /* IT may overshoot PT if text at PT is invisible. */
15593 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15594 w
->force_start
= 1;
15599 /* Handle case where place to start displaying has been specified,
15600 unless the specified location is outside the accessible range. */
15601 if (w
->force_start
|| window_frozen_p (w
))
15603 /* We set this later on if we have to adjust point. */
15606 w
->force_start
= 0;
15608 w
->window_end_valid
= 0;
15610 /* Forget any recorded base line for line number display. */
15611 if (!buffer_unchanged_p
)
15612 w
->base_line_number
= 0;
15614 /* Redisplay the mode line. Select the buffer properly for that.
15615 Also, run the hook window-scroll-functions
15616 because we have scrolled. */
15617 /* Note, we do this after clearing force_start because
15618 if there's an error, it is better to forget about force_start
15619 than to get into an infinite loop calling the hook functions
15620 and having them get more errors. */
15621 if (!update_mode_line
15622 || ! NILP (Vwindow_scroll_functions
))
15624 update_mode_line
= 1;
15625 w
->update_mode_line
= 1;
15626 startp
= run_window_scroll_functions (window
, startp
);
15629 if (CHARPOS (startp
) < BEGV
)
15630 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15631 else if (CHARPOS (startp
) > ZV
)
15632 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15634 /* Redisplay, then check if cursor has been set during the
15635 redisplay. Give up if new fonts were loaded. */
15636 /* We used to issue a CHECK_MARGINS argument to try_window here,
15637 but this causes scrolling to fail when point begins inside
15638 the scroll margin (bug#148) -- cyd */
15639 if (!try_window (window
, startp
, 0))
15641 w
->force_start
= 1;
15642 clear_glyph_matrix (w
->desired_matrix
);
15643 goto need_larger_matrices
;
15646 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15648 /* If point does not appear, try to move point so it does
15649 appear. The desired matrix has been built above, so we
15650 can use it here. */
15651 new_vpos
= window_box_height (w
) / 2;
15654 if (!cursor_row_fully_visible_p (w
, 0, 0))
15656 /* Point does appear, but on a line partly visible at end of window.
15657 Move it back to a fully-visible line. */
15658 new_vpos
= window_box_height (w
);
15660 else if (w
->cursor
.vpos
>= 0)
15662 /* Some people insist on not letting point enter the scroll
15663 margin, even though this part handles windows that didn't
15665 int window_total_lines
15666 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15667 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15668 int pixel_margin
= margin
* frame_line_height
;
15669 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15671 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15672 below, which finds the row to move point to, advances by
15673 the Y coordinate of the _next_ row, see the definition of
15674 MATRIX_ROW_BOTTOM_Y. */
15675 if (w
->cursor
.vpos
< margin
+ header_line
)
15677 w
->cursor
.vpos
= -1;
15678 clear_glyph_matrix (w
->desired_matrix
);
15679 goto try_to_scroll
;
15683 int window_height
= window_box_height (w
);
15686 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15687 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15689 w
->cursor
.vpos
= -1;
15690 clear_glyph_matrix (w
->desired_matrix
);
15691 goto try_to_scroll
;
15696 /* If we need to move point for either of the above reasons,
15697 now actually do it. */
15700 struct glyph_row
*row
;
15702 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15703 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15706 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15707 MATRIX_ROW_START_BYTEPOS (row
));
15709 if (w
!= XWINDOW (selected_window
))
15710 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15711 else if (current_buffer
== old
)
15712 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15714 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15716 /* If we are highlighting the region, then we just changed
15717 the region, so redisplay to show it. */
15718 /* FIXME: We need to (re)run pre-redisplay-function! */
15719 /* if (markpos_of_region () >= 0)
15721 clear_glyph_matrix (w->desired_matrix);
15722 if (!try_window (window, startp, 0))
15723 goto need_larger_matrices;
15729 debug_method_add (w
, "forced window start");
15734 /* Handle case where text has not changed, only point, and it has
15735 not moved off the frame, and we are not retrying after hscroll.
15736 (current_matrix_up_to_date_p is nonzero when retrying.) */
15737 if (current_matrix_up_to_date_p
15738 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15739 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15743 case CURSOR_MOVEMENT_SUCCESS
:
15744 used_current_matrix_p
= 1;
15747 case CURSOR_MOVEMENT_MUST_SCROLL
:
15748 goto try_to_scroll
;
15754 /* If current starting point was originally the beginning of a line
15755 but no longer is, find a new starting point. */
15756 else if (w
->start_at_line_beg
15757 && !(CHARPOS (startp
) <= BEGV
15758 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15761 debug_method_add (w
, "recenter 1");
15766 /* Try scrolling with try_window_id. Value is > 0 if update has
15767 been done, it is -1 if we know that the same window start will
15768 not work. It is 0 if unsuccessful for some other reason. */
15769 else if ((tem
= try_window_id (w
)) != 0)
15772 debug_method_add (w
, "try_window_id %d", tem
);
15775 if (f
->fonts_changed
)
15776 goto need_larger_matrices
;
15780 /* Otherwise try_window_id has returned -1 which means that we
15781 don't want the alternative below this comment to execute. */
15783 else if (CHARPOS (startp
) >= BEGV
15784 && CHARPOS (startp
) <= ZV
15785 && PT
>= CHARPOS (startp
)
15786 && (CHARPOS (startp
) < ZV
15787 /* Avoid starting at end of buffer. */
15788 || CHARPOS (startp
) == BEGV
15789 || !window_outdated (w
)))
15791 int d1
, d2
, d3
, d4
, d5
, d6
;
15793 /* If first window line is a continuation line, and window start
15794 is inside the modified region, but the first change is before
15795 current window start, we must select a new window start.
15797 However, if this is the result of a down-mouse event (e.g. by
15798 extending the mouse-drag-overlay), we don't want to select a
15799 new window start, since that would change the position under
15800 the mouse, resulting in an unwanted mouse-movement rather
15801 than a simple mouse-click. */
15802 if (!w
->start_at_line_beg
15803 && NILP (do_mouse_tracking
)
15804 && CHARPOS (startp
) > BEGV
15805 && CHARPOS (startp
) > BEG
+ beg_unchanged
15806 && CHARPOS (startp
) <= Z
- end_unchanged
15807 /* Even if w->start_at_line_beg is nil, a new window may
15808 start at a line_beg, since that's how set_buffer_window
15809 sets it. So, we need to check the return value of
15810 compute_window_start_on_continuation_line. (See also
15812 && XMARKER (w
->start
)->buffer
== current_buffer
15813 && compute_window_start_on_continuation_line (w
)
15814 /* It doesn't make sense to force the window start like we
15815 do at label force_start if it is already known that point
15816 will not be visible in the resulting window, because
15817 doing so will move point from its correct position
15818 instead of scrolling the window to bring point into view.
15820 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15822 w
->force_start
= 1;
15823 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15828 debug_method_add (w
, "same window start");
15831 /* Try to redisplay starting at same place as before.
15832 If point has not moved off frame, accept the results. */
15833 if (!current_matrix_up_to_date_p
15834 /* Don't use try_window_reusing_current_matrix in this case
15835 because a window scroll function can have changed the
15837 || !NILP (Vwindow_scroll_functions
)
15838 || MINI_WINDOW_P (w
)
15839 || !(used_current_matrix_p
15840 = try_window_reusing_current_matrix (w
)))
15842 IF_DEBUG (debug_method_add (w
, "1"));
15843 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15844 /* -1 means we need to scroll.
15845 0 means we need new matrices, but fonts_changed
15846 is set in that case, so we will detect it below. */
15847 goto try_to_scroll
;
15850 if (f
->fonts_changed
)
15851 goto need_larger_matrices
;
15853 if (w
->cursor
.vpos
>= 0)
15855 if (!just_this_one_p
15856 || current_buffer
->clip_changed
15857 || BEG_UNCHANGED
< CHARPOS (startp
))
15858 /* Forget any recorded base line for line number display. */
15859 w
->base_line_number
= 0;
15861 if (!cursor_row_fully_visible_p (w
, 1, 0))
15863 clear_glyph_matrix (w
->desired_matrix
);
15864 last_line_misfit
= 1;
15866 /* Drop through and scroll. */
15871 clear_glyph_matrix (w
->desired_matrix
);
15876 /* Redisplay the mode line. Select the buffer properly for that. */
15877 if (!update_mode_line
)
15879 update_mode_line
= 1;
15880 w
->update_mode_line
= 1;
15883 /* Try to scroll by specified few lines. */
15884 if ((scroll_conservatively
15885 || emacs_scroll_step
15886 || temp_scroll_step
15887 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15888 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15889 && CHARPOS (startp
) >= BEGV
15890 && CHARPOS (startp
) <= ZV
)
15892 /* The function returns -1 if new fonts were loaded, 1 if
15893 successful, 0 if not successful. */
15894 int ss
= try_scrolling (window
, just_this_one_p
,
15895 scroll_conservatively
,
15897 temp_scroll_step
, last_line_misfit
);
15900 case SCROLLING_SUCCESS
:
15903 case SCROLLING_NEED_LARGER_MATRICES
:
15904 goto need_larger_matrices
;
15906 case SCROLLING_FAILED
:
15914 /* Finally, just choose a place to start which positions point
15915 according to user preferences. */
15920 debug_method_add (w
, "recenter");
15923 /* Forget any previously recorded base line for line number display. */
15924 if (!buffer_unchanged_p
)
15925 w
->base_line_number
= 0;
15927 /* Determine the window start relative to point. */
15928 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15929 it
.current_y
= it
.last_visible_y
;
15930 if (centering_position
< 0)
15932 int window_total_lines
15933 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15936 ? min (scroll_margin
, window_total_lines
/ 4)
15938 ptrdiff_t margin_pos
= CHARPOS (startp
);
15939 Lisp_Object aggressive
;
15942 /* If there is a scroll margin at the top of the window, find
15943 its character position. */
15945 /* Cannot call start_display if startp is not in the
15946 accessible region of the buffer. This can happen when we
15947 have just switched to a different buffer and/or changed
15948 its restriction. In that case, startp is initialized to
15949 the character position 1 (BEGV) because we did not yet
15950 have chance to display the buffer even once. */
15951 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15954 void *it1data
= NULL
;
15956 SAVE_IT (it1
, it
, it1data
);
15957 start_display (&it1
, w
, startp
);
15958 move_it_vertically (&it1
, margin
* frame_line_height
);
15959 margin_pos
= IT_CHARPOS (it1
);
15960 RESTORE_IT (&it
, &it
, it1data
);
15962 scrolling_up
= PT
> margin_pos
;
15965 ? BVAR (current_buffer
, scroll_up_aggressively
)
15966 : BVAR (current_buffer
, scroll_down_aggressively
);
15968 if (!MINI_WINDOW_P (w
)
15969 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15973 /* Setting scroll-conservatively overrides
15974 scroll-*-aggressively. */
15975 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15977 double float_amount
= XFLOATINT (aggressive
);
15979 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15980 if (pt_offset
== 0 && float_amount
> 0)
15982 if (pt_offset
&& margin
> 0)
15985 /* Compute how much to move the window start backward from
15986 point so that point will be displayed where the user
15990 centering_position
= it
.last_visible_y
;
15992 centering_position
-= pt_offset
;
15993 centering_position
-=
15994 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15995 + WINDOW_HEADER_LINE_HEIGHT (w
);
15996 /* Don't let point enter the scroll margin near top of
15998 if (centering_position
< margin
* frame_line_height
)
15999 centering_position
= margin
* frame_line_height
;
16002 centering_position
= margin
* frame_line_height
+ pt_offset
;
16005 /* Set the window start half the height of the window backward
16007 centering_position
= window_box_height (w
) / 2;
16009 move_it_vertically_backward (&it
, centering_position
);
16011 eassert (IT_CHARPOS (it
) >= BEGV
);
16013 /* The function move_it_vertically_backward may move over more
16014 than the specified y-distance. If it->w is small, e.g. a
16015 mini-buffer window, we may end up in front of the window's
16016 display area. Start displaying at the start of the line
16017 containing PT in this case. */
16018 if (it
.current_y
<= 0)
16020 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16021 move_it_vertically_backward (&it
, 0);
16025 it
.current_x
= it
.hpos
= 0;
16027 /* Set the window start position here explicitly, to avoid an
16028 infinite loop in case the functions in window-scroll-functions
16030 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16032 /* Run scroll hooks. */
16033 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16035 /* Redisplay the window. */
16036 if (!current_matrix_up_to_date_p
16037 || windows_or_buffers_changed
16038 || f
->cursor_type_changed
16039 /* Don't use try_window_reusing_current_matrix in this case
16040 because it can have changed the buffer. */
16041 || !NILP (Vwindow_scroll_functions
)
16042 || !just_this_one_p
16043 || MINI_WINDOW_P (w
)
16044 || !(used_current_matrix_p
16045 = try_window_reusing_current_matrix (w
)))
16046 try_window (window
, startp
, 0);
16048 /* If new fonts have been loaded (due to fontsets), give up. We
16049 have to start a new redisplay since we need to re-adjust glyph
16051 if (f
->fonts_changed
)
16052 goto need_larger_matrices
;
16054 /* If cursor did not appear assume that the middle of the window is
16055 in the first line of the window. Do it again with the next line.
16056 (Imagine a window of height 100, displaying two lines of height
16057 60. Moving back 50 from it->last_visible_y will end in the first
16059 if (w
->cursor
.vpos
< 0)
16061 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16063 clear_glyph_matrix (w
->desired_matrix
);
16064 move_it_by_lines (&it
, 1);
16065 try_window (window
, it
.current
.pos
, 0);
16067 else if (PT
< IT_CHARPOS (it
))
16069 clear_glyph_matrix (w
->desired_matrix
);
16070 move_it_by_lines (&it
, -1);
16071 try_window (window
, it
.current
.pos
, 0);
16075 /* Not much we can do about it. */
16079 /* Consider the following case: Window starts at BEGV, there is
16080 invisible, intangible text at BEGV, so that display starts at
16081 some point START > BEGV. It can happen that we are called with
16082 PT somewhere between BEGV and START. Try to handle that case. */
16083 if (w
->cursor
.vpos
< 0)
16085 struct glyph_row
*row
= w
->current_matrix
->rows
;
16086 if (row
->mode_line_p
)
16088 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16091 if (!cursor_row_fully_visible_p (w
, 0, 0))
16093 /* If vscroll is enabled, disable it and try again. */
16097 clear_glyph_matrix (w
->desired_matrix
);
16101 /* Users who set scroll-conservatively to a large number want
16102 point just above/below the scroll margin. If we ended up
16103 with point's row partially visible, move the window start to
16104 make that row fully visible and out of the margin. */
16105 if (scroll_conservatively
> SCROLL_LIMIT
)
16107 int window_total_lines
16108 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16111 ? min (scroll_margin
, window_total_lines
/ 4)
16113 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16115 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16116 clear_glyph_matrix (w
->desired_matrix
);
16117 if (1 == try_window (window
, it
.current
.pos
,
16118 TRY_WINDOW_CHECK_MARGINS
))
16122 /* If centering point failed to make the whole line visible,
16123 put point at the top instead. That has to make the whole line
16124 visible, if it can be done. */
16125 if (centering_position
== 0)
16128 clear_glyph_matrix (w
->desired_matrix
);
16129 centering_position
= 0;
16135 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16136 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16137 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16139 /* Display the mode line, if we must. */
16140 if ((update_mode_line
16141 /* If window not full width, must redo its mode line
16142 if (a) the window to its side is being redone and
16143 (b) we do a frame-based redisplay. This is a consequence
16144 of how inverted lines are drawn in frame-based redisplay. */
16145 || (!just_this_one_p
16146 && !FRAME_WINDOW_P (f
)
16147 && !WINDOW_FULL_WIDTH_P (w
))
16148 /* Line number to display. */
16149 || w
->base_line_pos
> 0
16150 /* Column number is displayed and different from the one displayed. */
16151 || (w
->column_number_displayed
!= -1
16152 && (w
->column_number_displayed
!= current_column ())))
16153 /* This means that the window has a mode line. */
16154 && (WINDOW_WANTS_MODELINE_P (w
)
16155 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16158 display_mode_lines (w
);
16160 /* If mode line height has changed, arrange for a thorough
16161 immediate redisplay using the correct mode line height. */
16162 if (WINDOW_WANTS_MODELINE_P (w
)
16163 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16165 f
->fonts_changed
= 1;
16166 w
->mode_line_height
= -1;
16167 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16168 = DESIRED_MODE_LINE_HEIGHT (w
);
16171 /* If header line height has changed, arrange for a thorough
16172 immediate redisplay using the correct header line height. */
16173 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16174 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16176 f
->fonts_changed
= 1;
16177 w
->header_line_height
= -1;
16178 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16179 = DESIRED_HEADER_LINE_HEIGHT (w
);
16182 if (f
->fonts_changed
)
16183 goto need_larger_matrices
;
16186 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16188 w
->base_line_pos
= 0;
16189 w
->base_line_number
= 0;
16194 /* When we reach a frame's selected window, redo the frame's menu bar. */
16195 if (update_mode_line
16196 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16198 int redisplay_menu_p
= 0;
16200 if (FRAME_WINDOW_P (f
))
16202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16203 || defined (HAVE_NS) || defined (USE_GTK)
16204 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16206 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16210 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16212 if (redisplay_menu_p
)
16213 display_menu_bar (w
);
16215 #ifdef HAVE_WINDOW_SYSTEM
16216 if (FRAME_WINDOW_P (f
))
16218 #if defined (USE_GTK) || defined (HAVE_NS)
16219 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16220 redisplay_tool_bar (f
);
16222 if (WINDOWP (f
->tool_bar_window
)
16223 && (FRAME_TOOL_BAR_LINES (f
) > 0
16224 || !NILP (Vauto_resize_tool_bars
))
16225 && redisplay_tool_bar (f
))
16226 ignore_mouse_drag_p
= 1;
16232 #ifdef HAVE_WINDOW_SYSTEM
16233 if (FRAME_WINDOW_P (f
)
16234 && update_window_fringes (w
, (just_this_one_p
16235 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16236 || w
->pseudo_window_p
)))
16240 if (draw_window_fringes (w
, 1))
16241 x_draw_vertical_border (w
);
16245 #endif /* HAVE_WINDOW_SYSTEM */
16247 /* We go to this label, with fonts_changed set, if it is
16248 necessary to try again using larger glyph matrices.
16249 We have to redeem the scroll bar even in this case,
16250 because the loop in redisplay_internal expects that. */
16251 need_larger_matrices
:
16253 finish_scroll_bars
:
16255 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16257 /* Set the thumb's position and size. */
16258 set_vertical_scroll_bar (w
);
16260 /* Note that we actually used the scroll bar attached to this
16261 window, so it shouldn't be deleted at the end of redisplay. */
16262 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16263 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16266 /* Restore current_buffer and value of point in it. The window
16267 update may have changed the buffer, so first make sure `opoint'
16268 is still valid (Bug#6177). */
16269 if (CHARPOS (opoint
) < BEGV
)
16270 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16271 else if (CHARPOS (opoint
) > ZV
)
16272 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16274 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16276 set_buffer_internal_1 (old
);
16277 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16278 shorter. This can be caused by log truncation in *Messages*. */
16279 if (CHARPOS (lpoint
) <= ZV
)
16280 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16282 unbind_to (count
, Qnil
);
16286 /* Build the complete desired matrix of WINDOW with a window start
16287 buffer position POS.
16289 Value is 1 if successful. It is zero if fonts were loaded during
16290 redisplay which makes re-adjusting glyph matrices necessary, and -1
16291 if point would appear in the scroll margins.
16292 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16293 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16297 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16299 struct window
*w
= XWINDOW (window
);
16301 struct glyph_row
*last_text_row
= NULL
;
16302 struct frame
*f
= XFRAME (w
->frame
);
16303 int frame_line_height
= default_line_pixel_height (w
);
16305 /* Make POS the new window start. */
16306 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16308 /* Mark cursor position as unknown. No overlay arrow seen. */
16309 w
->cursor
.vpos
= -1;
16310 overlay_arrow_seen
= 0;
16312 /* Initialize iterator and info to start at POS. */
16313 start_display (&it
, w
, pos
);
16315 /* Display all lines of W. */
16316 while (it
.current_y
< it
.last_visible_y
)
16318 if (display_line (&it
))
16319 last_text_row
= it
.glyph_row
- 1;
16320 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16324 /* Don't let the cursor end in the scroll margins. */
16325 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16326 && !MINI_WINDOW_P (w
))
16328 int this_scroll_margin
;
16329 int window_total_lines
16330 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16332 if (scroll_margin
> 0)
16334 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16335 this_scroll_margin
*= frame_line_height
;
16338 this_scroll_margin
= 0;
16340 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16341 && w
->cursor
.y
< this_scroll_margin
16342 && CHARPOS (pos
) > BEGV
16343 && IT_CHARPOS (it
) < ZV
)
16344 /* rms: considering make_cursor_line_fully_visible_p here
16345 seems to give wrong results. We don't want to recenter
16346 when the last line is partly visible, we want to allow
16347 that case to be handled in the usual way. */
16348 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16350 w
->cursor
.vpos
= -1;
16351 clear_glyph_matrix (w
->desired_matrix
);
16356 /* If bottom moved off end of frame, change mode line percentage. */
16357 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16358 w
->update_mode_line
= 1;
16360 /* Set window_end_pos to the offset of the last character displayed
16361 on the window from the end of current_buffer. Set
16362 window_end_vpos to its row number. */
16365 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16366 adjust_window_ends (w
, last_text_row
, 0);
16368 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16369 w
->window_end_vpos
)));
16373 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16374 w
->window_end_pos
= Z
- ZV
;
16375 w
->window_end_vpos
= 0;
16378 /* But that is not valid info until redisplay finishes. */
16379 w
->window_end_valid
= 0;
16385 /************************************************************************
16386 Window redisplay reusing current matrix when buffer has not changed
16387 ************************************************************************/
16389 /* Try redisplay of window W showing an unchanged buffer with a
16390 different window start than the last time it was displayed by
16391 reusing its current matrix. Value is non-zero if successful.
16392 W->start is the new window start. */
16395 try_window_reusing_current_matrix (struct window
*w
)
16397 struct frame
*f
= XFRAME (w
->frame
);
16398 struct glyph_row
*bottom_row
;
16401 struct text_pos start
, new_start
;
16402 int nrows_scrolled
, i
;
16403 struct glyph_row
*last_text_row
;
16404 struct glyph_row
*last_reused_text_row
;
16405 struct glyph_row
*start_row
;
16406 int start_vpos
, min_y
, max_y
;
16409 if (inhibit_try_window_reusing
)
16413 if (/* This function doesn't handle terminal frames. */
16414 !FRAME_WINDOW_P (f
)
16415 /* Don't try to reuse the display if windows have been split
16417 || windows_or_buffers_changed
16418 || f
->cursor_type_changed
)
16421 /* Can't do this if showing trailing whitespace. */
16422 if (!NILP (Vshow_trailing_whitespace
))
16425 /* If top-line visibility has changed, give up. */
16426 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16427 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16430 /* Give up if old or new display is scrolled vertically. We could
16431 make this function handle this, but right now it doesn't. */
16432 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16433 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16436 /* The variable new_start now holds the new window start. The old
16437 start `start' can be determined from the current matrix. */
16438 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16439 start
= start_row
->minpos
;
16440 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16442 /* Clear the desired matrix for the display below. */
16443 clear_glyph_matrix (w
->desired_matrix
);
16445 if (CHARPOS (new_start
) <= CHARPOS (start
))
16447 /* Don't use this method if the display starts with an ellipsis
16448 displayed for invisible text. It's not easy to handle that case
16449 below, and it's certainly not worth the effort since this is
16450 not a frequent case. */
16451 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16454 IF_DEBUG (debug_method_add (w
, "twu1"));
16456 /* Display up to a row that can be reused. The variable
16457 last_text_row is set to the last row displayed that displays
16458 text. Note that it.vpos == 0 if or if not there is a
16459 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16460 start_display (&it
, w
, new_start
);
16461 w
->cursor
.vpos
= -1;
16462 last_text_row
= last_reused_text_row
= NULL
;
16464 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16466 /* If we have reached into the characters in the START row,
16467 that means the line boundaries have changed. So we
16468 can't start copying with the row START. Maybe it will
16469 work to start copying with the following row. */
16470 while (IT_CHARPOS (it
) > CHARPOS (start
))
16472 /* Advance to the next row as the "start". */
16474 start
= start_row
->minpos
;
16475 /* If there are no more rows to try, or just one, give up. */
16476 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16477 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16478 || CHARPOS (start
) == ZV
)
16480 clear_glyph_matrix (w
->desired_matrix
);
16484 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16486 /* If we have reached alignment, we can copy the rest of the
16488 if (IT_CHARPOS (it
) == CHARPOS (start
)
16489 /* Don't accept "alignment" inside a display vector,
16490 since start_row could have started in the middle of
16491 that same display vector (thus their character
16492 positions match), and we have no way of telling if
16493 that is the case. */
16494 && it
.current
.dpvec_index
< 0)
16497 if (display_line (&it
))
16498 last_text_row
= it
.glyph_row
- 1;
16502 /* A value of current_y < last_visible_y means that we stopped
16503 at the previous window start, which in turn means that we
16504 have at least one reusable row. */
16505 if (it
.current_y
< it
.last_visible_y
)
16507 struct glyph_row
*row
;
16509 /* IT.vpos always starts from 0; it counts text lines. */
16510 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16512 /* Find PT if not already found in the lines displayed. */
16513 if (w
->cursor
.vpos
< 0)
16515 int dy
= it
.current_y
- start_row
->y
;
16517 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16518 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16520 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16521 dy
, nrows_scrolled
);
16524 clear_glyph_matrix (w
->desired_matrix
);
16529 /* Scroll the display. Do it before the current matrix is
16530 changed. The problem here is that update has not yet
16531 run, i.e. part of the current matrix is not up to date.
16532 scroll_run_hook will clear the cursor, and use the
16533 current matrix to get the height of the row the cursor is
16535 run
.current_y
= start_row
->y
;
16536 run
.desired_y
= it
.current_y
;
16537 run
.height
= it
.last_visible_y
- it
.current_y
;
16539 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16542 FRAME_RIF (f
)->update_window_begin_hook (w
);
16543 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16544 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16545 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16549 /* Shift current matrix down by nrows_scrolled lines. */
16550 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16551 rotate_matrix (w
->current_matrix
,
16553 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16556 /* Disable lines that must be updated. */
16557 for (i
= 0; i
< nrows_scrolled
; ++i
)
16558 (start_row
+ i
)->enabled_p
= 0;
16560 /* Re-compute Y positions. */
16561 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16562 max_y
= it
.last_visible_y
;
16563 for (row
= start_row
+ nrows_scrolled
;
16567 row
->y
= it
.current_y
;
16568 row
->visible_height
= row
->height
;
16570 if (row
->y
< min_y
)
16571 row
->visible_height
-= min_y
- row
->y
;
16572 if (row
->y
+ row
->height
> max_y
)
16573 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16574 if (row
->fringe_bitmap_periodic_p
)
16575 row
->redraw_fringe_bitmaps_p
= 1;
16577 it
.current_y
+= row
->height
;
16579 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16580 last_reused_text_row
= row
;
16581 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16585 /* Disable lines in the current matrix which are now
16586 below the window. */
16587 for (++row
; row
< bottom_row
; ++row
)
16588 row
->enabled_p
= row
->mode_line_p
= 0;
16591 /* Update window_end_pos etc.; last_reused_text_row is the last
16592 reused row from the current matrix containing text, if any.
16593 The value of last_text_row is the last displayed line
16594 containing text. */
16595 if (last_reused_text_row
)
16596 adjust_window_ends (w
, last_reused_text_row
, 1);
16597 else if (last_text_row
)
16598 adjust_window_ends (w
, last_text_row
, 0);
16601 /* This window must be completely empty. */
16602 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16603 w
->window_end_pos
= Z
- ZV
;
16604 w
->window_end_vpos
= 0;
16606 w
->window_end_valid
= 0;
16608 /* Update hint: don't try scrolling again in update_window. */
16609 w
->desired_matrix
->no_scrolling_p
= 1;
16612 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16616 else if (CHARPOS (new_start
) > CHARPOS (start
))
16618 struct glyph_row
*pt_row
, *row
;
16619 struct glyph_row
*first_reusable_row
;
16620 struct glyph_row
*first_row_to_display
;
16622 int yb
= window_text_bottom_y (w
);
16624 /* Find the row starting at new_start, if there is one. Don't
16625 reuse a partially visible line at the end. */
16626 first_reusable_row
= start_row
;
16627 while (first_reusable_row
->enabled_p
16628 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16629 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16630 < CHARPOS (new_start
)))
16631 ++first_reusable_row
;
16633 /* Give up if there is no row to reuse. */
16634 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16635 || !first_reusable_row
->enabled_p
16636 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16637 != CHARPOS (new_start
)))
16640 /* We can reuse fully visible rows beginning with
16641 first_reusable_row to the end of the window. Set
16642 first_row_to_display to the first row that cannot be reused.
16643 Set pt_row to the row containing point, if there is any. */
16645 for (first_row_to_display
= first_reusable_row
;
16646 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16647 ++first_row_to_display
)
16649 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16650 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16651 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16652 && first_row_to_display
->ends_at_zv_p
16653 && pt_row
== NULL
)))
16654 pt_row
= first_row_to_display
;
16657 /* Start displaying at the start of first_row_to_display. */
16658 eassert (first_row_to_display
->y
< yb
);
16659 init_to_row_start (&it
, w
, first_row_to_display
);
16661 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16663 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16665 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16666 + WINDOW_HEADER_LINE_HEIGHT (w
));
16668 /* Display lines beginning with first_row_to_display in the
16669 desired matrix. Set last_text_row to the last row displayed
16670 that displays text. */
16671 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16672 if (pt_row
== NULL
)
16673 w
->cursor
.vpos
= -1;
16674 last_text_row
= NULL
;
16675 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16676 if (display_line (&it
))
16677 last_text_row
= it
.glyph_row
- 1;
16679 /* If point is in a reused row, adjust y and vpos of the cursor
16683 w
->cursor
.vpos
-= nrows_scrolled
;
16684 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16687 /* Give up if point isn't in a row displayed or reused. (This
16688 also handles the case where w->cursor.vpos < nrows_scrolled
16689 after the calls to display_line, which can happen with scroll
16690 margins. See bug#1295.) */
16691 if (w
->cursor
.vpos
< 0)
16693 clear_glyph_matrix (w
->desired_matrix
);
16697 /* Scroll the display. */
16698 run
.current_y
= first_reusable_row
->y
;
16699 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16700 run
.height
= it
.last_visible_y
- run
.current_y
;
16701 dy
= run
.current_y
- run
.desired_y
;
16706 FRAME_RIF (f
)->update_window_begin_hook (w
);
16707 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16708 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16709 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16713 /* Adjust Y positions of reused rows. */
16714 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16715 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16716 max_y
= it
.last_visible_y
;
16717 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16720 row
->visible_height
= row
->height
;
16721 if (row
->y
< min_y
)
16722 row
->visible_height
-= min_y
- row
->y
;
16723 if (row
->y
+ row
->height
> max_y
)
16724 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16725 if (row
->fringe_bitmap_periodic_p
)
16726 row
->redraw_fringe_bitmaps_p
= 1;
16729 /* Scroll the current matrix. */
16730 eassert (nrows_scrolled
> 0);
16731 rotate_matrix (w
->current_matrix
,
16733 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16736 /* Disable rows not reused. */
16737 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16738 row
->enabled_p
= 0;
16740 /* Point may have moved to a different line, so we cannot assume that
16741 the previous cursor position is valid; locate the correct row. */
16744 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16746 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16747 && !row
->ends_at_zv_p
;
16751 w
->cursor
.y
= row
->y
;
16753 if (row
< bottom_row
)
16755 /* Can't simply scan the row for point with
16756 bidi-reordered glyph rows. Let set_cursor_from_row
16757 figure out where to put the cursor, and if it fails,
16759 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16761 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16764 clear_glyph_matrix (w
->desired_matrix
);
16770 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16771 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16774 && (!BUFFERP (glyph
->object
)
16775 || glyph
->charpos
< PT
);
16779 w
->cursor
.x
+= glyph
->pixel_width
;
16785 /* Adjust window end. A null value of last_text_row means that
16786 the window end is in reused rows which in turn means that
16787 only its vpos can have changed. */
16789 adjust_window_ends (w
, last_text_row
, 0);
16791 w
->window_end_vpos
-= nrows_scrolled
;
16793 w
->window_end_valid
= 0;
16794 w
->desired_matrix
->no_scrolling_p
= 1;
16797 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16807 /************************************************************************
16808 Window redisplay reusing current matrix when buffer has changed
16809 ************************************************************************/
16811 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16812 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16813 ptrdiff_t *, ptrdiff_t *);
16814 static struct glyph_row
*
16815 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16816 struct glyph_row
*);
16819 /* Return the last row in MATRIX displaying text. If row START is
16820 non-null, start searching with that row. IT gives the dimensions
16821 of the display. Value is null if matrix is empty; otherwise it is
16822 a pointer to the row found. */
16824 static struct glyph_row
*
16825 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16826 struct glyph_row
*start
)
16828 struct glyph_row
*row
, *row_found
;
16830 /* Set row_found to the last row in IT->w's current matrix
16831 displaying text. The loop looks funny but think of partially
16834 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16835 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16837 eassert (row
->enabled_p
);
16839 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16848 /* Return the last row in the current matrix of W that is not affected
16849 by changes at the start of current_buffer that occurred since W's
16850 current matrix was built. Value is null if no such row exists.
16852 BEG_UNCHANGED us the number of characters unchanged at the start of
16853 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16854 first changed character in current_buffer. Characters at positions <
16855 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16856 when the current matrix was built. */
16858 static struct glyph_row
*
16859 find_last_unchanged_at_beg_row (struct window
*w
)
16861 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16862 struct glyph_row
*row
;
16863 struct glyph_row
*row_found
= NULL
;
16864 int yb
= window_text_bottom_y (w
);
16866 /* Find the last row displaying unchanged text. */
16867 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16868 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16869 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16872 if (/* If row ends before first_changed_pos, it is unchanged,
16873 except in some case. */
16874 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16875 /* When row ends in ZV and we write at ZV it is not
16877 && !row
->ends_at_zv_p
16878 /* When first_changed_pos is the end of a continued line,
16879 row is not unchanged because it may be no longer
16881 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16882 && (row
->continued_p
16883 || row
->exact_window_width_line_p
))
16884 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16885 needs to be recomputed, so don't consider this row as
16886 unchanged. This happens when the last line was
16887 bidi-reordered and was killed immediately before this
16888 redisplay cycle. In that case, ROW->end stores the
16889 buffer position of the first visual-order character of
16890 the killed text, which is now beyond ZV. */
16891 && CHARPOS (row
->end
.pos
) <= ZV
)
16894 /* Stop if last visible row. */
16895 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16903 /* Find the first glyph row in the current matrix of W that is not
16904 affected by changes at the end of current_buffer since the
16905 time W's current matrix was built.
16907 Return in *DELTA the number of chars by which buffer positions in
16908 unchanged text at the end of current_buffer must be adjusted.
16910 Return in *DELTA_BYTES the corresponding number of bytes.
16912 Value is null if no such row exists, i.e. all rows are affected by
16915 static struct glyph_row
*
16916 find_first_unchanged_at_end_row (struct window
*w
,
16917 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16919 struct glyph_row
*row
;
16920 struct glyph_row
*row_found
= NULL
;
16922 *delta
= *delta_bytes
= 0;
16924 /* Display must not have been paused, otherwise the current matrix
16925 is not up to date. */
16926 eassert (w
->window_end_valid
);
16928 /* A value of window_end_pos >= END_UNCHANGED means that the window
16929 end is in the range of changed text. If so, there is no
16930 unchanged row at the end of W's current matrix. */
16931 if (w
->window_end_pos
>= END_UNCHANGED
)
16934 /* Set row to the last row in W's current matrix displaying text. */
16935 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16937 /* If matrix is entirely empty, no unchanged row exists. */
16938 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16940 /* The value of row is the last glyph row in the matrix having a
16941 meaningful buffer position in it. The end position of row
16942 corresponds to window_end_pos. This allows us to translate
16943 buffer positions in the current matrix to current buffer
16944 positions for characters not in changed text. */
16946 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16947 ptrdiff_t Z_BYTE_old
=
16948 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16949 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16950 struct glyph_row
*first_text_row
16951 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16953 *delta
= Z
- Z_old
;
16954 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16956 /* Set last_unchanged_pos to the buffer position of the last
16957 character in the buffer that has not been changed. Z is the
16958 index + 1 of the last character in current_buffer, i.e. by
16959 subtracting END_UNCHANGED we get the index of the last
16960 unchanged character, and we have to add BEG to get its buffer
16962 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16963 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16965 /* Search backward from ROW for a row displaying a line that
16966 starts at a minimum position >= last_unchanged_pos_old. */
16967 for (; row
> first_text_row
; --row
)
16969 /* This used to abort, but it can happen.
16970 It is ok to just stop the search instead here. KFS. */
16971 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16974 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16979 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16985 /* Make sure that glyph rows in the current matrix of window W
16986 reference the same glyph memory as corresponding rows in the
16987 frame's frame matrix. This function is called after scrolling W's
16988 current matrix on a terminal frame in try_window_id and
16989 try_window_reusing_current_matrix. */
16992 sync_frame_with_window_matrix_rows (struct window
*w
)
16994 struct frame
*f
= XFRAME (w
->frame
);
16995 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16997 /* Preconditions: W must be a leaf window and full-width. Its frame
16998 must have a frame matrix. */
16999 eassert (BUFFERP (w
->contents
));
17000 eassert (WINDOW_FULL_WIDTH_P (w
));
17001 eassert (!FRAME_WINDOW_P (f
));
17003 /* If W is a full-width window, glyph pointers in W's current matrix
17004 have, by definition, to be the same as glyph pointers in the
17005 corresponding frame matrix. Note that frame matrices have no
17006 marginal areas (see build_frame_matrix). */
17007 window_row
= w
->current_matrix
->rows
;
17008 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17009 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17010 while (window_row
< window_row_end
)
17012 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17013 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17015 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17016 frame_row
->glyphs
[TEXT_AREA
] = start
;
17017 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17018 frame_row
->glyphs
[LAST_AREA
] = end
;
17020 /* Disable frame rows whose corresponding window rows have
17021 been disabled in try_window_id. */
17022 if (!window_row
->enabled_p
)
17023 frame_row
->enabled_p
= 0;
17025 ++window_row
, ++frame_row
;
17030 /* Find the glyph row in window W containing CHARPOS. Consider all
17031 rows between START and END (not inclusive). END null means search
17032 all rows to the end of the display area of W. Value is the row
17033 containing CHARPOS or null. */
17036 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17037 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17039 struct glyph_row
*row
= start
;
17040 struct glyph_row
*best_row
= NULL
;
17041 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17044 /* If we happen to start on a header-line, skip that. */
17045 if (row
->mode_line_p
)
17048 if ((end
&& row
>= end
) || !row
->enabled_p
)
17051 last_y
= window_text_bottom_y (w
) - dy
;
17055 /* Give up if we have gone too far. */
17056 if (end
&& row
>= end
)
17058 /* This formerly returned if they were equal.
17059 I think that both quantities are of a "last plus one" type;
17060 if so, when they are equal, the row is within the screen. -- rms. */
17061 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17064 /* If it is in this row, return this row. */
17065 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17066 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17067 /* The end position of a row equals the start
17068 position of the next row. If CHARPOS is there, we
17069 would rather consider it displayed in the next
17070 line, except when this line ends in ZV. */
17071 && !row_for_charpos_p (row
, charpos
)))
17072 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17076 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17077 || (!best_row
&& !row
->continued_p
))
17079 /* In bidi-reordered rows, there could be several rows whose
17080 edges surround CHARPOS, all of these rows belonging to
17081 the same continued line. We need to find the row which
17082 fits CHARPOS the best. */
17083 for (g
= row
->glyphs
[TEXT_AREA
];
17084 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17087 if (!STRINGP (g
->object
))
17089 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17091 mindif
= eabs (g
->charpos
- charpos
);
17093 /* Exact match always wins. */
17100 else if (best_row
&& !row
->continued_p
)
17107 /* Try to redisplay window W by reusing its existing display. W's
17108 current matrix must be up to date when this function is called,
17109 i.e. window_end_valid must be nonzero.
17113 1 if display has been updated
17114 0 if otherwise unsuccessful
17115 -1 if redisplay with same window start is known not to succeed
17117 The following steps are performed:
17119 1. Find the last row in the current matrix of W that is not
17120 affected by changes at the start of current_buffer. If no such row
17123 2. Find the first row in W's current matrix that is not affected by
17124 changes at the end of current_buffer. Maybe there is no such row.
17126 3. Display lines beginning with the row + 1 found in step 1 to the
17127 row found in step 2 or, if step 2 didn't find a row, to the end of
17130 4. If cursor is not known to appear on the window, give up.
17132 5. If display stopped at the row found in step 2, scroll the
17133 display and current matrix as needed.
17135 6. Maybe display some lines at the end of W, if we must. This can
17136 happen under various circumstances, like a partially visible line
17137 becoming fully visible, or because newly displayed lines are displayed
17138 in smaller font sizes.
17140 7. Update W's window end information. */
17143 try_window_id (struct window
*w
)
17145 struct frame
*f
= XFRAME (w
->frame
);
17146 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17147 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17148 struct glyph_row
*last_unchanged_at_beg_row
;
17149 struct glyph_row
*first_unchanged_at_end_row
;
17150 struct glyph_row
*row
;
17151 struct glyph_row
*bottom_row
;
17154 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17156 struct text_pos start_pos
;
17158 int first_unchanged_at_end_vpos
= 0;
17159 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17160 struct text_pos start
;
17161 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17164 if (inhibit_try_window_id
)
17168 /* This is handy for debugging. */
17170 #define GIVE_UP(X) \
17172 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17176 #define GIVE_UP(X) return 0
17179 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17181 /* Don't use this for mini-windows because these can show
17182 messages and mini-buffers, and we don't handle that here. */
17183 if (MINI_WINDOW_P (w
))
17186 /* This flag is used to prevent redisplay optimizations. */
17187 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17190 /* Verify that narrowing has not changed.
17191 Also verify that we were not told to prevent redisplay optimizations.
17192 It would be nice to further
17193 reduce the number of cases where this prevents try_window_id. */
17194 if (current_buffer
->clip_changed
17195 || current_buffer
->prevent_redisplay_optimizations_p
)
17198 /* Window must either use window-based redisplay or be full width. */
17199 if (!FRAME_WINDOW_P (f
)
17200 && (!FRAME_LINE_INS_DEL_OK (f
)
17201 || !WINDOW_FULL_WIDTH_P (w
)))
17204 /* Give up if point is known NOT to appear in W. */
17205 if (PT
< CHARPOS (start
))
17208 /* Another way to prevent redisplay optimizations. */
17209 if (w
->last_modified
== 0)
17212 /* Verify that window is not hscrolled. */
17213 if (w
->hscroll
!= 0)
17216 /* Verify that display wasn't paused. */
17217 if (!w
->window_end_valid
)
17220 /* Likewise if highlighting trailing whitespace. */
17221 if (!NILP (Vshow_trailing_whitespace
))
17224 /* Can't use this if overlay arrow position and/or string have
17226 if (overlay_arrows_changed_p ())
17229 /* When word-wrap is on, adding a space to the first word of a
17230 wrapped line can change the wrap position, altering the line
17231 above it. It might be worthwhile to handle this more
17232 intelligently, but for now just redisplay from scratch. */
17233 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17236 /* Under bidi reordering, adding or deleting a character in the
17237 beginning of a paragraph, before the first strong directional
17238 character, can change the base direction of the paragraph (unless
17239 the buffer specifies a fixed paragraph direction), which will
17240 require to redisplay the whole paragraph. It might be worthwhile
17241 to find the paragraph limits and widen the range of redisplayed
17242 lines to that, but for now just give up this optimization and
17243 redisplay from scratch. */
17244 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17245 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17248 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17249 only if buffer has really changed. The reason is that the gap is
17250 initially at Z for freshly visited files. The code below would
17251 set end_unchanged to 0 in that case. */
17252 if (MODIFF
> SAVE_MODIFF
17253 /* This seems to happen sometimes after saving a buffer. */
17254 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17256 if (GPT
- BEG
< BEG_UNCHANGED
)
17257 BEG_UNCHANGED
= GPT
- BEG
;
17258 if (Z
- GPT
< END_UNCHANGED
)
17259 END_UNCHANGED
= Z
- GPT
;
17262 /* The position of the first and last character that has been changed. */
17263 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17264 last_changed_charpos
= Z
- END_UNCHANGED
;
17266 /* If window starts after a line end, and the last change is in
17267 front of that newline, then changes don't affect the display.
17268 This case happens with stealth-fontification. Note that although
17269 the display is unchanged, glyph positions in the matrix have to
17270 be adjusted, of course. */
17271 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17272 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17273 && ((last_changed_charpos
< CHARPOS (start
)
17274 && CHARPOS (start
) == BEGV
)
17275 || (last_changed_charpos
< CHARPOS (start
) - 1
17276 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17278 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17279 struct glyph_row
*r0
;
17281 /* Compute how many chars/bytes have been added to or removed
17282 from the buffer. */
17283 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17284 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17285 Z_delta
= Z
- Z_old
;
17286 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17288 /* Give up if PT is not in the window. Note that it already has
17289 been checked at the start of try_window_id that PT is not in
17290 front of the window start. */
17291 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17294 /* If window start is unchanged, we can reuse the whole matrix
17295 as is, after adjusting glyph positions. No need to compute
17296 the window end again, since its offset from Z hasn't changed. */
17297 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17298 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17299 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17300 /* PT must not be in a partially visible line. */
17301 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17302 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17304 /* Adjust positions in the glyph matrix. */
17305 if (Z_delta
|| Z_delta_bytes
)
17307 struct glyph_row
*r1
17308 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17309 increment_matrix_positions (w
->current_matrix
,
17310 MATRIX_ROW_VPOS (r0
, current_matrix
),
17311 MATRIX_ROW_VPOS (r1
, current_matrix
),
17312 Z_delta
, Z_delta_bytes
);
17315 /* Set the cursor. */
17316 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17318 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17323 /* Handle the case that changes are all below what is displayed in
17324 the window, and that PT is in the window. This shortcut cannot
17325 be taken if ZV is visible in the window, and text has been added
17326 there that is visible in the window. */
17327 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17328 /* ZV is not visible in the window, or there are no
17329 changes at ZV, actually. */
17330 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17331 || first_changed_charpos
== last_changed_charpos
))
17333 struct glyph_row
*r0
;
17335 /* Give up if PT is not in the window. Note that it already has
17336 been checked at the start of try_window_id that PT is not in
17337 front of the window start. */
17338 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17341 /* If window start is unchanged, we can reuse the whole matrix
17342 as is, without changing glyph positions since no text has
17343 been added/removed in front of the window end. */
17344 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17345 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17346 /* PT must not be in a partially visible line. */
17347 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17348 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17350 /* We have to compute the window end anew since text
17351 could have been added/removed after it. */
17352 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17353 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17355 /* Set the cursor. */
17356 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17358 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17363 /* Give up if window start is in the changed area.
17365 The condition used to read
17367 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17369 but why that was tested escapes me at the moment. */
17370 if (CHARPOS (start
) >= first_changed_charpos
17371 && CHARPOS (start
) <= last_changed_charpos
)
17374 /* Check that window start agrees with the start of the first glyph
17375 row in its current matrix. Check this after we know the window
17376 start is not in changed text, otherwise positions would not be
17378 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17379 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17382 /* Give up if the window ends in strings. Overlay strings
17383 at the end are difficult to handle, so don't try. */
17384 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17385 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17388 /* Compute the position at which we have to start displaying new
17389 lines. Some of the lines at the top of the window might be
17390 reusable because they are not displaying changed text. Find the
17391 last row in W's current matrix not affected by changes at the
17392 start of current_buffer. Value is null if changes start in the
17393 first line of window. */
17394 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17395 if (last_unchanged_at_beg_row
)
17397 /* Avoid starting to display in the middle of a character, a TAB
17398 for instance. This is easier than to set up the iterator
17399 exactly, and it's not a frequent case, so the additional
17400 effort wouldn't really pay off. */
17401 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17402 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17403 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17404 --last_unchanged_at_beg_row
;
17406 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17409 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17411 start_pos
= it
.current
.pos
;
17413 /* Start displaying new lines in the desired matrix at the same
17414 vpos we would use in the current matrix, i.e. below
17415 last_unchanged_at_beg_row. */
17416 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17418 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17419 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17421 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17425 /* There are no reusable lines at the start of the window.
17426 Start displaying in the first text line. */
17427 start_display (&it
, w
, start
);
17428 it
.vpos
= it
.first_vpos
;
17429 start_pos
= it
.current
.pos
;
17432 /* Find the first row that is not affected by changes at the end of
17433 the buffer. Value will be null if there is no unchanged row, in
17434 which case we must redisplay to the end of the window. delta
17435 will be set to the value by which buffer positions beginning with
17436 first_unchanged_at_end_row have to be adjusted due to text
17438 first_unchanged_at_end_row
17439 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17440 IF_DEBUG (debug_delta
= delta
);
17441 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17443 /* Set stop_pos to the buffer position up to which we will have to
17444 display new lines. If first_unchanged_at_end_row != NULL, this
17445 is the buffer position of the start of the line displayed in that
17446 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17447 that we don't stop at a buffer position. */
17449 if (first_unchanged_at_end_row
)
17451 eassert (last_unchanged_at_beg_row
== NULL
17452 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17454 /* If this is a continuation line, move forward to the next one
17455 that isn't. Changes in lines above affect this line.
17456 Caution: this may move first_unchanged_at_end_row to a row
17457 not displaying text. */
17458 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17459 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17460 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17461 < it
.last_visible_y
))
17462 ++first_unchanged_at_end_row
;
17464 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17465 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17466 >= it
.last_visible_y
))
17467 first_unchanged_at_end_row
= NULL
;
17470 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17472 first_unchanged_at_end_vpos
17473 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17474 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17477 else if (last_unchanged_at_beg_row
== NULL
)
17483 /* Either there is no unchanged row at the end, or the one we have
17484 now displays text. This is a necessary condition for the window
17485 end pos calculation at the end of this function. */
17486 eassert (first_unchanged_at_end_row
== NULL
17487 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17489 debug_last_unchanged_at_beg_vpos
17490 = (last_unchanged_at_beg_row
17491 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17493 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17495 #endif /* GLYPH_DEBUG */
17498 /* Display new lines. Set last_text_row to the last new line
17499 displayed which has text on it, i.e. might end up as being the
17500 line where the window_end_vpos is. */
17501 w
->cursor
.vpos
= -1;
17502 last_text_row
= NULL
;
17503 overlay_arrow_seen
= 0;
17504 while (it
.current_y
< it
.last_visible_y
17505 && !f
->fonts_changed
17506 && (first_unchanged_at_end_row
== NULL
17507 || IT_CHARPOS (it
) < stop_pos
))
17509 if (display_line (&it
))
17510 last_text_row
= it
.glyph_row
- 1;
17513 if (f
->fonts_changed
)
17517 /* Compute differences in buffer positions, y-positions etc. for
17518 lines reused at the bottom of the window. Compute what we can
17520 if (first_unchanged_at_end_row
17521 /* No lines reused because we displayed everything up to the
17522 bottom of the window. */
17523 && it
.current_y
< it
.last_visible_y
)
17526 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17528 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17529 run
.current_y
= first_unchanged_at_end_row
->y
;
17530 run
.desired_y
= run
.current_y
+ dy
;
17531 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17535 delta
= delta_bytes
= dvpos
= dy
17536 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17537 first_unchanged_at_end_row
= NULL
;
17539 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17542 /* Find the cursor if not already found. We have to decide whether
17543 PT will appear on this window (it sometimes doesn't, but this is
17544 not a very frequent case.) This decision has to be made before
17545 the current matrix is altered. A value of cursor.vpos < 0 means
17546 that PT is either in one of the lines beginning at
17547 first_unchanged_at_end_row or below the window. Don't care for
17548 lines that might be displayed later at the window end; as
17549 mentioned, this is not a frequent case. */
17550 if (w
->cursor
.vpos
< 0)
17552 /* Cursor in unchanged rows at the top? */
17553 if (PT
< CHARPOS (start_pos
)
17554 && last_unchanged_at_beg_row
)
17556 row
= row_containing_pos (w
, PT
,
17557 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17558 last_unchanged_at_beg_row
+ 1, 0);
17560 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17563 /* Start from first_unchanged_at_end_row looking for PT. */
17564 else if (first_unchanged_at_end_row
)
17566 row
= row_containing_pos (w
, PT
- delta
,
17567 first_unchanged_at_end_row
, NULL
, 0);
17569 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17570 delta_bytes
, dy
, dvpos
);
17573 /* Give up if cursor was not found. */
17574 if (w
->cursor
.vpos
< 0)
17576 clear_glyph_matrix (w
->desired_matrix
);
17581 /* Don't let the cursor end in the scroll margins. */
17583 int this_scroll_margin
, cursor_height
;
17584 int frame_line_height
= default_line_pixel_height (w
);
17585 int window_total_lines
17586 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17588 this_scroll_margin
=
17589 max (0, min (scroll_margin
, window_total_lines
/ 4));
17590 this_scroll_margin
*= frame_line_height
;
17591 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17593 if ((w
->cursor
.y
< this_scroll_margin
17594 && CHARPOS (start
) > BEGV
)
17595 /* Old redisplay didn't take scroll margin into account at the bottom,
17596 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17597 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17598 ? cursor_height
+ this_scroll_margin
17599 : 1)) > it
.last_visible_y
)
17601 w
->cursor
.vpos
= -1;
17602 clear_glyph_matrix (w
->desired_matrix
);
17607 /* Scroll the display. Do it before changing the current matrix so
17608 that xterm.c doesn't get confused about where the cursor glyph is
17610 if (dy
&& run
.height
)
17614 if (FRAME_WINDOW_P (f
))
17616 FRAME_RIF (f
)->update_window_begin_hook (w
);
17617 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17618 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17619 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17623 /* Terminal frame. In this case, dvpos gives the number of
17624 lines to scroll by; dvpos < 0 means scroll up. */
17626 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17627 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17628 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17629 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17630 + window_internal_height (w
));
17632 #if defined (HAVE_GPM) || defined (MSDOS)
17633 x_clear_window_mouse_face (w
);
17635 /* Perform the operation on the screen. */
17638 /* Scroll last_unchanged_at_beg_row to the end of the
17639 window down dvpos lines. */
17640 set_terminal_window (f
, end
);
17642 /* On dumb terminals delete dvpos lines at the end
17643 before inserting dvpos empty lines. */
17644 if (!FRAME_SCROLL_REGION_OK (f
))
17645 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17647 /* Insert dvpos empty lines in front of
17648 last_unchanged_at_beg_row. */
17649 ins_del_lines (f
, from
, dvpos
);
17651 else if (dvpos
< 0)
17653 /* Scroll up last_unchanged_at_beg_vpos to the end of
17654 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17655 set_terminal_window (f
, end
);
17657 /* Delete dvpos lines in front of
17658 last_unchanged_at_beg_vpos. ins_del_lines will set
17659 the cursor to the given vpos and emit |dvpos| delete
17661 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17663 /* On a dumb terminal insert dvpos empty lines at the
17665 if (!FRAME_SCROLL_REGION_OK (f
))
17666 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17669 set_terminal_window (f
, 0);
17675 /* Shift reused rows of the current matrix to the right position.
17676 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17678 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17679 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17682 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17683 bottom_vpos
, dvpos
);
17684 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17687 else if (dvpos
> 0)
17689 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17690 bottom_vpos
, dvpos
);
17691 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17692 first_unchanged_at_end_vpos
+ dvpos
);
17695 /* For frame-based redisplay, make sure that current frame and window
17696 matrix are in sync with respect to glyph memory. */
17697 if (!FRAME_WINDOW_P (f
))
17698 sync_frame_with_window_matrix_rows (w
);
17700 /* Adjust buffer positions in reused rows. */
17701 if (delta
|| delta_bytes
)
17702 increment_matrix_positions (current_matrix
,
17703 first_unchanged_at_end_vpos
+ dvpos
,
17704 bottom_vpos
, delta
, delta_bytes
);
17706 /* Adjust Y positions. */
17708 shift_glyph_matrix (w
, current_matrix
,
17709 first_unchanged_at_end_vpos
+ dvpos
,
17712 if (first_unchanged_at_end_row
)
17714 first_unchanged_at_end_row
+= dvpos
;
17715 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17716 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17717 first_unchanged_at_end_row
= NULL
;
17720 /* If scrolling up, there may be some lines to display at the end of
17722 last_text_row_at_end
= NULL
;
17725 /* Scrolling up can leave for example a partially visible line
17726 at the end of the window to be redisplayed. */
17727 /* Set last_row to the glyph row in the current matrix where the
17728 window end line is found. It has been moved up or down in
17729 the matrix by dvpos. */
17730 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17731 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17733 /* If last_row is the window end line, it should display text. */
17734 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17736 /* If window end line was partially visible before, begin
17737 displaying at that line. Otherwise begin displaying with the
17738 line following it. */
17739 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17741 init_to_row_start (&it
, w
, last_row
);
17742 it
.vpos
= last_vpos
;
17743 it
.current_y
= last_row
->y
;
17747 init_to_row_end (&it
, w
, last_row
);
17748 it
.vpos
= 1 + last_vpos
;
17749 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17753 /* We may start in a continuation line. If so, we have to
17754 get the right continuation_lines_width and current_x. */
17755 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17756 it
.hpos
= it
.current_x
= 0;
17758 /* Display the rest of the lines at the window end. */
17759 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17760 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17762 /* Is it always sure that the display agrees with lines in
17763 the current matrix? I don't think so, so we mark rows
17764 displayed invalid in the current matrix by setting their
17765 enabled_p flag to zero. */
17766 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17767 if (display_line (&it
))
17768 last_text_row_at_end
= it
.glyph_row
- 1;
17772 /* Update window_end_pos and window_end_vpos. */
17773 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17775 /* Window end line if one of the preserved rows from the current
17776 matrix. Set row to the last row displaying text in current
17777 matrix starting at first_unchanged_at_end_row, after
17779 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17780 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17781 first_unchanged_at_end_row
);
17782 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17783 adjust_window_ends (w
, row
, 1);
17784 eassert (w
->window_end_bytepos
>= 0);
17785 IF_DEBUG (debug_method_add (w
, "A"));
17787 else if (last_text_row_at_end
)
17789 adjust_window_ends (w
, last_text_row_at_end
, 0);
17790 eassert (w
->window_end_bytepos
>= 0);
17791 IF_DEBUG (debug_method_add (w
, "B"));
17793 else if (last_text_row
)
17795 /* We have displayed either to the end of the window or at the
17796 end of the window, i.e. the last row with text is to be found
17797 in the desired matrix. */
17798 adjust_window_ends (w
, last_text_row
, 0);
17799 eassert (w
->window_end_bytepos
>= 0);
17801 else if (first_unchanged_at_end_row
== NULL
17802 && last_text_row
== NULL
17803 && last_text_row_at_end
== NULL
)
17805 /* Displayed to end of window, but no line containing text was
17806 displayed. Lines were deleted at the end of the window. */
17807 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17808 int vpos
= w
->window_end_vpos
;
17809 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17810 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17813 row
== NULL
&& vpos
>= first_vpos
;
17814 --vpos
, --current_row
, --desired_row
)
17816 if (desired_row
->enabled_p
)
17818 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17821 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17825 eassert (row
!= NULL
);
17826 w
->window_end_vpos
= vpos
+ 1;
17827 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17828 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17829 eassert (w
->window_end_bytepos
>= 0);
17830 IF_DEBUG (debug_method_add (w
, "C"));
17835 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17836 debug_end_vpos
= w
->window_end_vpos
);
17838 /* Record that display has not been completed. */
17839 w
->window_end_valid
= 0;
17840 w
->desired_matrix
->no_scrolling_p
= 1;
17848 /***********************************************************************
17849 More debugging support
17850 ***********************************************************************/
17854 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17855 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17856 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17859 /* Dump the contents of glyph matrix MATRIX on stderr.
17861 GLYPHS 0 means don't show glyph contents.
17862 GLYPHS 1 means show glyphs in short form
17863 GLYPHS > 1 means show glyphs in long form. */
17866 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17869 for (i
= 0; i
< matrix
->nrows
; ++i
)
17870 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17874 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17875 the glyph row and area where the glyph comes from. */
17878 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17880 if (glyph
->type
== CHAR_GLYPH
17881 || glyph
->type
== GLYPHLESS_GLYPH
)
17884 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17885 glyph
- row
->glyphs
[TEXT_AREA
],
17886 (glyph
->type
== CHAR_GLYPH
17890 (BUFFERP (glyph
->object
)
17892 : (STRINGP (glyph
->object
)
17894 : (INTEGERP (glyph
->object
)
17897 glyph
->pixel_width
,
17899 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17903 glyph
->left_box_line_p
,
17904 glyph
->right_box_line_p
);
17906 else if (glyph
->type
== STRETCH_GLYPH
)
17909 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17910 glyph
- row
->glyphs
[TEXT_AREA
],
17913 (BUFFERP (glyph
->object
)
17915 : (STRINGP (glyph
->object
)
17917 : (INTEGERP (glyph
->object
)
17920 glyph
->pixel_width
,
17924 glyph
->left_box_line_p
,
17925 glyph
->right_box_line_p
);
17927 else if (glyph
->type
== IMAGE_GLYPH
)
17930 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17931 glyph
- row
->glyphs
[TEXT_AREA
],
17934 (BUFFERP (glyph
->object
)
17936 : (STRINGP (glyph
->object
)
17938 : (INTEGERP (glyph
->object
)
17941 glyph
->pixel_width
,
17945 glyph
->left_box_line_p
,
17946 glyph
->right_box_line_p
);
17948 else if (glyph
->type
== COMPOSITE_GLYPH
)
17951 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17952 glyph
- row
->glyphs
[TEXT_AREA
],
17955 (BUFFERP (glyph
->object
)
17957 : (STRINGP (glyph
->object
)
17959 : (INTEGERP (glyph
->object
)
17962 glyph
->pixel_width
,
17964 if (glyph
->u
.cmp
.automatic
)
17967 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17968 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17970 glyph
->left_box_line_p
,
17971 glyph
->right_box_line_p
);
17976 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17977 GLYPHS 0 means don't show glyph contents.
17978 GLYPHS 1 means show glyphs in short form
17979 GLYPHS > 1 means show glyphs in long form. */
17982 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17986 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17987 fprintf (stderr
, "==============================================================================\n");
17989 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17990 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17992 MATRIX_ROW_START_CHARPOS (row
),
17993 MATRIX_ROW_END_CHARPOS (row
),
17994 row
->used
[TEXT_AREA
],
17995 row
->contains_overlapping_glyphs_p
,
17997 row
->truncated_on_left_p
,
17998 row
->truncated_on_right_p
,
18000 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18001 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18004 row
->ends_in_middle_of_char_p
,
18005 row
->starts_in_middle_of_char_p
,
18011 row
->visible_height
,
18014 /* The next 3 lines should align to "Start" in the header. */
18015 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18016 row
->end
.overlay_string_index
,
18017 row
->continuation_lines_width
);
18018 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18019 CHARPOS (row
->start
.string_pos
),
18020 CHARPOS (row
->end
.string_pos
));
18021 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18022 row
->end
.dpvec_index
);
18029 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18031 struct glyph
*glyph
= row
->glyphs
[area
];
18032 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18034 /* Glyph for a line end in text. */
18035 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18038 if (glyph
< glyph_end
)
18039 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18041 for (; glyph
< glyph_end
; ++glyph
)
18042 dump_glyph (row
, glyph
, area
);
18045 else if (glyphs
== 1)
18049 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18051 char *s
= alloca (row
->used
[area
] + 4);
18054 for (i
= 0; i
< row
->used
[area
]; ++i
)
18056 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18057 if (i
== row
->used
[area
] - 1
18058 && area
== TEXT_AREA
18059 && INTEGERP (glyph
->object
)
18060 && glyph
->type
== CHAR_GLYPH
18061 && glyph
->u
.ch
== ' ')
18063 strcpy (&s
[i
], "[\\n]");
18066 else if (glyph
->type
== CHAR_GLYPH
18067 && glyph
->u
.ch
< 0x80
18068 && glyph
->u
.ch
>= ' ')
18069 s
[i
] = glyph
->u
.ch
;
18075 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18081 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18082 Sdump_glyph_matrix
, 0, 1, "p",
18083 doc
: /* Dump the current matrix of the selected window to stderr.
18084 Shows contents of glyph row structures. With non-nil
18085 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18086 glyphs in short form, otherwise show glyphs in long form. */)
18087 (Lisp_Object glyphs
)
18089 struct window
*w
= XWINDOW (selected_window
);
18090 struct buffer
*buffer
= XBUFFER (w
->contents
);
18092 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18093 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18094 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18095 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18096 fprintf (stderr
, "=============================================\n");
18097 dump_glyph_matrix (w
->current_matrix
,
18098 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18103 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18104 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18107 struct frame
*f
= XFRAME (selected_frame
);
18108 dump_glyph_matrix (f
->current_matrix
, 1);
18113 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18114 doc
: /* Dump glyph row ROW to stderr.
18115 GLYPH 0 means don't dump glyphs.
18116 GLYPH 1 means dump glyphs in short form.
18117 GLYPH > 1 or omitted means dump glyphs in long form. */)
18118 (Lisp_Object row
, Lisp_Object glyphs
)
18120 struct glyph_matrix
*matrix
;
18123 CHECK_NUMBER (row
);
18124 matrix
= XWINDOW (selected_window
)->current_matrix
;
18126 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18127 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18129 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18134 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18135 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18136 GLYPH 0 means don't dump glyphs.
18137 GLYPH 1 means dump glyphs in short form.
18138 GLYPH > 1 or omitted means dump glyphs in long form.
18140 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18142 (Lisp_Object row
, Lisp_Object glyphs
)
18144 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18145 struct frame
*sf
= SELECTED_FRAME ();
18146 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18149 CHECK_NUMBER (row
);
18151 if (vpos
>= 0 && vpos
< m
->nrows
)
18152 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18153 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18159 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18160 doc
: /* Toggle tracing of redisplay.
18161 With ARG, turn tracing on if and only if ARG is positive. */)
18165 trace_redisplay_p
= !trace_redisplay_p
;
18168 arg
= Fprefix_numeric_value (arg
);
18169 trace_redisplay_p
= XINT (arg
) > 0;
18176 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18177 doc
: /* Like `format', but print result to stderr.
18178 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18179 (ptrdiff_t nargs
, Lisp_Object
*args
)
18181 Lisp_Object s
= Fformat (nargs
, args
);
18182 fprintf (stderr
, "%s", SDATA (s
));
18186 #endif /* GLYPH_DEBUG */
18190 /***********************************************************************
18191 Building Desired Matrix Rows
18192 ***********************************************************************/
18194 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18195 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18197 static struct glyph_row
*
18198 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18200 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18201 struct buffer
*buffer
= XBUFFER (w
->contents
);
18202 struct buffer
*old
= current_buffer
;
18203 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18204 int arrow_len
= SCHARS (overlay_arrow_string
);
18205 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18206 const unsigned char *p
;
18209 int n_glyphs_before
;
18211 set_buffer_temp (buffer
);
18212 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18213 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18214 SET_TEXT_POS (it
.position
, 0, 0);
18216 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18218 while (p
< arrow_end
)
18220 Lisp_Object face
, ilisp
;
18222 /* Get the next character. */
18224 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18227 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18228 if (! ASCII_CHAR_P (it
.c
))
18229 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18233 /* Get its face. */
18234 ilisp
= make_number (p
- arrow_string
);
18235 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18236 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18238 /* Compute its width, get its glyphs. */
18239 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18240 SET_TEXT_POS (it
.position
, -1, -1);
18241 PRODUCE_GLYPHS (&it
);
18243 /* If this character doesn't fit any more in the line, we have
18244 to remove some glyphs. */
18245 if (it
.current_x
> it
.last_visible_x
)
18247 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18252 set_buffer_temp (old
);
18253 return it
.glyph_row
;
18257 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18258 glyphs to insert is determined by produce_special_glyphs. */
18261 insert_left_trunc_glyphs (struct it
*it
)
18263 struct it truncate_it
;
18264 struct glyph
*from
, *end
, *to
, *toend
;
18266 eassert (!FRAME_WINDOW_P (it
->f
)
18267 || (!it
->glyph_row
->reversed_p
18268 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18269 || (it
->glyph_row
->reversed_p
18270 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18272 /* Get the truncation glyphs. */
18274 truncate_it
.current_x
= 0;
18275 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18276 truncate_it
.glyph_row
= &scratch_glyph_row
;
18277 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18278 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18279 truncate_it
.object
= make_number (0);
18280 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18282 /* Overwrite glyphs from IT with truncation glyphs. */
18283 if (!it
->glyph_row
->reversed_p
)
18285 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18287 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18288 end
= from
+ tused
;
18289 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18290 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18291 if (FRAME_WINDOW_P (it
->f
))
18293 /* On GUI frames, when variable-size fonts are displayed,
18294 the truncation glyphs may need more pixels than the row's
18295 glyphs they overwrite. We overwrite more glyphs to free
18296 enough screen real estate, and enlarge the stretch glyph
18297 on the right (see display_line), if there is one, to
18298 preserve the screen position of the truncation glyphs on
18301 struct glyph
*g
= to
;
18304 /* The first glyph could be partially visible, in which case
18305 it->glyph_row->x will be negative. But we want the left
18306 truncation glyphs to be aligned at the left margin of the
18307 window, so we override the x coordinate at which the row
18309 it
->glyph_row
->x
= 0;
18310 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18312 w
+= g
->pixel_width
;
18315 if (g
- to
- tused
> 0)
18317 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18318 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18320 used
= it
->glyph_row
->used
[TEXT_AREA
];
18321 if (it
->glyph_row
->truncated_on_right_p
18322 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18323 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18326 int extra
= w
- it
->truncation_pixel_width
;
18328 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18335 /* There may be padding glyphs left over. Overwrite them too. */
18336 if (!FRAME_WINDOW_P (it
->f
))
18338 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18340 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18347 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18351 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18353 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18354 that back to front. */
18355 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18356 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18357 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18358 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18359 if (FRAME_WINDOW_P (it
->f
))
18362 struct glyph
*g
= to
;
18364 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18366 w
+= g
->pixel_width
;
18369 if (to
- g
- tused
> 0)
18371 if (it
->glyph_row
->truncated_on_right_p
18372 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18373 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18375 int extra
= w
- it
->truncation_pixel_width
;
18377 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18381 while (from
>= end
&& to
>= toend
)
18383 if (!FRAME_WINDOW_P (it
->f
))
18385 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18388 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18389 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18390 while (from
>= end
&& to
>= toend
)
18396 /* Need to free some room before prepending additional
18398 int move_by
= from
- end
+ 1;
18399 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18400 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18402 for ( ; g
>= g0
; g
--)
18404 while (from
>= end
)
18406 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18411 /* Compute the hash code for ROW. */
18413 row_hash (struct glyph_row
*row
)
18416 unsigned hashval
= 0;
18418 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18419 for (k
= 0; k
< row
->used
[area
]; ++k
)
18420 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18421 + row
->glyphs
[area
][k
].u
.val
18422 + row
->glyphs
[area
][k
].face_id
18423 + row
->glyphs
[area
][k
].padding_p
18424 + (row
->glyphs
[area
][k
].type
<< 2));
18429 /* Compute the pixel height and width of IT->glyph_row.
18431 Most of the time, ascent and height of a display line will be equal
18432 to the max_ascent and max_height values of the display iterator
18433 structure. This is not the case if
18435 1. We hit ZV without displaying anything. In this case, max_ascent
18436 and max_height will be zero.
18438 2. We have some glyphs that don't contribute to the line height.
18439 (The glyph row flag contributes_to_line_height_p is for future
18440 pixmap extensions).
18442 The first case is easily covered by using default values because in
18443 these cases, the line height does not really matter, except that it
18444 must not be zero. */
18447 compute_line_metrics (struct it
*it
)
18449 struct glyph_row
*row
= it
->glyph_row
;
18451 if (FRAME_WINDOW_P (it
->f
))
18453 int i
, min_y
, max_y
;
18455 /* The line may consist of one space only, that was added to
18456 place the cursor on it. If so, the row's height hasn't been
18458 if (row
->height
== 0)
18460 if (it
->max_ascent
+ it
->max_descent
== 0)
18461 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18462 row
->ascent
= it
->max_ascent
;
18463 row
->height
= it
->max_ascent
+ it
->max_descent
;
18464 row
->phys_ascent
= it
->max_phys_ascent
;
18465 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18466 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18469 /* Compute the width of this line. */
18470 row
->pixel_width
= row
->x
;
18471 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18472 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18474 eassert (row
->pixel_width
>= 0);
18475 eassert (row
->ascent
>= 0 && row
->height
> 0);
18477 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18478 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18480 /* If first line's physical ascent is larger than its logical
18481 ascent, use the physical ascent, and make the row taller.
18482 This makes accented characters fully visible. */
18483 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18484 && row
->phys_ascent
> row
->ascent
)
18486 row
->height
+= row
->phys_ascent
- row
->ascent
;
18487 row
->ascent
= row
->phys_ascent
;
18490 /* Compute how much of the line is visible. */
18491 row
->visible_height
= row
->height
;
18493 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18494 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18496 if (row
->y
< min_y
)
18497 row
->visible_height
-= min_y
- row
->y
;
18498 if (row
->y
+ row
->height
> max_y
)
18499 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18503 row
->pixel_width
= row
->used
[TEXT_AREA
];
18504 if (row
->continued_p
)
18505 row
->pixel_width
-= it
->continuation_pixel_width
;
18506 else if (row
->truncated_on_right_p
)
18507 row
->pixel_width
-= it
->truncation_pixel_width
;
18508 row
->ascent
= row
->phys_ascent
= 0;
18509 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18510 row
->extra_line_spacing
= 0;
18513 /* Compute a hash code for this row. */
18514 row
->hash
= row_hash (row
);
18516 it
->max_ascent
= it
->max_descent
= 0;
18517 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18521 /* Append one space to the glyph row of iterator IT if doing a
18522 window-based redisplay. The space has the same face as
18523 IT->face_id. Value is non-zero if a space was added.
18525 This function is called to make sure that there is always one glyph
18526 at the end of a glyph row that the cursor can be set on under
18527 window-systems. (If there weren't such a glyph we would not know
18528 how wide and tall a box cursor should be displayed).
18530 At the same time this space let's a nicely handle clearing to the
18531 end of the line if the row ends in italic text. */
18534 append_space_for_newline (struct it
*it
, int default_face_p
)
18536 if (FRAME_WINDOW_P (it
->f
))
18538 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18540 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18541 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18543 /* Save some values that must not be changed.
18544 Must save IT->c and IT->len because otherwise
18545 ITERATOR_AT_END_P wouldn't work anymore after
18546 append_space_for_newline has been called. */
18547 enum display_element_type saved_what
= it
->what
;
18548 int saved_c
= it
->c
, saved_len
= it
->len
;
18549 int saved_char_to_display
= it
->char_to_display
;
18550 int saved_x
= it
->current_x
;
18551 int saved_face_id
= it
->face_id
;
18552 int saved_box_end
= it
->end_of_box_run_p
;
18553 struct text_pos saved_pos
;
18554 Lisp_Object saved_object
;
18557 saved_object
= it
->object
;
18558 saved_pos
= it
->position
;
18560 it
->what
= IT_CHARACTER
;
18561 memset (&it
->position
, 0, sizeof it
->position
);
18562 it
->object
= make_number (0);
18563 it
->c
= it
->char_to_display
= ' ';
18566 /* If the default face was remapped, be sure to use the
18567 remapped face for the appended newline. */
18568 if (default_face_p
)
18569 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18570 else if (it
->face_before_selective_p
)
18571 it
->face_id
= it
->saved_face_id
;
18572 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18573 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18574 /* In R2L rows, we will prepend a stretch glyph that will
18575 have the end_of_box_run_p flag set for it, so there's no
18576 need for the appended newline glyph to have that flag
18578 if (it
->glyph_row
->reversed_p
18579 /* But if the appended newline glyph goes all the way to
18580 the end of the row, there will be no stretch glyph,
18581 so leave the box flag set. */
18582 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18583 it
->end_of_box_run_p
= 0;
18585 PRODUCE_GLYPHS (it
);
18587 it
->override_ascent
= -1;
18588 it
->constrain_row_ascent_descent_p
= 0;
18589 it
->current_x
= saved_x
;
18590 it
->object
= saved_object
;
18591 it
->position
= saved_pos
;
18592 it
->what
= saved_what
;
18593 it
->face_id
= saved_face_id
;
18594 it
->len
= saved_len
;
18596 it
->char_to_display
= saved_char_to_display
;
18597 it
->end_of_box_run_p
= saved_box_end
;
18606 /* Extend the face of the last glyph in the text area of IT->glyph_row
18607 to the end of the display line. Called from display_line. If the
18608 glyph row is empty, add a space glyph to it so that we know the
18609 face to draw. Set the glyph row flag fill_line_p. If the glyph
18610 row is R2L, prepend a stretch glyph to cover the empty space to the
18611 left of the leftmost glyph. */
18614 extend_face_to_end_of_line (struct it
*it
)
18616 struct face
*face
, *default_face
;
18617 struct frame
*f
= it
->f
;
18619 /* If line is already filled, do nothing. Non window-system frames
18620 get a grace of one more ``pixel'' because their characters are
18621 1-``pixel'' wide, so they hit the equality too early. This grace
18622 is needed only for R2L rows that are not continued, to produce
18623 one extra blank where we could display the cursor. */
18624 if (it
->current_x
>= it
->last_visible_x
18625 + (!FRAME_WINDOW_P (f
)
18626 && it
->glyph_row
->reversed_p
18627 && !it
->glyph_row
->continued_p
))
18630 /* The default face, possibly remapped. */
18631 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18633 /* Face extension extends the background and box of IT->face_id
18634 to the end of the line. If the background equals the background
18635 of the frame, we don't have to do anything. */
18636 if (it
->face_before_selective_p
)
18637 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18639 face
= FACE_FROM_ID (f
, it
->face_id
);
18641 if (FRAME_WINDOW_P (f
)
18642 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18643 && face
->box
== FACE_NO_BOX
18644 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18645 #ifdef HAVE_WINDOW_SYSTEM
18648 && !it
->glyph_row
->reversed_p
)
18651 /* Set the glyph row flag indicating that the face of the last glyph
18652 in the text area has to be drawn to the end of the text area. */
18653 it
->glyph_row
->fill_line_p
= 1;
18655 /* If current character of IT is not ASCII, make sure we have the
18656 ASCII face. This will be automatically undone the next time
18657 get_next_display_element returns a multibyte character. Note
18658 that the character will always be single byte in unibyte
18660 if (!ASCII_CHAR_P (it
->c
))
18662 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18665 if (FRAME_WINDOW_P (f
))
18667 /* If the row is empty, add a space with the current face of IT,
18668 so that we know which face to draw. */
18669 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18671 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18672 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18673 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18675 #ifdef HAVE_WINDOW_SYSTEM
18676 if (it
->glyph_row
->reversed_p
)
18678 /* Prepend a stretch glyph to the row, such that the
18679 rightmost glyph will be drawn flushed all the way to the
18680 right margin of the window. The stretch glyph that will
18681 occupy the empty space, if any, to the left of the
18683 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18684 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18685 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18687 int row_width
, stretch_ascent
, stretch_width
;
18688 struct text_pos saved_pos
;
18689 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18691 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18692 row_width
+= g
->pixel_width
;
18693 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18694 if (stretch_width
> 0)
18697 (((it
->ascent
+ it
->descent
)
18698 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18699 saved_pos
= it
->position
;
18700 memset (&it
->position
, 0, sizeof it
->position
);
18701 saved_avoid_cursor
= it
->avoid_cursor_p
;
18702 it
->avoid_cursor_p
= 1;
18703 saved_face_id
= it
->face_id
;
18704 saved_box_start
= it
->start_of_box_run_p
;
18705 /* The last row's stretch glyph should get the default
18706 face, to avoid painting the rest of the window with
18707 the region face, if the region ends at ZV. */
18708 if (it
->glyph_row
->ends_at_zv_p
)
18709 it
->face_id
= default_face
->id
;
18711 it
->face_id
= face
->id
;
18712 it
->start_of_box_run_p
= 0;
18713 append_stretch_glyph (it
, make_number (0), stretch_width
,
18714 it
->ascent
+ it
->descent
, stretch_ascent
);
18715 it
->position
= saved_pos
;
18716 it
->avoid_cursor_p
= saved_avoid_cursor
;
18717 it
->face_id
= saved_face_id
;
18718 it
->start_of_box_run_p
= saved_box_start
;
18721 #endif /* HAVE_WINDOW_SYSTEM */
18725 /* Save some values that must not be changed. */
18726 int saved_x
= it
->current_x
;
18727 struct text_pos saved_pos
;
18728 Lisp_Object saved_object
;
18729 enum display_element_type saved_what
= it
->what
;
18730 int saved_face_id
= it
->face_id
;
18732 saved_object
= it
->object
;
18733 saved_pos
= it
->position
;
18735 it
->what
= IT_CHARACTER
;
18736 memset (&it
->position
, 0, sizeof it
->position
);
18737 it
->object
= make_number (0);
18738 it
->c
= it
->char_to_display
= ' ';
18740 /* The last row's blank glyphs should get the default face, to
18741 avoid painting the rest of the window with the region face,
18742 if the region ends at ZV. */
18743 if (it
->glyph_row
->ends_at_zv_p
)
18744 it
->face_id
= default_face
->id
;
18746 it
->face_id
= face
->id
;
18748 PRODUCE_GLYPHS (it
);
18750 while (it
->current_x
<= it
->last_visible_x
)
18751 PRODUCE_GLYPHS (it
);
18753 /* Don't count these blanks really. It would let us insert a left
18754 truncation glyph below and make us set the cursor on them, maybe. */
18755 it
->current_x
= saved_x
;
18756 it
->object
= saved_object
;
18757 it
->position
= saved_pos
;
18758 it
->what
= saved_what
;
18759 it
->face_id
= saved_face_id
;
18764 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18765 trailing whitespace. */
18768 trailing_whitespace_p (ptrdiff_t charpos
)
18770 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18773 while (bytepos
< ZV_BYTE
18774 && (c
= FETCH_CHAR (bytepos
),
18775 c
== ' ' || c
== '\t'))
18778 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18780 if (bytepos
!= PT_BYTE
)
18787 /* Highlight trailing whitespace, if any, in ROW. */
18790 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18792 int used
= row
->used
[TEXT_AREA
];
18796 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18797 struct glyph
*glyph
= start
+ used
- 1;
18799 if (row
->reversed_p
)
18801 /* Right-to-left rows need to be processed in the opposite
18802 direction, so swap the edge pointers. */
18804 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18807 /* Skip over glyphs inserted to display the cursor at the
18808 end of a line, for extending the face of the last glyph
18809 to the end of the line on terminals, and for truncation
18810 and continuation glyphs. */
18811 if (!row
->reversed_p
)
18813 while (glyph
>= start
18814 && glyph
->type
== CHAR_GLYPH
18815 && INTEGERP (glyph
->object
))
18820 while (glyph
<= start
18821 && glyph
->type
== CHAR_GLYPH
18822 && INTEGERP (glyph
->object
))
18826 /* If last glyph is a space or stretch, and it's trailing
18827 whitespace, set the face of all trailing whitespace glyphs in
18828 IT->glyph_row to `trailing-whitespace'. */
18829 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18830 && BUFFERP (glyph
->object
)
18831 && (glyph
->type
== STRETCH_GLYPH
18832 || (glyph
->type
== CHAR_GLYPH
18833 && glyph
->u
.ch
== ' '))
18834 && trailing_whitespace_p (glyph
->charpos
))
18836 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18840 if (!row
->reversed_p
)
18842 while (glyph
>= start
18843 && BUFFERP (glyph
->object
)
18844 && (glyph
->type
== STRETCH_GLYPH
18845 || (glyph
->type
== CHAR_GLYPH
18846 && glyph
->u
.ch
== ' ')))
18847 (glyph
--)->face_id
= face_id
;
18851 while (glyph
<= start
18852 && BUFFERP (glyph
->object
)
18853 && (glyph
->type
== STRETCH_GLYPH
18854 || (glyph
->type
== CHAR_GLYPH
18855 && glyph
->u
.ch
== ' ')))
18856 (glyph
++)->face_id
= face_id
;
18863 /* Value is non-zero if glyph row ROW should be
18864 considered to hold the buffer position CHARPOS. */
18867 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18871 if (charpos
== CHARPOS (row
->end
.pos
)
18872 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18874 /* Suppose the row ends on a string.
18875 Unless the row is continued, that means it ends on a newline
18876 in the string. If it's anything other than a display string
18877 (e.g., a before-string from an overlay), we don't want the
18878 cursor there. (This heuristic seems to give the optimal
18879 behavior for the various types of multi-line strings.)
18880 One exception: if the string has `cursor' property on one of
18881 its characters, we _do_ want the cursor there. */
18882 if (CHARPOS (row
->end
.string_pos
) >= 0)
18884 if (row
->continued_p
)
18888 /* Check for `display' property. */
18889 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18890 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18891 struct glyph
*glyph
;
18894 for (glyph
= end
; glyph
>= beg
; --glyph
)
18895 if (STRINGP (glyph
->object
))
18898 = Fget_char_property (make_number (charpos
),
18902 && display_prop_string_p (prop
, glyph
->object
));
18903 /* If there's a `cursor' property on one of the
18904 string's characters, this row is a cursor row,
18905 even though this is not a display string. */
18908 Lisp_Object s
= glyph
->object
;
18910 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18912 ptrdiff_t gpos
= glyph
->charpos
;
18914 if (!NILP (Fget_char_property (make_number (gpos
),
18926 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18928 /* If the row ends in middle of a real character,
18929 and the line is continued, we want the cursor here.
18930 That's because CHARPOS (ROW->end.pos) would equal
18931 PT if PT is before the character. */
18932 if (!row
->ends_in_ellipsis_p
)
18933 result
= row
->continued_p
;
18935 /* If the row ends in an ellipsis, then
18936 CHARPOS (ROW->end.pos) will equal point after the
18937 invisible text. We want that position to be displayed
18938 after the ellipsis. */
18941 /* If the row ends at ZV, display the cursor at the end of that
18942 row instead of at the start of the row below. */
18943 else if (row
->ends_at_zv_p
)
18952 /* Value is non-zero if glyph row ROW should be
18953 used to hold the cursor. */
18956 cursor_row_p (struct glyph_row
*row
)
18958 return row_for_charpos_p (row
, PT
);
18963 /* Push the property PROP so that it will be rendered at the current
18964 position in IT. Return 1 if PROP was successfully pushed, 0
18965 otherwise. Called from handle_line_prefix to handle the
18966 `line-prefix' and `wrap-prefix' properties. */
18969 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18971 struct text_pos pos
=
18972 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18974 eassert (it
->method
== GET_FROM_BUFFER
18975 || it
->method
== GET_FROM_DISPLAY_VECTOR
18976 || it
->method
== GET_FROM_STRING
);
18978 /* We need to save the current buffer/string position, so it will be
18979 restored by pop_it, because iterate_out_of_display_property
18980 depends on that being set correctly, but some situations leave
18981 it->position not yet set when this function is called. */
18982 push_it (it
, &pos
);
18984 if (STRINGP (prop
))
18986 if (SCHARS (prop
) == 0)
18993 it
->string_from_prefix_prop_p
= 1;
18994 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18995 it
->current
.overlay_string_index
= -1;
18996 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18997 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18998 it
->method
= GET_FROM_STRING
;
18999 it
->stop_charpos
= 0;
19001 it
->base_level_stop
= 0;
19003 /* Force paragraph direction to be that of the parent
19005 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19006 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19008 it
->paragraph_embedding
= L2R
;
19010 /* Set up the bidi iterator for this display string. */
19013 it
->bidi_it
.string
.lstring
= it
->string
;
19014 it
->bidi_it
.string
.s
= NULL
;
19015 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19016 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19017 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19018 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19019 it
->bidi_it
.w
= it
->w
;
19020 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19023 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19025 it
->method
= GET_FROM_STRETCH
;
19028 #ifdef HAVE_WINDOW_SYSTEM
19029 else if (IMAGEP (prop
))
19031 it
->what
= IT_IMAGE
;
19032 it
->image_id
= lookup_image (it
->f
, prop
);
19033 it
->method
= GET_FROM_IMAGE
;
19035 #endif /* HAVE_WINDOW_SYSTEM */
19038 pop_it (it
); /* bogus display property, give up */
19045 /* Return the character-property PROP at the current position in IT. */
19048 get_it_property (struct it
*it
, Lisp_Object prop
)
19050 Lisp_Object position
, object
= it
->object
;
19052 if (STRINGP (object
))
19053 position
= make_number (IT_STRING_CHARPOS (*it
));
19054 else if (BUFFERP (object
))
19056 position
= make_number (IT_CHARPOS (*it
));
19057 object
= it
->window
;
19062 return Fget_char_property (position
, prop
, object
);
19065 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19068 handle_line_prefix (struct it
*it
)
19070 Lisp_Object prefix
;
19072 if (it
->continuation_lines_width
> 0)
19074 prefix
= get_it_property (it
, Qwrap_prefix
);
19076 prefix
= Vwrap_prefix
;
19080 prefix
= get_it_property (it
, Qline_prefix
);
19082 prefix
= Vline_prefix
;
19084 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19086 /* If the prefix is wider than the window, and we try to wrap
19087 it, it would acquire its own wrap prefix, and so on till the
19088 iterator stack overflows. So, don't wrap the prefix. */
19089 it
->line_wrap
= TRUNCATE
;
19090 it
->avoid_cursor_p
= 1;
19096 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19097 only for R2L lines from display_line and display_string, when they
19098 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19099 the line/string needs to be continued on the next glyph row. */
19101 unproduce_glyphs (struct it
*it
, int n
)
19103 struct glyph
*glyph
, *end
;
19105 eassert (it
->glyph_row
);
19106 eassert (it
->glyph_row
->reversed_p
);
19107 eassert (it
->area
== TEXT_AREA
);
19108 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19110 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19111 n
= it
->glyph_row
->used
[TEXT_AREA
];
19112 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19113 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19114 for ( ; glyph
< end
; glyph
++)
19115 glyph
[-n
] = *glyph
;
19118 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19119 and ROW->maxpos. */
19121 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19122 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19123 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19125 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19126 lines' rows is implemented for bidi-reordered rows. */
19128 /* ROW->minpos is the value of min_pos, the minimal buffer position
19129 we have in ROW, or ROW->start.pos if that is smaller. */
19130 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19131 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19133 /* We didn't find buffer positions smaller than ROW->start, or
19134 didn't find _any_ valid buffer positions in any of the glyphs,
19135 so we must trust the iterator's computed positions. */
19136 row
->minpos
= row
->start
.pos
;
19139 max_pos
= CHARPOS (it
->current
.pos
);
19140 max_bpos
= BYTEPOS (it
->current
.pos
);
19143 /* Here are the various use-cases for ending the row, and the
19144 corresponding values for ROW->maxpos:
19146 Line ends in a newline from buffer eol_pos + 1
19147 Line is continued from buffer max_pos + 1
19148 Line is truncated on right it->current.pos
19149 Line ends in a newline from string max_pos + 1(*)
19150 (*) + 1 only when line ends in a forward scan
19151 Line is continued from string max_pos
19152 Line is continued from display vector max_pos
19153 Line is entirely from a string min_pos == max_pos
19154 Line is entirely from a display vector min_pos == max_pos
19155 Line that ends at ZV ZV
19157 If you discover other use-cases, please add them here as
19159 if (row
->ends_at_zv_p
)
19160 row
->maxpos
= it
->current
.pos
;
19161 else if (row
->used
[TEXT_AREA
])
19163 int seen_this_string
= 0;
19164 struct glyph_row
*r1
= row
- 1;
19166 /* Did we see the same display string on the previous row? */
19167 if (STRINGP (it
->object
)
19168 /* this is not the first row */
19169 && row
> it
->w
->desired_matrix
->rows
19170 /* previous row is not the header line */
19171 && !r1
->mode_line_p
19172 /* previous row also ends in a newline from a string */
19173 && r1
->ends_in_newline_from_string_p
)
19175 struct glyph
*start
, *end
;
19177 /* Search for the last glyph of the previous row that came
19178 from buffer or string. Depending on whether the row is
19179 L2R or R2L, we need to process it front to back or the
19180 other way round. */
19181 if (!r1
->reversed_p
)
19183 start
= r1
->glyphs
[TEXT_AREA
];
19184 end
= start
+ r1
->used
[TEXT_AREA
];
19185 /* Glyphs inserted by redisplay have an integer (zero)
19186 as their object. */
19188 && INTEGERP ((end
- 1)->object
)
19189 && (end
- 1)->charpos
<= 0)
19193 if (EQ ((end
- 1)->object
, it
->object
))
19194 seen_this_string
= 1;
19197 /* If all the glyphs of the previous row were inserted
19198 by redisplay, it means the previous row was
19199 produced from a single newline, which is only
19200 possible if that newline came from the same string
19201 as the one which produced this ROW. */
19202 seen_this_string
= 1;
19206 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19207 start
= end
+ r1
->used
[TEXT_AREA
];
19209 && INTEGERP ((end
+ 1)->object
)
19210 && (end
+ 1)->charpos
<= 0)
19214 if (EQ ((end
+ 1)->object
, it
->object
))
19215 seen_this_string
= 1;
19218 seen_this_string
= 1;
19221 /* Take note of each display string that covers a newline only
19222 once, the first time we see it. This is for when a display
19223 string includes more than one newline in it. */
19224 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19226 /* If we were scanning the buffer forward when we displayed
19227 the string, we want to account for at least one buffer
19228 position that belongs to this row (position covered by
19229 the display string), so that cursor positioning will
19230 consider this row as a candidate when point is at the end
19231 of the visual line represented by this row. This is not
19232 required when scanning back, because max_pos will already
19233 have a much larger value. */
19234 if (CHARPOS (row
->end
.pos
) > max_pos
)
19235 INC_BOTH (max_pos
, max_bpos
);
19236 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19238 else if (CHARPOS (it
->eol_pos
) > 0)
19239 SET_TEXT_POS (row
->maxpos
,
19240 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19241 else if (row
->continued_p
)
19243 /* If max_pos is different from IT's current position, it
19244 means IT->method does not belong to the display element
19245 at max_pos. However, it also means that the display
19246 element at max_pos was displayed in its entirety on this
19247 line, which is equivalent to saying that the next line
19248 starts at the next buffer position. */
19249 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19250 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19253 INC_BOTH (max_pos
, max_bpos
);
19254 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19257 else if (row
->truncated_on_right_p
)
19258 /* display_line already called reseat_at_next_visible_line_start,
19259 which puts the iterator at the beginning of the next line, in
19260 the logical order. */
19261 row
->maxpos
= it
->current
.pos
;
19262 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19263 /* A line that is entirely from a string/image/stretch... */
19264 row
->maxpos
= row
->minpos
;
19269 row
->maxpos
= it
->current
.pos
;
19272 /* Construct the glyph row IT->glyph_row in the desired matrix of
19273 IT->w from text at the current position of IT. See dispextern.h
19274 for an overview of struct it. Value is non-zero if
19275 IT->glyph_row displays text, as opposed to a line displaying ZV
19279 display_line (struct it
*it
)
19281 struct glyph_row
*row
= it
->glyph_row
;
19282 Lisp_Object overlay_arrow_string
;
19284 void *wrap_data
= NULL
;
19285 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19286 int wrap_row_used
= -1;
19287 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19288 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19289 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19290 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19291 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19293 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19294 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19296 /* We always start displaying at hpos zero even if hscrolled. */
19297 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19299 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19300 >= it
->w
->desired_matrix
->nrows
)
19302 it
->w
->nrows_scale_factor
++;
19303 it
->f
->fonts_changed
= 1;
19307 /* Clear the result glyph row and enable it. */
19308 prepare_desired_row (row
);
19310 row
->y
= it
->current_y
;
19311 row
->start
= it
->start
;
19312 row
->continuation_lines_width
= it
->continuation_lines_width
;
19313 row
->displays_text_p
= 1;
19314 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19315 it
->starts_in_middle_of_char_p
= 0;
19317 /* Arrange the overlays nicely for our purposes. Usually, we call
19318 display_line on only one line at a time, in which case this
19319 can't really hurt too much, or we call it on lines which appear
19320 one after another in the buffer, in which case all calls to
19321 recenter_overlay_lists but the first will be pretty cheap. */
19322 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19324 /* Move over display elements that are not visible because we are
19325 hscrolled. This may stop at an x-position < IT->first_visible_x
19326 if the first glyph is partially visible or if we hit a line end. */
19327 if (it
->current_x
< it
->first_visible_x
)
19329 enum move_it_result move_result
;
19331 this_line_min_pos
= row
->start
.pos
;
19332 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19333 MOVE_TO_POS
| MOVE_TO_X
);
19334 /* If we are under a large hscroll, move_it_in_display_line_to
19335 could hit the end of the line without reaching
19336 it->first_visible_x. Pretend that we did reach it. This is
19337 especially important on a TTY, where we will call
19338 extend_face_to_end_of_line, which needs to know how many
19339 blank glyphs to produce. */
19340 if (it
->current_x
< it
->first_visible_x
19341 && (move_result
== MOVE_NEWLINE_OR_CR
19342 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19343 it
->current_x
= it
->first_visible_x
;
19345 /* Record the smallest positions seen while we moved over
19346 display elements that are not visible. This is needed by
19347 redisplay_internal for optimizing the case where the cursor
19348 stays inside the same line. The rest of this function only
19349 considers positions that are actually displayed, so
19350 RECORD_MAX_MIN_POS will not otherwise record positions that
19351 are hscrolled to the left of the left edge of the window. */
19352 min_pos
= CHARPOS (this_line_min_pos
);
19353 min_bpos
= BYTEPOS (this_line_min_pos
);
19357 /* We only do this when not calling `move_it_in_display_line_to'
19358 above, because move_it_in_display_line_to calls
19359 handle_line_prefix itself. */
19360 handle_line_prefix (it
);
19363 /* Get the initial row height. This is either the height of the
19364 text hscrolled, if there is any, or zero. */
19365 row
->ascent
= it
->max_ascent
;
19366 row
->height
= it
->max_ascent
+ it
->max_descent
;
19367 row
->phys_ascent
= it
->max_phys_ascent
;
19368 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19369 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19371 /* Utility macro to record max and min buffer positions seen until now. */
19372 #define RECORD_MAX_MIN_POS(IT) \
19375 int composition_p = !STRINGP ((IT)->string) \
19376 && ((IT)->what == IT_COMPOSITION); \
19377 ptrdiff_t current_pos = \
19378 composition_p ? (IT)->cmp_it.charpos \
19379 : IT_CHARPOS (*(IT)); \
19380 ptrdiff_t current_bpos = \
19381 composition_p ? CHAR_TO_BYTE (current_pos) \
19382 : IT_BYTEPOS (*(IT)); \
19383 if (current_pos < min_pos) \
19385 min_pos = current_pos; \
19386 min_bpos = current_bpos; \
19388 if (IT_CHARPOS (*it) > max_pos) \
19390 max_pos = IT_CHARPOS (*it); \
19391 max_bpos = IT_BYTEPOS (*it); \
19396 /* Loop generating characters. The loop is left with IT on the next
19397 character to display. */
19400 int n_glyphs_before
, hpos_before
, x_before
;
19402 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19404 /* Retrieve the next thing to display. Value is zero if end of
19406 if (!get_next_display_element (it
))
19408 /* Maybe add a space at the end of this line that is used to
19409 display the cursor there under X. Set the charpos of the
19410 first glyph of blank lines not corresponding to any text
19412 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19413 row
->exact_window_width_line_p
= 1;
19414 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19415 || row
->used
[TEXT_AREA
] == 0)
19417 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19418 row
->displays_text_p
= 0;
19420 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19421 && (!MINI_WINDOW_P (it
->w
)
19422 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19423 row
->indicate_empty_line_p
= 1;
19426 it
->continuation_lines_width
= 0;
19427 row
->ends_at_zv_p
= 1;
19428 /* A row that displays right-to-left text must always have
19429 its last face extended all the way to the end of line,
19430 even if this row ends in ZV, because we still write to
19431 the screen left to right. We also need to extend the
19432 last face if the default face is remapped to some
19433 different face, otherwise the functions that clear
19434 portions of the screen will clear with the default face's
19435 background color. */
19436 if (row
->reversed_p
19437 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19438 extend_face_to_end_of_line (it
);
19442 /* Now, get the metrics of what we want to display. This also
19443 generates glyphs in `row' (which is IT->glyph_row). */
19444 n_glyphs_before
= row
->used
[TEXT_AREA
];
19447 /* Remember the line height so far in case the next element doesn't
19448 fit on the line. */
19449 if (it
->line_wrap
!= TRUNCATE
)
19451 ascent
= it
->max_ascent
;
19452 descent
= it
->max_descent
;
19453 phys_ascent
= it
->max_phys_ascent
;
19454 phys_descent
= it
->max_phys_descent
;
19456 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19458 if (IT_DISPLAYING_WHITESPACE (it
))
19462 SAVE_IT (wrap_it
, *it
, wrap_data
);
19464 wrap_row_used
= row
->used
[TEXT_AREA
];
19465 wrap_row_ascent
= row
->ascent
;
19466 wrap_row_height
= row
->height
;
19467 wrap_row_phys_ascent
= row
->phys_ascent
;
19468 wrap_row_phys_height
= row
->phys_height
;
19469 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19470 wrap_row_min_pos
= min_pos
;
19471 wrap_row_min_bpos
= min_bpos
;
19472 wrap_row_max_pos
= max_pos
;
19473 wrap_row_max_bpos
= max_bpos
;
19479 PRODUCE_GLYPHS (it
);
19481 /* If this display element was in marginal areas, continue with
19483 if (it
->area
!= TEXT_AREA
)
19485 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19486 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19487 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19488 row
->phys_height
= max (row
->phys_height
,
19489 it
->max_phys_ascent
+ it
->max_phys_descent
);
19490 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19491 it
->max_extra_line_spacing
);
19492 set_iterator_to_next (it
, 1);
19496 /* Does the display element fit on the line? If we truncate
19497 lines, we should draw past the right edge of the window. If
19498 we don't truncate, we want to stop so that we can display the
19499 continuation glyph before the right margin. If lines are
19500 continued, there are two possible strategies for characters
19501 resulting in more than 1 glyph (e.g. tabs): Display as many
19502 glyphs as possible in this line and leave the rest for the
19503 continuation line, or display the whole element in the next
19504 line. Original redisplay did the former, so we do it also. */
19505 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19506 hpos_before
= it
->hpos
;
19509 if (/* Not a newline. */
19511 /* Glyphs produced fit entirely in the line. */
19512 && it
->current_x
< it
->last_visible_x
)
19514 it
->hpos
+= nglyphs
;
19515 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19516 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19517 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19518 row
->phys_height
= max (row
->phys_height
,
19519 it
->max_phys_ascent
+ it
->max_phys_descent
);
19520 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19521 it
->max_extra_line_spacing
);
19522 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19523 row
->x
= x
- it
->first_visible_x
;
19524 /* Record the maximum and minimum buffer positions seen so
19525 far in glyphs that will be displayed by this row. */
19527 RECORD_MAX_MIN_POS (it
);
19532 struct glyph
*glyph
;
19534 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19536 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19537 new_x
= x
+ glyph
->pixel_width
;
19539 if (/* Lines are continued. */
19540 it
->line_wrap
!= TRUNCATE
19541 && (/* Glyph doesn't fit on the line. */
19542 new_x
> it
->last_visible_x
19543 /* Or it fits exactly on a window system frame. */
19544 || (new_x
== it
->last_visible_x
19545 && FRAME_WINDOW_P (it
->f
)
19546 && (row
->reversed_p
19547 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19548 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19550 /* End of a continued line. */
19553 || (new_x
== it
->last_visible_x
19554 && FRAME_WINDOW_P (it
->f
)
19555 && (row
->reversed_p
19556 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19557 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19559 /* Current glyph is the only one on the line or
19560 fits exactly on the line. We must continue
19561 the line because we can't draw the cursor
19562 after the glyph. */
19563 row
->continued_p
= 1;
19564 it
->current_x
= new_x
;
19565 it
->continuation_lines_width
+= new_x
;
19567 if (i
== nglyphs
- 1)
19569 /* If line-wrap is on, check if a previous
19570 wrap point was found. */
19571 if (wrap_row_used
> 0
19572 /* Even if there is a previous wrap
19573 point, continue the line here as
19574 usual, if (i) the previous character
19575 was a space or tab AND (ii) the
19576 current character is not. */
19578 || IT_DISPLAYING_WHITESPACE (it
)))
19581 /* Record the maximum and minimum buffer
19582 positions seen so far in glyphs that will be
19583 displayed by this row. */
19585 RECORD_MAX_MIN_POS (it
);
19586 set_iterator_to_next (it
, 1);
19587 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19589 if (!get_next_display_element (it
))
19591 row
->exact_window_width_line_p
= 1;
19592 it
->continuation_lines_width
= 0;
19593 row
->continued_p
= 0;
19594 row
->ends_at_zv_p
= 1;
19596 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19598 row
->continued_p
= 0;
19599 row
->exact_window_width_line_p
= 1;
19603 else if (it
->bidi_p
)
19604 RECORD_MAX_MIN_POS (it
);
19606 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19607 && !FRAME_WINDOW_P (it
->f
))
19609 /* A padding glyph that doesn't fit on this line.
19610 This means the whole character doesn't fit
19612 if (row
->reversed_p
)
19613 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19614 - n_glyphs_before
);
19615 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19617 /* Fill the rest of the row with continuation
19618 glyphs like in 20.x. */
19619 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19620 < row
->glyphs
[1 + TEXT_AREA
])
19621 produce_special_glyphs (it
, IT_CONTINUATION
);
19623 row
->continued_p
= 1;
19624 it
->current_x
= x_before
;
19625 it
->continuation_lines_width
+= x_before
;
19627 /* Restore the height to what it was before the
19628 element not fitting on the line. */
19629 it
->max_ascent
= ascent
;
19630 it
->max_descent
= descent
;
19631 it
->max_phys_ascent
= phys_ascent
;
19632 it
->max_phys_descent
= phys_descent
;
19634 else if (wrap_row_used
> 0)
19637 if (row
->reversed_p
)
19638 unproduce_glyphs (it
,
19639 row
->used
[TEXT_AREA
] - wrap_row_used
);
19640 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19641 it
->continuation_lines_width
+= wrap_x
;
19642 row
->used
[TEXT_AREA
] = wrap_row_used
;
19643 row
->ascent
= wrap_row_ascent
;
19644 row
->height
= wrap_row_height
;
19645 row
->phys_ascent
= wrap_row_phys_ascent
;
19646 row
->phys_height
= wrap_row_phys_height
;
19647 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19648 min_pos
= wrap_row_min_pos
;
19649 min_bpos
= wrap_row_min_bpos
;
19650 max_pos
= wrap_row_max_pos
;
19651 max_bpos
= wrap_row_max_bpos
;
19652 row
->continued_p
= 1;
19653 row
->ends_at_zv_p
= 0;
19654 row
->exact_window_width_line_p
= 0;
19655 it
->continuation_lines_width
+= x
;
19657 /* Make sure that a non-default face is extended
19658 up to the right margin of the window. */
19659 extend_face_to_end_of_line (it
);
19661 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19663 /* A TAB that extends past the right edge of the
19664 window. This produces a single glyph on
19665 window system frames. We leave the glyph in
19666 this row and let it fill the row, but don't
19667 consume the TAB. */
19668 if ((row
->reversed_p
19669 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19670 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19671 produce_special_glyphs (it
, IT_CONTINUATION
);
19672 it
->continuation_lines_width
+= it
->last_visible_x
;
19673 row
->ends_in_middle_of_char_p
= 1;
19674 row
->continued_p
= 1;
19675 glyph
->pixel_width
= it
->last_visible_x
- x
;
19676 it
->starts_in_middle_of_char_p
= 1;
19680 /* Something other than a TAB that draws past
19681 the right edge of the window. Restore
19682 positions to values before the element. */
19683 if (row
->reversed_p
)
19684 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19685 - (n_glyphs_before
+ i
));
19686 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19688 /* Display continuation glyphs. */
19689 it
->current_x
= x_before
;
19690 it
->continuation_lines_width
+= x
;
19691 if (!FRAME_WINDOW_P (it
->f
)
19692 || (row
->reversed_p
19693 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19694 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19695 produce_special_glyphs (it
, IT_CONTINUATION
);
19696 row
->continued_p
= 1;
19698 extend_face_to_end_of_line (it
);
19700 if (nglyphs
> 1 && i
> 0)
19702 row
->ends_in_middle_of_char_p
= 1;
19703 it
->starts_in_middle_of_char_p
= 1;
19706 /* Restore the height to what it was before the
19707 element not fitting on the line. */
19708 it
->max_ascent
= ascent
;
19709 it
->max_descent
= descent
;
19710 it
->max_phys_ascent
= phys_ascent
;
19711 it
->max_phys_descent
= phys_descent
;
19716 else if (new_x
> it
->first_visible_x
)
19718 /* Increment number of glyphs actually displayed. */
19721 /* Record the maximum and minimum buffer positions
19722 seen so far in glyphs that will be displayed by
19725 RECORD_MAX_MIN_POS (it
);
19727 if (x
< it
->first_visible_x
)
19728 /* Glyph is partially visible, i.e. row starts at
19729 negative X position. */
19730 row
->x
= x
- it
->first_visible_x
;
19734 /* Glyph is completely off the left margin of the
19735 window. This should not happen because of the
19736 move_it_in_display_line at the start of this
19737 function, unless the text display area of the
19738 window is empty. */
19739 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19742 /* Even if this display element produced no glyphs at all,
19743 we want to record its position. */
19744 if (it
->bidi_p
&& nglyphs
== 0)
19745 RECORD_MAX_MIN_POS (it
);
19747 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19748 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19749 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19750 row
->phys_height
= max (row
->phys_height
,
19751 it
->max_phys_ascent
+ it
->max_phys_descent
);
19752 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19753 it
->max_extra_line_spacing
);
19755 /* End of this display line if row is continued. */
19756 if (row
->continued_p
|| row
->ends_at_zv_p
)
19761 /* Is this a line end? If yes, we're also done, after making
19762 sure that a non-default face is extended up to the right
19763 margin of the window. */
19764 if (ITERATOR_AT_END_OF_LINE_P (it
))
19766 int used_before
= row
->used
[TEXT_AREA
];
19768 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19770 /* Add a space at the end of the line that is used to
19771 display the cursor there. */
19772 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19773 append_space_for_newline (it
, 0);
19775 /* Extend the face to the end of the line. */
19776 extend_face_to_end_of_line (it
);
19778 /* Make sure we have the position. */
19779 if (used_before
== 0)
19780 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19782 /* Record the position of the newline, for use in
19784 it
->eol_pos
= it
->current
.pos
;
19786 /* Consume the line end. This skips over invisible lines. */
19787 set_iterator_to_next (it
, 1);
19788 it
->continuation_lines_width
= 0;
19792 /* Proceed with next display element. Note that this skips
19793 over lines invisible because of selective display. */
19794 set_iterator_to_next (it
, 1);
19796 /* If we truncate lines, we are done when the last displayed
19797 glyphs reach past the right margin of the window. */
19798 if (it
->line_wrap
== TRUNCATE
19799 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19800 ? (it
->current_x
>= it
->last_visible_x
)
19801 : (it
->current_x
> it
->last_visible_x
)))
19803 /* Maybe add truncation glyphs. */
19804 if (!FRAME_WINDOW_P (it
->f
)
19805 || (row
->reversed_p
19806 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19807 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19811 if (!row
->reversed_p
)
19813 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19814 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19819 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19820 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19822 /* Remove any padding glyphs at the front of ROW, to
19823 make room for the truncation glyphs we will be
19824 adding below. The loop below always inserts at
19825 least one truncation glyph, so also remove the
19826 last glyph added to ROW. */
19827 unproduce_glyphs (it
, i
+ 1);
19828 /* Adjust i for the loop below. */
19829 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19832 it
->current_x
= x_before
;
19833 if (!FRAME_WINDOW_P (it
->f
))
19835 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19837 row
->used
[TEXT_AREA
] = i
;
19838 produce_special_glyphs (it
, IT_TRUNCATION
);
19843 row
->used
[TEXT_AREA
] = i
;
19844 produce_special_glyphs (it
, IT_TRUNCATION
);
19847 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19849 /* Don't truncate if we can overflow newline into fringe. */
19850 if (!get_next_display_element (it
))
19852 it
->continuation_lines_width
= 0;
19853 row
->ends_at_zv_p
= 1;
19854 row
->exact_window_width_line_p
= 1;
19857 if (ITERATOR_AT_END_OF_LINE_P (it
))
19859 row
->exact_window_width_line_p
= 1;
19860 goto at_end_of_line
;
19862 it
->current_x
= x_before
;
19865 row
->truncated_on_right_p
= 1;
19866 it
->continuation_lines_width
= 0;
19867 reseat_at_next_visible_line_start (it
, 0);
19868 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19869 it
->hpos
= hpos_before
;
19875 bidi_unshelve_cache (wrap_data
, 1);
19877 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19878 at the left window margin. */
19879 if (it
->first_visible_x
19880 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19882 if (!FRAME_WINDOW_P (it
->f
)
19883 || (row
->reversed_p
19884 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19885 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19886 insert_left_trunc_glyphs (it
);
19887 row
->truncated_on_left_p
= 1;
19890 /* Remember the position at which this line ends.
19892 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19893 cannot be before the call to find_row_edges below, since that is
19894 where these positions are determined. */
19895 row
->end
= it
->current
;
19898 row
->minpos
= row
->start
.pos
;
19899 row
->maxpos
= row
->end
.pos
;
19903 /* ROW->minpos and ROW->maxpos must be the smallest and
19904 `1 + the largest' buffer positions in ROW. But if ROW was
19905 bidi-reordered, these two positions can be anywhere in the
19906 row, so we must determine them now. */
19907 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19910 /* If the start of this line is the overlay arrow-position, then
19911 mark this glyph row as the one containing the overlay arrow.
19912 This is clearly a mess with variable size fonts. It would be
19913 better to let it be displayed like cursors under X. */
19914 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19915 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19916 !NILP (overlay_arrow_string
)))
19918 /* Overlay arrow in window redisplay is a fringe bitmap. */
19919 if (STRINGP (overlay_arrow_string
))
19921 struct glyph_row
*arrow_row
19922 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19923 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19924 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19925 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19926 struct glyph
*p2
, *end
;
19928 /* Copy the arrow glyphs. */
19929 while (glyph
< arrow_end
)
19932 /* Throw away padding glyphs. */
19934 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19935 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19941 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19946 eassert (INTEGERP (overlay_arrow_string
));
19947 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19949 overlay_arrow_seen
= 1;
19952 /* Highlight trailing whitespace. */
19953 if (!NILP (Vshow_trailing_whitespace
))
19954 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19956 /* Compute pixel dimensions of this line. */
19957 compute_line_metrics (it
);
19959 /* Implementation note: No changes in the glyphs of ROW or in their
19960 faces can be done past this point, because compute_line_metrics
19961 computes ROW's hash value and stores it within the glyph_row
19964 /* Record whether this row ends inside an ellipsis. */
19965 row
->ends_in_ellipsis_p
19966 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19967 && it
->ellipsis_p
);
19969 /* Save fringe bitmaps in this row. */
19970 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19971 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19972 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19973 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19975 it
->left_user_fringe_bitmap
= 0;
19976 it
->left_user_fringe_face_id
= 0;
19977 it
->right_user_fringe_bitmap
= 0;
19978 it
->right_user_fringe_face_id
= 0;
19980 /* Maybe set the cursor. */
19981 cvpos
= it
->w
->cursor
.vpos
;
19983 /* In bidi-reordered rows, keep checking for proper cursor
19984 position even if one has been found already, because buffer
19985 positions in such rows change non-linearly with ROW->VPOS,
19986 when a line is continued. One exception: when we are at ZV,
19987 display cursor on the first suitable glyph row, since all
19988 the empty rows after that also have their position set to ZV. */
19989 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19990 lines' rows is implemented for bidi-reordered rows. */
19992 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19993 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19994 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19995 && cursor_row_p (row
))
19996 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19998 /* Prepare for the next line. This line starts horizontally at (X
19999 HPOS) = (0 0). Vertical positions are incremented. As a
20000 convenience for the caller, IT->glyph_row is set to the next
20002 it
->current_x
= it
->hpos
= 0;
20003 it
->current_y
+= row
->height
;
20004 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20007 /* The next row should by default use the same value of the
20008 reversed_p flag as this one. set_iterator_to_next decides when
20009 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20010 the flag accordingly. */
20011 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20012 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20013 it
->start
= row
->end
;
20014 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20016 #undef RECORD_MAX_MIN_POS
20019 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20020 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20021 doc
: /* Return paragraph direction at point in BUFFER.
20022 Value is either `left-to-right' or `right-to-left'.
20023 If BUFFER is omitted or nil, it defaults to the current buffer.
20025 Paragraph direction determines how the text in the paragraph is displayed.
20026 In left-to-right paragraphs, text begins at the left margin of the window
20027 and the reading direction is generally left to right. In right-to-left
20028 paragraphs, text begins at the right margin and is read from right to left.
20030 See also `bidi-paragraph-direction'. */)
20031 (Lisp_Object buffer
)
20033 struct buffer
*buf
= current_buffer
;
20034 struct buffer
*old
= buf
;
20036 if (! NILP (buffer
))
20038 CHECK_BUFFER (buffer
);
20039 buf
= XBUFFER (buffer
);
20042 if (NILP (BVAR (buf
, bidi_display_reordering
))
20043 || NILP (BVAR (buf
, enable_multibyte_characters
))
20044 /* When we are loading loadup.el, the character property tables
20045 needed for bidi iteration are not yet available. */
20046 || !NILP (Vpurify_flag
))
20047 return Qleft_to_right
;
20048 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20049 return BVAR (buf
, bidi_paragraph_direction
);
20052 /* Determine the direction from buffer text. We could try to
20053 use current_matrix if it is up to date, but this seems fast
20054 enough as it is. */
20055 struct bidi_it itb
;
20056 ptrdiff_t pos
= BUF_PT (buf
);
20057 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20059 void *itb_data
= bidi_shelve_cache ();
20061 set_buffer_temp (buf
);
20062 /* bidi_paragraph_init finds the base direction of the paragraph
20063 by searching forward from paragraph start. We need the base
20064 direction of the current or _previous_ paragraph, so we need
20065 to make sure we are within that paragraph. To that end, find
20066 the previous non-empty line. */
20067 if (pos
>= ZV
&& pos
> BEGV
)
20068 DEC_BOTH (pos
, bytepos
);
20069 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20070 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20072 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20073 || c
== ' ' || c
== '\t' || c
== '\f')
20075 if (bytepos
<= BEGV_BYTE
)
20080 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20083 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20084 itb
.paragraph_dir
= NEUTRAL_DIR
;
20085 itb
.string
.s
= NULL
;
20086 itb
.string
.lstring
= Qnil
;
20087 itb
.string
.bufpos
= 0;
20088 itb
.string
.unibyte
= 0;
20089 /* We have no window to use here for ignoring window-specific
20090 overlays. Using NULL for window pointer will cause
20091 compute_display_string_pos to use the current buffer. */
20093 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20094 bidi_unshelve_cache (itb_data
, 0);
20095 set_buffer_temp (old
);
20096 switch (itb
.paragraph_dir
)
20099 return Qleft_to_right
;
20102 return Qright_to_left
;
20110 DEFUN ("move-point-visually", Fmove_point_visually
,
20111 Smove_point_visually
, 1, 1, 0,
20112 doc
: /* Move point in the visual order in the specified DIRECTION.
20113 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20116 Value is the new character position of point. */)
20117 (Lisp_Object direction
)
20119 struct window
*w
= XWINDOW (selected_window
);
20120 struct buffer
*b
= XBUFFER (w
->contents
);
20121 struct glyph_row
*row
;
20123 Lisp_Object paragraph_dir
;
20125 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20126 (!(ROW)->continued_p \
20127 && INTEGERP ((GLYPH)->object) \
20128 && (GLYPH)->type == CHAR_GLYPH \
20129 && (GLYPH)->u.ch == ' ' \
20130 && (GLYPH)->charpos >= 0 \
20131 && !(GLYPH)->avoid_cursor_p)
20133 CHECK_NUMBER (direction
);
20134 dir
= XINT (direction
);
20140 /* If current matrix is up-to-date, we can use the information
20141 recorded in the glyphs, at least as long as the goal is on the
20143 if (w
->window_end_valid
20144 && !windows_or_buffers_changed
20146 && !b
->clip_changed
20147 && !b
->prevent_redisplay_optimizations_p
20148 && !window_outdated (w
)
20149 && w
->cursor
.vpos
>= 0
20150 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20151 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20153 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20154 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20155 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20157 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20159 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20161 SET_PT (g
->charpos
);
20162 w
->cursor
.vpos
= -1;
20163 return make_number (PT
);
20165 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20169 if (BUFFERP (gpt
->object
))
20172 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20173 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20175 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20177 else if (BUFFERP (g
->object
))
20178 new_pos
= g
->charpos
;
20182 w
->cursor
.vpos
= -1;
20183 return make_number (PT
);
20185 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20187 /* Glyphs inserted at the end of a non-empty line for
20188 positioning the cursor have zero charpos, so we must
20189 deduce the value of point by other means. */
20190 if (g
->charpos
> 0)
20191 SET_PT (g
->charpos
);
20192 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20194 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20195 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20198 w
->cursor
.vpos
= -1;
20199 return make_number (PT
);
20202 if (g
== e
|| INTEGERP (g
->object
))
20204 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20205 goto simulate_display
;
20206 if (!row
->reversed_p
)
20210 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20211 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20212 goto simulate_display
;
20216 if (row
->reversed_p
&& !row
->continued_p
)
20218 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20219 w
->cursor
.vpos
= -1;
20220 return make_number (PT
);
20222 g
= row
->glyphs
[TEXT_AREA
];
20223 e
= g
+ row
->used
[TEXT_AREA
];
20224 for ( ; g
< e
; g
++)
20226 if (BUFFERP (g
->object
)
20227 /* Empty lines have only one glyph, which stands
20228 for the newline, and whose charpos is the
20229 buffer position of the newline. */
20230 || ROW_GLYPH_NEWLINE_P (row
, g
)
20231 /* When the buffer ends in a newline, the line at
20232 EOB also has one glyph, but its charpos is -1. */
20233 || (row
->ends_at_zv_p
20234 && !row
->reversed_p
20235 && INTEGERP (g
->object
)
20236 && g
->type
== CHAR_GLYPH
20237 && g
->u
.ch
== ' '))
20239 if (g
->charpos
> 0)
20240 SET_PT (g
->charpos
);
20241 else if (!row
->reversed_p
20242 && row
->ends_at_zv_p
20247 w
->cursor
.vpos
= -1;
20248 return make_number (PT
);
20254 if (!row
->reversed_p
&& !row
->continued_p
)
20256 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20257 w
->cursor
.vpos
= -1;
20258 return make_number (PT
);
20260 e
= row
->glyphs
[TEXT_AREA
];
20261 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20262 for ( ; g
>= e
; g
--)
20264 if (BUFFERP (g
->object
)
20265 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20267 /* Empty R2L lines on GUI frames have the buffer
20268 position of the newline stored in the stretch
20270 || g
->type
== STRETCH_GLYPH
20271 || (row
->ends_at_zv_p
20273 && INTEGERP (g
->object
)
20274 && g
->type
== CHAR_GLYPH
20275 && g
->u
.ch
== ' '))
20277 if (g
->charpos
> 0)
20278 SET_PT (g
->charpos
);
20279 else if (row
->reversed_p
20280 && row
->ends_at_zv_p
20285 w
->cursor
.vpos
= -1;
20286 return make_number (PT
);
20295 /* If we wind up here, we failed to move by using the glyphs, so we
20296 need to simulate display instead. */
20299 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20301 paragraph_dir
= Qleft_to_right
;
20302 if (EQ (paragraph_dir
, Qright_to_left
))
20304 if (PT
<= BEGV
&& dir
< 0)
20305 xsignal0 (Qbeginning_of_buffer
);
20306 else if (PT
>= ZV
&& dir
> 0)
20307 xsignal0 (Qend_of_buffer
);
20310 struct text_pos pt
;
20312 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20314 bool overshoot_expected
= false;
20315 bool target_is_eol_p
= false;
20317 /* Setup the arena. */
20318 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20319 start_display (&it
, w
, pt
);
20321 if (it
.cmp_it
.id
< 0
20322 && it
.method
== GET_FROM_STRING
20323 && it
.area
== TEXT_AREA
20324 && it
.string_from_display_prop_p
20325 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20326 overshoot_expected
= true;
20328 /* Find the X coordinate of point. We start from the beginning
20329 of this or previous line to make sure we are before point in
20330 the logical order (since the move_it_* functions can only
20332 reseat_at_previous_visible_line_start (&it
);
20333 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20334 if (IT_CHARPOS (it
) != PT
)
20335 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20336 -1, -1, -1, MOVE_TO_POS
);
20337 pt_x
= it
.current_x
;
20339 if (dir
> 0 || overshoot_expected
)
20341 struct glyph_row
*row
= it
.glyph_row
;
20343 /* When point is at beginning of line, we don't have
20344 information about the glyph there loaded into struct
20345 it. Calling get_next_display_element fixes that. */
20347 get_next_display_element (&it
);
20348 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20349 it
.glyph_row
= NULL
;
20350 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20351 it
.glyph_row
= row
;
20352 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20353 it, lest it will become out of sync with it's buffer
20355 it
.current_x
= pt_x
;
20358 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20359 pixel_width
= it
.pixel_width
;
20360 if (overshoot_expected
&& at_eol_p
)
20362 else if (pixel_width
<= 0)
20365 /* If there's a display string at point, we are actually at the
20366 glyph to the left of point, so we need to correct the X
20368 if (overshoot_expected
)
20369 pt_x
+= pixel_width
;
20371 /* Compute target X coordinate, either to the left or to the
20372 right of point. On TTY frames, all characters have the same
20373 pixel width of 1, so we can use that. On GUI frames we don't
20374 have an easy way of getting at the pixel width of the
20375 character to the left of point, so we use a different method
20376 of getting to that place. */
20378 target_x
= pt_x
+ pixel_width
;
20380 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20382 /* Target X coordinate could be one line above or below the line
20383 of point, in which case we need to adjust the target X
20384 coordinate. Also, if moving to the left, we need to begin at
20385 the left edge of the point's screen line. */
20390 start_display (&it
, w
, pt
);
20391 reseat_at_previous_visible_line_start (&it
);
20392 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20394 move_it_by_lines (&it
, pt_vpos
);
20398 move_it_by_lines (&it
, -1);
20399 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20400 target_is_eol_p
= true;
20406 || (target_x
>= it
.last_visible_x
20407 && it
.line_wrap
!= TRUNCATE
))
20410 move_it_by_lines (&it
, 0);
20411 move_it_by_lines (&it
, 1);
20416 /* Move to the target X coordinate. */
20417 #ifdef HAVE_WINDOW_SYSTEM
20418 /* On GUI frames, as we don't know the X coordinate of the
20419 character to the left of point, moving point to the left
20420 requires walking, one grapheme cluster at a time, until we
20421 find ourself at a place immediately to the left of the
20422 character at point. */
20423 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20425 struct text_pos new_pos
= it
.current
.pos
;
20426 enum move_it_result rc
= MOVE_X_REACHED
;
20428 while (it
.current_x
+ it
.pixel_width
<= target_x
20429 && rc
== MOVE_X_REACHED
)
20431 int new_x
= it
.current_x
+ it
.pixel_width
;
20433 new_pos
= it
.current
.pos
;
20434 if (new_x
== it
.current_x
)
20436 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20437 MOVE_TO_POS
| MOVE_TO_X
);
20438 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20441 /* If we ended up on a composed character inside
20442 bidi-reordered text (e.g., Hebrew text with diacritics),
20443 the iterator gives us the buffer position of the last (in
20444 logical order) character of the composed grapheme cluster,
20445 which is not what we want. So we cheat: we compute the
20446 character position of the character that follows (in the
20447 logical order) the one where the above loop stopped. That
20448 character will appear on display to the left of point. */
20450 && it
.bidi_it
.scan_dir
== -1
20451 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20453 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20454 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20456 it
.current
.pos
= new_pos
;
20460 if (it
.current_x
!= target_x
)
20461 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20463 /* When lines are truncated, the above loop will stop at the
20464 window edge. But we want to get to the end of line, even if
20465 it is beyond the window edge; automatic hscroll will then
20466 scroll the window to show point as appropriate. */
20467 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20468 && get_next_display_element (&it
))
20470 struct text_pos new_pos
= it
.current
.pos
;
20472 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20474 set_iterator_to_next (&it
, 0);
20475 if (it
.method
== GET_FROM_BUFFER
)
20476 new_pos
= it
.current
.pos
;
20477 if (!get_next_display_element (&it
))
20481 it
.current
.pos
= new_pos
;
20484 /* If we ended up in a display string that covers point, move to
20485 buffer position to the right in the visual order. */
20488 while (IT_CHARPOS (it
) == PT
)
20490 set_iterator_to_next (&it
, 0);
20491 if (!get_next_display_element (&it
))
20496 /* Move point to that position. */
20497 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20500 return make_number (PT
);
20502 #undef ROW_GLYPH_NEWLINE_P
20506 /***********************************************************************
20508 ***********************************************************************/
20510 /* Redisplay the menu bar in the frame for window W.
20512 The menu bar of X frames that don't have X toolkit support is
20513 displayed in a special window W->frame->menu_bar_window.
20515 The menu bar of terminal frames is treated specially as far as
20516 glyph matrices are concerned. Menu bar lines are not part of
20517 windows, so the update is done directly on the frame matrix rows
20518 for the menu bar. */
20521 display_menu_bar (struct window
*w
)
20523 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20528 /* Don't do all this for graphical frames. */
20530 if (FRAME_W32_P (f
))
20533 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20539 if (FRAME_NS_P (f
))
20541 #endif /* HAVE_NS */
20543 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20544 eassert (!FRAME_WINDOW_P (f
));
20545 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20546 it
.first_visible_x
= 0;
20547 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20548 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20549 if (FRAME_WINDOW_P (f
))
20551 /* Menu bar lines are displayed in the desired matrix of the
20552 dummy window menu_bar_window. */
20553 struct window
*menu_w
;
20554 menu_w
= XWINDOW (f
->menu_bar_window
);
20555 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20557 it
.first_visible_x
= 0;
20558 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20561 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20563 /* This is a TTY frame, i.e. character hpos/vpos are used as
20565 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20567 it
.first_visible_x
= 0;
20568 it
.last_visible_x
= FRAME_COLS (f
);
20571 /* FIXME: This should be controlled by a user option. See the
20572 comments in redisplay_tool_bar and display_mode_line about
20574 it
.paragraph_embedding
= L2R
;
20576 /* Clear all rows of the menu bar. */
20577 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20579 struct glyph_row
*row
= it
.glyph_row
+ i
;
20580 clear_glyph_row (row
);
20581 row
->enabled_p
= 1;
20582 row
->full_width_p
= 1;
20585 /* Display all items of the menu bar. */
20586 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20587 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20589 Lisp_Object string
;
20591 /* Stop at nil string. */
20592 string
= AREF (items
, i
+ 1);
20596 /* Remember where item was displayed. */
20597 ASET (items
, i
+ 3, make_number (it
.hpos
));
20599 /* Display the item, pad with one space. */
20600 if (it
.current_x
< it
.last_visible_x
)
20601 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20602 SCHARS (string
) + 1, 0, 0, -1);
20605 /* Fill out the line with spaces. */
20606 if (it
.current_x
< it
.last_visible_x
)
20607 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20609 /* Compute the total height of the lines. */
20610 compute_line_metrics (&it
);
20613 /* Deep copy of a glyph row, including the glyphs. */
20615 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20617 struct glyph
*pointers
[1 + LAST_AREA
];
20618 int to_used
= to
->used
[TEXT_AREA
];
20620 /* Save glyph pointers of TO. */
20621 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20623 /* Do a structure assignment. */
20626 /* Restore original glyph pointers of TO. */
20627 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20629 /* Copy the glyphs. */
20630 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20631 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20633 /* If we filled only part of the TO row, fill the rest with
20634 space_glyph (which will display as empty space). */
20635 if (to_used
> from
->used
[TEXT_AREA
])
20636 fill_up_frame_row_with_spaces (to
, to_used
);
20639 /* Display one menu item on a TTY, by overwriting the glyphs in the
20640 frame F's desired glyph matrix with glyphs produced from the menu
20641 item text. Called from term.c to display TTY drop-down menus one
20644 ITEM_TEXT is the menu item text as a C string.
20646 FACE_ID is the face ID to be used for this menu item. FACE_ID
20647 could specify one of 3 faces: a face for an enabled item, a face
20648 for a disabled item, or a face for a selected item.
20650 X and Y are coordinates of the first glyph in the frame's desired
20651 matrix to be overwritten by the menu item. Since this is a TTY, Y
20652 is the zero-based number of the glyph row and X is the zero-based
20653 glyph number in the row, starting from left, where to start
20654 displaying the item.
20656 SUBMENU non-zero means this menu item drops down a submenu, which
20657 should be indicated by displaying a proper visual cue after the
20661 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20662 int x
, int y
, int submenu
)
20665 struct frame
*f
= SELECTED_FRAME ();
20666 struct window
*w
= XWINDOW (f
->selected_window
);
20667 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20668 struct glyph_row
*row
;
20669 size_t item_len
= strlen (item_text
);
20671 eassert (FRAME_TERMCAP_P (f
));
20673 /* Don't write beyond the matrix's last row. This can happen for
20674 TTY screens that are not high enough to show the entire menu.
20675 (This is actually a bit of defensive programming, as
20676 tty_menu_display already limits the number of menu items to one
20677 less than the number of screen lines.) */
20678 if (y
>= f
->desired_matrix
->nrows
)
20681 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20682 it
.first_visible_x
= 0;
20683 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20684 row
= it
.glyph_row
;
20685 /* Start with the row contents from the current matrix. */
20686 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20687 saved_width
= row
->full_width_p
;
20688 row
->full_width_p
= 1;
20689 saved_reversed
= row
->reversed_p
;
20690 row
->reversed_p
= 0;
20691 row
->enabled_p
= 1;
20693 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20695 eassert (x
< f
->desired_matrix
->matrix_w
);
20696 it
.current_x
= it
.hpos
= x
;
20697 it
.current_y
= it
.vpos
= y
;
20698 saved_used
= row
->used
[TEXT_AREA
];
20699 saved_truncated
= row
->truncated_on_right_p
;
20700 row
->used
[TEXT_AREA
] = x
;
20701 it
.face_id
= face_id
;
20702 it
.line_wrap
= TRUNCATE
;
20704 /* FIXME: This should be controlled by a user option. See the
20705 comments in redisplay_tool_bar and display_mode_line about this.
20706 Also, if paragraph_embedding could ever be R2L, changes will be
20707 needed to avoid shifting to the right the row characters in
20708 term.c:append_glyph. */
20709 it
.paragraph_embedding
= L2R
;
20711 /* Pad with a space on the left. */
20712 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20714 /* Display the menu item, pad with spaces to WIDTH. */
20717 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20718 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20720 /* Indicate with " >" that there's a submenu. */
20721 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20722 FRAME_COLS (f
) - 1, -1);
20725 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20726 width
, 0, FRAME_COLS (f
) - 1, -1);
20728 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20729 row
->truncated_on_right_p
= saved_truncated
;
20730 row
->hash
= row_hash (row
);
20731 row
->full_width_p
= saved_width
;
20732 row
->reversed_p
= saved_reversed
;
20735 /***********************************************************************
20737 ***********************************************************************/
20739 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20740 FORCE is non-zero, redisplay mode lines unconditionally.
20741 Otherwise, redisplay only mode lines that are garbaged. Value is
20742 the number of windows whose mode lines were redisplayed. */
20745 redisplay_mode_lines (Lisp_Object window
, bool force
)
20749 while (!NILP (window
))
20751 struct window
*w
= XWINDOW (window
);
20753 if (WINDOWP (w
->contents
))
20754 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20756 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20757 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20759 struct text_pos lpoint
;
20760 struct buffer
*old
= current_buffer
;
20762 /* Set the window's buffer for the mode line display. */
20763 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20764 set_buffer_internal_1 (XBUFFER (w
->contents
));
20766 /* Point refers normally to the selected window. For any
20767 other window, set up appropriate value. */
20768 if (!EQ (window
, selected_window
))
20770 struct text_pos pt
;
20772 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20773 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20776 /* Display mode lines. */
20777 clear_glyph_matrix (w
->desired_matrix
);
20778 if (display_mode_lines (w
))
20781 /* Restore old settings. */
20782 set_buffer_internal_1 (old
);
20783 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20793 /* Display the mode and/or header line of window W. Value is the
20794 sum number of mode lines and header lines displayed. */
20797 display_mode_lines (struct window
*w
)
20799 Lisp_Object old_selected_window
= selected_window
;
20800 Lisp_Object old_selected_frame
= selected_frame
;
20801 Lisp_Object new_frame
= w
->frame
;
20802 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20805 selected_frame
= new_frame
;
20806 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20807 or window's point, then we'd need select_window_1 here as well. */
20808 XSETWINDOW (selected_window
, w
);
20809 XFRAME (new_frame
)->selected_window
= selected_window
;
20811 /* These will be set while the mode line specs are processed. */
20812 line_number_displayed
= 0;
20813 w
->column_number_displayed
= -1;
20815 if (WINDOW_WANTS_MODELINE_P (w
))
20817 struct window
*sel_w
= XWINDOW (old_selected_window
);
20819 /* Select mode line face based on the real selected window. */
20820 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20821 BVAR (current_buffer
, mode_line_format
));
20825 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20827 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20828 BVAR (current_buffer
, header_line_format
));
20832 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20833 selected_frame
= old_selected_frame
;
20834 selected_window
= old_selected_window
;
20836 w
->must_be_updated_p
= true;
20841 /* Display mode or header line of window W. FACE_ID specifies which
20842 line to display; it is either MODE_LINE_FACE_ID or
20843 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20844 display. Value is the pixel height of the mode/header line
20848 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20852 ptrdiff_t count
= SPECPDL_INDEX ();
20854 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20855 /* Don't extend on a previously drawn mode-line.
20856 This may happen if called from pos_visible_p. */
20857 it
.glyph_row
->enabled_p
= 0;
20858 prepare_desired_row (it
.glyph_row
);
20860 it
.glyph_row
->mode_line_p
= 1;
20862 /* FIXME: This should be controlled by a user option. But
20863 supporting such an option is not trivial, since the mode line is
20864 made up of many separate strings. */
20865 it
.paragraph_embedding
= L2R
;
20867 record_unwind_protect (unwind_format_mode_line
,
20868 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20870 mode_line_target
= MODE_LINE_DISPLAY
;
20872 /* Temporarily make frame's keyboard the current kboard so that
20873 kboard-local variables in the mode_line_format will get the right
20875 push_kboard (FRAME_KBOARD (it
.f
));
20876 record_unwind_save_match_data ();
20877 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20880 unbind_to (count
, Qnil
);
20882 /* Fill up with spaces. */
20883 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20885 compute_line_metrics (&it
);
20886 it
.glyph_row
->full_width_p
= 1;
20887 it
.glyph_row
->continued_p
= 0;
20888 it
.glyph_row
->truncated_on_left_p
= 0;
20889 it
.glyph_row
->truncated_on_right_p
= 0;
20891 /* Make a 3D mode-line have a shadow at its right end. */
20892 face
= FACE_FROM_ID (it
.f
, face_id
);
20893 extend_face_to_end_of_line (&it
);
20894 if (face
->box
!= FACE_NO_BOX
)
20896 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20897 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20898 last
->right_box_line_p
= 1;
20901 return it
.glyph_row
->height
;
20904 /* Move element ELT in LIST to the front of LIST.
20905 Return the updated list. */
20908 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20910 register Lisp_Object tail
, prev
;
20911 register Lisp_Object tem
;
20915 while (CONSP (tail
))
20921 /* Splice out the link TAIL. */
20923 list
= XCDR (tail
);
20925 Fsetcdr (prev
, XCDR (tail
));
20927 /* Now make it the first. */
20928 Fsetcdr (tail
, list
);
20933 tail
= XCDR (tail
);
20937 /* Not found--return unchanged LIST. */
20941 /* Contribute ELT to the mode line for window IT->w. How it
20942 translates into text depends on its data type.
20944 IT describes the display environment in which we display, as usual.
20946 DEPTH is the depth in recursion. It is used to prevent
20947 infinite recursion here.
20949 FIELD_WIDTH is the number of characters the display of ELT should
20950 occupy in the mode line, and PRECISION is the maximum number of
20951 characters to display from ELT's representation. See
20952 display_string for details.
20954 Returns the hpos of the end of the text generated by ELT.
20956 PROPS is a property list to add to any string we encounter.
20958 If RISKY is nonzero, remove (disregard) any properties in any string
20959 we encounter, and ignore :eval and :propertize.
20961 The global variable `mode_line_target' determines whether the
20962 output is passed to `store_mode_line_noprop',
20963 `store_mode_line_string', or `display_string'. */
20966 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20967 Lisp_Object elt
, Lisp_Object props
, int risky
)
20969 int n
= 0, field
, prec
;
20974 elt
= build_string ("*too-deep*");
20978 switch (XTYPE (elt
))
20982 /* A string: output it and check for %-constructs within it. */
20984 ptrdiff_t offset
= 0;
20986 if (SCHARS (elt
) > 0
20987 && (!NILP (props
) || risky
))
20989 Lisp_Object oprops
, aelt
;
20990 oprops
= Ftext_properties_at (make_number (0), elt
);
20992 /* If the starting string's properties are not what
20993 we want, translate the string. Also, if the string
20994 is risky, do that anyway. */
20996 if (NILP (Fequal (props
, oprops
)) || risky
)
20998 /* If the starting string has properties,
20999 merge the specified ones onto the existing ones. */
21000 if (! NILP (oprops
) && !risky
)
21004 oprops
= Fcopy_sequence (oprops
);
21006 while (CONSP (tem
))
21008 oprops
= Fplist_put (oprops
, XCAR (tem
),
21009 XCAR (XCDR (tem
)));
21010 tem
= XCDR (XCDR (tem
));
21015 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21016 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21018 /* AELT is what we want. Move it to the front
21019 without consing. */
21021 mode_line_proptrans_alist
21022 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21028 /* If AELT has the wrong props, it is useless.
21029 so get rid of it. */
21031 mode_line_proptrans_alist
21032 = Fdelq (aelt
, mode_line_proptrans_alist
);
21034 elt
= Fcopy_sequence (elt
);
21035 Fset_text_properties (make_number (0), Flength (elt
),
21037 /* Add this item to mode_line_proptrans_alist. */
21038 mode_line_proptrans_alist
21039 = Fcons (Fcons (elt
, props
),
21040 mode_line_proptrans_alist
);
21041 /* Truncate mode_line_proptrans_alist
21042 to at most 50 elements. */
21043 tem
= Fnthcdr (make_number (50),
21044 mode_line_proptrans_alist
);
21046 XSETCDR (tem
, Qnil
);
21055 prec
= precision
- n
;
21056 switch (mode_line_target
)
21058 case MODE_LINE_NOPROP
:
21059 case MODE_LINE_TITLE
:
21060 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21062 case MODE_LINE_STRING
:
21063 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21065 case MODE_LINE_DISPLAY
:
21066 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21067 0, prec
, 0, STRING_MULTIBYTE (elt
));
21074 /* Handle the non-literal case. */
21076 while ((precision
<= 0 || n
< precision
)
21077 && SREF (elt
, offset
) != 0
21078 && (mode_line_target
!= MODE_LINE_DISPLAY
21079 || it
->current_x
< it
->last_visible_x
))
21081 ptrdiff_t last_offset
= offset
;
21083 /* Advance to end of string or next format specifier. */
21084 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21087 if (offset
- 1 != last_offset
)
21089 ptrdiff_t nchars
, nbytes
;
21091 /* Output to end of string or up to '%'. Field width
21092 is length of string. Don't output more than
21093 PRECISION allows us. */
21096 prec
= c_string_width (SDATA (elt
) + last_offset
,
21097 offset
- last_offset
, precision
- n
,
21100 switch (mode_line_target
)
21102 case MODE_LINE_NOPROP
:
21103 case MODE_LINE_TITLE
:
21104 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21106 case MODE_LINE_STRING
:
21108 ptrdiff_t bytepos
= last_offset
;
21109 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21110 ptrdiff_t endpos
= (precision
<= 0
21111 ? string_byte_to_char (elt
, offset
)
21112 : charpos
+ nchars
);
21114 n
+= store_mode_line_string (NULL
,
21115 Fsubstring (elt
, make_number (charpos
),
21116 make_number (endpos
)),
21120 case MODE_LINE_DISPLAY
:
21122 ptrdiff_t bytepos
= last_offset
;
21123 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21125 if (precision
<= 0)
21126 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21127 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21129 STRING_MULTIBYTE (elt
));
21134 else /* c == '%' */
21136 ptrdiff_t percent_position
= offset
;
21138 /* Get the specified minimum width. Zero means
21141 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21142 field
= field
* 10 + c
- '0';
21144 /* Don't pad beyond the total padding allowed. */
21145 if (field_width
- n
> 0 && field
> field_width
- n
)
21146 field
= field_width
- n
;
21148 /* Note that either PRECISION <= 0 or N < PRECISION. */
21149 prec
= precision
- n
;
21152 n
+= display_mode_element (it
, depth
, field
, prec
,
21153 Vglobal_mode_string
, props
,
21158 ptrdiff_t bytepos
, charpos
;
21160 Lisp_Object string
;
21162 bytepos
= percent_position
;
21163 charpos
= (STRING_MULTIBYTE (elt
)
21164 ? string_byte_to_char (elt
, bytepos
)
21166 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21167 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21169 switch (mode_line_target
)
21171 case MODE_LINE_NOPROP
:
21172 case MODE_LINE_TITLE
:
21173 n
+= store_mode_line_noprop (spec
, field
, prec
);
21175 case MODE_LINE_STRING
:
21177 Lisp_Object tem
= build_string (spec
);
21178 props
= Ftext_properties_at (make_number (charpos
), elt
);
21179 /* Should only keep face property in props */
21180 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21183 case MODE_LINE_DISPLAY
:
21185 int nglyphs_before
, nwritten
;
21187 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21188 nwritten
= display_string (spec
, string
, elt
,
21193 /* Assign to the glyphs written above the
21194 string where the `%x' came from, position
21198 struct glyph
*glyph
21199 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21203 for (i
= 0; i
< nwritten
; ++i
)
21205 glyph
[i
].object
= elt
;
21206 glyph
[i
].charpos
= charpos
;
21223 /* A symbol: process the value of the symbol recursively
21224 as if it appeared here directly. Avoid error if symbol void.
21225 Special case: if value of symbol is a string, output the string
21228 register Lisp_Object tem
;
21230 /* If the variable is not marked as risky to set
21231 then its contents are risky to use. */
21232 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21235 tem
= Fboundp (elt
);
21238 tem
= Fsymbol_value (elt
);
21239 /* If value is a string, output that string literally:
21240 don't check for % within it. */
21244 if (!EQ (tem
, elt
))
21246 /* Give up right away for nil or t. */
21256 register Lisp_Object car
, tem
;
21258 /* A cons cell: five distinct cases.
21259 If first element is :eval or :propertize, do something special.
21260 If first element is a string or a cons, process all the elements
21261 and effectively concatenate them.
21262 If first element is a negative number, truncate displaying cdr to
21263 at most that many characters. If positive, pad (with spaces)
21264 to at least that many characters.
21265 If first element is a symbol, process the cadr or caddr recursively
21266 according to whether the symbol's value is non-nil or nil. */
21268 if (EQ (car
, QCeval
))
21270 /* An element of the form (:eval FORM) means evaluate FORM
21271 and use the result as mode line elements. */
21276 if (CONSP (XCDR (elt
)))
21279 spec
= safe_eval (XCAR (XCDR (elt
)));
21280 n
+= display_mode_element (it
, depth
, field_width
- n
,
21281 precision
- n
, spec
, props
,
21285 else if (EQ (car
, QCpropertize
))
21287 /* An element of the form (:propertize ELT PROPS...)
21288 means display ELT but applying properties PROPS. */
21293 if (CONSP (XCDR (elt
)))
21294 n
+= display_mode_element (it
, depth
, field_width
- n
,
21295 precision
- n
, XCAR (XCDR (elt
)),
21296 XCDR (XCDR (elt
)), risky
);
21298 else if (SYMBOLP (car
))
21300 tem
= Fboundp (car
);
21304 /* elt is now the cdr, and we know it is a cons cell.
21305 Use its car if CAR has a non-nil value. */
21308 tem
= Fsymbol_value (car
);
21315 /* Symbol's value is nil (or symbol is unbound)
21316 Get the cddr of the original list
21317 and if possible find the caddr and use that. */
21321 else if (!CONSP (elt
))
21326 else if (INTEGERP (car
))
21328 register int lim
= XINT (car
);
21332 /* Negative int means reduce maximum width. */
21333 if (precision
<= 0)
21336 precision
= min (precision
, -lim
);
21340 /* Padding specified. Don't let it be more than
21341 current maximum. */
21343 lim
= min (precision
, lim
);
21345 /* If that's more padding than already wanted, queue it.
21346 But don't reduce padding already specified even if
21347 that is beyond the current truncation point. */
21348 field_width
= max (lim
, field_width
);
21352 else if (STRINGP (car
) || CONSP (car
))
21354 Lisp_Object halftail
= elt
;
21358 && (precision
<= 0 || n
< precision
))
21360 n
+= display_mode_element (it
, depth
,
21361 /* Do padding only after the last
21362 element in the list. */
21363 (! CONSP (XCDR (elt
))
21366 precision
- n
, XCAR (elt
),
21370 if ((len
& 1) == 0)
21371 halftail
= XCDR (halftail
);
21372 /* Check for cycle. */
21373 if (EQ (halftail
, elt
))
21382 elt
= build_string ("*invalid*");
21386 /* Pad to FIELD_WIDTH. */
21387 if (field_width
> 0 && n
< field_width
)
21389 switch (mode_line_target
)
21391 case MODE_LINE_NOPROP
:
21392 case MODE_LINE_TITLE
:
21393 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21395 case MODE_LINE_STRING
:
21396 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21398 case MODE_LINE_DISPLAY
:
21399 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21408 /* Store a mode-line string element in mode_line_string_list.
21410 If STRING is non-null, display that C string. Otherwise, the Lisp
21411 string LISP_STRING is displayed.
21413 FIELD_WIDTH is the minimum number of output glyphs to produce.
21414 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21415 with spaces. FIELD_WIDTH <= 0 means don't pad.
21417 PRECISION is the maximum number of characters to output from
21418 STRING. PRECISION <= 0 means don't truncate the string.
21420 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21421 properties to the string.
21423 PROPS are the properties to add to the string.
21424 The mode_line_string_face face property is always added to the string.
21428 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21429 int field_width
, int precision
, Lisp_Object props
)
21434 if (string
!= NULL
)
21436 len
= strlen (string
);
21437 if (precision
> 0 && len
> precision
)
21439 lisp_string
= make_string (string
, len
);
21441 props
= mode_line_string_face_prop
;
21442 else if (!NILP (mode_line_string_face
))
21444 Lisp_Object face
= Fplist_get (props
, Qface
);
21445 props
= Fcopy_sequence (props
);
21447 face
= mode_line_string_face
;
21449 face
= list2 (face
, mode_line_string_face
);
21450 props
= Fplist_put (props
, Qface
, face
);
21452 Fadd_text_properties (make_number (0), make_number (len
),
21453 props
, lisp_string
);
21457 len
= XFASTINT (Flength (lisp_string
));
21458 if (precision
> 0 && len
> precision
)
21461 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21464 if (!NILP (mode_line_string_face
))
21468 props
= Ftext_properties_at (make_number (0), lisp_string
);
21469 face
= Fplist_get (props
, Qface
);
21471 face
= mode_line_string_face
;
21473 face
= list2 (face
, mode_line_string_face
);
21474 props
= list2 (Qface
, face
);
21476 lisp_string
= Fcopy_sequence (lisp_string
);
21479 Fadd_text_properties (make_number (0), make_number (len
),
21480 props
, lisp_string
);
21485 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21489 if (field_width
> len
)
21491 field_width
-= len
;
21492 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21494 Fadd_text_properties (make_number (0), make_number (field_width
),
21495 props
, lisp_string
);
21496 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21504 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21506 doc
: /* Format a string out of a mode line format specification.
21507 First arg FORMAT specifies the mode line format (see `mode-line-format'
21508 for details) to use.
21510 By default, the format is evaluated for the currently selected window.
21512 Optional second arg FACE specifies the face property to put on all
21513 characters for which no face is specified. The value nil means the
21514 default face. The value t means whatever face the window's mode line
21515 currently uses (either `mode-line' or `mode-line-inactive',
21516 depending on whether the window is the selected window or not).
21517 An integer value means the value string has no text
21520 Optional third and fourth args WINDOW and BUFFER specify the window
21521 and buffer to use as the context for the formatting (defaults
21522 are the selected window and the WINDOW's buffer). */)
21523 (Lisp_Object format
, Lisp_Object face
,
21524 Lisp_Object window
, Lisp_Object buffer
)
21529 struct buffer
*old_buffer
= NULL
;
21531 int no_props
= INTEGERP (face
);
21532 ptrdiff_t count
= SPECPDL_INDEX ();
21534 int string_start
= 0;
21536 w
= decode_any_window (window
);
21537 XSETWINDOW (window
, w
);
21540 buffer
= w
->contents
;
21541 CHECK_BUFFER (buffer
);
21543 /* Make formatting the modeline a non-op when noninteractive, otherwise
21544 there will be problems later caused by a partially initialized frame. */
21545 if (NILP (format
) || noninteractive
)
21546 return empty_unibyte_string
;
21551 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21552 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21553 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21554 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21555 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21556 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21557 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21560 old_buffer
= current_buffer
;
21562 /* Save things including mode_line_proptrans_alist,
21563 and set that to nil so that we don't alter the outer value. */
21564 record_unwind_protect (unwind_format_mode_line
,
21565 format_mode_line_unwind_data
21566 (XFRAME (WINDOW_FRAME (w
)),
21567 old_buffer
, selected_window
, 1));
21568 mode_line_proptrans_alist
= Qnil
;
21570 Fselect_window (window
, Qt
);
21571 set_buffer_internal_1 (XBUFFER (buffer
));
21573 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21577 mode_line_target
= MODE_LINE_NOPROP
;
21578 mode_line_string_face_prop
= Qnil
;
21579 mode_line_string_list
= Qnil
;
21580 string_start
= MODE_LINE_NOPROP_LEN (0);
21584 mode_line_target
= MODE_LINE_STRING
;
21585 mode_line_string_list
= Qnil
;
21586 mode_line_string_face
= face
;
21587 mode_line_string_face_prop
21588 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21591 push_kboard (FRAME_KBOARD (it
.f
));
21592 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21597 len
= MODE_LINE_NOPROP_LEN (string_start
);
21598 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21602 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21603 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21604 empty_unibyte_string
);
21607 unbind_to (count
, Qnil
);
21611 /* Write a null-terminated, right justified decimal representation of
21612 the positive integer D to BUF using a minimal field width WIDTH. */
21615 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21617 register char *p
= buf
;
21625 *p
++ = d
% 10 + '0';
21630 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21641 /* Write a null-terminated, right justified decimal and "human
21642 readable" representation of the nonnegative integer D to BUF using
21643 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21645 static const char power_letter
[] =
21659 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21661 /* We aim to represent the nonnegative integer D as
21662 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21663 ptrdiff_t quotient
= d
;
21665 /* -1 means: do not use TENTHS. */
21669 /* Length of QUOTIENT.TENTHS as a string. */
21675 if (quotient
>= 1000)
21677 /* Scale to the appropriate EXPONENT. */
21680 remainder
= quotient
% 1000;
21684 while (quotient
>= 1000);
21686 /* Round to nearest and decide whether to use TENTHS or not. */
21689 tenths
= remainder
/ 100;
21690 if (remainder
% 100 >= 50)
21697 if (quotient
== 10)
21705 if (remainder
>= 500)
21707 if (quotient
< 999)
21718 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21719 if (tenths
== -1 && quotient
<= 99)
21726 p
= psuffix
= buf
+ max (width
, length
);
21728 /* Print EXPONENT. */
21729 *psuffix
++ = power_letter
[exponent
];
21732 /* Print TENTHS. */
21735 *--p
= '0' + tenths
;
21739 /* Print QUOTIENT. */
21742 int digit
= quotient
% 10;
21743 *--p
= '0' + digit
;
21745 while ((quotient
/= 10) != 0);
21747 /* Print leading spaces. */
21752 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21753 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21754 type of CODING_SYSTEM. Return updated pointer into BUF. */
21756 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21759 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21762 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21763 const unsigned char *eol_str
;
21765 /* The EOL conversion we are using. */
21766 Lisp_Object eoltype
;
21768 val
= CODING_SYSTEM_SPEC (coding_system
);
21771 if (!VECTORP (val
)) /* Not yet decided. */
21773 *buf
++ = multibyte
? '-' : ' ';
21775 eoltype
= eol_mnemonic_undecided
;
21776 /* Don't mention EOL conversion if it isn't decided. */
21781 Lisp_Object eolvalue
;
21783 attrs
= AREF (val
, 0);
21784 eolvalue
= AREF (val
, 2);
21787 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21792 /* The EOL conversion that is normal on this system. */
21794 if (NILP (eolvalue
)) /* Not yet decided. */
21795 eoltype
= eol_mnemonic_undecided
;
21796 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21797 eoltype
= eol_mnemonic_undecided
;
21798 else /* eolvalue is Qunix, Qdos, or Qmac. */
21799 eoltype
= (EQ (eolvalue
, Qunix
)
21800 ? eol_mnemonic_unix
21801 : (EQ (eolvalue
, Qdos
) == 1
21802 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21808 /* Mention the EOL conversion if it is not the usual one. */
21809 if (STRINGP (eoltype
))
21811 eol_str
= SDATA (eoltype
);
21812 eol_str_len
= SBYTES (eoltype
);
21814 else if (CHARACTERP (eoltype
))
21816 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21817 int c
= XFASTINT (eoltype
);
21818 eol_str_len
= CHAR_STRING (c
, tmp
);
21823 eol_str
= invalid_eol_type
;
21824 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21826 memcpy (buf
, eol_str
, eol_str_len
);
21827 buf
+= eol_str_len
;
21833 /* Return a string for the output of a mode line %-spec for window W,
21834 generated by character C. FIELD_WIDTH > 0 means pad the string
21835 returned with spaces to that value. Return a Lisp string in
21836 *STRING if the resulting string is taken from that Lisp string.
21838 Note we operate on the current buffer for most purposes. */
21840 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21842 static const char *
21843 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21844 Lisp_Object
*string
)
21847 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21848 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21849 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21850 produce strings from numerical values, so limit preposterously
21851 large values of FIELD_WIDTH to avoid overrunning the buffer's
21852 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21853 bytes plus the terminating null. */
21854 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21855 struct buffer
*b
= current_buffer
;
21863 if (!NILP (BVAR (b
, read_only
)))
21865 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21870 /* This differs from %* only for a modified read-only buffer. */
21871 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21873 if (!NILP (BVAR (b
, read_only
)))
21878 /* This differs from %* in ignoring read-only-ness. */
21879 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21891 if (command_loop_level
> 5)
21893 p
= decode_mode_spec_buf
;
21894 for (i
= 0; i
< command_loop_level
; i
++)
21897 return decode_mode_spec_buf
;
21905 if (command_loop_level
> 5)
21907 p
= decode_mode_spec_buf
;
21908 for (i
= 0; i
< command_loop_level
; i
++)
21911 return decode_mode_spec_buf
;
21918 /* Let lots_of_dashes be a string of infinite length. */
21919 if (mode_line_target
== MODE_LINE_NOPROP
21920 || mode_line_target
== MODE_LINE_STRING
)
21922 if (field_width
<= 0
21923 || field_width
> sizeof (lots_of_dashes
))
21925 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21926 decode_mode_spec_buf
[i
] = '-';
21927 decode_mode_spec_buf
[i
] = '\0';
21928 return decode_mode_spec_buf
;
21931 return lots_of_dashes
;
21935 obj
= BVAR (b
, name
);
21939 /* %c and %l are ignored in `frame-title-format'.
21940 (In redisplay_internal, the frame title is drawn _before_ the
21941 windows are updated, so the stuff which depends on actual
21942 window contents (such as %l) may fail to render properly, or
21943 even crash emacs.) */
21944 if (mode_line_target
== MODE_LINE_TITLE
)
21948 ptrdiff_t col
= current_column ();
21949 w
->column_number_displayed
= col
;
21950 pint2str (decode_mode_spec_buf
, width
, col
);
21951 return decode_mode_spec_buf
;
21955 #ifndef SYSTEM_MALLOC
21957 if (NILP (Vmemory_full
))
21960 return "!MEM FULL! ";
21967 /* %F displays the frame name. */
21968 if (!NILP (f
->title
))
21969 return SSDATA (f
->title
);
21970 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21971 return SSDATA (f
->name
);
21975 obj
= BVAR (b
, filename
);
21980 ptrdiff_t size
= ZV
- BEGV
;
21981 pint2str (decode_mode_spec_buf
, width
, size
);
21982 return decode_mode_spec_buf
;
21987 ptrdiff_t size
= ZV
- BEGV
;
21988 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21989 return decode_mode_spec_buf
;
21994 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21995 ptrdiff_t topline
, nlines
, height
;
21998 /* %c and %l are ignored in `frame-title-format'. */
21999 if (mode_line_target
== MODE_LINE_TITLE
)
22002 startpos
= marker_position (w
->start
);
22003 startpos_byte
= marker_byte_position (w
->start
);
22004 height
= WINDOW_TOTAL_LINES (w
);
22006 /* If we decided that this buffer isn't suitable for line numbers,
22007 don't forget that too fast. */
22008 if (w
->base_line_pos
== -1)
22011 /* If the buffer is very big, don't waste time. */
22012 if (INTEGERP (Vline_number_display_limit
)
22013 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22015 w
->base_line_pos
= 0;
22016 w
->base_line_number
= 0;
22020 if (w
->base_line_number
> 0
22021 && w
->base_line_pos
> 0
22022 && w
->base_line_pos
<= startpos
)
22024 line
= w
->base_line_number
;
22025 linepos
= w
->base_line_pos
;
22026 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22031 linepos
= BUF_BEGV (b
);
22032 linepos_byte
= BUF_BEGV_BYTE (b
);
22035 /* Count lines from base line to window start position. */
22036 nlines
= display_count_lines (linepos_byte
,
22040 topline
= nlines
+ line
;
22042 /* Determine a new base line, if the old one is too close
22043 or too far away, or if we did not have one.
22044 "Too close" means it's plausible a scroll-down would
22045 go back past it. */
22046 if (startpos
== BUF_BEGV (b
))
22048 w
->base_line_number
= topline
;
22049 w
->base_line_pos
= BUF_BEGV (b
);
22051 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22052 || linepos
== BUF_BEGV (b
))
22054 ptrdiff_t limit
= BUF_BEGV (b
);
22055 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22056 ptrdiff_t position
;
22057 ptrdiff_t distance
=
22058 (height
* 2 + 30) * line_number_display_limit_width
;
22060 if (startpos
- distance
> limit
)
22062 limit
= startpos
- distance
;
22063 limit_byte
= CHAR_TO_BYTE (limit
);
22066 nlines
= display_count_lines (startpos_byte
,
22068 - (height
* 2 + 30),
22070 /* If we couldn't find the lines we wanted within
22071 line_number_display_limit_width chars per line,
22072 give up on line numbers for this window. */
22073 if (position
== limit_byte
&& limit
== startpos
- distance
)
22075 w
->base_line_pos
= -1;
22076 w
->base_line_number
= 0;
22080 w
->base_line_number
= topline
- nlines
;
22081 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22084 /* Now count lines from the start pos to point. */
22085 nlines
= display_count_lines (startpos_byte
,
22086 PT_BYTE
, PT
, &junk
);
22088 /* Record that we did display the line number. */
22089 line_number_displayed
= 1;
22091 /* Make the string to show. */
22092 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22093 return decode_mode_spec_buf
;
22096 char* p
= decode_mode_spec_buf
;
22097 int pad
= width
- 2;
22103 return decode_mode_spec_buf
;
22109 obj
= BVAR (b
, mode_name
);
22113 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22119 ptrdiff_t pos
= marker_position (w
->start
);
22120 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22122 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22124 if (pos
<= BUF_BEGV (b
))
22129 else if (pos
<= BUF_BEGV (b
))
22133 if (total
> 1000000)
22134 /* Do it differently for a large value, to avoid overflow. */
22135 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22137 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22138 /* We can't normally display a 3-digit number,
22139 so get us a 2-digit number that is close. */
22142 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22143 return decode_mode_spec_buf
;
22147 /* Display percentage of size above the bottom of the screen. */
22150 ptrdiff_t toppos
= marker_position (w
->start
);
22151 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22152 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22154 if (botpos
>= BUF_ZV (b
))
22156 if (toppos
<= BUF_BEGV (b
))
22163 if (total
> 1000000)
22164 /* Do it differently for a large value, to avoid overflow. */
22165 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22167 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22168 /* We can't normally display a 3-digit number,
22169 so get us a 2-digit number that is close. */
22172 if (toppos
<= BUF_BEGV (b
))
22173 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22175 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22176 return decode_mode_spec_buf
;
22181 /* status of process */
22182 obj
= Fget_buffer_process (Fcurrent_buffer ());
22184 return "no process";
22186 obj
= Fsymbol_name (Fprocess_status (obj
));
22192 ptrdiff_t count
= inhibit_garbage_collection ();
22193 Lisp_Object val
= call1 (intern ("file-remote-p"),
22194 BVAR (current_buffer
, directory
));
22195 unbind_to (count
, Qnil
);
22204 /* coding-system (not including end-of-line format) */
22206 /* coding-system (including end-of-line type) */
22208 int eol_flag
= (c
== 'Z');
22209 char *p
= decode_mode_spec_buf
;
22211 if (! FRAME_WINDOW_P (f
))
22213 /* No need to mention EOL here--the terminal never needs
22214 to do EOL conversion. */
22215 p
= decode_mode_spec_coding (CODING_ID_NAME
22216 (FRAME_KEYBOARD_CODING (f
)->id
),
22218 p
= decode_mode_spec_coding (CODING_ID_NAME
22219 (FRAME_TERMINAL_CODING (f
)->id
),
22222 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22225 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22226 #ifdef subprocesses
22227 obj
= Fget_buffer_process (Fcurrent_buffer ());
22228 if (PROCESSP (obj
))
22230 p
= decode_mode_spec_coding
22231 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22232 p
= decode_mode_spec_coding
22233 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22235 #endif /* subprocesses */
22238 return decode_mode_spec_buf
;
22245 return SSDATA (obj
);
22252 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22253 means count lines back from START_BYTE. But don't go beyond
22254 LIMIT_BYTE. Return the number of lines thus found (always
22257 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22258 either the position COUNT lines after/before START_BYTE, if we
22259 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22263 display_count_lines (ptrdiff_t start_byte
,
22264 ptrdiff_t limit_byte
, ptrdiff_t count
,
22265 ptrdiff_t *byte_pos_ptr
)
22267 register unsigned char *cursor
;
22268 unsigned char *base
;
22270 register ptrdiff_t ceiling
;
22271 register unsigned char *ceiling_addr
;
22272 ptrdiff_t orig_count
= count
;
22274 /* If we are not in selective display mode,
22275 check only for newlines. */
22276 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22277 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22281 while (start_byte
< limit_byte
)
22283 ceiling
= BUFFER_CEILING_OF (start_byte
);
22284 ceiling
= min (limit_byte
- 1, ceiling
);
22285 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22286 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22290 if (selective_display
)
22292 while (*cursor
!= '\n' && *cursor
!= 015
22293 && ++cursor
!= ceiling_addr
)
22295 if (cursor
== ceiling_addr
)
22300 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22309 start_byte
+= cursor
- base
;
22310 *byte_pos_ptr
= start_byte
;
22314 while (cursor
< ceiling_addr
);
22316 start_byte
+= ceiling_addr
- base
;
22321 while (start_byte
> limit_byte
)
22323 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22324 ceiling
= max (limit_byte
, ceiling
);
22325 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22326 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22329 if (selective_display
)
22331 while (--cursor
>= ceiling_addr
22332 && *cursor
!= '\n' && *cursor
!= 015)
22334 if (cursor
< ceiling_addr
)
22339 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22346 start_byte
+= cursor
- base
+ 1;
22347 *byte_pos_ptr
= start_byte
;
22348 /* When scanning backwards, we should
22349 not count the newline posterior to which we stop. */
22350 return - orig_count
- 1;
22353 start_byte
+= ceiling_addr
- base
;
22357 *byte_pos_ptr
= limit_byte
;
22360 return - orig_count
+ count
;
22361 return orig_count
- count
;
22367 /***********************************************************************
22369 ***********************************************************************/
22371 /* Display a NUL-terminated string, starting with index START.
22373 If STRING is non-null, display that C string. Otherwise, the Lisp
22374 string LISP_STRING is displayed. There's a case that STRING is
22375 non-null and LISP_STRING is not nil. It means STRING is a string
22376 data of LISP_STRING. In that case, we display LISP_STRING while
22377 ignoring its text properties.
22379 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22380 FACE_STRING. Display STRING or LISP_STRING with the face at
22381 FACE_STRING_POS in FACE_STRING:
22383 Display the string in the environment given by IT, but use the
22384 standard display table, temporarily.
22386 FIELD_WIDTH is the minimum number of output glyphs to produce.
22387 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22388 with spaces. If STRING has more characters, more than FIELD_WIDTH
22389 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22391 PRECISION is the maximum number of characters to output from
22392 STRING. PRECISION < 0 means don't truncate the string.
22394 This is roughly equivalent to printf format specifiers:
22396 FIELD_WIDTH PRECISION PRINTF
22397 ----------------------------------------
22403 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22404 display them, and < 0 means obey the current buffer's value of
22405 enable_multibyte_characters.
22407 Value is the number of columns displayed. */
22410 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22411 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22412 int field_width
, int precision
, int max_x
, int multibyte
)
22414 int hpos_at_start
= it
->hpos
;
22415 int saved_face_id
= it
->face_id
;
22416 struct glyph_row
*row
= it
->glyph_row
;
22417 ptrdiff_t it_charpos
;
22419 /* Initialize the iterator IT for iteration over STRING beginning
22420 with index START. */
22421 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22422 precision
, field_width
, multibyte
);
22423 if (string
&& STRINGP (lisp_string
))
22424 /* LISP_STRING is the one returned by decode_mode_spec. We should
22425 ignore its text properties. */
22426 it
->stop_charpos
= it
->end_charpos
;
22428 /* If displaying STRING, set up the face of the iterator from
22429 FACE_STRING, if that's given. */
22430 if (STRINGP (face_string
))
22436 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22437 0, &endptr
, it
->base_face_id
, 0);
22438 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22439 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22442 /* Set max_x to the maximum allowed X position. Don't let it go
22443 beyond the right edge of the window. */
22445 max_x
= it
->last_visible_x
;
22447 max_x
= min (max_x
, it
->last_visible_x
);
22449 /* Skip over display elements that are not visible. because IT->w is
22451 if (it
->current_x
< it
->first_visible_x
)
22452 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22453 MOVE_TO_POS
| MOVE_TO_X
);
22455 row
->ascent
= it
->max_ascent
;
22456 row
->height
= it
->max_ascent
+ it
->max_descent
;
22457 row
->phys_ascent
= it
->max_phys_ascent
;
22458 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22459 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22461 if (STRINGP (it
->string
))
22462 it_charpos
= IT_STRING_CHARPOS (*it
);
22464 it_charpos
= IT_CHARPOS (*it
);
22466 /* This condition is for the case that we are called with current_x
22467 past last_visible_x. */
22468 while (it
->current_x
< max_x
)
22470 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22472 /* Get the next display element. */
22473 if (!get_next_display_element (it
))
22476 /* Produce glyphs. */
22477 x_before
= it
->current_x
;
22478 n_glyphs_before
= row
->used
[TEXT_AREA
];
22479 PRODUCE_GLYPHS (it
);
22481 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22484 while (i
< nglyphs
)
22486 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22488 if (it
->line_wrap
!= TRUNCATE
22489 && x
+ glyph
->pixel_width
> max_x
)
22491 /* End of continued line or max_x reached. */
22492 if (CHAR_GLYPH_PADDING_P (*glyph
))
22494 /* A wide character is unbreakable. */
22495 if (row
->reversed_p
)
22496 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22497 - n_glyphs_before
);
22498 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22499 it
->current_x
= x_before
;
22503 if (row
->reversed_p
)
22504 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22505 - (n_glyphs_before
+ i
));
22506 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22511 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22513 /* Glyph is at least partially visible. */
22515 if (x
< it
->first_visible_x
)
22516 row
->x
= x
- it
->first_visible_x
;
22520 /* Glyph is off the left margin of the display area.
22521 Should not happen. */
22525 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22526 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22527 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22528 row
->phys_height
= max (row
->phys_height
,
22529 it
->max_phys_ascent
+ it
->max_phys_descent
);
22530 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22531 it
->max_extra_line_spacing
);
22532 x
+= glyph
->pixel_width
;
22536 /* Stop if max_x reached. */
22540 /* Stop at line ends. */
22541 if (ITERATOR_AT_END_OF_LINE_P (it
))
22543 it
->continuation_lines_width
= 0;
22547 set_iterator_to_next (it
, 1);
22548 if (STRINGP (it
->string
))
22549 it_charpos
= IT_STRING_CHARPOS (*it
);
22551 it_charpos
= IT_CHARPOS (*it
);
22553 /* Stop if truncating at the right edge. */
22554 if (it
->line_wrap
== TRUNCATE
22555 && it
->current_x
>= it
->last_visible_x
)
22557 /* Add truncation mark, but don't do it if the line is
22558 truncated at a padding space. */
22559 if (it_charpos
< it
->string_nchars
)
22561 if (!FRAME_WINDOW_P (it
->f
))
22565 if (it
->current_x
> it
->last_visible_x
)
22567 if (!row
->reversed_p
)
22569 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22570 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22575 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22576 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22578 unproduce_glyphs (it
, ii
+ 1);
22579 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22581 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22583 row
->used
[TEXT_AREA
] = ii
;
22584 produce_special_glyphs (it
, IT_TRUNCATION
);
22587 produce_special_glyphs (it
, IT_TRUNCATION
);
22589 row
->truncated_on_right_p
= 1;
22595 /* Maybe insert a truncation at the left. */
22596 if (it
->first_visible_x
22599 if (!FRAME_WINDOW_P (it
->f
)
22600 || (row
->reversed_p
22601 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22602 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22603 insert_left_trunc_glyphs (it
);
22604 row
->truncated_on_left_p
= 1;
22607 it
->face_id
= saved_face_id
;
22609 /* Value is number of columns displayed. */
22610 return it
->hpos
- hpos_at_start
;
22615 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22616 appears as an element of LIST or as the car of an element of LIST.
22617 If PROPVAL is a list, compare each element against LIST in that
22618 way, and return 1/2 if any element of PROPVAL is found in LIST.
22619 Otherwise return 0. This function cannot quit.
22620 The return value is 2 if the text is invisible but with an ellipsis
22621 and 1 if it's invisible and without an ellipsis. */
22624 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22626 register Lisp_Object tail
, proptail
;
22628 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22630 register Lisp_Object tem
;
22632 if (EQ (propval
, tem
))
22634 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22635 return NILP (XCDR (tem
)) ? 1 : 2;
22638 if (CONSP (propval
))
22640 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22642 Lisp_Object propelt
;
22643 propelt
= XCAR (proptail
);
22644 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22646 register Lisp_Object tem
;
22648 if (EQ (propelt
, tem
))
22650 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22651 return NILP (XCDR (tem
)) ? 1 : 2;
22659 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22660 doc
: /* Non-nil if the property makes the text invisible.
22661 POS-OR-PROP can be a marker or number, in which case it is taken to be
22662 a position in the current buffer and the value of the `invisible' property
22663 is checked; or it can be some other value, which is then presumed to be the
22664 value of the `invisible' property of the text of interest.
22665 The non-nil value returned can be t for truly invisible text or something
22666 else if the text is replaced by an ellipsis. */)
22667 (Lisp_Object pos_or_prop
)
22670 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22671 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22673 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22674 return (invis
== 0 ? Qnil
22676 : make_number (invis
));
22679 /* Calculate a width or height in pixels from a specification using
22680 the following elements:
22683 NUM - a (fractional) multiple of the default font width/height
22684 (NUM) - specifies exactly NUM pixels
22685 UNIT - a fixed number of pixels, see below.
22686 ELEMENT - size of a display element in pixels, see below.
22687 (NUM . SPEC) - equals NUM * SPEC
22688 (+ SPEC SPEC ...) - add pixel values
22689 (- SPEC SPEC ...) - subtract pixel values
22690 (- SPEC) - negate pixel value
22693 INT or FLOAT - a number constant
22694 SYMBOL - use symbol's (buffer local) variable binding.
22697 in - pixels per inch *)
22698 mm - pixels per 1/1000 meter *)
22699 cm - pixels per 1/100 meter *)
22700 width - width of current font in pixels.
22701 height - height of current font in pixels.
22703 *) using the ratio(s) defined in display-pixels-per-inch.
22707 left-fringe - left fringe width in pixels
22708 right-fringe - right fringe width in pixels
22710 left-margin - left margin width in pixels
22711 right-margin - right margin width in pixels
22713 scroll-bar - scroll-bar area width in pixels
22717 Pixels corresponding to 5 inches:
22720 Total width of non-text areas on left side of window (if scroll-bar is on left):
22721 '(space :width (+ left-fringe left-margin scroll-bar))
22723 Align to first text column (in header line):
22724 '(space :align-to 0)
22726 Align to middle of text area minus half the width of variable `my-image'
22727 containing a loaded image:
22728 '(space :align-to (0.5 . (- text my-image)))
22730 Width of left margin minus width of 1 character in the default font:
22731 '(space :width (- left-margin 1))
22733 Width of left margin minus width of 2 characters in the current font:
22734 '(space :width (- left-margin (2 . width)))
22736 Center 1 character over left-margin (in header line):
22737 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22739 Different ways to express width of left fringe plus left margin minus one pixel:
22740 '(space :width (- (+ left-fringe left-margin) (1)))
22741 '(space :width (+ left-fringe left-margin (- (1))))
22742 '(space :width (+ left-fringe left-margin (-1)))
22747 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22748 struct font
*font
, int width_p
, int *align_to
)
22752 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22753 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22756 return OK_PIXELS (0);
22758 eassert (FRAME_LIVE_P (it
->f
));
22760 if (SYMBOLP (prop
))
22762 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22764 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22766 if (unit
[0] == 'i' && unit
[1] == 'n')
22768 else if (unit
[0] == 'm' && unit
[1] == 'm')
22770 else if (unit
[0] == 'c' && unit
[1] == 'm')
22776 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22777 : FRAME_RES_Y (it
->f
));
22780 return OK_PIXELS (ppi
/ pixels
);
22785 #ifdef HAVE_WINDOW_SYSTEM
22786 if (EQ (prop
, Qheight
))
22787 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22788 if (EQ (prop
, Qwidth
))
22789 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22791 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22792 return OK_PIXELS (1);
22795 if (EQ (prop
, Qtext
))
22796 return OK_PIXELS (width_p
22797 ? window_box_width (it
->w
, TEXT_AREA
)
22798 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22800 if (align_to
&& *align_to
< 0)
22803 if (EQ (prop
, Qleft
))
22804 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22805 if (EQ (prop
, Qright
))
22806 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22807 if (EQ (prop
, Qcenter
))
22808 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22809 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22810 if (EQ (prop
, Qleft_fringe
))
22811 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22812 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22813 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22814 if (EQ (prop
, Qright_fringe
))
22815 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22816 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22817 : window_box_right_offset (it
->w
, TEXT_AREA
));
22818 if (EQ (prop
, Qleft_margin
))
22819 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22820 if (EQ (prop
, Qright_margin
))
22821 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22822 if (EQ (prop
, Qscroll_bar
))
22823 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22825 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22826 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22827 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22832 if (EQ (prop
, Qleft_fringe
))
22833 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22834 if (EQ (prop
, Qright_fringe
))
22835 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22836 if (EQ (prop
, Qleft_margin
))
22837 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22838 if (EQ (prop
, Qright_margin
))
22839 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22840 if (EQ (prop
, Qscroll_bar
))
22841 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22844 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22845 if (EQ (prop
, Qunbound
))
22849 if (INTEGERP (prop
) || FLOATP (prop
))
22851 int base_unit
= (width_p
22852 ? FRAME_COLUMN_WIDTH (it
->f
)
22853 : FRAME_LINE_HEIGHT (it
->f
));
22854 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22859 Lisp_Object car
= XCAR (prop
);
22860 Lisp_Object cdr
= XCDR (prop
);
22864 #ifdef HAVE_WINDOW_SYSTEM
22865 if (FRAME_WINDOW_P (it
->f
)
22866 && valid_image_p (prop
))
22868 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22869 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22871 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22874 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22880 while (CONSP (cdr
))
22882 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22883 font
, width_p
, align_to
))
22886 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22891 if (EQ (car
, Qminus
))
22893 return OK_PIXELS (pixels
);
22896 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22897 if (EQ (car
, Qunbound
))
22901 if (INTEGERP (car
) || FLOATP (car
))
22904 pixels
= XFLOATINT (car
);
22906 return OK_PIXELS (pixels
);
22907 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22908 font
, width_p
, align_to
))
22909 return OK_PIXELS (pixels
* fact
);
22920 /***********************************************************************
22922 ***********************************************************************/
22924 #ifdef HAVE_WINDOW_SYSTEM
22929 dump_glyph_string (struct glyph_string
*s
)
22931 fprintf (stderr
, "glyph string\n");
22932 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22933 s
->x
, s
->y
, s
->width
, s
->height
);
22934 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22935 fprintf (stderr
, " hl = %d\n", s
->hl
);
22936 fprintf (stderr
, " left overhang = %d, right = %d\n",
22937 s
->left_overhang
, s
->right_overhang
);
22938 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22939 fprintf (stderr
, " extends to end of line = %d\n",
22940 s
->extends_to_end_of_line_p
);
22941 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22942 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22945 #endif /* GLYPH_DEBUG */
22947 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22948 of XChar2b structures for S; it can't be allocated in
22949 init_glyph_string because it must be allocated via `alloca'. W
22950 is the window on which S is drawn. ROW and AREA are the glyph row
22951 and area within the row from which S is constructed. START is the
22952 index of the first glyph structure covered by S. HL is a
22953 face-override for drawing S. */
22956 #define OPTIONAL_HDC(hdc) HDC hdc,
22957 #define DECLARE_HDC(hdc) HDC hdc;
22958 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22959 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22962 #ifndef OPTIONAL_HDC
22963 #define OPTIONAL_HDC(hdc)
22964 #define DECLARE_HDC(hdc)
22965 #define ALLOCATE_HDC(hdc, f)
22966 #define RELEASE_HDC(hdc, f)
22970 init_glyph_string (struct glyph_string
*s
,
22972 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22973 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22975 memset (s
, 0, sizeof *s
);
22977 s
->f
= XFRAME (w
->frame
);
22981 s
->display
= FRAME_X_DISPLAY (s
->f
);
22982 s
->window
= FRAME_X_WINDOW (s
->f
);
22983 s
->char2b
= char2b
;
22987 s
->first_glyph
= row
->glyphs
[area
] + start
;
22988 s
->height
= row
->height
;
22989 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22990 s
->ybase
= s
->y
+ row
->ascent
;
22994 /* Append the list of glyph strings with head H and tail T to the list
22995 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22998 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22999 struct glyph_string
*h
, struct glyph_string
*t
)
23013 /* Prepend the list of glyph strings with head H and tail T to the
23014 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23018 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23019 struct glyph_string
*h
, struct glyph_string
*t
)
23033 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23034 Set *HEAD and *TAIL to the resulting list. */
23037 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23038 struct glyph_string
*s
)
23040 s
->next
= s
->prev
= NULL
;
23041 append_glyph_string_lists (head
, tail
, s
, s
);
23045 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23046 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23047 make sure that X resources for the face returned are allocated.
23048 Value is a pointer to a realized face that is ready for display if
23049 DISPLAY_P is non-zero. */
23051 static struct face
*
23052 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23053 XChar2b
*char2b
, int display_p
)
23055 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23060 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23062 if (code
== FONT_INVALID_CODE
)
23065 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23067 /* Make sure X resources of the face are allocated. */
23068 #ifdef HAVE_X_WINDOWS
23072 eassert (face
!= NULL
);
23073 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23080 /* Get face and two-byte form of character glyph GLYPH on frame F.
23081 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23082 a pointer to a realized face that is ready for display. */
23084 static struct face
*
23085 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23086 XChar2b
*char2b
, int *two_byte_p
)
23091 eassert (glyph
->type
== CHAR_GLYPH
);
23092 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23094 /* Make sure X resources of the face are allocated. */
23095 eassert (face
!= NULL
);
23096 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23103 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23104 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23106 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23108 if (code
== FONT_INVALID_CODE
)
23112 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23117 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23118 Return 1 if FONT has a glyph for C, otherwise return 0. */
23121 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23125 if (CHAR_BYTE8_P (c
))
23126 code
= CHAR_TO_BYTE8 (c
);
23128 code
= font
->driver
->encode_char (font
, c
);
23130 if (code
== FONT_INVALID_CODE
)
23132 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23137 /* Fill glyph string S with composition components specified by S->cmp.
23139 BASE_FACE is the base face of the composition.
23140 S->cmp_from is the index of the first component for S.
23142 OVERLAPS non-zero means S should draw the foreground only, and use
23143 its physical height for clipping. See also draw_glyphs.
23145 Value is the index of a component not in S. */
23148 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23152 /* For all glyphs of this composition, starting at the offset
23153 S->cmp_from, until we reach the end of the definition or encounter a
23154 glyph that requires the different face, add it to S. */
23159 s
->for_overlaps
= overlaps
;
23162 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23164 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23166 /* TAB in a composition means display glyphs with padding space
23167 on the left or right. */
23170 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23173 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23180 s
->font
= s
->face
->font
;
23182 else if (s
->face
!= face
)
23190 if (s
->face
== NULL
)
23192 s
->face
= base_face
->ascii_face
;
23193 s
->font
= s
->face
->font
;
23196 /* All glyph strings for the same composition has the same width,
23197 i.e. the width set for the first component of the composition. */
23198 s
->width
= s
->first_glyph
->pixel_width
;
23200 /* If the specified font could not be loaded, use the frame's
23201 default font, but record the fact that we couldn't load it in
23202 the glyph string so that we can draw rectangles for the
23203 characters of the glyph string. */
23204 if (s
->font
== NULL
)
23206 s
->font_not_found_p
= 1;
23207 s
->font
= FRAME_FONT (s
->f
);
23210 /* Adjust base line for subscript/superscript text. */
23211 s
->ybase
+= s
->first_glyph
->voffset
;
23213 /* This glyph string must always be drawn with 16-bit functions. */
23220 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23221 int start
, int end
, int overlaps
)
23223 struct glyph
*glyph
, *last
;
23224 Lisp_Object lgstring
;
23227 s
->for_overlaps
= overlaps
;
23228 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23229 last
= s
->row
->glyphs
[s
->area
] + end
;
23230 s
->cmp_id
= glyph
->u
.cmp
.id
;
23231 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23232 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23233 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23234 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23235 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23237 while (glyph
< last
23238 && glyph
->u
.cmp
.automatic
23239 && glyph
->u
.cmp
.id
== s
->cmp_id
23240 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23241 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23243 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23245 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23246 unsigned code
= LGLYPH_CODE (lglyph
);
23248 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23250 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23251 return glyph
- s
->row
->glyphs
[s
->area
];
23255 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23256 See the comment of fill_glyph_string for arguments.
23257 Value is the index of the first glyph not in S. */
23261 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23262 int start
, int end
, int overlaps
)
23264 struct glyph
*glyph
, *last
;
23267 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23268 s
->for_overlaps
= overlaps
;
23269 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23270 last
= s
->row
->glyphs
[s
->area
] + end
;
23271 voffset
= glyph
->voffset
;
23272 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23273 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23275 s
->width
= glyph
->pixel_width
;
23277 while (glyph
< last
23278 && glyph
->type
== GLYPHLESS_GLYPH
23279 && glyph
->voffset
== voffset
23280 && glyph
->face_id
== face_id
)
23283 s
->width
+= glyph
->pixel_width
;
23286 s
->ybase
+= voffset
;
23287 return glyph
- s
->row
->glyphs
[s
->area
];
23291 /* Fill glyph string S from a sequence of character glyphs.
23293 FACE_ID is the face id of the string. START is the index of the
23294 first glyph to consider, END is the index of the last + 1.
23295 OVERLAPS non-zero means S should draw the foreground only, and use
23296 its physical height for clipping. See also draw_glyphs.
23298 Value is the index of the first glyph not in S. */
23301 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23302 int start
, int end
, int overlaps
)
23304 struct glyph
*glyph
, *last
;
23306 int glyph_not_available_p
;
23308 eassert (s
->f
== XFRAME (s
->w
->frame
));
23309 eassert (s
->nchars
== 0);
23310 eassert (start
>= 0 && end
> start
);
23312 s
->for_overlaps
= overlaps
;
23313 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23314 last
= s
->row
->glyphs
[s
->area
] + end
;
23315 voffset
= glyph
->voffset
;
23316 s
->padding_p
= glyph
->padding_p
;
23317 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23319 while (glyph
< last
23320 && glyph
->type
== CHAR_GLYPH
23321 && glyph
->voffset
== voffset
23322 /* Same face id implies same font, nowadays. */
23323 && glyph
->face_id
== face_id
23324 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23328 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23329 s
->char2b
+ s
->nchars
,
23331 s
->two_byte_p
= two_byte_p
;
23333 eassert (s
->nchars
<= end
- start
);
23334 s
->width
+= glyph
->pixel_width
;
23335 if (glyph
++->padding_p
!= s
->padding_p
)
23339 s
->font
= s
->face
->font
;
23341 /* If the specified font could not be loaded, use the frame's font,
23342 but record the fact that we couldn't load it in
23343 S->font_not_found_p so that we can draw rectangles for the
23344 characters of the glyph string. */
23345 if (s
->font
== NULL
|| glyph_not_available_p
)
23347 s
->font_not_found_p
= 1;
23348 s
->font
= FRAME_FONT (s
->f
);
23351 /* Adjust base line for subscript/superscript text. */
23352 s
->ybase
+= voffset
;
23354 eassert (s
->face
&& s
->face
->gc
);
23355 return glyph
- s
->row
->glyphs
[s
->area
];
23359 /* Fill glyph string S from image glyph S->first_glyph. */
23362 fill_image_glyph_string (struct glyph_string
*s
)
23364 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23365 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23367 s
->slice
= s
->first_glyph
->slice
.img
;
23368 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23369 s
->font
= s
->face
->font
;
23370 s
->width
= s
->first_glyph
->pixel_width
;
23372 /* Adjust base line for subscript/superscript text. */
23373 s
->ybase
+= s
->first_glyph
->voffset
;
23377 /* Fill glyph string S from a sequence of stretch glyphs.
23379 START is the index of the first glyph to consider,
23380 END is the index of the last + 1.
23382 Value is the index of the first glyph not in S. */
23385 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23387 struct glyph
*glyph
, *last
;
23388 int voffset
, face_id
;
23390 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23392 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23393 last
= s
->row
->glyphs
[s
->area
] + end
;
23394 face_id
= glyph
->face_id
;
23395 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23396 s
->font
= s
->face
->font
;
23397 s
->width
= glyph
->pixel_width
;
23399 voffset
= glyph
->voffset
;
23403 && glyph
->type
== STRETCH_GLYPH
23404 && glyph
->voffset
== voffset
23405 && glyph
->face_id
== face_id
);
23407 s
->width
+= glyph
->pixel_width
;
23409 /* Adjust base line for subscript/superscript text. */
23410 s
->ybase
+= voffset
;
23412 /* The case that face->gc == 0 is handled when drawing the glyph
23413 string by calling PREPARE_FACE_FOR_DISPLAY. */
23415 return glyph
- s
->row
->glyphs
[s
->area
];
23418 static struct font_metrics
*
23419 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23421 static struct font_metrics metrics
;
23426 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23427 if (code
== FONT_INVALID_CODE
)
23429 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23434 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23435 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23436 assumed to be zero. */
23439 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23441 *left
= *right
= 0;
23443 if (glyph
->type
== CHAR_GLYPH
)
23447 struct font_metrics
*pcm
;
23449 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23450 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23452 if (pcm
->rbearing
> pcm
->width
)
23453 *right
= pcm
->rbearing
- pcm
->width
;
23454 if (pcm
->lbearing
< 0)
23455 *left
= -pcm
->lbearing
;
23458 else if (glyph
->type
== COMPOSITE_GLYPH
)
23460 if (! glyph
->u
.cmp
.automatic
)
23462 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23464 if (cmp
->rbearing
> cmp
->pixel_width
)
23465 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23466 if (cmp
->lbearing
< 0)
23467 *left
= - cmp
->lbearing
;
23471 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23472 struct font_metrics metrics
;
23474 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23475 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23476 if (metrics
.rbearing
> metrics
.width
)
23477 *right
= metrics
.rbearing
- metrics
.width
;
23478 if (metrics
.lbearing
< 0)
23479 *left
= - metrics
.lbearing
;
23485 /* Return the index of the first glyph preceding glyph string S that
23486 is overwritten by S because of S's left overhang. Value is -1
23487 if no glyphs are overwritten. */
23490 left_overwritten (struct glyph_string
*s
)
23494 if (s
->left_overhang
)
23497 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23498 int first
= s
->first_glyph
- glyphs
;
23500 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23501 x
-= glyphs
[i
].pixel_width
;
23512 /* Return the index of the first glyph preceding glyph string S that
23513 is overwriting S because of its right overhang. Value is -1 if no
23514 glyph in front of S overwrites S. */
23517 left_overwriting (struct glyph_string
*s
)
23520 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23521 int first
= s
->first_glyph
- glyphs
;
23525 for (i
= first
- 1; i
>= 0; --i
)
23528 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23531 x
-= glyphs
[i
].pixel_width
;
23538 /* Return the index of the last glyph following glyph string S that is
23539 overwritten by S because of S's right overhang. Value is -1 if
23540 no such glyph is found. */
23543 right_overwritten (struct glyph_string
*s
)
23547 if (s
->right_overhang
)
23550 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23551 int first
= (s
->first_glyph
- glyphs
23552 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23553 int end
= s
->row
->used
[s
->area
];
23555 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23556 x
+= glyphs
[i
].pixel_width
;
23565 /* Return the index of the last glyph following glyph string S that
23566 overwrites S because of its left overhang. Value is negative
23567 if no such glyph is found. */
23570 right_overwriting (struct glyph_string
*s
)
23573 int end
= s
->row
->used
[s
->area
];
23574 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23575 int first
= (s
->first_glyph
- glyphs
23576 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23580 for (i
= first
; i
< end
; ++i
)
23583 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23586 x
+= glyphs
[i
].pixel_width
;
23593 /* Set background width of glyph string S. START is the index of the
23594 first glyph following S. LAST_X is the right-most x-position + 1
23595 in the drawing area. */
23598 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23600 /* If the face of this glyph string has to be drawn to the end of
23601 the drawing area, set S->extends_to_end_of_line_p. */
23603 if (start
== s
->row
->used
[s
->area
]
23604 && s
->area
== TEXT_AREA
23605 && ((s
->row
->fill_line_p
23606 && (s
->hl
== DRAW_NORMAL_TEXT
23607 || s
->hl
== DRAW_IMAGE_RAISED
23608 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23609 || s
->hl
== DRAW_MOUSE_FACE
))
23610 s
->extends_to_end_of_line_p
= 1;
23612 /* If S extends its face to the end of the line, set its
23613 background_width to the distance to the right edge of the drawing
23615 if (s
->extends_to_end_of_line_p
)
23616 s
->background_width
= last_x
- s
->x
+ 1;
23618 s
->background_width
= s
->width
;
23622 /* Compute overhangs and x-positions for glyph string S and its
23623 predecessors, or successors. X is the starting x-position for S.
23624 BACKWARD_P non-zero means process predecessors. */
23627 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23633 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23634 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23644 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23645 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23655 /* The following macros are only called from draw_glyphs below.
23656 They reference the following parameters of that function directly:
23657 `w', `row', `area', and `overlap_p'
23658 as well as the following local variables:
23659 `s', `f', and `hdc' (in W32) */
23662 /* On W32, silently add local `hdc' variable to argument list of
23663 init_glyph_string. */
23664 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23665 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23667 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23668 init_glyph_string (s, char2b, w, row, area, start, hl)
23671 /* Add a glyph string for a stretch glyph to the list of strings
23672 between HEAD and TAIL. START is the index of the stretch glyph in
23673 row area AREA of glyph row ROW. END is the index of the last glyph
23674 in that glyph row area. X is the current output position assigned
23675 to the new glyph string constructed. HL overrides that face of the
23676 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23677 is the right-most x-position of the drawing area. */
23679 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23680 and below -- keep them on one line. */
23681 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23684 s = alloca (sizeof *s); \
23685 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23686 START = fill_stretch_glyph_string (s, START, END); \
23687 append_glyph_string (&HEAD, &TAIL, s); \
23693 /* Add a glyph string for an image glyph to the list of strings
23694 between HEAD and TAIL. START is the index of the image glyph in
23695 row area AREA of glyph row ROW. END is the index of the last glyph
23696 in that glyph row area. X is the current output position assigned
23697 to the new glyph string constructed. HL overrides that face of the
23698 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23699 is the right-most x-position of the drawing area. */
23701 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23704 s = alloca (sizeof *s); \
23705 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23706 fill_image_glyph_string (s); \
23707 append_glyph_string (&HEAD, &TAIL, s); \
23714 /* Add a glyph string for a sequence of character glyphs to the list
23715 of strings between HEAD and TAIL. START is the index of the first
23716 glyph in row area AREA of glyph row ROW that is part of the new
23717 glyph string. END is the index of the last glyph in that glyph row
23718 area. X is the current output position assigned to the new glyph
23719 string constructed. HL overrides that face of the glyph; e.g. it
23720 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23721 right-most x-position of the drawing area. */
23723 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23729 face_id = (row)->glyphs[area][START].face_id; \
23731 s = alloca (sizeof *s); \
23732 char2b = alloca ((END - START) * sizeof *char2b); \
23733 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23734 append_glyph_string (&HEAD, &TAIL, s); \
23736 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23741 /* Add a glyph string for a composite sequence to the list of strings
23742 between HEAD and TAIL. START is the index of the first glyph in
23743 row area AREA of glyph row ROW that is part of the new glyph
23744 string. END is the index of the last glyph in that glyph row area.
23745 X is the current output position assigned to the new glyph string
23746 constructed. HL overrides that face of the glyph; e.g. it is
23747 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23748 x-position of the drawing area. */
23750 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23752 int face_id = (row)->glyphs[area][START].face_id; \
23753 struct face *base_face = FACE_FROM_ID (f, face_id); \
23754 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23755 struct composition *cmp = composition_table[cmp_id]; \
23757 struct glyph_string *first_s = NULL; \
23760 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23762 /* Make glyph_strings for each glyph sequence that is drawable by \
23763 the same face, and append them to HEAD/TAIL. */ \
23764 for (n = 0; n < cmp->glyph_len;) \
23766 s = alloca (sizeof *s); \
23767 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23768 append_glyph_string (&(HEAD), &(TAIL), s); \
23774 n = fill_composite_glyph_string (s, base_face, overlaps); \
23782 /* Add a glyph string for a glyph-string sequence to the list of strings
23783 between HEAD and TAIL. */
23785 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23789 Lisp_Object gstring; \
23791 face_id = (row)->glyphs[area][START].face_id; \
23792 gstring = (composition_gstring_from_id \
23793 ((row)->glyphs[area][START].u.cmp.id)); \
23794 s = alloca (sizeof *s); \
23795 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23796 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23797 append_glyph_string (&(HEAD), &(TAIL), s); \
23799 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23803 /* Add a glyph string for a sequence of glyphless character's glyphs
23804 to the list of strings between HEAD and TAIL. The meanings of
23805 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23807 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23812 face_id = (row)->glyphs[area][START].face_id; \
23814 s = alloca (sizeof *s); \
23815 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23816 append_glyph_string (&HEAD, &TAIL, s); \
23818 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23824 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23825 of AREA of glyph row ROW on window W between indices START and END.
23826 HL overrides the face for drawing glyph strings, e.g. it is
23827 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23828 x-positions of the drawing area.
23830 This is an ugly monster macro construct because we must use alloca
23831 to allocate glyph strings (because draw_glyphs can be called
23832 asynchronously). */
23834 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23837 HEAD = TAIL = NULL; \
23838 while (START < END) \
23840 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23841 switch (first_glyph->type) \
23844 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23848 case COMPOSITE_GLYPH: \
23849 if (first_glyph->u.cmp.automatic) \
23850 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23853 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23857 case STRETCH_GLYPH: \
23858 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23862 case IMAGE_GLYPH: \
23863 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23867 case GLYPHLESS_GLYPH: \
23868 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23878 set_glyph_string_background_width (s, START, LAST_X); \
23885 /* Draw glyphs between START and END in AREA of ROW on window W,
23886 starting at x-position X. X is relative to AREA in W. HL is a
23887 face-override with the following meaning:
23889 DRAW_NORMAL_TEXT draw normally
23890 DRAW_CURSOR draw in cursor face
23891 DRAW_MOUSE_FACE draw in mouse face.
23892 DRAW_INVERSE_VIDEO draw in mode line face
23893 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23894 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23896 If OVERLAPS is non-zero, draw only the foreground of characters and
23897 clip to the physical height of ROW. Non-zero value also defines
23898 the overlapping part to be drawn:
23900 OVERLAPS_PRED overlap with preceding rows
23901 OVERLAPS_SUCC overlap with succeeding rows
23902 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23903 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23905 Value is the x-position reached, relative to AREA of W. */
23908 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23909 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23910 enum draw_glyphs_face hl
, int overlaps
)
23912 struct glyph_string
*head
, *tail
;
23913 struct glyph_string
*s
;
23914 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23915 int i
, j
, x_reached
, last_x
, area_left
= 0;
23916 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23919 ALLOCATE_HDC (hdc
, f
);
23921 /* Let's rather be paranoid than getting a SEGV. */
23922 end
= min (end
, row
->used
[area
]);
23923 start
= clip_to_bounds (0, start
, end
);
23925 /* Translate X to frame coordinates. Set last_x to the right
23926 end of the drawing area. */
23927 if (row
->full_width_p
)
23929 /* X is relative to the left edge of W, without scroll bars
23931 area_left
= WINDOW_LEFT_EDGE_X (w
);
23932 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23936 area_left
= window_box_left (w
, area
);
23937 last_x
= area_left
+ window_box_width (w
, area
);
23941 /* Build a doubly-linked list of glyph_string structures between
23942 head and tail from what we have to draw. Note that the macro
23943 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23944 the reason we use a separate variable `i'. */
23946 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23948 x_reached
= tail
->x
+ tail
->background_width
;
23952 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23953 the row, redraw some glyphs in front or following the glyph
23954 strings built above. */
23955 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23957 struct glyph_string
*h
, *t
;
23958 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23959 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23960 int check_mouse_face
= 0;
23963 /* If mouse highlighting is on, we may need to draw adjacent
23964 glyphs using mouse-face highlighting. */
23965 if (area
== TEXT_AREA
&& row
->mouse_face_p
23966 && hlinfo
->mouse_face_beg_row
>= 0
23967 && hlinfo
->mouse_face_end_row
>= 0)
23969 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23971 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23972 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23974 check_mouse_face
= 1;
23975 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23976 ? hlinfo
->mouse_face_beg_col
: 0;
23977 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23978 ? hlinfo
->mouse_face_end_col
23979 : row
->used
[TEXT_AREA
];
23983 /* Compute overhangs for all glyph strings. */
23984 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23985 for (s
= head
; s
; s
= s
->next
)
23986 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23988 /* Prepend glyph strings for glyphs in front of the first glyph
23989 string that are overwritten because of the first glyph
23990 string's left overhang. The background of all strings
23991 prepended must be drawn because the first glyph string
23993 i
= left_overwritten (head
);
23996 enum draw_glyphs_face overlap_hl
;
23998 /* If this row contains mouse highlighting, attempt to draw
23999 the overlapped glyphs with the correct highlight. This
24000 code fails if the overlap encompasses more than one glyph
24001 and mouse-highlight spans only some of these glyphs.
24002 However, making it work perfectly involves a lot more
24003 code, and I don't know if the pathological case occurs in
24004 practice, so we'll stick to this for now. --- cyd */
24005 if (check_mouse_face
24006 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24007 overlap_hl
= DRAW_MOUSE_FACE
;
24009 overlap_hl
= DRAW_NORMAL_TEXT
;
24012 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24013 overlap_hl
, dummy_x
, last_x
);
24015 compute_overhangs_and_x (t
, head
->x
, 1);
24016 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24020 /* Prepend glyph strings for glyphs in front of the first glyph
24021 string that overwrite that glyph string because of their
24022 right overhang. For these strings, only the foreground must
24023 be drawn, because it draws over the glyph string at `head'.
24024 The background must not be drawn because this would overwrite
24025 right overhangs of preceding glyphs for which no glyph
24027 i
= left_overwriting (head
);
24030 enum draw_glyphs_face overlap_hl
;
24032 if (check_mouse_face
24033 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24034 overlap_hl
= DRAW_MOUSE_FACE
;
24036 overlap_hl
= DRAW_NORMAL_TEXT
;
24039 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24040 overlap_hl
, dummy_x
, last_x
);
24041 for (s
= h
; s
; s
= s
->next
)
24042 s
->background_filled_p
= 1;
24043 compute_overhangs_and_x (t
, head
->x
, 1);
24044 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24047 /* Append glyphs strings for glyphs following the last glyph
24048 string tail that are overwritten by tail. The background of
24049 these strings has to be drawn because tail's foreground draws
24051 i
= right_overwritten (tail
);
24054 enum draw_glyphs_face overlap_hl
;
24056 if (check_mouse_face
24057 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24058 overlap_hl
= DRAW_MOUSE_FACE
;
24060 overlap_hl
= DRAW_NORMAL_TEXT
;
24062 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24063 overlap_hl
, x
, last_x
);
24064 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24065 we don't have `end = i;' here. */
24066 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24067 append_glyph_string_lists (&head
, &tail
, h
, t
);
24071 /* Append glyph strings for glyphs following the last glyph
24072 string tail that overwrite tail. The foreground of such
24073 glyphs has to be drawn because it writes into the background
24074 of tail. The background must not be drawn because it could
24075 paint over the foreground of following glyphs. */
24076 i
= right_overwriting (tail
);
24079 enum draw_glyphs_face overlap_hl
;
24080 if (check_mouse_face
24081 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24082 overlap_hl
= DRAW_MOUSE_FACE
;
24084 overlap_hl
= DRAW_NORMAL_TEXT
;
24087 i
++; /* We must include the Ith glyph. */
24088 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24089 overlap_hl
, x
, last_x
);
24090 for (s
= h
; s
; s
= s
->next
)
24091 s
->background_filled_p
= 1;
24092 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24093 append_glyph_string_lists (&head
, &tail
, h
, t
);
24095 if (clip_head
|| clip_tail
)
24096 for (s
= head
; s
; s
= s
->next
)
24098 s
->clip_head
= clip_head
;
24099 s
->clip_tail
= clip_tail
;
24103 /* Draw all strings. */
24104 for (s
= head
; s
; s
= s
->next
)
24105 FRAME_RIF (f
)->draw_glyph_string (s
);
24108 /* When focus a sole frame and move horizontally, this sets on_p to 0
24109 causing a failure to erase prev cursor position. */
24110 if (area
== TEXT_AREA
24111 && !row
->full_width_p
24112 /* When drawing overlapping rows, only the glyph strings'
24113 foreground is drawn, which doesn't erase a cursor
24117 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24118 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24119 : (tail
? tail
->x
+ tail
->background_width
: x
));
24123 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24124 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24128 /* Value is the x-position up to which drawn, relative to AREA of W.
24129 This doesn't include parts drawn because of overhangs. */
24130 if (row
->full_width_p
)
24131 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24133 x_reached
-= area_left
;
24135 RELEASE_HDC (hdc
, f
);
24140 /* Expand row matrix if too narrow. Don't expand if area
24143 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24145 if (!it->f->fonts_changed \
24146 && (it->glyph_row->glyphs[area] \
24147 < it->glyph_row->glyphs[area + 1])) \
24149 it->w->ncols_scale_factor++; \
24150 it->f->fonts_changed = 1; \
24154 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24155 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24158 append_glyph (struct it
*it
)
24160 struct glyph
*glyph
;
24161 enum glyph_row_area area
= it
->area
;
24163 eassert (it
->glyph_row
);
24164 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24166 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24167 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24169 /* If the glyph row is reversed, we need to prepend the glyph
24170 rather than append it. */
24171 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24175 /* Make room for the additional glyph. */
24176 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24178 glyph
= it
->glyph_row
->glyphs
[area
];
24180 glyph
->charpos
= CHARPOS (it
->position
);
24181 glyph
->object
= it
->object
;
24182 if (it
->pixel_width
> 0)
24184 glyph
->pixel_width
= it
->pixel_width
;
24185 glyph
->padding_p
= 0;
24189 /* Assure at least 1-pixel width. Otherwise, cursor can't
24190 be displayed correctly. */
24191 glyph
->pixel_width
= 1;
24192 glyph
->padding_p
= 1;
24194 glyph
->ascent
= it
->ascent
;
24195 glyph
->descent
= it
->descent
;
24196 glyph
->voffset
= it
->voffset
;
24197 glyph
->type
= CHAR_GLYPH
;
24198 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24199 glyph
->multibyte_p
= it
->multibyte_p
;
24200 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24202 /* In R2L rows, the left and the right box edges need to be
24203 drawn in reverse direction. */
24204 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24205 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24209 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24210 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24212 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24213 || it
->phys_descent
> it
->descent
);
24214 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24215 glyph
->face_id
= it
->face_id
;
24216 glyph
->u
.ch
= it
->char_to_display
;
24217 glyph
->slice
.img
= null_glyph_slice
;
24218 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24221 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24222 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24224 glyph
->bidi_type
= it
->bidi_it
.type
;
24228 glyph
->resolved_level
= 0;
24229 glyph
->bidi_type
= UNKNOWN_BT
;
24231 ++it
->glyph_row
->used
[area
];
24234 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24237 /* Store one glyph for the composition IT->cmp_it.id in
24238 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24242 append_composite_glyph (struct it
*it
)
24244 struct glyph
*glyph
;
24245 enum glyph_row_area area
= it
->area
;
24247 eassert (it
->glyph_row
);
24249 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24250 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24252 /* If the glyph row is reversed, we need to prepend the glyph
24253 rather than append it. */
24254 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24258 /* Make room for the new glyph. */
24259 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24261 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24263 glyph
->charpos
= it
->cmp_it
.charpos
;
24264 glyph
->object
= it
->object
;
24265 glyph
->pixel_width
= it
->pixel_width
;
24266 glyph
->ascent
= it
->ascent
;
24267 glyph
->descent
= it
->descent
;
24268 glyph
->voffset
= it
->voffset
;
24269 glyph
->type
= COMPOSITE_GLYPH
;
24270 if (it
->cmp_it
.ch
< 0)
24272 glyph
->u
.cmp
.automatic
= 0;
24273 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24274 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24278 glyph
->u
.cmp
.automatic
= 1;
24279 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24280 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24281 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24283 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24284 glyph
->multibyte_p
= it
->multibyte_p
;
24285 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24287 /* In R2L rows, the left and the right box edges need to be
24288 drawn in reverse direction. */
24289 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24290 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24294 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24295 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24297 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24298 || it
->phys_descent
> it
->descent
);
24299 glyph
->padding_p
= 0;
24300 glyph
->glyph_not_available_p
= 0;
24301 glyph
->face_id
= it
->face_id
;
24302 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24305 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24306 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24308 glyph
->bidi_type
= it
->bidi_it
.type
;
24310 ++it
->glyph_row
->used
[area
];
24313 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24317 /* Change IT->ascent and IT->height according to the setting of
24321 take_vertical_position_into_account (struct it
*it
)
24325 if (it
->voffset
< 0)
24326 /* Increase the ascent so that we can display the text higher
24328 it
->ascent
-= it
->voffset
;
24330 /* Increase the descent so that we can display the text lower
24332 it
->descent
+= it
->voffset
;
24337 /* Produce glyphs/get display metrics for the image IT is loaded with.
24338 See the description of struct display_iterator in dispextern.h for
24339 an overview of struct display_iterator. */
24342 produce_image_glyph (struct it
*it
)
24346 int glyph_ascent
, crop
;
24347 struct glyph_slice slice
;
24349 eassert (it
->what
== IT_IMAGE
);
24351 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24353 /* Make sure X resources of the face is loaded. */
24354 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24356 if (it
->image_id
< 0)
24358 /* Fringe bitmap. */
24359 it
->ascent
= it
->phys_ascent
= 0;
24360 it
->descent
= it
->phys_descent
= 0;
24361 it
->pixel_width
= 0;
24366 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24368 /* Make sure X resources of the image is loaded. */
24369 prepare_image_for_display (it
->f
, img
);
24371 slice
.x
= slice
.y
= 0;
24372 slice
.width
= img
->width
;
24373 slice
.height
= img
->height
;
24375 if (INTEGERP (it
->slice
.x
))
24376 slice
.x
= XINT (it
->slice
.x
);
24377 else if (FLOATP (it
->slice
.x
))
24378 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24380 if (INTEGERP (it
->slice
.y
))
24381 slice
.y
= XINT (it
->slice
.y
);
24382 else if (FLOATP (it
->slice
.y
))
24383 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24385 if (INTEGERP (it
->slice
.width
))
24386 slice
.width
= XINT (it
->slice
.width
);
24387 else if (FLOATP (it
->slice
.width
))
24388 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24390 if (INTEGERP (it
->slice
.height
))
24391 slice
.height
= XINT (it
->slice
.height
);
24392 else if (FLOATP (it
->slice
.height
))
24393 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24395 if (slice
.x
>= img
->width
)
24396 slice
.x
= img
->width
;
24397 if (slice
.y
>= img
->height
)
24398 slice
.y
= img
->height
;
24399 if (slice
.x
+ slice
.width
>= img
->width
)
24400 slice
.width
= img
->width
- slice
.x
;
24401 if (slice
.y
+ slice
.height
> img
->height
)
24402 slice
.height
= img
->height
- slice
.y
;
24404 if (slice
.width
== 0 || slice
.height
== 0)
24407 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24409 it
->descent
= slice
.height
- glyph_ascent
;
24411 it
->descent
+= img
->vmargin
;
24412 if (slice
.y
+ slice
.height
== img
->height
)
24413 it
->descent
+= img
->vmargin
;
24414 it
->phys_descent
= it
->descent
;
24416 it
->pixel_width
= slice
.width
;
24418 it
->pixel_width
+= img
->hmargin
;
24419 if (slice
.x
+ slice
.width
== img
->width
)
24420 it
->pixel_width
+= img
->hmargin
;
24422 /* It's quite possible for images to have an ascent greater than
24423 their height, so don't get confused in that case. */
24424 if (it
->descent
< 0)
24429 if (face
->box
!= FACE_NO_BOX
)
24431 if (face
->box_line_width
> 0)
24434 it
->ascent
+= face
->box_line_width
;
24435 if (slice
.y
+ slice
.height
== img
->height
)
24436 it
->descent
+= face
->box_line_width
;
24439 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24440 it
->pixel_width
+= eabs (face
->box_line_width
);
24441 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24442 it
->pixel_width
+= eabs (face
->box_line_width
);
24445 take_vertical_position_into_account (it
);
24447 /* Automatically crop wide image glyphs at right edge so we can
24448 draw the cursor on same display row. */
24449 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24450 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24452 it
->pixel_width
-= crop
;
24453 slice
.width
-= crop
;
24458 struct glyph
*glyph
;
24459 enum glyph_row_area area
= it
->area
;
24461 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24462 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24464 glyph
->charpos
= CHARPOS (it
->position
);
24465 glyph
->object
= it
->object
;
24466 glyph
->pixel_width
= it
->pixel_width
;
24467 glyph
->ascent
= glyph_ascent
;
24468 glyph
->descent
= it
->descent
;
24469 glyph
->voffset
= it
->voffset
;
24470 glyph
->type
= IMAGE_GLYPH
;
24471 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24472 glyph
->multibyte_p
= it
->multibyte_p
;
24473 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24475 /* In R2L rows, the left and the right box edges need to be
24476 drawn in reverse direction. */
24477 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24478 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24482 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24483 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24485 glyph
->overlaps_vertically_p
= 0;
24486 glyph
->padding_p
= 0;
24487 glyph
->glyph_not_available_p
= 0;
24488 glyph
->face_id
= it
->face_id
;
24489 glyph
->u
.img_id
= img
->id
;
24490 glyph
->slice
.img
= slice
;
24491 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24494 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24495 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24497 glyph
->bidi_type
= it
->bidi_it
.type
;
24499 ++it
->glyph_row
->used
[area
];
24502 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24507 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24508 of the glyph, WIDTH and HEIGHT are the width and height of the
24509 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24512 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24513 int width
, int height
, int ascent
)
24515 struct glyph
*glyph
;
24516 enum glyph_row_area area
= it
->area
;
24518 eassert (ascent
>= 0 && ascent
<= height
);
24520 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24521 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24523 /* If the glyph row is reversed, we need to prepend the glyph
24524 rather than append it. */
24525 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24529 /* Make room for the additional glyph. */
24530 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24532 glyph
= it
->glyph_row
->glyphs
[area
];
24534 glyph
->charpos
= CHARPOS (it
->position
);
24535 glyph
->object
= object
;
24536 glyph
->pixel_width
= width
;
24537 glyph
->ascent
= ascent
;
24538 glyph
->descent
= height
- ascent
;
24539 glyph
->voffset
= it
->voffset
;
24540 glyph
->type
= STRETCH_GLYPH
;
24541 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24542 glyph
->multibyte_p
= it
->multibyte_p
;
24543 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24545 /* In R2L rows, the left and the right box edges need to be
24546 drawn in reverse direction. */
24547 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24548 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24552 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24553 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24555 glyph
->overlaps_vertically_p
= 0;
24556 glyph
->padding_p
= 0;
24557 glyph
->glyph_not_available_p
= 0;
24558 glyph
->face_id
= it
->face_id
;
24559 glyph
->u
.stretch
.ascent
= ascent
;
24560 glyph
->u
.stretch
.height
= height
;
24561 glyph
->slice
.img
= null_glyph_slice
;
24562 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24565 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24566 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24568 glyph
->bidi_type
= it
->bidi_it
.type
;
24572 glyph
->resolved_level
= 0;
24573 glyph
->bidi_type
= UNKNOWN_BT
;
24575 ++it
->glyph_row
->used
[area
];
24578 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24581 #endif /* HAVE_WINDOW_SYSTEM */
24583 /* Produce a stretch glyph for iterator IT. IT->object is the value
24584 of the glyph property displayed. The value must be a list
24585 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24588 1. `:width WIDTH' specifies that the space should be WIDTH *
24589 canonical char width wide. WIDTH may be an integer or floating
24592 2. `:relative-width FACTOR' specifies that the width of the stretch
24593 should be computed from the width of the first character having the
24594 `glyph' property, and should be FACTOR times that width.
24596 3. `:align-to HPOS' specifies that the space should be wide enough
24597 to reach HPOS, a value in canonical character units.
24599 Exactly one of the above pairs must be present.
24601 4. `:height HEIGHT' specifies that the height of the stretch produced
24602 should be HEIGHT, measured in canonical character units.
24604 5. `:relative-height FACTOR' specifies that the height of the
24605 stretch should be FACTOR times the height of the characters having
24606 the glyph property.
24608 Either none or exactly one of 4 or 5 must be present.
24610 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24611 of the stretch should be used for the ascent of the stretch.
24612 ASCENT must be in the range 0 <= ASCENT <= 100. */
24615 produce_stretch_glyph (struct it
*it
)
24617 /* (space :width WIDTH :height HEIGHT ...) */
24618 Lisp_Object prop
, plist
;
24619 int width
= 0, height
= 0, align_to
= -1;
24620 int zero_width_ok_p
= 0;
24622 struct font
*font
= NULL
;
24624 #ifdef HAVE_WINDOW_SYSTEM
24626 int zero_height_ok_p
= 0;
24628 if (FRAME_WINDOW_P (it
->f
))
24630 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24631 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24632 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24636 /* List should start with `space'. */
24637 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24638 plist
= XCDR (it
->object
);
24640 /* Compute the width of the stretch. */
24641 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24642 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24644 /* Absolute width `:width WIDTH' specified and valid. */
24645 zero_width_ok_p
= 1;
24648 #ifdef HAVE_WINDOW_SYSTEM
24649 else if (FRAME_WINDOW_P (it
->f
)
24650 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24652 /* Relative width `:relative-width FACTOR' specified and valid.
24653 Compute the width of the characters having the `glyph'
24656 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24659 if (it
->multibyte_p
)
24660 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24663 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24664 if (! ASCII_CHAR_P (it2
.c
))
24665 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24668 it2
.glyph_row
= NULL
;
24669 it2
.what
= IT_CHARACTER
;
24670 x_produce_glyphs (&it2
);
24671 width
= NUMVAL (prop
) * it2
.pixel_width
;
24673 #endif /* HAVE_WINDOW_SYSTEM */
24674 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24675 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24677 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24678 align_to
= (align_to
< 0
24680 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24681 else if (align_to
< 0)
24682 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24683 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24684 zero_width_ok_p
= 1;
24687 /* Nothing specified -> width defaults to canonical char width. */
24688 width
= FRAME_COLUMN_WIDTH (it
->f
);
24690 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24693 #ifdef HAVE_WINDOW_SYSTEM
24694 /* Compute height. */
24695 if (FRAME_WINDOW_P (it
->f
))
24697 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24698 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24701 zero_height_ok_p
= 1;
24703 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24705 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24707 height
= FONT_HEIGHT (font
);
24709 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24712 /* Compute percentage of height used for ascent. If
24713 `:ascent ASCENT' is present and valid, use that. Otherwise,
24714 derive the ascent from the font in use. */
24715 if (prop
= Fplist_get (plist
, QCascent
),
24716 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24717 ascent
= height
* NUMVAL (prop
) / 100.0;
24718 else if (!NILP (prop
)
24719 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24720 ascent
= min (max (0, (int)tem
), height
);
24722 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24725 #endif /* HAVE_WINDOW_SYSTEM */
24728 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24729 && it
->current_x
+ width
> it
->last_visible_x
)
24731 width
= it
->last_visible_x
- it
->current_x
;
24732 #ifdef HAVE_WINDOW_SYSTEM
24733 /* Subtract one more pixel from the stretch width, but only on
24734 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24735 width
-= FRAME_WINDOW_P (it
->f
);
24739 if (width
> 0 && height
> 0 && it
->glyph_row
)
24741 Lisp_Object o_object
= it
->object
;
24742 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24745 if (!STRINGP (object
))
24746 object
= it
->w
->contents
;
24747 #ifdef HAVE_WINDOW_SYSTEM
24748 if (FRAME_WINDOW_P (it
->f
))
24749 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24753 it
->object
= object
;
24754 it
->char_to_display
= ' ';
24755 it
->pixel_width
= it
->len
= 1;
24757 tty_append_glyph (it
);
24758 it
->object
= o_object
;
24762 it
->pixel_width
= width
;
24763 #ifdef HAVE_WINDOW_SYSTEM
24764 if (FRAME_WINDOW_P (it
->f
))
24766 it
->ascent
= it
->phys_ascent
= ascent
;
24767 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24768 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24769 take_vertical_position_into_account (it
);
24773 it
->nglyphs
= width
;
24776 /* Get information about special display element WHAT in an
24777 environment described by IT. WHAT is one of IT_TRUNCATION or
24778 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24779 non-null glyph_row member. This function ensures that fields like
24780 face_id, c, len of IT are left untouched. */
24783 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24790 temp_it
.object
= make_number (0);
24791 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24793 if (what
== IT_CONTINUATION
)
24795 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24796 if (it
->bidi_it
.paragraph_dir
== R2L
)
24797 SET_GLYPH_FROM_CHAR (glyph
, '/');
24799 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24801 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24803 /* FIXME: Should we mirror GC for R2L lines? */
24804 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24805 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24808 else if (what
== IT_TRUNCATION
)
24810 /* Truncation glyph. */
24811 SET_GLYPH_FROM_CHAR (glyph
, '$');
24813 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24815 /* FIXME: Should we mirror GC for R2L lines? */
24816 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24817 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24823 #ifdef HAVE_WINDOW_SYSTEM
24824 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24825 is turned off, we precede the truncation/continuation glyphs by a
24826 stretch glyph whose width is computed such that these special
24827 glyphs are aligned at the window margin, even when very different
24828 fonts are used in different glyph rows. */
24829 if (FRAME_WINDOW_P (temp_it
.f
)
24830 /* init_iterator calls this with it->glyph_row == NULL, and it
24831 wants only the pixel width of the truncation/continuation
24833 && temp_it
.glyph_row
24834 /* insert_left_trunc_glyphs calls us at the beginning of the
24835 row, and it has its own calculation of the stretch glyph
24837 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24838 && (temp_it
.glyph_row
->reversed_p
24839 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24840 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24842 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24844 if (stretch_width
> 0)
24846 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24847 struct font
*font
=
24848 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24849 int stretch_ascent
=
24850 (((temp_it
.ascent
+ temp_it
.descent
)
24851 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24853 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24854 temp_it
.ascent
+ temp_it
.descent
,
24861 temp_it
.what
= IT_CHARACTER
;
24863 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24864 temp_it
.face_id
= GLYPH_FACE (glyph
);
24865 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24867 PRODUCE_GLYPHS (&temp_it
);
24868 it
->pixel_width
= temp_it
.pixel_width
;
24869 it
->nglyphs
= temp_it
.pixel_width
;
24872 #ifdef HAVE_WINDOW_SYSTEM
24874 /* Calculate line-height and line-spacing properties.
24875 An integer value specifies explicit pixel value.
24876 A float value specifies relative value to current face height.
24877 A cons (float . face-name) specifies relative value to
24878 height of specified face font.
24880 Returns height in pixels, or nil. */
24884 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24885 int boff
, int override
)
24887 Lisp_Object face_name
= Qnil
;
24888 int ascent
, descent
, height
;
24890 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24895 face_name
= XCAR (val
);
24897 if (!NUMBERP (val
))
24898 val
= make_number (1);
24899 if (NILP (face_name
))
24901 height
= it
->ascent
+ it
->descent
;
24906 if (NILP (face_name
))
24908 font
= FRAME_FONT (it
->f
);
24909 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24911 else if (EQ (face_name
, Qt
))
24920 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24922 return make_number (-1);
24924 face
= FACE_FROM_ID (it
->f
, face_id
);
24927 return make_number (-1);
24928 boff
= font
->baseline_offset
;
24929 if (font
->vertical_centering
)
24930 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24933 ascent
= FONT_BASE (font
) + boff
;
24934 descent
= FONT_DESCENT (font
) - boff
;
24938 it
->override_ascent
= ascent
;
24939 it
->override_descent
= descent
;
24940 it
->override_boff
= boff
;
24943 height
= ascent
+ descent
;
24947 height
= (int)(XFLOAT_DATA (val
) * height
);
24948 else if (INTEGERP (val
))
24949 height
*= XINT (val
);
24951 return make_number (height
);
24955 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24956 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24957 and only if this is for a character for which no font was found.
24959 If the display method (it->glyphless_method) is
24960 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24961 length of the acronym or the hexadecimal string, UPPER_XOFF and
24962 UPPER_YOFF are pixel offsets for the upper part of the string,
24963 LOWER_XOFF and LOWER_YOFF are for the lower part.
24965 For the other display methods, LEN through LOWER_YOFF are zero. */
24968 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24969 short upper_xoff
, short upper_yoff
,
24970 short lower_xoff
, short lower_yoff
)
24972 struct glyph
*glyph
;
24973 enum glyph_row_area area
= it
->area
;
24975 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24976 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24978 /* If the glyph row is reversed, we need to prepend the glyph
24979 rather than append it. */
24980 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24984 /* Make room for the additional glyph. */
24985 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24987 glyph
= it
->glyph_row
->glyphs
[area
];
24989 glyph
->charpos
= CHARPOS (it
->position
);
24990 glyph
->object
= it
->object
;
24991 glyph
->pixel_width
= it
->pixel_width
;
24992 glyph
->ascent
= it
->ascent
;
24993 glyph
->descent
= it
->descent
;
24994 glyph
->voffset
= it
->voffset
;
24995 glyph
->type
= GLYPHLESS_GLYPH
;
24996 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24997 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24998 glyph
->u
.glyphless
.len
= len
;
24999 glyph
->u
.glyphless
.ch
= it
->c
;
25000 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25001 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25002 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25003 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25004 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25005 glyph
->multibyte_p
= it
->multibyte_p
;
25006 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25008 /* In R2L rows, the left and the right box edges need to be
25009 drawn in reverse direction. */
25010 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25011 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25015 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25016 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25018 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25019 || it
->phys_descent
> it
->descent
);
25020 glyph
->padding_p
= 0;
25021 glyph
->glyph_not_available_p
= 0;
25022 glyph
->face_id
= face_id
;
25023 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25026 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25027 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25029 glyph
->bidi_type
= it
->bidi_it
.type
;
25031 ++it
->glyph_row
->used
[area
];
25034 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25038 /* Produce a glyph for a glyphless character for iterator IT.
25039 IT->glyphless_method specifies which method to use for displaying
25040 the character. See the description of enum
25041 glyphless_display_method in dispextern.h for the detail.
25043 FOR_NO_FONT is nonzero if and only if this is for a character for
25044 which no font was found. ACRONYM, if non-nil, is an acronym string
25045 for the character. */
25048 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25053 int base_width
, base_height
, width
, height
;
25054 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25057 /* Get the metrics of the base font. We always refer to the current
25059 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25060 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25061 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25062 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25063 base_height
= it
->ascent
+ it
->descent
;
25064 base_width
= font
->average_width
;
25066 face_id
= merge_glyphless_glyph_face (it
);
25068 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25070 it
->pixel_width
= THIN_SPACE_WIDTH
;
25072 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25074 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25076 width
= CHAR_WIDTH (it
->c
);
25079 else if (width
> 4)
25081 it
->pixel_width
= base_width
* width
;
25083 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25089 unsigned int code
[6];
25091 int ascent
, descent
;
25092 struct font_metrics metrics_upper
, metrics_lower
;
25094 face
= FACE_FROM_ID (it
->f
, face_id
);
25095 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25096 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25098 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25100 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25101 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25102 if (CONSP (acronym
))
25103 acronym
= XCAR (acronym
);
25104 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25108 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25109 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25112 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25113 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25114 upper_len
= (len
+ 1) / 2;
25115 font
->driver
->text_extents (font
, code
, upper_len
,
25117 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25122 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25123 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25124 upper_xoff
= upper_yoff
= 2; /* the typical case */
25125 if (base_width
>= width
)
25127 /* Align the upper to the left, the lower to the right. */
25128 it
->pixel_width
= base_width
;
25129 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25133 /* Center the shorter one. */
25134 it
->pixel_width
= width
;
25135 if (metrics_upper
.width
>= metrics_lower
.width
)
25136 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25139 /* FIXME: This code doesn't look right. It formerly was
25140 missing the "lower_xoff = 0;", which couldn't have
25141 been right since it left lower_xoff uninitialized. */
25143 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25147 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25148 top, bottom, and between upper and lower strings. */
25149 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25150 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25151 /* Center vertically.
25152 H:base_height, D:base_descent
25153 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25155 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25156 descent = D - H/2 + h/2;
25157 lower_yoff = descent - 2 - ld;
25158 upper_yoff = lower_yoff - la - 1 - ud; */
25159 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25160 descent
= it
->descent
- (base_height
- height
) / 2;
25161 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25162 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25163 - metrics_upper
.descent
);
25164 /* Don't make the height shorter than the base height. */
25165 if (height
> base_height
)
25167 it
->ascent
= ascent
;
25168 it
->descent
= descent
;
25172 it
->phys_ascent
= it
->ascent
;
25173 it
->phys_descent
= it
->descent
;
25175 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25176 upper_xoff
, upper_yoff
,
25177 lower_xoff
, lower_yoff
);
25179 take_vertical_position_into_account (it
);
25184 Produce glyphs/get display metrics for the display element IT is
25185 loaded with. See the description of struct it in dispextern.h
25186 for an overview of struct it. */
25189 x_produce_glyphs (struct it
*it
)
25191 int extra_line_spacing
= it
->extra_line_spacing
;
25193 it
->glyph_not_available_p
= 0;
25195 if (it
->what
== IT_CHARACTER
)
25198 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25199 struct font
*font
= face
->font
;
25200 struct font_metrics
*pcm
= NULL
;
25201 int boff
; /* Baseline offset. */
25205 /* When no suitable font is found, display this character by
25206 the method specified in the first extra slot of
25207 Vglyphless_char_display. */
25208 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25210 eassert (it
->what
== IT_GLYPHLESS
);
25211 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25215 boff
= font
->baseline_offset
;
25216 if (font
->vertical_centering
)
25217 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25219 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25225 if (it
->override_ascent
>= 0)
25227 it
->ascent
= it
->override_ascent
;
25228 it
->descent
= it
->override_descent
;
25229 boff
= it
->override_boff
;
25233 it
->ascent
= FONT_BASE (font
) + boff
;
25234 it
->descent
= FONT_DESCENT (font
) - boff
;
25237 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25239 pcm
= get_per_char_metric (font
, &char2b
);
25240 if (pcm
->width
== 0
25241 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25247 it
->phys_ascent
= pcm
->ascent
+ boff
;
25248 it
->phys_descent
= pcm
->descent
- boff
;
25249 it
->pixel_width
= pcm
->width
;
25253 it
->glyph_not_available_p
= 1;
25254 it
->phys_ascent
= it
->ascent
;
25255 it
->phys_descent
= it
->descent
;
25256 it
->pixel_width
= font
->space_width
;
25259 if (it
->constrain_row_ascent_descent_p
)
25261 if (it
->descent
> it
->max_descent
)
25263 it
->ascent
+= it
->descent
- it
->max_descent
;
25264 it
->descent
= it
->max_descent
;
25266 if (it
->ascent
> it
->max_ascent
)
25268 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25269 it
->ascent
= it
->max_ascent
;
25271 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25272 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25273 extra_line_spacing
= 0;
25276 /* If this is a space inside a region of text with
25277 `space-width' property, change its width. */
25278 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25280 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25282 /* If face has a box, add the box thickness to the character
25283 height. If character has a box line to the left and/or
25284 right, add the box line width to the character's width. */
25285 if (face
->box
!= FACE_NO_BOX
)
25287 int thick
= face
->box_line_width
;
25291 it
->ascent
+= thick
;
25292 it
->descent
+= thick
;
25297 if (it
->start_of_box_run_p
)
25298 it
->pixel_width
+= thick
;
25299 if (it
->end_of_box_run_p
)
25300 it
->pixel_width
+= thick
;
25303 /* If face has an overline, add the height of the overline
25304 (1 pixel) and a 1 pixel margin to the character height. */
25305 if (face
->overline_p
)
25306 it
->ascent
+= overline_margin
;
25308 if (it
->constrain_row_ascent_descent_p
)
25310 if (it
->ascent
> it
->max_ascent
)
25311 it
->ascent
= it
->max_ascent
;
25312 if (it
->descent
> it
->max_descent
)
25313 it
->descent
= it
->max_descent
;
25316 take_vertical_position_into_account (it
);
25318 /* If we have to actually produce glyphs, do it. */
25323 /* Translate a space with a `space-width' property
25324 into a stretch glyph. */
25325 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25326 / FONT_HEIGHT (font
));
25327 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25328 it
->ascent
+ it
->descent
, ascent
);
25333 /* If characters with lbearing or rbearing are displayed
25334 in this line, record that fact in a flag of the
25335 glyph row. This is used to optimize X output code. */
25336 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25337 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25339 if (! stretched_p
&& it
->pixel_width
== 0)
25340 /* We assure that all visible glyphs have at least 1-pixel
25342 it
->pixel_width
= 1;
25344 else if (it
->char_to_display
== '\n')
25346 /* A newline has no width, but we need the height of the
25347 line. But if previous part of the line sets a height,
25348 don't increase that height. */
25350 Lisp_Object height
;
25351 Lisp_Object total_height
= Qnil
;
25353 it
->override_ascent
= -1;
25354 it
->pixel_width
= 0;
25357 height
= get_it_property (it
, Qline_height
);
25358 /* Split (line-height total-height) list. */
25360 && CONSP (XCDR (height
))
25361 && NILP (XCDR (XCDR (height
))))
25363 total_height
= XCAR (XCDR (height
));
25364 height
= XCAR (height
);
25366 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25368 if (it
->override_ascent
>= 0)
25370 it
->ascent
= it
->override_ascent
;
25371 it
->descent
= it
->override_descent
;
25372 boff
= it
->override_boff
;
25376 it
->ascent
= FONT_BASE (font
) + boff
;
25377 it
->descent
= FONT_DESCENT (font
) - boff
;
25380 if (EQ (height
, Qt
))
25382 if (it
->descent
> it
->max_descent
)
25384 it
->ascent
+= it
->descent
- it
->max_descent
;
25385 it
->descent
= it
->max_descent
;
25387 if (it
->ascent
> it
->max_ascent
)
25389 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25390 it
->ascent
= it
->max_ascent
;
25392 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25393 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25394 it
->constrain_row_ascent_descent_p
= 1;
25395 extra_line_spacing
= 0;
25399 Lisp_Object spacing
;
25401 it
->phys_ascent
= it
->ascent
;
25402 it
->phys_descent
= it
->descent
;
25404 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25405 && face
->box
!= FACE_NO_BOX
25406 && face
->box_line_width
> 0)
25408 it
->ascent
+= face
->box_line_width
;
25409 it
->descent
+= face
->box_line_width
;
25412 && XINT (height
) > it
->ascent
+ it
->descent
)
25413 it
->ascent
= XINT (height
) - it
->descent
;
25415 if (!NILP (total_height
))
25416 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25419 spacing
= get_it_property (it
, Qline_spacing
);
25420 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25422 if (INTEGERP (spacing
))
25424 extra_line_spacing
= XINT (spacing
);
25425 if (!NILP (total_height
))
25426 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25430 else /* i.e. (it->char_to_display == '\t') */
25432 if (font
->space_width
> 0)
25434 int tab_width
= it
->tab_width
* font
->space_width
;
25435 int x
= it
->current_x
+ it
->continuation_lines_width
;
25436 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25438 /* If the distance from the current position to the next tab
25439 stop is less than a space character width, use the
25440 tab stop after that. */
25441 if (next_tab_x
- x
< font
->space_width
)
25442 next_tab_x
+= tab_width
;
25444 it
->pixel_width
= next_tab_x
- x
;
25446 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25447 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25451 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25452 it
->ascent
+ it
->descent
, it
->ascent
);
25457 it
->pixel_width
= 0;
25462 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25464 /* A static composition.
25466 Note: A composition is represented as one glyph in the
25467 glyph matrix. There are no padding glyphs.
25469 Important note: pixel_width, ascent, and descent are the
25470 values of what is drawn by draw_glyphs (i.e. the values of
25471 the overall glyphs composed). */
25472 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25473 int boff
; /* baseline offset */
25474 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25475 int glyph_len
= cmp
->glyph_len
;
25476 struct font
*font
= face
->font
;
25480 /* If we have not yet calculated pixel size data of glyphs of
25481 the composition for the current face font, calculate them
25482 now. Theoretically, we have to check all fonts for the
25483 glyphs, but that requires much time and memory space. So,
25484 here we check only the font of the first glyph. This may
25485 lead to incorrect display, but it's very rare, and C-l
25486 (recenter-top-bottom) can correct the display anyway. */
25487 if (! cmp
->font
|| cmp
->font
!= font
)
25489 /* Ascent and descent of the font of the first character
25490 of this composition (adjusted by baseline offset).
25491 Ascent and descent of overall glyphs should not be less
25492 than these, respectively. */
25493 int font_ascent
, font_descent
, font_height
;
25494 /* Bounding box of the overall glyphs. */
25495 int leftmost
, rightmost
, lowest
, highest
;
25496 int lbearing
, rbearing
;
25497 int i
, width
, ascent
, descent
;
25498 int left_padded
= 0, right_padded
= 0;
25499 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25501 struct font_metrics
*pcm
;
25502 int font_not_found_p
;
25505 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25506 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25508 if (glyph_len
< cmp
->glyph_len
)
25510 for (i
= 0; i
< glyph_len
; i
++)
25512 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25514 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25519 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25520 : IT_CHARPOS (*it
));
25521 /* If no suitable font is found, use the default font. */
25522 font_not_found_p
= font
== NULL
;
25523 if (font_not_found_p
)
25525 face
= face
->ascii_face
;
25528 boff
= font
->baseline_offset
;
25529 if (font
->vertical_centering
)
25530 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25531 font_ascent
= FONT_BASE (font
) + boff
;
25532 font_descent
= FONT_DESCENT (font
) - boff
;
25533 font_height
= FONT_HEIGHT (font
);
25538 if (! font_not_found_p
)
25540 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25542 pcm
= get_per_char_metric (font
, &char2b
);
25545 /* Initialize the bounding box. */
25548 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25549 ascent
= pcm
->ascent
;
25550 descent
= pcm
->descent
;
25551 lbearing
= pcm
->lbearing
;
25552 rbearing
= pcm
->rbearing
;
25556 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25557 ascent
= FONT_BASE (font
);
25558 descent
= FONT_DESCENT (font
);
25565 lowest
= - descent
+ boff
;
25566 highest
= ascent
+ boff
;
25568 if (! font_not_found_p
25569 && font
->default_ascent
25570 && CHAR_TABLE_P (Vuse_default_ascent
)
25571 && !NILP (Faref (Vuse_default_ascent
,
25572 make_number (it
->char_to_display
))))
25573 highest
= font
->default_ascent
+ boff
;
25575 /* Draw the first glyph at the normal position. It may be
25576 shifted to right later if some other glyphs are drawn
25578 cmp
->offsets
[i
* 2] = 0;
25579 cmp
->offsets
[i
* 2 + 1] = boff
;
25580 cmp
->lbearing
= lbearing
;
25581 cmp
->rbearing
= rbearing
;
25583 /* Set cmp->offsets for the remaining glyphs. */
25584 for (i
++; i
< glyph_len
; i
++)
25586 int left
, right
, btm
, top
;
25587 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25589 struct face
*this_face
;
25593 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25594 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25595 font
= this_face
->font
;
25601 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25603 pcm
= get_per_char_metric (font
, &char2b
);
25606 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25609 width
= pcm
->width
;
25610 ascent
= pcm
->ascent
;
25611 descent
= pcm
->descent
;
25612 lbearing
= pcm
->lbearing
;
25613 rbearing
= pcm
->rbearing
;
25614 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25616 /* Relative composition with or without
25617 alternate chars. */
25618 left
= (leftmost
+ rightmost
- width
) / 2;
25619 btm
= - descent
+ boff
;
25620 if (font
->relative_compose
25621 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25622 || NILP (Faref (Vignore_relative_composition
,
25623 make_number (ch
)))))
25626 if (- descent
>= font
->relative_compose
)
25627 /* One extra pixel between two glyphs. */
25629 else if (ascent
<= 0)
25630 /* One extra pixel between two glyphs. */
25631 btm
= lowest
- 1 - ascent
- descent
;
25636 /* A composition rule is specified by an integer
25637 value that encodes global and new reference
25638 points (GREF and NREF). GREF and NREF are
25639 specified by numbers as below:
25641 0---1---2 -- ascent
25645 9--10--11 -- center
25647 ---3---4---5--- baseline
25649 6---7---8 -- descent
25651 int rule
= COMPOSITION_RULE (cmp
, i
);
25652 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25654 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25655 grefx
= gref
% 3, nrefx
= nref
% 3;
25656 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25658 xoff
= font_height
* (xoff
- 128) / 256;
25660 yoff
= font_height
* (yoff
- 128) / 256;
25663 + grefx
* (rightmost
- leftmost
) / 2
25664 - nrefx
* width
/ 2
25667 btm
= ((grefy
== 0 ? highest
25669 : grefy
== 2 ? lowest
25670 : (highest
+ lowest
) / 2)
25671 - (nrefy
== 0 ? ascent
+ descent
25672 : nrefy
== 1 ? descent
- boff
25674 : (ascent
+ descent
) / 2)
25678 cmp
->offsets
[i
* 2] = left
;
25679 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25681 /* Update the bounding box of the overall glyphs. */
25684 right
= left
+ width
;
25685 if (left
< leftmost
)
25687 if (right
> rightmost
)
25690 top
= btm
+ descent
+ ascent
;
25696 if (cmp
->lbearing
> left
+ lbearing
)
25697 cmp
->lbearing
= left
+ lbearing
;
25698 if (cmp
->rbearing
< left
+ rbearing
)
25699 cmp
->rbearing
= left
+ rbearing
;
25703 /* If there are glyphs whose x-offsets are negative,
25704 shift all glyphs to the right and make all x-offsets
25708 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25709 cmp
->offsets
[i
* 2] -= leftmost
;
25710 rightmost
-= leftmost
;
25711 cmp
->lbearing
-= leftmost
;
25712 cmp
->rbearing
-= leftmost
;
25715 if (left_padded
&& cmp
->lbearing
< 0)
25717 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25718 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25719 rightmost
-= cmp
->lbearing
;
25720 cmp
->rbearing
-= cmp
->lbearing
;
25723 if (right_padded
&& rightmost
< cmp
->rbearing
)
25725 rightmost
= cmp
->rbearing
;
25728 cmp
->pixel_width
= rightmost
;
25729 cmp
->ascent
= highest
;
25730 cmp
->descent
= - lowest
;
25731 if (cmp
->ascent
< font_ascent
)
25732 cmp
->ascent
= font_ascent
;
25733 if (cmp
->descent
< font_descent
)
25734 cmp
->descent
= font_descent
;
25738 && (cmp
->lbearing
< 0
25739 || cmp
->rbearing
> cmp
->pixel_width
))
25740 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25742 it
->pixel_width
= cmp
->pixel_width
;
25743 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25744 it
->descent
= it
->phys_descent
= cmp
->descent
;
25745 if (face
->box
!= FACE_NO_BOX
)
25747 int thick
= face
->box_line_width
;
25751 it
->ascent
+= thick
;
25752 it
->descent
+= thick
;
25757 if (it
->start_of_box_run_p
)
25758 it
->pixel_width
+= thick
;
25759 if (it
->end_of_box_run_p
)
25760 it
->pixel_width
+= thick
;
25763 /* If face has an overline, add the height of the overline
25764 (1 pixel) and a 1 pixel margin to the character height. */
25765 if (face
->overline_p
)
25766 it
->ascent
+= overline_margin
;
25768 take_vertical_position_into_account (it
);
25769 if (it
->ascent
< 0)
25771 if (it
->descent
< 0)
25774 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25775 append_composite_glyph (it
);
25777 else if (it
->what
== IT_COMPOSITION
)
25779 /* A dynamic (automatic) composition. */
25780 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25781 Lisp_Object gstring
;
25782 struct font_metrics metrics
;
25786 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25788 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25791 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25792 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25793 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25794 it
->descent
= it
->phys_descent
= metrics
.descent
;
25795 if (face
->box
!= FACE_NO_BOX
)
25797 int thick
= face
->box_line_width
;
25801 it
->ascent
+= thick
;
25802 it
->descent
+= thick
;
25807 if (it
->start_of_box_run_p
)
25808 it
->pixel_width
+= thick
;
25809 if (it
->end_of_box_run_p
)
25810 it
->pixel_width
+= thick
;
25812 /* If face has an overline, add the height of the overline
25813 (1 pixel) and a 1 pixel margin to the character height. */
25814 if (face
->overline_p
)
25815 it
->ascent
+= overline_margin
;
25816 take_vertical_position_into_account (it
);
25817 if (it
->ascent
< 0)
25819 if (it
->descent
< 0)
25823 append_composite_glyph (it
);
25825 else if (it
->what
== IT_GLYPHLESS
)
25826 produce_glyphless_glyph (it
, 0, Qnil
);
25827 else if (it
->what
== IT_IMAGE
)
25828 produce_image_glyph (it
);
25829 else if (it
->what
== IT_STRETCH
)
25830 produce_stretch_glyph (it
);
25833 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25834 because this isn't true for images with `:ascent 100'. */
25835 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25836 if (it
->area
== TEXT_AREA
)
25837 it
->current_x
+= it
->pixel_width
;
25839 if (extra_line_spacing
> 0)
25841 it
->descent
+= extra_line_spacing
;
25842 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25843 it
->max_extra_line_spacing
= extra_line_spacing
;
25846 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25847 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25848 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25849 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25853 Output LEN glyphs starting at START at the nominal cursor position.
25854 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25855 being updated, and UPDATED_AREA is the area of that row being updated. */
25858 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25859 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25861 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25863 eassert (updated_row
);
25864 /* When the window is hscrolled, cursor hpos can legitimately be out
25865 of bounds, but we draw the cursor at the corresponding window
25866 margin in that case. */
25867 if (!updated_row
->reversed_p
&& chpos
< 0)
25869 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25870 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25874 /* Write glyphs. */
25876 hpos
= start
- updated_row
->glyphs
[updated_area
];
25877 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25878 updated_row
, updated_area
,
25880 DRAW_NORMAL_TEXT
, 0);
25882 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25883 if (updated_area
== TEXT_AREA
25884 && w
->phys_cursor_on_p
25885 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25887 && chpos
< hpos
+ len
)
25888 w
->phys_cursor_on_p
= 0;
25892 /* Advance the output cursor. */
25893 w
->output_cursor
.hpos
+= len
;
25894 w
->output_cursor
.x
= x
;
25899 Insert LEN glyphs from START at the nominal cursor position. */
25902 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25903 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25906 int line_height
, shift_by_width
, shifted_region_width
;
25907 struct glyph_row
*row
;
25908 struct glyph
*glyph
;
25909 int frame_x
, frame_y
;
25912 eassert (updated_row
);
25914 f
= XFRAME (WINDOW_FRAME (w
));
25916 /* Get the height of the line we are in. */
25918 line_height
= row
->height
;
25920 /* Get the width of the glyphs to insert. */
25921 shift_by_width
= 0;
25922 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25923 shift_by_width
+= glyph
->pixel_width
;
25925 /* Get the width of the region to shift right. */
25926 shifted_region_width
= (window_box_width (w
, updated_area
)
25927 - w
->output_cursor
.x
25931 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25932 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25934 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25935 line_height
, shift_by_width
);
25937 /* Write the glyphs. */
25938 hpos
= start
- row
->glyphs
[updated_area
];
25939 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25941 DRAW_NORMAL_TEXT
, 0);
25943 /* Advance the output cursor. */
25944 w
->output_cursor
.hpos
+= len
;
25945 w
->output_cursor
.x
+= shift_by_width
;
25951 Erase the current text line from the nominal cursor position
25952 (inclusive) to pixel column TO_X (exclusive). The idea is that
25953 everything from TO_X onward is already erased.
25955 TO_X is a pixel position relative to UPDATED_AREA of currently
25956 updated window W. TO_X == -1 means clear to the end of this area. */
25959 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25960 enum glyph_row_area updated_area
, int to_x
)
25963 int max_x
, min_y
, max_y
;
25964 int from_x
, from_y
, to_y
;
25966 eassert (updated_row
);
25967 f
= XFRAME (w
->frame
);
25969 if (updated_row
->full_width_p
)
25970 max_x
= WINDOW_TOTAL_WIDTH (w
);
25972 max_x
= window_box_width (w
, updated_area
);
25973 max_y
= window_text_bottom_y (w
);
25975 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25976 of window. For TO_X > 0, truncate to end of drawing area. */
25982 to_x
= min (to_x
, max_x
);
25984 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25986 /* Notice if the cursor will be cleared by this operation. */
25987 if (!updated_row
->full_width_p
)
25988 notice_overwritten_cursor (w
, updated_area
,
25989 w
->output_cursor
.x
, -1,
25991 MATRIX_ROW_BOTTOM_Y (updated_row
));
25993 from_x
= w
->output_cursor
.x
;
25995 /* Translate to frame coordinates. */
25996 if (updated_row
->full_width_p
)
25998 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25999 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26003 int area_left
= window_box_left (w
, updated_area
);
26004 from_x
+= area_left
;
26008 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26009 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26010 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26012 /* Prevent inadvertently clearing to end of the X window. */
26013 if (to_x
> from_x
&& to_y
> from_y
)
26016 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26017 to_x
- from_x
, to_y
- from_y
);
26022 #endif /* HAVE_WINDOW_SYSTEM */
26026 /***********************************************************************
26028 ***********************************************************************/
26030 /* Value is the internal representation of the specified cursor type
26031 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26032 of the bar cursor. */
26034 static enum text_cursor_kinds
26035 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26037 enum text_cursor_kinds type
;
26042 if (EQ (arg
, Qbox
))
26043 return FILLED_BOX_CURSOR
;
26045 if (EQ (arg
, Qhollow
))
26046 return HOLLOW_BOX_CURSOR
;
26048 if (EQ (arg
, Qbar
))
26055 && EQ (XCAR (arg
), Qbar
)
26056 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26058 *width
= XINT (XCDR (arg
));
26062 if (EQ (arg
, Qhbar
))
26065 return HBAR_CURSOR
;
26069 && EQ (XCAR (arg
), Qhbar
)
26070 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26072 *width
= XINT (XCDR (arg
));
26073 return HBAR_CURSOR
;
26076 /* Treat anything unknown as "hollow box cursor".
26077 It was bad to signal an error; people have trouble fixing
26078 .Xdefaults with Emacs, when it has something bad in it. */
26079 type
= HOLLOW_BOX_CURSOR
;
26084 /* Set the default cursor types for specified frame. */
26086 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26091 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26092 FRAME_CURSOR_WIDTH (f
) = width
;
26094 /* By default, set up the blink-off state depending on the on-state. */
26096 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26099 FRAME_BLINK_OFF_CURSOR (f
)
26100 = get_specified_cursor_type (XCDR (tem
), &width
);
26101 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26104 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26106 /* Make sure the cursor gets redrawn. */
26107 f
->cursor_type_changed
= 1;
26111 #ifdef HAVE_WINDOW_SYSTEM
26113 /* Return the cursor we want to be displayed in window W. Return
26114 width of bar/hbar cursor through WIDTH arg. Return with
26115 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26116 (i.e. if the `system caret' should track this cursor).
26118 In a mini-buffer window, we want the cursor only to appear if we
26119 are reading input from this window. For the selected window, we
26120 want the cursor type given by the frame parameter or buffer local
26121 setting of cursor-type. If explicitly marked off, draw no cursor.
26122 In all other cases, we want a hollow box cursor. */
26124 static enum text_cursor_kinds
26125 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26126 int *active_cursor
)
26128 struct frame
*f
= XFRAME (w
->frame
);
26129 struct buffer
*b
= XBUFFER (w
->contents
);
26130 int cursor_type
= DEFAULT_CURSOR
;
26131 Lisp_Object alt_cursor
;
26132 int non_selected
= 0;
26134 *active_cursor
= 1;
26137 if (cursor_in_echo_area
26138 && FRAME_HAS_MINIBUF_P (f
)
26139 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26141 if (w
== XWINDOW (echo_area_window
))
26143 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26145 *width
= FRAME_CURSOR_WIDTH (f
);
26146 return FRAME_DESIRED_CURSOR (f
);
26149 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26152 *active_cursor
= 0;
26156 /* Detect a nonselected window or nonselected frame. */
26157 else if (w
!= XWINDOW (f
->selected_window
)
26158 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26160 *active_cursor
= 0;
26162 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26168 /* Never display a cursor in a window in which cursor-type is nil. */
26169 if (NILP (BVAR (b
, cursor_type
)))
26172 /* Get the normal cursor type for this window. */
26173 if (EQ (BVAR (b
, cursor_type
), Qt
))
26175 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26176 *width
= FRAME_CURSOR_WIDTH (f
);
26179 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26181 /* Use cursor-in-non-selected-windows instead
26182 for non-selected window or frame. */
26185 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26186 if (!EQ (Qt
, alt_cursor
))
26187 return get_specified_cursor_type (alt_cursor
, width
);
26188 /* t means modify the normal cursor type. */
26189 if (cursor_type
== FILLED_BOX_CURSOR
)
26190 cursor_type
= HOLLOW_BOX_CURSOR
;
26191 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26193 return cursor_type
;
26196 /* Use normal cursor if not blinked off. */
26197 if (!w
->cursor_off_p
)
26199 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26201 if (cursor_type
== FILLED_BOX_CURSOR
)
26203 /* Using a block cursor on large images can be very annoying.
26204 So use a hollow cursor for "large" images.
26205 If image is not transparent (no mask), also use hollow cursor. */
26206 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26207 if (img
!= NULL
&& IMAGEP (img
->spec
))
26209 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26210 where N = size of default frame font size.
26211 This should cover most of the "tiny" icons people may use. */
26213 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26214 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26215 cursor_type
= HOLLOW_BOX_CURSOR
;
26218 else if (cursor_type
!= NO_CURSOR
)
26220 /* Display current only supports BOX and HOLLOW cursors for images.
26221 So for now, unconditionally use a HOLLOW cursor when cursor is
26222 not a solid box cursor. */
26223 cursor_type
= HOLLOW_BOX_CURSOR
;
26226 return cursor_type
;
26229 /* Cursor is blinked off, so determine how to "toggle" it. */
26231 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26232 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26233 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26235 /* Then see if frame has specified a specific blink off cursor type. */
26236 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26238 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26239 return FRAME_BLINK_OFF_CURSOR (f
);
26243 /* Some people liked having a permanently visible blinking cursor,
26244 while others had very strong opinions against it. So it was
26245 decided to remove it. KFS 2003-09-03 */
26247 /* Finally perform built-in cursor blinking:
26248 filled box <-> hollow box
26249 wide [h]bar <-> narrow [h]bar
26250 narrow [h]bar <-> no cursor
26251 other type <-> no cursor */
26253 if (cursor_type
== FILLED_BOX_CURSOR
)
26254 return HOLLOW_BOX_CURSOR
;
26256 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26259 return cursor_type
;
26267 /* Notice when the text cursor of window W has been completely
26268 overwritten by a drawing operation that outputs glyphs in AREA
26269 starting at X0 and ending at X1 in the line starting at Y0 and
26270 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26271 the rest of the line after X0 has been written. Y coordinates
26272 are window-relative. */
26275 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26276 int x0
, int x1
, int y0
, int y1
)
26278 int cx0
, cx1
, cy0
, cy1
;
26279 struct glyph_row
*row
;
26281 if (!w
->phys_cursor_on_p
)
26283 if (area
!= TEXT_AREA
)
26286 if (w
->phys_cursor
.vpos
< 0
26287 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26288 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26289 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26292 if (row
->cursor_in_fringe_p
)
26294 row
->cursor_in_fringe_p
= 0;
26295 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26296 w
->phys_cursor_on_p
= 0;
26300 cx0
= w
->phys_cursor
.x
;
26301 cx1
= cx0
+ w
->phys_cursor_width
;
26302 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26305 /* The cursor image will be completely removed from the
26306 screen if the output area intersects the cursor area in
26307 y-direction. When we draw in [y0 y1[, and some part of
26308 the cursor is at y < y0, that part must have been drawn
26309 before. When scrolling, the cursor is erased before
26310 actually scrolling, so we don't come here. When not
26311 scrolling, the rows above the old cursor row must have
26312 changed, and in this case these rows must have written
26313 over the cursor image.
26315 Likewise if part of the cursor is below y1, with the
26316 exception of the cursor being in the first blank row at
26317 the buffer and window end because update_text_area
26318 doesn't draw that row. (Except when it does, but
26319 that's handled in update_text_area.) */
26321 cy0
= w
->phys_cursor
.y
;
26322 cy1
= cy0
+ w
->phys_cursor_height
;
26323 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26326 w
->phys_cursor_on_p
= 0;
26329 #endif /* HAVE_WINDOW_SYSTEM */
26332 /************************************************************************
26334 ************************************************************************/
26336 #ifdef HAVE_WINDOW_SYSTEM
26339 Fix the display of area AREA of overlapping row ROW in window W
26340 with respect to the overlapping part OVERLAPS. */
26343 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26344 enum glyph_row_area area
, int overlaps
)
26351 for (i
= 0; i
< row
->used
[area
];)
26353 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26355 int start
= i
, start_x
= x
;
26359 x
+= row
->glyphs
[area
][i
].pixel_width
;
26362 while (i
< row
->used
[area
]
26363 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26365 draw_glyphs (w
, start_x
, row
, area
,
26367 DRAW_NORMAL_TEXT
, overlaps
);
26371 x
+= row
->glyphs
[area
][i
].pixel_width
;
26381 Draw the cursor glyph of window W in glyph row ROW. See the
26382 comment of draw_glyphs for the meaning of HL. */
26385 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26386 enum draw_glyphs_face hl
)
26388 /* If cursor hpos is out of bounds, don't draw garbage. This can
26389 happen in mini-buffer windows when switching between echo area
26390 glyphs and mini-buffer. */
26391 if ((row
->reversed_p
26392 ? (w
->phys_cursor
.hpos
>= 0)
26393 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26395 int on_p
= w
->phys_cursor_on_p
;
26397 int hpos
= w
->phys_cursor
.hpos
;
26399 /* When the window is hscrolled, cursor hpos can legitimately be
26400 out of bounds, but we draw the cursor at the corresponding
26401 window margin in that case. */
26402 if (!row
->reversed_p
&& hpos
< 0)
26404 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26405 hpos
= row
->used
[TEXT_AREA
] - 1;
26407 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26409 w
->phys_cursor_on_p
= on_p
;
26411 if (hl
== DRAW_CURSOR
)
26412 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26413 /* When we erase the cursor, and ROW is overlapped by other
26414 rows, make sure that these overlapping parts of other rows
26416 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26418 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26420 if (row
> w
->current_matrix
->rows
26421 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26422 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26423 OVERLAPS_ERASED_CURSOR
);
26425 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26426 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26427 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26428 OVERLAPS_ERASED_CURSOR
);
26434 /* Erase the image of a cursor of window W from the screen. */
26440 erase_phys_cursor (struct window
*w
)
26442 struct frame
*f
= XFRAME (w
->frame
);
26443 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26444 int hpos
= w
->phys_cursor
.hpos
;
26445 int vpos
= w
->phys_cursor
.vpos
;
26446 int mouse_face_here_p
= 0;
26447 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26448 struct glyph_row
*cursor_row
;
26449 struct glyph
*cursor_glyph
;
26450 enum draw_glyphs_face hl
;
26452 /* No cursor displayed or row invalidated => nothing to do on the
26454 if (w
->phys_cursor_type
== NO_CURSOR
)
26455 goto mark_cursor_off
;
26457 /* VPOS >= active_glyphs->nrows means that window has been resized.
26458 Don't bother to erase the cursor. */
26459 if (vpos
>= active_glyphs
->nrows
)
26460 goto mark_cursor_off
;
26462 /* If row containing cursor is marked invalid, there is nothing we
26464 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26465 if (!cursor_row
->enabled_p
)
26466 goto mark_cursor_off
;
26468 /* If line spacing is > 0, old cursor may only be partially visible in
26469 window after split-window. So adjust visible height. */
26470 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26471 window_text_bottom_y (w
) - cursor_row
->y
);
26473 /* If row is completely invisible, don't attempt to delete a cursor which
26474 isn't there. This can happen if cursor is at top of a window, and
26475 we switch to a buffer with a header line in that window. */
26476 if (cursor_row
->visible_height
<= 0)
26477 goto mark_cursor_off
;
26479 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26480 if (cursor_row
->cursor_in_fringe_p
)
26482 cursor_row
->cursor_in_fringe_p
= 0;
26483 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26484 goto mark_cursor_off
;
26487 /* This can happen when the new row is shorter than the old one.
26488 In this case, either draw_glyphs or clear_end_of_line
26489 should have cleared the cursor. Note that we wouldn't be
26490 able to erase the cursor in this case because we don't have a
26491 cursor glyph at hand. */
26492 if ((cursor_row
->reversed_p
26493 ? (w
->phys_cursor
.hpos
< 0)
26494 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26495 goto mark_cursor_off
;
26497 /* When the window is hscrolled, cursor hpos can legitimately be out
26498 of bounds, but we draw the cursor at the corresponding window
26499 margin in that case. */
26500 if (!cursor_row
->reversed_p
&& hpos
< 0)
26502 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26503 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26505 /* If the cursor is in the mouse face area, redisplay that when
26506 we clear the cursor. */
26507 if (! NILP (hlinfo
->mouse_face_window
)
26508 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26509 /* Don't redraw the cursor's spot in mouse face if it is at the
26510 end of a line (on a newline). The cursor appears there, but
26511 mouse highlighting does not. */
26512 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26513 mouse_face_here_p
= 1;
26515 /* Maybe clear the display under the cursor. */
26516 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26519 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26522 cursor_glyph
= get_phys_cursor_glyph (w
);
26523 if (cursor_glyph
== NULL
)
26524 goto mark_cursor_off
;
26526 width
= cursor_glyph
->pixel_width
;
26527 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26528 x
= w
->phys_cursor
.x
;
26530 width
-= left_x
- x
;
26531 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26532 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26533 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26536 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26539 /* Erase the cursor by redrawing the character underneath it. */
26540 if (mouse_face_here_p
)
26541 hl
= DRAW_MOUSE_FACE
;
26543 hl
= DRAW_NORMAL_TEXT
;
26544 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26547 w
->phys_cursor_on_p
= 0;
26548 w
->phys_cursor_type
= NO_CURSOR
;
26553 Display or clear cursor of window W. If ON is zero, clear the
26554 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26555 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26558 display_and_set_cursor (struct window
*w
, bool on
,
26559 int hpos
, int vpos
, int x
, int y
)
26561 struct frame
*f
= XFRAME (w
->frame
);
26562 int new_cursor_type
;
26563 int new_cursor_width
;
26565 struct glyph_row
*glyph_row
;
26566 struct glyph
*glyph
;
26568 /* This is pointless on invisible frames, and dangerous on garbaged
26569 windows and frames; in the latter case, the frame or window may
26570 be in the midst of changing its size, and x and y may be off the
26572 if (! FRAME_VISIBLE_P (f
)
26573 || FRAME_GARBAGED_P (f
)
26574 || vpos
>= w
->current_matrix
->nrows
26575 || hpos
>= w
->current_matrix
->matrix_w
)
26578 /* If cursor is off and we want it off, return quickly. */
26579 if (!on
&& !w
->phys_cursor_on_p
)
26582 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26583 /* If cursor row is not enabled, we don't really know where to
26584 display the cursor. */
26585 if (!glyph_row
->enabled_p
)
26587 w
->phys_cursor_on_p
= 0;
26592 if (!glyph_row
->exact_window_width_line_p
26593 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26594 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26596 eassert (input_blocked_p ());
26598 /* Set new_cursor_type to the cursor we want to be displayed. */
26599 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26600 &new_cursor_width
, &active_cursor
);
26602 /* If cursor is currently being shown and we don't want it to be or
26603 it is in the wrong place, or the cursor type is not what we want,
26605 if (w
->phys_cursor_on_p
26607 || w
->phys_cursor
.x
!= x
26608 || w
->phys_cursor
.y
!= y
26609 || new_cursor_type
!= w
->phys_cursor_type
26610 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26611 && new_cursor_width
!= w
->phys_cursor_width
)))
26612 erase_phys_cursor (w
);
26614 /* Don't check phys_cursor_on_p here because that flag is only set
26615 to zero in some cases where we know that the cursor has been
26616 completely erased, to avoid the extra work of erasing the cursor
26617 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26618 still not be visible, or it has only been partly erased. */
26621 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26622 w
->phys_cursor_height
= glyph_row
->height
;
26624 /* Set phys_cursor_.* before x_draw_.* is called because some
26625 of them may need the information. */
26626 w
->phys_cursor
.x
= x
;
26627 w
->phys_cursor
.y
= glyph_row
->y
;
26628 w
->phys_cursor
.hpos
= hpos
;
26629 w
->phys_cursor
.vpos
= vpos
;
26632 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26633 new_cursor_type
, new_cursor_width
,
26634 on
, active_cursor
);
26638 /* Switch the display of W's cursor on or off, according to the value
26642 update_window_cursor (struct window
*w
, bool on
)
26644 /* Don't update cursor in windows whose frame is in the process
26645 of being deleted. */
26646 if (w
->current_matrix
)
26648 int hpos
= w
->phys_cursor
.hpos
;
26649 int vpos
= w
->phys_cursor
.vpos
;
26650 struct glyph_row
*row
;
26652 if (vpos
>= w
->current_matrix
->nrows
26653 || hpos
>= w
->current_matrix
->matrix_w
)
26656 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26658 /* When the window is hscrolled, cursor hpos can legitimately be
26659 out of bounds, but we draw the cursor at the corresponding
26660 window margin in that case. */
26661 if (!row
->reversed_p
&& hpos
< 0)
26663 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26664 hpos
= row
->used
[TEXT_AREA
] - 1;
26667 display_and_set_cursor (w
, on
, hpos
, vpos
,
26668 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26674 /* Call update_window_cursor with parameter ON_P on all leaf windows
26675 in the window tree rooted at W. */
26678 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26682 if (WINDOWP (w
->contents
))
26683 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26685 update_window_cursor (w
, on_p
);
26687 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26693 Display the cursor on window W, or clear it, according to ON_P.
26694 Don't change the cursor's position. */
26697 x_update_cursor (struct frame
*f
, bool on_p
)
26699 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26704 Clear the cursor of window W to background color, and mark the
26705 cursor as not shown. This is used when the text where the cursor
26706 is about to be rewritten. */
26709 x_clear_cursor (struct window
*w
)
26711 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26712 update_window_cursor (w
, 0);
26715 #endif /* HAVE_WINDOW_SYSTEM */
26717 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26720 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26721 int start_hpos
, int end_hpos
,
26722 enum draw_glyphs_face draw
)
26724 #ifdef HAVE_WINDOW_SYSTEM
26725 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26727 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26731 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26732 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26736 /* Display the active region described by mouse_face_* according to DRAW. */
26739 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26741 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26742 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26744 if (/* If window is in the process of being destroyed, don't bother
26746 w
->current_matrix
!= NULL
26747 /* Don't update mouse highlight if hidden */
26748 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26749 /* Recognize when we are called to operate on rows that don't exist
26750 anymore. This can happen when a window is split. */
26751 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26753 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26754 struct glyph_row
*row
, *first
, *last
;
26756 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26757 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26759 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26761 int start_hpos
, end_hpos
, start_x
;
26763 /* For all but the first row, the highlight starts at column 0. */
26766 /* R2L rows have BEG and END in reversed order, but the
26767 screen drawing geometry is always left to right. So
26768 we need to mirror the beginning and end of the
26769 highlighted area in R2L rows. */
26770 if (!row
->reversed_p
)
26772 start_hpos
= hlinfo
->mouse_face_beg_col
;
26773 start_x
= hlinfo
->mouse_face_beg_x
;
26775 else if (row
== last
)
26777 start_hpos
= hlinfo
->mouse_face_end_col
;
26778 start_x
= hlinfo
->mouse_face_end_x
;
26786 else if (row
->reversed_p
&& row
== last
)
26788 start_hpos
= hlinfo
->mouse_face_end_col
;
26789 start_x
= hlinfo
->mouse_face_end_x
;
26799 if (!row
->reversed_p
)
26800 end_hpos
= hlinfo
->mouse_face_end_col
;
26801 else if (row
== first
)
26802 end_hpos
= hlinfo
->mouse_face_beg_col
;
26805 end_hpos
= row
->used
[TEXT_AREA
];
26806 if (draw
== DRAW_NORMAL_TEXT
)
26807 row
->fill_line_p
= 1; /* Clear to end of line */
26810 else if (row
->reversed_p
&& row
== first
)
26811 end_hpos
= hlinfo
->mouse_face_beg_col
;
26814 end_hpos
= row
->used
[TEXT_AREA
];
26815 if (draw
== DRAW_NORMAL_TEXT
)
26816 row
->fill_line_p
= 1; /* Clear to end of line */
26819 if (end_hpos
> start_hpos
)
26821 draw_row_with_mouse_face (w
, start_x
, row
,
26822 start_hpos
, end_hpos
, draw
);
26825 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26829 #ifdef HAVE_WINDOW_SYSTEM
26830 /* When we've written over the cursor, arrange for it to
26831 be displayed again. */
26832 if (FRAME_WINDOW_P (f
)
26833 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26835 int hpos
= w
->phys_cursor
.hpos
;
26837 /* When the window is hscrolled, cursor hpos can legitimately be
26838 out of bounds, but we draw the cursor at the corresponding
26839 window margin in that case. */
26840 if (!row
->reversed_p
&& hpos
< 0)
26842 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26843 hpos
= row
->used
[TEXT_AREA
] - 1;
26846 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26847 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26850 #endif /* HAVE_WINDOW_SYSTEM */
26853 #ifdef HAVE_WINDOW_SYSTEM
26854 /* Change the mouse cursor. */
26855 if (FRAME_WINDOW_P (f
))
26857 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
26858 if (draw
== DRAW_NORMAL_TEXT
26859 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26860 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26863 if (draw
== DRAW_MOUSE_FACE
)
26864 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26866 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26868 #endif /* HAVE_WINDOW_SYSTEM */
26872 Clear out the mouse-highlighted active region.
26873 Redraw it un-highlighted first. Value is non-zero if mouse
26874 face was actually drawn unhighlighted. */
26877 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26881 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26883 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26887 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26888 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26889 hlinfo
->mouse_face_window
= Qnil
;
26890 hlinfo
->mouse_face_overlay
= Qnil
;
26894 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26895 within the mouse face on that window. */
26897 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26899 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26901 /* Quickly resolve the easy cases. */
26902 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26903 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26905 if (vpos
< hlinfo
->mouse_face_beg_row
26906 || vpos
> hlinfo
->mouse_face_end_row
)
26908 if (vpos
> hlinfo
->mouse_face_beg_row
26909 && vpos
< hlinfo
->mouse_face_end_row
)
26912 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26914 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26916 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26919 else if ((vpos
== hlinfo
->mouse_face_beg_row
26920 && hpos
>= hlinfo
->mouse_face_beg_col
)
26921 || (vpos
== hlinfo
->mouse_face_end_row
26922 && hpos
< hlinfo
->mouse_face_end_col
))
26927 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26929 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26932 else if ((vpos
== hlinfo
->mouse_face_beg_row
26933 && hpos
<= hlinfo
->mouse_face_beg_col
)
26934 || (vpos
== hlinfo
->mouse_face_end_row
26935 && hpos
> hlinfo
->mouse_face_end_col
))
26943 Non-zero if physical cursor of window W is within mouse face. */
26946 cursor_in_mouse_face_p (struct window
*w
)
26948 int hpos
= w
->phys_cursor
.hpos
;
26949 int vpos
= w
->phys_cursor
.vpos
;
26950 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26952 /* When the window is hscrolled, cursor hpos can legitimately be out
26953 of bounds, but we draw the cursor at the corresponding window
26954 margin in that case. */
26955 if (!row
->reversed_p
&& hpos
< 0)
26957 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26958 hpos
= row
->used
[TEXT_AREA
] - 1;
26960 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26965 /* Find the glyph rows START_ROW and END_ROW of window W that display
26966 characters between buffer positions START_CHARPOS and END_CHARPOS
26967 (excluding END_CHARPOS). DISP_STRING is a display string that
26968 covers these buffer positions. This is similar to
26969 row_containing_pos, but is more accurate when bidi reordering makes
26970 buffer positions change non-linearly with glyph rows. */
26972 rows_from_pos_range (struct window
*w
,
26973 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26974 Lisp_Object disp_string
,
26975 struct glyph_row
**start
, struct glyph_row
**end
)
26977 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26978 int last_y
= window_text_bottom_y (w
);
26979 struct glyph_row
*row
;
26984 while (!first
->enabled_p
26985 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26988 /* Find the START row. */
26990 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26993 /* A row can potentially be the START row if the range of the
26994 characters it displays intersects the range
26995 [START_CHARPOS..END_CHARPOS). */
26996 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26997 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26998 /* See the commentary in row_containing_pos, for the
26999 explanation of the complicated way to check whether
27000 some position is beyond the end of the characters
27001 displayed by a row. */
27002 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27003 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27004 && !row
->ends_at_zv_p
27005 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27006 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27007 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27008 && !row
->ends_at_zv_p
27009 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27011 /* Found a candidate row. Now make sure at least one of the
27012 glyphs it displays has a charpos from the range
27013 [START_CHARPOS..END_CHARPOS).
27015 This is not obvious because bidi reordering could make
27016 buffer positions of a row be 1,2,3,102,101,100, and if we
27017 want to highlight characters in [50..60), we don't want
27018 this row, even though [50..60) does intersect [1..103),
27019 the range of character positions given by the row's start
27020 and end positions. */
27021 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27022 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27026 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27027 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27028 /* A glyph that comes from DISP_STRING is by
27029 definition to be highlighted. */
27030 || EQ (g
->object
, disp_string
))
27039 /* Find the END row. */
27041 /* If the last row is partially visible, start looking for END
27042 from that row, instead of starting from FIRST. */
27043 && !(row
->enabled_p
27044 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27046 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27048 struct glyph_row
*next
= row
+ 1;
27049 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27051 if (!next
->enabled_p
27052 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27053 /* The first row >= START whose range of displayed characters
27054 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27055 is the row END + 1. */
27056 || (start_charpos
< next_start
27057 && end_charpos
< next_start
)
27058 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27059 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27060 && !next
->ends_at_zv_p
27061 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27062 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27063 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27064 && !next
->ends_at_zv_p
27065 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27072 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27073 but none of the characters it displays are in the range, it is
27075 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27076 struct glyph
*s
= g
;
27077 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27081 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27082 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27083 /* If the buffer position of the first glyph in
27084 the row is equal to END_CHARPOS, it means
27085 the last character to be highlighted is the
27086 newline of ROW, and we must consider NEXT as
27088 || (((!next
->reversed_p
&& g
== s
)
27089 || (next
->reversed_p
&& g
== e
- 1))
27090 && (g
->charpos
== end_charpos
27091 /* Special case for when NEXT is an
27092 empty line at ZV. */
27093 || (g
->charpos
== -1
27094 && !row
->ends_at_zv_p
27095 && next_start
== end_charpos
)))))
27096 /* A glyph that comes from DISP_STRING is by
27097 definition to be highlighted. */
27098 || EQ (g
->object
, disp_string
))
27107 /* The first row that ends at ZV must be the last to be
27109 else if (next
->ends_at_zv_p
)
27118 /* This function sets the mouse_face_* elements of HLINFO, assuming
27119 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27120 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27121 for the overlay or run of text properties specifying the mouse
27122 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27123 before-string and after-string that must also be highlighted.
27124 DISP_STRING, if non-nil, is a display string that may cover some
27125 or all of the highlighted text. */
27128 mouse_face_from_buffer_pos (Lisp_Object window
,
27129 Mouse_HLInfo
*hlinfo
,
27130 ptrdiff_t mouse_charpos
,
27131 ptrdiff_t start_charpos
,
27132 ptrdiff_t end_charpos
,
27133 Lisp_Object before_string
,
27134 Lisp_Object after_string
,
27135 Lisp_Object disp_string
)
27137 struct window
*w
= XWINDOW (window
);
27138 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27139 struct glyph_row
*r1
, *r2
;
27140 struct glyph
*glyph
, *end
;
27141 ptrdiff_t ignore
, pos
;
27144 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27145 eassert (NILP (before_string
) || STRINGP (before_string
));
27146 eassert (NILP (after_string
) || STRINGP (after_string
));
27148 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27149 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27151 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27152 /* If the before-string or display-string contains newlines,
27153 rows_from_pos_range skips to its last row. Move back. */
27154 if (!NILP (before_string
) || !NILP (disp_string
))
27156 struct glyph_row
*prev
;
27157 while ((prev
= r1
- 1, prev
>= first
)
27158 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27159 && prev
->used
[TEXT_AREA
] > 0)
27161 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27162 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27163 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27165 || !(EQ (glyph
->object
, before_string
)
27166 || EQ (glyph
->object
, disp_string
)))
27173 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27174 hlinfo
->mouse_face_past_end
= 1;
27176 else if (!NILP (after_string
))
27178 /* If the after-string has newlines, advance to its last row. */
27179 struct glyph_row
*next
;
27180 struct glyph_row
*last
27181 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27183 for (next
= r2
+ 1;
27185 && next
->used
[TEXT_AREA
] > 0
27186 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27190 /* The rest of the display engine assumes that mouse_face_beg_row is
27191 either above mouse_face_end_row or identical to it. But with
27192 bidi-reordered continued lines, the row for START_CHARPOS could
27193 be below the row for END_CHARPOS. If so, swap the rows and store
27194 them in correct order. */
27197 struct glyph_row
*tem
= r2
;
27203 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27204 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27206 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27207 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27208 could be anywhere in the row and in any order. The strategy
27209 below is to find the leftmost and the rightmost glyph that
27210 belongs to either of these 3 strings, or whose position is
27211 between START_CHARPOS and END_CHARPOS, and highlight all the
27212 glyphs between those two. This may cover more than just the text
27213 between START_CHARPOS and END_CHARPOS if the range of characters
27214 strides the bidi level boundary, e.g. if the beginning is in R2L
27215 text while the end is in L2R text or vice versa. */
27216 if (!r1
->reversed_p
)
27218 /* This row is in a left to right paragraph. Scan it left to
27220 glyph
= r1
->glyphs
[TEXT_AREA
];
27221 end
= glyph
+ r1
->used
[TEXT_AREA
];
27224 /* Skip truncation glyphs at the start of the glyph row. */
27225 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27227 && INTEGERP (glyph
->object
)
27228 && glyph
->charpos
< 0;
27230 x
+= glyph
->pixel_width
;
27232 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27233 or DISP_STRING, and the first glyph from buffer whose
27234 position is between START_CHARPOS and END_CHARPOS. */
27236 && !INTEGERP (glyph
->object
)
27237 && !EQ (glyph
->object
, disp_string
)
27238 && !(BUFFERP (glyph
->object
)
27239 && (glyph
->charpos
>= start_charpos
27240 && glyph
->charpos
< end_charpos
));
27243 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27244 are present at buffer positions between START_CHARPOS and
27245 END_CHARPOS, or if they come from an overlay. */
27246 if (EQ (glyph
->object
, before_string
))
27248 pos
= string_buffer_position (before_string
,
27250 /* If pos == 0, it means before_string came from an
27251 overlay, not from a buffer position. */
27252 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27255 else if (EQ (glyph
->object
, after_string
))
27257 pos
= string_buffer_position (after_string
, end_charpos
);
27258 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27261 x
+= glyph
->pixel_width
;
27263 hlinfo
->mouse_face_beg_x
= x
;
27264 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27268 /* This row is in a right to left paragraph. Scan it right to
27272 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27273 glyph
= end
+ r1
->used
[TEXT_AREA
];
27275 /* Skip truncation glyphs at the start of the glyph row. */
27276 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27278 && INTEGERP (glyph
->object
)
27279 && glyph
->charpos
< 0;
27283 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27284 or DISP_STRING, and the first glyph from buffer whose
27285 position is between START_CHARPOS and END_CHARPOS. */
27287 && !INTEGERP (glyph
->object
)
27288 && !EQ (glyph
->object
, disp_string
)
27289 && !(BUFFERP (glyph
->object
)
27290 && (glyph
->charpos
>= start_charpos
27291 && glyph
->charpos
< end_charpos
));
27294 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27295 are present at buffer positions between START_CHARPOS and
27296 END_CHARPOS, or if they come from an overlay. */
27297 if (EQ (glyph
->object
, before_string
))
27299 pos
= string_buffer_position (before_string
, start_charpos
);
27300 /* If pos == 0, it means before_string came from an
27301 overlay, not from a buffer position. */
27302 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27305 else if (EQ (glyph
->object
, after_string
))
27307 pos
= string_buffer_position (after_string
, end_charpos
);
27308 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27313 glyph
++; /* first glyph to the right of the highlighted area */
27314 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27315 x
+= g
->pixel_width
;
27316 hlinfo
->mouse_face_beg_x
= x
;
27317 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27320 /* If the highlight ends in a different row, compute GLYPH and END
27321 for the end row. Otherwise, reuse the values computed above for
27322 the row where the highlight begins. */
27325 if (!r2
->reversed_p
)
27327 glyph
= r2
->glyphs
[TEXT_AREA
];
27328 end
= glyph
+ r2
->used
[TEXT_AREA
];
27333 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27334 glyph
= end
+ r2
->used
[TEXT_AREA
];
27338 if (!r2
->reversed_p
)
27340 /* Skip truncation and continuation glyphs near the end of the
27341 row, and also blanks and stretch glyphs inserted by
27342 extend_face_to_end_of_line. */
27344 && INTEGERP ((end
- 1)->object
))
27346 /* Scan the rest of the glyph row from the end, looking for the
27347 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27348 DISP_STRING, or whose position is between START_CHARPOS
27352 && !INTEGERP (end
->object
)
27353 && !EQ (end
->object
, disp_string
)
27354 && !(BUFFERP (end
->object
)
27355 && (end
->charpos
>= start_charpos
27356 && end
->charpos
< end_charpos
));
27359 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27360 are present at buffer positions between START_CHARPOS and
27361 END_CHARPOS, or if they come from an overlay. */
27362 if (EQ (end
->object
, before_string
))
27364 pos
= string_buffer_position (before_string
, start_charpos
);
27365 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27368 else if (EQ (end
->object
, after_string
))
27370 pos
= string_buffer_position (after_string
, end_charpos
);
27371 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27375 /* Find the X coordinate of the last glyph to be highlighted. */
27376 for (; glyph
<= end
; ++glyph
)
27377 x
+= glyph
->pixel_width
;
27379 hlinfo
->mouse_face_end_x
= x
;
27380 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27384 /* Skip truncation and continuation glyphs near the end of the
27385 row, and also blanks and stretch glyphs inserted by
27386 extend_face_to_end_of_line. */
27390 && INTEGERP (end
->object
))
27392 x
+= end
->pixel_width
;
27395 /* Scan the rest of the glyph row from the end, looking for the
27396 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27397 DISP_STRING, or whose position is between START_CHARPOS
27401 && !INTEGERP (end
->object
)
27402 && !EQ (end
->object
, disp_string
)
27403 && !(BUFFERP (end
->object
)
27404 && (end
->charpos
>= start_charpos
27405 && end
->charpos
< end_charpos
));
27408 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27409 are present at buffer positions between START_CHARPOS and
27410 END_CHARPOS, or if they come from an overlay. */
27411 if (EQ (end
->object
, before_string
))
27413 pos
= string_buffer_position (before_string
, start_charpos
);
27414 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27417 else if (EQ (end
->object
, after_string
))
27419 pos
= string_buffer_position (after_string
, end_charpos
);
27420 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27423 x
+= end
->pixel_width
;
27425 /* If we exited the above loop because we arrived at the last
27426 glyph of the row, and its buffer position is still not in
27427 range, it means the last character in range is the preceding
27428 newline. Bump the end column and x values to get past the
27431 && BUFFERP (end
->object
)
27432 && (end
->charpos
< start_charpos
27433 || end
->charpos
>= end_charpos
))
27435 x
+= end
->pixel_width
;
27438 hlinfo
->mouse_face_end_x
= x
;
27439 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27442 hlinfo
->mouse_face_window
= window
;
27443 hlinfo
->mouse_face_face_id
27444 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27446 !hlinfo
->mouse_face_hidden
, -1);
27447 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27450 /* The following function is not used anymore (replaced with
27451 mouse_face_from_string_pos), but I leave it here for the time
27452 being, in case someone would. */
27454 #if 0 /* not used */
27456 /* Find the position of the glyph for position POS in OBJECT in
27457 window W's current matrix, and return in *X, *Y the pixel
27458 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27460 RIGHT_P non-zero means return the position of the right edge of the
27461 glyph, RIGHT_P zero means return the left edge position.
27463 If no glyph for POS exists in the matrix, return the position of
27464 the glyph with the next smaller position that is in the matrix, if
27465 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27466 exists in the matrix, return the position of the glyph with the
27467 next larger position in OBJECT.
27469 Value is non-zero if a glyph was found. */
27472 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27473 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27475 int yb
= window_text_bottom_y (w
);
27476 struct glyph_row
*r
;
27477 struct glyph
*best_glyph
= NULL
;
27478 struct glyph_row
*best_row
= NULL
;
27481 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27482 r
->enabled_p
&& r
->y
< yb
;
27485 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27486 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27489 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27490 if (EQ (g
->object
, object
))
27492 if (g
->charpos
== pos
)
27499 else if (best_glyph
== NULL
27500 || ((eabs (g
->charpos
- pos
)
27501 < eabs (best_glyph
->charpos
- pos
))
27504 : g
->charpos
> pos
)))
27518 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27522 *x
+= best_glyph
->pixel_width
;
27527 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27530 return best_glyph
!= NULL
;
27532 #endif /* not used */
27534 /* Find the positions of the first and the last glyphs in window W's
27535 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27536 (assumed to be a string), and return in HLINFO's mouse_face_*
27537 members the pixel and column/row coordinates of those glyphs. */
27540 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27541 Lisp_Object object
,
27542 ptrdiff_t startpos
, ptrdiff_t endpos
)
27544 int yb
= window_text_bottom_y (w
);
27545 struct glyph_row
*r
;
27546 struct glyph
*g
, *e
;
27550 /* Find the glyph row with at least one position in the range
27551 [STARTPOS..ENDPOS), and the first glyph in that row whose
27552 position belongs to that range. */
27553 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27554 r
->enabled_p
&& r
->y
< yb
;
27557 if (!r
->reversed_p
)
27559 g
= r
->glyphs
[TEXT_AREA
];
27560 e
= g
+ r
->used
[TEXT_AREA
];
27561 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27562 if (EQ (g
->object
, object
)
27563 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27565 hlinfo
->mouse_face_beg_row
27566 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27567 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27568 hlinfo
->mouse_face_beg_x
= gx
;
27577 e
= r
->glyphs
[TEXT_AREA
];
27578 g
= e
+ r
->used
[TEXT_AREA
];
27579 for ( ; g
> e
; --g
)
27580 if (EQ ((g
-1)->object
, object
)
27581 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27583 hlinfo
->mouse_face_beg_row
27584 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27585 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27586 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27587 gx
+= g1
->pixel_width
;
27588 hlinfo
->mouse_face_beg_x
= gx
;
27600 /* Starting with the next row, look for the first row which does NOT
27601 include any glyphs whose positions are in the range. */
27602 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27604 g
= r
->glyphs
[TEXT_AREA
];
27605 e
= g
+ r
->used
[TEXT_AREA
];
27607 for ( ; g
< e
; ++g
)
27608 if (EQ (g
->object
, object
)
27609 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27618 /* The highlighted region ends on the previous row. */
27621 /* Set the end row. */
27622 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27624 /* Compute and set the end column and the end column's horizontal
27625 pixel coordinate. */
27626 if (!r
->reversed_p
)
27628 g
= r
->glyphs
[TEXT_AREA
];
27629 e
= g
+ r
->used
[TEXT_AREA
];
27630 for ( ; e
> g
; --e
)
27631 if (EQ ((e
-1)->object
, object
)
27632 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27634 hlinfo
->mouse_face_end_col
= e
- g
;
27636 for (gx
= r
->x
; g
< e
; ++g
)
27637 gx
+= g
->pixel_width
;
27638 hlinfo
->mouse_face_end_x
= gx
;
27642 e
= r
->glyphs
[TEXT_AREA
];
27643 g
= e
+ r
->used
[TEXT_AREA
];
27644 for (gx
= r
->x
; e
< g
; ++e
)
27646 if (EQ (e
->object
, object
)
27647 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27649 gx
+= e
->pixel_width
;
27651 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27652 hlinfo
->mouse_face_end_x
= gx
;
27656 #ifdef HAVE_WINDOW_SYSTEM
27658 /* See if position X, Y is within a hot-spot of an image. */
27661 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27663 if (!CONSP (hot_spot
))
27666 if (EQ (XCAR (hot_spot
), Qrect
))
27668 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27669 Lisp_Object rect
= XCDR (hot_spot
);
27673 if (!CONSP (XCAR (rect
)))
27675 if (!CONSP (XCDR (rect
)))
27677 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27679 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27681 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27683 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27687 else if (EQ (XCAR (hot_spot
), Qcircle
))
27689 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27690 Lisp_Object circ
= XCDR (hot_spot
);
27691 Lisp_Object lr
, lx0
, ly0
;
27693 && CONSP (XCAR (circ
))
27694 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27695 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27696 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27698 double r
= XFLOATINT (lr
);
27699 double dx
= XINT (lx0
) - x
;
27700 double dy
= XINT (ly0
) - y
;
27701 return (dx
* dx
+ dy
* dy
<= r
* r
);
27704 else if (EQ (XCAR (hot_spot
), Qpoly
))
27706 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27707 if (VECTORP (XCDR (hot_spot
)))
27709 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27710 Lisp_Object
*poly
= v
->contents
;
27711 ptrdiff_t n
= v
->header
.size
;
27714 Lisp_Object lx
, ly
;
27717 /* Need an even number of coordinates, and at least 3 edges. */
27718 if (n
< 6 || n
& 1)
27721 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27722 If count is odd, we are inside polygon. Pixels on edges
27723 may or may not be included depending on actual geometry of the
27725 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27726 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27728 x0
= XINT (lx
), y0
= XINT (ly
);
27729 for (i
= 0; i
< n
; i
+= 2)
27731 int x1
= x0
, y1
= y0
;
27732 if ((lx
= poly
[i
], !INTEGERP (lx
))
27733 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27735 x0
= XINT (lx
), y0
= XINT (ly
);
27737 /* Does this segment cross the X line? */
27745 if (y
> y0
&& y
> y1
)
27747 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27757 find_hot_spot (Lisp_Object map
, int x
, int y
)
27759 while (CONSP (map
))
27761 if (CONSP (XCAR (map
))
27762 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27770 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27772 doc
: /* Lookup in image map MAP coordinates X and Y.
27773 An image map is an alist where each element has the format (AREA ID PLIST).
27774 An AREA is specified as either a rectangle, a circle, or a polygon:
27775 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27776 pixel coordinates of the upper left and bottom right corners.
27777 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27778 and the radius of the circle; r may be a float or integer.
27779 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27780 vector describes one corner in the polygon.
27781 Returns the alist element for the first matching AREA in MAP. */)
27782 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27790 return find_hot_spot (map
,
27791 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27792 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27796 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27798 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27800 /* Do not change cursor shape while dragging mouse. */
27801 if (!NILP (do_mouse_tracking
))
27804 if (!NILP (pointer
))
27806 if (EQ (pointer
, Qarrow
))
27807 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27808 else if (EQ (pointer
, Qhand
))
27809 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27810 else if (EQ (pointer
, Qtext
))
27811 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27812 else if (EQ (pointer
, intern ("hdrag")))
27813 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27814 #ifdef HAVE_X_WINDOWS
27815 else if (EQ (pointer
, intern ("vdrag")))
27816 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27818 else if (EQ (pointer
, intern ("hourglass")))
27819 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27820 else if (EQ (pointer
, Qmodeline
))
27821 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27823 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27826 if (cursor
!= No_Cursor
)
27827 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27830 #endif /* HAVE_WINDOW_SYSTEM */
27832 /* Take proper action when mouse has moved to the mode or header line
27833 or marginal area AREA of window W, x-position X and y-position Y.
27834 X is relative to the start of the text display area of W, so the
27835 width of bitmap areas and scroll bars must be subtracted to get a
27836 position relative to the start of the mode line. */
27839 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27840 enum window_part area
)
27842 struct window
*w
= XWINDOW (window
);
27843 struct frame
*f
= XFRAME (w
->frame
);
27844 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27845 #ifdef HAVE_WINDOW_SYSTEM
27846 Display_Info
*dpyinfo
;
27848 Cursor cursor
= No_Cursor
;
27849 Lisp_Object pointer
= Qnil
;
27850 int dx
, dy
, width
, height
;
27852 Lisp_Object string
, object
= Qnil
;
27853 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27855 Lisp_Object mouse_face
;
27856 int original_x_pixel
= x
;
27857 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27858 struct glyph_row
*row
IF_LINT (= 0);
27860 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27865 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27866 returns them in row/column units! */
27867 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27868 &object
, &dx
, &dy
, &width
, &height
);
27870 row
= (area
== ON_MODE_LINE
27871 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27872 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27874 /* Find the glyph under the mouse pointer. */
27875 if (row
->mode_line_p
&& row
->enabled_p
)
27877 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27878 end
= glyph
+ row
->used
[TEXT_AREA
];
27880 for (x0
= original_x_pixel
;
27881 glyph
< end
&& x0
>= glyph
->pixel_width
;
27883 x0
-= glyph
->pixel_width
;
27891 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27892 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27893 returns them in row/column units! */
27894 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27895 &object
, &dx
, &dy
, &width
, &height
);
27900 #ifdef HAVE_WINDOW_SYSTEM
27901 if (IMAGEP (object
))
27903 Lisp_Object image_map
, hotspot
;
27904 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27906 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27908 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27912 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27913 If so, we could look for mouse-enter, mouse-leave
27914 properties in PLIST (and do something...). */
27915 hotspot
= XCDR (hotspot
);
27916 if (CONSP (hotspot
)
27917 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27919 pointer
= Fplist_get (plist
, Qpointer
);
27920 if (NILP (pointer
))
27922 help
= Fplist_get (plist
, Qhelp_echo
);
27925 help_echo_string
= help
;
27926 XSETWINDOW (help_echo_window
, w
);
27927 help_echo_object
= w
->contents
;
27928 help_echo_pos
= charpos
;
27932 if (NILP (pointer
))
27933 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27935 #endif /* HAVE_WINDOW_SYSTEM */
27937 if (STRINGP (string
))
27938 pos
= make_number (charpos
);
27940 /* Set the help text and mouse pointer. If the mouse is on a part
27941 of the mode line without any text (e.g. past the right edge of
27942 the mode line text), use the default help text and pointer. */
27943 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27945 /* Arrange to display the help by setting the global variables
27946 help_echo_string, help_echo_object, and help_echo_pos. */
27949 if (STRINGP (string
))
27950 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27954 help_echo_string
= help
;
27955 XSETWINDOW (help_echo_window
, w
);
27956 help_echo_object
= string
;
27957 help_echo_pos
= charpos
;
27959 else if (area
== ON_MODE_LINE
)
27961 Lisp_Object default_help
27962 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27965 if (STRINGP (default_help
))
27967 help_echo_string
= default_help
;
27968 XSETWINDOW (help_echo_window
, w
);
27969 help_echo_object
= Qnil
;
27970 help_echo_pos
= -1;
27975 #ifdef HAVE_WINDOW_SYSTEM
27976 /* Change the mouse pointer according to what is under it. */
27977 if (FRAME_WINDOW_P (f
))
27979 dpyinfo
= FRAME_DISPLAY_INFO (f
);
27980 if (STRINGP (string
))
27982 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27984 if (NILP (pointer
))
27985 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27987 /* Change the mouse pointer according to what is under X/Y. */
27989 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27992 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27993 if (!KEYMAPP (map
))
27994 map
= Fget_text_property (pos
, Qkeymap
, string
);
27995 if (!KEYMAPP (map
))
27996 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28000 /* Default mode-line pointer. */
28001 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28006 /* Change the mouse face according to what is under X/Y. */
28007 if (STRINGP (string
))
28009 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28010 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28011 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28016 struct glyph
* tmp_glyph
;
28020 int total_pixel_width
;
28021 ptrdiff_t begpos
, endpos
, ignore
;
28025 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28026 Qmouse_face
, string
, Qnil
);
28032 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28034 endpos
= SCHARS (string
);
28038 /* Calculate the glyph position GPOS of GLYPH in the
28039 displayed string, relative to the beginning of the
28040 highlighted part of the string.
28042 Note: GPOS is different from CHARPOS. CHARPOS is the
28043 position of GLYPH in the internal string object. A mode
28044 line string format has structures which are converted to
28045 a flattened string by the Emacs Lisp interpreter. The
28046 internal string is an element of those structures. The
28047 displayed string is the flattened string. */
28048 tmp_glyph
= row_start_glyph
;
28049 while (tmp_glyph
< glyph
28050 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28051 && begpos
<= tmp_glyph
->charpos
28052 && tmp_glyph
->charpos
< endpos
)))
28054 gpos
= glyph
- tmp_glyph
;
28056 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28057 the highlighted part of the displayed string to which
28058 GLYPH belongs. Note: GSEQ_LENGTH is different from
28059 SCHARS (STRING), because the latter returns the length of
28060 the internal string. */
28061 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28063 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28064 && begpos
<= tmp_glyph
->charpos
28065 && tmp_glyph
->charpos
< endpos
));
28068 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28070 /* Calculate the total pixel width of all the glyphs between
28071 the beginning of the highlighted area and GLYPH. */
28072 total_pixel_width
= 0;
28073 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28074 total_pixel_width
+= tmp_glyph
->pixel_width
;
28076 /* Pre calculation of re-rendering position. Note: X is in
28077 column units here, after the call to mode_line_string or
28078 marginal_area_string. */
28080 vpos
= (area
== ON_MODE_LINE
28081 ? (w
->current_matrix
)->nrows
- 1
28084 /* If GLYPH's position is included in the region that is
28085 already drawn in mouse face, we have nothing to do. */
28086 if ( EQ (window
, hlinfo
->mouse_face_window
)
28087 && (!row
->reversed_p
28088 ? (hlinfo
->mouse_face_beg_col
<= hpos
28089 && hpos
< hlinfo
->mouse_face_end_col
)
28090 /* In R2L rows we swap BEG and END, see below. */
28091 : (hlinfo
->mouse_face_end_col
<= hpos
28092 && hpos
< hlinfo
->mouse_face_beg_col
))
28093 && hlinfo
->mouse_face_beg_row
== vpos
)
28096 if (clear_mouse_face (hlinfo
))
28097 cursor
= No_Cursor
;
28099 if (!row
->reversed_p
)
28101 hlinfo
->mouse_face_beg_col
= hpos
;
28102 hlinfo
->mouse_face_beg_x
= original_x_pixel
28103 - (total_pixel_width
+ dx
);
28104 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28105 hlinfo
->mouse_face_end_x
= 0;
28109 /* In R2L rows, show_mouse_face expects BEG and END
28110 coordinates to be swapped. */
28111 hlinfo
->mouse_face_end_col
= hpos
;
28112 hlinfo
->mouse_face_end_x
= original_x_pixel
28113 - (total_pixel_width
+ dx
);
28114 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28115 hlinfo
->mouse_face_beg_x
= 0;
28118 hlinfo
->mouse_face_beg_row
= vpos
;
28119 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28120 hlinfo
->mouse_face_past_end
= 0;
28121 hlinfo
->mouse_face_window
= window
;
28123 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28128 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28130 if (NILP (pointer
))
28133 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28134 clear_mouse_face (hlinfo
);
28136 #ifdef HAVE_WINDOW_SYSTEM
28137 if (FRAME_WINDOW_P (f
))
28138 define_frame_cursor1 (f
, cursor
, pointer
);
28144 Take proper action when the mouse has moved to position X, Y on
28145 frame F with regards to highlighting portions of display that have
28146 mouse-face properties. Also de-highlight portions of display where
28147 the mouse was before, set the mouse pointer shape as appropriate
28148 for the mouse coordinates, and activate help echo (tooltips).
28149 X and Y can be negative or out of range. */
28152 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28154 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28155 enum window_part part
= ON_NOTHING
;
28156 Lisp_Object window
;
28158 Cursor cursor
= No_Cursor
;
28159 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28162 /* When a menu is active, don't highlight because this looks odd. */
28163 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28164 if (popup_activated ())
28168 if (!f
->glyphs_initialized_p
28169 || f
->pointer_invisible
)
28172 hlinfo
->mouse_face_mouse_x
= x
;
28173 hlinfo
->mouse_face_mouse_y
= y
;
28174 hlinfo
->mouse_face_mouse_frame
= f
;
28176 if (hlinfo
->mouse_face_defer
)
28179 /* Which window is that in? */
28180 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28182 /* If displaying active text in another window, clear that. */
28183 if (! EQ (window
, hlinfo
->mouse_face_window
)
28184 /* Also clear if we move out of text area in same window. */
28185 || (!NILP (hlinfo
->mouse_face_window
)
28188 && part
!= ON_MODE_LINE
28189 && part
!= ON_HEADER_LINE
))
28190 clear_mouse_face (hlinfo
);
28192 /* Not on a window -> return. */
28193 if (!WINDOWP (window
))
28196 /* Reset help_echo_string. It will get recomputed below. */
28197 help_echo_string
= Qnil
;
28199 /* Convert to window-relative pixel coordinates. */
28200 w
= XWINDOW (window
);
28201 frame_to_window_pixel_xy (w
, &x
, &y
);
28203 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28204 /* Handle tool-bar window differently since it doesn't display a
28206 if (EQ (window
, f
->tool_bar_window
))
28208 note_tool_bar_highlight (f
, x
, y
);
28213 /* Mouse is on the mode, header line or margin? */
28214 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28215 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28217 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28221 #ifdef HAVE_WINDOW_SYSTEM
28222 if (part
== ON_VERTICAL_BORDER
)
28224 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28225 help_echo_string
= build_string ("drag-mouse-1: resize");
28227 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28228 || part
== ON_SCROLL_BAR
)
28229 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28231 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28234 /* Are we in a window whose display is up to date?
28235 And verify the buffer's text has not changed. */
28236 b
= XBUFFER (w
->contents
);
28237 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28239 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28241 struct glyph
*glyph
;
28242 Lisp_Object object
;
28243 Lisp_Object mouse_face
= Qnil
, position
;
28244 Lisp_Object
*overlay_vec
= NULL
;
28245 ptrdiff_t i
, noverlays
;
28246 struct buffer
*obuf
;
28247 ptrdiff_t obegv
, ozv
;
28250 /* Find the glyph under X/Y. */
28251 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28253 #ifdef HAVE_WINDOW_SYSTEM
28254 /* Look for :pointer property on image. */
28255 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28257 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28258 if (img
!= NULL
&& IMAGEP (img
->spec
))
28260 Lisp_Object image_map
, hotspot
;
28261 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28263 && (hotspot
= find_hot_spot (image_map
,
28264 glyph
->slice
.img
.x
+ dx
,
28265 glyph
->slice
.img
.y
+ dy
),
28267 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28271 /* Could check XCAR (hotspot) to see if we enter/leave
28273 If so, we could look for mouse-enter, mouse-leave
28274 properties in PLIST (and do something...). */
28275 hotspot
= XCDR (hotspot
);
28276 if (CONSP (hotspot
)
28277 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28279 pointer
= Fplist_get (plist
, Qpointer
);
28280 if (NILP (pointer
))
28282 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28283 if (!NILP (help_echo_string
))
28285 help_echo_window
= window
;
28286 help_echo_object
= glyph
->object
;
28287 help_echo_pos
= glyph
->charpos
;
28291 if (NILP (pointer
))
28292 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28295 #endif /* HAVE_WINDOW_SYSTEM */
28297 /* Clear mouse face if X/Y not over text. */
28299 || area
!= TEXT_AREA
28300 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28301 /* Glyph's OBJECT is an integer for glyphs inserted by the
28302 display engine for its internal purposes, like truncation
28303 and continuation glyphs and blanks beyond the end of
28304 line's text on text terminals. If we are over such a
28305 glyph, we are not over any text. */
28306 || INTEGERP (glyph
->object
)
28307 /* R2L rows have a stretch glyph at their front, which
28308 stands for no text, whereas L2R rows have no glyphs at
28309 all beyond the end of text. Treat such stretch glyphs
28310 like we do with NULL glyphs in L2R rows. */
28311 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28312 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28313 && glyph
->type
== STRETCH_GLYPH
28314 && glyph
->avoid_cursor_p
))
28316 if (clear_mouse_face (hlinfo
))
28317 cursor
= No_Cursor
;
28318 #ifdef HAVE_WINDOW_SYSTEM
28319 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28321 if (area
!= TEXT_AREA
)
28322 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28324 pointer
= Vvoid_text_area_pointer
;
28330 pos
= glyph
->charpos
;
28331 object
= glyph
->object
;
28332 if (!STRINGP (object
) && !BUFFERP (object
))
28335 /* If we get an out-of-range value, return now; avoid an error. */
28336 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28339 /* Make the window's buffer temporarily current for
28340 overlays_at and compute_char_face. */
28341 obuf
= current_buffer
;
28342 current_buffer
= b
;
28348 /* Is this char mouse-active or does it have help-echo? */
28349 position
= make_number (pos
);
28351 if (BUFFERP (object
))
28353 /* Put all the overlays we want in a vector in overlay_vec. */
28354 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28355 /* Sort overlays into increasing priority order. */
28356 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28361 if (NILP (Vmouse_highlight
))
28363 clear_mouse_face (hlinfo
);
28364 goto check_help_echo
;
28367 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28370 cursor
= No_Cursor
;
28372 /* Check mouse-face highlighting. */
28374 /* If there exists an overlay with mouse-face overlapping
28375 the one we are currently highlighting, we have to
28376 check if we enter the overlapping overlay, and then
28377 highlight only that. */
28378 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28379 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28381 /* Find the highest priority overlay with a mouse-face. */
28382 Lisp_Object overlay
= Qnil
;
28383 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28385 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28386 if (!NILP (mouse_face
))
28387 overlay
= overlay_vec
[i
];
28390 /* If we're highlighting the same overlay as before, there's
28391 no need to do that again. */
28392 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28393 goto check_help_echo
;
28394 hlinfo
->mouse_face_overlay
= overlay
;
28396 /* Clear the display of the old active region, if any. */
28397 if (clear_mouse_face (hlinfo
))
28398 cursor
= No_Cursor
;
28400 /* If no overlay applies, get a text property. */
28401 if (NILP (overlay
))
28402 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28404 /* Next, compute the bounds of the mouse highlighting and
28406 if (!NILP (mouse_face
) && STRINGP (object
))
28408 /* The mouse-highlighting comes from a display string
28409 with a mouse-face. */
28413 s
= Fprevious_single_property_change
28414 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28415 e
= Fnext_single_property_change
28416 (position
, Qmouse_face
, object
, Qnil
);
28418 s
= make_number (0);
28420 e
= make_number (SCHARS (object
));
28421 mouse_face_from_string_pos (w
, hlinfo
, object
,
28422 XINT (s
), XINT (e
));
28423 hlinfo
->mouse_face_past_end
= 0;
28424 hlinfo
->mouse_face_window
= window
;
28425 hlinfo
->mouse_face_face_id
28426 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28427 glyph
->face_id
, 1);
28428 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28429 cursor
= No_Cursor
;
28433 /* The mouse-highlighting, if any, comes from an overlay
28434 or text property in the buffer. */
28435 Lisp_Object buffer
IF_LINT (= Qnil
);
28436 Lisp_Object disp_string
IF_LINT (= Qnil
);
28438 if (STRINGP (object
))
28440 /* If we are on a display string with no mouse-face,
28441 check if the text under it has one. */
28442 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28443 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28444 pos
= string_buffer_position (object
, start
);
28447 mouse_face
= get_char_property_and_overlay
28448 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28449 buffer
= w
->contents
;
28450 disp_string
= object
;
28456 disp_string
= Qnil
;
28459 if (!NILP (mouse_face
))
28461 Lisp_Object before
, after
;
28462 Lisp_Object before_string
, after_string
;
28463 /* To correctly find the limits of mouse highlight
28464 in a bidi-reordered buffer, we must not use the
28465 optimization of limiting the search in
28466 previous-single-property-change and
28467 next-single-property-change, because
28468 rows_from_pos_range needs the real start and end
28469 positions to DTRT in this case. That's because
28470 the first row visible in a window does not
28471 necessarily display the character whose position
28472 is the smallest. */
28474 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28475 ? Fmarker_position (w
->start
)
28478 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28479 ? make_number (BUF_Z (XBUFFER (buffer
))
28480 - w
->window_end_pos
)
28483 if (NILP (overlay
))
28485 /* Handle the text property case. */
28486 before
= Fprevious_single_property_change
28487 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28488 after
= Fnext_single_property_change
28489 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28490 before_string
= after_string
= Qnil
;
28494 /* Handle the overlay case. */
28495 before
= Foverlay_start (overlay
);
28496 after
= Foverlay_end (overlay
);
28497 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28498 after_string
= Foverlay_get (overlay
, Qafter_string
);
28500 if (!STRINGP (before_string
)) before_string
= Qnil
;
28501 if (!STRINGP (after_string
)) after_string
= Qnil
;
28504 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28507 : XFASTINT (before
),
28509 ? BUF_Z (XBUFFER (buffer
))
28510 : XFASTINT (after
),
28511 before_string
, after_string
,
28513 cursor
= No_Cursor
;
28520 /* Look for a `help-echo' property. */
28521 if (NILP (help_echo_string
)) {
28522 Lisp_Object help
, overlay
;
28524 /* Check overlays first. */
28525 help
= overlay
= Qnil
;
28526 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28528 overlay
= overlay_vec
[i
];
28529 help
= Foverlay_get (overlay
, Qhelp_echo
);
28534 help_echo_string
= help
;
28535 help_echo_window
= window
;
28536 help_echo_object
= overlay
;
28537 help_echo_pos
= pos
;
28541 Lisp_Object obj
= glyph
->object
;
28542 ptrdiff_t charpos
= glyph
->charpos
;
28544 /* Try text properties. */
28547 && charpos
< SCHARS (obj
))
28549 help
= Fget_text_property (make_number (charpos
),
28553 /* If the string itself doesn't specify a help-echo,
28554 see if the buffer text ``under'' it does. */
28555 struct glyph_row
*r
28556 = MATRIX_ROW (w
->current_matrix
, vpos
);
28557 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28558 ptrdiff_t p
= string_buffer_position (obj
, start
);
28561 help
= Fget_char_property (make_number (p
),
28562 Qhelp_echo
, w
->contents
);
28571 else if (BUFFERP (obj
)
28574 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28579 help_echo_string
= help
;
28580 help_echo_window
= window
;
28581 help_echo_object
= obj
;
28582 help_echo_pos
= charpos
;
28587 #ifdef HAVE_WINDOW_SYSTEM
28588 /* Look for a `pointer' property. */
28589 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28591 /* Check overlays first. */
28592 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28593 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28595 if (NILP (pointer
))
28597 Lisp_Object obj
= glyph
->object
;
28598 ptrdiff_t charpos
= glyph
->charpos
;
28600 /* Try text properties. */
28603 && charpos
< SCHARS (obj
))
28605 pointer
= Fget_text_property (make_number (charpos
),
28607 if (NILP (pointer
))
28609 /* If the string itself doesn't specify a pointer,
28610 see if the buffer text ``under'' it does. */
28611 struct glyph_row
*r
28612 = MATRIX_ROW (w
->current_matrix
, vpos
);
28613 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28614 ptrdiff_t p
= string_buffer_position (obj
, start
);
28616 pointer
= Fget_char_property (make_number (p
),
28617 Qpointer
, w
->contents
);
28620 else if (BUFFERP (obj
)
28623 pointer
= Fget_text_property (make_number (charpos
),
28627 #endif /* HAVE_WINDOW_SYSTEM */
28631 current_buffer
= obuf
;
28636 #ifdef HAVE_WINDOW_SYSTEM
28637 if (FRAME_WINDOW_P (f
))
28638 define_frame_cursor1 (f
, cursor
, pointer
);
28640 /* This is here to prevent a compiler error, about "label at end of
28641 compound statement". */
28648 Clear any mouse-face on window W. This function is part of the
28649 redisplay interface, and is called from try_window_id and similar
28650 functions to ensure the mouse-highlight is off. */
28653 x_clear_window_mouse_face (struct window
*w
)
28655 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28656 Lisp_Object window
;
28659 XSETWINDOW (window
, w
);
28660 if (EQ (window
, hlinfo
->mouse_face_window
))
28661 clear_mouse_face (hlinfo
);
28667 Just discard the mouse face information for frame F, if any.
28668 This is used when the size of F is changed. */
28671 cancel_mouse_face (struct frame
*f
)
28673 Lisp_Object window
;
28674 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28676 window
= hlinfo
->mouse_face_window
;
28677 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28678 reset_mouse_highlight (hlinfo
);
28683 /***********************************************************************
28685 ***********************************************************************/
28687 #ifdef HAVE_WINDOW_SYSTEM
28689 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28690 which intersects rectangle R. R is in window-relative coordinates. */
28693 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28694 enum glyph_row_area area
)
28696 struct glyph
*first
= row
->glyphs
[area
];
28697 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28698 struct glyph
*last
;
28699 int first_x
, start_x
, x
;
28701 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28702 /* If row extends face to end of line write the whole line. */
28703 draw_glyphs (w
, 0, row
, area
,
28704 0, row
->used
[area
],
28705 DRAW_NORMAL_TEXT
, 0);
28708 /* Set START_X to the window-relative start position for drawing glyphs of
28709 AREA. The first glyph of the text area can be partially visible.
28710 The first glyphs of other areas cannot. */
28711 start_x
= window_box_left_offset (w
, area
);
28713 if (area
== TEXT_AREA
)
28716 /* Find the first glyph that must be redrawn. */
28718 && x
+ first
->pixel_width
< r
->x
)
28720 x
+= first
->pixel_width
;
28724 /* Find the last one. */
28728 && x
< r
->x
+ r
->width
)
28730 x
+= last
->pixel_width
;
28736 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28737 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28738 DRAW_NORMAL_TEXT
, 0);
28743 /* Redraw the parts of the glyph row ROW on window W intersecting
28744 rectangle R. R is in window-relative coordinates. Value is
28745 non-zero if mouse-face was overwritten. */
28748 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28750 eassert (row
->enabled_p
);
28752 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28753 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28754 0, row
->used
[TEXT_AREA
],
28755 DRAW_NORMAL_TEXT
, 0);
28758 if (row
->used
[LEFT_MARGIN_AREA
])
28759 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28760 if (row
->used
[TEXT_AREA
])
28761 expose_area (w
, row
, r
, TEXT_AREA
);
28762 if (row
->used
[RIGHT_MARGIN_AREA
])
28763 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28764 draw_row_fringe_bitmaps (w
, row
);
28767 return row
->mouse_face_p
;
28771 /* Redraw those parts of glyphs rows during expose event handling that
28772 overlap other rows. Redrawing of an exposed line writes over parts
28773 of lines overlapping that exposed line; this function fixes that.
28775 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28776 row in W's current matrix that is exposed and overlaps other rows.
28777 LAST_OVERLAPPING_ROW is the last such row. */
28780 expose_overlaps (struct window
*w
,
28781 struct glyph_row
*first_overlapping_row
,
28782 struct glyph_row
*last_overlapping_row
,
28785 struct glyph_row
*row
;
28787 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28788 if (row
->overlapping_p
)
28790 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28793 if (row
->used
[LEFT_MARGIN_AREA
])
28794 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28796 if (row
->used
[TEXT_AREA
])
28797 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28799 if (row
->used
[RIGHT_MARGIN_AREA
])
28800 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28806 /* Return non-zero if W's cursor intersects rectangle R. */
28809 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28811 XRectangle cr
, result
;
28812 struct glyph
*cursor_glyph
;
28813 struct glyph_row
*row
;
28815 if (w
->phys_cursor
.vpos
>= 0
28816 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28817 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28819 && row
->cursor_in_fringe_p
)
28821 /* Cursor is in the fringe. */
28822 cr
.x
= window_box_right_offset (w
,
28823 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28824 ? RIGHT_MARGIN_AREA
28827 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28828 cr
.height
= row
->height
;
28829 return x_intersect_rectangles (&cr
, r
, &result
);
28832 cursor_glyph
= get_phys_cursor_glyph (w
);
28835 /* r is relative to W's box, but w->phys_cursor.x is relative
28836 to left edge of W's TEXT area. Adjust it. */
28837 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28838 cr
.y
= w
->phys_cursor
.y
;
28839 cr
.width
= cursor_glyph
->pixel_width
;
28840 cr
.height
= w
->phys_cursor_height
;
28841 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28842 I assume the effect is the same -- and this is portable. */
28843 return x_intersect_rectangles (&cr
, r
, &result
);
28845 /* If we don't understand the format, pretend we're not in the hot-spot. */
28851 Draw a vertical window border to the right of window W if W doesn't
28852 have vertical scroll bars. */
28855 x_draw_vertical_border (struct window
*w
)
28857 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28859 /* We could do better, if we knew what type of scroll-bar the adjacent
28860 windows (on either side) have... But we don't :-(
28861 However, I think this works ok. ++KFS 2003-04-25 */
28863 /* Redraw borders between horizontally adjacent windows. Don't
28864 do it for frames with vertical scroll bars because either the
28865 right scroll bar of a window, or the left scroll bar of its
28866 neighbor will suffice as a border. */
28867 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28870 /* Note: It is necessary to redraw both the left and the right
28871 borders, for when only this single window W is being
28873 if (!WINDOW_RIGHTMOST_P (w
)
28874 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28876 int x0
, x1
, y0
, y1
;
28878 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28881 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28884 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28886 if (!WINDOW_LEFTMOST_P (w
)
28887 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28889 int x0
, x1
, y0
, y1
;
28891 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28894 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28897 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28902 /* Redraw the part of window W intersection rectangle FR. Pixel
28903 coordinates in FR are frame-relative. Call this function with
28904 input blocked. Value is non-zero if the exposure overwrites
28908 expose_window (struct window
*w
, XRectangle
*fr
)
28910 struct frame
*f
= XFRAME (w
->frame
);
28912 int mouse_face_overwritten_p
= 0;
28914 /* If window is not yet fully initialized, do nothing. This can
28915 happen when toolkit scroll bars are used and a window is split.
28916 Reconfiguring the scroll bar will generate an expose for a newly
28918 if (w
->current_matrix
== NULL
)
28921 /* When we're currently updating the window, display and current
28922 matrix usually don't agree. Arrange for a thorough display
28924 if (w
->must_be_updated_p
)
28926 SET_FRAME_GARBAGED (f
);
28930 /* Frame-relative pixel rectangle of W. */
28931 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28932 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28933 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28934 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28936 if (x_intersect_rectangles (fr
, &wr
, &r
))
28938 int yb
= window_text_bottom_y (w
);
28939 struct glyph_row
*row
;
28940 int cursor_cleared_p
, phys_cursor_on_p
;
28941 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28943 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28944 r
.x
, r
.y
, r
.width
, r
.height
));
28946 /* Convert to window coordinates. */
28947 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28948 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28950 /* Turn off the cursor. */
28951 if (!w
->pseudo_window_p
28952 && phys_cursor_in_rect_p (w
, &r
))
28954 x_clear_cursor (w
);
28955 cursor_cleared_p
= 1;
28958 cursor_cleared_p
= 0;
28960 /* If the row containing the cursor extends face to end of line,
28961 then expose_area might overwrite the cursor outside the
28962 rectangle and thus notice_overwritten_cursor might clear
28963 w->phys_cursor_on_p. We remember the original value and
28964 check later if it is changed. */
28965 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28967 /* Update lines intersecting rectangle R. */
28968 first_overlapping_row
= last_overlapping_row
= NULL
;
28969 for (row
= w
->current_matrix
->rows
;
28974 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28976 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28977 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28978 || (r
.y
>= y0
&& r
.y
< y1
)
28979 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28981 /* A header line may be overlapping, but there is no need
28982 to fix overlapping areas for them. KFS 2005-02-12 */
28983 if (row
->overlapping_p
&& !row
->mode_line_p
)
28985 if (first_overlapping_row
== NULL
)
28986 first_overlapping_row
= row
;
28987 last_overlapping_row
= row
;
28991 if (expose_line (w
, row
, &r
))
28992 mouse_face_overwritten_p
= 1;
28995 else if (row
->overlapping_p
)
28997 /* We must redraw a row overlapping the exposed area. */
28999 ? y0
+ row
->phys_height
> r
.y
29000 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29002 if (first_overlapping_row
== NULL
)
29003 first_overlapping_row
= row
;
29004 last_overlapping_row
= row
;
29012 /* Display the mode line if there is one. */
29013 if (WINDOW_WANTS_MODELINE_P (w
)
29014 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29016 && row
->y
< r
.y
+ r
.height
)
29018 if (expose_line (w
, row
, &r
))
29019 mouse_face_overwritten_p
= 1;
29022 if (!w
->pseudo_window_p
)
29024 /* Fix the display of overlapping rows. */
29025 if (first_overlapping_row
)
29026 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29029 /* Draw border between windows. */
29030 x_draw_vertical_border (w
);
29032 /* Turn the cursor on again. */
29033 if (cursor_cleared_p
29034 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29035 update_window_cursor (w
, 1);
29039 return mouse_face_overwritten_p
;
29044 /* Redraw (parts) of all windows in the window tree rooted at W that
29045 intersect R. R contains frame pixel coordinates. Value is
29046 non-zero if the exposure overwrites mouse-face. */
29049 expose_window_tree (struct window
*w
, XRectangle
*r
)
29051 struct frame
*f
= XFRAME (w
->frame
);
29052 int mouse_face_overwritten_p
= 0;
29054 while (w
&& !FRAME_GARBAGED_P (f
))
29056 if (WINDOWP (w
->contents
))
29057 mouse_face_overwritten_p
29058 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29060 mouse_face_overwritten_p
|= expose_window (w
, r
);
29062 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29065 return mouse_face_overwritten_p
;
29070 Redisplay an exposed area of frame F. X and Y are the upper-left
29071 corner of the exposed rectangle. W and H are width and height of
29072 the exposed area. All are pixel values. W or H zero means redraw
29073 the entire frame. */
29076 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29079 int mouse_face_overwritten_p
= 0;
29081 TRACE ((stderr
, "expose_frame "));
29083 /* No need to redraw if frame will be redrawn soon. */
29084 if (FRAME_GARBAGED_P (f
))
29086 TRACE ((stderr
, " garbaged\n"));
29090 /* If basic faces haven't been realized yet, there is no point in
29091 trying to redraw anything. This can happen when we get an expose
29092 event while Emacs is starting, e.g. by moving another window. */
29093 if (FRAME_FACE_CACHE (f
) == NULL
29094 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29096 TRACE ((stderr
, " no faces\n"));
29100 if (w
== 0 || h
== 0)
29103 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29104 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29114 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29115 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29117 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29118 if (WINDOWP (f
->tool_bar_window
))
29119 mouse_face_overwritten_p
29120 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29123 #ifdef HAVE_X_WINDOWS
29125 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29126 if (WINDOWP (f
->menu_bar_window
))
29127 mouse_face_overwritten_p
29128 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29129 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29133 /* Some window managers support a focus-follows-mouse style with
29134 delayed raising of frames. Imagine a partially obscured frame,
29135 and moving the mouse into partially obscured mouse-face on that
29136 frame. The visible part of the mouse-face will be highlighted,
29137 then the WM raises the obscured frame. With at least one WM, KDE
29138 2.1, Emacs is not getting any event for the raising of the frame
29139 (even tried with SubstructureRedirectMask), only Expose events.
29140 These expose events will draw text normally, i.e. not
29141 highlighted. Which means we must redo the highlight here.
29142 Subsume it under ``we love X''. --gerd 2001-08-15 */
29143 /* Included in Windows version because Windows most likely does not
29144 do the right thing if any third party tool offers
29145 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29146 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29148 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29149 if (f
== hlinfo
->mouse_face_mouse_frame
)
29151 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29152 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29153 clear_mouse_face (hlinfo
);
29154 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29161 Determine the intersection of two rectangles R1 and R2. Return
29162 the intersection in *RESULT. Value is non-zero if RESULT is not
29166 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29168 XRectangle
*left
, *right
;
29169 XRectangle
*upper
, *lower
;
29170 int intersection_p
= 0;
29172 /* Rearrange so that R1 is the left-most rectangle. */
29174 left
= r1
, right
= r2
;
29176 left
= r2
, right
= r1
;
29178 /* X0 of the intersection is right.x0, if this is inside R1,
29179 otherwise there is no intersection. */
29180 if (right
->x
<= left
->x
+ left
->width
)
29182 result
->x
= right
->x
;
29184 /* The right end of the intersection is the minimum of
29185 the right ends of left and right. */
29186 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29189 /* Same game for Y. */
29191 upper
= r1
, lower
= r2
;
29193 upper
= r2
, lower
= r1
;
29195 /* The upper end of the intersection is lower.y0, if this is inside
29196 of upper. Otherwise, there is no intersection. */
29197 if (lower
->y
<= upper
->y
+ upper
->height
)
29199 result
->y
= lower
->y
;
29201 /* The lower end of the intersection is the minimum of the lower
29202 ends of upper and lower. */
29203 result
->height
= (min (lower
->y
+ lower
->height
,
29204 upper
->y
+ upper
->height
)
29206 intersection_p
= 1;
29210 return intersection_p
;
29213 #endif /* HAVE_WINDOW_SYSTEM */
29216 /***********************************************************************
29218 ***********************************************************************/
29221 syms_of_xdisp (void)
29223 Vwith_echo_area_save_vector
= Qnil
;
29224 staticpro (&Vwith_echo_area_save_vector
);
29226 Vmessage_stack
= Qnil
;
29227 staticpro (&Vmessage_stack
);
29229 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29230 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29232 message_dolog_marker1
= Fmake_marker ();
29233 staticpro (&message_dolog_marker1
);
29234 message_dolog_marker2
= Fmake_marker ();
29235 staticpro (&message_dolog_marker2
);
29236 message_dolog_marker3
= Fmake_marker ();
29237 staticpro (&message_dolog_marker3
);
29240 defsubr (&Sdump_frame_glyph_matrix
);
29241 defsubr (&Sdump_glyph_matrix
);
29242 defsubr (&Sdump_glyph_row
);
29243 defsubr (&Sdump_tool_bar_row
);
29244 defsubr (&Strace_redisplay
);
29245 defsubr (&Strace_to_stderr
);
29247 #ifdef HAVE_WINDOW_SYSTEM
29248 defsubr (&Stool_bar_lines_needed
);
29249 defsubr (&Slookup_image_map
);
29251 defsubr (&Sline_pixel_height
);
29252 defsubr (&Sformat_mode_line
);
29253 defsubr (&Sinvisible_p
);
29254 defsubr (&Scurrent_bidi_paragraph_direction
);
29255 defsubr (&Smove_point_visually
);
29257 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29258 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29259 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29260 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29261 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29262 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29263 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29264 DEFSYM (Qeval
, "eval");
29265 DEFSYM (QCdata
, ":data");
29266 DEFSYM (Qdisplay
, "display");
29267 DEFSYM (Qspace_width
, "space-width");
29268 DEFSYM (Qraise
, "raise");
29269 DEFSYM (Qslice
, "slice");
29270 DEFSYM (Qspace
, "space");
29271 DEFSYM (Qmargin
, "margin");
29272 DEFSYM (Qpointer
, "pointer");
29273 DEFSYM (Qleft_margin
, "left-margin");
29274 DEFSYM (Qright_margin
, "right-margin");
29275 DEFSYM (Qcenter
, "center");
29276 DEFSYM (Qline_height
, "line-height");
29277 DEFSYM (QCalign_to
, ":align-to");
29278 DEFSYM (QCrelative_width
, ":relative-width");
29279 DEFSYM (QCrelative_height
, ":relative-height");
29280 DEFSYM (QCeval
, ":eval");
29281 DEFSYM (QCpropertize
, ":propertize");
29282 DEFSYM (QCfile
, ":file");
29283 DEFSYM (Qfontified
, "fontified");
29284 DEFSYM (Qfontification_functions
, "fontification-functions");
29285 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29286 DEFSYM (Qescape_glyph
, "escape-glyph");
29287 DEFSYM (Qnobreak_space
, "nobreak-space");
29288 DEFSYM (Qimage
, "image");
29289 DEFSYM (Qtext
, "text");
29290 DEFSYM (Qboth
, "both");
29291 DEFSYM (Qboth_horiz
, "both-horiz");
29292 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29293 DEFSYM (QCmap
, ":map");
29294 DEFSYM (QCpointer
, ":pointer");
29295 DEFSYM (Qrect
, "rect");
29296 DEFSYM (Qcircle
, "circle");
29297 DEFSYM (Qpoly
, "poly");
29298 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29299 DEFSYM (Qgrow_only
, "grow-only");
29300 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29301 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29302 DEFSYM (Qposition
, "position");
29303 DEFSYM (Qbuffer_position
, "buffer-position");
29304 DEFSYM (Qobject
, "object");
29305 DEFSYM (Qbar
, "bar");
29306 DEFSYM (Qhbar
, "hbar");
29307 DEFSYM (Qbox
, "box");
29308 DEFSYM (Qhollow
, "hollow");
29309 DEFSYM (Qhand
, "hand");
29310 DEFSYM (Qarrow
, "arrow");
29311 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29313 list_of_error
= list1 (list2 (intern_c_string ("error"),
29314 intern_c_string ("void-variable")));
29315 staticpro (&list_of_error
);
29317 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29318 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29319 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29320 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29322 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29323 staticpro (&echo_buffer
[0]);
29324 staticpro (&echo_buffer
[1]);
29326 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29327 staticpro (&echo_area_buffer
[0]);
29328 staticpro (&echo_area_buffer
[1]);
29330 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29331 staticpro (&Vmessages_buffer_name
);
29333 mode_line_proptrans_alist
= Qnil
;
29334 staticpro (&mode_line_proptrans_alist
);
29335 mode_line_string_list
= Qnil
;
29336 staticpro (&mode_line_string_list
);
29337 mode_line_string_face
= Qnil
;
29338 staticpro (&mode_line_string_face
);
29339 mode_line_string_face_prop
= Qnil
;
29340 staticpro (&mode_line_string_face_prop
);
29341 Vmode_line_unwind_vector
= Qnil
;
29342 staticpro (&Vmode_line_unwind_vector
);
29344 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29346 help_echo_string
= Qnil
;
29347 staticpro (&help_echo_string
);
29348 help_echo_object
= Qnil
;
29349 staticpro (&help_echo_object
);
29350 help_echo_window
= Qnil
;
29351 staticpro (&help_echo_window
);
29352 previous_help_echo_string
= Qnil
;
29353 staticpro (&previous_help_echo_string
);
29354 help_echo_pos
= -1;
29356 DEFSYM (Qright_to_left
, "right-to-left");
29357 DEFSYM (Qleft_to_right
, "left-to-right");
29359 #ifdef HAVE_WINDOW_SYSTEM
29360 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29361 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29362 For example, if a block cursor is over a tab, it will be drawn as
29363 wide as that tab on the display. */);
29364 x_stretch_cursor_p
= 0;
29367 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29368 doc
: /* Non-nil means highlight trailing whitespace.
29369 The face used for trailing whitespace is `trailing-whitespace'. */);
29370 Vshow_trailing_whitespace
= Qnil
;
29372 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29373 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29374 If the value is t, Emacs highlights non-ASCII chars which have the
29375 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29376 or `escape-glyph' face respectively.
29378 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29379 U+2011 (non-breaking hyphen) are affected.
29381 Any other non-nil value means to display these characters as a escape
29382 glyph followed by an ordinary space or hyphen.
29384 A value of nil means no special handling of these characters. */);
29385 Vnobreak_char_display
= Qt
;
29387 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29388 doc
: /* The pointer shape to show in void text areas.
29389 A value of nil means to show the text pointer. Other options are `arrow',
29390 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29391 Vvoid_text_area_pointer
= Qarrow
;
29393 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29394 doc
: /* Non-nil means don't actually do any redisplay.
29395 This is used for internal purposes. */);
29396 Vinhibit_redisplay
= Qnil
;
29398 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29399 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29400 Vglobal_mode_string
= Qnil
;
29402 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29403 doc
: /* Marker for where to display an arrow on top of the buffer text.
29404 This must be the beginning of a line in order to work.
29405 See also `overlay-arrow-string'. */);
29406 Voverlay_arrow_position
= Qnil
;
29408 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29409 doc
: /* String to display as an arrow in non-window frames.
29410 See also `overlay-arrow-position'. */);
29411 Voverlay_arrow_string
= build_pure_c_string ("=>");
29413 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29414 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29415 The symbols on this list are examined during redisplay to determine
29416 where to display overlay arrows. */);
29417 Voverlay_arrow_variable_list
29418 = list1 (intern_c_string ("overlay-arrow-position"));
29420 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29421 doc
: /* The number of lines to try scrolling a window by when point moves out.
29422 If that fails to bring point back on frame, point is centered instead.
29423 If this is zero, point is always centered after it moves off frame.
29424 If you want scrolling to always be a line at a time, you should set
29425 `scroll-conservatively' to a large value rather than set this to 1. */);
29427 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29428 doc
: /* Scroll up to this many lines, to bring point back on screen.
29429 If point moves off-screen, redisplay will scroll by up to
29430 `scroll-conservatively' lines in order to bring point just barely
29431 onto the screen again. If that cannot be done, then redisplay
29432 recenters point as usual.
29434 If the value is greater than 100, redisplay will never recenter point,
29435 but will always scroll just enough text to bring point into view, even
29436 if you move far away.
29438 A value of zero means always recenter point if it moves off screen. */);
29439 scroll_conservatively
= 0;
29441 DEFVAR_INT ("scroll-margin", scroll_margin
,
29442 doc
: /* Number of lines of margin at the top and bottom of a window.
29443 Recenter the window whenever point gets within this many lines
29444 of the top or bottom of the window. */);
29447 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29448 doc
: /* Pixels per inch value for non-window system displays.
29449 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29450 Vdisplay_pixels_per_inch
= make_float (72.0);
29453 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29456 DEFVAR_LISP ("truncate-partial-width-windows",
29457 Vtruncate_partial_width_windows
,
29458 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29459 For an integer value, truncate lines in each window narrower than the
29460 full frame width, provided the window width is less than that integer;
29461 otherwise, respect the value of `truncate-lines'.
29463 For any other non-nil value, truncate lines in all windows that do
29464 not span the full frame width.
29466 A value of nil means to respect the value of `truncate-lines'.
29468 If `word-wrap' is enabled, you might want to reduce this. */);
29469 Vtruncate_partial_width_windows
= make_number (50);
29471 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29472 doc
: /* Maximum buffer size for which line number should be displayed.
29473 If the buffer is bigger than this, the line number does not appear
29474 in the mode line. A value of nil means no limit. */);
29475 Vline_number_display_limit
= Qnil
;
29477 DEFVAR_INT ("line-number-display-limit-width",
29478 line_number_display_limit_width
,
29479 doc
: /* Maximum line width (in characters) for line number display.
29480 If the average length of the lines near point is bigger than this, then the
29481 line number may be omitted from the mode line. */);
29482 line_number_display_limit_width
= 200;
29484 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29485 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29486 highlight_nonselected_windows
= 0;
29488 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29489 doc
: /* Non-nil if more than one frame is visible on this display.
29490 Minibuffer-only frames don't count, but iconified frames do.
29491 This variable is not guaranteed to be accurate except while processing
29492 `frame-title-format' and `icon-title-format'. */);
29494 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29495 doc
: /* Template for displaying the title bar of visible frames.
29496 \(Assuming the window manager supports this feature.)
29498 This variable has the same structure as `mode-line-format', except that
29499 the %c and %l constructs are ignored. It is used only on frames for
29500 which no explicit name has been set \(see `modify-frame-parameters'). */);
29502 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29503 doc
: /* Template for displaying the title bar of an iconified frame.
29504 \(Assuming the window manager supports this feature.)
29505 This variable has the same structure as `mode-line-format' (which see),
29506 and is used only on frames for which no explicit name has been set
29507 \(see `modify-frame-parameters'). */);
29509 = Vframe_title_format
29510 = listn (CONSTYPE_PURE
, 3,
29511 intern_c_string ("multiple-frames"),
29512 build_pure_c_string ("%b"),
29513 listn (CONSTYPE_PURE
, 4,
29514 empty_unibyte_string
,
29515 intern_c_string ("invocation-name"),
29516 build_pure_c_string ("@"),
29517 intern_c_string ("system-name")));
29519 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29520 doc
: /* Maximum number of lines to keep in the message log buffer.
29521 If nil, disable message logging. If t, log messages but don't truncate
29522 the buffer when it becomes large. */);
29523 Vmessage_log_max
= make_number (1000);
29525 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29526 doc
: /* Functions called before redisplay, if window sizes have changed.
29527 The value should be a list of functions that take one argument.
29528 Just before redisplay, for each frame, if any of its windows have changed
29529 size since the last redisplay, or have been split or deleted,
29530 all the functions in the list are called, with the frame as argument. */);
29531 Vwindow_size_change_functions
= Qnil
;
29533 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29534 doc
: /* List of functions to call before redisplaying a window with scrolling.
29535 Each function is called with two arguments, the window and its new
29536 display-start position. Note that these functions are also called by
29537 `set-window-buffer'. Also note that the value of `window-end' is not
29538 valid when these functions are called.
29540 Warning: Do not use this feature to alter the way the window
29541 is scrolled. It is not designed for that, and such use probably won't
29543 Vwindow_scroll_functions
= Qnil
;
29545 DEFVAR_LISP ("window-text-change-functions",
29546 Vwindow_text_change_functions
,
29547 doc
: /* Functions to call in redisplay when text in the window might change. */);
29548 Vwindow_text_change_functions
= Qnil
;
29550 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29551 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29552 Each function is called with two arguments, the window and the end trigger value.
29553 See `set-window-redisplay-end-trigger'. */);
29554 Vredisplay_end_trigger_functions
= Qnil
;
29556 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29557 doc
: /* Non-nil means autoselect window with mouse pointer.
29558 If nil, do not autoselect windows.
29559 A positive number means delay autoselection by that many seconds: a
29560 window is autoselected only after the mouse has remained in that
29561 window for the duration of the delay.
29562 A negative number has a similar effect, but causes windows to be
29563 autoselected only after the mouse has stopped moving. \(Because of
29564 the way Emacs compares mouse events, you will occasionally wait twice
29565 that time before the window gets selected.\)
29566 Any other value means to autoselect window instantaneously when the
29567 mouse pointer enters it.
29569 Autoselection selects the minibuffer only if it is active, and never
29570 unselects the minibuffer if it is active.
29572 When customizing this variable make sure that the actual value of
29573 `focus-follows-mouse' matches the behavior of your window manager. */);
29574 Vmouse_autoselect_window
= Qnil
;
29576 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29577 doc
: /* Non-nil means automatically resize tool-bars.
29578 This dynamically changes the tool-bar's height to the minimum height
29579 that is needed to make all tool-bar items visible.
29580 If value is `grow-only', the tool-bar's height is only increased
29581 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29582 Vauto_resize_tool_bars
= Qt
;
29584 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29585 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29586 auto_raise_tool_bar_buttons_p
= 1;
29588 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29589 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29590 make_cursor_line_fully_visible_p
= 1;
29592 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29593 doc
: /* Border below tool-bar in pixels.
29594 If an integer, use it as the height of the border.
29595 If it is one of `internal-border-width' or `border-width', use the
29596 value of the corresponding frame parameter.
29597 Otherwise, no border is added below the tool-bar. */);
29598 Vtool_bar_border
= Qinternal_border_width
;
29600 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29601 doc
: /* Margin around tool-bar buttons in pixels.
29602 If an integer, use that for both horizontal and vertical margins.
29603 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29604 HORZ specifying the horizontal margin, and VERT specifying the
29605 vertical margin. */);
29606 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29608 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29609 doc
: /* Relief thickness of tool-bar buttons. */);
29610 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29612 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29613 doc
: /* Tool bar style to use.
29615 image - show images only
29616 text - show text only
29617 both - show both, text below image
29618 both-horiz - show text to the right of the image
29619 text-image-horiz - show text to the left of the image
29620 any other - use system default or image if no system default.
29622 This variable only affects the GTK+ toolkit version of Emacs. */);
29623 Vtool_bar_style
= Qnil
;
29625 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29626 doc
: /* Maximum number of characters a label can have to be shown.
29627 The tool bar style must also show labels for this to have any effect, see
29628 `tool-bar-style'. */);
29629 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29631 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29632 doc
: /* List of functions to call to fontify regions of text.
29633 Each function is called with one argument POS. Functions must
29634 fontify a region starting at POS in the current buffer, and give
29635 fontified regions the property `fontified'. */);
29636 Vfontification_functions
= Qnil
;
29637 Fmake_variable_buffer_local (Qfontification_functions
);
29639 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29640 unibyte_display_via_language_environment
,
29641 doc
: /* Non-nil means display unibyte text according to language environment.
29642 Specifically, this means that raw bytes in the range 160-255 decimal
29643 are displayed by converting them to the equivalent multibyte characters
29644 according to the current language environment. As a result, they are
29645 displayed according to the current fontset.
29647 Note that this variable affects only how these bytes are displayed,
29648 but does not change the fact they are interpreted as raw bytes. */);
29649 unibyte_display_via_language_environment
= 0;
29651 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29652 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29653 If a float, it specifies a fraction of the mini-window frame's height.
29654 If an integer, it specifies a number of lines. */);
29655 Vmax_mini_window_height
= make_float (0.25);
29657 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29658 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29659 A value of nil means don't automatically resize mini-windows.
29660 A value of t means resize them to fit the text displayed in them.
29661 A value of `grow-only', the default, means let mini-windows grow only;
29662 they return to their normal size when the minibuffer is closed, or the
29663 echo area becomes empty. */);
29664 Vresize_mini_windows
= Qgrow_only
;
29666 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29667 doc
: /* Alist specifying how to blink the cursor off.
29668 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29669 `cursor-type' frame-parameter or variable equals ON-STATE,
29670 comparing using `equal', Emacs uses OFF-STATE to specify
29671 how to blink it off. ON-STATE and OFF-STATE are values for
29672 the `cursor-type' frame parameter.
29674 If a frame's ON-STATE has no entry in this list,
29675 the frame's other specifications determine how to blink the cursor off. */);
29676 Vblink_cursor_alist
= Qnil
;
29678 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29679 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29680 If non-nil, windows are automatically scrolled horizontally to make
29681 point visible. */);
29682 automatic_hscrolling_p
= 1;
29683 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29685 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29686 doc
: /* How many columns away from the window edge point is allowed to get
29687 before automatic hscrolling will horizontally scroll the window. */);
29688 hscroll_margin
= 5;
29690 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29691 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29692 When point is less than `hscroll-margin' columns from the window
29693 edge, automatic hscrolling will scroll the window by the amount of columns
29694 determined by this variable. If its value is a positive integer, scroll that
29695 many columns. If it's a positive floating-point number, it specifies the
29696 fraction of the window's width to scroll. If it's nil or zero, point will be
29697 centered horizontally after the scroll. Any other value, including negative
29698 numbers, are treated as if the value were zero.
29700 Automatic hscrolling always moves point outside the scroll margin, so if
29701 point was more than scroll step columns inside the margin, the window will
29702 scroll more than the value given by the scroll step.
29704 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29705 and `scroll-right' overrides this variable's effect. */);
29706 Vhscroll_step
= make_number (0);
29708 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29709 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29710 Bind this around calls to `message' to let it take effect. */);
29711 message_truncate_lines
= 0;
29713 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29714 doc
: /* Normal hook run to update the menu bar definitions.
29715 Redisplay runs this hook before it redisplays the menu bar.
29716 This is used to update submenus such as Buffers,
29717 whose contents depend on various data. */);
29718 Vmenu_bar_update_hook
= Qnil
;
29720 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29721 doc
: /* Frame for which we are updating a menu.
29722 The enable predicate for a menu binding should check this variable. */);
29723 Vmenu_updating_frame
= Qnil
;
29725 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29726 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29727 inhibit_menubar_update
= 0;
29729 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29730 doc
: /* Prefix prepended to all continuation lines at display time.
29731 The value may be a string, an image, or a stretch-glyph; it is
29732 interpreted in the same way as the value of a `display' text property.
29734 This variable is overridden by any `wrap-prefix' text or overlay
29737 To add a prefix to non-continuation lines, use `line-prefix'. */);
29738 Vwrap_prefix
= Qnil
;
29739 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29740 Fmake_variable_buffer_local (Qwrap_prefix
);
29742 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29743 doc
: /* Prefix prepended to all non-continuation lines at display time.
29744 The value may be a string, an image, or a stretch-glyph; it is
29745 interpreted in the same way as the value of a `display' text property.
29747 This variable is overridden by any `line-prefix' text or overlay
29750 To add a prefix to continuation lines, use `wrap-prefix'. */);
29751 Vline_prefix
= Qnil
;
29752 DEFSYM (Qline_prefix
, "line-prefix");
29753 Fmake_variable_buffer_local (Qline_prefix
);
29755 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29756 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29757 inhibit_eval_during_redisplay
= 0;
29759 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29760 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29761 inhibit_free_realized_faces
= 0;
29764 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29765 doc
: /* Inhibit try_window_id display optimization. */);
29766 inhibit_try_window_id
= 0;
29768 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29769 doc
: /* Inhibit try_window_reusing display optimization. */);
29770 inhibit_try_window_reusing
= 0;
29772 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29773 doc
: /* Inhibit try_cursor_movement display optimization. */);
29774 inhibit_try_cursor_movement
= 0;
29775 #endif /* GLYPH_DEBUG */
29777 DEFVAR_INT ("overline-margin", overline_margin
,
29778 doc
: /* Space between overline and text, in pixels.
29779 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29780 margin to the character height. */);
29781 overline_margin
= 2;
29783 DEFVAR_INT ("underline-minimum-offset",
29784 underline_minimum_offset
,
29785 doc
: /* Minimum distance between baseline and underline.
29786 This can improve legibility of underlined text at small font sizes,
29787 particularly when using variable `x-use-underline-position-properties'
29788 with fonts that specify an UNDERLINE_POSITION relatively close to the
29789 baseline. The default value is 1. */);
29790 underline_minimum_offset
= 1;
29792 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29793 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29794 This feature only works when on a window system that can change
29795 cursor shapes. */);
29796 display_hourglass_p
= 1;
29798 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29799 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29800 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29802 #ifdef HAVE_WINDOW_SYSTEM
29803 hourglass_atimer
= NULL
;
29804 hourglass_shown_p
= 0;
29805 #endif /* HAVE_WINDOW_SYSTEM */
29807 DEFSYM (Qglyphless_char
, "glyphless-char");
29808 DEFSYM (Qhex_code
, "hex-code");
29809 DEFSYM (Qempty_box
, "empty-box");
29810 DEFSYM (Qthin_space
, "thin-space");
29811 DEFSYM (Qzero_width
, "zero-width");
29813 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
29814 doc
: /* Function run just before redisplay.
29815 It is called with one argument, which is the set of windows that are to
29816 be redisplayed. This set can be nil (meaning, only the selected window),
29817 or t (meaning all windows). */);
29818 Vpre_redisplay_function
= intern ("ignore");
29820 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29821 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29823 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29824 doc
: /* Char-table defining glyphless characters.
29825 Each element, if non-nil, should be one of the following:
29826 an ASCII acronym string: display this string in a box
29827 `hex-code': display the hexadecimal code of a character in a box
29828 `empty-box': display as an empty box
29829 `thin-space': display as 1-pixel width space
29830 `zero-width': don't display
29831 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29832 display method for graphical terminals and text terminals respectively.
29833 GRAPHICAL and TEXT should each have one of the values listed above.
29835 The char-table has one extra slot to control the display of a character for
29836 which no font is found. This slot only takes effect on graphical terminals.
29837 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29838 `thin-space'. The default is `empty-box'.
29840 If a character has a non-nil entry in an active display table, the
29841 display table takes effect; in this case, Emacs does not consult
29842 `glyphless-char-display' at all. */);
29843 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29844 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29847 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29848 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29849 Vdebug_on_message
= Qnil
;
29851 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
29853 Vredisplay__all_windows_cause
29854 = Fmake_vector (make_number (100), make_number (0));
29856 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
29858 Vredisplay__mode_lines_cause
29859 = Fmake_vector (make_number (100), make_number (0));
29863 /* Initialize this module when Emacs starts. */
29868 CHARPOS (this_line_start_pos
) = 0;
29870 if (!noninteractive
)
29872 struct window
*m
= XWINDOW (minibuf_window
);
29873 Lisp_Object frame
= m
->frame
;
29874 struct frame
*f
= XFRAME (frame
);
29875 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29876 struct window
*r
= XWINDOW (root
);
29879 echo_area_window
= minibuf_window
;
29881 r
->top_line
= FRAME_TOP_MARGIN (f
);
29882 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29883 r
->total_cols
= FRAME_COLS (f
);
29885 m
->top_line
= FRAME_LINES (f
) - 1;
29886 m
->total_lines
= 1;
29887 m
->total_cols
= FRAME_COLS (f
);
29889 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29890 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29891 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29893 /* The default ellipsis glyphs `...'. */
29894 for (i
= 0; i
< 3; ++i
)
29895 default_invis_vector
[i
] = make_number ('.');
29899 /* Allocate the buffer for frame titles.
29900 Also used for `format-mode-line'. */
29902 mode_line_noprop_buf
= xmalloc (size
);
29903 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29904 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29905 mode_line_target
= MODE_LINE_DISPLAY
;
29908 help_echo_showing_p
= 0;
29911 #ifdef HAVE_WINDOW_SYSTEM
29913 /* Platform-independent portion of hourglass implementation. */
29915 /* Cancel a currently active hourglass timer, and start a new one. */
29917 start_hourglass (void)
29919 struct timespec delay
;
29921 cancel_hourglass ();
29923 if (INTEGERP (Vhourglass_delay
)
29924 && XINT (Vhourglass_delay
) > 0)
29925 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29926 TYPE_MAXIMUM (time_t)),
29928 else if (FLOATP (Vhourglass_delay
)
29929 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29930 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29932 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29936 extern void w32_note_current_window (void);
29937 w32_note_current_window ();
29939 #endif /* HAVE_NTGUI */
29941 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29942 show_hourglass
, NULL
);
29946 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29949 cancel_hourglass (void)
29951 if (hourglass_atimer
)
29953 cancel_atimer (hourglass_atimer
);
29954 hourglass_atimer
= NULL
;
29957 if (hourglass_shown_p
)
29961 #endif /* HAVE_WINDOW_SYSTEM */