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
, int);
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
, int);
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
= 1;
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
= 1;
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
= 1;
4212 while (invis_p
&& endpos
< len
);
4214 if (display_ellipsis_p
)
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
= 1;
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
);
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
;
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
= 1;
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
= 1;
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
= 1;
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
= 1;
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
= 1;
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
= 1;
6803 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6804 nonascii_hyphen_p
= 1;
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
= 1;
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
)
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
= 1;
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
)
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
= 1;
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 (1,1);
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 (1, 1);
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
= 1;
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
= 1;
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 (int current_p
, int last_displayed_p
)
10739 echo_area_buffer
[0] = Qnil
;
10740 message_cleared_p
= 1;
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
= 1;
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
), 0);
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
));
13429 /* The X error handler may have deleted that frame. */
13430 if (!FRAME_LIVE_P (f
))
13433 /* Any scroll bars which redisplay_windows should have
13434 nuked should now go away. */
13435 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13436 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13438 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13440 /* If fonts changed on visible frame, display again. */
13441 if (f
->fonts_changed
)
13443 adjust_frame_glyphs (f
);
13444 f
->fonts_changed
= 0;
13448 /* See if we have to hscroll. */
13449 if (!f
->already_hscrolled_p
)
13451 f
->already_hscrolled_p
= 1;
13452 if (hscroll_windows (f
->root_window
))
13456 /* Prevent various kinds of signals during display
13457 update. stdio is not robust about handling
13458 signals, which can cause an apparent I/O
13460 if (interrupt_input
)
13461 unrequest_sigio ();
13464 /* Mark windows on frame F to update. If we decide to
13465 update all frames but windows_or_buffers_changed is
13466 zero, we assume that only the windows that shows
13467 current buffer should be really updated. */
13468 set_window_update_flags
13469 (XWINDOW (f
->root_window
),
13470 (windows_or_buffers_changed
? NULL
: current_buffer
), 1);
13471 pending
|= update_frame (f
, 0, 0);
13472 f
->cursor_type_changed
= 0;
13478 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13482 /* Do the mark_window_display_accurate after all windows have
13483 been redisplayed because this call resets flags in buffers
13484 which are needed for proper redisplay. */
13485 FOR_EACH_FRAME (tail
, frame
)
13487 struct frame
*f
= XFRAME (frame
);
13490 f
->redisplay
= false;
13491 mark_window_display_accurate (f
->root_window
, 1);
13492 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13493 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13498 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13500 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13501 struct frame
*mini_frame
;
13503 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13504 /* Use list_of_error, not Qerror, so that
13505 we catch only errors and don't run the debugger. */
13506 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13508 redisplay_window_error
);
13509 if (update_miniwindow_p
)
13510 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13512 redisplay_window_error
);
13514 /* Compare desired and current matrices, perform output. */
13517 /* If fonts changed, display again. */
13518 if (sf
->fonts_changed
)
13521 /* Prevent various kinds of signals during display update.
13522 stdio is not robust about handling signals,
13523 which can cause an apparent I/O error. */
13524 if (interrupt_input
)
13525 unrequest_sigio ();
13528 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13530 if (hscroll_windows (selected_window
))
13533 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13534 pending
= update_frame (sf
, 0, 0);
13535 sf
->cursor_type_changed
= 0;
13538 /* We may have called echo_area_display at the top of this
13539 function. If the echo area is on another frame, that may
13540 have put text on a frame other than the selected one, so the
13541 above call to update_frame would not have caught it. Catch
13543 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13544 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13546 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13548 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13549 pending
|= update_frame (mini_frame
, 0, 0);
13550 mini_frame
->cursor_type_changed
= 0;
13551 if (!pending
&& hscroll_windows (mini_window
))
13556 /* If display was paused because of pending input, make sure we do a
13557 thorough update the next time. */
13560 /* Prevent the optimization at the beginning of
13561 redisplay_internal that tries a single-line update of the
13562 line containing the cursor in the selected window. */
13563 CHARPOS (this_line_start_pos
) = 0;
13565 /* Let the overlay arrow be updated the next time. */
13566 update_overlay_arrows (0);
13568 /* If we pause after scrolling, some rows in the current
13569 matrices of some windows are not valid. */
13570 if (!WINDOW_FULL_WIDTH_P (w
)
13571 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13572 update_mode_lines
= 36;
13576 if (!consider_all_windows_p
)
13578 /* This has already been done above if
13579 consider_all_windows_p is set. */
13580 if (XBUFFER (w
->contents
)->text
->redisplay
13581 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13582 /* This can happen if b->text->redisplay was set during
13584 propagate_buffer_redisplay ();
13585 mark_window_display_accurate_1 (w
, 1);
13587 /* Say overlay arrows are up to date. */
13588 update_overlay_arrows (1);
13590 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13591 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13594 update_mode_lines
= 0;
13595 windows_or_buffers_changed
= 0;
13598 /* Start SIGIO interrupts coming again. Having them off during the
13599 code above makes it less likely one will discard output, but not
13600 impossible, since there might be stuff in the system buffer here.
13601 But it is much hairier to try to do anything about that. */
13602 if (interrupt_input
)
13606 /* If a frame has become visible which was not before, redisplay
13607 again, so that we display it. Expose events for such a frame
13608 (which it gets when becoming visible) don't call the parts of
13609 redisplay constructing glyphs, so simply exposing a frame won't
13610 display anything in this case. So, we have to display these
13611 frames here explicitly. */
13616 FOR_EACH_FRAME (tail
, frame
)
13618 if (XFRAME (frame
)->visible
)
13622 if (new_count
!= number_of_visible_frames
)
13623 windows_or_buffers_changed
= 52;
13626 /* Change frame size now if a change is pending. */
13627 do_pending_window_change (1);
13629 /* If we just did a pending size change, or have additional
13630 visible frames, or selected_window changed, redisplay again. */
13631 if ((windows_or_buffers_changed
&& !pending
)
13632 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13635 /* Clear the face and image caches.
13637 We used to do this only if consider_all_windows_p. But the cache
13638 needs to be cleared if a timer creates images in the current
13639 buffer (e.g. the test case in Bug#6230). */
13641 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13643 clear_face_cache (0);
13644 clear_face_cache_count
= 0;
13647 #ifdef HAVE_WINDOW_SYSTEM
13648 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13650 clear_image_caches (Qnil
);
13651 clear_image_cache_count
= 0;
13653 #endif /* HAVE_WINDOW_SYSTEM */
13656 unbind_to (count
, Qnil
);
13661 /* Redisplay, but leave alone any recent echo area message unless
13662 another message has been requested in its place.
13664 This is useful in situations where you need to redisplay but no
13665 user action has occurred, making it inappropriate for the message
13666 area to be cleared. See tracking_off and
13667 wait_reading_process_output for examples of these situations.
13669 FROM_WHERE is an integer saying from where this function was
13670 called. This is useful for debugging. */
13673 redisplay_preserve_echo_area (int from_where
)
13675 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13677 if (!NILP (echo_area_buffer
[1]))
13679 /* We have a previously displayed message, but no current
13680 message. Redisplay the previous message. */
13681 display_last_displayed_message_p
= 1;
13682 redisplay_internal ();
13683 display_last_displayed_message_p
= 0;
13686 redisplay_internal ();
13688 flush_frame (SELECTED_FRAME ());
13692 /* Function registered with record_unwind_protect in redisplay_internal. */
13695 unwind_redisplay (void)
13697 redisplaying_p
= 0;
13701 /* Mark the display of leaf window W as accurate or inaccurate.
13702 If ACCURATE_P is non-zero mark display of W as accurate. If
13703 ACCURATE_P is zero, arrange for W to be redisplayed the next
13704 time redisplay_internal is called. */
13707 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13709 struct buffer
*b
= XBUFFER (w
->contents
);
13711 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13712 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13713 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13717 b
->clip_changed
= false;
13718 b
->prevent_redisplay_optimizations_p
= false;
13719 eassert (buffer_window_count (b
) > 0);
13720 /* Resetting b->text->redisplay is problematic!
13721 In order to make it safer to do it here, redisplay_internal must
13722 have copied all b->text->redisplay to their respective windows. */
13723 b
->text
->redisplay
= false;
13725 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13726 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13727 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13728 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13730 w
->current_matrix
->buffer
= b
;
13731 w
->current_matrix
->begv
= BUF_BEGV (b
);
13732 w
->current_matrix
->zv
= BUF_ZV (b
);
13734 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13735 w
->last_cursor_off_p
= w
->cursor_off_p
;
13737 if (w
== XWINDOW (selected_window
))
13738 w
->last_point
= BUF_PT (b
);
13740 w
->last_point
= marker_position (w
->pointm
);
13742 w
->window_end_valid
= true;
13743 w
->update_mode_line
= false;
13746 w
->redisplay
= !accurate_p
;
13750 /* Mark the display of windows in the window tree rooted at WINDOW as
13751 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13752 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13753 be redisplayed the next time redisplay_internal is called. */
13756 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13760 for (; !NILP (window
); window
= w
->next
)
13762 w
= XWINDOW (window
);
13763 if (WINDOWP (w
->contents
))
13764 mark_window_display_accurate (w
->contents
, accurate_p
);
13766 mark_window_display_accurate_1 (w
, accurate_p
);
13770 update_overlay_arrows (1);
13772 /* Force a thorough redisplay the next time by setting
13773 last_arrow_position and last_arrow_string to t, which is
13774 unequal to any useful value of Voverlay_arrow_... */
13775 update_overlay_arrows (-1);
13779 /* Return value in display table DP (Lisp_Char_Table *) for character
13780 C. Since a display table doesn't have any parent, we don't have to
13781 follow parent. Do not call this function directly but use the
13782 macro DISP_CHAR_VECTOR. */
13785 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13789 if (ASCII_CHAR_P (c
))
13792 if (SUB_CHAR_TABLE_P (val
))
13793 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13799 XSETCHAR_TABLE (table
, dp
);
13800 val
= char_table_ref (table
, c
);
13809 /***********************************************************************
13811 ***********************************************************************/
13813 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13816 redisplay_windows (Lisp_Object window
)
13818 while (!NILP (window
))
13820 struct window
*w
= XWINDOW (window
);
13822 if (WINDOWP (w
->contents
))
13823 redisplay_windows (w
->contents
);
13824 else if (BUFFERP (w
->contents
))
13826 displayed_buffer
= XBUFFER (w
->contents
);
13827 /* Use list_of_error, not Qerror, so that
13828 we catch only errors and don't run the debugger. */
13829 internal_condition_case_1 (redisplay_window_0
, window
,
13831 redisplay_window_error
);
13839 redisplay_window_error (Lisp_Object ignore
)
13841 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13846 redisplay_window_0 (Lisp_Object window
)
13848 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13849 redisplay_window (window
, 0);
13854 redisplay_window_1 (Lisp_Object window
)
13856 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13857 redisplay_window (window
, 1);
13862 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13863 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13864 which positions recorded in ROW differ from current buffer
13867 Return 0 if cursor is not on this row, 1 otherwise. */
13870 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13871 struct glyph_matrix
*matrix
,
13872 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13875 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13876 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13877 struct glyph
*cursor
= NULL
;
13878 /* The last known character position in row. */
13879 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13881 ptrdiff_t pt_old
= PT
- delta
;
13882 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13883 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13884 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13885 /* A glyph beyond the edge of TEXT_AREA which we should never
13887 struct glyph
*glyphs_end
= end
;
13888 /* Non-zero means we've found a match for cursor position, but that
13889 glyph has the avoid_cursor_p flag set. */
13890 int match_with_avoid_cursor
= 0;
13891 /* Non-zero means we've seen at least one glyph that came from a
13893 int string_seen
= 0;
13894 /* Largest and smallest buffer positions seen so far during scan of
13896 ptrdiff_t bpos_max
= pos_before
;
13897 ptrdiff_t bpos_min
= pos_after
;
13898 /* Last buffer position covered by an overlay string with an integer
13899 `cursor' property. */
13900 ptrdiff_t bpos_covered
= 0;
13901 /* Non-zero means the display string on which to display the cursor
13902 comes from a text property, not from an overlay. */
13903 int string_from_text_prop
= 0;
13905 /* Don't even try doing anything if called for a mode-line or
13906 header-line row, since the rest of the code isn't prepared to
13907 deal with such calamities. */
13908 eassert (!row
->mode_line_p
);
13909 if (row
->mode_line_p
)
13912 /* Skip over glyphs not having an object at the start and the end of
13913 the row. These are special glyphs like truncation marks on
13914 terminal frames. */
13915 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13917 if (!row
->reversed_p
)
13920 && INTEGERP (glyph
->object
)
13921 && glyph
->charpos
< 0)
13923 x
+= glyph
->pixel_width
;
13927 && INTEGERP ((end
- 1)->object
)
13928 /* CHARPOS is zero for blanks and stretch glyphs
13929 inserted by extend_face_to_end_of_line. */
13930 && (end
- 1)->charpos
<= 0)
13932 glyph_before
= glyph
- 1;
13939 /* If the glyph row is reversed, we need to process it from back
13940 to front, so swap the edge pointers. */
13941 glyphs_end
= end
= glyph
- 1;
13942 glyph
+= row
->used
[TEXT_AREA
] - 1;
13944 while (glyph
> end
+ 1
13945 && INTEGERP (glyph
->object
)
13946 && glyph
->charpos
< 0)
13949 x
-= glyph
->pixel_width
;
13951 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13953 /* By default, in reversed rows we put the cursor on the
13954 rightmost (first in the reading order) glyph. */
13955 for (g
= end
+ 1; g
< glyph
; g
++)
13956 x
+= g
->pixel_width
;
13958 && INTEGERP ((end
+ 1)->object
)
13959 && (end
+ 1)->charpos
<= 0)
13961 glyph_before
= glyph
+ 1;
13965 else if (row
->reversed_p
)
13967 /* In R2L rows that don't display text, put the cursor on the
13968 rightmost glyph. Case in point: an empty last line that is
13969 part of an R2L paragraph. */
13971 /* Avoid placing the cursor on the last glyph of the row, where
13972 on terminal frames we hold the vertical border between
13973 adjacent windows. */
13974 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13975 && !WINDOW_RIGHTMOST_P (w
)
13976 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13978 x
= -1; /* will be computed below, at label compute_x */
13981 /* Step 1: Try to find the glyph whose character position
13982 corresponds to point. If that's not possible, find 2 glyphs
13983 whose character positions are the closest to point, one before
13984 point, the other after it. */
13985 if (!row
->reversed_p
)
13986 while (/* not marched to end of glyph row */
13988 /* glyph was not inserted by redisplay for internal purposes */
13989 && !INTEGERP (glyph
->object
))
13991 if (BUFFERP (glyph
->object
))
13993 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13995 if (glyph
->charpos
> bpos_max
)
13996 bpos_max
= glyph
->charpos
;
13997 if (glyph
->charpos
< bpos_min
)
13998 bpos_min
= glyph
->charpos
;
13999 if (!glyph
->avoid_cursor_p
)
14001 /* If we hit point, we've found the glyph on which to
14002 display the cursor. */
14005 match_with_avoid_cursor
= 0;
14008 /* See if we've found a better approximation to
14009 POS_BEFORE or to POS_AFTER. */
14010 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14012 pos_before
= glyph
->charpos
;
14013 glyph_before
= glyph
;
14015 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14017 pos_after
= glyph
->charpos
;
14018 glyph_after
= glyph
;
14021 else if (dpos
== 0)
14022 match_with_avoid_cursor
= 1;
14024 else if (STRINGP (glyph
->object
))
14026 Lisp_Object chprop
;
14027 ptrdiff_t glyph_pos
= glyph
->charpos
;
14029 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14031 if (!NILP (chprop
))
14033 /* If the string came from a `display' text property,
14034 look up the buffer position of that property and
14035 use that position to update bpos_max, as if we
14036 actually saw such a position in one of the row's
14037 glyphs. This helps with supporting integer values
14038 of `cursor' property on the display string in
14039 situations where most or all of the row's buffer
14040 text is completely covered by display properties,
14041 so that no glyph with valid buffer positions is
14042 ever seen in the row. */
14043 ptrdiff_t prop_pos
=
14044 string_buffer_position_lim (glyph
->object
, pos_before
,
14047 if (prop_pos
>= pos_before
)
14048 bpos_max
= prop_pos
- 1;
14050 if (INTEGERP (chprop
))
14052 bpos_covered
= bpos_max
+ XINT (chprop
);
14053 /* If the `cursor' property covers buffer positions up
14054 to and including point, we should display cursor on
14055 this glyph. Note that, if a `cursor' property on one
14056 of the string's characters has an integer value, we
14057 will break out of the loop below _before_ we get to
14058 the position match above. IOW, integer values of
14059 the `cursor' property override the "exact match for
14060 point" strategy of positioning the cursor. */
14061 /* Implementation note: bpos_max == pt_old when, e.g.,
14062 we are in an empty line, where bpos_max is set to
14063 MATRIX_ROW_START_CHARPOS, see above. */
14064 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14073 x
+= glyph
->pixel_width
;
14076 else if (glyph
> end
) /* row is reversed */
14077 while (!INTEGERP (glyph
->object
))
14079 if (BUFFERP (glyph
->object
))
14081 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14083 if (glyph
->charpos
> bpos_max
)
14084 bpos_max
= glyph
->charpos
;
14085 if (glyph
->charpos
< bpos_min
)
14086 bpos_min
= glyph
->charpos
;
14087 if (!glyph
->avoid_cursor_p
)
14091 match_with_avoid_cursor
= 0;
14094 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14096 pos_before
= glyph
->charpos
;
14097 glyph_before
= glyph
;
14099 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14101 pos_after
= glyph
->charpos
;
14102 glyph_after
= glyph
;
14105 else if (dpos
== 0)
14106 match_with_avoid_cursor
= 1;
14108 else if (STRINGP (glyph
->object
))
14110 Lisp_Object chprop
;
14111 ptrdiff_t glyph_pos
= glyph
->charpos
;
14113 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14115 if (!NILP (chprop
))
14117 ptrdiff_t prop_pos
=
14118 string_buffer_position_lim (glyph
->object
, pos_before
,
14121 if (prop_pos
>= pos_before
)
14122 bpos_max
= prop_pos
- 1;
14124 if (INTEGERP (chprop
))
14126 bpos_covered
= bpos_max
+ XINT (chprop
);
14127 /* If the `cursor' property covers buffer positions up
14128 to and including point, we should display cursor on
14130 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14139 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14141 x
--; /* can't use any pixel_width */
14144 x
-= glyph
->pixel_width
;
14147 /* Step 2: If we didn't find an exact match for point, we need to
14148 look for a proper place to put the cursor among glyphs between
14149 GLYPH_BEFORE and GLYPH_AFTER. */
14150 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14151 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14152 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14154 /* An empty line has a single glyph whose OBJECT is zero and
14155 whose CHARPOS is the position of a newline on that line.
14156 Note that on a TTY, there are more glyphs after that, which
14157 were produced by extend_face_to_end_of_line, but their
14158 CHARPOS is zero or negative. */
14160 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14161 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14162 /* On a TTY, continued and truncated rows also have a glyph at
14163 their end whose OBJECT is zero and whose CHARPOS is
14164 positive (the continuation and truncation glyphs), but such
14165 rows are obviously not "empty". */
14166 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14168 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14170 ptrdiff_t ellipsis_pos
;
14172 /* Scan back over the ellipsis glyphs. */
14173 if (!row
->reversed_p
)
14175 ellipsis_pos
= (glyph
- 1)->charpos
;
14176 while (glyph
> row
->glyphs
[TEXT_AREA
]
14177 && (glyph
- 1)->charpos
== ellipsis_pos
)
14178 glyph
--, x
-= glyph
->pixel_width
;
14179 /* That loop always goes one position too far, including
14180 the glyph before the ellipsis. So scan forward over
14182 x
+= glyph
->pixel_width
;
14185 else /* row is reversed */
14187 ellipsis_pos
= (glyph
+ 1)->charpos
;
14188 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14189 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14190 glyph
++, x
+= glyph
->pixel_width
;
14191 x
-= glyph
->pixel_width
;
14195 else if (match_with_avoid_cursor
)
14197 cursor
= glyph_after
;
14200 else if (string_seen
)
14202 int incr
= row
->reversed_p
? -1 : +1;
14204 /* Need to find the glyph that came out of a string which is
14205 present at point. That glyph is somewhere between
14206 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14207 positioned between POS_BEFORE and POS_AFTER in the
14209 struct glyph
*start
, *stop
;
14210 ptrdiff_t pos
= pos_before
;
14214 /* If the row ends in a newline from a display string,
14215 reordering could have moved the glyphs belonging to the
14216 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14217 in this case we extend the search to the last glyph in
14218 the row that was not inserted by redisplay. */
14219 if (row
->ends_in_newline_from_string_p
)
14222 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14225 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14226 correspond to POS_BEFORE and POS_AFTER, respectively. We
14227 need START and STOP in the order that corresponds to the
14228 row's direction as given by its reversed_p flag. If the
14229 directionality of characters between POS_BEFORE and
14230 POS_AFTER is the opposite of the row's base direction,
14231 these characters will have been reordered for display,
14232 and we need to reverse START and STOP. */
14233 if (!row
->reversed_p
)
14235 start
= min (glyph_before
, glyph_after
);
14236 stop
= max (glyph_before
, glyph_after
);
14240 start
= max (glyph_before
, glyph_after
);
14241 stop
= min (glyph_before
, glyph_after
);
14243 for (glyph
= start
+ incr
;
14244 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14247 /* Any glyphs that come from the buffer are here because
14248 of bidi reordering. Skip them, and only pay
14249 attention to glyphs that came from some string. */
14250 if (STRINGP (glyph
->object
))
14254 /* If the display property covers the newline, we
14255 need to search for it one position farther. */
14256 ptrdiff_t lim
= pos_after
14257 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14259 string_from_text_prop
= 0;
14260 str
= glyph
->object
;
14261 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14262 if (tem
== 0 /* from overlay */
14265 /* If the string from which this glyph came is
14266 found in the buffer at point, or at position
14267 that is closer to point than pos_after, then
14268 we've found the glyph we've been looking for.
14269 If it comes from an overlay (tem == 0), and
14270 it has the `cursor' property on one of its
14271 glyphs, record that glyph as a candidate for
14272 displaying the cursor. (As in the
14273 unidirectional version, we will display the
14274 cursor on the last candidate we find.) */
14277 || (tem
- pt_old
> 0 && tem
< pos_after
))
14279 /* The glyphs from this string could have
14280 been reordered. Find the one with the
14281 smallest string position. Or there could
14282 be a character in the string with the
14283 `cursor' property, which means display
14284 cursor on that character's glyph. */
14285 ptrdiff_t strpos
= glyph
->charpos
;
14290 string_from_text_prop
= 1;
14293 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14294 && EQ (glyph
->object
, str
);
14298 ptrdiff_t gpos
= glyph
->charpos
;
14300 cprop
= Fget_char_property (make_number (gpos
),
14308 if (tem
&& glyph
->charpos
< strpos
)
14310 strpos
= glyph
->charpos
;
14316 || (tem
- pt_old
> 0 && tem
< pos_after
))
14320 pos
= tem
+ 1; /* don't find previous instances */
14322 /* This string is not what we want; skip all of the
14323 glyphs that came from it. */
14324 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14325 && EQ (glyph
->object
, str
))
14332 /* If we reached the end of the line, and END was from a string,
14333 the cursor is not on this line. */
14335 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14336 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14337 && STRINGP (end
->object
)
14338 && row
->continued_p
)
14341 /* A truncated row may not include PT among its character positions.
14342 Setting the cursor inside the scroll margin will trigger
14343 recalculation of hscroll in hscroll_window_tree. But if a
14344 display string covers point, defer to the string-handling
14345 code below to figure this out. */
14346 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14348 cursor
= glyph_before
;
14351 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14352 /* Zero-width characters produce no glyphs. */
14354 && (row
->reversed_p
14355 ? glyph_after
> glyphs_end
14356 : glyph_after
< glyphs_end
)))
14358 cursor
= glyph_after
;
14364 if (cursor
!= NULL
)
14366 else if (glyph
== glyphs_end
14367 && pos_before
== pos_after
14368 && STRINGP ((row
->reversed_p
14369 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14370 : row
->glyphs
[TEXT_AREA
])->object
))
14372 /* If all the glyphs of this row came from strings, put the
14373 cursor on the first glyph of the row. This avoids having the
14374 cursor outside of the text area in this very rare and hard
14378 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14379 : row
->glyphs
[TEXT_AREA
];
14385 /* Need to compute x that corresponds to GLYPH. */
14386 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14388 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14390 x
+= g
->pixel_width
;
14394 /* ROW could be part of a continued line, which, under bidi
14395 reordering, might have other rows whose start and end charpos
14396 occlude point. Only set w->cursor if we found a better
14397 approximation to the cursor position than we have from previously
14398 examined candidate rows belonging to the same continued line. */
14399 if (/* We already have a candidate row. */
14400 w
->cursor
.vpos
>= 0
14401 /* That candidate is not the row we are processing. */
14402 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14403 /* Make sure cursor.vpos specifies a row whose start and end
14404 charpos occlude point, and it is valid candidate for being a
14405 cursor-row. This is because some callers of this function
14406 leave cursor.vpos at the row where the cursor was displayed
14407 during the last redisplay cycle. */
14408 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14409 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14410 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14413 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14415 /* Don't consider glyphs that are outside TEXT_AREA. */
14416 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14418 /* Keep the candidate whose buffer position is the closest to
14419 point or has the `cursor' property. */
14420 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14421 w
->cursor
.hpos
>= 0
14422 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14423 && ((BUFFERP (g1
->object
)
14424 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14425 || (BUFFERP (glyph
->object
)
14426 && eabs (g1
->charpos
- pt_old
)
14427 < eabs (glyph
->charpos
- pt_old
))))
14428 /* Previous candidate is a glyph from a string that has
14429 a non-nil `cursor' property. */
14430 || (STRINGP (g1
->object
)
14431 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14432 Qcursor
, g1
->object
))
14433 /* Previous candidate is from the same display
14434 string as this one, and the display string
14435 came from a text property. */
14436 || (EQ (g1
->object
, glyph
->object
)
14437 && string_from_text_prop
)
14438 /* this candidate is from newline and its
14439 position is not an exact match */
14440 || (INTEGERP (glyph
->object
)
14441 && glyph
->charpos
!= pt_old
)))))
14443 /* If this candidate gives an exact match, use that. */
14444 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14445 /* If this candidate is a glyph created for the
14446 terminating newline of a line, and point is on that
14447 newline, it wins because it's an exact match. */
14448 || (!row
->continued_p
14449 && INTEGERP (glyph
->object
)
14450 && glyph
->charpos
== 0
14451 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14452 /* Otherwise, keep the candidate that comes from a row
14453 spanning less buffer positions. This may win when one or
14454 both candidate positions are on glyphs that came from
14455 display strings, for which we cannot compare buffer
14457 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14458 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14459 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14462 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14464 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14465 w
->cursor
.y
= row
->y
+ dy
;
14467 if (w
== XWINDOW (selected_window
))
14469 if (!row
->continued_p
14470 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14473 this_line_buffer
= XBUFFER (w
->contents
);
14475 CHARPOS (this_line_start_pos
)
14476 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14477 BYTEPOS (this_line_start_pos
)
14478 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14480 CHARPOS (this_line_end_pos
)
14481 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14482 BYTEPOS (this_line_end_pos
)
14483 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14485 this_line_y
= w
->cursor
.y
;
14486 this_line_pixel_height
= row
->height
;
14487 this_line_vpos
= w
->cursor
.vpos
;
14488 this_line_start_x
= row
->x
;
14491 CHARPOS (this_line_start_pos
) = 0;
14498 /* Run window scroll functions, if any, for WINDOW with new window
14499 start STARTP. Sets the window start of WINDOW to that position.
14501 We assume that the window's buffer is really current. */
14503 static struct text_pos
14504 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14506 struct window
*w
= XWINDOW (window
);
14507 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14509 eassert (current_buffer
== XBUFFER (w
->contents
));
14511 if (!NILP (Vwindow_scroll_functions
))
14513 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14514 make_number (CHARPOS (startp
)));
14515 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14516 /* In case the hook functions switch buffers. */
14517 set_buffer_internal (XBUFFER (w
->contents
));
14524 /* Make sure the line containing the cursor is fully visible.
14525 A value of 1 means there is nothing to be done.
14526 (Either the line is fully visible, or it cannot be made so,
14527 or we cannot tell.)
14529 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14530 is higher than window.
14532 A value of 0 means the caller should do scrolling
14533 as if point had gone off the screen. */
14536 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14538 struct glyph_matrix
*matrix
;
14539 struct glyph_row
*row
;
14542 if (!make_cursor_line_fully_visible_p
)
14545 /* It's not always possible to find the cursor, e.g, when a window
14546 is full of overlay strings. Don't do anything in that case. */
14547 if (w
->cursor
.vpos
< 0)
14550 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14551 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14553 /* If the cursor row is not partially visible, there's nothing to do. */
14554 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14557 /* If the row the cursor is in is taller than the window's height,
14558 it's not clear what to do, so do nothing. */
14559 window_height
= window_box_height (w
);
14560 if (row
->height
>= window_height
)
14562 if (!force_p
|| MINI_WINDOW_P (w
)
14563 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14570 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14571 non-zero means only WINDOW is redisplayed in redisplay_internal.
14572 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14573 in redisplay_window to bring a partially visible line into view in
14574 the case that only the cursor has moved.
14576 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14577 last screen line's vertical height extends past the end of the screen.
14581 1 if scrolling succeeded
14583 0 if scrolling didn't find point.
14585 -1 if new fonts have been loaded so that we must interrupt
14586 redisplay, adjust glyph matrices, and try again. */
14592 SCROLLING_NEED_LARGER_MATRICES
14595 /* If scroll-conservatively is more than this, never recenter.
14597 If you change this, don't forget to update the doc string of
14598 `scroll-conservatively' and the Emacs manual. */
14599 #define SCROLL_LIMIT 100
14602 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14603 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14604 int temp_scroll_step
, int last_line_misfit
)
14606 struct window
*w
= XWINDOW (window
);
14607 struct frame
*f
= XFRAME (w
->frame
);
14608 struct text_pos pos
, startp
;
14610 int this_scroll_margin
, scroll_max
, rc
, height
;
14611 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14612 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14613 Lisp_Object aggressive
;
14614 /* We will never try scrolling more than this number of lines. */
14615 int scroll_limit
= SCROLL_LIMIT
;
14616 int frame_line_height
= default_line_pixel_height (w
);
14617 int window_total_lines
14618 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14621 debug_method_add (w
, "try_scrolling");
14624 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14626 /* Compute scroll margin height in pixels. We scroll when point is
14627 within this distance from the top or bottom of the window. */
14628 if (scroll_margin
> 0)
14629 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14630 * frame_line_height
;
14632 this_scroll_margin
= 0;
14634 /* Force arg_scroll_conservatively to have a reasonable value, to
14635 avoid scrolling too far away with slow move_it_* functions. Note
14636 that the user can supply scroll-conservatively equal to
14637 `most-positive-fixnum', which can be larger than INT_MAX. */
14638 if (arg_scroll_conservatively
> scroll_limit
)
14640 arg_scroll_conservatively
= scroll_limit
+ 1;
14641 scroll_max
= scroll_limit
* frame_line_height
;
14643 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14644 /* Compute how much we should try to scroll maximally to bring
14645 point into view. */
14646 scroll_max
= (max (scroll_step
,
14647 max (arg_scroll_conservatively
, temp_scroll_step
))
14648 * frame_line_height
);
14649 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14650 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14651 /* We're trying to scroll because of aggressive scrolling but no
14652 scroll_step is set. Choose an arbitrary one. */
14653 scroll_max
= 10 * frame_line_height
;
14659 /* Decide whether to scroll down. */
14660 if (PT
> CHARPOS (startp
))
14662 int scroll_margin_y
;
14664 /* Compute the pixel ypos of the scroll margin, then move IT to
14665 either that ypos or PT, whichever comes first. */
14666 start_display (&it
, w
, startp
);
14667 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14668 - frame_line_height
* extra_scroll_margin_lines
;
14669 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14670 (MOVE_TO_POS
| MOVE_TO_Y
));
14672 if (PT
> CHARPOS (it
.current
.pos
))
14674 int y0
= line_bottom_y (&it
);
14675 /* Compute how many pixels below window bottom to stop searching
14676 for PT. This avoids costly search for PT that is far away if
14677 the user limited scrolling by a small number of lines, but
14678 always finds PT if scroll_conservatively is set to a large
14679 number, such as most-positive-fixnum. */
14680 int slack
= max (scroll_max
, 10 * frame_line_height
);
14681 int y_to_move
= it
.last_visible_y
+ slack
;
14683 /* Compute the distance from the scroll margin to PT or to
14684 the scroll limit, whichever comes first. This should
14685 include the height of the cursor line, to make that line
14687 move_it_to (&it
, PT
, -1, y_to_move
,
14688 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14689 dy
= line_bottom_y (&it
) - y0
;
14691 if (dy
> scroll_max
)
14692 return SCROLLING_FAILED
;
14701 /* Point is in or below the bottom scroll margin, so move the
14702 window start down. If scrolling conservatively, move it just
14703 enough down to make point visible. If scroll_step is set,
14704 move it down by scroll_step. */
14705 if (arg_scroll_conservatively
)
14707 = min (max (dy
, frame_line_height
),
14708 frame_line_height
* arg_scroll_conservatively
);
14709 else if (scroll_step
|| temp_scroll_step
)
14710 amount_to_scroll
= scroll_max
;
14713 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14714 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14715 if (NUMBERP (aggressive
))
14717 double float_amount
= XFLOATINT (aggressive
) * height
;
14718 int aggressive_scroll
= float_amount
;
14719 if (aggressive_scroll
== 0 && float_amount
> 0)
14720 aggressive_scroll
= 1;
14721 /* Don't let point enter the scroll margin near top of
14722 the window. This could happen if the value of
14723 scroll_up_aggressively is too large and there are
14724 non-zero margins, because scroll_up_aggressively
14725 means put point that fraction of window height
14726 _from_the_bottom_margin_. */
14727 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14728 aggressive_scroll
= height
- 2*this_scroll_margin
;
14729 amount_to_scroll
= dy
+ aggressive_scroll
;
14733 if (amount_to_scroll
<= 0)
14734 return SCROLLING_FAILED
;
14736 start_display (&it
, w
, startp
);
14737 if (arg_scroll_conservatively
<= scroll_limit
)
14738 move_it_vertically (&it
, amount_to_scroll
);
14741 /* Extra precision for users who set scroll-conservatively
14742 to a large number: make sure the amount we scroll
14743 the window start is never less than amount_to_scroll,
14744 which was computed as distance from window bottom to
14745 point. This matters when lines at window top and lines
14746 below window bottom have different height. */
14748 void *it1data
= NULL
;
14749 /* We use a temporary it1 because line_bottom_y can modify
14750 its argument, if it moves one line down; see there. */
14753 SAVE_IT (it1
, it
, it1data
);
14754 start_y
= line_bottom_y (&it1
);
14756 RESTORE_IT (&it
, &it
, it1data
);
14757 move_it_by_lines (&it
, 1);
14758 SAVE_IT (it1
, it
, it1data
);
14759 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14762 /* If STARTP is unchanged, move it down another screen line. */
14763 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14764 move_it_by_lines (&it
, 1);
14765 startp
= it
.current
.pos
;
14769 struct text_pos scroll_margin_pos
= startp
;
14772 /* See if point is inside the scroll margin at the top of the
14774 if (this_scroll_margin
)
14778 start_display (&it
, w
, startp
);
14779 y_start
= it
.current_y
;
14780 move_it_vertically (&it
, this_scroll_margin
);
14781 scroll_margin_pos
= it
.current
.pos
;
14782 /* If we didn't move enough before hitting ZV, request
14783 additional amount of scroll, to move point out of the
14785 if (IT_CHARPOS (it
) == ZV
14786 && it
.current_y
- y_start
< this_scroll_margin
)
14787 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14790 if (PT
< CHARPOS (scroll_margin_pos
))
14792 /* Point is in the scroll margin at the top of the window or
14793 above what is displayed in the window. */
14796 /* Compute the vertical distance from PT to the scroll
14797 margin position. Move as far as scroll_max allows, or
14798 one screenful, or 10 screen lines, whichever is largest.
14799 Give up if distance is greater than scroll_max or if we
14800 didn't reach the scroll margin position. */
14801 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14802 start_display (&it
, w
, pos
);
14804 y_to_move
= max (it
.last_visible_y
,
14805 max (scroll_max
, 10 * frame_line_height
));
14806 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14808 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14809 dy
= it
.current_y
- y0
;
14810 if (dy
> scroll_max
14811 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14812 return SCROLLING_FAILED
;
14814 /* Additional scroll for when ZV was too close to point. */
14817 /* Compute new window start. */
14818 start_display (&it
, w
, startp
);
14820 if (arg_scroll_conservatively
)
14821 amount_to_scroll
= max (dy
, frame_line_height
*
14822 max (scroll_step
, temp_scroll_step
));
14823 else if (scroll_step
|| temp_scroll_step
)
14824 amount_to_scroll
= scroll_max
;
14827 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14828 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14829 if (NUMBERP (aggressive
))
14831 double float_amount
= XFLOATINT (aggressive
) * height
;
14832 int aggressive_scroll
= float_amount
;
14833 if (aggressive_scroll
== 0 && float_amount
> 0)
14834 aggressive_scroll
= 1;
14835 /* Don't let point enter the scroll margin near
14836 bottom of the window, if the value of
14837 scroll_down_aggressively happens to be too
14839 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14840 aggressive_scroll
= height
- 2*this_scroll_margin
;
14841 amount_to_scroll
= dy
+ aggressive_scroll
;
14845 if (amount_to_scroll
<= 0)
14846 return SCROLLING_FAILED
;
14848 move_it_vertically_backward (&it
, amount_to_scroll
);
14849 startp
= it
.current
.pos
;
14853 /* Run window scroll functions. */
14854 startp
= run_window_scroll_functions (window
, startp
);
14856 /* Display the window. Give up if new fonts are loaded, or if point
14858 if (!try_window (window
, startp
, 0))
14859 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14860 else if (w
->cursor
.vpos
< 0)
14862 clear_glyph_matrix (w
->desired_matrix
);
14863 rc
= SCROLLING_FAILED
;
14867 /* Maybe forget recorded base line for line number display. */
14868 if (!just_this_one_p
14869 || current_buffer
->clip_changed
14870 || BEG_UNCHANGED
< CHARPOS (startp
))
14871 w
->base_line_number
= 0;
14873 /* If cursor ends up on a partially visible line,
14874 treat that as being off the bottom of the screen. */
14875 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14876 /* It's possible that the cursor is on the first line of the
14877 buffer, which is partially obscured due to a vscroll
14878 (Bug#7537). In that case, avoid looping forever . */
14879 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14881 clear_glyph_matrix (w
->desired_matrix
);
14882 ++extra_scroll_margin_lines
;
14885 rc
= SCROLLING_SUCCESS
;
14892 /* Compute a suitable window start for window W if display of W starts
14893 on a continuation line. Value is non-zero if a new window start
14896 The new window start will be computed, based on W's width, starting
14897 from the start of the continued line. It is the start of the
14898 screen line with the minimum distance from the old start W->start. */
14901 compute_window_start_on_continuation_line (struct window
*w
)
14903 struct text_pos pos
, start_pos
;
14904 int window_start_changed_p
= 0;
14906 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14908 /* If window start is on a continuation line... Window start may be
14909 < BEGV in case there's invisible text at the start of the
14910 buffer (M-x rmail, for example). */
14911 if (CHARPOS (start_pos
) > BEGV
14912 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14915 struct glyph_row
*row
;
14917 /* Handle the case that the window start is out of range. */
14918 if (CHARPOS (start_pos
) < BEGV
)
14919 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14920 else if (CHARPOS (start_pos
) > ZV
)
14921 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14923 /* Find the start of the continued line. This should be fast
14924 because find_newline is fast (newline cache). */
14925 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14926 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14927 row
, DEFAULT_FACE_ID
);
14928 reseat_at_previous_visible_line_start (&it
);
14930 /* If the line start is "too far" away from the window start,
14931 say it takes too much time to compute a new window start. */
14932 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14933 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14935 int min_distance
, distance
;
14937 /* Move forward by display lines to find the new window
14938 start. If window width was enlarged, the new start can
14939 be expected to be > the old start. If window width was
14940 decreased, the new window start will be < the old start.
14941 So, we're looking for the display line start with the
14942 minimum distance from the old window start. */
14943 pos
= it
.current
.pos
;
14944 min_distance
= INFINITY
;
14945 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14946 distance
< min_distance
)
14948 min_distance
= distance
;
14949 pos
= it
.current
.pos
;
14950 if (it
.line_wrap
== WORD_WRAP
)
14952 /* Under WORD_WRAP, move_it_by_lines is likely to
14953 overshoot and stop not at the first, but the
14954 second character from the left margin. So in
14955 that case, we need a more tight control on the X
14956 coordinate of the iterator than move_it_by_lines
14957 promises in its contract. The method is to first
14958 go to the last (rightmost) visible character of a
14959 line, then move to the leftmost character on the
14960 next line in a separate call. */
14961 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14962 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14963 move_it_to (&it
, ZV
, 0,
14964 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14965 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14968 move_it_by_lines (&it
, 1);
14971 /* Set the window start there. */
14972 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14973 window_start_changed_p
= 1;
14977 return window_start_changed_p
;
14981 /* Try cursor movement in case text has not changed in window WINDOW,
14982 with window start STARTP. Value is
14984 CURSOR_MOVEMENT_SUCCESS if successful
14986 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14988 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14989 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14990 we want to scroll as if scroll-step were set to 1. See the code.
14992 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14993 which case we have to abort this redisplay, and adjust matrices
14998 CURSOR_MOVEMENT_SUCCESS
,
14999 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15000 CURSOR_MOVEMENT_MUST_SCROLL
,
15001 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15005 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15007 struct window
*w
= XWINDOW (window
);
15008 struct frame
*f
= XFRAME (w
->frame
);
15009 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15012 if (inhibit_try_cursor_movement
)
15016 /* Previously, there was a check for Lisp integer in the
15017 if-statement below. Now, this field is converted to
15018 ptrdiff_t, thus zero means invalid position in a buffer. */
15019 eassert (w
->last_point
> 0);
15020 /* Likewise there was a check whether window_end_vpos is nil or larger
15021 than the window. Now window_end_vpos is int and so never nil, but
15022 let's leave eassert to check whether it fits in the window. */
15023 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15025 /* Handle case where text has not changed, only point, and it has
15026 not moved off the frame. */
15027 if (/* Point may be in this window. */
15028 PT
>= CHARPOS (startp
)
15029 /* Selective display hasn't changed. */
15030 && !current_buffer
->clip_changed
15031 /* Function force-mode-line-update is used to force a thorough
15032 redisplay. It sets either windows_or_buffers_changed or
15033 update_mode_lines. So don't take a shortcut here for these
15035 && !update_mode_lines
15036 && !windows_or_buffers_changed
15037 && !f
->cursor_type_changed
15038 && NILP (Vshow_trailing_whitespace
)
15039 /* This code is not used for mini-buffer for the sake of the case
15040 of redisplaying to replace an echo area message; since in
15041 that case the mini-buffer contents per se are usually
15042 unchanged. This code is of no real use in the mini-buffer
15043 since the handling of this_line_start_pos, etc., in redisplay
15044 handles the same cases. */
15045 && !EQ (window
, minibuf_window
)
15046 && (FRAME_WINDOW_P (f
)
15047 || !overlay_arrow_in_current_buffer_p ()))
15049 int this_scroll_margin
, top_scroll_margin
;
15050 struct glyph_row
*row
= NULL
;
15051 int frame_line_height
= default_line_pixel_height (w
);
15052 int window_total_lines
15053 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15056 debug_method_add (w
, "cursor movement");
15059 /* Scroll if point within this distance from the top or bottom
15060 of the window. This is a pixel value. */
15061 if (scroll_margin
> 0)
15063 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15064 this_scroll_margin
*= frame_line_height
;
15067 this_scroll_margin
= 0;
15069 top_scroll_margin
= this_scroll_margin
;
15070 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15071 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15073 /* Start with the row the cursor was displayed during the last
15074 not paused redisplay. Give up if that row is not valid. */
15075 if (w
->last_cursor_vpos
< 0
15076 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15077 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15080 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15081 if (row
->mode_line_p
)
15083 if (!row
->enabled_p
)
15084 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15087 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15089 int scroll_p
= 0, must_scroll
= 0;
15090 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15092 if (PT
> w
->last_point
)
15094 /* Point has moved forward. */
15095 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15096 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15098 eassert (row
->enabled_p
);
15102 /* If the end position of a row equals the start
15103 position of the next row, and PT is at that position,
15104 we would rather display cursor in the next line. */
15105 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15106 && MATRIX_ROW_END_CHARPOS (row
) == PT
15107 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15108 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15109 && !cursor_row_p (row
))
15112 /* If within the scroll margin, scroll. Note that
15113 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15114 the next line would be drawn, and that
15115 this_scroll_margin can be zero. */
15116 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15117 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15118 /* Line is completely visible last line in window
15119 and PT is to be set in the next line. */
15120 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15121 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15122 && !row
->ends_at_zv_p
15123 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15126 else if (PT
< w
->last_point
)
15128 /* Cursor has to be moved backward. Note that PT >=
15129 CHARPOS (startp) because of the outer if-statement. */
15130 while (!row
->mode_line_p
15131 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15132 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15133 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15134 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15135 row
> w
->current_matrix
->rows
15136 && (row
-1)->ends_in_newline_from_string_p
))))
15137 && (row
->y
> top_scroll_margin
15138 || CHARPOS (startp
) == BEGV
))
15140 eassert (row
->enabled_p
);
15144 /* Consider the following case: Window starts at BEGV,
15145 there is invisible, intangible text at BEGV, so that
15146 display starts at some point START > BEGV. It can
15147 happen that we are called with PT somewhere between
15148 BEGV and START. Try to handle that case. */
15149 if (row
< w
->current_matrix
->rows
15150 || row
->mode_line_p
)
15152 row
= w
->current_matrix
->rows
;
15153 if (row
->mode_line_p
)
15157 /* Due to newlines in overlay strings, we may have to
15158 skip forward over overlay strings. */
15159 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15160 && MATRIX_ROW_END_CHARPOS (row
) == PT
15161 && !cursor_row_p (row
))
15164 /* If within the scroll margin, scroll. */
15165 if (row
->y
< top_scroll_margin
15166 && CHARPOS (startp
) != BEGV
)
15171 /* Cursor did not move. So don't scroll even if cursor line
15172 is partially visible, as it was so before. */
15173 rc
= CURSOR_MOVEMENT_SUCCESS
;
15176 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15177 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15179 /* if PT is not in the glyph row, give up. */
15180 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15183 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15184 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15186 struct glyph_row
*row1
;
15188 /* If rows are bidi-reordered and point moved, back up
15189 until we find a row that does not belong to a
15190 continuation line. This is because we must consider
15191 all rows of a continued line as candidates for the
15192 new cursor positioning, since row start and end
15193 positions change non-linearly with vertical position
15195 /* FIXME: Revisit this when glyph ``spilling'' in
15196 continuation lines' rows is implemented for
15197 bidi-reordered rows. */
15198 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15199 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15202 /* If we hit the beginning of the displayed portion
15203 without finding the first row of a continued
15207 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15210 eassert (row
->enabled_p
);
15215 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15216 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15217 /* Make sure this isn't a header line by any chance, since
15218 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15219 && !row
->mode_line_p
15220 && make_cursor_line_fully_visible_p
)
15222 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15223 && !row
->ends_at_zv_p
15224 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15225 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15226 else if (row
->height
> window_box_height (w
))
15228 /* If we end up in a partially visible line, let's
15229 make it fully visible, except when it's taller
15230 than the window, in which case we can't do much
15233 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15237 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15238 if (!cursor_row_fully_visible_p (w
, 0, 1))
15239 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15241 rc
= CURSOR_MOVEMENT_SUCCESS
;
15245 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15246 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15247 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15249 /* With bidi-reordered rows, there could be more than
15250 one candidate row whose start and end positions
15251 occlude point. We need to let set_cursor_from_row
15252 find the best candidate. */
15253 /* FIXME: Revisit this when glyph ``spilling'' in
15254 continuation lines' rows is implemented for
15255 bidi-reordered rows. */
15260 int at_zv_p
= 0, exact_match_p
= 0;
15262 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15263 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15264 && cursor_row_p (row
))
15265 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15267 /* As soon as we've found the exact match for point,
15268 or the first suitable row whose ends_at_zv_p flag
15269 is set, we are done. */
15271 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15273 && w
->cursor
.hpos
>= 0
15274 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15277 struct glyph_row
*candidate
=
15278 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15280 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15281 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15284 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15285 || (INTEGERP (g
->object
)
15286 && (g
->charpos
== PT
15287 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15289 if (rv
&& (at_zv_p
|| exact_match_p
))
15291 rc
= CURSOR_MOVEMENT_SUCCESS
;
15294 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15298 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15299 || row
->continued_p
)
15300 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15301 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15302 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15303 /* If we didn't find any candidate rows, or exited the
15304 loop before all the candidates were examined, signal
15305 to the caller that this method failed. */
15306 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15308 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15309 && !row
->continued_p
))
15310 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15312 rc
= CURSOR_MOVEMENT_SUCCESS
;
15318 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15320 rc
= CURSOR_MOVEMENT_SUCCESS
;
15325 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15326 && MATRIX_ROW_START_CHARPOS (row
) == PT
15327 && cursor_row_p (row
));
15335 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15339 set_vertical_scroll_bar (struct window
*w
)
15341 ptrdiff_t start
, end
, whole
;
15343 /* Calculate the start and end positions for the current window.
15344 At some point, it would be nice to choose between scrollbars
15345 which reflect the whole buffer size, with special markers
15346 indicating narrowing, and scrollbars which reflect only the
15349 Note that mini-buffers sometimes aren't displaying any text. */
15350 if (!MINI_WINDOW_P (w
)
15351 || (w
== XWINDOW (minibuf_window
)
15352 && NILP (echo_area_buffer
[0])))
15354 struct buffer
*buf
= XBUFFER (w
->contents
);
15355 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15356 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15357 /* I don't think this is guaranteed to be right. For the
15358 moment, we'll pretend it is. */
15359 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15363 if (whole
< (end
- start
))
15364 whole
= end
- start
;
15367 start
= end
= whole
= 0;
15369 /* Indicate what this scroll bar ought to be displaying now. */
15370 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15371 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15372 (w
, end
- start
, whole
, start
);
15376 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15377 selected_window is redisplayed.
15379 We can return without actually redisplaying the window if fonts has been
15380 changed on window's frame. In that case, redisplay_internal will retry. */
15383 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15385 struct window
*w
= XWINDOW (window
);
15386 struct frame
*f
= XFRAME (w
->frame
);
15387 struct buffer
*buffer
= XBUFFER (w
->contents
);
15388 struct buffer
*old
= current_buffer
;
15389 struct text_pos lpoint
, opoint
, startp
;
15390 int update_mode_line
;
15393 /* Record it now because it's overwritten. */
15394 int current_matrix_up_to_date_p
= 0;
15395 int used_current_matrix_p
= 0;
15396 /* This is less strict than current_matrix_up_to_date_p.
15397 It indicates that the buffer contents and narrowing are unchanged. */
15398 int buffer_unchanged_p
= 0;
15399 int temp_scroll_step
= 0;
15400 ptrdiff_t count
= SPECPDL_INDEX ();
15402 int centering_position
= -1;
15403 int last_line_misfit
= 0;
15404 ptrdiff_t beg_unchanged
, end_unchanged
;
15405 int frame_line_height
;
15407 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15411 *w
->desired_matrix
->method
= 0;
15414 if (!just_this_one_p
15415 && REDISPLAY_SOME_P ()
15418 && !buffer
->text
->redisplay
)
15421 /* Make sure that both W's markers are valid. */
15422 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15423 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15426 reconsider_clip_changes (w
);
15427 frame_line_height
= default_line_pixel_height (w
);
15429 /* Has the mode line to be updated? */
15430 update_mode_line
= (w
->update_mode_line
15431 || update_mode_lines
15432 || buffer
->clip_changed
15433 || buffer
->prevent_redisplay_optimizations_p
);
15435 if (MINI_WINDOW_P (w
))
15437 if (w
== XWINDOW (echo_area_window
)
15438 && !NILP (echo_area_buffer
[0]))
15440 if (update_mode_line
)
15441 /* We may have to update a tty frame's menu bar or a
15442 tool-bar. Example `M-x C-h C-h C-g'. */
15443 goto finish_menu_bars
;
15445 /* We've already displayed the echo area glyphs in this window. */
15446 goto finish_scroll_bars
;
15448 else if ((w
!= XWINDOW (minibuf_window
)
15449 || minibuf_level
== 0)
15450 /* When buffer is nonempty, redisplay window normally. */
15451 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15452 /* Quail displays non-mini buffers in minibuffer window.
15453 In that case, redisplay the window normally. */
15454 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15456 /* W is a mini-buffer window, but it's not active, so clear
15458 int yb
= window_text_bottom_y (w
);
15459 struct glyph_row
*row
;
15462 for (y
= 0, row
= w
->desired_matrix
->rows
;
15464 y
+= row
->height
, ++row
)
15465 blank_row (w
, row
, y
);
15466 goto finish_scroll_bars
;
15469 clear_glyph_matrix (w
->desired_matrix
);
15472 /* Otherwise set up data on this window; select its buffer and point
15474 /* Really select the buffer, for the sake of buffer-local
15476 set_buffer_internal_1 (XBUFFER (w
->contents
));
15478 current_matrix_up_to_date_p
15479 = (w
->window_end_valid
15480 && !current_buffer
->clip_changed
15481 && !current_buffer
->prevent_redisplay_optimizations_p
15482 && !window_outdated (w
));
15484 /* Run the window-bottom-change-functions
15485 if it is possible that the text on the screen has changed
15486 (either due to modification of the text, or any other reason). */
15487 if (!current_matrix_up_to_date_p
15488 && !NILP (Vwindow_text_change_functions
))
15490 safe_run_hooks (Qwindow_text_change_functions
);
15494 beg_unchanged
= BEG_UNCHANGED
;
15495 end_unchanged
= END_UNCHANGED
;
15497 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15499 specbind (Qinhibit_point_motion_hooks
, Qt
);
15502 = (w
->window_end_valid
15503 && !current_buffer
->clip_changed
15504 && !window_outdated (w
));
15506 /* When windows_or_buffers_changed is non-zero, we can't rely
15507 on the window end being valid, so set it to zero there. */
15508 if (windows_or_buffers_changed
)
15510 /* If window starts on a continuation line, maybe adjust the
15511 window start in case the window's width changed. */
15512 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15513 compute_window_start_on_continuation_line (w
);
15515 w
->window_end_valid
= 0;
15516 /* If so, we also can't rely on current matrix
15517 and should not fool try_cursor_movement below. */
15518 current_matrix_up_to_date_p
= 0;
15521 /* Some sanity checks. */
15522 CHECK_WINDOW_END (w
);
15523 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15525 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15528 if (mode_line_update_needed (w
))
15529 update_mode_line
= 1;
15531 /* Point refers normally to the selected window. For any other
15532 window, set up appropriate value. */
15533 if (!EQ (window
, selected_window
))
15535 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15536 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15540 new_pt_byte
= BEGV_BYTE
;
15541 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15543 else if (new_pt
> (ZV
- 1))
15546 new_pt_byte
= ZV_BYTE
;
15547 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15550 /* We don't use SET_PT so that the point-motion hooks don't run. */
15551 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15554 /* If any of the character widths specified in the display table
15555 have changed, invalidate the width run cache. It's true that
15556 this may be a bit late to catch such changes, but the rest of
15557 redisplay goes (non-fatally) haywire when the display table is
15558 changed, so why should we worry about doing any better? */
15559 if (current_buffer
->width_run_cache
)
15561 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15563 if (! disptab_matches_widthtab
15564 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15566 invalidate_region_cache (current_buffer
,
15567 current_buffer
->width_run_cache
,
15569 recompute_width_table (current_buffer
, disptab
);
15573 /* If window-start is screwed up, choose a new one. */
15574 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15577 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15579 /* If someone specified a new starting point but did not insist,
15580 check whether it can be used. */
15581 if (w
->optional_new_start
15582 && CHARPOS (startp
) >= BEGV
15583 && CHARPOS (startp
) <= ZV
)
15585 w
->optional_new_start
= 0;
15586 start_display (&it
, w
, startp
);
15587 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15588 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15589 if (IT_CHARPOS (it
) == PT
)
15590 w
->force_start
= 1;
15591 /* IT may overshoot PT if text at PT is invisible. */
15592 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15593 w
->force_start
= 1;
15598 /* Handle case where place to start displaying has been specified,
15599 unless the specified location is outside the accessible range. */
15600 if (w
->force_start
|| window_frozen_p (w
))
15602 /* We set this later on if we have to adjust point. */
15605 w
->force_start
= 0;
15607 w
->window_end_valid
= 0;
15609 /* Forget any recorded base line for line number display. */
15610 if (!buffer_unchanged_p
)
15611 w
->base_line_number
= 0;
15613 /* Redisplay the mode line. Select the buffer properly for that.
15614 Also, run the hook window-scroll-functions
15615 because we have scrolled. */
15616 /* Note, we do this after clearing force_start because
15617 if there's an error, it is better to forget about force_start
15618 than to get into an infinite loop calling the hook functions
15619 and having them get more errors. */
15620 if (!update_mode_line
15621 || ! NILP (Vwindow_scroll_functions
))
15623 update_mode_line
= 1;
15624 w
->update_mode_line
= 1;
15625 startp
= run_window_scroll_functions (window
, startp
);
15628 if (CHARPOS (startp
) < BEGV
)
15629 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15630 else if (CHARPOS (startp
) > ZV
)
15631 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15633 /* Redisplay, then check if cursor has been set during the
15634 redisplay. Give up if new fonts were loaded. */
15635 /* We used to issue a CHECK_MARGINS argument to try_window here,
15636 but this causes scrolling to fail when point begins inside
15637 the scroll margin (bug#148) -- cyd */
15638 if (!try_window (window
, startp
, 0))
15640 w
->force_start
= 1;
15641 clear_glyph_matrix (w
->desired_matrix
);
15642 goto need_larger_matrices
;
15645 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15647 /* If point does not appear, try to move point so it does
15648 appear. The desired matrix has been built above, so we
15649 can use it here. */
15650 new_vpos
= window_box_height (w
) / 2;
15653 if (!cursor_row_fully_visible_p (w
, 0, 0))
15655 /* Point does appear, but on a line partly visible at end of window.
15656 Move it back to a fully-visible line. */
15657 new_vpos
= window_box_height (w
);
15659 else if (w
->cursor
.vpos
>= 0)
15661 /* Some people insist on not letting point enter the scroll
15662 margin, even though this part handles windows that didn't
15664 int window_total_lines
15665 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15666 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15667 int pixel_margin
= margin
* frame_line_height
;
15668 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15670 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15671 below, which finds the row to move point to, advances by
15672 the Y coordinate of the _next_ row, see the definition of
15673 MATRIX_ROW_BOTTOM_Y. */
15674 if (w
->cursor
.vpos
< margin
+ header_line
)
15676 w
->cursor
.vpos
= -1;
15677 clear_glyph_matrix (w
->desired_matrix
);
15678 goto try_to_scroll
;
15682 int window_height
= window_box_height (w
);
15685 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15686 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15688 w
->cursor
.vpos
= -1;
15689 clear_glyph_matrix (w
->desired_matrix
);
15690 goto try_to_scroll
;
15695 /* If we need to move point for either of the above reasons,
15696 now actually do it. */
15699 struct glyph_row
*row
;
15701 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15702 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15705 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15706 MATRIX_ROW_START_BYTEPOS (row
));
15708 if (w
!= XWINDOW (selected_window
))
15709 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15710 else if (current_buffer
== old
)
15711 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15713 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15715 /* If we are highlighting the region, then we just changed
15716 the region, so redisplay to show it. */
15717 /* FIXME: We need to (re)run pre-redisplay-function! */
15718 /* if (markpos_of_region () >= 0)
15720 clear_glyph_matrix (w->desired_matrix);
15721 if (!try_window (window, startp, 0))
15722 goto need_larger_matrices;
15728 debug_method_add (w
, "forced window start");
15733 /* Handle case where text has not changed, only point, and it has
15734 not moved off the frame, and we are not retrying after hscroll.
15735 (current_matrix_up_to_date_p is nonzero when retrying.) */
15736 if (current_matrix_up_to_date_p
15737 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15738 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15742 case CURSOR_MOVEMENT_SUCCESS
:
15743 used_current_matrix_p
= 1;
15746 case CURSOR_MOVEMENT_MUST_SCROLL
:
15747 goto try_to_scroll
;
15753 /* If current starting point was originally the beginning of a line
15754 but no longer is, find a new starting point. */
15755 else if (w
->start_at_line_beg
15756 && !(CHARPOS (startp
) <= BEGV
15757 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15760 debug_method_add (w
, "recenter 1");
15765 /* Try scrolling with try_window_id. Value is > 0 if update has
15766 been done, it is -1 if we know that the same window start will
15767 not work. It is 0 if unsuccessful for some other reason. */
15768 else if ((tem
= try_window_id (w
)) != 0)
15771 debug_method_add (w
, "try_window_id %d", tem
);
15774 if (f
->fonts_changed
)
15775 goto need_larger_matrices
;
15779 /* Otherwise try_window_id has returned -1 which means that we
15780 don't want the alternative below this comment to execute. */
15782 else if (CHARPOS (startp
) >= BEGV
15783 && CHARPOS (startp
) <= ZV
15784 && PT
>= CHARPOS (startp
)
15785 && (CHARPOS (startp
) < ZV
15786 /* Avoid starting at end of buffer. */
15787 || CHARPOS (startp
) == BEGV
15788 || !window_outdated (w
)))
15790 int d1
, d2
, d3
, d4
, d5
, d6
;
15792 /* If first window line is a continuation line, and window start
15793 is inside the modified region, but the first change is before
15794 current window start, we must select a new window start.
15796 However, if this is the result of a down-mouse event (e.g. by
15797 extending the mouse-drag-overlay), we don't want to select a
15798 new window start, since that would change the position under
15799 the mouse, resulting in an unwanted mouse-movement rather
15800 than a simple mouse-click. */
15801 if (!w
->start_at_line_beg
15802 && NILP (do_mouse_tracking
)
15803 && CHARPOS (startp
) > BEGV
15804 && CHARPOS (startp
) > BEG
+ beg_unchanged
15805 && CHARPOS (startp
) <= Z
- end_unchanged
15806 /* Even if w->start_at_line_beg is nil, a new window may
15807 start at a line_beg, since that's how set_buffer_window
15808 sets it. So, we need to check the return value of
15809 compute_window_start_on_continuation_line. (See also
15811 && XMARKER (w
->start
)->buffer
== current_buffer
15812 && compute_window_start_on_continuation_line (w
)
15813 /* It doesn't make sense to force the window start like we
15814 do at label force_start if it is already known that point
15815 will not be visible in the resulting window, because
15816 doing so will move point from its correct position
15817 instead of scrolling the window to bring point into view.
15819 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15821 w
->force_start
= 1;
15822 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15827 debug_method_add (w
, "same window start");
15830 /* Try to redisplay starting at same place as before.
15831 If point has not moved off frame, accept the results. */
15832 if (!current_matrix_up_to_date_p
15833 /* Don't use try_window_reusing_current_matrix in this case
15834 because a window scroll function can have changed the
15836 || !NILP (Vwindow_scroll_functions
)
15837 || MINI_WINDOW_P (w
)
15838 || !(used_current_matrix_p
15839 = try_window_reusing_current_matrix (w
)))
15841 IF_DEBUG (debug_method_add (w
, "1"));
15842 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15843 /* -1 means we need to scroll.
15844 0 means we need new matrices, but fonts_changed
15845 is set in that case, so we will detect it below. */
15846 goto try_to_scroll
;
15849 if (f
->fonts_changed
)
15850 goto need_larger_matrices
;
15852 if (w
->cursor
.vpos
>= 0)
15854 if (!just_this_one_p
15855 || current_buffer
->clip_changed
15856 || BEG_UNCHANGED
< CHARPOS (startp
))
15857 /* Forget any recorded base line for line number display. */
15858 w
->base_line_number
= 0;
15860 if (!cursor_row_fully_visible_p (w
, 1, 0))
15862 clear_glyph_matrix (w
->desired_matrix
);
15863 last_line_misfit
= 1;
15865 /* Drop through and scroll. */
15870 clear_glyph_matrix (w
->desired_matrix
);
15875 /* Redisplay the mode line. Select the buffer properly for that. */
15876 if (!update_mode_line
)
15878 update_mode_line
= 1;
15879 w
->update_mode_line
= 1;
15882 /* Try to scroll by specified few lines. */
15883 if ((scroll_conservatively
15884 || emacs_scroll_step
15885 || temp_scroll_step
15886 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15887 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15888 && CHARPOS (startp
) >= BEGV
15889 && CHARPOS (startp
) <= ZV
)
15891 /* The function returns -1 if new fonts were loaded, 1 if
15892 successful, 0 if not successful. */
15893 int ss
= try_scrolling (window
, just_this_one_p
,
15894 scroll_conservatively
,
15896 temp_scroll_step
, last_line_misfit
);
15899 case SCROLLING_SUCCESS
:
15902 case SCROLLING_NEED_LARGER_MATRICES
:
15903 goto need_larger_matrices
;
15905 case SCROLLING_FAILED
:
15913 /* Finally, just choose a place to start which positions point
15914 according to user preferences. */
15919 debug_method_add (w
, "recenter");
15922 /* Forget any previously recorded base line for line number display. */
15923 if (!buffer_unchanged_p
)
15924 w
->base_line_number
= 0;
15926 /* Determine the window start relative to point. */
15927 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15928 it
.current_y
= it
.last_visible_y
;
15929 if (centering_position
< 0)
15931 int window_total_lines
15932 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15935 ? min (scroll_margin
, window_total_lines
/ 4)
15937 ptrdiff_t margin_pos
= CHARPOS (startp
);
15938 Lisp_Object aggressive
;
15941 /* If there is a scroll margin at the top of the window, find
15942 its character position. */
15944 /* Cannot call start_display if startp is not in the
15945 accessible region of the buffer. This can happen when we
15946 have just switched to a different buffer and/or changed
15947 its restriction. In that case, startp is initialized to
15948 the character position 1 (BEGV) because we did not yet
15949 have chance to display the buffer even once. */
15950 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15953 void *it1data
= NULL
;
15955 SAVE_IT (it1
, it
, it1data
);
15956 start_display (&it1
, w
, startp
);
15957 move_it_vertically (&it1
, margin
* frame_line_height
);
15958 margin_pos
= IT_CHARPOS (it1
);
15959 RESTORE_IT (&it
, &it
, it1data
);
15961 scrolling_up
= PT
> margin_pos
;
15964 ? BVAR (current_buffer
, scroll_up_aggressively
)
15965 : BVAR (current_buffer
, scroll_down_aggressively
);
15967 if (!MINI_WINDOW_P (w
)
15968 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15972 /* Setting scroll-conservatively overrides
15973 scroll-*-aggressively. */
15974 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15976 double float_amount
= XFLOATINT (aggressive
);
15978 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15979 if (pt_offset
== 0 && float_amount
> 0)
15981 if (pt_offset
&& margin
> 0)
15984 /* Compute how much to move the window start backward from
15985 point so that point will be displayed where the user
15989 centering_position
= it
.last_visible_y
;
15991 centering_position
-= pt_offset
;
15992 centering_position
-=
15993 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15994 + WINDOW_HEADER_LINE_HEIGHT (w
);
15995 /* Don't let point enter the scroll margin near top of
15997 if (centering_position
< margin
* frame_line_height
)
15998 centering_position
= margin
* frame_line_height
;
16001 centering_position
= margin
* frame_line_height
+ pt_offset
;
16004 /* Set the window start half the height of the window backward
16006 centering_position
= window_box_height (w
) / 2;
16008 move_it_vertically_backward (&it
, centering_position
);
16010 eassert (IT_CHARPOS (it
) >= BEGV
);
16012 /* The function move_it_vertically_backward may move over more
16013 than the specified y-distance. If it->w is small, e.g. a
16014 mini-buffer window, we may end up in front of the window's
16015 display area. Start displaying at the start of the line
16016 containing PT in this case. */
16017 if (it
.current_y
<= 0)
16019 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16020 move_it_vertically_backward (&it
, 0);
16024 it
.current_x
= it
.hpos
= 0;
16026 /* Set the window start position here explicitly, to avoid an
16027 infinite loop in case the functions in window-scroll-functions
16029 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16031 /* Run scroll hooks. */
16032 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16034 /* Redisplay the window. */
16035 if (!current_matrix_up_to_date_p
16036 || windows_or_buffers_changed
16037 || f
->cursor_type_changed
16038 /* Don't use try_window_reusing_current_matrix in this case
16039 because it can have changed the buffer. */
16040 || !NILP (Vwindow_scroll_functions
)
16041 || !just_this_one_p
16042 || MINI_WINDOW_P (w
)
16043 || !(used_current_matrix_p
16044 = try_window_reusing_current_matrix (w
)))
16045 try_window (window
, startp
, 0);
16047 /* If new fonts have been loaded (due to fontsets), give up. We
16048 have to start a new redisplay since we need to re-adjust glyph
16050 if (f
->fonts_changed
)
16051 goto need_larger_matrices
;
16053 /* If cursor did not appear assume that the middle of the window is
16054 in the first line of the window. Do it again with the next line.
16055 (Imagine a window of height 100, displaying two lines of height
16056 60. Moving back 50 from it->last_visible_y will end in the first
16058 if (w
->cursor
.vpos
< 0)
16060 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16062 clear_glyph_matrix (w
->desired_matrix
);
16063 move_it_by_lines (&it
, 1);
16064 try_window (window
, it
.current
.pos
, 0);
16066 else if (PT
< IT_CHARPOS (it
))
16068 clear_glyph_matrix (w
->desired_matrix
);
16069 move_it_by_lines (&it
, -1);
16070 try_window (window
, it
.current
.pos
, 0);
16074 /* Not much we can do about it. */
16078 /* Consider the following case: Window starts at BEGV, there is
16079 invisible, intangible text at BEGV, so that display starts at
16080 some point START > BEGV. It can happen that we are called with
16081 PT somewhere between BEGV and START. Try to handle that case. */
16082 if (w
->cursor
.vpos
< 0)
16084 struct glyph_row
*row
= w
->current_matrix
->rows
;
16085 if (row
->mode_line_p
)
16087 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16090 if (!cursor_row_fully_visible_p (w
, 0, 0))
16092 /* If vscroll is enabled, disable it and try again. */
16096 clear_glyph_matrix (w
->desired_matrix
);
16100 /* Users who set scroll-conservatively to a large number want
16101 point just above/below the scroll margin. If we ended up
16102 with point's row partially visible, move the window start to
16103 make that row fully visible and out of the margin. */
16104 if (scroll_conservatively
> SCROLL_LIMIT
)
16106 int window_total_lines
16107 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16110 ? min (scroll_margin
, window_total_lines
/ 4)
16112 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16114 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16115 clear_glyph_matrix (w
->desired_matrix
);
16116 if (1 == try_window (window
, it
.current
.pos
,
16117 TRY_WINDOW_CHECK_MARGINS
))
16121 /* If centering point failed to make the whole line visible,
16122 put point at the top instead. That has to make the whole line
16123 visible, if it can be done. */
16124 if (centering_position
== 0)
16127 clear_glyph_matrix (w
->desired_matrix
);
16128 centering_position
= 0;
16134 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16135 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16136 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16138 /* Display the mode line, if we must. */
16139 if ((update_mode_line
16140 /* If window not full width, must redo its mode line
16141 if (a) the window to its side is being redone and
16142 (b) we do a frame-based redisplay. This is a consequence
16143 of how inverted lines are drawn in frame-based redisplay. */
16144 || (!just_this_one_p
16145 && !FRAME_WINDOW_P (f
)
16146 && !WINDOW_FULL_WIDTH_P (w
))
16147 /* Line number to display. */
16148 || w
->base_line_pos
> 0
16149 /* Column number is displayed and different from the one displayed. */
16150 || (w
->column_number_displayed
!= -1
16151 && (w
->column_number_displayed
!= current_column ())))
16152 /* This means that the window has a mode line. */
16153 && (WINDOW_WANTS_MODELINE_P (w
)
16154 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16156 display_mode_lines (w
);
16158 /* If mode line height has changed, arrange for a thorough
16159 immediate redisplay using the correct mode line height. */
16160 if (WINDOW_WANTS_MODELINE_P (w
)
16161 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16163 f
->fonts_changed
= 1;
16164 w
->mode_line_height
= -1;
16165 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16166 = DESIRED_MODE_LINE_HEIGHT (w
);
16169 /* If header line height has changed, arrange for a thorough
16170 immediate redisplay using the correct header line height. */
16171 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16172 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16174 f
->fonts_changed
= 1;
16175 w
->header_line_height
= -1;
16176 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16177 = DESIRED_HEADER_LINE_HEIGHT (w
);
16180 if (f
->fonts_changed
)
16181 goto need_larger_matrices
;
16184 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16186 w
->base_line_pos
= 0;
16187 w
->base_line_number
= 0;
16192 /* When we reach a frame's selected window, redo the frame's menu bar. */
16193 if (update_mode_line
16194 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16196 int redisplay_menu_p
= 0;
16198 if (FRAME_WINDOW_P (f
))
16200 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16201 || defined (HAVE_NS) || defined (USE_GTK)
16202 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16204 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16208 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16210 if (redisplay_menu_p
)
16211 display_menu_bar (w
);
16213 #ifdef HAVE_WINDOW_SYSTEM
16214 if (FRAME_WINDOW_P (f
))
16216 #if defined (USE_GTK) || defined (HAVE_NS)
16217 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16218 redisplay_tool_bar (f
);
16220 if (WINDOWP (f
->tool_bar_window
)
16221 && (FRAME_TOOL_BAR_LINES (f
) > 0
16222 || !NILP (Vauto_resize_tool_bars
))
16223 && redisplay_tool_bar (f
))
16224 ignore_mouse_drag_p
= 1;
16230 #ifdef HAVE_WINDOW_SYSTEM
16231 if (FRAME_WINDOW_P (f
)
16232 && update_window_fringes (w
, (just_this_one_p
16233 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16234 || w
->pseudo_window_p
)))
16238 if (draw_window_fringes (w
, 1))
16239 x_draw_vertical_border (w
);
16243 #endif /* HAVE_WINDOW_SYSTEM */
16245 /* We go to this label, with fonts_changed set, if it is
16246 necessary to try again using larger glyph matrices.
16247 We have to redeem the scroll bar even in this case,
16248 because the loop in redisplay_internal expects that. */
16249 need_larger_matrices
:
16251 finish_scroll_bars
:
16253 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16255 /* Set the thumb's position and size. */
16256 set_vertical_scroll_bar (w
);
16258 /* Note that we actually used the scroll bar attached to this
16259 window, so it shouldn't be deleted at the end of redisplay. */
16260 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16261 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16264 /* Restore current_buffer and value of point in it. The window
16265 update may have changed the buffer, so first make sure `opoint'
16266 is still valid (Bug#6177). */
16267 if (CHARPOS (opoint
) < BEGV
)
16268 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16269 else if (CHARPOS (opoint
) > ZV
)
16270 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16272 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16274 set_buffer_internal_1 (old
);
16275 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16276 shorter. This can be caused by log truncation in *Messages*. */
16277 if (CHARPOS (lpoint
) <= ZV
)
16278 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16280 unbind_to (count
, Qnil
);
16284 /* Build the complete desired matrix of WINDOW with a window start
16285 buffer position POS.
16287 Value is 1 if successful. It is zero if fonts were loaded during
16288 redisplay which makes re-adjusting glyph matrices necessary, and -1
16289 if point would appear in the scroll margins.
16290 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16291 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16295 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16297 struct window
*w
= XWINDOW (window
);
16299 struct glyph_row
*last_text_row
= NULL
;
16300 struct frame
*f
= XFRAME (w
->frame
);
16301 int frame_line_height
= default_line_pixel_height (w
);
16303 /* Make POS the new window start. */
16304 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16306 /* Mark cursor position as unknown. No overlay arrow seen. */
16307 w
->cursor
.vpos
= -1;
16308 overlay_arrow_seen
= 0;
16310 /* Initialize iterator and info to start at POS. */
16311 start_display (&it
, w
, pos
);
16313 /* Display all lines of W. */
16314 while (it
.current_y
< it
.last_visible_y
)
16316 if (display_line (&it
))
16317 last_text_row
= it
.glyph_row
- 1;
16318 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16322 /* Don't let the cursor end in the scroll margins. */
16323 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16324 && !MINI_WINDOW_P (w
))
16326 int this_scroll_margin
;
16327 int window_total_lines
16328 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16330 if (scroll_margin
> 0)
16332 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16333 this_scroll_margin
*= frame_line_height
;
16336 this_scroll_margin
= 0;
16338 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16339 && w
->cursor
.y
< this_scroll_margin
16340 && CHARPOS (pos
) > BEGV
16341 && IT_CHARPOS (it
) < ZV
)
16342 /* rms: considering make_cursor_line_fully_visible_p here
16343 seems to give wrong results. We don't want to recenter
16344 when the last line is partly visible, we want to allow
16345 that case to be handled in the usual way. */
16346 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16348 w
->cursor
.vpos
= -1;
16349 clear_glyph_matrix (w
->desired_matrix
);
16354 /* If bottom moved off end of frame, change mode line percentage. */
16355 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16356 w
->update_mode_line
= 1;
16358 /* Set window_end_pos to the offset of the last character displayed
16359 on the window from the end of current_buffer. Set
16360 window_end_vpos to its row number. */
16363 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16364 adjust_window_ends (w
, last_text_row
, 0);
16366 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16367 w
->window_end_vpos
)));
16371 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16372 w
->window_end_pos
= Z
- ZV
;
16373 w
->window_end_vpos
= 0;
16376 /* But that is not valid info until redisplay finishes. */
16377 w
->window_end_valid
= 0;
16383 /************************************************************************
16384 Window redisplay reusing current matrix when buffer has not changed
16385 ************************************************************************/
16387 /* Try redisplay of window W showing an unchanged buffer with a
16388 different window start than the last time it was displayed by
16389 reusing its current matrix. Value is non-zero if successful.
16390 W->start is the new window start. */
16393 try_window_reusing_current_matrix (struct window
*w
)
16395 struct frame
*f
= XFRAME (w
->frame
);
16396 struct glyph_row
*bottom_row
;
16399 struct text_pos start
, new_start
;
16400 int nrows_scrolled
, i
;
16401 struct glyph_row
*last_text_row
;
16402 struct glyph_row
*last_reused_text_row
;
16403 struct glyph_row
*start_row
;
16404 int start_vpos
, min_y
, max_y
;
16407 if (inhibit_try_window_reusing
)
16411 if (/* This function doesn't handle terminal frames. */
16412 !FRAME_WINDOW_P (f
)
16413 /* Don't try to reuse the display if windows have been split
16415 || windows_or_buffers_changed
16416 || f
->cursor_type_changed
)
16419 /* Can't do this if showing trailing whitespace. */
16420 if (!NILP (Vshow_trailing_whitespace
))
16423 /* If top-line visibility has changed, give up. */
16424 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16425 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16428 /* Give up if old or new display is scrolled vertically. We could
16429 make this function handle this, but right now it doesn't. */
16430 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16431 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16434 /* The variable new_start now holds the new window start. The old
16435 start `start' can be determined from the current matrix. */
16436 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16437 start
= start_row
->minpos
;
16438 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16440 /* Clear the desired matrix for the display below. */
16441 clear_glyph_matrix (w
->desired_matrix
);
16443 if (CHARPOS (new_start
) <= CHARPOS (start
))
16445 /* Don't use this method if the display starts with an ellipsis
16446 displayed for invisible text. It's not easy to handle that case
16447 below, and it's certainly not worth the effort since this is
16448 not a frequent case. */
16449 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16452 IF_DEBUG (debug_method_add (w
, "twu1"));
16454 /* Display up to a row that can be reused. The variable
16455 last_text_row is set to the last row displayed that displays
16456 text. Note that it.vpos == 0 if or if not there is a
16457 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16458 start_display (&it
, w
, new_start
);
16459 w
->cursor
.vpos
= -1;
16460 last_text_row
= last_reused_text_row
= NULL
;
16462 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16464 /* If we have reached into the characters in the START row,
16465 that means the line boundaries have changed. So we
16466 can't start copying with the row START. Maybe it will
16467 work to start copying with the following row. */
16468 while (IT_CHARPOS (it
) > CHARPOS (start
))
16470 /* Advance to the next row as the "start". */
16472 start
= start_row
->minpos
;
16473 /* If there are no more rows to try, or just one, give up. */
16474 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16475 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16476 || CHARPOS (start
) == ZV
)
16478 clear_glyph_matrix (w
->desired_matrix
);
16482 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16484 /* If we have reached alignment, we can copy the rest of the
16486 if (IT_CHARPOS (it
) == CHARPOS (start
)
16487 /* Don't accept "alignment" inside a display vector,
16488 since start_row could have started in the middle of
16489 that same display vector (thus their character
16490 positions match), and we have no way of telling if
16491 that is the case. */
16492 && it
.current
.dpvec_index
< 0)
16495 if (display_line (&it
))
16496 last_text_row
= it
.glyph_row
- 1;
16500 /* A value of current_y < last_visible_y means that we stopped
16501 at the previous window start, which in turn means that we
16502 have at least one reusable row. */
16503 if (it
.current_y
< it
.last_visible_y
)
16505 struct glyph_row
*row
;
16507 /* IT.vpos always starts from 0; it counts text lines. */
16508 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16510 /* Find PT if not already found in the lines displayed. */
16511 if (w
->cursor
.vpos
< 0)
16513 int dy
= it
.current_y
- start_row
->y
;
16515 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16516 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16518 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16519 dy
, nrows_scrolled
);
16522 clear_glyph_matrix (w
->desired_matrix
);
16527 /* Scroll the display. Do it before the current matrix is
16528 changed. The problem here is that update has not yet
16529 run, i.e. part of the current matrix is not up to date.
16530 scroll_run_hook will clear the cursor, and use the
16531 current matrix to get the height of the row the cursor is
16533 run
.current_y
= start_row
->y
;
16534 run
.desired_y
= it
.current_y
;
16535 run
.height
= it
.last_visible_y
- it
.current_y
;
16537 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16540 FRAME_RIF (f
)->update_window_begin_hook (w
);
16541 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16542 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16543 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16547 /* Shift current matrix down by nrows_scrolled lines. */
16548 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16549 rotate_matrix (w
->current_matrix
,
16551 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16554 /* Disable lines that must be updated. */
16555 for (i
= 0; i
< nrows_scrolled
; ++i
)
16556 (start_row
+ i
)->enabled_p
= 0;
16558 /* Re-compute Y positions. */
16559 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16560 max_y
= it
.last_visible_y
;
16561 for (row
= start_row
+ nrows_scrolled
;
16565 row
->y
= it
.current_y
;
16566 row
->visible_height
= row
->height
;
16568 if (row
->y
< min_y
)
16569 row
->visible_height
-= min_y
- row
->y
;
16570 if (row
->y
+ row
->height
> max_y
)
16571 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16572 if (row
->fringe_bitmap_periodic_p
)
16573 row
->redraw_fringe_bitmaps_p
= 1;
16575 it
.current_y
+= row
->height
;
16577 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16578 last_reused_text_row
= row
;
16579 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16583 /* Disable lines in the current matrix which are now
16584 below the window. */
16585 for (++row
; row
< bottom_row
; ++row
)
16586 row
->enabled_p
= row
->mode_line_p
= 0;
16589 /* Update window_end_pos etc.; last_reused_text_row is the last
16590 reused row from the current matrix containing text, if any.
16591 The value of last_text_row is the last displayed line
16592 containing text. */
16593 if (last_reused_text_row
)
16594 adjust_window_ends (w
, last_reused_text_row
, 1);
16595 else if (last_text_row
)
16596 adjust_window_ends (w
, last_text_row
, 0);
16599 /* This window must be completely empty. */
16600 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16601 w
->window_end_pos
= Z
- ZV
;
16602 w
->window_end_vpos
= 0;
16604 w
->window_end_valid
= 0;
16606 /* Update hint: don't try scrolling again in update_window. */
16607 w
->desired_matrix
->no_scrolling_p
= 1;
16610 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16614 else if (CHARPOS (new_start
) > CHARPOS (start
))
16616 struct glyph_row
*pt_row
, *row
;
16617 struct glyph_row
*first_reusable_row
;
16618 struct glyph_row
*first_row_to_display
;
16620 int yb
= window_text_bottom_y (w
);
16622 /* Find the row starting at new_start, if there is one. Don't
16623 reuse a partially visible line at the end. */
16624 first_reusable_row
= start_row
;
16625 while (first_reusable_row
->enabled_p
16626 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16627 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16628 < CHARPOS (new_start
)))
16629 ++first_reusable_row
;
16631 /* Give up if there is no row to reuse. */
16632 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16633 || !first_reusable_row
->enabled_p
16634 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16635 != CHARPOS (new_start
)))
16638 /* We can reuse fully visible rows beginning with
16639 first_reusable_row to the end of the window. Set
16640 first_row_to_display to the first row that cannot be reused.
16641 Set pt_row to the row containing point, if there is any. */
16643 for (first_row_to_display
= first_reusable_row
;
16644 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16645 ++first_row_to_display
)
16647 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16648 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16649 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16650 && first_row_to_display
->ends_at_zv_p
16651 && pt_row
== NULL
)))
16652 pt_row
= first_row_to_display
;
16655 /* Start displaying at the start of first_row_to_display. */
16656 eassert (first_row_to_display
->y
< yb
);
16657 init_to_row_start (&it
, w
, first_row_to_display
);
16659 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16661 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16663 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16664 + WINDOW_HEADER_LINE_HEIGHT (w
));
16666 /* Display lines beginning with first_row_to_display in the
16667 desired matrix. Set last_text_row to the last row displayed
16668 that displays text. */
16669 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16670 if (pt_row
== NULL
)
16671 w
->cursor
.vpos
= -1;
16672 last_text_row
= NULL
;
16673 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16674 if (display_line (&it
))
16675 last_text_row
= it
.glyph_row
- 1;
16677 /* If point is in a reused row, adjust y and vpos of the cursor
16681 w
->cursor
.vpos
-= nrows_scrolled
;
16682 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16685 /* Give up if point isn't in a row displayed or reused. (This
16686 also handles the case where w->cursor.vpos < nrows_scrolled
16687 after the calls to display_line, which can happen with scroll
16688 margins. See bug#1295.) */
16689 if (w
->cursor
.vpos
< 0)
16691 clear_glyph_matrix (w
->desired_matrix
);
16695 /* Scroll the display. */
16696 run
.current_y
= first_reusable_row
->y
;
16697 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16698 run
.height
= it
.last_visible_y
- run
.current_y
;
16699 dy
= run
.current_y
- run
.desired_y
;
16704 FRAME_RIF (f
)->update_window_begin_hook (w
);
16705 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16706 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16707 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16711 /* Adjust Y positions of reused rows. */
16712 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16713 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16714 max_y
= it
.last_visible_y
;
16715 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16718 row
->visible_height
= row
->height
;
16719 if (row
->y
< min_y
)
16720 row
->visible_height
-= min_y
- row
->y
;
16721 if (row
->y
+ row
->height
> max_y
)
16722 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16723 if (row
->fringe_bitmap_periodic_p
)
16724 row
->redraw_fringe_bitmaps_p
= 1;
16727 /* Scroll the current matrix. */
16728 eassert (nrows_scrolled
> 0);
16729 rotate_matrix (w
->current_matrix
,
16731 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16734 /* Disable rows not reused. */
16735 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16736 row
->enabled_p
= 0;
16738 /* Point may have moved to a different line, so we cannot assume that
16739 the previous cursor position is valid; locate the correct row. */
16742 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16744 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16745 && !row
->ends_at_zv_p
;
16749 w
->cursor
.y
= row
->y
;
16751 if (row
< bottom_row
)
16753 /* Can't simply scan the row for point with
16754 bidi-reordered glyph rows. Let set_cursor_from_row
16755 figure out where to put the cursor, and if it fails,
16757 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16759 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16762 clear_glyph_matrix (w
->desired_matrix
);
16768 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16769 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16772 && (!BUFFERP (glyph
->object
)
16773 || glyph
->charpos
< PT
);
16777 w
->cursor
.x
+= glyph
->pixel_width
;
16783 /* Adjust window end. A null value of last_text_row means that
16784 the window end is in reused rows which in turn means that
16785 only its vpos can have changed. */
16787 adjust_window_ends (w
, last_text_row
, 0);
16789 w
->window_end_vpos
-= nrows_scrolled
;
16791 w
->window_end_valid
= 0;
16792 w
->desired_matrix
->no_scrolling_p
= 1;
16795 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16805 /************************************************************************
16806 Window redisplay reusing current matrix when buffer has changed
16807 ************************************************************************/
16809 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16810 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16811 ptrdiff_t *, ptrdiff_t *);
16812 static struct glyph_row
*
16813 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16814 struct glyph_row
*);
16817 /* Return the last row in MATRIX displaying text. If row START is
16818 non-null, start searching with that row. IT gives the dimensions
16819 of the display. Value is null if matrix is empty; otherwise it is
16820 a pointer to the row found. */
16822 static struct glyph_row
*
16823 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16824 struct glyph_row
*start
)
16826 struct glyph_row
*row
, *row_found
;
16828 /* Set row_found to the last row in IT->w's current matrix
16829 displaying text. The loop looks funny but think of partially
16832 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16833 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16835 eassert (row
->enabled_p
);
16837 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16846 /* Return the last row in the current matrix of W that is not affected
16847 by changes at the start of current_buffer that occurred since W's
16848 current matrix was built. Value is null if no such row exists.
16850 BEG_UNCHANGED us the number of characters unchanged at the start of
16851 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16852 first changed character in current_buffer. Characters at positions <
16853 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16854 when the current matrix was built. */
16856 static struct glyph_row
*
16857 find_last_unchanged_at_beg_row (struct window
*w
)
16859 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16860 struct glyph_row
*row
;
16861 struct glyph_row
*row_found
= NULL
;
16862 int yb
= window_text_bottom_y (w
);
16864 /* Find the last row displaying unchanged text. */
16865 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16866 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16867 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16870 if (/* If row ends before first_changed_pos, it is unchanged,
16871 except in some case. */
16872 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16873 /* When row ends in ZV and we write at ZV it is not
16875 && !row
->ends_at_zv_p
16876 /* When first_changed_pos is the end of a continued line,
16877 row is not unchanged because it may be no longer
16879 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16880 && (row
->continued_p
16881 || row
->exact_window_width_line_p
))
16882 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16883 needs to be recomputed, so don't consider this row as
16884 unchanged. This happens when the last line was
16885 bidi-reordered and was killed immediately before this
16886 redisplay cycle. In that case, ROW->end stores the
16887 buffer position of the first visual-order character of
16888 the killed text, which is now beyond ZV. */
16889 && CHARPOS (row
->end
.pos
) <= ZV
)
16892 /* Stop if last visible row. */
16893 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16901 /* Find the first glyph row in the current matrix of W that is not
16902 affected by changes at the end of current_buffer since the
16903 time W's current matrix was built.
16905 Return in *DELTA the number of chars by which buffer positions in
16906 unchanged text at the end of current_buffer must be adjusted.
16908 Return in *DELTA_BYTES the corresponding number of bytes.
16910 Value is null if no such row exists, i.e. all rows are affected by
16913 static struct glyph_row
*
16914 find_first_unchanged_at_end_row (struct window
*w
,
16915 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16917 struct glyph_row
*row
;
16918 struct glyph_row
*row_found
= NULL
;
16920 *delta
= *delta_bytes
= 0;
16922 /* Display must not have been paused, otherwise the current matrix
16923 is not up to date. */
16924 eassert (w
->window_end_valid
);
16926 /* A value of window_end_pos >= END_UNCHANGED means that the window
16927 end is in the range of changed text. If so, there is no
16928 unchanged row at the end of W's current matrix. */
16929 if (w
->window_end_pos
>= END_UNCHANGED
)
16932 /* Set row to the last row in W's current matrix displaying text. */
16933 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16935 /* If matrix is entirely empty, no unchanged row exists. */
16936 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16938 /* The value of row is the last glyph row in the matrix having a
16939 meaningful buffer position in it. The end position of row
16940 corresponds to window_end_pos. This allows us to translate
16941 buffer positions in the current matrix to current buffer
16942 positions for characters not in changed text. */
16944 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16945 ptrdiff_t Z_BYTE_old
=
16946 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16947 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16948 struct glyph_row
*first_text_row
16949 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16951 *delta
= Z
- Z_old
;
16952 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16954 /* Set last_unchanged_pos to the buffer position of the last
16955 character in the buffer that has not been changed. Z is the
16956 index + 1 of the last character in current_buffer, i.e. by
16957 subtracting END_UNCHANGED we get the index of the last
16958 unchanged character, and we have to add BEG to get its buffer
16960 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16961 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16963 /* Search backward from ROW for a row displaying a line that
16964 starts at a minimum position >= last_unchanged_pos_old. */
16965 for (; row
> first_text_row
; --row
)
16967 /* This used to abort, but it can happen.
16968 It is ok to just stop the search instead here. KFS. */
16969 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16972 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16977 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16983 /* Make sure that glyph rows in the current matrix of window W
16984 reference the same glyph memory as corresponding rows in the
16985 frame's frame matrix. This function is called after scrolling W's
16986 current matrix on a terminal frame in try_window_id and
16987 try_window_reusing_current_matrix. */
16990 sync_frame_with_window_matrix_rows (struct window
*w
)
16992 struct frame
*f
= XFRAME (w
->frame
);
16993 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16995 /* Preconditions: W must be a leaf window and full-width. Its frame
16996 must have a frame matrix. */
16997 eassert (BUFFERP (w
->contents
));
16998 eassert (WINDOW_FULL_WIDTH_P (w
));
16999 eassert (!FRAME_WINDOW_P (f
));
17001 /* If W is a full-width window, glyph pointers in W's current matrix
17002 have, by definition, to be the same as glyph pointers in the
17003 corresponding frame matrix. Note that frame matrices have no
17004 marginal areas (see build_frame_matrix). */
17005 window_row
= w
->current_matrix
->rows
;
17006 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17007 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17008 while (window_row
< window_row_end
)
17010 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17011 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17013 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17014 frame_row
->glyphs
[TEXT_AREA
] = start
;
17015 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17016 frame_row
->glyphs
[LAST_AREA
] = end
;
17018 /* Disable frame rows whose corresponding window rows have
17019 been disabled in try_window_id. */
17020 if (!window_row
->enabled_p
)
17021 frame_row
->enabled_p
= 0;
17023 ++window_row
, ++frame_row
;
17028 /* Find the glyph row in window W containing CHARPOS. Consider all
17029 rows between START and END (not inclusive). END null means search
17030 all rows to the end of the display area of W. Value is the row
17031 containing CHARPOS or null. */
17034 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17035 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17037 struct glyph_row
*row
= start
;
17038 struct glyph_row
*best_row
= NULL
;
17039 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17042 /* If we happen to start on a header-line, skip that. */
17043 if (row
->mode_line_p
)
17046 if ((end
&& row
>= end
) || !row
->enabled_p
)
17049 last_y
= window_text_bottom_y (w
) - dy
;
17053 /* Give up if we have gone too far. */
17054 if (end
&& row
>= end
)
17056 /* This formerly returned if they were equal.
17057 I think that both quantities are of a "last plus one" type;
17058 if so, when they are equal, the row is within the screen. -- rms. */
17059 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17062 /* If it is in this row, return this row. */
17063 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17064 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17065 /* The end position of a row equals the start
17066 position of the next row. If CHARPOS is there, we
17067 would rather consider it displayed in the next
17068 line, except when this line ends in ZV. */
17069 && !row_for_charpos_p (row
, charpos
)))
17070 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17074 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17075 || (!best_row
&& !row
->continued_p
))
17077 /* In bidi-reordered rows, there could be several rows whose
17078 edges surround CHARPOS, all of these rows belonging to
17079 the same continued line. We need to find the row which
17080 fits CHARPOS the best. */
17081 for (g
= row
->glyphs
[TEXT_AREA
];
17082 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17085 if (!STRINGP (g
->object
))
17087 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17089 mindif
= eabs (g
->charpos
- charpos
);
17091 /* Exact match always wins. */
17098 else if (best_row
&& !row
->continued_p
)
17105 /* Try to redisplay window W by reusing its existing display. W's
17106 current matrix must be up to date when this function is called,
17107 i.e. window_end_valid must be nonzero.
17111 1 if display has been updated
17112 0 if otherwise unsuccessful
17113 -1 if redisplay with same window start is known not to succeed
17115 The following steps are performed:
17117 1. Find the last row in the current matrix of W that is not
17118 affected by changes at the start of current_buffer. If no such row
17121 2. Find the first row in W's current matrix that is not affected by
17122 changes at the end of current_buffer. Maybe there is no such row.
17124 3. Display lines beginning with the row + 1 found in step 1 to the
17125 row found in step 2 or, if step 2 didn't find a row, to the end of
17128 4. If cursor is not known to appear on the window, give up.
17130 5. If display stopped at the row found in step 2, scroll the
17131 display and current matrix as needed.
17133 6. Maybe display some lines at the end of W, if we must. This can
17134 happen under various circumstances, like a partially visible line
17135 becoming fully visible, or because newly displayed lines are displayed
17136 in smaller font sizes.
17138 7. Update W's window end information. */
17141 try_window_id (struct window
*w
)
17143 struct frame
*f
= XFRAME (w
->frame
);
17144 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17145 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17146 struct glyph_row
*last_unchanged_at_beg_row
;
17147 struct glyph_row
*first_unchanged_at_end_row
;
17148 struct glyph_row
*row
;
17149 struct glyph_row
*bottom_row
;
17152 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17154 struct text_pos start_pos
;
17156 int first_unchanged_at_end_vpos
= 0;
17157 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17158 struct text_pos start
;
17159 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17162 if (inhibit_try_window_id
)
17166 /* This is handy for debugging. */
17168 #define GIVE_UP(X) \
17170 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17174 #define GIVE_UP(X) return 0
17177 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17179 /* Don't use this for mini-windows because these can show
17180 messages and mini-buffers, and we don't handle that here. */
17181 if (MINI_WINDOW_P (w
))
17184 /* This flag is used to prevent redisplay optimizations. */
17185 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17188 /* Verify that narrowing has not changed.
17189 Also verify that we were not told to prevent redisplay optimizations.
17190 It would be nice to further
17191 reduce the number of cases where this prevents try_window_id. */
17192 if (current_buffer
->clip_changed
17193 || current_buffer
->prevent_redisplay_optimizations_p
)
17196 /* Window must either use window-based redisplay or be full width. */
17197 if (!FRAME_WINDOW_P (f
)
17198 && (!FRAME_LINE_INS_DEL_OK (f
)
17199 || !WINDOW_FULL_WIDTH_P (w
)))
17202 /* Give up if point is known NOT to appear in W. */
17203 if (PT
< CHARPOS (start
))
17206 /* Another way to prevent redisplay optimizations. */
17207 if (w
->last_modified
== 0)
17210 /* Verify that window is not hscrolled. */
17211 if (w
->hscroll
!= 0)
17214 /* Verify that display wasn't paused. */
17215 if (!w
->window_end_valid
)
17218 /* Likewise if highlighting trailing whitespace. */
17219 if (!NILP (Vshow_trailing_whitespace
))
17222 /* Can't use this if overlay arrow position and/or string have
17224 if (overlay_arrows_changed_p ())
17227 /* When word-wrap is on, adding a space to the first word of a
17228 wrapped line can change the wrap position, altering the line
17229 above it. It might be worthwhile to handle this more
17230 intelligently, but for now just redisplay from scratch. */
17231 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17234 /* Under bidi reordering, adding or deleting a character in the
17235 beginning of a paragraph, before the first strong directional
17236 character, can change the base direction of the paragraph (unless
17237 the buffer specifies a fixed paragraph direction), which will
17238 require to redisplay the whole paragraph. It might be worthwhile
17239 to find the paragraph limits and widen the range of redisplayed
17240 lines to that, but for now just give up this optimization and
17241 redisplay from scratch. */
17242 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17243 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17246 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17247 only if buffer has really changed. The reason is that the gap is
17248 initially at Z for freshly visited files. The code below would
17249 set end_unchanged to 0 in that case. */
17250 if (MODIFF
> SAVE_MODIFF
17251 /* This seems to happen sometimes after saving a buffer. */
17252 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17254 if (GPT
- BEG
< BEG_UNCHANGED
)
17255 BEG_UNCHANGED
= GPT
- BEG
;
17256 if (Z
- GPT
< END_UNCHANGED
)
17257 END_UNCHANGED
= Z
- GPT
;
17260 /* The position of the first and last character that has been changed. */
17261 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17262 last_changed_charpos
= Z
- END_UNCHANGED
;
17264 /* If window starts after a line end, and the last change is in
17265 front of that newline, then changes don't affect the display.
17266 This case happens with stealth-fontification. Note that although
17267 the display is unchanged, glyph positions in the matrix have to
17268 be adjusted, of course. */
17269 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17270 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17271 && ((last_changed_charpos
< CHARPOS (start
)
17272 && CHARPOS (start
) == BEGV
)
17273 || (last_changed_charpos
< CHARPOS (start
) - 1
17274 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17276 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17277 struct glyph_row
*r0
;
17279 /* Compute how many chars/bytes have been added to or removed
17280 from the buffer. */
17281 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17282 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17283 Z_delta
= Z
- Z_old
;
17284 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17286 /* Give up if PT is not in the window. Note that it already has
17287 been checked at the start of try_window_id that PT is not in
17288 front of the window start. */
17289 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17292 /* If window start is unchanged, we can reuse the whole matrix
17293 as is, after adjusting glyph positions. No need to compute
17294 the window end again, since its offset from Z hasn't changed. */
17295 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17296 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17297 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17298 /* PT must not be in a partially visible line. */
17299 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17300 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17302 /* Adjust positions in the glyph matrix. */
17303 if (Z_delta
|| Z_delta_bytes
)
17305 struct glyph_row
*r1
17306 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17307 increment_matrix_positions (w
->current_matrix
,
17308 MATRIX_ROW_VPOS (r0
, current_matrix
),
17309 MATRIX_ROW_VPOS (r1
, current_matrix
),
17310 Z_delta
, Z_delta_bytes
);
17313 /* Set the cursor. */
17314 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17316 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17321 /* Handle the case that changes are all below what is displayed in
17322 the window, and that PT is in the window. This shortcut cannot
17323 be taken if ZV is visible in the window, and text has been added
17324 there that is visible in the window. */
17325 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17326 /* ZV is not visible in the window, or there are no
17327 changes at ZV, actually. */
17328 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17329 || first_changed_charpos
== last_changed_charpos
))
17331 struct glyph_row
*r0
;
17333 /* Give up if PT is not in the window. Note that it already has
17334 been checked at the start of try_window_id that PT is not in
17335 front of the window start. */
17336 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17339 /* If window start is unchanged, we can reuse the whole matrix
17340 as is, without changing glyph positions since no text has
17341 been added/removed in front of the window end. */
17342 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17343 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17344 /* PT must not be in a partially visible line. */
17345 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17346 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17348 /* We have to compute the window end anew since text
17349 could have been added/removed after it. */
17350 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17351 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17353 /* Set the cursor. */
17354 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17356 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17361 /* Give up if window start is in the changed area.
17363 The condition used to read
17365 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17367 but why that was tested escapes me at the moment. */
17368 if (CHARPOS (start
) >= first_changed_charpos
17369 && CHARPOS (start
) <= last_changed_charpos
)
17372 /* Check that window start agrees with the start of the first glyph
17373 row in its current matrix. Check this after we know the window
17374 start is not in changed text, otherwise positions would not be
17376 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17377 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17380 /* Give up if the window ends in strings. Overlay strings
17381 at the end are difficult to handle, so don't try. */
17382 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17383 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17386 /* Compute the position at which we have to start displaying new
17387 lines. Some of the lines at the top of the window might be
17388 reusable because they are not displaying changed text. Find the
17389 last row in W's current matrix not affected by changes at the
17390 start of current_buffer. Value is null if changes start in the
17391 first line of window. */
17392 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17393 if (last_unchanged_at_beg_row
)
17395 /* Avoid starting to display in the middle of a character, a TAB
17396 for instance. This is easier than to set up the iterator
17397 exactly, and it's not a frequent case, so the additional
17398 effort wouldn't really pay off. */
17399 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17400 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17401 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17402 --last_unchanged_at_beg_row
;
17404 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17407 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17409 start_pos
= it
.current
.pos
;
17411 /* Start displaying new lines in the desired matrix at the same
17412 vpos we would use in the current matrix, i.e. below
17413 last_unchanged_at_beg_row. */
17414 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17416 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17417 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17419 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17423 /* There are no reusable lines at the start of the window.
17424 Start displaying in the first text line. */
17425 start_display (&it
, w
, start
);
17426 it
.vpos
= it
.first_vpos
;
17427 start_pos
= it
.current
.pos
;
17430 /* Find the first row that is not affected by changes at the end of
17431 the buffer. Value will be null if there is no unchanged row, in
17432 which case we must redisplay to the end of the window. delta
17433 will be set to the value by which buffer positions beginning with
17434 first_unchanged_at_end_row have to be adjusted due to text
17436 first_unchanged_at_end_row
17437 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17438 IF_DEBUG (debug_delta
= delta
);
17439 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17441 /* Set stop_pos to the buffer position up to which we will have to
17442 display new lines. If first_unchanged_at_end_row != NULL, this
17443 is the buffer position of the start of the line displayed in that
17444 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17445 that we don't stop at a buffer position. */
17447 if (first_unchanged_at_end_row
)
17449 eassert (last_unchanged_at_beg_row
== NULL
17450 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17452 /* If this is a continuation line, move forward to the next one
17453 that isn't. Changes in lines above affect this line.
17454 Caution: this may move first_unchanged_at_end_row to a row
17455 not displaying text. */
17456 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17457 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17458 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17459 < it
.last_visible_y
))
17460 ++first_unchanged_at_end_row
;
17462 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17463 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17464 >= it
.last_visible_y
))
17465 first_unchanged_at_end_row
= NULL
;
17468 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17470 first_unchanged_at_end_vpos
17471 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17472 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17475 else if (last_unchanged_at_beg_row
== NULL
)
17481 /* Either there is no unchanged row at the end, or the one we have
17482 now displays text. This is a necessary condition for the window
17483 end pos calculation at the end of this function. */
17484 eassert (first_unchanged_at_end_row
== NULL
17485 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17487 debug_last_unchanged_at_beg_vpos
17488 = (last_unchanged_at_beg_row
17489 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17491 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17493 #endif /* GLYPH_DEBUG */
17496 /* Display new lines. Set last_text_row to the last new line
17497 displayed which has text on it, i.e. might end up as being the
17498 line where the window_end_vpos is. */
17499 w
->cursor
.vpos
= -1;
17500 last_text_row
= NULL
;
17501 overlay_arrow_seen
= 0;
17502 while (it
.current_y
< it
.last_visible_y
17503 && !f
->fonts_changed
17504 && (first_unchanged_at_end_row
== NULL
17505 || IT_CHARPOS (it
) < stop_pos
))
17507 if (display_line (&it
))
17508 last_text_row
= it
.glyph_row
- 1;
17511 if (f
->fonts_changed
)
17515 /* Compute differences in buffer positions, y-positions etc. for
17516 lines reused at the bottom of the window. Compute what we can
17518 if (first_unchanged_at_end_row
17519 /* No lines reused because we displayed everything up to the
17520 bottom of the window. */
17521 && it
.current_y
< it
.last_visible_y
)
17524 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17526 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17527 run
.current_y
= first_unchanged_at_end_row
->y
;
17528 run
.desired_y
= run
.current_y
+ dy
;
17529 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17533 delta
= delta_bytes
= dvpos
= dy
17534 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17535 first_unchanged_at_end_row
= NULL
;
17537 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17540 /* Find the cursor if not already found. We have to decide whether
17541 PT will appear on this window (it sometimes doesn't, but this is
17542 not a very frequent case.) This decision has to be made before
17543 the current matrix is altered. A value of cursor.vpos < 0 means
17544 that PT is either in one of the lines beginning at
17545 first_unchanged_at_end_row or below the window. Don't care for
17546 lines that might be displayed later at the window end; as
17547 mentioned, this is not a frequent case. */
17548 if (w
->cursor
.vpos
< 0)
17550 /* Cursor in unchanged rows at the top? */
17551 if (PT
< CHARPOS (start_pos
)
17552 && last_unchanged_at_beg_row
)
17554 row
= row_containing_pos (w
, PT
,
17555 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17556 last_unchanged_at_beg_row
+ 1, 0);
17558 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17561 /* Start from first_unchanged_at_end_row looking for PT. */
17562 else if (first_unchanged_at_end_row
)
17564 row
= row_containing_pos (w
, PT
- delta
,
17565 first_unchanged_at_end_row
, NULL
, 0);
17567 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17568 delta_bytes
, dy
, dvpos
);
17571 /* Give up if cursor was not found. */
17572 if (w
->cursor
.vpos
< 0)
17574 clear_glyph_matrix (w
->desired_matrix
);
17579 /* Don't let the cursor end in the scroll margins. */
17581 int this_scroll_margin
, cursor_height
;
17582 int frame_line_height
= default_line_pixel_height (w
);
17583 int window_total_lines
17584 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17586 this_scroll_margin
=
17587 max (0, min (scroll_margin
, window_total_lines
/ 4));
17588 this_scroll_margin
*= frame_line_height
;
17589 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17591 if ((w
->cursor
.y
< this_scroll_margin
17592 && CHARPOS (start
) > BEGV
)
17593 /* Old redisplay didn't take scroll margin into account at the bottom,
17594 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17595 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17596 ? cursor_height
+ this_scroll_margin
17597 : 1)) > it
.last_visible_y
)
17599 w
->cursor
.vpos
= -1;
17600 clear_glyph_matrix (w
->desired_matrix
);
17605 /* Scroll the display. Do it before changing the current matrix so
17606 that xterm.c doesn't get confused about where the cursor glyph is
17608 if (dy
&& run
.height
)
17612 if (FRAME_WINDOW_P (f
))
17614 FRAME_RIF (f
)->update_window_begin_hook (w
);
17615 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17616 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17617 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17621 /* Terminal frame. In this case, dvpos gives the number of
17622 lines to scroll by; dvpos < 0 means scroll up. */
17624 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17625 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17626 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17627 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17628 + window_internal_height (w
));
17630 #if defined (HAVE_GPM) || defined (MSDOS)
17631 x_clear_window_mouse_face (w
);
17633 /* Perform the operation on the screen. */
17636 /* Scroll last_unchanged_at_beg_row to the end of the
17637 window down dvpos lines. */
17638 set_terminal_window (f
, end
);
17640 /* On dumb terminals delete dvpos lines at the end
17641 before inserting dvpos empty lines. */
17642 if (!FRAME_SCROLL_REGION_OK (f
))
17643 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17645 /* Insert dvpos empty lines in front of
17646 last_unchanged_at_beg_row. */
17647 ins_del_lines (f
, from
, dvpos
);
17649 else if (dvpos
< 0)
17651 /* Scroll up last_unchanged_at_beg_vpos to the end of
17652 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17653 set_terminal_window (f
, end
);
17655 /* Delete dvpos lines in front of
17656 last_unchanged_at_beg_vpos. ins_del_lines will set
17657 the cursor to the given vpos and emit |dvpos| delete
17659 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17661 /* On a dumb terminal insert dvpos empty lines at the
17663 if (!FRAME_SCROLL_REGION_OK (f
))
17664 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17667 set_terminal_window (f
, 0);
17673 /* Shift reused rows of the current matrix to the right position.
17674 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17676 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17677 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17680 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17681 bottom_vpos
, dvpos
);
17682 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17685 else if (dvpos
> 0)
17687 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17688 bottom_vpos
, dvpos
);
17689 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17690 first_unchanged_at_end_vpos
+ dvpos
);
17693 /* For frame-based redisplay, make sure that current frame and window
17694 matrix are in sync with respect to glyph memory. */
17695 if (!FRAME_WINDOW_P (f
))
17696 sync_frame_with_window_matrix_rows (w
);
17698 /* Adjust buffer positions in reused rows. */
17699 if (delta
|| delta_bytes
)
17700 increment_matrix_positions (current_matrix
,
17701 first_unchanged_at_end_vpos
+ dvpos
,
17702 bottom_vpos
, delta
, delta_bytes
);
17704 /* Adjust Y positions. */
17706 shift_glyph_matrix (w
, current_matrix
,
17707 first_unchanged_at_end_vpos
+ dvpos
,
17710 if (first_unchanged_at_end_row
)
17712 first_unchanged_at_end_row
+= dvpos
;
17713 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17714 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17715 first_unchanged_at_end_row
= NULL
;
17718 /* If scrolling up, there may be some lines to display at the end of
17720 last_text_row_at_end
= NULL
;
17723 /* Scrolling up can leave for example a partially visible line
17724 at the end of the window to be redisplayed. */
17725 /* Set last_row to the glyph row in the current matrix where the
17726 window end line is found. It has been moved up or down in
17727 the matrix by dvpos. */
17728 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17729 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17731 /* If last_row is the window end line, it should display text. */
17732 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17734 /* If window end line was partially visible before, begin
17735 displaying at that line. Otherwise begin displaying with the
17736 line following it. */
17737 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17739 init_to_row_start (&it
, w
, last_row
);
17740 it
.vpos
= last_vpos
;
17741 it
.current_y
= last_row
->y
;
17745 init_to_row_end (&it
, w
, last_row
);
17746 it
.vpos
= 1 + last_vpos
;
17747 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17751 /* We may start in a continuation line. If so, we have to
17752 get the right continuation_lines_width and current_x. */
17753 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17754 it
.hpos
= it
.current_x
= 0;
17756 /* Display the rest of the lines at the window end. */
17757 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17758 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17760 /* Is it always sure that the display agrees with lines in
17761 the current matrix? I don't think so, so we mark rows
17762 displayed invalid in the current matrix by setting their
17763 enabled_p flag to zero. */
17764 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17765 if (display_line (&it
))
17766 last_text_row_at_end
= it
.glyph_row
- 1;
17770 /* Update window_end_pos and window_end_vpos. */
17771 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17773 /* Window end line if one of the preserved rows from the current
17774 matrix. Set row to the last row displaying text in current
17775 matrix starting at first_unchanged_at_end_row, after
17777 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17778 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17779 first_unchanged_at_end_row
);
17780 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17781 adjust_window_ends (w
, row
, 1);
17782 eassert (w
->window_end_bytepos
>= 0);
17783 IF_DEBUG (debug_method_add (w
, "A"));
17785 else if (last_text_row_at_end
)
17787 adjust_window_ends (w
, last_text_row_at_end
, 0);
17788 eassert (w
->window_end_bytepos
>= 0);
17789 IF_DEBUG (debug_method_add (w
, "B"));
17791 else if (last_text_row
)
17793 /* We have displayed either to the end of the window or at the
17794 end of the window, i.e. the last row with text is to be found
17795 in the desired matrix. */
17796 adjust_window_ends (w
, last_text_row
, 0);
17797 eassert (w
->window_end_bytepos
>= 0);
17799 else if (first_unchanged_at_end_row
== NULL
17800 && last_text_row
== NULL
17801 && last_text_row_at_end
== NULL
)
17803 /* Displayed to end of window, but no line containing text was
17804 displayed. Lines were deleted at the end of the window. */
17805 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17806 int vpos
= w
->window_end_vpos
;
17807 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17808 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17811 row
== NULL
&& vpos
>= first_vpos
;
17812 --vpos
, --current_row
, --desired_row
)
17814 if (desired_row
->enabled_p
)
17816 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17819 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17823 eassert (row
!= NULL
);
17824 w
->window_end_vpos
= vpos
+ 1;
17825 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17826 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17827 eassert (w
->window_end_bytepos
>= 0);
17828 IF_DEBUG (debug_method_add (w
, "C"));
17833 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17834 debug_end_vpos
= w
->window_end_vpos
);
17836 /* Record that display has not been completed. */
17837 w
->window_end_valid
= 0;
17838 w
->desired_matrix
->no_scrolling_p
= 1;
17846 /***********************************************************************
17847 More debugging support
17848 ***********************************************************************/
17852 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17853 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17854 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17857 /* Dump the contents of glyph matrix MATRIX on stderr.
17859 GLYPHS 0 means don't show glyph contents.
17860 GLYPHS 1 means show glyphs in short form
17861 GLYPHS > 1 means show glyphs in long form. */
17864 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17867 for (i
= 0; i
< matrix
->nrows
; ++i
)
17868 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17872 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17873 the glyph row and area where the glyph comes from. */
17876 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17878 if (glyph
->type
== CHAR_GLYPH
17879 || glyph
->type
== GLYPHLESS_GLYPH
)
17882 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17883 glyph
- row
->glyphs
[TEXT_AREA
],
17884 (glyph
->type
== CHAR_GLYPH
17888 (BUFFERP (glyph
->object
)
17890 : (STRINGP (glyph
->object
)
17892 : (INTEGERP (glyph
->object
)
17895 glyph
->pixel_width
,
17897 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17901 glyph
->left_box_line_p
,
17902 glyph
->right_box_line_p
);
17904 else if (glyph
->type
== STRETCH_GLYPH
)
17907 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17908 glyph
- row
->glyphs
[TEXT_AREA
],
17911 (BUFFERP (glyph
->object
)
17913 : (STRINGP (glyph
->object
)
17915 : (INTEGERP (glyph
->object
)
17918 glyph
->pixel_width
,
17922 glyph
->left_box_line_p
,
17923 glyph
->right_box_line_p
);
17925 else if (glyph
->type
== IMAGE_GLYPH
)
17928 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17929 glyph
- row
->glyphs
[TEXT_AREA
],
17932 (BUFFERP (glyph
->object
)
17934 : (STRINGP (glyph
->object
)
17936 : (INTEGERP (glyph
->object
)
17939 glyph
->pixel_width
,
17943 glyph
->left_box_line_p
,
17944 glyph
->right_box_line_p
);
17946 else if (glyph
->type
== COMPOSITE_GLYPH
)
17949 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17950 glyph
- row
->glyphs
[TEXT_AREA
],
17953 (BUFFERP (glyph
->object
)
17955 : (STRINGP (glyph
->object
)
17957 : (INTEGERP (glyph
->object
)
17960 glyph
->pixel_width
,
17962 if (glyph
->u
.cmp
.automatic
)
17965 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17966 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17968 glyph
->left_box_line_p
,
17969 glyph
->right_box_line_p
);
17974 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17975 GLYPHS 0 means don't show glyph contents.
17976 GLYPHS 1 means show glyphs in short form
17977 GLYPHS > 1 means show glyphs in long form. */
17980 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17984 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17985 fprintf (stderr
, "==============================================================================\n");
17987 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17988 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17990 MATRIX_ROW_START_CHARPOS (row
),
17991 MATRIX_ROW_END_CHARPOS (row
),
17992 row
->used
[TEXT_AREA
],
17993 row
->contains_overlapping_glyphs_p
,
17995 row
->truncated_on_left_p
,
17996 row
->truncated_on_right_p
,
17998 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17999 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18002 row
->ends_in_middle_of_char_p
,
18003 row
->starts_in_middle_of_char_p
,
18009 row
->visible_height
,
18012 /* The next 3 lines should align to "Start" in the header. */
18013 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18014 row
->end
.overlay_string_index
,
18015 row
->continuation_lines_width
);
18016 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18017 CHARPOS (row
->start
.string_pos
),
18018 CHARPOS (row
->end
.string_pos
));
18019 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18020 row
->end
.dpvec_index
);
18027 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18029 struct glyph
*glyph
= row
->glyphs
[area
];
18030 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18032 /* Glyph for a line end in text. */
18033 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18036 if (glyph
< glyph_end
)
18037 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18039 for (; glyph
< glyph_end
; ++glyph
)
18040 dump_glyph (row
, glyph
, area
);
18043 else if (glyphs
== 1)
18047 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18049 char *s
= alloca (row
->used
[area
] + 4);
18052 for (i
= 0; i
< row
->used
[area
]; ++i
)
18054 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18055 if (i
== row
->used
[area
] - 1
18056 && area
== TEXT_AREA
18057 && INTEGERP (glyph
->object
)
18058 && glyph
->type
== CHAR_GLYPH
18059 && glyph
->u
.ch
== ' ')
18061 strcpy (&s
[i
], "[\\n]");
18064 else if (glyph
->type
== CHAR_GLYPH
18065 && glyph
->u
.ch
< 0x80
18066 && glyph
->u
.ch
>= ' ')
18067 s
[i
] = glyph
->u
.ch
;
18073 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18079 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18080 Sdump_glyph_matrix
, 0, 1, "p",
18081 doc
: /* Dump the current matrix of the selected window to stderr.
18082 Shows contents of glyph row structures. With non-nil
18083 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18084 glyphs in short form, otherwise show glyphs in long form. */)
18085 (Lisp_Object glyphs
)
18087 struct window
*w
= XWINDOW (selected_window
);
18088 struct buffer
*buffer
= XBUFFER (w
->contents
);
18090 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18091 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18092 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18093 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18094 fprintf (stderr
, "=============================================\n");
18095 dump_glyph_matrix (w
->current_matrix
,
18096 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18101 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18102 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18105 struct frame
*f
= XFRAME (selected_frame
);
18106 dump_glyph_matrix (f
->current_matrix
, 1);
18111 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18112 doc
: /* Dump glyph row ROW to stderr.
18113 GLYPH 0 means don't dump glyphs.
18114 GLYPH 1 means dump glyphs in short form.
18115 GLYPH > 1 or omitted means dump glyphs in long form. */)
18116 (Lisp_Object row
, Lisp_Object glyphs
)
18118 struct glyph_matrix
*matrix
;
18121 CHECK_NUMBER (row
);
18122 matrix
= XWINDOW (selected_window
)->current_matrix
;
18124 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18125 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18127 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18132 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18133 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18134 GLYPH 0 means don't dump glyphs.
18135 GLYPH 1 means dump glyphs in short form.
18136 GLYPH > 1 or omitted means dump glyphs in long form.
18138 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18140 (Lisp_Object row
, Lisp_Object glyphs
)
18142 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18143 struct frame
*sf
= SELECTED_FRAME ();
18144 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18147 CHECK_NUMBER (row
);
18149 if (vpos
>= 0 && vpos
< m
->nrows
)
18150 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18151 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18157 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18158 doc
: /* Toggle tracing of redisplay.
18159 With ARG, turn tracing on if and only if ARG is positive. */)
18163 trace_redisplay_p
= !trace_redisplay_p
;
18166 arg
= Fprefix_numeric_value (arg
);
18167 trace_redisplay_p
= XINT (arg
) > 0;
18174 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18175 doc
: /* Like `format', but print result to stderr.
18176 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18177 (ptrdiff_t nargs
, Lisp_Object
*args
)
18179 Lisp_Object s
= Fformat (nargs
, args
);
18180 fprintf (stderr
, "%s", SDATA (s
));
18184 #endif /* GLYPH_DEBUG */
18188 /***********************************************************************
18189 Building Desired Matrix Rows
18190 ***********************************************************************/
18192 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18193 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18195 static struct glyph_row
*
18196 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18198 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18199 struct buffer
*buffer
= XBUFFER (w
->contents
);
18200 struct buffer
*old
= current_buffer
;
18201 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18202 int arrow_len
= SCHARS (overlay_arrow_string
);
18203 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18204 const unsigned char *p
;
18207 int n_glyphs_before
;
18209 set_buffer_temp (buffer
);
18210 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18211 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18212 SET_TEXT_POS (it
.position
, 0, 0);
18214 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18216 while (p
< arrow_end
)
18218 Lisp_Object face
, ilisp
;
18220 /* Get the next character. */
18222 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18225 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18226 if (! ASCII_CHAR_P (it
.c
))
18227 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18231 /* Get its face. */
18232 ilisp
= make_number (p
- arrow_string
);
18233 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18234 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18236 /* Compute its width, get its glyphs. */
18237 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18238 SET_TEXT_POS (it
.position
, -1, -1);
18239 PRODUCE_GLYPHS (&it
);
18241 /* If this character doesn't fit any more in the line, we have
18242 to remove some glyphs. */
18243 if (it
.current_x
> it
.last_visible_x
)
18245 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18250 set_buffer_temp (old
);
18251 return it
.glyph_row
;
18255 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18256 glyphs to insert is determined by produce_special_glyphs. */
18259 insert_left_trunc_glyphs (struct it
*it
)
18261 struct it truncate_it
;
18262 struct glyph
*from
, *end
, *to
, *toend
;
18264 eassert (!FRAME_WINDOW_P (it
->f
)
18265 || (!it
->glyph_row
->reversed_p
18266 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18267 || (it
->glyph_row
->reversed_p
18268 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18270 /* Get the truncation glyphs. */
18272 truncate_it
.current_x
= 0;
18273 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18274 truncate_it
.glyph_row
= &scratch_glyph_row
;
18275 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18276 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18277 truncate_it
.object
= make_number (0);
18278 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18280 /* Overwrite glyphs from IT with truncation glyphs. */
18281 if (!it
->glyph_row
->reversed_p
)
18283 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18285 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18286 end
= from
+ tused
;
18287 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18288 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18289 if (FRAME_WINDOW_P (it
->f
))
18291 /* On GUI frames, when variable-size fonts are displayed,
18292 the truncation glyphs may need more pixels than the row's
18293 glyphs they overwrite. We overwrite more glyphs to free
18294 enough screen real estate, and enlarge the stretch glyph
18295 on the right (see display_line), if there is one, to
18296 preserve the screen position of the truncation glyphs on
18299 struct glyph
*g
= to
;
18302 /* The first glyph could be partially visible, in which case
18303 it->glyph_row->x will be negative. But we want the left
18304 truncation glyphs to be aligned at the left margin of the
18305 window, so we override the x coordinate at which the row
18307 it
->glyph_row
->x
= 0;
18308 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18310 w
+= g
->pixel_width
;
18313 if (g
- to
- tused
> 0)
18315 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18316 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18318 used
= it
->glyph_row
->used
[TEXT_AREA
];
18319 if (it
->glyph_row
->truncated_on_right_p
18320 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18321 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18324 int extra
= w
- it
->truncation_pixel_width
;
18326 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18333 /* There may be padding glyphs left over. Overwrite them too. */
18334 if (!FRAME_WINDOW_P (it
->f
))
18336 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18338 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18345 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18349 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18351 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18352 that back to front. */
18353 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18354 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18355 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18356 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18357 if (FRAME_WINDOW_P (it
->f
))
18360 struct glyph
*g
= to
;
18362 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18364 w
+= g
->pixel_width
;
18367 if (to
- g
- tused
> 0)
18369 if (it
->glyph_row
->truncated_on_right_p
18370 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18371 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18373 int extra
= w
- it
->truncation_pixel_width
;
18375 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18379 while (from
>= end
&& to
>= toend
)
18381 if (!FRAME_WINDOW_P (it
->f
))
18383 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18386 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18387 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18388 while (from
>= end
&& to
>= toend
)
18394 /* Need to free some room before prepending additional
18396 int move_by
= from
- end
+ 1;
18397 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18398 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18400 for ( ; g
>= g0
; g
--)
18402 while (from
>= end
)
18404 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18409 /* Compute the hash code for ROW. */
18411 row_hash (struct glyph_row
*row
)
18414 unsigned hashval
= 0;
18416 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18417 for (k
= 0; k
< row
->used
[area
]; ++k
)
18418 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18419 + row
->glyphs
[area
][k
].u
.val
18420 + row
->glyphs
[area
][k
].face_id
18421 + row
->glyphs
[area
][k
].padding_p
18422 + (row
->glyphs
[area
][k
].type
<< 2));
18427 /* Compute the pixel height and width of IT->glyph_row.
18429 Most of the time, ascent and height of a display line will be equal
18430 to the max_ascent and max_height values of the display iterator
18431 structure. This is not the case if
18433 1. We hit ZV without displaying anything. In this case, max_ascent
18434 and max_height will be zero.
18436 2. We have some glyphs that don't contribute to the line height.
18437 (The glyph row flag contributes_to_line_height_p is for future
18438 pixmap extensions).
18440 The first case is easily covered by using default values because in
18441 these cases, the line height does not really matter, except that it
18442 must not be zero. */
18445 compute_line_metrics (struct it
*it
)
18447 struct glyph_row
*row
= it
->glyph_row
;
18449 if (FRAME_WINDOW_P (it
->f
))
18451 int i
, min_y
, max_y
;
18453 /* The line may consist of one space only, that was added to
18454 place the cursor on it. If so, the row's height hasn't been
18456 if (row
->height
== 0)
18458 if (it
->max_ascent
+ it
->max_descent
== 0)
18459 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18460 row
->ascent
= it
->max_ascent
;
18461 row
->height
= it
->max_ascent
+ it
->max_descent
;
18462 row
->phys_ascent
= it
->max_phys_ascent
;
18463 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18464 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18467 /* Compute the width of this line. */
18468 row
->pixel_width
= row
->x
;
18469 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18470 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18472 eassert (row
->pixel_width
>= 0);
18473 eassert (row
->ascent
>= 0 && row
->height
> 0);
18475 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18476 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18478 /* If first line's physical ascent is larger than its logical
18479 ascent, use the physical ascent, and make the row taller.
18480 This makes accented characters fully visible. */
18481 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18482 && row
->phys_ascent
> row
->ascent
)
18484 row
->height
+= row
->phys_ascent
- row
->ascent
;
18485 row
->ascent
= row
->phys_ascent
;
18488 /* Compute how much of the line is visible. */
18489 row
->visible_height
= row
->height
;
18491 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18492 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18494 if (row
->y
< min_y
)
18495 row
->visible_height
-= min_y
- row
->y
;
18496 if (row
->y
+ row
->height
> max_y
)
18497 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18501 row
->pixel_width
= row
->used
[TEXT_AREA
];
18502 if (row
->continued_p
)
18503 row
->pixel_width
-= it
->continuation_pixel_width
;
18504 else if (row
->truncated_on_right_p
)
18505 row
->pixel_width
-= it
->truncation_pixel_width
;
18506 row
->ascent
= row
->phys_ascent
= 0;
18507 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18508 row
->extra_line_spacing
= 0;
18511 /* Compute a hash code for this row. */
18512 row
->hash
= row_hash (row
);
18514 it
->max_ascent
= it
->max_descent
= 0;
18515 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18519 /* Append one space to the glyph row of iterator IT if doing a
18520 window-based redisplay. The space has the same face as
18521 IT->face_id. Value is non-zero if a space was added.
18523 This function is called to make sure that there is always one glyph
18524 at the end of a glyph row that the cursor can be set on under
18525 window-systems. (If there weren't such a glyph we would not know
18526 how wide and tall a box cursor should be displayed).
18528 At the same time this space let's a nicely handle clearing to the
18529 end of the line if the row ends in italic text. */
18532 append_space_for_newline (struct it
*it
, int default_face_p
)
18534 if (FRAME_WINDOW_P (it
->f
))
18536 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18538 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18539 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18541 /* Save some values that must not be changed.
18542 Must save IT->c and IT->len because otherwise
18543 ITERATOR_AT_END_P wouldn't work anymore after
18544 append_space_for_newline has been called. */
18545 enum display_element_type saved_what
= it
->what
;
18546 int saved_c
= it
->c
, saved_len
= it
->len
;
18547 int saved_char_to_display
= it
->char_to_display
;
18548 int saved_x
= it
->current_x
;
18549 int saved_face_id
= it
->face_id
;
18550 int saved_box_end
= it
->end_of_box_run_p
;
18551 struct text_pos saved_pos
;
18552 Lisp_Object saved_object
;
18555 saved_object
= it
->object
;
18556 saved_pos
= it
->position
;
18558 it
->what
= IT_CHARACTER
;
18559 memset (&it
->position
, 0, sizeof it
->position
);
18560 it
->object
= make_number (0);
18561 it
->c
= it
->char_to_display
= ' ';
18564 /* If the default face was remapped, be sure to use the
18565 remapped face for the appended newline. */
18566 if (default_face_p
)
18567 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18568 else if (it
->face_before_selective_p
)
18569 it
->face_id
= it
->saved_face_id
;
18570 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18571 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18572 /* In R2L rows, we will prepend a stretch glyph that will
18573 have the end_of_box_run_p flag set for it, so there's no
18574 need for the appended newline glyph to have that flag
18576 if (it
->glyph_row
->reversed_p
18577 /* But if the appended newline glyph goes all the way to
18578 the end of the row, there will be no stretch glyph,
18579 so leave the box flag set. */
18580 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18581 it
->end_of_box_run_p
= 0;
18583 PRODUCE_GLYPHS (it
);
18585 it
->override_ascent
= -1;
18586 it
->constrain_row_ascent_descent_p
= 0;
18587 it
->current_x
= saved_x
;
18588 it
->object
= saved_object
;
18589 it
->position
= saved_pos
;
18590 it
->what
= saved_what
;
18591 it
->face_id
= saved_face_id
;
18592 it
->len
= saved_len
;
18594 it
->char_to_display
= saved_char_to_display
;
18595 it
->end_of_box_run_p
= saved_box_end
;
18604 /* Extend the face of the last glyph in the text area of IT->glyph_row
18605 to the end of the display line. Called from display_line. If the
18606 glyph row is empty, add a space glyph to it so that we know the
18607 face to draw. Set the glyph row flag fill_line_p. If the glyph
18608 row is R2L, prepend a stretch glyph to cover the empty space to the
18609 left of the leftmost glyph. */
18612 extend_face_to_end_of_line (struct it
*it
)
18614 struct face
*face
, *default_face
;
18615 struct frame
*f
= it
->f
;
18617 /* If line is already filled, do nothing. Non window-system frames
18618 get a grace of one more ``pixel'' because their characters are
18619 1-``pixel'' wide, so they hit the equality too early. This grace
18620 is needed only for R2L rows that are not continued, to produce
18621 one extra blank where we could display the cursor. */
18622 if (it
->current_x
>= it
->last_visible_x
18623 + (!FRAME_WINDOW_P (f
)
18624 && it
->glyph_row
->reversed_p
18625 && !it
->glyph_row
->continued_p
))
18628 /* The default face, possibly remapped. */
18629 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18631 /* Face extension extends the background and box of IT->face_id
18632 to the end of the line. If the background equals the background
18633 of the frame, we don't have to do anything. */
18634 if (it
->face_before_selective_p
)
18635 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18637 face
= FACE_FROM_ID (f
, it
->face_id
);
18639 if (FRAME_WINDOW_P (f
)
18640 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18641 && face
->box
== FACE_NO_BOX
18642 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18643 #ifdef HAVE_WINDOW_SYSTEM
18646 && !it
->glyph_row
->reversed_p
)
18649 /* Set the glyph row flag indicating that the face of the last glyph
18650 in the text area has to be drawn to the end of the text area. */
18651 it
->glyph_row
->fill_line_p
= 1;
18653 /* If current character of IT is not ASCII, make sure we have the
18654 ASCII face. This will be automatically undone the next time
18655 get_next_display_element returns a multibyte character. Note
18656 that the character will always be single byte in unibyte
18658 if (!ASCII_CHAR_P (it
->c
))
18660 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18663 if (FRAME_WINDOW_P (f
))
18665 /* If the row is empty, add a space with the current face of IT,
18666 so that we know which face to draw. */
18667 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18669 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18670 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18671 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18673 #ifdef HAVE_WINDOW_SYSTEM
18674 if (it
->glyph_row
->reversed_p
)
18676 /* Prepend a stretch glyph to the row, such that the
18677 rightmost glyph will be drawn flushed all the way to the
18678 right margin of the window. The stretch glyph that will
18679 occupy the empty space, if any, to the left of the
18681 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18682 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18683 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18685 int row_width
, stretch_ascent
, stretch_width
;
18686 struct text_pos saved_pos
;
18687 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18689 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18690 row_width
+= g
->pixel_width
;
18691 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18692 if (stretch_width
> 0)
18695 (((it
->ascent
+ it
->descent
)
18696 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18697 saved_pos
= it
->position
;
18698 memset (&it
->position
, 0, sizeof it
->position
);
18699 saved_avoid_cursor
= it
->avoid_cursor_p
;
18700 it
->avoid_cursor_p
= 1;
18701 saved_face_id
= it
->face_id
;
18702 saved_box_start
= it
->start_of_box_run_p
;
18703 /* The last row's stretch glyph should get the default
18704 face, to avoid painting the rest of the window with
18705 the region face, if the region ends at ZV. */
18706 if (it
->glyph_row
->ends_at_zv_p
)
18707 it
->face_id
= default_face
->id
;
18709 it
->face_id
= face
->id
;
18710 it
->start_of_box_run_p
= 0;
18711 append_stretch_glyph (it
, make_number (0), stretch_width
,
18712 it
->ascent
+ it
->descent
, stretch_ascent
);
18713 it
->position
= saved_pos
;
18714 it
->avoid_cursor_p
= saved_avoid_cursor
;
18715 it
->face_id
= saved_face_id
;
18716 it
->start_of_box_run_p
= saved_box_start
;
18719 #endif /* HAVE_WINDOW_SYSTEM */
18723 /* Save some values that must not be changed. */
18724 int saved_x
= it
->current_x
;
18725 struct text_pos saved_pos
;
18726 Lisp_Object saved_object
;
18727 enum display_element_type saved_what
= it
->what
;
18728 int saved_face_id
= it
->face_id
;
18730 saved_object
= it
->object
;
18731 saved_pos
= it
->position
;
18733 it
->what
= IT_CHARACTER
;
18734 memset (&it
->position
, 0, sizeof it
->position
);
18735 it
->object
= make_number (0);
18736 it
->c
= it
->char_to_display
= ' ';
18738 /* The last row's blank glyphs should get the default face, to
18739 avoid painting the rest of the window with the region face,
18740 if the region ends at ZV. */
18741 if (it
->glyph_row
->ends_at_zv_p
)
18742 it
->face_id
= default_face
->id
;
18744 it
->face_id
= face
->id
;
18746 PRODUCE_GLYPHS (it
);
18748 while (it
->current_x
<= it
->last_visible_x
)
18749 PRODUCE_GLYPHS (it
);
18751 /* Don't count these blanks really. It would let us insert a left
18752 truncation glyph below and make us set the cursor on them, maybe. */
18753 it
->current_x
= saved_x
;
18754 it
->object
= saved_object
;
18755 it
->position
= saved_pos
;
18756 it
->what
= saved_what
;
18757 it
->face_id
= saved_face_id
;
18762 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18763 trailing whitespace. */
18766 trailing_whitespace_p (ptrdiff_t charpos
)
18768 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18771 while (bytepos
< ZV_BYTE
18772 && (c
= FETCH_CHAR (bytepos
),
18773 c
== ' ' || c
== '\t'))
18776 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18778 if (bytepos
!= PT_BYTE
)
18785 /* Highlight trailing whitespace, if any, in ROW. */
18788 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18790 int used
= row
->used
[TEXT_AREA
];
18794 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18795 struct glyph
*glyph
= start
+ used
- 1;
18797 if (row
->reversed_p
)
18799 /* Right-to-left rows need to be processed in the opposite
18800 direction, so swap the edge pointers. */
18802 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18805 /* Skip over glyphs inserted to display the cursor at the
18806 end of a line, for extending the face of the last glyph
18807 to the end of the line on terminals, and for truncation
18808 and continuation glyphs. */
18809 if (!row
->reversed_p
)
18811 while (glyph
>= start
18812 && glyph
->type
== CHAR_GLYPH
18813 && INTEGERP (glyph
->object
))
18818 while (glyph
<= start
18819 && glyph
->type
== CHAR_GLYPH
18820 && INTEGERP (glyph
->object
))
18824 /* If last glyph is a space or stretch, and it's trailing
18825 whitespace, set the face of all trailing whitespace glyphs in
18826 IT->glyph_row to `trailing-whitespace'. */
18827 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18828 && BUFFERP (glyph
->object
)
18829 && (glyph
->type
== STRETCH_GLYPH
18830 || (glyph
->type
== CHAR_GLYPH
18831 && glyph
->u
.ch
== ' '))
18832 && trailing_whitespace_p (glyph
->charpos
))
18834 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18838 if (!row
->reversed_p
)
18840 while (glyph
>= start
18841 && BUFFERP (glyph
->object
)
18842 && (glyph
->type
== STRETCH_GLYPH
18843 || (glyph
->type
== CHAR_GLYPH
18844 && glyph
->u
.ch
== ' ')))
18845 (glyph
--)->face_id
= face_id
;
18849 while (glyph
<= start
18850 && BUFFERP (glyph
->object
)
18851 && (glyph
->type
== STRETCH_GLYPH
18852 || (glyph
->type
== CHAR_GLYPH
18853 && glyph
->u
.ch
== ' ')))
18854 (glyph
++)->face_id
= face_id
;
18861 /* Value is non-zero if glyph row ROW should be
18862 considered to hold the buffer position CHARPOS. */
18865 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18869 if (charpos
== CHARPOS (row
->end
.pos
)
18870 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18872 /* Suppose the row ends on a string.
18873 Unless the row is continued, that means it ends on a newline
18874 in the string. If it's anything other than a display string
18875 (e.g., a before-string from an overlay), we don't want the
18876 cursor there. (This heuristic seems to give the optimal
18877 behavior for the various types of multi-line strings.)
18878 One exception: if the string has `cursor' property on one of
18879 its characters, we _do_ want the cursor there. */
18880 if (CHARPOS (row
->end
.string_pos
) >= 0)
18882 if (row
->continued_p
)
18886 /* Check for `display' property. */
18887 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18888 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18889 struct glyph
*glyph
;
18892 for (glyph
= end
; glyph
>= beg
; --glyph
)
18893 if (STRINGP (glyph
->object
))
18896 = Fget_char_property (make_number (charpos
),
18900 && display_prop_string_p (prop
, glyph
->object
));
18901 /* If there's a `cursor' property on one of the
18902 string's characters, this row is a cursor row,
18903 even though this is not a display string. */
18906 Lisp_Object s
= glyph
->object
;
18908 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18910 ptrdiff_t gpos
= glyph
->charpos
;
18912 if (!NILP (Fget_char_property (make_number (gpos
),
18924 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18926 /* If the row ends in middle of a real character,
18927 and the line is continued, we want the cursor here.
18928 That's because CHARPOS (ROW->end.pos) would equal
18929 PT if PT is before the character. */
18930 if (!row
->ends_in_ellipsis_p
)
18931 result
= row
->continued_p
;
18933 /* If the row ends in an ellipsis, then
18934 CHARPOS (ROW->end.pos) will equal point after the
18935 invisible text. We want that position to be displayed
18936 after the ellipsis. */
18939 /* If the row ends at ZV, display the cursor at the end of that
18940 row instead of at the start of the row below. */
18941 else if (row
->ends_at_zv_p
)
18950 /* Value is non-zero if glyph row ROW should be
18951 used to hold the cursor. */
18954 cursor_row_p (struct glyph_row
*row
)
18956 return row_for_charpos_p (row
, PT
);
18961 /* Push the property PROP so that it will be rendered at the current
18962 position in IT. Return 1 if PROP was successfully pushed, 0
18963 otherwise. Called from handle_line_prefix to handle the
18964 `line-prefix' and `wrap-prefix' properties. */
18967 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18969 struct text_pos pos
=
18970 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18972 eassert (it
->method
== GET_FROM_BUFFER
18973 || it
->method
== GET_FROM_DISPLAY_VECTOR
18974 || it
->method
== GET_FROM_STRING
);
18976 /* We need to save the current buffer/string position, so it will be
18977 restored by pop_it, because iterate_out_of_display_property
18978 depends on that being set correctly, but some situations leave
18979 it->position not yet set when this function is called. */
18980 push_it (it
, &pos
);
18982 if (STRINGP (prop
))
18984 if (SCHARS (prop
) == 0)
18991 it
->string_from_prefix_prop_p
= 1;
18992 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18993 it
->current
.overlay_string_index
= -1;
18994 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18995 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18996 it
->method
= GET_FROM_STRING
;
18997 it
->stop_charpos
= 0;
18999 it
->base_level_stop
= 0;
19001 /* Force paragraph direction to be that of the parent
19003 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19004 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19006 it
->paragraph_embedding
= L2R
;
19008 /* Set up the bidi iterator for this display string. */
19011 it
->bidi_it
.string
.lstring
= it
->string
;
19012 it
->bidi_it
.string
.s
= NULL
;
19013 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19014 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19015 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19016 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19017 it
->bidi_it
.w
= it
->w
;
19018 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19021 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19023 it
->method
= GET_FROM_STRETCH
;
19026 #ifdef HAVE_WINDOW_SYSTEM
19027 else if (IMAGEP (prop
))
19029 it
->what
= IT_IMAGE
;
19030 it
->image_id
= lookup_image (it
->f
, prop
);
19031 it
->method
= GET_FROM_IMAGE
;
19033 #endif /* HAVE_WINDOW_SYSTEM */
19036 pop_it (it
); /* bogus display property, give up */
19043 /* Return the character-property PROP at the current position in IT. */
19046 get_it_property (struct it
*it
, Lisp_Object prop
)
19048 Lisp_Object position
, object
= it
->object
;
19050 if (STRINGP (object
))
19051 position
= make_number (IT_STRING_CHARPOS (*it
));
19052 else if (BUFFERP (object
))
19054 position
= make_number (IT_CHARPOS (*it
));
19055 object
= it
->window
;
19060 return Fget_char_property (position
, prop
, object
);
19063 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19066 handle_line_prefix (struct it
*it
)
19068 Lisp_Object prefix
;
19070 if (it
->continuation_lines_width
> 0)
19072 prefix
= get_it_property (it
, Qwrap_prefix
);
19074 prefix
= Vwrap_prefix
;
19078 prefix
= get_it_property (it
, Qline_prefix
);
19080 prefix
= Vline_prefix
;
19082 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19084 /* If the prefix is wider than the window, and we try to wrap
19085 it, it would acquire its own wrap prefix, and so on till the
19086 iterator stack overflows. So, don't wrap the prefix. */
19087 it
->line_wrap
= TRUNCATE
;
19088 it
->avoid_cursor_p
= 1;
19094 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19095 only for R2L lines from display_line and display_string, when they
19096 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19097 the line/string needs to be continued on the next glyph row. */
19099 unproduce_glyphs (struct it
*it
, int n
)
19101 struct glyph
*glyph
, *end
;
19103 eassert (it
->glyph_row
);
19104 eassert (it
->glyph_row
->reversed_p
);
19105 eassert (it
->area
== TEXT_AREA
);
19106 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19108 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19109 n
= it
->glyph_row
->used
[TEXT_AREA
];
19110 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19111 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19112 for ( ; glyph
< end
; glyph
++)
19113 glyph
[-n
] = *glyph
;
19116 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19117 and ROW->maxpos. */
19119 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19120 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19121 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19123 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19124 lines' rows is implemented for bidi-reordered rows. */
19126 /* ROW->minpos is the value of min_pos, the minimal buffer position
19127 we have in ROW, or ROW->start.pos if that is smaller. */
19128 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19129 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19131 /* We didn't find buffer positions smaller than ROW->start, or
19132 didn't find _any_ valid buffer positions in any of the glyphs,
19133 so we must trust the iterator's computed positions. */
19134 row
->minpos
= row
->start
.pos
;
19137 max_pos
= CHARPOS (it
->current
.pos
);
19138 max_bpos
= BYTEPOS (it
->current
.pos
);
19141 /* Here are the various use-cases for ending the row, and the
19142 corresponding values for ROW->maxpos:
19144 Line ends in a newline from buffer eol_pos + 1
19145 Line is continued from buffer max_pos + 1
19146 Line is truncated on right it->current.pos
19147 Line ends in a newline from string max_pos + 1(*)
19148 (*) + 1 only when line ends in a forward scan
19149 Line is continued from string max_pos
19150 Line is continued from display vector max_pos
19151 Line is entirely from a string min_pos == max_pos
19152 Line is entirely from a display vector min_pos == max_pos
19153 Line that ends at ZV ZV
19155 If you discover other use-cases, please add them here as
19157 if (row
->ends_at_zv_p
)
19158 row
->maxpos
= it
->current
.pos
;
19159 else if (row
->used
[TEXT_AREA
])
19161 int seen_this_string
= 0;
19162 struct glyph_row
*r1
= row
- 1;
19164 /* Did we see the same display string on the previous row? */
19165 if (STRINGP (it
->object
)
19166 /* this is not the first row */
19167 && row
> it
->w
->desired_matrix
->rows
19168 /* previous row is not the header line */
19169 && !r1
->mode_line_p
19170 /* previous row also ends in a newline from a string */
19171 && r1
->ends_in_newline_from_string_p
)
19173 struct glyph
*start
, *end
;
19175 /* Search for the last glyph of the previous row that came
19176 from buffer or string. Depending on whether the row is
19177 L2R or R2L, we need to process it front to back or the
19178 other way round. */
19179 if (!r1
->reversed_p
)
19181 start
= r1
->glyphs
[TEXT_AREA
];
19182 end
= start
+ r1
->used
[TEXT_AREA
];
19183 /* Glyphs inserted by redisplay have an integer (zero)
19184 as their object. */
19186 && INTEGERP ((end
- 1)->object
)
19187 && (end
- 1)->charpos
<= 0)
19191 if (EQ ((end
- 1)->object
, it
->object
))
19192 seen_this_string
= 1;
19195 /* If all the glyphs of the previous row were inserted
19196 by redisplay, it means the previous row was
19197 produced from a single newline, which is only
19198 possible if that newline came from the same string
19199 as the one which produced this ROW. */
19200 seen_this_string
= 1;
19204 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19205 start
= end
+ r1
->used
[TEXT_AREA
];
19207 && INTEGERP ((end
+ 1)->object
)
19208 && (end
+ 1)->charpos
<= 0)
19212 if (EQ ((end
+ 1)->object
, it
->object
))
19213 seen_this_string
= 1;
19216 seen_this_string
= 1;
19219 /* Take note of each display string that covers a newline only
19220 once, the first time we see it. This is for when a display
19221 string includes more than one newline in it. */
19222 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19224 /* If we were scanning the buffer forward when we displayed
19225 the string, we want to account for at least one buffer
19226 position that belongs to this row (position covered by
19227 the display string), so that cursor positioning will
19228 consider this row as a candidate when point is at the end
19229 of the visual line represented by this row. This is not
19230 required when scanning back, because max_pos will already
19231 have a much larger value. */
19232 if (CHARPOS (row
->end
.pos
) > max_pos
)
19233 INC_BOTH (max_pos
, max_bpos
);
19234 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19236 else if (CHARPOS (it
->eol_pos
) > 0)
19237 SET_TEXT_POS (row
->maxpos
,
19238 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19239 else if (row
->continued_p
)
19241 /* If max_pos is different from IT's current position, it
19242 means IT->method does not belong to the display element
19243 at max_pos. However, it also means that the display
19244 element at max_pos was displayed in its entirety on this
19245 line, which is equivalent to saying that the next line
19246 starts at the next buffer position. */
19247 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19248 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19251 INC_BOTH (max_pos
, max_bpos
);
19252 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19255 else if (row
->truncated_on_right_p
)
19256 /* display_line already called reseat_at_next_visible_line_start,
19257 which puts the iterator at the beginning of the next line, in
19258 the logical order. */
19259 row
->maxpos
= it
->current
.pos
;
19260 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19261 /* A line that is entirely from a string/image/stretch... */
19262 row
->maxpos
= row
->minpos
;
19267 row
->maxpos
= it
->current
.pos
;
19270 /* Construct the glyph row IT->glyph_row in the desired matrix of
19271 IT->w from text at the current position of IT. See dispextern.h
19272 for an overview of struct it. Value is non-zero if
19273 IT->glyph_row displays text, as opposed to a line displaying ZV
19277 display_line (struct it
*it
)
19279 struct glyph_row
*row
= it
->glyph_row
;
19280 Lisp_Object overlay_arrow_string
;
19282 void *wrap_data
= NULL
;
19283 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19284 int wrap_row_used
= -1;
19285 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19286 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19287 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19288 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19289 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19291 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19292 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19294 /* We always start displaying at hpos zero even if hscrolled. */
19295 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19297 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19298 >= it
->w
->desired_matrix
->nrows
)
19300 it
->w
->nrows_scale_factor
++;
19301 it
->f
->fonts_changed
= 1;
19305 /* Clear the result glyph row and enable it. */
19306 prepare_desired_row (row
);
19308 row
->y
= it
->current_y
;
19309 row
->start
= it
->start
;
19310 row
->continuation_lines_width
= it
->continuation_lines_width
;
19311 row
->displays_text_p
= 1;
19312 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19313 it
->starts_in_middle_of_char_p
= 0;
19315 /* Arrange the overlays nicely for our purposes. Usually, we call
19316 display_line on only one line at a time, in which case this
19317 can't really hurt too much, or we call it on lines which appear
19318 one after another in the buffer, in which case all calls to
19319 recenter_overlay_lists but the first will be pretty cheap. */
19320 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19322 /* Move over display elements that are not visible because we are
19323 hscrolled. This may stop at an x-position < IT->first_visible_x
19324 if the first glyph is partially visible or if we hit a line end. */
19325 if (it
->current_x
< it
->first_visible_x
)
19327 enum move_it_result move_result
;
19329 this_line_min_pos
= row
->start
.pos
;
19330 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19331 MOVE_TO_POS
| MOVE_TO_X
);
19332 /* If we are under a large hscroll, move_it_in_display_line_to
19333 could hit the end of the line without reaching
19334 it->first_visible_x. Pretend that we did reach it. This is
19335 especially important on a TTY, where we will call
19336 extend_face_to_end_of_line, which needs to know how many
19337 blank glyphs to produce. */
19338 if (it
->current_x
< it
->first_visible_x
19339 && (move_result
== MOVE_NEWLINE_OR_CR
19340 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19341 it
->current_x
= it
->first_visible_x
;
19343 /* Record the smallest positions seen while we moved over
19344 display elements that are not visible. This is needed by
19345 redisplay_internal for optimizing the case where the cursor
19346 stays inside the same line. The rest of this function only
19347 considers positions that are actually displayed, so
19348 RECORD_MAX_MIN_POS will not otherwise record positions that
19349 are hscrolled to the left of the left edge of the window. */
19350 min_pos
= CHARPOS (this_line_min_pos
);
19351 min_bpos
= BYTEPOS (this_line_min_pos
);
19355 /* We only do this when not calling `move_it_in_display_line_to'
19356 above, because move_it_in_display_line_to calls
19357 handle_line_prefix itself. */
19358 handle_line_prefix (it
);
19361 /* Get the initial row height. This is either the height of the
19362 text hscrolled, if there is any, or zero. */
19363 row
->ascent
= it
->max_ascent
;
19364 row
->height
= it
->max_ascent
+ it
->max_descent
;
19365 row
->phys_ascent
= it
->max_phys_ascent
;
19366 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19367 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19369 /* Utility macro to record max and min buffer positions seen until now. */
19370 #define RECORD_MAX_MIN_POS(IT) \
19373 int composition_p = !STRINGP ((IT)->string) \
19374 && ((IT)->what == IT_COMPOSITION); \
19375 ptrdiff_t current_pos = \
19376 composition_p ? (IT)->cmp_it.charpos \
19377 : IT_CHARPOS (*(IT)); \
19378 ptrdiff_t current_bpos = \
19379 composition_p ? CHAR_TO_BYTE (current_pos) \
19380 : IT_BYTEPOS (*(IT)); \
19381 if (current_pos < min_pos) \
19383 min_pos = current_pos; \
19384 min_bpos = current_bpos; \
19386 if (IT_CHARPOS (*it) > max_pos) \
19388 max_pos = IT_CHARPOS (*it); \
19389 max_bpos = IT_BYTEPOS (*it); \
19394 /* Loop generating characters. The loop is left with IT on the next
19395 character to display. */
19398 int n_glyphs_before
, hpos_before
, x_before
;
19400 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19402 /* Retrieve the next thing to display. Value is zero if end of
19404 if (!get_next_display_element (it
))
19406 /* Maybe add a space at the end of this line that is used to
19407 display the cursor there under X. Set the charpos of the
19408 first glyph of blank lines not corresponding to any text
19410 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19411 row
->exact_window_width_line_p
= 1;
19412 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19413 || row
->used
[TEXT_AREA
] == 0)
19415 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19416 row
->displays_text_p
= 0;
19418 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19419 && (!MINI_WINDOW_P (it
->w
)
19420 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19421 row
->indicate_empty_line_p
= 1;
19424 it
->continuation_lines_width
= 0;
19425 row
->ends_at_zv_p
= 1;
19426 /* A row that displays right-to-left text must always have
19427 its last face extended all the way to the end of line,
19428 even if this row ends in ZV, because we still write to
19429 the screen left to right. We also need to extend the
19430 last face if the default face is remapped to some
19431 different face, otherwise the functions that clear
19432 portions of the screen will clear with the default face's
19433 background color. */
19434 if (row
->reversed_p
19435 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19436 extend_face_to_end_of_line (it
);
19440 /* Now, get the metrics of what we want to display. This also
19441 generates glyphs in `row' (which is IT->glyph_row). */
19442 n_glyphs_before
= row
->used
[TEXT_AREA
];
19445 /* Remember the line height so far in case the next element doesn't
19446 fit on the line. */
19447 if (it
->line_wrap
!= TRUNCATE
)
19449 ascent
= it
->max_ascent
;
19450 descent
= it
->max_descent
;
19451 phys_ascent
= it
->max_phys_ascent
;
19452 phys_descent
= it
->max_phys_descent
;
19454 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19456 if (IT_DISPLAYING_WHITESPACE (it
))
19460 SAVE_IT (wrap_it
, *it
, wrap_data
);
19462 wrap_row_used
= row
->used
[TEXT_AREA
];
19463 wrap_row_ascent
= row
->ascent
;
19464 wrap_row_height
= row
->height
;
19465 wrap_row_phys_ascent
= row
->phys_ascent
;
19466 wrap_row_phys_height
= row
->phys_height
;
19467 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19468 wrap_row_min_pos
= min_pos
;
19469 wrap_row_min_bpos
= min_bpos
;
19470 wrap_row_max_pos
= max_pos
;
19471 wrap_row_max_bpos
= max_bpos
;
19477 PRODUCE_GLYPHS (it
);
19479 /* If this display element was in marginal areas, continue with
19481 if (it
->area
!= TEXT_AREA
)
19483 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19484 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19485 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19486 row
->phys_height
= max (row
->phys_height
,
19487 it
->max_phys_ascent
+ it
->max_phys_descent
);
19488 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19489 it
->max_extra_line_spacing
);
19490 set_iterator_to_next (it
, 1);
19494 /* Does the display element fit on the line? If we truncate
19495 lines, we should draw past the right edge of the window. If
19496 we don't truncate, we want to stop so that we can display the
19497 continuation glyph before the right margin. If lines are
19498 continued, there are two possible strategies for characters
19499 resulting in more than 1 glyph (e.g. tabs): Display as many
19500 glyphs as possible in this line and leave the rest for the
19501 continuation line, or display the whole element in the next
19502 line. Original redisplay did the former, so we do it also. */
19503 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19504 hpos_before
= it
->hpos
;
19507 if (/* Not a newline. */
19509 /* Glyphs produced fit entirely in the line. */
19510 && it
->current_x
< it
->last_visible_x
)
19512 it
->hpos
+= nglyphs
;
19513 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19514 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19515 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19516 row
->phys_height
= max (row
->phys_height
,
19517 it
->max_phys_ascent
+ it
->max_phys_descent
);
19518 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19519 it
->max_extra_line_spacing
);
19520 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19521 row
->x
= x
- it
->first_visible_x
;
19522 /* Record the maximum and minimum buffer positions seen so
19523 far in glyphs that will be displayed by this row. */
19525 RECORD_MAX_MIN_POS (it
);
19530 struct glyph
*glyph
;
19532 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19534 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19535 new_x
= x
+ glyph
->pixel_width
;
19537 if (/* Lines are continued. */
19538 it
->line_wrap
!= TRUNCATE
19539 && (/* Glyph doesn't fit on the line. */
19540 new_x
> it
->last_visible_x
19541 /* Or it fits exactly on a window system frame. */
19542 || (new_x
== it
->last_visible_x
19543 && FRAME_WINDOW_P (it
->f
)
19544 && (row
->reversed_p
19545 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19546 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19548 /* End of a continued line. */
19551 || (new_x
== it
->last_visible_x
19552 && FRAME_WINDOW_P (it
->f
)
19553 && (row
->reversed_p
19554 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19555 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19557 /* Current glyph is the only one on the line or
19558 fits exactly on the line. We must continue
19559 the line because we can't draw the cursor
19560 after the glyph. */
19561 row
->continued_p
= 1;
19562 it
->current_x
= new_x
;
19563 it
->continuation_lines_width
+= new_x
;
19565 if (i
== nglyphs
- 1)
19567 /* If line-wrap is on, check if a previous
19568 wrap point was found. */
19569 if (wrap_row_used
> 0
19570 /* Even if there is a previous wrap
19571 point, continue the line here as
19572 usual, if (i) the previous character
19573 was a space or tab AND (ii) the
19574 current character is not. */
19576 || IT_DISPLAYING_WHITESPACE (it
)))
19579 /* Record the maximum and minimum buffer
19580 positions seen so far in glyphs that will be
19581 displayed by this row. */
19583 RECORD_MAX_MIN_POS (it
);
19584 set_iterator_to_next (it
, 1);
19585 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19587 if (!get_next_display_element (it
))
19589 row
->exact_window_width_line_p
= 1;
19590 it
->continuation_lines_width
= 0;
19591 row
->continued_p
= 0;
19592 row
->ends_at_zv_p
= 1;
19594 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19596 row
->continued_p
= 0;
19597 row
->exact_window_width_line_p
= 1;
19601 else if (it
->bidi_p
)
19602 RECORD_MAX_MIN_POS (it
);
19604 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19605 && !FRAME_WINDOW_P (it
->f
))
19607 /* A padding glyph that doesn't fit on this line.
19608 This means the whole character doesn't fit
19610 if (row
->reversed_p
)
19611 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19612 - n_glyphs_before
);
19613 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19615 /* Fill the rest of the row with continuation
19616 glyphs like in 20.x. */
19617 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19618 < row
->glyphs
[1 + TEXT_AREA
])
19619 produce_special_glyphs (it
, IT_CONTINUATION
);
19621 row
->continued_p
= 1;
19622 it
->current_x
= x_before
;
19623 it
->continuation_lines_width
+= x_before
;
19625 /* Restore the height to what it was before the
19626 element not fitting on the line. */
19627 it
->max_ascent
= ascent
;
19628 it
->max_descent
= descent
;
19629 it
->max_phys_ascent
= phys_ascent
;
19630 it
->max_phys_descent
= phys_descent
;
19632 else if (wrap_row_used
> 0)
19635 if (row
->reversed_p
)
19636 unproduce_glyphs (it
,
19637 row
->used
[TEXT_AREA
] - wrap_row_used
);
19638 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19639 it
->continuation_lines_width
+= wrap_x
;
19640 row
->used
[TEXT_AREA
] = wrap_row_used
;
19641 row
->ascent
= wrap_row_ascent
;
19642 row
->height
= wrap_row_height
;
19643 row
->phys_ascent
= wrap_row_phys_ascent
;
19644 row
->phys_height
= wrap_row_phys_height
;
19645 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19646 min_pos
= wrap_row_min_pos
;
19647 min_bpos
= wrap_row_min_bpos
;
19648 max_pos
= wrap_row_max_pos
;
19649 max_bpos
= wrap_row_max_bpos
;
19650 row
->continued_p
= 1;
19651 row
->ends_at_zv_p
= 0;
19652 row
->exact_window_width_line_p
= 0;
19653 it
->continuation_lines_width
+= x
;
19655 /* Make sure that a non-default face is extended
19656 up to the right margin of the window. */
19657 extend_face_to_end_of_line (it
);
19659 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19661 /* A TAB that extends past the right edge of the
19662 window. This produces a single glyph on
19663 window system frames. We leave the glyph in
19664 this row and let it fill the row, but don't
19665 consume the TAB. */
19666 if ((row
->reversed_p
19667 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19668 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19669 produce_special_glyphs (it
, IT_CONTINUATION
);
19670 it
->continuation_lines_width
+= it
->last_visible_x
;
19671 row
->ends_in_middle_of_char_p
= 1;
19672 row
->continued_p
= 1;
19673 glyph
->pixel_width
= it
->last_visible_x
- x
;
19674 it
->starts_in_middle_of_char_p
= 1;
19678 /* Something other than a TAB that draws past
19679 the right edge of the window. Restore
19680 positions to values before the element. */
19681 if (row
->reversed_p
)
19682 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19683 - (n_glyphs_before
+ i
));
19684 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19686 /* Display continuation glyphs. */
19687 it
->current_x
= x_before
;
19688 it
->continuation_lines_width
+= x
;
19689 if (!FRAME_WINDOW_P (it
->f
)
19690 || (row
->reversed_p
19691 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19692 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19693 produce_special_glyphs (it
, IT_CONTINUATION
);
19694 row
->continued_p
= 1;
19696 extend_face_to_end_of_line (it
);
19698 if (nglyphs
> 1 && i
> 0)
19700 row
->ends_in_middle_of_char_p
= 1;
19701 it
->starts_in_middle_of_char_p
= 1;
19704 /* Restore the height to what it was before the
19705 element not fitting on the line. */
19706 it
->max_ascent
= ascent
;
19707 it
->max_descent
= descent
;
19708 it
->max_phys_ascent
= phys_ascent
;
19709 it
->max_phys_descent
= phys_descent
;
19714 else if (new_x
> it
->first_visible_x
)
19716 /* Increment number of glyphs actually displayed. */
19719 /* Record the maximum and minimum buffer positions
19720 seen so far in glyphs that will be displayed by
19723 RECORD_MAX_MIN_POS (it
);
19725 if (x
< it
->first_visible_x
)
19726 /* Glyph is partially visible, i.e. row starts at
19727 negative X position. */
19728 row
->x
= x
- it
->first_visible_x
;
19732 /* Glyph is completely off the left margin of the
19733 window. This should not happen because of the
19734 move_it_in_display_line at the start of this
19735 function, unless the text display area of the
19736 window is empty. */
19737 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19740 /* Even if this display element produced no glyphs at all,
19741 we want to record its position. */
19742 if (it
->bidi_p
&& nglyphs
== 0)
19743 RECORD_MAX_MIN_POS (it
);
19745 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19746 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19747 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19748 row
->phys_height
= max (row
->phys_height
,
19749 it
->max_phys_ascent
+ it
->max_phys_descent
);
19750 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19751 it
->max_extra_line_spacing
);
19753 /* End of this display line if row is continued. */
19754 if (row
->continued_p
|| row
->ends_at_zv_p
)
19759 /* Is this a line end? If yes, we're also done, after making
19760 sure that a non-default face is extended up to the right
19761 margin of the window. */
19762 if (ITERATOR_AT_END_OF_LINE_P (it
))
19764 int used_before
= row
->used
[TEXT_AREA
];
19766 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19768 /* Add a space at the end of the line that is used to
19769 display the cursor there. */
19770 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19771 append_space_for_newline (it
, 0);
19773 /* Extend the face to the end of the line. */
19774 extend_face_to_end_of_line (it
);
19776 /* Make sure we have the position. */
19777 if (used_before
== 0)
19778 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19780 /* Record the position of the newline, for use in
19782 it
->eol_pos
= it
->current
.pos
;
19784 /* Consume the line end. This skips over invisible lines. */
19785 set_iterator_to_next (it
, 1);
19786 it
->continuation_lines_width
= 0;
19790 /* Proceed with next display element. Note that this skips
19791 over lines invisible because of selective display. */
19792 set_iterator_to_next (it
, 1);
19794 /* If we truncate lines, we are done when the last displayed
19795 glyphs reach past the right margin of the window. */
19796 if (it
->line_wrap
== TRUNCATE
19797 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19798 ? (it
->current_x
>= it
->last_visible_x
)
19799 : (it
->current_x
> it
->last_visible_x
)))
19801 /* Maybe add truncation glyphs. */
19802 if (!FRAME_WINDOW_P (it
->f
)
19803 || (row
->reversed_p
19804 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19805 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19809 if (!row
->reversed_p
)
19811 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19812 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19817 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19818 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19820 /* Remove any padding glyphs at the front of ROW, to
19821 make room for the truncation glyphs we will be
19822 adding below. The loop below always inserts at
19823 least one truncation glyph, so also remove the
19824 last glyph added to ROW. */
19825 unproduce_glyphs (it
, i
+ 1);
19826 /* Adjust i for the loop below. */
19827 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19830 it
->current_x
= x_before
;
19831 if (!FRAME_WINDOW_P (it
->f
))
19833 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19835 row
->used
[TEXT_AREA
] = i
;
19836 produce_special_glyphs (it
, IT_TRUNCATION
);
19841 row
->used
[TEXT_AREA
] = i
;
19842 produce_special_glyphs (it
, IT_TRUNCATION
);
19845 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19847 /* Don't truncate if we can overflow newline into fringe. */
19848 if (!get_next_display_element (it
))
19850 it
->continuation_lines_width
= 0;
19851 row
->ends_at_zv_p
= 1;
19852 row
->exact_window_width_line_p
= 1;
19855 if (ITERATOR_AT_END_OF_LINE_P (it
))
19857 row
->exact_window_width_line_p
= 1;
19858 goto at_end_of_line
;
19860 it
->current_x
= x_before
;
19863 row
->truncated_on_right_p
= 1;
19864 it
->continuation_lines_width
= 0;
19865 reseat_at_next_visible_line_start (it
, 0);
19866 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19867 it
->hpos
= hpos_before
;
19873 bidi_unshelve_cache (wrap_data
, 1);
19875 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19876 at the left window margin. */
19877 if (it
->first_visible_x
19878 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19880 if (!FRAME_WINDOW_P (it
->f
)
19881 || (row
->reversed_p
19882 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19883 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19884 insert_left_trunc_glyphs (it
);
19885 row
->truncated_on_left_p
= 1;
19888 /* Remember the position at which this line ends.
19890 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19891 cannot be before the call to find_row_edges below, since that is
19892 where these positions are determined. */
19893 row
->end
= it
->current
;
19896 row
->minpos
= row
->start
.pos
;
19897 row
->maxpos
= row
->end
.pos
;
19901 /* ROW->minpos and ROW->maxpos must be the smallest and
19902 `1 + the largest' buffer positions in ROW. But if ROW was
19903 bidi-reordered, these two positions can be anywhere in the
19904 row, so we must determine them now. */
19905 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19908 /* If the start of this line is the overlay arrow-position, then
19909 mark this glyph row as the one containing the overlay arrow.
19910 This is clearly a mess with variable size fonts. It would be
19911 better to let it be displayed like cursors under X. */
19912 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19913 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19914 !NILP (overlay_arrow_string
)))
19916 /* Overlay arrow in window redisplay is a fringe bitmap. */
19917 if (STRINGP (overlay_arrow_string
))
19919 struct glyph_row
*arrow_row
19920 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19921 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19922 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19923 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19924 struct glyph
*p2
, *end
;
19926 /* Copy the arrow glyphs. */
19927 while (glyph
< arrow_end
)
19930 /* Throw away padding glyphs. */
19932 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19933 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19939 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19944 eassert (INTEGERP (overlay_arrow_string
));
19945 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19947 overlay_arrow_seen
= 1;
19950 /* Highlight trailing whitespace. */
19951 if (!NILP (Vshow_trailing_whitespace
))
19952 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19954 /* Compute pixel dimensions of this line. */
19955 compute_line_metrics (it
);
19957 /* Implementation note: No changes in the glyphs of ROW or in their
19958 faces can be done past this point, because compute_line_metrics
19959 computes ROW's hash value and stores it within the glyph_row
19962 /* Record whether this row ends inside an ellipsis. */
19963 row
->ends_in_ellipsis_p
19964 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19965 && it
->ellipsis_p
);
19967 /* Save fringe bitmaps in this row. */
19968 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19969 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19970 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19971 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19973 it
->left_user_fringe_bitmap
= 0;
19974 it
->left_user_fringe_face_id
= 0;
19975 it
->right_user_fringe_bitmap
= 0;
19976 it
->right_user_fringe_face_id
= 0;
19978 /* Maybe set the cursor. */
19979 cvpos
= it
->w
->cursor
.vpos
;
19981 /* In bidi-reordered rows, keep checking for proper cursor
19982 position even if one has been found already, because buffer
19983 positions in such rows change non-linearly with ROW->VPOS,
19984 when a line is continued. One exception: when we are at ZV,
19985 display cursor on the first suitable glyph row, since all
19986 the empty rows after that also have their position set to ZV. */
19987 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19988 lines' rows is implemented for bidi-reordered rows. */
19990 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19991 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19992 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19993 && cursor_row_p (row
))
19994 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19996 /* Prepare for the next line. This line starts horizontally at (X
19997 HPOS) = (0 0). Vertical positions are incremented. As a
19998 convenience for the caller, IT->glyph_row is set to the next
20000 it
->current_x
= it
->hpos
= 0;
20001 it
->current_y
+= row
->height
;
20002 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20005 /* The next row should by default use the same value of the
20006 reversed_p flag as this one. set_iterator_to_next decides when
20007 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20008 the flag accordingly. */
20009 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20010 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20011 it
->start
= row
->end
;
20012 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20014 #undef RECORD_MAX_MIN_POS
20017 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20018 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20019 doc
: /* Return paragraph direction at point in BUFFER.
20020 Value is either `left-to-right' or `right-to-left'.
20021 If BUFFER is omitted or nil, it defaults to the current buffer.
20023 Paragraph direction determines how the text in the paragraph is displayed.
20024 In left-to-right paragraphs, text begins at the left margin of the window
20025 and the reading direction is generally left to right. In right-to-left
20026 paragraphs, text begins at the right margin and is read from right to left.
20028 See also `bidi-paragraph-direction'. */)
20029 (Lisp_Object buffer
)
20031 struct buffer
*buf
= current_buffer
;
20032 struct buffer
*old
= buf
;
20034 if (! NILP (buffer
))
20036 CHECK_BUFFER (buffer
);
20037 buf
= XBUFFER (buffer
);
20040 if (NILP (BVAR (buf
, bidi_display_reordering
))
20041 || NILP (BVAR (buf
, enable_multibyte_characters
))
20042 /* When we are loading loadup.el, the character property tables
20043 needed for bidi iteration are not yet available. */
20044 || !NILP (Vpurify_flag
))
20045 return Qleft_to_right
;
20046 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20047 return BVAR (buf
, bidi_paragraph_direction
);
20050 /* Determine the direction from buffer text. We could try to
20051 use current_matrix if it is up to date, but this seems fast
20052 enough as it is. */
20053 struct bidi_it itb
;
20054 ptrdiff_t pos
= BUF_PT (buf
);
20055 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20057 void *itb_data
= bidi_shelve_cache ();
20059 set_buffer_temp (buf
);
20060 /* bidi_paragraph_init finds the base direction of the paragraph
20061 by searching forward from paragraph start. We need the base
20062 direction of the current or _previous_ paragraph, so we need
20063 to make sure we are within that paragraph. To that end, find
20064 the previous non-empty line. */
20065 if (pos
>= ZV
&& pos
> BEGV
)
20066 DEC_BOTH (pos
, bytepos
);
20067 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20068 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20070 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20071 || c
== ' ' || c
== '\t' || c
== '\f')
20073 if (bytepos
<= BEGV_BYTE
)
20078 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20081 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20082 itb
.paragraph_dir
= NEUTRAL_DIR
;
20083 itb
.string
.s
= NULL
;
20084 itb
.string
.lstring
= Qnil
;
20085 itb
.string
.bufpos
= 0;
20086 itb
.string
.unibyte
= 0;
20087 /* We have no window to use here for ignoring window-specific
20088 overlays. Using NULL for window pointer will cause
20089 compute_display_string_pos to use the current buffer. */
20091 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20092 bidi_unshelve_cache (itb_data
, 0);
20093 set_buffer_temp (old
);
20094 switch (itb
.paragraph_dir
)
20097 return Qleft_to_right
;
20100 return Qright_to_left
;
20108 DEFUN ("move-point-visually", Fmove_point_visually
,
20109 Smove_point_visually
, 1, 1, 0,
20110 doc
: /* Move point in the visual order in the specified DIRECTION.
20111 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20114 Value is the new character position of point. */)
20115 (Lisp_Object direction
)
20117 struct window
*w
= XWINDOW (selected_window
);
20118 struct buffer
*b
= XBUFFER (w
->contents
);
20119 struct glyph_row
*row
;
20121 Lisp_Object paragraph_dir
;
20123 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20124 (!(ROW)->continued_p \
20125 && INTEGERP ((GLYPH)->object) \
20126 && (GLYPH)->type == CHAR_GLYPH \
20127 && (GLYPH)->u.ch == ' ' \
20128 && (GLYPH)->charpos >= 0 \
20129 && !(GLYPH)->avoid_cursor_p)
20131 CHECK_NUMBER (direction
);
20132 dir
= XINT (direction
);
20138 /* If current matrix is up-to-date, we can use the information
20139 recorded in the glyphs, at least as long as the goal is on the
20141 if (w
->window_end_valid
20142 && !windows_or_buffers_changed
20144 && !b
->clip_changed
20145 && !b
->prevent_redisplay_optimizations_p
20146 && !window_outdated (w
)
20147 && w
->cursor
.vpos
>= 0
20148 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20149 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20151 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20152 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20153 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20155 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20157 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20159 SET_PT (g
->charpos
);
20160 w
->cursor
.vpos
= -1;
20161 return make_number (PT
);
20163 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20167 if (BUFFERP (gpt
->object
))
20170 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20171 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20173 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20175 else if (BUFFERP (g
->object
))
20176 new_pos
= g
->charpos
;
20180 w
->cursor
.vpos
= -1;
20181 return make_number (PT
);
20183 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20185 /* Glyphs inserted at the end of a non-empty line for
20186 positioning the cursor have zero charpos, so we must
20187 deduce the value of point by other means. */
20188 if (g
->charpos
> 0)
20189 SET_PT (g
->charpos
);
20190 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20192 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20193 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20196 w
->cursor
.vpos
= -1;
20197 return make_number (PT
);
20200 if (g
== e
|| INTEGERP (g
->object
))
20202 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20203 goto simulate_display
;
20204 if (!row
->reversed_p
)
20208 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20209 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20210 goto simulate_display
;
20214 if (row
->reversed_p
&& !row
->continued_p
)
20216 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20217 w
->cursor
.vpos
= -1;
20218 return make_number (PT
);
20220 g
= row
->glyphs
[TEXT_AREA
];
20221 e
= g
+ row
->used
[TEXT_AREA
];
20222 for ( ; g
< e
; g
++)
20224 if (BUFFERP (g
->object
)
20225 /* Empty lines have only one glyph, which stands
20226 for the newline, and whose charpos is the
20227 buffer position of the newline. */
20228 || ROW_GLYPH_NEWLINE_P (row
, g
)
20229 /* When the buffer ends in a newline, the line at
20230 EOB also has one glyph, but its charpos is -1. */
20231 || (row
->ends_at_zv_p
20232 && !row
->reversed_p
20233 && INTEGERP (g
->object
)
20234 && g
->type
== CHAR_GLYPH
20235 && g
->u
.ch
== ' '))
20237 if (g
->charpos
> 0)
20238 SET_PT (g
->charpos
);
20239 else if (!row
->reversed_p
20240 && row
->ends_at_zv_p
20245 w
->cursor
.vpos
= -1;
20246 return make_number (PT
);
20252 if (!row
->reversed_p
&& !row
->continued_p
)
20254 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20255 w
->cursor
.vpos
= -1;
20256 return make_number (PT
);
20258 e
= row
->glyphs
[TEXT_AREA
];
20259 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20260 for ( ; g
>= e
; g
--)
20262 if (BUFFERP (g
->object
)
20263 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20265 /* Empty R2L lines on GUI frames have the buffer
20266 position of the newline stored in the stretch
20268 || g
->type
== STRETCH_GLYPH
20269 || (row
->ends_at_zv_p
20271 && INTEGERP (g
->object
)
20272 && g
->type
== CHAR_GLYPH
20273 && g
->u
.ch
== ' '))
20275 if (g
->charpos
> 0)
20276 SET_PT (g
->charpos
);
20277 else if (row
->reversed_p
20278 && row
->ends_at_zv_p
20283 w
->cursor
.vpos
= -1;
20284 return make_number (PT
);
20293 /* If we wind up here, we failed to move by using the glyphs, so we
20294 need to simulate display instead. */
20297 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20299 paragraph_dir
= Qleft_to_right
;
20300 if (EQ (paragraph_dir
, Qright_to_left
))
20302 if (PT
<= BEGV
&& dir
< 0)
20303 xsignal0 (Qbeginning_of_buffer
);
20304 else if (PT
>= ZV
&& dir
> 0)
20305 xsignal0 (Qend_of_buffer
);
20308 struct text_pos pt
;
20310 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20312 bool overshoot_expected
= false;
20313 bool target_is_eol_p
= false;
20315 /* Setup the arena. */
20316 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20317 start_display (&it
, w
, pt
);
20319 if (it
.cmp_it
.id
< 0
20320 && it
.method
== GET_FROM_STRING
20321 && it
.area
== TEXT_AREA
20322 && it
.string_from_display_prop_p
20323 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20324 overshoot_expected
= true;
20326 /* Find the X coordinate of point. We start from the beginning
20327 of this or previous line to make sure we are before point in
20328 the logical order (since the move_it_* functions can only
20330 reseat_at_previous_visible_line_start (&it
);
20331 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20332 if (IT_CHARPOS (it
) != PT
)
20333 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20334 -1, -1, -1, MOVE_TO_POS
);
20335 pt_x
= it
.current_x
;
20337 if (dir
> 0 || overshoot_expected
)
20339 struct glyph_row
*row
= it
.glyph_row
;
20341 /* When point is at beginning of line, we don't have
20342 information about the glyph there loaded into struct
20343 it. Calling get_next_display_element fixes that. */
20345 get_next_display_element (&it
);
20346 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20347 it
.glyph_row
= NULL
;
20348 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20349 it
.glyph_row
= row
;
20350 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20351 it, lest it will become out of sync with it's buffer
20353 it
.current_x
= pt_x
;
20356 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20357 pixel_width
= it
.pixel_width
;
20358 if (overshoot_expected
&& at_eol_p
)
20360 else if (pixel_width
<= 0)
20363 /* If there's a display string at point, we are actually at the
20364 glyph to the left of point, so we need to correct the X
20366 if (overshoot_expected
)
20367 pt_x
+= pixel_width
;
20369 /* Compute target X coordinate, either to the left or to the
20370 right of point. On TTY frames, all characters have the same
20371 pixel width of 1, so we can use that. On GUI frames we don't
20372 have an easy way of getting at the pixel width of the
20373 character to the left of point, so we use a different method
20374 of getting to that place. */
20376 target_x
= pt_x
+ pixel_width
;
20378 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20380 /* Target X coordinate could be one line above or below the line
20381 of point, in which case we need to adjust the target X
20382 coordinate. Also, if moving to the left, we need to begin at
20383 the left edge of the point's screen line. */
20388 start_display (&it
, w
, pt
);
20389 reseat_at_previous_visible_line_start (&it
);
20390 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20392 move_it_by_lines (&it
, pt_vpos
);
20396 move_it_by_lines (&it
, -1);
20397 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20398 target_is_eol_p
= true;
20404 || (target_x
>= it
.last_visible_x
20405 && it
.line_wrap
!= TRUNCATE
))
20408 move_it_by_lines (&it
, 0);
20409 move_it_by_lines (&it
, 1);
20414 /* Move to the target X coordinate. */
20415 #ifdef HAVE_WINDOW_SYSTEM
20416 /* On GUI frames, as we don't know the X coordinate of the
20417 character to the left of point, moving point to the left
20418 requires walking, one grapheme cluster at a time, until we
20419 find ourself at a place immediately to the left of the
20420 character at point. */
20421 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20423 struct text_pos new_pos
= it
.current
.pos
;
20424 enum move_it_result rc
= MOVE_X_REACHED
;
20426 while (it
.current_x
+ it
.pixel_width
<= target_x
20427 && rc
== MOVE_X_REACHED
)
20429 int new_x
= it
.current_x
+ it
.pixel_width
;
20431 new_pos
= it
.current
.pos
;
20432 if (new_x
== it
.current_x
)
20434 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20435 MOVE_TO_POS
| MOVE_TO_X
);
20436 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20439 /* If we ended up on a composed character inside
20440 bidi-reordered text (e.g., Hebrew text with diacritics),
20441 the iterator gives us the buffer position of the last (in
20442 logical order) character of the composed grapheme cluster,
20443 which is not what we want. So we cheat: we compute the
20444 character position of the character that follows (in the
20445 logical order) the one where the above loop stopped. That
20446 character will appear on display to the left of point. */
20448 && it
.bidi_it
.scan_dir
== -1
20449 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20451 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20452 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20454 it
.current
.pos
= new_pos
;
20458 if (it
.current_x
!= target_x
)
20459 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20461 /* When lines are truncated, the above loop will stop at the
20462 window edge. But we want to get to the end of line, even if
20463 it is beyond the window edge; automatic hscroll will then
20464 scroll the window to show point as appropriate. */
20465 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20466 && get_next_display_element (&it
))
20468 struct text_pos new_pos
= it
.current
.pos
;
20470 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20472 set_iterator_to_next (&it
, 0);
20473 if (it
.method
== GET_FROM_BUFFER
)
20474 new_pos
= it
.current
.pos
;
20475 if (!get_next_display_element (&it
))
20479 it
.current
.pos
= new_pos
;
20482 /* If we ended up in a display string that covers point, move to
20483 buffer position to the right in the visual order. */
20486 while (IT_CHARPOS (it
) == PT
)
20488 set_iterator_to_next (&it
, 0);
20489 if (!get_next_display_element (&it
))
20494 /* Move point to that position. */
20495 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20498 return make_number (PT
);
20500 #undef ROW_GLYPH_NEWLINE_P
20504 /***********************************************************************
20506 ***********************************************************************/
20508 /* Redisplay the menu bar in the frame for window W.
20510 The menu bar of X frames that don't have X toolkit support is
20511 displayed in a special window W->frame->menu_bar_window.
20513 The menu bar of terminal frames is treated specially as far as
20514 glyph matrices are concerned. Menu bar lines are not part of
20515 windows, so the update is done directly on the frame matrix rows
20516 for the menu bar. */
20519 display_menu_bar (struct window
*w
)
20521 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20526 /* Don't do all this for graphical frames. */
20528 if (FRAME_W32_P (f
))
20531 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20537 if (FRAME_NS_P (f
))
20539 #endif /* HAVE_NS */
20541 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20542 eassert (!FRAME_WINDOW_P (f
));
20543 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20544 it
.first_visible_x
= 0;
20545 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20546 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20547 if (FRAME_WINDOW_P (f
))
20549 /* Menu bar lines are displayed in the desired matrix of the
20550 dummy window menu_bar_window. */
20551 struct window
*menu_w
;
20552 menu_w
= XWINDOW (f
->menu_bar_window
);
20553 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20555 it
.first_visible_x
= 0;
20556 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20559 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20561 /* This is a TTY frame, i.e. character hpos/vpos are used as
20563 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20565 it
.first_visible_x
= 0;
20566 it
.last_visible_x
= FRAME_COLS (f
);
20569 /* FIXME: This should be controlled by a user option. See the
20570 comments in redisplay_tool_bar and display_mode_line about
20572 it
.paragraph_embedding
= L2R
;
20574 /* Clear all rows of the menu bar. */
20575 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20577 struct glyph_row
*row
= it
.glyph_row
+ i
;
20578 clear_glyph_row (row
);
20579 row
->enabled_p
= 1;
20580 row
->full_width_p
= 1;
20583 /* Display all items of the menu bar. */
20584 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20585 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20587 Lisp_Object string
;
20589 /* Stop at nil string. */
20590 string
= AREF (items
, i
+ 1);
20594 /* Remember where item was displayed. */
20595 ASET (items
, i
+ 3, make_number (it
.hpos
));
20597 /* Display the item, pad with one space. */
20598 if (it
.current_x
< it
.last_visible_x
)
20599 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20600 SCHARS (string
) + 1, 0, 0, -1);
20603 /* Fill out the line with spaces. */
20604 if (it
.current_x
< it
.last_visible_x
)
20605 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20607 /* Compute the total height of the lines. */
20608 compute_line_metrics (&it
);
20611 /* Deep copy of a glyph row, including the glyphs. */
20613 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20615 struct glyph
*pointers
[1 + LAST_AREA
];
20616 int to_used
= to
->used
[TEXT_AREA
];
20618 /* Save glyph pointers of TO. */
20619 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20621 /* Do a structure assignment. */
20624 /* Restore original glyph pointers of TO. */
20625 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20627 /* Copy the glyphs. */
20628 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20629 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20631 /* If we filled only part of the TO row, fill the rest with
20632 space_glyph (which will display as empty space). */
20633 if (to_used
> from
->used
[TEXT_AREA
])
20634 fill_up_frame_row_with_spaces (to
, to_used
);
20637 /* Display one menu item on a TTY, by overwriting the glyphs in the
20638 frame F's desired glyph matrix with glyphs produced from the menu
20639 item text. Called from term.c to display TTY drop-down menus one
20642 ITEM_TEXT is the menu item text as a C string.
20644 FACE_ID is the face ID to be used for this menu item. FACE_ID
20645 could specify one of 3 faces: a face for an enabled item, a face
20646 for a disabled item, or a face for a selected item.
20648 X and Y are coordinates of the first glyph in the frame's desired
20649 matrix to be overwritten by the menu item. Since this is a TTY, Y
20650 is the zero-based number of the glyph row and X is the zero-based
20651 glyph number in the row, starting from left, where to start
20652 displaying the item.
20654 SUBMENU non-zero means this menu item drops down a submenu, which
20655 should be indicated by displaying a proper visual cue after the
20659 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20660 int x
, int y
, int submenu
)
20663 struct frame
*f
= SELECTED_FRAME ();
20664 struct window
*w
= XWINDOW (f
->selected_window
);
20665 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20666 struct glyph_row
*row
;
20667 size_t item_len
= strlen (item_text
);
20669 eassert (FRAME_TERMCAP_P (f
));
20671 /* Don't write beyond the matrix's last row. This can happen for
20672 TTY screens that are not high enough to show the entire menu.
20673 (This is actually a bit of defensive programming, as
20674 tty_menu_display already limits the number of menu items to one
20675 less than the number of screen lines.) */
20676 if (y
>= f
->desired_matrix
->nrows
)
20679 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20680 it
.first_visible_x
= 0;
20681 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20682 row
= it
.glyph_row
;
20683 /* Start with the row contents from the current matrix. */
20684 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20685 saved_width
= row
->full_width_p
;
20686 row
->full_width_p
= 1;
20687 saved_reversed
= row
->reversed_p
;
20688 row
->reversed_p
= 0;
20689 row
->enabled_p
= 1;
20691 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20693 eassert (x
< f
->desired_matrix
->matrix_w
);
20694 it
.current_x
= it
.hpos
= x
;
20695 it
.current_y
= it
.vpos
= y
;
20696 saved_used
= row
->used
[TEXT_AREA
];
20697 saved_truncated
= row
->truncated_on_right_p
;
20698 row
->used
[TEXT_AREA
] = x
;
20699 it
.face_id
= face_id
;
20700 it
.line_wrap
= TRUNCATE
;
20702 /* FIXME: This should be controlled by a user option. See the
20703 comments in redisplay_tool_bar and display_mode_line about this.
20704 Also, if paragraph_embedding could ever be R2L, changes will be
20705 needed to avoid shifting to the right the row characters in
20706 term.c:append_glyph. */
20707 it
.paragraph_embedding
= L2R
;
20709 /* Pad with a space on the left. */
20710 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20712 /* Display the menu item, pad with spaces to WIDTH. */
20715 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20716 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20718 /* Indicate with " >" that there's a submenu. */
20719 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20720 FRAME_COLS (f
) - 1, -1);
20723 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20724 width
, 0, FRAME_COLS (f
) - 1, -1);
20726 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20727 row
->truncated_on_right_p
= saved_truncated
;
20728 row
->hash
= row_hash (row
);
20729 row
->full_width_p
= saved_width
;
20730 row
->reversed_p
= saved_reversed
;
20733 /***********************************************************************
20735 ***********************************************************************/
20737 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20738 FORCE is non-zero, redisplay mode lines unconditionally.
20739 Otherwise, redisplay only mode lines that are garbaged. Value is
20740 the number of windows whose mode lines were redisplayed. */
20743 redisplay_mode_lines (Lisp_Object window
, int force
)
20747 while (!NILP (window
))
20749 struct window
*w
= XWINDOW (window
);
20751 if (WINDOWP (w
->contents
))
20752 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20754 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20755 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20757 struct text_pos lpoint
;
20758 struct buffer
*old
= current_buffer
;
20760 /* Set the window's buffer for the mode line display. */
20761 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20762 set_buffer_internal_1 (XBUFFER (w
->contents
));
20764 /* Point refers normally to the selected window. For any
20765 other window, set up appropriate value. */
20766 if (!EQ (window
, selected_window
))
20768 struct text_pos pt
;
20770 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20771 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20774 /* Display mode lines. */
20775 clear_glyph_matrix (w
->desired_matrix
);
20776 if (display_mode_lines (w
))
20779 w
->must_be_updated_p
= 1;
20782 /* Restore old settings. */
20783 set_buffer_internal_1 (old
);
20784 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20794 /* Display the mode and/or header line of window W. Value is the
20795 sum number of mode lines and header lines displayed. */
20798 display_mode_lines (struct window
*w
)
20800 Lisp_Object old_selected_window
= selected_window
;
20801 Lisp_Object old_selected_frame
= selected_frame
;
20802 Lisp_Object new_frame
= w
->frame
;
20803 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20806 selected_frame
= new_frame
;
20807 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20808 or window's point, then we'd need select_window_1 here as well. */
20809 XSETWINDOW (selected_window
, w
);
20810 XFRAME (new_frame
)->selected_window
= selected_window
;
20812 /* These will be set while the mode line specs are processed. */
20813 line_number_displayed
= 0;
20814 w
->column_number_displayed
= -1;
20816 if (WINDOW_WANTS_MODELINE_P (w
))
20818 struct window
*sel_w
= XWINDOW (old_selected_window
);
20820 /* Select mode line face based on the real selected window. */
20821 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20822 BVAR (current_buffer
, mode_line_format
));
20826 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20828 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20829 BVAR (current_buffer
, header_line_format
));
20833 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20834 selected_frame
= old_selected_frame
;
20835 selected_window
= old_selected_window
;
20840 /* Display mode or header line of window W. FACE_ID specifies which
20841 line to display; it is either MODE_LINE_FACE_ID or
20842 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20843 display. Value is the pixel height of the mode/header line
20847 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20851 ptrdiff_t count
= SPECPDL_INDEX ();
20853 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20854 /* Don't extend on a previously drawn mode-line.
20855 This may happen if called from pos_visible_p. */
20856 it
.glyph_row
->enabled_p
= 0;
20857 prepare_desired_row (it
.glyph_row
);
20859 it
.glyph_row
->mode_line_p
= 1;
20861 /* FIXME: This should be controlled by a user option. But
20862 supporting such an option is not trivial, since the mode line is
20863 made up of many separate strings. */
20864 it
.paragraph_embedding
= L2R
;
20866 record_unwind_protect (unwind_format_mode_line
,
20867 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20869 mode_line_target
= MODE_LINE_DISPLAY
;
20871 /* Temporarily make frame's keyboard the current kboard so that
20872 kboard-local variables in the mode_line_format will get the right
20874 push_kboard (FRAME_KBOARD (it
.f
));
20875 record_unwind_save_match_data ();
20876 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20879 unbind_to (count
, Qnil
);
20881 /* Fill up with spaces. */
20882 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20884 compute_line_metrics (&it
);
20885 it
.glyph_row
->full_width_p
= 1;
20886 it
.glyph_row
->continued_p
= 0;
20887 it
.glyph_row
->truncated_on_left_p
= 0;
20888 it
.glyph_row
->truncated_on_right_p
= 0;
20890 /* Make a 3D mode-line have a shadow at its right end. */
20891 face
= FACE_FROM_ID (it
.f
, face_id
);
20892 extend_face_to_end_of_line (&it
);
20893 if (face
->box
!= FACE_NO_BOX
)
20895 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20896 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20897 last
->right_box_line_p
= 1;
20900 return it
.glyph_row
->height
;
20903 /* Move element ELT in LIST to the front of LIST.
20904 Return the updated list. */
20907 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20909 register Lisp_Object tail
, prev
;
20910 register Lisp_Object tem
;
20914 while (CONSP (tail
))
20920 /* Splice out the link TAIL. */
20922 list
= XCDR (tail
);
20924 Fsetcdr (prev
, XCDR (tail
));
20926 /* Now make it the first. */
20927 Fsetcdr (tail
, list
);
20932 tail
= XCDR (tail
);
20936 /* Not found--return unchanged LIST. */
20940 /* Contribute ELT to the mode line for window IT->w. How it
20941 translates into text depends on its data type.
20943 IT describes the display environment in which we display, as usual.
20945 DEPTH is the depth in recursion. It is used to prevent
20946 infinite recursion here.
20948 FIELD_WIDTH is the number of characters the display of ELT should
20949 occupy in the mode line, and PRECISION is the maximum number of
20950 characters to display from ELT's representation. See
20951 display_string for details.
20953 Returns the hpos of the end of the text generated by ELT.
20955 PROPS is a property list to add to any string we encounter.
20957 If RISKY is nonzero, remove (disregard) any properties in any string
20958 we encounter, and ignore :eval and :propertize.
20960 The global variable `mode_line_target' determines whether the
20961 output is passed to `store_mode_line_noprop',
20962 `store_mode_line_string', or `display_string'. */
20965 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20966 Lisp_Object elt
, Lisp_Object props
, int risky
)
20968 int n
= 0, field
, prec
;
20973 elt
= build_string ("*too-deep*");
20977 switch (XTYPE (elt
))
20981 /* A string: output it and check for %-constructs within it. */
20983 ptrdiff_t offset
= 0;
20985 if (SCHARS (elt
) > 0
20986 && (!NILP (props
) || risky
))
20988 Lisp_Object oprops
, aelt
;
20989 oprops
= Ftext_properties_at (make_number (0), elt
);
20991 /* If the starting string's properties are not what
20992 we want, translate the string. Also, if the string
20993 is risky, do that anyway. */
20995 if (NILP (Fequal (props
, oprops
)) || risky
)
20997 /* If the starting string has properties,
20998 merge the specified ones onto the existing ones. */
20999 if (! NILP (oprops
) && !risky
)
21003 oprops
= Fcopy_sequence (oprops
);
21005 while (CONSP (tem
))
21007 oprops
= Fplist_put (oprops
, XCAR (tem
),
21008 XCAR (XCDR (tem
)));
21009 tem
= XCDR (XCDR (tem
));
21014 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21015 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21017 /* AELT is what we want. Move it to the front
21018 without consing. */
21020 mode_line_proptrans_alist
21021 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21027 /* If AELT has the wrong props, it is useless.
21028 so get rid of it. */
21030 mode_line_proptrans_alist
21031 = Fdelq (aelt
, mode_line_proptrans_alist
);
21033 elt
= Fcopy_sequence (elt
);
21034 Fset_text_properties (make_number (0), Flength (elt
),
21036 /* Add this item to mode_line_proptrans_alist. */
21037 mode_line_proptrans_alist
21038 = Fcons (Fcons (elt
, props
),
21039 mode_line_proptrans_alist
);
21040 /* Truncate mode_line_proptrans_alist
21041 to at most 50 elements. */
21042 tem
= Fnthcdr (make_number (50),
21043 mode_line_proptrans_alist
);
21045 XSETCDR (tem
, Qnil
);
21054 prec
= precision
- n
;
21055 switch (mode_line_target
)
21057 case MODE_LINE_NOPROP
:
21058 case MODE_LINE_TITLE
:
21059 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21061 case MODE_LINE_STRING
:
21062 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21064 case MODE_LINE_DISPLAY
:
21065 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21066 0, prec
, 0, STRING_MULTIBYTE (elt
));
21073 /* Handle the non-literal case. */
21075 while ((precision
<= 0 || n
< precision
)
21076 && SREF (elt
, offset
) != 0
21077 && (mode_line_target
!= MODE_LINE_DISPLAY
21078 || it
->current_x
< it
->last_visible_x
))
21080 ptrdiff_t last_offset
= offset
;
21082 /* Advance to end of string or next format specifier. */
21083 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21086 if (offset
- 1 != last_offset
)
21088 ptrdiff_t nchars
, nbytes
;
21090 /* Output to end of string or up to '%'. Field width
21091 is length of string. Don't output more than
21092 PRECISION allows us. */
21095 prec
= c_string_width (SDATA (elt
) + last_offset
,
21096 offset
- last_offset
, precision
- n
,
21099 switch (mode_line_target
)
21101 case MODE_LINE_NOPROP
:
21102 case MODE_LINE_TITLE
:
21103 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21105 case MODE_LINE_STRING
:
21107 ptrdiff_t bytepos
= last_offset
;
21108 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21109 ptrdiff_t endpos
= (precision
<= 0
21110 ? string_byte_to_char (elt
, offset
)
21111 : charpos
+ nchars
);
21113 n
+= store_mode_line_string (NULL
,
21114 Fsubstring (elt
, make_number (charpos
),
21115 make_number (endpos
)),
21119 case MODE_LINE_DISPLAY
:
21121 ptrdiff_t bytepos
= last_offset
;
21122 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21124 if (precision
<= 0)
21125 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21126 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21128 STRING_MULTIBYTE (elt
));
21133 else /* c == '%' */
21135 ptrdiff_t percent_position
= offset
;
21137 /* Get the specified minimum width. Zero means
21140 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21141 field
= field
* 10 + c
- '0';
21143 /* Don't pad beyond the total padding allowed. */
21144 if (field_width
- n
> 0 && field
> field_width
- n
)
21145 field
= field_width
- n
;
21147 /* Note that either PRECISION <= 0 or N < PRECISION. */
21148 prec
= precision
- n
;
21151 n
+= display_mode_element (it
, depth
, field
, prec
,
21152 Vglobal_mode_string
, props
,
21157 ptrdiff_t bytepos
, charpos
;
21159 Lisp_Object string
;
21161 bytepos
= percent_position
;
21162 charpos
= (STRING_MULTIBYTE (elt
)
21163 ? string_byte_to_char (elt
, bytepos
)
21165 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21166 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21168 switch (mode_line_target
)
21170 case MODE_LINE_NOPROP
:
21171 case MODE_LINE_TITLE
:
21172 n
+= store_mode_line_noprop (spec
, field
, prec
);
21174 case MODE_LINE_STRING
:
21176 Lisp_Object tem
= build_string (spec
);
21177 props
= Ftext_properties_at (make_number (charpos
), elt
);
21178 /* Should only keep face property in props */
21179 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21182 case MODE_LINE_DISPLAY
:
21184 int nglyphs_before
, nwritten
;
21186 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21187 nwritten
= display_string (spec
, string
, elt
,
21192 /* Assign to the glyphs written above the
21193 string where the `%x' came from, position
21197 struct glyph
*glyph
21198 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21202 for (i
= 0; i
< nwritten
; ++i
)
21204 glyph
[i
].object
= elt
;
21205 glyph
[i
].charpos
= charpos
;
21222 /* A symbol: process the value of the symbol recursively
21223 as if it appeared here directly. Avoid error if symbol void.
21224 Special case: if value of symbol is a string, output the string
21227 register Lisp_Object tem
;
21229 /* If the variable is not marked as risky to set
21230 then its contents are risky to use. */
21231 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21234 tem
= Fboundp (elt
);
21237 tem
= Fsymbol_value (elt
);
21238 /* If value is a string, output that string literally:
21239 don't check for % within it. */
21243 if (!EQ (tem
, elt
))
21245 /* Give up right away for nil or t. */
21255 register Lisp_Object car
, tem
;
21257 /* A cons cell: five distinct cases.
21258 If first element is :eval or :propertize, do something special.
21259 If first element is a string or a cons, process all the elements
21260 and effectively concatenate them.
21261 If first element is a negative number, truncate displaying cdr to
21262 at most that many characters. If positive, pad (with spaces)
21263 to at least that many characters.
21264 If first element is a symbol, process the cadr or caddr recursively
21265 according to whether the symbol's value is non-nil or nil. */
21267 if (EQ (car
, QCeval
))
21269 /* An element of the form (:eval FORM) means evaluate FORM
21270 and use the result as mode line elements. */
21275 if (CONSP (XCDR (elt
)))
21278 spec
= safe_eval (XCAR (XCDR (elt
)));
21279 n
+= display_mode_element (it
, depth
, field_width
- n
,
21280 precision
- n
, spec
, props
,
21284 else if (EQ (car
, QCpropertize
))
21286 /* An element of the form (:propertize ELT PROPS...)
21287 means display ELT but applying properties PROPS. */
21292 if (CONSP (XCDR (elt
)))
21293 n
+= display_mode_element (it
, depth
, field_width
- n
,
21294 precision
- n
, XCAR (XCDR (elt
)),
21295 XCDR (XCDR (elt
)), risky
);
21297 else if (SYMBOLP (car
))
21299 tem
= Fboundp (car
);
21303 /* elt is now the cdr, and we know it is a cons cell.
21304 Use its car if CAR has a non-nil value. */
21307 tem
= Fsymbol_value (car
);
21314 /* Symbol's value is nil (or symbol is unbound)
21315 Get the cddr of the original list
21316 and if possible find the caddr and use that. */
21320 else if (!CONSP (elt
))
21325 else if (INTEGERP (car
))
21327 register int lim
= XINT (car
);
21331 /* Negative int means reduce maximum width. */
21332 if (precision
<= 0)
21335 precision
= min (precision
, -lim
);
21339 /* Padding specified. Don't let it be more than
21340 current maximum. */
21342 lim
= min (precision
, lim
);
21344 /* If that's more padding than already wanted, queue it.
21345 But don't reduce padding already specified even if
21346 that is beyond the current truncation point. */
21347 field_width
= max (lim
, field_width
);
21351 else if (STRINGP (car
) || CONSP (car
))
21353 Lisp_Object halftail
= elt
;
21357 && (precision
<= 0 || n
< precision
))
21359 n
+= display_mode_element (it
, depth
,
21360 /* Do padding only after the last
21361 element in the list. */
21362 (! CONSP (XCDR (elt
))
21365 precision
- n
, XCAR (elt
),
21369 if ((len
& 1) == 0)
21370 halftail
= XCDR (halftail
);
21371 /* Check for cycle. */
21372 if (EQ (halftail
, elt
))
21381 elt
= build_string ("*invalid*");
21385 /* Pad to FIELD_WIDTH. */
21386 if (field_width
> 0 && n
< field_width
)
21388 switch (mode_line_target
)
21390 case MODE_LINE_NOPROP
:
21391 case MODE_LINE_TITLE
:
21392 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21394 case MODE_LINE_STRING
:
21395 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21397 case MODE_LINE_DISPLAY
:
21398 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21407 /* Store a mode-line string element in mode_line_string_list.
21409 If STRING is non-null, display that C string. Otherwise, the Lisp
21410 string LISP_STRING is displayed.
21412 FIELD_WIDTH is the minimum number of output glyphs to produce.
21413 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21414 with spaces. FIELD_WIDTH <= 0 means don't pad.
21416 PRECISION is the maximum number of characters to output from
21417 STRING. PRECISION <= 0 means don't truncate the string.
21419 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21420 properties to the string.
21422 PROPS are the properties to add to the string.
21423 The mode_line_string_face face property is always added to the string.
21427 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21428 int field_width
, int precision
, Lisp_Object props
)
21433 if (string
!= NULL
)
21435 len
= strlen (string
);
21436 if (precision
> 0 && len
> precision
)
21438 lisp_string
= make_string (string
, len
);
21440 props
= mode_line_string_face_prop
;
21441 else if (!NILP (mode_line_string_face
))
21443 Lisp_Object face
= Fplist_get (props
, Qface
);
21444 props
= Fcopy_sequence (props
);
21446 face
= mode_line_string_face
;
21448 face
= list2 (face
, mode_line_string_face
);
21449 props
= Fplist_put (props
, Qface
, face
);
21451 Fadd_text_properties (make_number (0), make_number (len
),
21452 props
, lisp_string
);
21456 len
= XFASTINT (Flength (lisp_string
));
21457 if (precision
> 0 && len
> precision
)
21460 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21463 if (!NILP (mode_line_string_face
))
21467 props
= Ftext_properties_at (make_number (0), lisp_string
);
21468 face
= Fplist_get (props
, Qface
);
21470 face
= mode_line_string_face
;
21472 face
= list2 (face
, mode_line_string_face
);
21473 props
= list2 (Qface
, face
);
21475 lisp_string
= Fcopy_sequence (lisp_string
);
21478 Fadd_text_properties (make_number (0), make_number (len
),
21479 props
, lisp_string
);
21484 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21488 if (field_width
> len
)
21490 field_width
-= len
;
21491 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21493 Fadd_text_properties (make_number (0), make_number (field_width
),
21494 props
, lisp_string
);
21495 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21503 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21505 doc
: /* Format a string out of a mode line format specification.
21506 First arg FORMAT specifies the mode line format (see `mode-line-format'
21507 for details) to use.
21509 By default, the format is evaluated for the currently selected window.
21511 Optional second arg FACE specifies the face property to put on all
21512 characters for which no face is specified. The value nil means the
21513 default face. The value t means whatever face the window's mode line
21514 currently uses (either `mode-line' or `mode-line-inactive',
21515 depending on whether the window is the selected window or not).
21516 An integer value means the value string has no text
21519 Optional third and fourth args WINDOW and BUFFER specify the window
21520 and buffer to use as the context for the formatting (defaults
21521 are the selected window and the WINDOW's buffer). */)
21522 (Lisp_Object format
, Lisp_Object face
,
21523 Lisp_Object window
, Lisp_Object buffer
)
21528 struct buffer
*old_buffer
= NULL
;
21530 int no_props
= INTEGERP (face
);
21531 ptrdiff_t count
= SPECPDL_INDEX ();
21533 int string_start
= 0;
21535 w
= decode_any_window (window
);
21536 XSETWINDOW (window
, w
);
21539 buffer
= w
->contents
;
21540 CHECK_BUFFER (buffer
);
21542 /* Make formatting the modeline a non-op when noninteractive, otherwise
21543 there will be problems later caused by a partially initialized frame. */
21544 if (NILP (format
) || noninteractive
)
21545 return empty_unibyte_string
;
21550 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21551 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21552 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21553 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21554 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21555 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21556 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21559 old_buffer
= current_buffer
;
21561 /* Save things including mode_line_proptrans_alist,
21562 and set that to nil so that we don't alter the outer value. */
21563 record_unwind_protect (unwind_format_mode_line
,
21564 format_mode_line_unwind_data
21565 (XFRAME (WINDOW_FRAME (w
)),
21566 old_buffer
, selected_window
, 1));
21567 mode_line_proptrans_alist
= Qnil
;
21569 Fselect_window (window
, Qt
);
21570 set_buffer_internal_1 (XBUFFER (buffer
));
21572 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21576 mode_line_target
= MODE_LINE_NOPROP
;
21577 mode_line_string_face_prop
= Qnil
;
21578 mode_line_string_list
= Qnil
;
21579 string_start
= MODE_LINE_NOPROP_LEN (0);
21583 mode_line_target
= MODE_LINE_STRING
;
21584 mode_line_string_list
= Qnil
;
21585 mode_line_string_face
= face
;
21586 mode_line_string_face_prop
21587 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21590 push_kboard (FRAME_KBOARD (it
.f
));
21591 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21596 len
= MODE_LINE_NOPROP_LEN (string_start
);
21597 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21601 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21602 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21603 empty_unibyte_string
);
21606 unbind_to (count
, Qnil
);
21610 /* Write a null-terminated, right justified decimal representation of
21611 the positive integer D to BUF using a minimal field width WIDTH. */
21614 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21616 register char *p
= buf
;
21624 *p
++ = d
% 10 + '0';
21629 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21640 /* Write a null-terminated, right justified decimal and "human
21641 readable" representation of the nonnegative integer D to BUF using
21642 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21644 static const char power_letter
[] =
21658 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21660 /* We aim to represent the nonnegative integer D as
21661 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21662 ptrdiff_t quotient
= d
;
21664 /* -1 means: do not use TENTHS. */
21668 /* Length of QUOTIENT.TENTHS as a string. */
21674 if (quotient
>= 1000)
21676 /* Scale to the appropriate EXPONENT. */
21679 remainder
= quotient
% 1000;
21683 while (quotient
>= 1000);
21685 /* Round to nearest and decide whether to use TENTHS or not. */
21688 tenths
= remainder
/ 100;
21689 if (remainder
% 100 >= 50)
21696 if (quotient
== 10)
21704 if (remainder
>= 500)
21706 if (quotient
< 999)
21717 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21718 if (tenths
== -1 && quotient
<= 99)
21725 p
= psuffix
= buf
+ max (width
, length
);
21727 /* Print EXPONENT. */
21728 *psuffix
++ = power_letter
[exponent
];
21731 /* Print TENTHS. */
21734 *--p
= '0' + tenths
;
21738 /* Print QUOTIENT. */
21741 int digit
= quotient
% 10;
21742 *--p
= '0' + digit
;
21744 while ((quotient
/= 10) != 0);
21746 /* Print leading spaces. */
21751 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21752 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21753 type of CODING_SYSTEM. Return updated pointer into BUF. */
21755 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21758 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21761 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21762 const unsigned char *eol_str
;
21764 /* The EOL conversion we are using. */
21765 Lisp_Object eoltype
;
21767 val
= CODING_SYSTEM_SPEC (coding_system
);
21770 if (!VECTORP (val
)) /* Not yet decided. */
21772 *buf
++ = multibyte
? '-' : ' ';
21774 eoltype
= eol_mnemonic_undecided
;
21775 /* Don't mention EOL conversion if it isn't decided. */
21780 Lisp_Object eolvalue
;
21782 attrs
= AREF (val
, 0);
21783 eolvalue
= AREF (val
, 2);
21786 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21791 /* The EOL conversion that is normal on this system. */
21793 if (NILP (eolvalue
)) /* Not yet decided. */
21794 eoltype
= eol_mnemonic_undecided
;
21795 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21796 eoltype
= eol_mnemonic_undecided
;
21797 else /* eolvalue is Qunix, Qdos, or Qmac. */
21798 eoltype
= (EQ (eolvalue
, Qunix
)
21799 ? eol_mnemonic_unix
21800 : (EQ (eolvalue
, Qdos
) == 1
21801 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21807 /* Mention the EOL conversion if it is not the usual one. */
21808 if (STRINGP (eoltype
))
21810 eol_str
= SDATA (eoltype
);
21811 eol_str_len
= SBYTES (eoltype
);
21813 else if (CHARACTERP (eoltype
))
21815 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21816 int c
= XFASTINT (eoltype
);
21817 eol_str_len
= CHAR_STRING (c
, tmp
);
21822 eol_str
= invalid_eol_type
;
21823 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21825 memcpy (buf
, eol_str
, eol_str_len
);
21826 buf
+= eol_str_len
;
21832 /* Return a string for the output of a mode line %-spec for window W,
21833 generated by character C. FIELD_WIDTH > 0 means pad the string
21834 returned with spaces to that value. Return a Lisp string in
21835 *STRING if the resulting string is taken from that Lisp string.
21837 Note we operate on the current buffer for most purposes. */
21839 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21841 static const char *
21842 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21843 Lisp_Object
*string
)
21846 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21847 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21848 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21849 produce strings from numerical values, so limit preposterously
21850 large values of FIELD_WIDTH to avoid overrunning the buffer's
21851 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21852 bytes plus the terminating null. */
21853 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21854 struct buffer
*b
= current_buffer
;
21862 if (!NILP (BVAR (b
, read_only
)))
21864 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21869 /* This differs from %* only for a modified read-only buffer. */
21870 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21872 if (!NILP (BVAR (b
, read_only
)))
21877 /* This differs from %* in ignoring read-only-ness. */
21878 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21890 if (command_loop_level
> 5)
21892 p
= decode_mode_spec_buf
;
21893 for (i
= 0; i
< command_loop_level
; i
++)
21896 return decode_mode_spec_buf
;
21904 if (command_loop_level
> 5)
21906 p
= decode_mode_spec_buf
;
21907 for (i
= 0; i
< command_loop_level
; i
++)
21910 return decode_mode_spec_buf
;
21917 /* Let lots_of_dashes be a string of infinite length. */
21918 if (mode_line_target
== MODE_LINE_NOPROP
21919 || mode_line_target
== MODE_LINE_STRING
)
21921 if (field_width
<= 0
21922 || field_width
> sizeof (lots_of_dashes
))
21924 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21925 decode_mode_spec_buf
[i
] = '-';
21926 decode_mode_spec_buf
[i
] = '\0';
21927 return decode_mode_spec_buf
;
21930 return lots_of_dashes
;
21934 obj
= BVAR (b
, name
);
21938 /* %c and %l are ignored in `frame-title-format'.
21939 (In redisplay_internal, the frame title is drawn _before_ the
21940 windows are updated, so the stuff which depends on actual
21941 window contents (such as %l) may fail to render properly, or
21942 even crash emacs.) */
21943 if (mode_line_target
== MODE_LINE_TITLE
)
21947 ptrdiff_t col
= current_column ();
21948 w
->column_number_displayed
= col
;
21949 pint2str (decode_mode_spec_buf
, width
, col
);
21950 return decode_mode_spec_buf
;
21954 #ifndef SYSTEM_MALLOC
21956 if (NILP (Vmemory_full
))
21959 return "!MEM FULL! ";
21966 /* %F displays the frame name. */
21967 if (!NILP (f
->title
))
21968 return SSDATA (f
->title
);
21969 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21970 return SSDATA (f
->name
);
21974 obj
= BVAR (b
, filename
);
21979 ptrdiff_t size
= ZV
- BEGV
;
21980 pint2str (decode_mode_spec_buf
, width
, size
);
21981 return decode_mode_spec_buf
;
21986 ptrdiff_t size
= ZV
- BEGV
;
21987 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21988 return decode_mode_spec_buf
;
21993 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21994 ptrdiff_t topline
, nlines
, height
;
21997 /* %c and %l are ignored in `frame-title-format'. */
21998 if (mode_line_target
== MODE_LINE_TITLE
)
22001 startpos
= marker_position (w
->start
);
22002 startpos_byte
= marker_byte_position (w
->start
);
22003 height
= WINDOW_TOTAL_LINES (w
);
22005 /* If we decided that this buffer isn't suitable for line numbers,
22006 don't forget that too fast. */
22007 if (w
->base_line_pos
== -1)
22010 /* If the buffer is very big, don't waste time. */
22011 if (INTEGERP (Vline_number_display_limit
)
22012 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22014 w
->base_line_pos
= 0;
22015 w
->base_line_number
= 0;
22019 if (w
->base_line_number
> 0
22020 && w
->base_line_pos
> 0
22021 && w
->base_line_pos
<= startpos
)
22023 line
= w
->base_line_number
;
22024 linepos
= w
->base_line_pos
;
22025 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22030 linepos
= BUF_BEGV (b
);
22031 linepos_byte
= BUF_BEGV_BYTE (b
);
22034 /* Count lines from base line to window start position. */
22035 nlines
= display_count_lines (linepos_byte
,
22039 topline
= nlines
+ line
;
22041 /* Determine a new base line, if the old one is too close
22042 or too far away, or if we did not have one.
22043 "Too close" means it's plausible a scroll-down would
22044 go back past it. */
22045 if (startpos
== BUF_BEGV (b
))
22047 w
->base_line_number
= topline
;
22048 w
->base_line_pos
= BUF_BEGV (b
);
22050 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22051 || linepos
== BUF_BEGV (b
))
22053 ptrdiff_t limit
= BUF_BEGV (b
);
22054 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22055 ptrdiff_t position
;
22056 ptrdiff_t distance
=
22057 (height
* 2 + 30) * line_number_display_limit_width
;
22059 if (startpos
- distance
> limit
)
22061 limit
= startpos
- distance
;
22062 limit_byte
= CHAR_TO_BYTE (limit
);
22065 nlines
= display_count_lines (startpos_byte
,
22067 - (height
* 2 + 30),
22069 /* If we couldn't find the lines we wanted within
22070 line_number_display_limit_width chars per line,
22071 give up on line numbers for this window. */
22072 if (position
== limit_byte
&& limit
== startpos
- distance
)
22074 w
->base_line_pos
= -1;
22075 w
->base_line_number
= 0;
22079 w
->base_line_number
= topline
- nlines
;
22080 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22083 /* Now count lines from the start pos to point. */
22084 nlines
= display_count_lines (startpos_byte
,
22085 PT_BYTE
, PT
, &junk
);
22087 /* Record that we did display the line number. */
22088 line_number_displayed
= 1;
22090 /* Make the string to show. */
22091 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22092 return decode_mode_spec_buf
;
22095 char* p
= decode_mode_spec_buf
;
22096 int pad
= width
- 2;
22102 return decode_mode_spec_buf
;
22108 obj
= BVAR (b
, mode_name
);
22112 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22118 ptrdiff_t pos
= marker_position (w
->start
);
22119 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22121 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22123 if (pos
<= BUF_BEGV (b
))
22128 else if (pos
<= BUF_BEGV (b
))
22132 if (total
> 1000000)
22133 /* Do it differently for a large value, to avoid overflow. */
22134 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22136 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22137 /* We can't normally display a 3-digit number,
22138 so get us a 2-digit number that is close. */
22141 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22142 return decode_mode_spec_buf
;
22146 /* Display percentage of size above the bottom of the screen. */
22149 ptrdiff_t toppos
= marker_position (w
->start
);
22150 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22151 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22153 if (botpos
>= BUF_ZV (b
))
22155 if (toppos
<= BUF_BEGV (b
))
22162 if (total
> 1000000)
22163 /* Do it differently for a large value, to avoid overflow. */
22164 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22166 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22167 /* We can't normally display a 3-digit number,
22168 so get us a 2-digit number that is close. */
22171 if (toppos
<= BUF_BEGV (b
))
22172 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22174 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22175 return decode_mode_spec_buf
;
22180 /* status of process */
22181 obj
= Fget_buffer_process (Fcurrent_buffer ());
22183 return "no process";
22185 obj
= Fsymbol_name (Fprocess_status (obj
));
22191 ptrdiff_t count
= inhibit_garbage_collection ();
22192 Lisp_Object val
= call1 (intern ("file-remote-p"),
22193 BVAR (current_buffer
, directory
));
22194 unbind_to (count
, Qnil
);
22203 /* coding-system (not including end-of-line format) */
22205 /* coding-system (including end-of-line type) */
22207 int eol_flag
= (c
== 'Z');
22208 char *p
= decode_mode_spec_buf
;
22210 if (! FRAME_WINDOW_P (f
))
22212 /* No need to mention EOL here--the terminal never needs
22213 to do EOL conversion. */
22214 p
= decode_mode_spec_coding (CODING_ID_NAME
22215 (FRAME_KEYBOARD_CODING (f
)->id
),
22217 p
= decode_mode_spec_coding (CODING_ID_NAME
22218 (FRAME_TERMINAL_CODING (f
)->id
),
22221 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22224 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22225 #ifdef subprocesses
22226 obj
= Fget_buffer_process (Fcurrent_buffer ());
22227 if (PROCESSP (obj
))
22229 p
= decode_mode_spec_coding
22230 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22231 p
= decode_mode_spec_coding
22232 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22234 #endif /* subprocesses */
22237 return decode_mode_spec_buf
;
22244 return SSDATA (obj
);
22251 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22252 means count lines back from START_BYTE. But don't go beyond
22253 LIMIT_BYTE. Return the number of lines thus found (always
22256 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22257 either the position COUNT lines after/before START_BYTE, if we
22258 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22262 display_count_lines (ptrdiff_t start_byte
,
22263 ptrdiff_t limit_byte
, ptrdiff_t count
,
22264 ptrdiff_t *byte_pos_ptr
)
22266 register unsigned char *cursor
;
22267 unsigned char *base
;
22269 register ptrdiff_t ceiling
;
22270 register unsigned char *ceiling_addr
;
22271 ptrdiff_t orig_count
= count
;
22273 /* If we are not in selective display mode,
22274 check only for newlines. */
22275 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22276 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22280 while (start_byte
< limit_byte
)
22282 ceiling
= BUFFER_CEILING_OF (start_byte
);
22283 ceiling
= min (limit_byte
- 1, ceiling
);
22284 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22285 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22289 if (selective_display
)
22291 while (*cursor
!= '\n' && *cursor
!= 015
22292 && ++cursor
!= ceiling_addr
)
22294 if (cursor
== ceiling_addr
)
22299 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22308 start_byte
+= cursor
- base
;
22309 *byte_pos_ptr
= start_byte
;
22313 while (cursor
< ceiling_addr
);
22315 start_byte
+= ceiling_addr
- base
;
22320 while (start_byte
> limit_byte
)
22322 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22323 ceiling
= max (limit_byte
, ceiling
);
22324 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22325 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22328 if (selective_display
)
22330 while (--cursor
>= ceiling_addr
22331 && *cursor
!= '\n' && *cursor
!= 015)
22333 if (cursor
< ceiling_addr
)
22338 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22345 start_byte
+= cursor
- base
+ 1;
22346 *byte_pos_ptr
= start_byte
;
22347 /* When scanning backwards, we should
22348 not count the newline posterior to which we stop. */
22349 return - orig_count
- 1;
22352 start_byte
+= ceiling_addr
- base
;
22356 *byte_pos_ptr
= limit_byte
;
22359 return - orig_count
+ count
;
22360 return orig_count
- count
;
22366 /***********************************************************************
22368 ***********************************************************************/
22370 /* Display a NUL-terminated string, starting with index START.
22372 If STRING is non-null, display that C string. Otherwise, the Lisp
22373 string LISP_STRING is displayed. There's a case that STRING is
22374 non-null and LISP_STRING is not nil. It means STRING is a string
22375 data of LISP_STRING. In that case, we display LISP_STRING while
22376 ignoring its text properties.
22378 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22379 FACE_STRING. Display STRING or LISP_STRING with the face at
22380 FACE_STRING_POS in FACE_STRING:
22382 Display the string in the environment given by IT, but use the
22383 standard display table, temporarily.
22385 FIELD_WIDTH is the minimum number of output glyphs to produce.
22386 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22387 with spaces. If STRING has more characters, more than FIELD_WIDTH
22388 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22390 PRECISION is the maximum number of characters to output from
22391 STRING. PRECISION < 0 means don't truncate the string.
22393 This is roughly equivalent to printf format specifiers:
22395 FIELD_WIDTH PRECISION PRINTF
22396 ----------------------------------------
22402 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22403 display them, and < 0 means obey the current buffer's value of
22404 enable_multibyte_characters.
22406 Value is the number of columns displayed. */
22409 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22410 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22411 int field_width
, int precision
, int max_x
, int multibyte
)
22413 int hpos_at_start
= it
->hpos
;
22414 int saved_face_id
= it
->face_id
;
22415 struct glyph_row
*row
= it
->glyph_row
;
22416 ptrdiff_t it_charpos
;
22418 /* Initialize the iterator IT for iteration over STRING beginning
22419 with index START. */
22420 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22421 precision
, field_width
, multibyte
);
22422 if (string
&& STRINGP (lisp_string
))
22423 /* LISP_STRING is the one returned by decode_mode_spec. We should
22424 ignore its text properties. */
22425 it
->stop_charpos
= it
->end_charpos
;
22427 /* If displaying STRING, set up the face of the iterator from
22428 FACE_STRING, if that's given. */
22429 if (STRINGP (face_string
))
22435 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22436 0, &endptr
, it
->base_face_id
, 0);
22437 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22438 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22441 /* Set max_x to the maximum allowed X position. Don't let it go
22442 beyond the right edge of the window. */
22444 max_x
= it
->last_visible_x
;
22446 max_x
= min (max_x
, it
->last_visible_x
);
22448 /* Skip over display elements that are not visible. because IT->w is
22450 if (it
->current_x
< it
->first_visible_x
)
22451 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22452 MOVE_TO_POS
| MOVE_TO_X
);
22454 row
->ascent
= it
->max_ascent
;
22455 row
->height
= it
->max_ascent
+ it
->max_descent
;
22456 row
->phys_ascent
= it
->max_phys_ascent
;
22457 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22458 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22460 if (STRINGP (it
->string
))
22461 it_charpos
= IT_STRING_CHARPOS (*it
);
22463 it_charpos
= IT_CHARPOS (*it
);
22465 /* This condition is for the case that we are called with current_x
22466 past last_visible_x. */
22467 while (it
->current_x
< max_x
)
22469 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22471 /* Get the next display element. */
22472 if (!get_next_display_element (it
))
22475 /* Produce glyphs. */
22476 x_before
= it
->current_x
;
22477 n_glyphs_before
= row
->used
[TEXT_AREA
];
22478 PRODUCE_GLYPHS (it
);
22480 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22483 while (i
< nglyphs
)
22485 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22487 if (it
->line_wrap
!= TRUNCATE
22488 && x
+ glyph
->pixel_width
> max_x
)
22490 /* End of continued line or max_x reached. */
22491 if (CHAR_GLYPH_PADDING_P (*glyph
))
22493 /* A wide character is unbreakable. */
22494 if (row
->reversed_p
)
22495 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22496 - n_glyphs_before
);
22497 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22498 it
->current_x
= x_before
;
22502 if (row
->reversed_p
)
22503 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22504 - (n_glyphs_before
+ i
));
22505 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22510 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22512 /* Glyph is at least partially visible. */
22514 if (x
< it
->first_visible_x
)
22515 row
->x
= x
- it
->first_visible_x
;
22519 /* Glyph is off the left margin of the display area.
22520 Should not happen. */
22524 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22525 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22526 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22527 row
->phys_height
= max (row
->phys_height
,
22528 it
->max_phys_ascent
+ it
->max_phys_descent
);
22529 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22530 it
->max_extra_line_spacing
);
22531 x
+= glyph
->pixel_width
;
22535 /* Stop if max_x reached. */
22539 /* Stop at line ends. */
22540 if (ITERATOR_AT_END_OF_LINE_P (it
))
22542 it
->continuation_lines_width
= 0;
22546 set_iterator_to_next (it
, 1);
22547 if (STRINGP (it
->string
))
22548 it_charpos
= IT_STRING_CHARPOS (*it
);
22550 it_charpos
= IT_CHARPOS (*it
);
22552 /* Stop if truncating at the right edge. */
22553 if (it
->line_wrap
== TRUNCATE
22554 && it
->current_x
>= it
->last_visible_x
)
22556 /* Add truncation mark, but don't do it if the line is
22557 truncated at a padding space. */
22558 if (it_charpos
< it
->string_nchars
)
22560 if (!FRAME_WINDOW_P (it
->f
))
22564 if (it
->current_x
> it
->last_visible_x
)
22566 if (!row
->reversed_p
)
22568 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22569 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22574 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22575 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22577 unproduce_glyphs (it
, ii
+ 1);
22578 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22580 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22582 row
->used
[TEXT_AREA
] = ii
;
22583 produce_special_glyphs (it
, IT_TRUNCATION
);
22586 produce_special_glyphs (it
, IT_TRUNCATION
);
22588 row
->truncated_on_right_p
= 1;
22594 /* Maybe insert a truncation at the left. */
22595 if (it
->first_visible_x
22598 if (!FRAME_WINDOW_P (it
->f
)
22599 || (row
->reversed_p
22600 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22601 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22602 insert_left_trunc_glyphs (it
);
22603 row
->truncated_on_left_p
= 1;
22606 it
->face_id
= saved_face_id
;
22608 /* Value is number of columns displayed. */
22609 return it
->hpos
- hpos_at_start
;
22614 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22615 appears as an element of LIST or as the car of an element of LIST.
22616 If PROPVAL is a list, compare each element against LIST in that
22617 way, and return 1/2 if any element of PROPVAL is found in LIST.
22618 Otherwise return 0. This function cannot quit.
22619 The return value is 2 if the text is invisible but with an ellipsis
22620 and 1 if it's invisible and without an ellipsis. */
22623 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22625 register Lisp_Object tail
, proptail
;
22627 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22629 register Lisp_Object tem
;
22631 if (EQ (propval
, tem
))
22633 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22634 return NILP (XCDR (tem
)) ? 1 : 2;
22637 if (CONSP (propval
))
22639 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22641 Lisp_Object propelt
;
22642 propelt
= XCAR (proptail
);
22643 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22645 register Lisp_Object tem
;
22647 if (EQ (propelt
, tem
))
22649 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22650 return NILP (XCDR (tem
)) ? 1 : 2;
22658 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22659 doc
: /* Non-nil if the property makes the text invisible.
22660 POS-OR-PROP can be a marker or number, in which case it is taken to be
22661 a position in the current buffer and the value of the `invisible' property
22662 is checked; or it can be some other value, which is then presumed to be the
22663 value of the `invisible' property of the text of interest.
22664 The non-nil value returned can be t for truly invisible text or something
22665 else if the text is replaced by an ellipsis. */)
22666 (Lisp_Object pos_or_prop
)
22669 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22670 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22672 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22673 return (invis
== 0 ? Qnil
22675 : make_number (invis
));
22678 /* Calculate a width or height in pixels from a specification using
22679 the following elements:
22682 NUM - a (fractional) multiple of the default font width/height
22683 (NUM) - specifies exactly NUM pixels
22684 UNIT - a fixed number of pixels, see below.
22685 ELEMENT - size of a display element in pixels, see below.
22686 (NUM . SPEC) - equals NUM * SPEC
22687 (+ SPEC SPEC ...) - add pixel values
22688 (- SPEC SPEC ...) - subtract pixel values
22689 (- SPEC) - negate pixel value
22692 INT or FLOAT - a number constant
22693 SYMBOL - use symbol's (buffer local) variable binding.
22696 in - pixels per inch *)
22697 mm - pixels per 1/1000 meter *)
22698 cm - pixels per 1/100 meter *)
22699 width - width of current font in pixels.
22700 height - height of current font in pixels.
22702 *) using the ratio(s) defined in display-pixels-per-inch.
22706 left-fringe - left fringe width in pixels
22707 right-fringe - right fringe width in pixels
22709 left-margin - left margin width in pixels
22710 right-margin - right margin width in pixels
22712 scroll-bar - scroll-bar area width in pixels
22716 Pixels corresponding to 5 inches:
22719 Total width of non-text areas on left side of window (if scroll-bar is on left):
22720 '(space :width (+ left-fringe left-margin scroll-bar))
22722 Align to first text column (in header line):
22723 '(space :align-to 0)
22725 Align to middle of text area minus half the width of variable `my-image'
22726 containing a loaded image:
22727 '(space :align-to (0.5 . (- text my-image)))
22729 Width of left margin minus width of 1 character in the default font:
22730 '(space :width (- left-margin 1))
22732 Width of left margin minus width of 2 characters in the current font:
22733 '(space :width (- left-margin (2 . width)))
22735 Center 1 character over left-margin (in header line):
22736 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22738 Different ways to express width of left fringe plus left margin minus one pixel:
22739 '(space :width (- (+ left-fringe left-margin) (1)))
22740 '(space :width (+ left-fringe left-margin (- (1))))
22741 '(space :width (+ left-fringe left-margin (-1)))
22746 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22747 struct font
*font
, int width_p
, int *align_to
)
22751 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22752 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22755 return OK_PIXELS (0);
22757 eassert (FRAME_LIVE_P (it
->f
));
22759 if (SYMBOLP (prop
))
22761 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22763 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22765 if (unit
[0] == 'i' && unit
[1] == 'n')
22767 else if (unit
[0] == 'm' && unit
[1] == 'm')
22769 else if (unit
[0] == 'c' && unit
[1] == 'm')
22775 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22776 : FRAME_RES_Y (it
->f
));
22779 return OK_PIXELS (ppi
/ pixels
);
22784 #ifdef HAVE_WINDOW_SYSTEM
22785 if (EQ (prop
, Qheight
))
22786 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22787 if (EQ (prop
, Qwidth
))
22788 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22790 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22791 return OK_PIXELS (1);
22794 if (EQ (prop
, Qtext
))
22795 return OK_PIXELS (width_p
22796 ? window_box_width (it
->w
, TEXT_AREA
)
22797 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22799 if (align_to
&& *align_to
< 0)
22802 if (EQ (prop
, Qleft
))
22803 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22804 if (EQ (prop
, Qright
))
22805 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22806 if (EQ (prop
, Qcenter
))
22807 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22808 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22809 if (EQ (prop
, Qleft_fringe
))
22810 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22811 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22812 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22813 if (EQ (prop
, Qright_fringe
))
22814 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22815 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22816 : window_box_right_offset (it
->w
, TEXT_AREA
));
22817 if (EQ (prop
, Qleft_margin
))
22818 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22819 if (EQ (prop
, Qright_margin
))
22820 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22821 if (EQ (prop
, Qscroll_bar
))
22822 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22824 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22825 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22826 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22831 if (EQ (prop
, Qleft_fringe
))
22832 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22833 if (EQ (prop
, Qright_fringe
))
22834 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22835 if (EQ (prop
, Qleft_margin
))
22836 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22837 if (EQ (prop
, Qright_margin
))
22838 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22839 if (EQ (prop
, Qscroll_bar
))
22840 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22843 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22844 if (EQ (prop
, Qunbound
))
22848 if (INTEGERP (prop
) || FLOATP (prop
))
22850 int base_unit
= (width_p
22851 ? FRAME_COLUMN_WIDTH (it
->f
)
22852 : FRAME_LINE_HEIGHT (it
->f
));
22853 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22858 Lisp_Object car
= XCAR (prop
);
22859 Lisp_Object cdr
= XCDR (prop
);
22863 #ifdef HAVE_WINDOW_SYSTEM
22864 if (FRAME_WINDOW_P (it
->f
)
22865 && valid_image_p (prop
))
22867 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22868 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22870 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22873 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22879 while (CONSP (cdr
))
22881 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22882 font
, width_p
, align_to
))
22885 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22890 if (EQ (car
, Qminus
))
22892 return OK_PIXELS (pixels
);
22895 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22896 if (EQ (car
, Qunbound
))
22900 if (INTEGERP (car
) || FLOATP (car
))
22903 pixels
= XFLOATINT (car
);
22905 return OK_PIXELS (pixels
);
22906 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22907 font
, width_p
, align_to
))
22908 return OK_PIXELS (pixels
* fact
);
22919 /***********************************************************************
22921 ***********************************************************************/
22923 #ifdef HAVE_WINDOW_SYSTEM
22928 dump_glyph_string (struct glyph_string
*s
)
22930 fprintf (stderr
, "glyph string\n");
22931 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22932 s
->x
, s
->y
, s
->width
, s
->height
);
22933 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22934 fprintf (stderr
, " hl = %d\n", s
->hl
);
22935 fprintf (stderr
, " left overhang = %d, right = %d\n",
22936 s
->left_overhang
, s
->right_overhang
);
22937 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22938 fprintf (stderr
, " extends to end of line = %d\n",
22939 s
->extends_to_end_of_line_p
);
22940 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22941 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22944 #endif /* GLYPH_DEBUG */
22946 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22947 of XChar2b structures for S; it can't be allocated in
22948 init_glyph_string because it must be allocated via `alloca'. W
22949 is the window on which S is drawn. ROW and AREA are the glyph row
22950 and area within the row from which S is constructed. START is the
22951 index of the first glyph structure covered by S. HL is a
22952 face-override for drawing S. */
22955 #define OPTIONAL_HDC(hdc) HDC hdc,
22956 #define DECLARE_HDC(hdc) HDC hdc;
22957 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22958 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22961 #ifndef OPTIONAL_HDC
22962 #define OPTIONAL_HDC(hdc)
22963 #define DECLARE_HDC(hdc)
22964 #define ALLOCATE_HDC(hdc, f)
22965 #define RELEASE_HDC(hdc, f)
22969 init_glyph_string (struct glyph_string
*s
,
22971 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22972 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22974 memset (s
, 0, sizeof *s
);
22976 s
->f
= XFRAME (w
->frame
);
22980 s
->display
= FRAME_X_DISPLAY (s
->f
);
22981 s
->window
= FRAME_X_WINDOW (s
->f
);
22982 s
->char2b
= char2b
;
22986 s
->first_glyph
= row
->glyphs
[area
] + start
;
22987 s
->height
= row
->height
;
22988 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22989 s
->ybase
= s
->y
+ row
->ascent
;
22993 /* Append the list of glyph strings with head H and tail T to the list
22994 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22997 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22998 struct glyph_string
*h
, struct glyph_string
*t
)
23012 /* Prepend the list of glyph strings with head H and tail T to the
23013 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23017 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23018 struct glyph_string
*h
, struct glyph_string
*t
)
23032 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23033 Set *HEAD and *TAIL to the resulting list. */
23036 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23037 struct glyph_string
*s
)
23039 s
->next
= s
->prev
= NULL
;
23040 append_glyph_string_lists (head
, tail
, s
, s
);
23044 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23045 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23046 make sure that X resources for the face returned are allocated.
23047 Value is a pointer to a realized face that is ready for display if
23048 DISPLAY_P is non-zero. */
23050 static struct face
*
23051 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23052 XChar2b
*char2b
, int display_p
)
23054 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23059 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23061 if (code
== FONT_INVALID_CODE
)
23064 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23066 /* Make sure X resources of the face are allocated. */
23067 #ifdef HAVE_X_WINDOWS
23071 eassert (face
!= NULL
);
23072 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23079 /* Get face and two-byte form of character glyph GLYPH on frame F.
23080 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23081 a pointer to a realized face that is ready for display. */
23083 static struct face
*
23084 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23085 XChar2b
*char2b
, int *two_byte_p
)
23090 eassert (glyph
->type
== CHAR_GLYPH
);
23091 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23093 /* Make sure X resources of the face are allocated. */
23094 eassert (face
!= NULL
);
23095 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23102 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23103 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23105 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23107 if (code
== FONT_INVALID_CODE
)
23111 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23116 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23117 Return 1 if FONT has a glyph for C, otherwise return 0. */
23120 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23124 if (CHAR_BYTE8_P (c
))
23125 code
= CHAR_TO_BYTE8 (c
);
23127 code
= font
->driver
->encode_char (font
, c
);
23129 if (code
== FONT_INVALID_CODE
)
23131 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23136 /* Fill glyph string S with composition components specified by S->cmp.
23138 BASE_FACE is the base face of the composition.
23139 S->cmp_from is the index of the first component for S.
23141 OVERLAPS non-zero means S should draw the foreground only, and use
23142 its physical height for clipping. See also draw_glyphs.
23144 Value is the index of a component not in S. */
23147 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23151 /* For all glyphs of this composition, starting at the offset
23152 S->cmp_from, until we reach the end of the definition or encounter a
23153 glyph that requires the different face, add it to S. */
23158 s
->for_overlaps
= overlaps
;
23161 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23163 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23165 /* TAB in a composition means display glyphs with padding space
23166 on the left or right. */
23169 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23172 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23179 s
->font
= s
->face
->font
;
23181 else if (s
->face
!= face
)
23189 if (s
->face
== NULL
)
23191 s
->face
= base_face
->ascii_face
;
23192 s
->font
= s
->face
->font
;
23195 /* All glyph strings for the same composition has the same width,
23196 i.e. the width set for the first component of the composition. */
23197 s
->width
= s
->first_glyph
->pixel_width
;
23199 /* If the specified font could not be loaded, use the frame's
23200 default font, but record the fact that we couldn't load it in
23201 the glyph string so that we can draw rectangles for the
23202 characters of the glyph string. */
23203 if (s
->font
== NULL
)
23205 s
->font_not_found_p
= 1;
23206 s
->font
= FRAME_FONT (s
->f
);
23209 /* Adjust base line for subscript/superscript text. */
23210 s
->ybase
+= s
->first_glyph
->voffset
;
23212 /* This glyph string must always be drawn with 16-bit functions. */
23219 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23220 int start
, int end
, int overlaps
)
23222 struct glyph
*glyph
, *last
;
23223 Lisp_Object lgstring
;
23226 s
->for_overlaps
= overlaps
;
23227 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23228 last
= s
->row
->glyphs
[s
->area
] + end
;
23229 s
->cmp_id
= glyph
->u
.cmp
.id
;
23230 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23231 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23232 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23233 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23234 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23236 while (glyph
< last
23237 && glyph
->u
.cmp
.automatic
23238 && glyph
->u
.cmp
.id
== s
->cmp_id
23239 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23240 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23242 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23244 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23245 unsigned code
= LGLYPH_CODE (lglyph
);
23247 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23249 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23250 return glyph
- s
->row
->glyphs
[s
->area
];
23254 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23255 See the comment of fill_glyph_string for arguments.
23256 Value is the index of the first glyph not in S. */
23260 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23261 int start
, int end
, int overlaps
)
23263 struct glyph
*glyph
, *last
;
23266 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23267 s
->for_overlaps
= overlaps
;
23268 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23269 last
= s
->row
->glyphs
[s
->area
] + end
;
23270 voffset
= glyph
->voffset
;
23271 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23272 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23274 s
->width
= glyph
->pixel_width
;
23276 while (glyph
< last
23277 && glyph
->type
== GLYPHLESS_GLYPH
23278 && glyph
->voffset
== voffset
23279 && glyph
->face_id
== face_id
)
23282 s
->width
+= glyph
->pixel_width
;
23285 s
->ybase
+= voffset
;
23286 return glyph
- s
->row
->glyphs
[s
->area
];
23290 /* Fill glyph string S from a sequence of character glyphs.
23292 FACE_ID is the face id of the string. START is the index of the
23293 first glyph to consider, END is the index of the last + 1.
23294 OVERLAPS non-zero means S should draw the foreground only, and use
23295 its physical height for clipping. See also draw_glyphs.
23297 Value is the index of the first glyph not in S. */
23300 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23301 int start
, int end
, int overlaps
)
23303 struct glyph
*glyph
, *last
;
23305 int glyph_not_available_p
;
23307 eassert (s
->f
== XFRAME (s
->w
->frame
));
23308 eassert (s
->nchars
== 0);
23309 eassert (start
>= 0 && end
> start
);
23311 s
->for_overlaps
= overlaps
;
23312 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23313 last
= s
->row
->glyphs
[s
->area
] + end
;
23314 voffset
= glyph
->voffset
;
23315 s
->padding_p
= glyph
->padding_p
;
23316 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23318 while (glyph
< last
23319 && glyph
->type
== CHAR_GLYPH
23320 && glyph
->voffset
== voffset
23321 /* Same face id implies same font, nowadays. */
23322 && glyph
->face_id
== face_id
23323 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23327 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23328 s
->char2b
+ s
->nchars
,
23330 s
->two_byte_p
= two_byte_p
;
23332 eassert (s
->nchars
<= end
- start
);
23333 s
->width
+= glyph
->pixel_width
;
23334 if (glyph
++->padding_p
!= s
->padding_p
)
23338 s
->font
= s
->face
->font
;
23340 /* If the specified font could not be loaded, use the frame's font,
23341 but record the fact that we couldn't load it in
23342 S->font_not_found_p so that we can draw rectangles for the
23343 characters of the glyph string. */
23344 if (s
->font
== NULL
|| glyph_not_available_p
)
23346 s
->font_not_found_p
= 1;
23347 s
->font
= FRAME_FONT (s
->f
);
23350 /* Adjust base line for subscript/superscript text. */
23351 s
->ybase
+= voffset
;
23353 eassert (s
->face
&& s
->face
->gc
);
23354 return glyph
- s
->row
->glyphs
[s
->area
];
23358 /* Fill glyph string S from image glyph S->first_glyph. */
23361 fill_image_glyph_string (struct glyph_string
*s
)
23363 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23364 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23366 s
->slice
= s
->first_glyph
->slice
.img
;
23367 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23368 s
->font
= s
->face
->font
;
23369 s
->width
= s
->first_glyph
->pixel_width
;
23371 /* Adjust base line for subscript/superscript text. */
23372 s
->ybase
+= s
->first_glyph
->voffset
;
23376 /* Fill glyph string S from a sequence of stretch glyphs.
23378 START is the index of the first glyph to consider,
23379 END is the index of the last + 1.
23381 Value is the index of the first glyph not in S. */
23384 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23386 struct glyph
*glyph
, *last
;
23387 int voffset
, face_id
;
23389 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23391 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23392 last
= s
->row
->glyphs
[s
->area
] + end
;
23393 face_id
= glyph
->face_id
;
23394 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23395 s
->font
= s
->face
->font
;
23396 s
->width
= glyph
->pixel_width
;
23398 voffset
= glyph
->voffset
;
23402 && glyph
->type
== STRETCH_GLYPH
23403 && glyph
->voffset
== voffset
23404 && glyph
->face_id
== face_id
);
23406 s
->width
+= glyph
->pixel_width
;
23408 /* Adjust base line for subscript/superscript text. */
23409 s
->ybase
+= voffset
;
23411 /* The case that face->gc == 0 is handled when drawing the glyph
23412 string by calling PREPARE_FACE_FOR_DISPLAY. */
23414 return glyph
- s
->row
->glyphs
[s
->area
];
23417 static struct font_metrics
*
23418 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23420 static struct font_metrics metrics
;
23425 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23426 if (code
== FONT_INVALID_CODE
)
23428 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23433 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23434 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23435 assumed to be zero. */
23438 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23440 *left
= *right
= 0;
23442 if (glyph
->type
== CHAR_GLYPH
)
23446 struct font_metrics
*pcm
;
23448 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23449 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23451 if (pcm
->rbearing
> pcm
->width
)
23452 *right
= pcm
->rbearing
- pcm
->width
;
23453 if (pcm
->lbearing
< 0)
23454 *left
= -pcm
->lbearing
;
23457 else if (glyph
->type
== COMPOSITE_GLYPH
)
23459 if (! glyph
->u
.cmp
.automatic
)
23461 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23463 if (cmp
->rbearing
> cmp
->pixel_width
)
23464 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23465 if (cmp
->lbearing
< 0)
23466 *left
= - cmp
->lbearing
;
23470 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23471 struct font_metrics metrics
;
23473 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23474 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23475 if (metrics
.rbearing
> metrics
.width
)
23476 *right
= metrics
.rbearing
- metrics
.width
;
23477 if (metrics
.lbearing
< 0)
23478 *left
= - metrics
.lbearing
;
23484 /* Return the index of the first glyph preceding glyph string S that
23485 is overwritten by S because of S's left overhang. Value is -1
23486 if no glyphs are overwritten. */
23489 left_overwritten (struct glyph_string
*s
)
23493 if (s
->left_overhang
)
23496 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23497 int first
= s
->first_glyph
- glyphs
;
23499 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23500 x
-= glyphs
[i
].pixel_width
;
23511 /* Return the index of the first glyph preceding glyph string S that
23512 is overwriting S because of its right overhang. Value is -1 if no
23513 glyph in front of S overwrites S. */
23516 left_overwriting (struct glyph_string
*s
)
23519 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23520 int first
= s
->first_glyph
- glyphs
;
23524 for (i
= first
- 1; i
>= 0; --i
)
23527 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23530 x
-= glyphs
[i
].pixel_width
;
23537 /* Return the index of the last glyph following glyph string S that is
23538 overwritten by S because of S's right overhang. Value is -1 if
23539 no such glyph is found. */
23542 right_overwritten (struct glyph_string
*s
)
23546 if (s
->right_overhang
)
23549 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23550 int first
= (s
->first_glyph
- glyphs
23551 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23552 int end
= s
->row
->used
[s
->area
];
23554 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23555 x
+= glyphs
[i
].pixel_width
;
23564 /* Return the index of the last glyph following glyph string S that
23565 overwrites S because of its left overhang. Value is negative
23566 if no such glyph is found. */
23569 right_overwriting (struct glyph_string
*s
)
23572 int end
= s
->row
->used
[s
->area
];
23573 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23574 int first
= (s
->first_glyph
- glyphs
23575 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23579 for (i
= first
; i
< end
; ++i
)
23582 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23585 x
+= glyphs
[i
].pixel_width
;
23592 /* Set background width of glyph string S. START is the index of the
23593 first glyph following S. LAST_X is the right-most x-position + 1
23594 in the drawing area. */
23597 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23599 /* If the face of this glyph string has to be drawn to the end of
23600 the drawing area, set S->extends_to_end_of_line_p. */
23602 if (start
== s
->row
->used
[s
->area
]
23603 && s
->area
== TEXT_AREA
23604 && ((s
->row
->fill_line_p
23605 && (s
->hl
== DRAW_NORMAL_TEXT
23606 || s
->hl
== DRAW_IMAGE_RAISED
23607 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23608 || s
->hl
== DRAW_MOUSE_FACE
))
23609 s
->extends_to_end_of_line_p
= 1;
23611 /* If S extends its face to the end of the line, set its
23612 background_width to the distance to the right edge of the drawing
23614 if (s
->extends_to_end_of_line_p
)
23615 s
->background_width
= last_x
- s
->x
+ 1;
23617 s
->background_width
= s
->width
;
23621 /* Compute overhangs and x-positions for glyph string S and its
23622 predecessors, or successors. X is the starting x-position for S.
23623 BACKWARD_P non-zero means process predecessors. */
23626 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23632 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23633 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23643 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23644 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23654 /* The following macros are only called from draw_glyphs below.
23655 They reference the following parameters of that function directly:
23656 `w', `row', `area', and `overlap_p'
23657 as well as the following local variables:
23658 `s', `f', and `hdc' (in W32) */
23661 /* On W32, silently add local `hdc' variable to argument list of
23662 init_glyph_string. */
23663 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23664 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23666 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23667 init_glyph_string (s, char2b, w, row, area, start, hl)
23670 /* Add a glyph string for a stretch glyph to the list of strings
23671 between HEAD and TAIL. START is the index of the stretch glyph in
23672 row area AREA of glyph row ROW. END is the index of the last glyph
23673 in that glyph row area. X is the current output position assigned
23674 to the new glyph string constructed. HL overrides that face of the
23675 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23676 is the right-most x-position of the drawing area. */
23678 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23679 and below -- keep them on one line. */
23680 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23683 s = alloca (sizeof *s); \
23684 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23685 START = fill_stretch_glyph_string (s, START, END); \
23686 append_glyph_string (&HEAD, &TAIL, s); \
23692 /* Add a glyph string for an image glyph to the list of strings
23693 between HEAD and TAIL. START is the index of the image glyph in
23694 row area AREA of glyph row ROW. END is the index of the last glyph
23695 in that glyph row area. X is the current output position assigned
23696 to the new glyph string constructed. HL overrides that face of the
23697 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23698 is the right-most x-position of the drawing area. */
23700 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23703 s = alloca (sizeof *s); \
23704 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23705 fill_image_glyph_string (s); \
23706 append_glyph_string (&HEAD, &TAIL, s); \
23713 /* Add a glyph string for a sequence of character glyphs to the list
23714 of strings between HEAD and TAIL. START is the index of the first
23715 glyph in row area AREA of glyph row ROW that is part of the new
23716 glyph string. END is the index of the last glyph in that glyph row
23717 area. X is the current output position assigned to the new glyph
23718 string constructed. HL overrides that face of the glyph; e.g. it
23719 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23720 right-most x-position of the drawing area. */
23722 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23728 face_id = (row)->glyphs[area][START].face_id; \
23730 s = alloca (sizeof *s); \
23731 char2b = alloca ((END - START) * sizeof *char2b); \
23732 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23733 append_glyph_string (&HEAD, &TAIL, s); \
23735 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23740 /* Add a glyph string for a composite sequence to the list of strings
23741 between HEAD and TAIL. START is the index of the first glyph in
23742 row area AREA of glyph row ROW that is part of the new glyph
23743 string. END is the index of the last glyph in that glyph row area.
23744 X is the current output position assigned to the new glyph string
23745 constructed. HL overrides that face of the glyph; e.g. it is
23746 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23747 x-position of the drawing area. */
23749 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23751 int face_id = (row)->glyphs[area][START].face_id; \
23752 struct face *base_face = FACE_FROM_ID (f, face_id); \
23753 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23754 struct composition *cmp = composition_table[cmp_id]; \
23756 struct glyph_string *first_s = NULL; \
23759 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23761 /* Make glyph_strings for each glyph sequence that is drawable by \
23762 the same face, and append them to HEAD/TAIL. */ \
23763 for (n = 0; n < cmp->glyph_len;) \
23765 s = alloca (sizeof *s); \
23766 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23767 append_glyph_string (&(HEAD), &(TAIL), s); \
23773 n = fill_composite_glyph_string (s, base_face, overlaps); \
23781 /* Add a glyph string for a glyph-string sequence to the list of strings
23782 between HEAD and TAIL. */
23784 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23788 Lisp_Object gstring; \
23790 face_id = (row)->glyphs[area][START].face_id; \
23791 gstring = (composition_gstring_from_id \
23792 ((row)->glyphs[area][START].u.cmp.id)); \
23793 s = alloca (sizeof *s); \
23794 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23795 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23796 append_glyph_string (&(HEAD), &(TAIL), s); \
23798 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23802 /* Add a glyph string for a sequence of glyphless character's glyphs
23803 to the list of strings between HEAD and TAIL. The meanings of
23804 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23806 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23811 face_id = (row)->glyphs[area][START].face_id; \
23813 s = alloca (sizeof *s); \
23814 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23815 append_glyph_string (&HEAD, &TAIL, s); \
23817 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23823 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23824 of AREA of glyph row ROW on window W between indices START and END.
23825 HL overrides the face for drawing glyph strings, e.g. it is
23826 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23827 x-positions of the drawing area.
23829 This is an ugly monster macro construct because we must use alloca
23830 to allocate glyph strings (because draw_glyphs can be called
23831 asynchronously). */
23833 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23836 HEAD = TAIL = NULL; \
23837 while (START < END) \
23839 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23840 switch (first_glyph->type) \
23843 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23847 case COMPOSITE_GLYPH: \
23848 if (first_glyph->u.cmp.automatic) \
23849 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23852 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23856 case STRETCH_GLYPH: \
23857 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23861 case IMAGE_GLYPH: \
23862 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23866 case GLYPHLESS_GLYPH: \
23867 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23877 set_glyph_string_background_width (s, START, LAST_X); \
23884 /* Draw glyphs between START and END in AREA of ROW on window W,
23885 starting at x-position X. X is relative to AREA in W. HL is a
23886 face-override with the following meaning:
23888 DRAW_NORMAL_TEXT draw normally
23889 DRAW_CURSOR draw in cursor face
23890 DRAW_MOUSE_FACE draw in mouse face.
23891 DRAW_INVERSE_VIDEO draw in mode line face
23892 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23893 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23895 If OVERLAPS is non-zero, draw only the foreground of characters and
23896 clip to the physical height of ROW. Non-zero value also defines
23897 the overlapping part to be drawn:
23899 OVERLAPS_PRED overlap with preceding rows
23900 OVERLAPS_SUCC overlap with succeeding rows
23901 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23902 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23904 Value is the x-position reached, relative to AREA of W. */
23907 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23908 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23909 enum draw_glyphs_face hl
, int overlaps
)
23911 struct glyph_string
*head
, *tail
;
23912 struct glyph_string
*s
;
23913 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23914 int i
, j
, x_reached
, last_x
, area_left
= 0;
23915 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23918 ALLOCATE_HDC (hdc
, f
);
23920 /* Let's rather be paranoid than getting a SEGV. */
23921 end
= min (end
, row
->used
[area
]);
23922 start
= clip_to_bounds (0, start
, end
);
23924 /* Translate X to frame coordinates. Set last_x to the right
23925 end of the drawing area. */
23926 if (row
->full_width_p
)
23928 /* X is relative to the left edge of W, without scroll bars
23930 area_left
= WINDOW_LEFT_EDGE_X (w
);
23931 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23935 area_left
= window_box_left (w
, area
);
23936 last_x
= area_left
+ window_box_width (w
, area
);
23940 /* Build a doubly-linked list of glyph_string structures between
23941 head and tail from what we have to draw. Note that the macro
23942 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23943 the reason we use a separate variable `i'. */
23945 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23947 x_reached
= tail
->x
+ tail
->background_width
;
23951 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23952 the row, redraw some glyphs in front or following the glyph
23953 strings built above. */
23954 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23956 struct glyph_string
*h
, *t
;
23957 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23958 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23959 int check_mouse_face
= 0;
23962 /* If mouse highlighting is on, we may need to draw adjacent
23963 glyphs using mouse-face highlighting. */
23964 if (area
== TEXT_AREA
&& row
->mouse_face_p
23965 && hlinfo
->mouse_face_beg_row
>= 0
23966 && hlinfo
->mouse_face_end_row
>= 0)
23968 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23970 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23971 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23973 check_mouse_face
= 1;
23974 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23975 ? hlinfo
->mouse_face_beg_col
: 0;
23976 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23977 ? hlinfo
->mouse_face_end_col
23978 : row
->used
[TEXT_AREA
];
23982 /* Compute overhangs for all glyph strings. */
23983 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23984 for (s
= head
; s
; s
= s
->next
)
23985 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23987 /* Prepend glyph strings for glyphs in front of the first glyph
23988 string that are overwritten because of the first glyph
23989 string's left overhang. The background of all strings
23990 prepended must be drawn because the first glyph string
23992 i
= left_overwritten (head
);
23995 enum draw_glyphs_face overlap_hl
;
23997 /* If this row contains mouse highlighting, attempt to draw
23998 the overlapped glyphs with the correct highlight. This
23999 code fails if the overlap encompasses more than one glyph
24000 and mouse-highlight spans only some of these glyphs.
24001 However, making it work perfectly involves a lot more
24002 code, and I don't know if the pathological case occurs in
24003 practice, so we'll stick to this for now. --- cyd */
24004 if (check_mouse_face
24005 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24006 overlap_hl
= DRAW_MOUSE_FACE
;
24008 overlap_hl
= DRAW_NORMAL_TEXT
;
24011 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24012 overlap_hl
, dummy_x
, last_x
);
24014 compute_overhangs_and_x (t
, head
->x
, 1);
24015 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24019 /* Prepend glyph strings for glyphs in front of the first glyph
24020 string that overwrite that glyph string because of their
24021 right overhang. For these strings, only the foreground must
24022 be drawn, because it draws over the glyph string at `head'.
24023 The background must not be drawn because this would overwrite
24024 right overhangs of preceding glyphs for which no glyph
24026 i
= left_overwriting (head
);
24029 enum draw_glyphs_face overlap_hl
;
24031 if (check_mouse_face
24032 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24033 overlap_hl
= DRAW_MOUSE_FACE
;
24035 overlap_hl
= DRAW_NORMAL_TEXT
;
24038 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24039 overlap_hl
, dummy_x
, last_x
);
24040 for (s
= h
; s
; s
= s
->next
)
24041 s
->background_filled_p
= 1;
24042 compute_overhangs_and_x (t
, head
->x
, 1);
24043 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24046 /* Append glyphs strings for glyphs following the last glyph
24047 string tail that are overwritten by tail. The background of
24048 these strings has to be drawn because tail's foreground draws
24050 i
= right_overwritten (tail
);
24053 enum draw_glyphs_face overlap_hl
;
24055 if (check_mouse_face
24056 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24057 overlap_hl
= DRAW_MOUSE_FACE
;
24059 overlap_hl
= DRAW_NORMAL_TEXT
;
24061 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24062 overlap_hl
, x
, last_x
);
24063 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24064 we don't have `end = i;' here. */
24065 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24066 append_glyph_string_lists (&head
, &tail
, h
, t
);
24070 /* Append glyph strings for glyphs following the last glyph
24071 string tail that overwrite tail. The foreground of such
24072 glyphs has to be drawn because it writes into the background
24073 of tail. The background must not be drawn because it could
24074 paint over the foreground of following glyphs. */
24075 i
= right_overwriting (tail
);
24078 enum draw_glyphs_face overlap_hl
;
24079 if (check_mouse_face
24080 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24081 overlap_hl
= DRAW_MOUSE_FACE
;
24083 overlap_hl
= DRAW_NORMAL_TEXT
;
24086 i
++; /* We must include the Ith glyph. */
24087 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24088 overlap_hl
, x
, last_x
);
24089 for (s
= h
; s
; s
= s
->next
)
24090 s
->background_filled_p
= 1;
24091 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24092 append_glyph_string_lists (&head
, &tail
, h
, t
);
24094 if (clip_head
|| clip_tail
)
24095 for (s
= head
; s
; s
= s
->next
)
24097 s
->clip_head
= clip_head
;
24098 s
->clip_tail
= clip_tail
;
24102 /* Draw all strings. */
24103 for (s
= head
; s
; s
= s
->next
)
24104 FRAME_RIF (f
)->draw_glyph_string (s
);
24107 /* When focus a sole frame and move horizontally, this sets on_p to 0
24108 causing a failure to erase prev cursor position. */
24109 if (area
== TEXT_AREA
24110 && !row
->full_width_p
24111 /* When drawing overlapping rows, only the glyph strings'
24112 foreground is drawn, which doesn't erase a cursor
24116 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24117 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24118 : (tail
? tail
->x
+ tail
->background_width
: x
));
24122 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24123 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24127 /* Value is the x-position up to which drawn, relative to AREA of W.
24128 This doesn't include parts drawn because of overhangs. */
24129 if (row
->full_width_p
)
24130 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24132 x_reached
-= area_left
;
24134 RELEASE_HDC (hdc
, f
);
24139 /* Expand row matrix if too narrow. Don't expand if area
24142 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24144 if (!it->f->fonts_changed \
24145 && (it->glyph_row->glyphs[area] \
24146 < it->glyph_row->glyphs[area + 1])) \
24148 it->w->ncols_scale_factor++; \
24149 it->f->fonts_changed = 1; \
24153 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24154 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24157 append_glyph (struct it
*it
)
24159 struct glyph
*glyph
;
24160 enum glyph_row_area area
= it
->area
;
24162 eassert (it
->glyph_row
);
24163 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24165 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24166 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24168 /* If the glyph row is reversed, we need to prepend the glyph
24169 rather than append it. */
24170 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24174 /* Make room for the additional glyph. */
24175 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24177 glyph
= it
->glyph_row
->glyphs
[area
];
24179 glyph
->charpos
= CHARPOS (it
->position
);
24180 glyph
->object
= it
->object
;
24181 if (it
->pixel_width
> 0)
24183 glyph
->pixel_width
= it
->pixel_width
;
24184 glyph
->padding_p
= 0;
24188 /* Assure at least 1-pixel width. Otherwise, cursor can't
24189 be displayed correctly. */
24190 glyph
->pixel_width
= 1;
24191 glyph
->padding_p
= 1;
24193 glyph
->ascent
= it
->ascent
;
24194 glyph
->descent
= it
->descent
;
24195 glyph
->voffset
= it
->voffset
;
24196 glyph
->type
= CHAR_GLYPH
;
24197 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24198 glyph
->multibyte_p
= it
->multibyte_p
;
24199 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24201 /* In R2L rows, the left and the right box edges need to be
24202 drawn in reverse direction. */
24203 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24204 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24208 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24209 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24211 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24212 || it
->phys_descent
> it
->descent
);
24213 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24214 glyph
->face_id
= it
->face_id
;
24215 glyph
->u
.ch
= it
->char_to_display
;
24216 glyph
->slice
.img
= null_glyph_slice
;
24217 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24220 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24221 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24223 glyph
->bidi_type
= it
->bidi_it
.type
;
24227 glyph
->resolved_level
= 0;
24228 glyph
->bidi_type
= UNKNOWN_BT
;
24230 ++it
->glyph_row
->used
[area
];
24233 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24236 /* Store one glyph for the composition IT->cmp_it.id in
24237 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24241 append_composite_glyph (struct it
*it
)
24243 struct glyph
*glyph
;
24244 enum glyph_row_area area
= it
->area
;
24246 eassert (it
->glyph_row
);
24248 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24249 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24251 /* If the glyph row is reversed, we need to prepend the glyph
24252 rather than append it. */
24253 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24257 /* Make room for the new glyph. */
24258 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24260 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24262 glyph
->charpos
= it
->cmp_it
.charpos
;
24263 glyph
->object
= it
->object
;
24264 glyph
->pixel_width
= it
->pixel_width
;
24265 glyph
->ascent
= it
->ascent
;
24266 glyph
->descent
= it
->descent
;
24267 glyph
->voffset
= it
->voffset
;
24268 glyph
->type
= COMPOSITE_GLYPH
;
24269 if (it
->cmp_it
.ch
< 0)
24271 glyph
->u
.cmp
.automatic
= 0;
24272 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24273 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24277 glyph
->u
.cmp
.automatic
= 1;
24278 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24279 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24280 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24282 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24283 glyph
->multibyte_p
= it
->multibyte_p
;
24284 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24286 /* In R2L rows, the left and the right box edges need to be
24287 drawn in reverse direction. */
24288 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24289 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24293 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24294 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24296 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24297 || it
->phys_descent
> it
->descent
);
24298 glyph
->padding_p
= 0;
24299 glyph
->glyph_not_available_p
= 0;
24300 glyph
->face_id
= it
->face_id
;
24301 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24304 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24305 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24307 glyph
->bidi_type
= it
->bidi_it
.type
;
24309 ++it
->glyph_row
->used
[area
];
24312 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24316 /* Change IT->ascent and IT->height according to the setting of
24320 take_vertical_position_into_account (struct it
*it
)
24324 if (it
->voffset
< 0)
24325 /* Increase the ascent so that we can display the text higher
24327 it
->ascent
-= it
->voffset
;
24329 /* Increase the descent so that we can display the text lower
24331 it
->descent
+= it
->voffset
;
24336 /* Produce glyphs/get display metrics for the image IT is loaded with.
24337 See the description of struct display_iterator in dispextern.h for
24338 an overview of struct display_iterator. */
24341 produce_image_glyph (struct it
*it
)
24345 int glyph_ascent
, crop
;
24346 struct glyph_slice slice
;
24348 eassert (it
->what
== IT_IMAGE
);
24350 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24352 /* Make sure X resources of the face is loaded. */
24353 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24355 if (it
->image_id
< 0)
24357 /* Fringe bitmap. */
24358 it
->ascent
= it
->phys_ascent
= 0;
24359 it
->descent
= it
->phys_descent
= 0;
24360 it
->pixel_width
= 0;
24365 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24367 /* Make sure X resources of the image is loaded. */
24368 prepare_image_for_display (it
->f
, img
);
24370 slice
.x
= slice
.y
= 0;
24371 slice
.width
= img
->width
;
24372 slice
.height
= img
->height
;
24374 if (INTEGERP (it
->slice
.x
))
24375 slice
.x
= XINT (it
->slice
.x
);
24376 else if (FLOATP (it
->slice
.x
))
24377 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24379 if (INTEGERP (it
->slice
.y
))
24380 slice
.y
= XINT (it
->slice
.y
);
24381 else if (FLOATP (it
->slice
.y
))
24382 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24384 if (INTEGERP (it
->slice
.width
))
24385 slice
.width
= XINT (it
->slice
.width
);
24386 else if (FLOATP (it
->slice
.width
))
24387 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24389 if (INTEGERP (it
->slice
.height
))
24390 slice
.height
= XINT (it
->slice
.height
);
24391 else if (FLOATP (it
->slice
.height
))
24392 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24394 if (slice
.x
>= img
->width
)
24395 slice
.x
= img
->width
;
24396 if (slice
.y
>= img
->height
)
24397 slice
.y
= img
->height
;
24398 if (slice
.x
+ slice
.width
>= img
->width
)
24399 slice
.width
= img
->width
- slice
.x
;
24400 if (slice
.y
+ slice
.height
> img
->height
)
24401 slice
.height
= img
->height
- slice
.y
;
24403 if (slice
.width
== 0 || slice
.height
== 0)
24406 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24408 it
->descent
= slice
.height
- glyph_ascent
;
24410 it
->descent
+= img
->vmargin
;
24411 if (slice
.y
+ slice
.height
== img
->height
)
24412 it
->descent
+= img
->vmargin
;
24413 it
->phys_descent
= it
->descent
;
24415 it
->pixel_width
= slice
.width
;
24417 it
->pixel_width
+= img
->hmargin
;
24418 if (slice
.x
+ slice
.width
== img
->width
)
24419 it
->pixel_width
+= img
->hmargin
;
24421 /* It's quite possible for images to have an ascent greater than
24422 their height, so don't get confused in that case. */
24423 if (it
->descent
< 0)
24428 if (face
->box
!= FACE_NO_BOX
)
24430 if (face
->box_line_width
> 0)
24433 it
->ascent
+= face
->box_line_width
;
24434 if (slice
.y
+ slice
.height
== img
->height
)
24435 it
->descent
+= face
->box_line_width
;
24438 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24439 it
->pixel_width
+= eabs (face
->box_line_width
);
24440 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24441 it
->pixel_width
+= eabs (face
->box_line_width
);
24444 take_vertical_position_into_account (it
);
24446 /* Automatically crop wide image glyphs at right edge so we can
24447 draw the cursor on same display row. */
24448 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24449 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24451 it
->pixel_width
-= crop
;
24452 slice
.width
-= crop
;
24457 struct glyph
*glyph
;
24458 enum glyph_row_area area
= it
->area
;
24460 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24461 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24463 glyph
->charpos
= CHARPOS (it
->position
);
24464 glyph
->object
= it
->object
;
24465 glyph
->pixel_width
= it
->pixel_width
;
24466 glyph
->ascent
= glyph_ascent
;
24467 glyph
->descent
= it
->descent
;
24468 glyph
->voffset
= it
->voffset
;
24469 glyph
->type
= IMAGE_GLYPH
;
24470 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24471 glyph
->multibyte_p
= it
->multibyte_p
;
24472 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24474 /* In R2L rows, the left and the right box edges need to be
24475 drawn in reverse direction. */
24476 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24477 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24481 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24482 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24484 glyph
->overlaps_vertically_p
= 0;
24485 glyph
->padding_p
= 0;
24486 glyph
->glyph_not_available_p
= 0;
24487 glyph
->face_id
= it
->face_id
;
24488 glyph
->u
.img_id
= img
->id
;
24489 glyph
->slice
.img
= slice
;
24490 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24493 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24494 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24496 glyph
->bidi_type
= it
->bidi_it
.type
;
24498 ++it
->glyph_row
->used
[area
];
24501 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24506 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24507 of the glyph, WIDTH and HEIGHT are the width and height of the
24508 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24511 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24512 int width
, int height
, int ascent
)
24514 struct glyph
*glyph
;
24515 enum glyph_row_area area
= it
->area
;
24517 eassert (ascent
>= 0 && ascent
<= height
);
24519 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24520 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24522 /* If the glyph row is reversed, we need to prepend the glyph
24523 rather than append it. */
24524 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24528 /* Make room for the additional glyph. */
24529 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24531 glyph
= it
->glyph_row
->glyphs
[area
];
24533 glyph
->charpos
= CHARPOS (it
->position
);
24534 glyph
->object
= object
;
24535 glyph
->pixel_width
= width
;
24536 glyph
->ascent
= ascent
;
24537 glyph
->descent
= height
- ascent
;
24538 glyph
->voffset
= it
->voffset
;
24539 glyph
->type
= STRETCH_GLYPH
;
24540 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24541 glyph
->multibyte_p
= it
->multibyte_p
;
24542 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24544 /* In R2L rows, the left and the right box edges need to be
24545 drawn in reverse direction. */
24546 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24547 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24551 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24552 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24554 glyph
->overlaps_vertically_p
= 0;
24555 glyph
->padding_p
= 0;
24556 glyph
->glyph_not_available_p
= 0;
24557 glyph
->face_id
= it
->face_id
;
24558 glyph
->u
.stretch
.ascent
= ascent
;
24559 glyph
->u
.stretch
.height
= height
;
24560 glyph
->slice
.img
= null_glyph_slice
;
24561 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24564 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24565 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24567 glyph
->bidi_type
= it
->bidi_it
.type
;
24571 glyph
->resolved_level
= 0;
24572 glyph
->bidi_type
= UNKNOWN_BT
;
24574 ++it
->glyph_row
->used
[area
];
24577 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24580 #endif /* HAVE_WINDOW_SYSTEM */
24582 /* Produce a stretch glyph for iterator IT. IT->object is the value
24583 of the glyph property displayed. The value must be a list
24584 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24587 1. `:width WIDTH' specifies that the space should be WIDTH *
24588 canonical char width wide. WIDTH may be an integer or floating
24591 2. `:relative-width FACTOR' specifies that the width of the stretch
24592 should be computed from the width of the first character having the
24593 `glyph' property, and should be FACTOR times that width.
24595 3. `:align-to HPOS' specifies that the space should be wide enough
24596 to reach HPOS, a value in canonical character units.
24598 Exactly one of the above pairs must be present.
24600 4. `:height HEIGHT' specifies that the height of the stretch produced
24601 should be HEIGHT, measured in canonical character units.
24603 5. `:relative-height FACTOR' specifies that the height of the
24604 stretch should be FACTOR times the height of the characters having
24605 the glyph property.
24607 Either none or exactly one of 4 or 5 must be present.
24609 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24610 of the stretch should be used for the ascent of the stretch.
24611 ASCENT must be in the range 0 <= ASCENT <= 100. */
24614 produce_stretch_glyph (struct it
*it
)
24616 /* (space :width WIDTH :height HEIGHT ...) */
24617 Lisp_Object prop
, plist
;
24618 int width
= 0, height
= 0, align_to
= -1;
24619 int zero_width_ok_p
= 0;
24621 struct font
*font
= NULL
;
24623 #ifdef HAVE_WINDOW_SYSTEM
24625 int zero_height_ok_p
= 0;
24627 if (FRAME_WINDOW_P (it
->f
))
24629 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24630 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24631 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24635 /* List should start with `space'. */
24636 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24637 plist
= XCDR (it
->object
);
24639 /* Compute the width of the stretch. */
24640 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24641 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24643 /* Absolute width `:width WIDTH' specified and valid. */
24644 zero_width_ok_p
= 1;
24647 #ifdef HAVE_WINDOW_SYSTEM
24648 else if (FRAME_WINDOW_P (it
->f
)
24649 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24651 /* Relative width `:relative-width FACTOR' specified and valid.
24652 Compute the width of the characters having the `glyph'
24655 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24658 if (it
->multibyte_p
)
24659 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24662 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24663 if (! ASCII_CHAR_P (it2
.c
))
24664 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24667 it2
.glyph_row
= NULL
;
24668 it2
.what
= IT_CHARACTER
;
24669 x_produce_glyphs (&it2
);
24670 width
= NUMVAL (prop
) * it2
.pixel_width
;
24672 #endif /* HAVE_WINDOW_SYSTEM */
24673 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24674 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24676 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24677 align_to
= (align_to
< 0
24679 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24680 else if (align_to
< 0)
24681 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24682 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24683 zero_width_ok_p
= 1;
24686 /* Nothing specified -> width defaults to canonical char width. */
24687 width
= FRAME_COLUMN_WIDTH (it
->f
);
24689 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24692 #ifdef HAVE_WINDOW_SYSTEM
24693 /* Compute height. */
24694 if (FRAME_WINDOW_P (it
->f
))
24696 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24697 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24700 zero_height_ok_p
= 1;
24702 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24704 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24706 height
= FONT_HEIGHT (font
);
24708 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24711 /* Compute percentage of height used for ascent. If
24712 `:ascent ASCENT' is present and valid, use that. Otherwise,
24713 derive the ascent from the font in use. */
24714 if (prop
= Fplist_get (plist
, QCascent
),
24715 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24716 ascent
= height
* NUMVAL (prop
) / 100.0;
24717 else if (!NILP (prop
)
24718 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24719 ascent
= min (max (0, (int)tem
), height
);
24721 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24724 #endif /* HAVE_WINDOW_SYSTEM */
24727 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24728 && it
->current_x
+ width
> it
->last_visible_x
)
24730 width
= it
->last_visible_x
- it
->current_x
;
24731 #ifdef HAVE_WINDOW_SYSTEM
24732 /* Subtract one more pixel from the stretch width, but only on
24733 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24734 width
-= FRAME_WINDOW_P (it
->f
);
24738 if (width
> 0 && height
> 0 && it
->glyph_row
)
24740 Lisp_Object o_object
= it
->object
;
24741 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24744 if (!STRINGP (object
))
24745 object
= it
->w
->contents
;
24746 #ifdef HAVE_WINDOW_SYSTEM
24747 if (FRAME_WINDOW_P (it
->f
))
24748 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24752 it
->object
= object
;
24753 it
->char_to_display
= ' ';
24754 it
->pixel_width
= it
->len
= 1;
24756 tty_append_glyph (it
);
24757 it
->object
= o_object
;
24761 it
->pixel_width
= width
;
24762 #ifdef HAVE_WINDOW_SYSTEM
24763 if (FRAME_WINDOW_P (it
->f
))
24765 it
->ascent
= it
->phys_ascent
= ascent
;
24766 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24767 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24768 take_vertical_position_into_account (it
);
24772 it
->nglyphs
= width
;
24775 /* Get information about special display element WHAT in an
24776 environment described by IT. WHAT is one of IT_TRUNCATION or
24777 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24778 non-null glyph_row member. This function ensures that fields like
24779 face_id, c, len of IT are left untouched. */
24782 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24789 temp_it
.object
= make_number (0);
24790 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24792 if (what
== IT_CONTINUATION
)
24794 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24795 if (it
->bidi_it
.paragraph_dir
== R2L
)
24796 SET_GLYPH_FROM_CHAR (glyph
, '/');
24798 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24800 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24802 /* FIXME: Should we mirror GC for R2L lines? */
24803 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24804 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24807 else if (what
== IT_TRUNCATION
)
24809 /* Truncation glyph. */
24810 SET_GLYPH_FROM_CHAR (glyph
, '$');
24812 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24814 /* FIXME: Should we mirror GC for R2L lines? */
24815 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24816 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24822 #ifdef HAVE_WINDOW_SYSTEM
24823 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24824 is turned off, we precede the truncation/continuation glyphs by a
24825 stretch glyph whose width is computed such that these special
24826 glyphs are aligned at the window margin, even when very different
24827 fonts are used in different glyph rows. */
24828 if (FRAME_WINDOW_P (temp_it
.f
)
24829 /* init_iterator calls this with it->glyph_row == NULL, and it
24830 wants only the pixel width of the truncation/continuation
24832 && temp_it
.glyph_row
24833 /* insert_left_trunc_glyphs calls us at the beginning of the
24834 row, and it has its own calculation of the stretch glyph
24836 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24837 && (temp_it
.glyph_row
->reversed_p
24838 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24839 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24841 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24843 if (stretch_width
> 0)
24845 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24846 struct font
*font
=
24847 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24848 int stretch_ascent
=
24849 (((temp_it
.ascent
+ temp_it
.descent
)
24850 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24852 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24853 temp_it
.ascent
+ temp_it
.descent
,
24860 temp_it
.what
= IT_CHARACTER
;
24862 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24863 temp_it
.face_id
= GLYPH_FACE (glyph
);
24864 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24866 PRODUCE_GLYPHS (&temp_it
);
24867 it
->pixel_width
= temp_it
.pixel_width
;
24868 it
->nglyphs
= temp_it
.pixel_width
;
24871 #ifdef HAVE_WINDOW_SYSTEM
24873 /* Calculate line-height and line-spacing properties.
24874 An integer value specifies explicit pixel value.
24875 A float value specifies relative value to current face height.
24876 A cons (float . face-name) specifies relative value to
24877 height of specified face font.
24879 Returns height in pixels, or nil. */
24883 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24884 int boff
, int override
)
24886 Lisp_Object face_name
= Qnil
;
24887 int ascent
, descent
, height
;
24889 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24894 face_name
= XCAR (val
);
24896 if (!NUMBERP (val
))
24897 val
= make_number (1);
24898 if (NILP (face_name
))
24900 height
= it
->ascent
+ it
->descent
;
24905 if (NILP (face_name
))
24907 font
= FRAME_FONT (it
->f
);
24908 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24910 else if (EQ (face_name
, Qt
))
24919 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24921 return make_number (-1);
24923 face
= FACE_FROM_ID (it
->f
, face_id
);
24926 return make_number (-1);
24927 boff
= font
->baseline_offset
;
24928 if (font
->vertical_centering
)
24929 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24932 ascent
= FONT_BASE (font
) + boff
;
24933 descent
= FONT_DESCENT (font
) - boff
;
24937 it
->override_ascent
= ascent
;
24938 it
->override_descent
= descent
;
24939 it
->override_boff
= boff
;
24942 height
= ascent
+ descent
;
24946 height
= (int)(XFLOAT_DATA (val
) * height
);
24947 else if (INTEGERP (val
))
24948 height
*= XINT (val
);
24950 return make_number (height
);
24954 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24955 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24956 and only if this is for a character for which no font was found.
24958 If the display method (it->glyphless_method) is
24959 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24960 length of the acronym or the hexadecimal string, UPPER_XOFF and
24961 UPPER_YOFF are pixel offsets for the upper part of the string,
24962 LOWER_XOFF and LOWER_YOFF are for the lower part.
24964 For the other display methods, LEN through LOWER_YOFF are zero. */
24967 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24968 short upper_xoff
, short upper_yoff
,
24969 short lower_xoff
, short lower_yoff
)
24971 struct glyph
*glyph
;
24972 enum glyph_row_area area
= it
->area
;
24974 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24975 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24977 /* If the glyph row is reversed, we need to prepend the glyph
24978 rather than append it. */
24979 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24983 /* Make room for the additional glyph. */
24984 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24986 glyph
= it
->glyph_row
->glyphs
[area
];
24988 glyph
->charpos
= CHARPOS (it
->position
);
24989 glyph
->object
= it
->object
;
24990 glyph
->pixel_width
= it
->pixel_width
;
24991 glyph
->ascent
= it
->ascent
;
24992 glyph
->descent
= it
->descent
;
24993 glyph
->voffset
= it
->voffset
;
24994 glyph
->type
= GLYPHLESS_GLYPH
;
24995 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24996 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24997 glyph
->u
.glyphless
.len
= len
;
24998 glyph
->u
.glyphless
.ch
= it
->c
;
24999 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25000 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25001 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25002 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25003 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25004 glyph
->multibyte_p
= it
->multibyte_p
;
25005 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25007 /* In R2L rows, the left and the right box edges need to be
25008 drawn in reverse direction. */
25009 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25010 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25014 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25015 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25017 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25018 || it
->phys_descent
> it
->descent
);
25019 glyph
->padding_p
= 0;
25020 glyph
->glyph_not_available_p
= 0;
25021 glyph
->face_id
= face_id
;
25022 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25025 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25026 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25028 glyph
->bidi_type
= it
->bidi_it
.type
;
25030 ++it
->glyph_row
->used
[area
];
25033 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25037 /* Produce a glyph for a glyphless character for iterator IT.
25038 IT->glyphless_method specifies which method to use for displaying
25039 the character. See the description of enum
25040 glyphless_display_method in dispextern.h for the detail.
25042 FOR_NO_FONT is nonzero if and only if this is for a character for
25043 which no font was found. ACRONYM, if non-nil, is an acronym string
25044 for the character. */
25047 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25052 int base_width
, base_height
, width
, height
;
25053 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25056 /* Get the metrics of the base font. We always refer to the current
25058 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25059 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25060 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25061 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25062 base_height
= it
->ascent
+ it
->descent
;
25063 base_width
= font
->average_width
;
25065 face_id
= merge_glyphless_glyph_face (it
);
25067 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25069 it
->pixel_width
= THIN_SPACE_WIDTH
;
25071 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25073 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25075 width
= CHAR_WIDTH (it
->c
);
25078 else if (width
> 4)
25080 it
->pixel_width
= base_width
* width
;
25082 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25088 unsigned int code
[6];
25090 int ascent
, descent
;
25091 struct font_metrics metrics_upper
, metrics_lower
;
25093 face
= FACE_FROM_ID (it
->f
, face_id
);
25094 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25095 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25097 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25099 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25100 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25101 if (CONSP (acronym
))
25102 acronym
= XCAR (acronym
);
25103 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25107 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25108 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25111 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25112 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25113 upper_len
= (len
+ 1) / 2;
25114 font
->driver
->text_extents (font
, code
, upper_len
,
25116 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25121 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25122 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25123 upper_xoff
= upper_yoff
= 2; /* the typical case */
25124 if (base_width
>= width
)
25126 /* Align the upper to the left, the lower to the right. */
25127 it
->pixel_width
= base_width
;
25128 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25132 /* Center the shorter one. */
25133 it
->pixel_width
= width
;
25134 if (metrics_upper
.width
>= metrics_lower
.width
)
25135 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25138 /* FIXME: This code doesn't look right. It formerly was
25139 missing the "lower_xoff = 0;", which couldn't have
25140 been right since it left lower_xoff uninitialized. */
25142 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25146 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25147 top, bottom, and between upper and lower strings. */
25148 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25149 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25150 /* Center vertically.
25151 H:base_height, D:base_descent
25152 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25154 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25155 descent = D - H/2 + h/2;
25156 lower_yoff = descent - 2 - ld;
25157 upper_yoff = lower_yoff - la - 1 - ud; */
25158 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25159 descent
= it
->descent
- (base_height
- height
) / 2;
25160 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25161 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25162 - metrics_upper
.descent
);
25163 /* Don't make the height shorter than the base height. */
25164 if (height
> base_height
)
25166 it
->ascent
= ascent
;
25167 it
->descent
= descent
;
25171 it
->phys_ascent
= it
->ascent
;
25172 it
->phys_descent
= it
->descent
;
25174 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25175 upper_xoff
, upper_yoff
,
25176 lower_xoff
, lower_yoff
);
25178 take_vertical_position_into_account (it
);
25183 Produce glyphs/get display metrics for the display element IT is
25184 loaded with. See the description of struct it in dispextern.h
25185 for an overview of struct it. */
25188 x_produce_glyphs (struct it
*it
)
25190 int extra_line_spacing
= it
->extra_line_spacing
;
25192 it
->glyph_not_available_p
= 0;
25194 if (it
->what
== IT_CHARACTER
)
25197 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25198 struct font
*font
= face
->font
;
25199 struct font_metrics
*pcm
= NULL
;
25200 int boff
; /* Baseline offset. */
25204 /* When no suitable font is found, display this character by
25205 the method specified in the first extra slot of
25206 Vglyphless_char_display. */
25207 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25209 eassert (it
->what
== IT_GLYPHLESS
);
25210 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25214 boff
= font
->baseline_offset
;
25215 if (font
->vertical_centering
)
25216 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25218 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25224 if (it
->override_ascent
>= 0)
25226 it
->ascent
= it
->override_ascent
;
25227 it
->descent
= it
->override_descent
;
25228 boff
= it
->override_boff
;
25232 it
->ascent
= FONT_BASE (font
) + boff
;
25233 it
->descent
= FONT_DESCENT (font
) - boff
;
25236 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25238 pcm
= get_per_char_metric (font
, &char2b
);
25239 if (pcm
->width
== 0
25240 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25246 it
->phys_ascent
= pcm
->ascent
+ boff
;
25247 it
->phys_descent
= pcm
->descent
- boff
;
25248 it
->pixel_width
= pcm
->width
;
25252 it
->glyph_not_available_p
= 1;
25253 it
->phys_ascent
= it
->ascent
;
25254 it
->phys_descent
= it
->descent
;
25255 it
->pixel_width
= font
->space_width
;
25258 if (it
->constrain_row_ascent_descent_p
)
25260 if (it
->descent
> it
->max_descent
)
25262 it
->ascent
+= it
->descent
- it
->max_descent
;
25263 it
->descent
= it
->max_descent
;
25265 if (it
->ascent
> it
->max_ascent
)
25267 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25268 it
->ascent
= it
->max_ascent
;
25270 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25271 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25272 extra_line_spacing
= 0;
25275 /* If this is a space inside a region of text with
25276 `space-width' property, change its width. */
25277 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25279 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25281 /* If face has a box, add the box thickness to the character
25282 height. If character has a box line to the left and/or
25283 right, add the box line width to the character's width. */
25284 if (face
->box
!= FACE_NO_BOX
)
25286 int thick
= face
->box_line_width
;
25290 it
->ascent
+= thick
;
25291 it
->descent
+= thick
;
25296 if (it
->start_of_box_run_p
)
25297 it
->pixel_width
+= thick
;
25298 if (it
->end_of_box_run_p
)
25299 it
->pixel_width
+= thick
;
25302 /* If face has an overline, add the height of the overline
25303 (1 pixel) and a 1 pixel margin to the character height. */
25304 if (face
->overline_p
)
25305 it
->ascent
+= overline_margin
;
25307 if (it
->constrain_row_ascent_descent_p
)
25309 if (it
->ascent
> it
->max_ascent
)
25310 it
->ascent
= it
->max_ascent
;
25311 if (it
->descent
> it
->max_descent
)
25312 it
->descent
= it
->max_descent
;
25315 take_vertical_position_into_account (it
);
25317 /* If we have to actually produce glyphs, do it. */
25322 /* Translate a space with a `space-width' property
25323 into a stretch glyph. */
25324 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25325 / FONT_HEIGHT (font
));
25326 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25327 it
->ascent
+ it
->descent
, ascent
);
25332 /* If characters with lbearing or rbearing are displayed
25333 in this line, record that fact in a flag of the
25334 glyph row. This is used to optimize X output code. */
25335 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25336 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25338 if (! stretched_p
&& it
->pixel_width
== 0)
25339 /* We assure that all visible glyphs have at least 1-pixel
25341 it
->pixel_width
= 1;
25343 else if (it
->char_to_display
== '\n')
25345 /* A newline has no width, but we need the height of the
25346 line. But if previous part of the line sets a height,
25347 don't increase that height. */
25349 Lisp_Object height
;
25350 Lisp_Object total_height
= Qnil
;
25352 it
->override_ascent
= -1;
25353 it
->pixel_width
= 0;
25356 height
= get_it_property (it
, Qline_height
);
25357 /* Split (line-height total-height) list. */
25359 && CONSP (XCDR (height
))
25360 && NILP (XCDR (XCDR (height
))))
25362 total_height
= XCAR (XCDR (height
));
25363 height
= XCAR (height
);
25365 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25367 if (it
->override_ascent
>= 0)
25369 it
->ascent
= it
->override_ascent
;
25370 it
->descent
= it
->override_descent
;
25371 boff
= it
->override_boff
;
25375 it
->ascent
= FONT_BASE (font
) + boff
;
25376 it
->descent
= FONT_DESCENT (font
) - boff
;
25379 if (EQ (height
, Qt
))
25381 if (it
->descent
> it
->max_descent
)
25383 it
->ascent
+= it
->descent
- it
->max_descent
;
25384 it
->descent
= it
->max_descent
;
25386 if (it
->ascent
> it
->max_ascent
)
25388 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25389 it
->ascent
= it
->max_ascent
;
25391 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25392 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25393 it
->constrain_row_ascent_descent_p
= 1;
25394 extra_line_spacing
= 0;
25398 Lisp_Object spacing
;
25400 it
->phys_ascent
= it
->ascent
;
25401 it
->phys_descent
= it
->descent
;
25403 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25404 && face
->box
!= FACE_NO_BOX
25405 && face
->box_line_width
> 0)
25407 it
->ascent
+= face
->box_line_width
;
25408 it
->descent
+= face
->box_line_width
;
25411 && XINT (height
) > it
->ascent
+ it
->descent
)
25412 it
->ascent
= XINT (height
) - it
->descent
;
25414 if (!NILP (total_height
))
25415 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25418 spacing
= get_it_property (it
, Qline_spacing
);
25419 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25421 if (INTEGERP (spacing
))
25423 extra_line_spacing
= XINT (spacing
);
25424 if (!NILP (total_height
))
25425 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25429 else /* i.e. (it->char_to_display == '\t') */
25431 if (font
->space_width
> 0)
25433 int tab_width
= it
->tab_width
* font
->space_width
;
25434 int x
= it
->current_x
+ it
->continuation_lines_width
;
25435 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25437 /* If the distance from the current position to the next tab
25438 stop is less than a space character width, use the
25439 tab stop after that. */
25440 if (next_tab_x
- x
< font
->space_width
)
25441 next_tab_x
+= tab_width
;
25443 it
->pixel_width
= next_tab_x
- x
;
25445 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25446 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25450 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25451 it
->ascent
+ it
->descent
, it
->ascent
);
25456 it
->pixel_width
= 0;
25461 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25463 /* A static composition.
25465 Note: A composition is represented as one glyph in the
25466 glyph matrix. There are no padding glyphs.
25468 Important note: pixel_width, ascent, and descent are the
25469 values of what is drawn by draw_glyphs (i.e. the values of
25470 the overall glyphs composed). */
25471 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25472 int boff
; /* baseline offset */
25473 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25474 int glyph_len
= cmp
->glyph_len
;
25475 struct font
*font
= face
->font
;
25479 /* If we have not yet calculated pixel size data of glyphs of
25480 the composition for the current face font, calculate them
25481 now. Theoretically, we have to check all fonts for the
25482 glyphs, but that requires much time and memory space. So,
25483 here we check only the font of the first glyph. This may
25484 lead to incorrect display, but it's very rare, and C-l
25485 (recenter-top-bottom) can correct the display anyway. */
25486 if (! cmp
->font
|| cmp
->font
!= font
)
25488 /* Ascent and descent of the font of the first character
25489 of this composition (adjusted by baseline offset).
25490 Ascent and descent of overall glyphs should not be less
25491 than these, respectively. */
25492 int font_ascent
, font_descent
, font_height
;
25493 /* Bounding box of the overall glyphs. */
25494 int leftmost
, rightmost
, lowest
, highest
;
25495 int lbearing
, rbearing
;
25496 int i
, width
, ascent
, descent
;
25497 int left_padded
= 0, right_padded
= 0;
25498 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25500 struct font_metrics
*pcm
;
25501 int font_not_found_p
;
25504 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25505 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25507 if (glyph_len
< cmp
->glyph_len
)
25509 for (i
= 0; i
< glyph_len
; i
++)
25511 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25513 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25518 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25519 : IT_CHARPOS (*it
));
25520 /* If no suitable font is found, use the default font. */
25521 font_not_found_p
= font
== NULL
;
25522 if (font_not_found_p
)
25524 face
= face
->ascii_face
;
25527 boff
= font
->baseline_offset
;
25528 if (font
->vertical_centering
)
25529 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25530 font_ascent
= FONT_BASE (font
) + boff
;
25531 font_descent
= FONT_DESCENT (font
) - boff
;
25532 font_height
= FONT_HEIGHT (font
);
25537 if (! font_not_found_p
)
25539 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25541 pcm
= get_per_char_metric (font
, &char2b
);
25544 /* Initialize the bounding box. */
25547 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25548 ascent
= pcm
->ascent
;
25549 descent
= pcm
->descent
;
25550 lbearing
= pcm
->lbearing
;
25551 rbearing
= pcm
->rbearing
;
25555 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25556 ascent
= FONT_BASE (font
);
25557 descent
= FONT_DESCENT (font
);
25564 lowest
= - descent
+ boff
;
25565 highest
= ascent
+ boff
;
25567 if (! font_not_found_p
25568 && font
->default_ascent
25569 && CHAR_TABLE_P (Vuse_default_ascent
)
25570 && !NILP (Faref (Vuse_default_ascent
,
25571 make_number (it
->char_to_display
))))
25572 highest
= font
->default_ascent
+ boff
;
25574 /* Draw the first glyph at the normal position. It may be
25575 shifted to right later if some other glyphs are drawn
25577 cmp
->offsets
[i
* 2] = 0;
25578 cmp
->offsets
[i
* 2 + 1] = boff
;
25579 cmp
->lbearing
= lbearing
;
25580 cmp
->rbearing
= rbearing
;
25582 /* Set cmp->offsets for the remaining glyphs. */
25583 for (i
++; i
< glyph_len
; i
++)
25585 int left
, right
, btm
, top
;
25586 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25588 struct face
*this_face
;
25592 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25593 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25594 font
= this_face
->font
;
25600 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25602 pcm
= get_per_char_metric (font
, &char2b
);
25605 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25608 width
= pcm
->width
;
25609 ascent
= pcm
->ascent
;
25610 descent
= pcm
->descent
;
25611 lbearing
= pcm
->lbearing
;
25612 rbearing
= pcm
->rbearing
;
25613 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25615 /* Relative composition with or without
25616 alternate chars. */
25617 left
= (leftmost
+ rightmost
- width
) / 2;
25618 btm
= - descent
+ boff
;
25619 if (font
->relative_compose
25620 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25621 || NILP (Faref (Vignore_relative_composition
,
25622 make_number (ch
)))))
25625 if (- descent
>= font
->relative_compose
)
25626 /* One extra pixel between two glyphs. */
25628 else if (ascent
<= 0)
25629 /* One extra pixel between two glyphs. */
25630 btm
= lowest
- 1 - ascent
- descent
;
25635 /* A composition rule is specified by an integer
25636 value that encodes global and new reference
25637 points (GREF and NREF). GREF and NREF are
25638 specified by numbers as below:
25640 0---1---2 -- ascent
25644 9--10--11 -- center
25646 ---3---4---5--- baseline
25648 6---7---8 -- descent
25650 int rule
= COMPOSITION_RULE (cmp
, i
);
25651 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25653 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25654 grefx
= gref
% 3, nrefx
= nref
% 3;
25655 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25657 xoff
= font_height
* (xoff
- 128) / 256;
25659 yoff
= font_height
* (yoff
- 128) / 256;
25662 + grefx
* (rightmost
- leftmost
) / 2
25663 - nrefx
* width
/ 2
25666 btm
= ((grefy
== 0 ? highest
25668 : grefy
== 2 ? lowest
25669 : (highest
+ lowest
) / 2)
25670 - (nrefy
== 0 ? ascent
+ descent
25671 : nrefy
== 1 ? descent
- boff
25673 : (ascent
+ descent
) / 2)
25677 cmp
->offsets
[i
* 2] = left
;
25678 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25680 /* Update the bounding box of the overall glyphs. */
25683 right
= left
+ width
;
25684 if (left
< leftmost
)
25686 if (right
> rightmost
)
25689 top
= btm
+ descent
+ ascent
;
25695 if (cmp
->lbearing
> left
+ lbearing
)
25696 cmp
->lbearing
= left
+ lbearing
;
25697 if (cmp
->rbearing
< left
+ rbearing
)
25698 cmp
->rbearing
= left
+ rbearing
;
25702 /* If there are glyphs whose x-offsets are negative,
25703 shift all glyphs to the right and make all x-offsets
25707 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25708 cmp
->offsets
[i
* 2] -= leftmost
;
25709 rightmost
-= leftmost
;
25710 cmp
->lbearing
-= leftmost
;
25711 cmp
->rbearing
-= leftmost
;
25714 if (left_padded
&& cmp
->lbearing
< 0)
25716 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25717 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25718 rightmost
-= cmp
->lbearing
;
25719 cmp
->rbearing
-= cmp
->lbearing
;
25722 if (right_padded
&& rightmost
< cmp
->rbearing
)
25724 rightmost
= cmp
->rbearing
;
25727 cmp
->pixel_width
= rightmost
;
25728 cmp
->ascent
= highest
;
25729 cmp
->descent
= - lowest
;
25730 if (cmp
->ascent
< font_ascent
)
25731 cmp
->ascent
= font_ascent
;
25732 if (cmp
->descent
< font_descent
)
25733 cmp
->descent
= font_descent
;
25737 && (cmp
->lbearing
< 0
25738 || cmp
->rbearing
> cmp
->pixel_width
))
25739 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25741 it
->pixel_width
= cmp
->pixel_width
;
25742 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25743 it
->descent
= it
->phys_descent
= cmp
->descent
;
25744 if (face
->box
!= FACE_NO_BOX
)
25746 int thick
= face
->box_line_width
;
25750 it
->ascent
+= thick
;
25751 it
->descent
+= thick
;
25756 if (it
->start_of_box_run_p
)
25757 it
->pixel_width
+= thick
;
25758 if (it
->end_of_box_run_p
)
25759 it
->pixel_width
+= thick
;
25762 /* If face has an overline, add the height of the overline
25763 (1 pixel) and a 1 pixel margin to the character height. */
25764 if (face
->overline_p
)
25765 it
->ascent
+= overline_margin
;
25767 take_vertical_position_into_account (it
);
25768 if (it
->ascent
< 0)
25770 if (it
->descent
< 0)
25773 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25774 append_composite_glyph (it
);
25776 else if (it
->what
== IT_COMPOSITION
)
25778 /* A dynamic (automatic) composition. */
25779 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25780 Lisp_Object gstring
;
25781 struct font_metrics metrics
;
25785 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25787 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25790 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25791 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25792 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25793 it
->descent
= it
->phys_descent
= metrics
.descent
;
25794 if (face
->box
!= FACE_NO_BOX
)
25796 int thick
= face
->box_line_width
;
25800 it
->ascent
+= thick
;
25801 it
->descent
+= thick
;
25806 if (it
->start_of_box_run_p
)
25807 it
->pixel_width
+= thick
;
25808 if (it
->end_of_box_run_p
)
25809 it
->pixel_width
+= thick
;
25811 /* If face has an overline, add the height of the overline
25812 (1 pixel) and a 1 pixel margin to the character height. */
25813 if (face
->overline_p
)
25814 it
->ascent
+= overline_margin
;
25815 take_vertical_position_into_account (it
);
25816 if (it
->ascent
< 0)
25818 if (it
->descent
< 0)
25822 append_composite_glyph (it
);
25824 else if (it
->what
== IT_GLYPHLESS
)
25825 produce_glyphless_glyph (it
, 0, Qnil
);
25826 else if (it
->what
== IT_IMAGE
)
25827 produce_image_glyph (it
);
25828 else if (it
->what
== IT_STRETCH
)
25829 produce_stretch_glyph (it
);
25832 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25833 because this isn't true for images with `:ascent 100'. */
25834 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25835 if (it
->area
== TEXT_AREA
)
25836 it
->current_x
+= it
->pixel_width
;
25838 if (extra_line_spacing
> 0)
25840 it
->descent
+= extra_line_spacing
;
25841 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25842 it
->max_extra_line_spacing
= extra_line_spacing
;
25845 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25846 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25847 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25848 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25852 Output LEN glyphs starting at START at the nominal cursor position.
25853 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25854 being updated, and UPDATED_AREA is the area of that row being updated. */
25857 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25858 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25860 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25862 eassert (updated_row
);
25863 /* When the window is hscrolled, cursor hpos can legitimately be out
25864 of bounds, but we draw the cursor at the corresponding window
25865 margin in that case. */
25866 if (!updated_row
->reversed_p
&& chpos
< 0)
25868 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25869 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25873 /* Write glyphs. */
25875 hpos
= start
- updated_row
->glyphs
[updated_area
];
25876 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25877 updated_row
, updated_area
,
25879 DRAW_NORMAL_TEXT
, 0);
25881 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25882 if (updated_area
== TEXT_AREA
25883 && w
->phys_cursor_on_p
25884 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25886 && chpos
< hpos
+ len
)
25887 w
->phys_cursor_on_p
= 0;
25891 /* Advance the output cursor. */
25892 w
->output_cursor
.hpos
+= len
;
25893 w
->output_cursor
.x
= x
;
25898 Insert LEN glyphs from START at the nominal cursor position. */
25901 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25902 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25905 int line_height
, shift_by_width
, shifted_region_width
;
25906 struct glyph_row
*row
;
25907 struct glyph
*glyph
;
25908 int frame_x
, frame_y
;
25911 eassert (updated_row
);
25913 f
= XFRAME (WINDOW_FRAME (w
));
25915 /* Get the height of the line we are in. */
25917 line_height
= row
->height
;
25919 /* Get the width of the glyphs to insert. */
25920 shift_by_width
= 0;
25921 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25922 shift_by_width
+= glyph
->pixel_width
;
25924 /* Get the width of the region to shift right. */
25925 shifted_region_width
= (window_box_width (w
, updated_area
)
25926 - w
->output_cursor
.x
25930 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25931 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25933 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25934 line_height
, shift_by_width
);
25936 /* Write the glyphs. */
25937 hpos
= start
- row
->glyphs
[updated_area
];
25938 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25940 DRAW_NORMAL_TEXT
, 0);
25942 /* Advance the output cursor. */
25943 w
->output_cursor
.hpos
+= len
;
25944 w
->output_cursor
.x
+= shift_by_width
;
25950 Erase the current text line from the nominal cursor position
25951 (inclusive) to pixel column TO_X (exclusive). The idea is that
25952 everything from TO_X onward is already erased.
25954 TO_X is a pixel position relative to UPDATED_AREA of currently
25955 updated window W. TO_X == -1 means clear to the end of this area. */
25958 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25959 enum glyph_row_area updated_area
, int to_x
)
25962 int max_x
, min_y
, max_y
;
25963 int from_x
, from_y
, to_y
;
25965 eassert (updated_row
);
25966 f
= XFRAME (w
->frame
);
25968 if (updated_row
->full_width_p
)
25969 max_x
= WINDOW_TOTAL_WIDTH (w
);
25971 max_x
= window_box_width (w
, updated_area
);
25972 max_y
= window_text_bottom_y (w
);
25974 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25975 of window. For TO_X > 0, truncate to end of drawing area. */
25981 to_x
= min (to_x
, max_x
);
25983 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25985 /* Notice if the cursor will be cleared by this operation. */
25986 if (!updated_row
->full_width_p
)
25987 notice_overwritten_cursor (w
, updated_area
,
25988 w
->output_cursor
.x
, -1,
25990 MATRIX_ROW_BOTTOM_Y (updated_row
));
25992 from_x
= w
->output_cursor
.x
;
25994 /* Translate to frame coordinates. */
25995 if (updated_row
->full_width_p
)
25997 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25998 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26002 int area_left
= window_box_left (w
, updated_area
);
26003 from_x
+= area_left
;
26007 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26008 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26009 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26011 /* Prevent inadvertently clearing to end of the X window. */
26012 if (to_x
> from_x
&& to_y
> from_y
)
26015 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26016 to_x
- from_x
, to_y
- from_y
);
26021 #endif /* HAVE_WINDOW_SYSTEM */
26025 /***********************************************************************
26027 ***********************************************************************/
26029 /* Value is the internal representation of the specified cursor type
26030 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26031 of the bar cursor. */
26033 static enum text_cursor_kinds
26034 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26036 enum text_cursor_kinds type
;
26041 if (EQ (arg
, Qbox
))
26042 return FILLED_BOX_CURSOR
;
26044 if (EQ (arg
, Qhollow
))
26045 return HOLLOW_BOX_CURSOR
;
26047 if (EQ (arg
, Qbar
))
26054 && EQ (XCAR (arg
), Qbar
)
26055 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26057 *width
= XINT (XCDR (arg
));
26061 if (EQ (arg
, Qhbar
))
26064 return HBAR_CURSOR
;
26068 && EQ (XCAR (arg
), Qhbar
)
26069 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26071 *width
= XINT (XCDR (arg
));
26072 return HBAR_CURSOR
;
26075 /* Treat anything unknown as "hollow box cursor".
26076 It was bad to signal an error; people have trouble fixing
26077 .Xdefaults with Emacs, when it has something bad in it. */
26078 type
= HOLLOW_BOX_CURSOR
;
26083 /* Set the default cursor types for specified frame. */
26085 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26090 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26091 FRAME_CURSOR_WIDTH (f
) = width
;
26093 /* By default, set up the blink-off state depending on the on-state. */
26095 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26098 FRAME_BLINK_OFF_CURSOR (f
)
26099 = get_specified_cursor_type (XCDR (tem
), &width
);
26100 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26103 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26105 /* Make sure the cursor gets redrawn. */
26106 f
->cursor_type_changed
= 1;
26110 #ifdef HAVE_WINDOW_SYSTEM
26112 /* Return the cursor we want to be displayed in window W. Return
26113 width of bar/hbar cursor through WIDTH arg. Return with
26114 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26115 (i.e. if the `system caret' should track this cursor).
26117 In a mini-buffer window, we want the cursor only to appear if we
26118 are reading input from this window. For the selected window, we
26119 want the cursor type given by the frame parameter or buffer local
26120 setting of cursor-type. If explicitly marked off, draw no cursor.
26121 In all other cases, we want a hollow box cursor. */
26123 static enum text_cursor_kinds
26124 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26125 int *active_cursor
)
26127 struct frame
*f
= XFRAME (w
->frame
);
26128 struct buffer
*b
= XBUFFER (w
->contents
);
26129 int cursor_type
= DEFAULT_CURSOR
;
26130 Lisp_Object alt_cursor
;
26131 int non_selected
= 0;
26133 *active_cursor
= 1;
26136 if (cursor_in_echo_area
26137 && FRAME_HAS_MINIBUF_P (f
)
26138 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26140 if (w
== XWINDOW (echo_area_window
))
26142 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26144 *width
= FRAME_CURSOR_WIDTH (f
);
26145 return FRAME_DESIRED_CURSOR (f
);
26148 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26151 *active_cursor
= 0;
26155 /* Detect a nonselected window or nonselected frame. */
26156 else if (w
!= XWINDOW (f
->selected_window
)
26157 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26159 *active_cursor
= 0;
26161 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26167 /* Never display a cursor in a window in which cursor-type is nil. */
26168 if (NILP (BVAR (b
, cursor_type
)))
26171 /* Get the normal cursor type for this window. */
26172 if (EQ (BVAR (b
, cursor_type
), Qt
))
26174 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26175 *width
= FRAME_CURSOR_WIDTH (f
);
26178 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26180 /* Use cursor-in-non-selected-windows instead
26181 for non-selected window or frame. */
26184 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26185 if (!EQ (Qt
, alt_cursor
))
26186 return get_specified_cursor_type (alt_cursor
, width
);
26187 /* t means modify the normal cursor type. */
26188 if (cursor_type
== FILLED_BOX_CURSOR
)
26189 cursor_type
= HOLLOW_BOX_CURSOR
;
26190 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26192 return cursor_type
;
26195 /* Use normal cursor if not blinked off. */
26196 if (!w
->cursor_off_p
)
26198 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26200 if (cursor_type
== FILLED_BOX_CURSOR
)
26202 /* Using a block cursor on large images can be very annoying.
26203 So use a hollow cursor for "large" images.
26204 If image is not transparent (no mask), also use hollow cursor. */
26205 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26206 if (img
!= NULL
&& IMAGEP (img
->spec
))
26208 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26209 where N = size of default frame font size.
26210 This should cover most of the "tiny" icons people may use. */
26212 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26213 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26214 cursor_type
= HOLLOW_BOX_CURSOR
;
26217 else if (cursor_type
!= NO_CURSOR
)
26219 /* Display current only supports BOX and HOLLOW cursors for images.
26220 So for now, unconditionally use a HOLLOW cursor when cursor is
26221 not a solid box cursor. */
26222 cursor_type
= HOLLOW_BOX_CURSOR
;
26225 return cursor_type
;
26228 /* Cursor is blinked off, so determine how to "toggle" it. */
26230 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26231 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26232 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26234 /* Then see if frame has specified a specific blink off cursor type. */
26235 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26237 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26238 return FRAME_BLINK_OFF_CURSOR (f
);
26242 /* Some people liked having a permanently visible blinking cursor,
26243 while others had very strong opinions against it. So it was
26244 decided to remove it. KFS 2003-09-03 */
26246 /* Finally perform built-in cursor blinking:
26247 filled box <-> hollow box
26248 wide [h]bar <-> narrow [h]bar
26249 narrow [h]bar <-> no cursor
26250 other type <-> no cursor */
26252 if (cursor_type
== FILLED_BOX_CURSOR
)
26253 return HOLLOW_BOX_CURSOR
;
26255 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26258 return cursor_type
;
26266 /* Notice when the text cursor of window W has been completely
26267 overwritten by a drawing operation that outputs glyphs in AREA
26268 starting at X0 and ending at X1 in the line starting at Y0 and
26269 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26270 the rest of the line after X0 has been written. Y coordinates
26271 are window-relative. */
26274 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26275 int x0
, int x1
, int y0
, int y1
)
26277 int cx0
, cx1
, cy0
, cy1
;
26278 struct glyph_row
*row
;
26280 if (!w
->phys_cursor_on_p
)
26282 if (area
!= TEXT_AREA
)
26285 if (w
->phys_cursor
.vpos
< 0
26286 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26287 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26288 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26291 if (row
->cursor_in_fringe_p
)
26293 row
->cursor_in_fringe_p
= 0;
26294 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26295 w
->phys_cursor_on_p
= 0;
26299 cx0
= w
->phys_cursor
.x
;
26300 cx1
= cx0
+ w
->phys_cursor_width
;
26301 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26304 /* The cursor image will be completely removed from the
26305 screen if the output area intersects the cursor area in
26306 y-direction. When we draw in [y0 y1[, and some part of
26307 the cursor is at y < y0, that part must have been drawn
26308 before. When scrolling, the cursor is erased before
26309 actually scrolling, so we don't come here. When not
26310 scrolling, the rows above the old cursor row must have
26311 changed, and in this case these rows must have written
26312 over the cursor image.
26314 Likewise if part of the cursor is below y1, with the
26315 exception of the cursor being in the first blank row at
26316 the buffer and window end because update_text_area
26317 doesn't draw that row. (Except when it does, but
26318 that's handled in update_text_area.) */
26320 cy0
= w
->phys_cursor
.y
;
26321 cy1
= cy0
+ w
->phys_cursor_height
;
26322 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26325 w
->phys_cursor_on_p
= 0;
26328 #endif /* HAVE_WINDOW_SYSTEM */
26331 /************************************************************************
26333 ************************************************************************/
26335 #ifdef HAVE_WINDOW_SYSTEM
26338 Fix the display of area AREA of overlapping row ROW in window W
26339 with respect to the overlapping part OVERLAPS. */
26342 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26343 enum glyph_row_area area
, int overlaps
)
26350 for (i
= 0; i
< row
->used
[area
];)
26352 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26354 int start
= i
, start_x
= x
;
26358 x
+= row
->glyphs
[area
][i
].pixel_width
;
26361 while (i
< row
->used
[area
]
26362 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26364 draw_glyphs (w
, start_x
, row
, area
,
26366 DRAW_NORMAL_TEXT
, overlaps
);
26370 x
+= row
->glyphs
[area
][i
].pixel_width
;
26380 Draw the cursor glyph of window W in glyph row ROW. See the
26381 comment of draw_glyphs for the meaning of HL. */
26384 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26385 enum draw_glyphs_face hl
)
26387 /* If cursor hpos is out of bounds, don't draw garbage. This can
26388 happen in mini-buffer windows when switching between echo area
26389 glyphs and mini-buffer. */
26390 if ((row
->reversed_p
26391 ? (w
->phys_cursor
.hpos
>= 0)
26392 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26394 int on_p
= w
->phys_cursor_on_p
;
26396 int hpos
= w
->phys_cursor
.hpos
;
26398 /* When the window is hscrolled, cursor hpos can legitimately be
26399 out of bounds, but we draw the cursor at the corresponding
26400 window margin in that case. */
26401 if (!row
->reversed_p
&& hpos
< 0)
26403 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26404 hpos
= row
->used
[TEXT_AREA
] - 1;
26406 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26408 w
->phys_cursor_on_p
= on_p
;
26410 if (hl
== DRAW_CURSOR
)
26411 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26412 /* When we erase the cursor, and ROW is overlapped by other
26413 rows, make sure that these overlapping parts of other rows
26415 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26417 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26419 if (row
> w
->current_matrix
->rows
26420 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26421 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26422 OVERLAPS_ERASED_CURSOR
);
26424 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26425 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26426 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26427 OVERLAPS_ERASED_CURSOR
);
26433 /* Erase the image of a cursor of window W from the screen. */
26439 erase_phys_cursor (struct window
*w
)
26441 struct frame
*f
= XFRAME (w
->frame
);
26442 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26443 int hpos
= w
->phys_cursor
.hpos
;
26444 int vpos
= w
->phys_cursor
.vpos
;
26445 int mouse_face_here_p
= 0;
26446 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26447 struct glyph_row
*cursor_row
;
26448 struct glyph
*cursor_glyph
;
26449 enum draw_glyphs_face hl
;
26451 /* No cursor displayed or row invalidated => nothing to do on the
26453 if (w
->phys_cursor_type
== NO_CURSOR
)
26454 goto mark_cursor_off
;
26456 /* VPOS >= active_glyphs->nrows means that window has been resized.
26457 Don't bother to erase the cursor. */
26458 if (vpos
>= active_glyphs
->nrows
)
26459 goto mark_cursor_off
;
26461 /* If row containing cursor is marked invalid, there is nothing we
26463 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26464 if (!cursor_row
->enabled_p
)
26465 goto mark_cursor_off
;
26467 /* If line spacing is > 0, old cursor may only be partially visible in
26468 window after split-window. So adjust visible height. */
26469 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26470 window_text_bottom_y (w
) - cursor_row
->y
);
26472 /* If row is completely invisible, don't attempt to delete a cursor which
26473 isn't there. This can happen if cursor is at top of a window, and
26474 we switch to a buffer with a header line in that window. */
26475 if (cursor_row
->visible_height
<= 0)
26476 goto mark_cursor_off
;
26478 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26479 if (cursor_row
->cursor_in_fringe_p
)
26481 cursor_row
->cursor_in_fringe_p
= 0;
26482 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26483 goto mark_cursor_off
;
26486 /* This can happen when the new row is shorter than the old one.
26487 In this case, either draw_glyphs or clear_end_of_line
26488 should have cleared the cursor. Note that we wouldn't be
26489 able to erase the cursor in this case because we don't have a
26490 cursor glyph at hand. */
26491 if ((cursor_row
->reversed_p
26492 ? (w
->phys_cursor
.hpos
< 0)
26493 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26494 goto mark_cursor_off
;
26496 /* When the window is hscrolled, cursor hpos can legitimately be out
26497 of bounds, but we draw the cursor at the corresponding window
26498 margin in that case. */
26499 if (!cursor_row
->reversed_p
&& hpos
< 0)
26501 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26502 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26504 /* If the cursor is in the mouse face area, redisplay that when
26505 we clear the cursor. */
26506 if (! NILP (hlinfo
->mouse_face_window
)
26507 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26508 /* Don't redraw the cursor's spot in mouse face if it is at the
26509 end of a line (on a newline). The cursor appears there, but
26510 mouse highlighting does not. */
26511 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26512 mouse_face_here_p
= 1;
26514 /* Maybe clear the display under the cursor. */
26515 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26518 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26521 cursor_glyph
= get_phys_cursor_glyph (w
);
26522 if (cursor_glyph
== NULL
)
26523 goto mark_cursor_off
;
26525 width
= cursor_glyph
->pixel_width
;
26526 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26527 x
= w
->phys_cursor
.x
;
26529 width
-= left_x
- x
;
26530 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26531 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26532 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26535 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26538 /* Erase the cursor by redrawing the character underneath it. */
26539 if (mouse_face_here_p
)
26540 hl
= DRAW_MOUSE_FACE
;
26542 hl
= DRAW_NORMAL_TEXT
;
26543 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26546 w
->phys_cursor_on_p
= 0;
26547 w
->phys_cursor_type
= NO_CURSOR
;
26552 Display or clear cursor of window W. If ON is zero, clear the
26553 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26554 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26557 display_and_set_cursor (struct window
*w
, bool on
,
26558 int hpos
, int vpos
, int x
, int y
)
26560 struct frame
*f
= XFRAME (w
->frame
);
26561 int new_cursor_type
;
26562 int new_cursor_width
;
26564 struct glyph_row
*glyph_row
;
26565 struct glyph
*glyph
;
26567 /* This is pointless on invisible frames, and dangerous on garbaged
26568 windows and frames; in the latter case, the frame or window may
26569 be in the midst of changing its size, and x and y may be off the
26571 if (! FRAME_VISIBLE_P (f
)
26572 || FRAME_GARBAGED_P (f
)
26573 || vpos
>= w
->current_matrix
->nrows
26574 || hpos
>= w
->current_matrix
->matrix_w
)
26577 /* If cursor is off and we want it off, return quickly. */
26578 if (!on
&& !w
->phys_cursor_on_p
)
26581 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26582 /* If cursor row is not enabled, we don't really know where to
26583 display the cursor. */
26584 if (!glyph_row
->enabled_p
)
26586 w
->phys_cursor_on_p
= 0;
26591 if (!glyph_row
->exact_window_width_line_p
26592 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26593 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26595 eassert (input_blocked_p ());
26597 /* Set new_cursor_type to the cursor we want to be displayed. */
26598 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26599 &new_cursor_width
, &active_cursor
);
26601 /* If cursor is currently being shown and we don't want it to be or
26602 it is in the wrong place, or the cursor type is not what we want,
26604 if (w
->phys_cursor_on_p
26606 || w
->phys_cursor
.x
!= x
26607 || w
->phys_cursor
.y
!= y
26608 || new_cursor_type
!= w
->phys_cursor_type
26609 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26610 && new_cursor_width
!= w
->phys_cursor_width
)))
26611 erase_phys_cursor (w
);
26613 /* Don't check phys_cursor_on_p here because that flag is only set
26614 to zero in some cases where we know that the cursor has been
26615 completely erased, to avoid the extra work of erasing the cursor
26616 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26617 still not be visible, or it has only been partly erased. */
26620 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26621 w
->phys_cursor_height
= glyph_row
->height
;
26623 /* Set phys_cursor_.* before x_draw_.* is called because some
26624 of them may need the information. */
26625 w
->phys_cursor
.x
= x
;
26626 w
->phys_cursor
.y
= glyph_row
->y
;
26627 w
->phys_cursor
.hpos
= hpos
;
26628 w
->phys_cursor
.vpos
= vpos
;
26631 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26632 new_cursor_type
, new_cursor_width
,
26633 on
, active_cursor
);
26637 /* Switch the display of W's cursor on or off, according to the value
26641 update_window_cursor (struct window
*w
, bool on
)
26643 /* Don't update cursor in windows whose frame is in the process
26644 of being deleted. */
26645 if (w
->current_matrix
)
26647 int hpos
= w
->phys_cursor
.hpos
;
26648 int vpos
= w
->phys_cursor
.vpos
;
26649 struct glyph_row
*row
;
26651 if (vpos
>= w
->current_matrix
->nrows
26652 || hpos
>= w
->current_matrix
->matrix_w
)
26655 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26657 /* When the window is hscrolled, cursor hpos can legitimately be
26658 out of bounds, but we draw the cursor at the corresponding
26659 window margin in that case. */
26660 if (!row
->reversed_p
&& hpos
< 0)
26662 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26663 hpos
= row
->used
[TEXT_AREA
] - 1;
26666 display_and_set_cursor (w
, on
, hpos
, vpos
,
26667 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26673 /* Call update_window_cursor with parameter ON_P on all leaf windows
26674 in the window tree rooted at W. */
26677 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26681 if (WINDOWP (w
->contents
))
26682 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26684 update_window_cursor (w
, on_p
);
26686 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26692 Display the cursor on window W, or clear it, according to ON_P.
26693 Don't change the cursor's position. */
26696 x_update_cursor (struct frame
*f
, bool on_p
)
26698 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26703 Clear the cursor of window W to background color, and mark the
26704 cursor as not shown. This is used when the text where the cursor
26705 is about to be rewritten. */
26708 x_clear_cursor (struct window
*w
)
26710 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26711 update_window_cursor (w
, 0);
26714 #endif /* HAVE_WINDOW_SYSTEM */
26716 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26719 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26720 int start_hpos
, int end_hpos
,
26721 enum draw_glyphs_face draw
)
26723 #ifdef HAVE_WINDOW_SYSTEM
26724 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26726 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26730 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26731 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26735 /* Display the active region described by mouse_face_* according to DRAW. */
26738 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26740 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26741 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26743 if (/* If window is in the process of being destroyed, don't bother
26745 w
->current_matrix
!= NULL
26746 /* Don't update mouse highlight if hidden */
26747 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26748 /* Recognize when we are called to operate on rows that don't exist
26749 anymore. This can happen when a window is split. */
26750 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26752 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26753 struct glyph_row
*row
, *first
, *last
;
26755 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26756 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26758 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26760 int start_hpos
, end_hpos
, start_x
;
26762 /* For all but the first row, the highlight starts at column 0. */
26765 /* R2L rows have BEG and END in reversed order, but the
26766 screen drawing geometry is always left to right. So
26767 we need to mirror the beginning and end of the
26768 highlighted area in R2L rows. */
26769 if (!row
->reversed_p
)
26771 start_hpos
= hlinfo
->mouse_face_beg_col
;
26772 start_x
= hlinfo
->mouse_face_beg_x
;
26774 else if (row
== last
)
26776 start_hpos
= hlinfo
->mouse_face_end_col
;
26777 start_x
= hlinfo
->mouse_face_end_x
;
26785 else if (row
->reversed_p
&& row
== last
)
26787 start_hpos
= hlinfo
->mouse_face_end_col
;
26788 start_x
= hlinfo
->mouse_face_end_x
;
26798 if (!row
->reversed_p
)
26799 end_hpos
= hlinfo
->mouse_face_end_col
;
26800 else if (row
== first
)
26801 end_hpos
= hlinfo
->mouse_face_beg_col
;
26804 end_hpos
= row
->used
[TEXT_AREA
];
26805 if (draw
== DRAW_NORMAL_TEXT
)
26806 row
->fill_line_p
= 1; /* Clear to end of line */
26809 else if (row
->reversed_p
&& row
== first
)
26810 end_hpos
= hlinfo
->mouse_face_beg_col
;
26813 end_hpos
= row
->used
[TEXT_AREA
];
26814 if (draw
== DRAW_NORMAL_TEXT
)
26815 row
->fill_line_p
= 1; /* Clear to end of line */
26818 if (end_hpos
> start_hpos
)
26820 draw_row_with_mouse_face (w
, start_x
, row
,
26821 start_hpos
, end_hpos
, draw
);
26824 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26828 #ifdef HAVE_WINDOW_SYSTEM
26829 /* When we've written over the cursor, arrange for it to
26830 be displayed again. */
26831 if (FRAME_WINDOW_P (f
)
26832 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26834 int hpos
= w
->phys_cursor
.hpos
;
26836 /* When the window is hscrolled, cursor hpos can legitimately be
26837 out of bounds, but we draw the cursor at the corresponding
26838 window margin in that case. */
26839 if (!row
->reversed_p
&& hpos
< 0)
26841 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26842 hpos
= row
->used
[TEXT_AREA
] - 1;
26845 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26846 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26849 #endif /* HAVE_WINDOW_SYSTEM */
26852 #ifdef HAVE_WINDOW_SYSTEM
26853 /* Change the mouse cursor. */
26854 if (FRAME_WINDOW_P (f
))
26856 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
26857 if (draw
== DRAW_NORMAL_TEXT
26858 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26859 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26862 if (draw
== DRAW_MOUSE_FACE
)
26863 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26865 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26867 #endif /* HAVE_WINDOW_SYSTEM */
26871 Clear out the mouse-highlighted active region.
26872 Redraw it un-highlighted first. Value is non-zero if mouse
26873 face was actually drawn unhighlighted. */
26876 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26880 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26882 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26886 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26887 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26888 hlinfo
->mouse_face_window
= Qnil
;
26889 hlinfo
->mouse_face_overlay
= Qnil
;
26893 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26894 within the mouse face on that window. */
26896 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26898 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26900 /* Quickly resolve the easy cases. */
26901 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26902 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26904 if (vpos
< hlinfo
->mouse_face_beg_row
26905 || vpos
> hlinfo
->mouse_face_end_row
)
26907 if (vpos
> hlinfo
->mouse_face_beg_row
26908 && vpos
< hlinfo
->mouse_face_end_row
)
26911 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26913 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26915 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26918 else if ((vpos
== hlinfo
->mouse_face_beg_row
26919 && hpos
>= hlinfo
->mouse_face_beg_col
)
26920 || (vpos
== hlinfo
->mouse_face_end_row
26921 && hpos
< hlinfo
->mouse_face_end_col
))
26926 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26928 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26931 else if ((vpos
== hlinfo
->mouse_face_beg_row
26932 && hpos
<= hlinfo
->mouse_face_beg_col
)
26933 || (vpos
== hlinfo
->mouse_face_end_row
26934 && hpos
> hlinfo
->mouse_face_end_col
))
26942 Non-zero if physical cursor of window W is within mouse face. */
26945 cursor_in_mouse_face_p (struct window
*w
)
26947 int hpos
= w
->phys_cursor
.hpos
;
26948 int vpos
= w
->phys_cursor
.vpos
;
26949 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26951 /* When the window is hscrolled, cursor hpos can legitimately be out
26952 of bounds, but we draw the cursor at the corresponding window
26953 margin in that case. */
26954 if (!row
->reversed_p
&& hpos
< 0)
26956 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26957 hpos
= row
->used
[TEXT_AREA
] - 1;
26959 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26964 /* Find the glyph rows START_ROW and END_ROW of window W that display
26965 characters between buffer positions START_CHARPOS and END_CHARPOS
26966 (excluding END_CHARPOS). DISP_STRING is a display string that
26967 covers these buffer positions. This is similar to
26968 row_containing_pos, but is more accurate when bidi reordering makes
26969 buffer positions change non-linearly with glyph rows. */
26971 rows_from_pos_range (struct window
*w
,
26972 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26973 Lisp_Object disp_string
,
26974 struct glyph_row
**start
, struct glyph_row
**end
)
26976 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26977 int last_y
= window_text_bottom_y (w
);
26978 struct glyph_row
*row
;
26983 while (!first
->enabled_p
26984 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26987 /* Find the START row. */
26989 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26992 /* A row can potentially be the START row if the range of the
26993 characters it displays intersects the range
26994 [START_CHARPOS..END_CHARPOS). */
26995 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26996 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26997 /* See the commentary in row_containing_pos, for the
26998 explanation of the complicated way to check whether
26999 some position is beyond the end of the characters
27000 displayed by a row. */
27001 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27002 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27003 && !row
->ends_at_zv_p
27004 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27005 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27006 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27007 && !row
->ends_at_zv_p
27008 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27010 /* Found a candidate row. Now make sure at least one of the
27011 glyphs it displays has a charpos from the range
27012 [START_CHARPOS..END_CHARPOS).
27014 This is not obvious because bidi reordering could make
27015 buffer positions of a row be 1,2,3,102,101,100, and if we
27016 want to highlight characters in [50..60), we don't want
27017 this row, even though [50..60) does intersect [1..103),
27018 the range of character positions given by the row's start
27019 and end positions. */
27020 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27021 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27025 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27026 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27027 /* A glyph that comes from DISP_STRING is by
27028 definition to be highlighted. */
27029 || EQ (g
->object
, disp_string
))
27038 /* Find the END row. */
27040 /* If the last row is partially visible, start looking for END
27041 from that row, instead of starting from FIRST. */
27042 && !(row
->enabled_p
27043 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27045 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27047 struct glyph_row
*next
= row
+ 1;
27048 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27050 if (!next
->enabled_p
27051 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27052 /* The first row >= START whose range of displayed characters
27053 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27054 is the row END + 1. */
27055 || (start_charpos
< next_start
27056 && end_charpos
< next_start
)
27057 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27058 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27059 && !next
->ends_at_zv_p
27060 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27061 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27062 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27063 && !next
->ends_at_zv_p
27064 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27071 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27072 but none of the characters it displays are in the range, it is
27074 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27075 struct glyph
*s
= g
;
27076 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27080 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27081 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27082 /* If the buffer position of the first glyph in
27083 the row is equal to END_CHARPOS, it means
27084 the last character to be highlighted is the
27085 newline of ROW, and we must consider NEXT as
27087 || (((!next
->reversed_p
&& g
== s
)
27088 || (next
->reversed_p
&& g
== e
- 1))
27089 && (g
->charpos
== end_charpos
27090 /* Special case for when NEXT is an
27091 empty line at ZV. */
27092 || (g
->charpos
== -1
27093 && !row
->ends_at_zv_p
27094 && next_start
== end_charpos
)))))
27095 /* A glyph that comes from DISP_STRING is by
27096 definition to be highlighted. */
27097 || EQ (g
->object
, disp_string
))
27106 /* The first row that ends at ZV must be the last to be
27108 else if (next
->ends_at_zv_p
)
27117 /* This function sets the mouse_face_* elements of HLINFO, assuming
27118 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27119 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27120 for the overlay or run of text properties specifying the mouse
27121 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27122 before-string and after-string that must also be highlighted.
27123 DISP_STRING, if non-nil, is a display string that may cover some
27124 or all of the highlighted text. */
27127 mouse_face_from_buffer_pos (Lisp_Object window
,
27128 Mouse_HLInfo
*hlinfo
,
27129 ptrdiff_t mouse_charpos
,
27130 ptrdiff_t start_charpos
,
27131 ptrdiff_t end_charpos
,
27132 Lisp_Object before_string
,
27133 Lisp_Object after_string
,
27134 Lisp_Object disp_string
)
27136 struct window
*w
= XWINDOW (window
);
27137 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27138 struct glyph_row
*r1
, *r2
;
27139 struct glyph
*glyph
, *end
;
27140 ptrdiff_t ignore
, pos
;
27143 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27144 eassert (NILP (before_string
) || STRINGP (before_string
));
27145 eassert (NILP (after_string
) || STRINGP (after_string
));
27147 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27148 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27150 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27151 /* If the before-string or display-string contains newlines,
27152 rows_from_pos_range skips to its last row. Move back. */
27153 if (!NILP (before_string
) || !NILP (disp_string
))
27155 struct glyph_row
*prev
;
27156 while ((prev
= r1
- 1, prev
>= first
)
27157 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27158 && prev
->used
[TEXT_AREA
] > 0)
27160 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27161 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27162 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27164 || !(EQ (glyph
->object
, before_string
)
27165 || EQ (glyph
->object
, disp_string
)))
27172 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27173 hlinfo
->mouse_face_past_end
= 1;
27175 else if (!NILP (after_string
))
27177 /* If the after-string has newlines, advance to its last row. */
27178 struct glyph_row
*next
;
27179 struct glyph_row
*last
27180 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27182 for (next
= r2
+ 1;
27184 && next
->used
[TEXT_AREA
] > 0
27185 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27189 /* The rest of the display engine assumes that mouse_face_beg_row is
27190 either above mouse_face_end_row or identical to it. But with
27191 bidi-reordered continued lines, the row for START_CHARPOS could
27192 be below the row for END_CHARPOS. If so, swap the rows and store
27193 them in correct order. */
27196 struct glyph_row
*tem
= r2
;
27202 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27203 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27205 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27206 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27207 could be anywhere in the row and in any order. The strategy
27208 below is to find the leftmost and the rightmost glyph that
27209 belongs to either of these 3 strings, or whose position is
27210 between START_CHARPOS and END_CHARPOS, and highlight all the
27211 glyphs between those two. This may cover more than just the text
27212 between START_CHARPOS and END_CHARPOS if the range of characters
27213 strides the bidi level boundary, e.g. if the beginning is in R2L
27214 text while the end is in L2R text or vice versa. */
27215 if (!r1
->reversed_p
)
27217 /* This row is in a left to right paragraph. Scan it left to
27219 glyph
= r1
->glyphs
[TEXT_AREA
];
27220 end
= glyph
+ r1
->used
[TEXT_AREA
];
27223 /* Skip truncation glyphs at the start of the glyph row. */
27224 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27226 && INTEGERP (glyph
->object
)
27227 && glyph
->charpos
< 0;
27229 x
+= glyph
->pixel_width
;
27231 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27232 or DISP_STRING, and the first glyph from buffer whose
27233 position is between START_CHARPOS and END_CHARPOS. */
27235 && !INTEGERP (glyph
->object
)
27236 && !EQ (glyph
->object
, disp_string
)
27237 && !(BUFFERP (glyph
->object
)
27238 && (glyph
->charpos
>= start_charpos
27239 && glyph
->charpos
< end_charpos
));
27242 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27243 are present at buffer positions between START_CHARPOS and
27244 END_CHARPOS, or if they come from an overlay. */
27245 if (EQ (glyph
->object
, before_string
))
27247 pos
= string_buffer_position (before_string
,
27249 /* If pos == 0, it means before_string came from an
27250 overlay, not from a buffer position. */
27251 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27254 else if (EQ (glyph
->object
, after_string
))
27256 pos
= string_buffer_position (after_string
, end_charpos
);
27257 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27260 x
+= glyph
->pixel_width
;
27262 hlinfo
->mouse_face_beg_x
= x
;
27263 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27267 /* This row is in a right to left paragraph. Scan it right to
27271 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27272 glyph
= end
+ r1
->used
[TEXT_AREA
];
27274 /* Skip truncation glyphs at the start of the glyph row. */
27275 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27277 && INTEGERP (glyph
->object
)
27278 && glyph
->charpos
< 0;
27282 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27283 or DISP_STRING, and the first glyph from buffer whose
27284 position is between START_CHARPOS and END_CHARPOS. */
27286 && !INTEGERP (glyph
->object
)
27287 && !EQ (glyph
->object
, disp_string
)
27288 && !(BUFFERP (glyph
->object
)
27289 && (glyph
->charpos
>= start_charpos
27290 && glyph
->charpos
< end_charpos
));
27293 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27294 are present at buffer positions between START_CHARPOS and
27295 END_CHARPOS, or if they come from an overlay. */
27296 if (EQ (glyph
->object
, before_string
))
27298 pos
= string_buffer_position (before_string
, start_charpos
);
27299 /* If pos == 0, it means before_string came from an
27300 overlay, not from a buffer position. */
27301 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27304 else if (EQ (glyph
->object
, after_string
))
27306 pos
= string_buffer_position (after_string
, end_charpos
);
27307 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27312 glyph
++; /* first glyph to the right of the highlighted area */
27313 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27314 x
+= g
->pixel_width
;
27315 hlinfo
->mouse_face_beg_x
= x
;
27316 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27319 /* If the highlight ends in a different row, compute GLYPH and END
27320 for the end row. Otherwise, reuse the values computed above for
27321 the row where the highlight begins. */
27324 if (!r2
->reversed_p
)
27326 glyph
= r2
->glyphs
[TEXT_AREA
];
27327 end
= glyph
+ r2
->used
[TEXT_AREA
];
27332 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27333 glyph
= end
+ r2
->used
[TEXT_AREA
];
27337 if (!r2
->reversed_p
)
27339 /* Skip truncation and continuation glyphs near the end of the
27340 row, and also blanks and stretch glyphs inserted by
27341 extend_face_to_end_of_line. */
27343 && INTEGERP ((end
- 1)->object
))
27345 /* Scan the rest of the glyph row from the end, looking for the
27346 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27347 DISP_STRING, or whose position is between START_CHARPOS
27351 && !INTEGERP (end
->object
)
27352 && !EQ (end
->object
, disp_string
)
27353 && !(BUFFERP (end
->object
)
27354 && (end
->charpos
>= start_charpos
27355 && end
->charpos
< end_charpos
));
27358 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27359 are present at buffer positions between START_CHARPOS and
27360 END_CHARPOS, or if they come from an overlay. */
27361 if (EQ (end
->object
, before_string
))
27363 pos
= string_buffer_position (before_string
, start_charpos
);
27364 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27367 else if (EQ (end
->object
, after_string
))
27369 pos
= string_buffer_position (after_string
, end_charpos
);
27370 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27374 /* Find the X coordinate of the last glyph to be highlighted. */
27375 for (; glyph
<= end
; ++glyph
)
27376 x
+= glyph
->pixel_width
;
27378 hlinfo
->mouse_face_end_x
= x
;
27379 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27383 /* Skip truncation and continuation glyphs near the end of the
27384 row, and also blanks and stretch glyphs inserted by
27385 extend_face_to_end_of_line. */
27389 && INTEGERP (end
->object
))
27391 x
+= end
->pixel_width
;
27394 /* Scan the rest of the glyph row from the end, looking for the
27395 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27396 DISP_STRING, or whose position is between START_CHARPOS
27400 && !INTEGERP (end
->object
)
27401 && !EQ (end
->object
, disp_string
)
27402 && !(BUFFERP (end
->object
)
27403 && (end
->charpos
>= start_charpos
27404 && end
->charpos
< end_charpos
));
27407 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27408 are present at buffer positions between START_CHARPOS and
27409 END_CHARPOS, or if they come from an overlay. */
27410 if (EQ (end
->object
, before_string
))
27412 pos
= string_buffer_position (before_string
, start_charpos
);
27413 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27416 else if (EQ (end
->object
, after_string
))
27418 pos
= string_buffer_position (after_string
, end_charpos
);
27419 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27422 x
+= end
->pixel_width
;
27424 /* If we exited the above loop because we arrived at the last
27425 glyph of the row, and its buffer position is still not in
27426 range, it means the last character in range is the preceding
27427 newline. Bump the end column and x values to get past the
27430 && BUFFERP (end
->object
)
27431 && (end
->charpos
< start_charpos
27432 || end
->charpos
>= end_charpos
))
27434 x
+= end
->pixel_width
;
27437 hlinfo
->mouse_face_end_x
= x
;
27438 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27441 hlinfo
->mouse_face_window
= window
;
27442 hlinfo
->mouse_face_face_id
27443 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27445 !hlinfo
->mouse_face_hidden
, -1);
27446 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27449 /* The following function is not used anymore (replaced with
27450 mouse_face_from_string_pos), but I leave it here for the time
27451 being, in case someone would. */
27453 #if 0 /* not used */
27455 /* Find the position of the glyph for position POS in OBJECT in
27456 window W's current matrix, and return in *X, *Y the pixel
27457 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27459 RIGHT_P non-zero means return the position of the right edge of the
27460 glyph, RIGHT_P zero means return the left edge position.
27462 If no glyph for POS exists in the matrix, return the position of
27463 the glyph with the next smaller position that is in the matrix, if
27464 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27465 exists in the matrix, return the position of the glyph with the
27466 next larger position in OBJECT.
27468 Value is non-zero if a glyph was found. */
27471 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27472 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27474 int yb
= window_text_bottom_y (w
);
27475 struct glyph_row
*r
;
27476 struct glyph
*best_glyph
= NULL
;
27477 struct glyph_row
*best_row
= NULL
;
27480 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27481 r
->enabled_p
&& r
->y
< yb
;
27484 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27485 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27488 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27489 if (EQ (g
->object
, object
))
27491 if (g
->charpos
== pos
)
27498 else if (best_glyph
== NULL
27499 || ((eabs (g
->charpos
- pos
)
27500 < eabs (best_glyph
->charpos
- pos
))
27503 : g
->charpos
> pos
)))
27517 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27521 *x
+= best_glyph
->pixel_width
;
27526 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27529 return best_glyph
!= NULL
;
27531 #endif /* not used */
27533 /* Find the positions of the first and the last glyphs in window W's
27534 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27535 (assumed to be a string), and return in HLINFO's mouse_face_*
27536 members the pixel and column/row coordinates of those glyphs. */
27539 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27540 Lisp_Object object
,
27541 ptrdiff_t startpos
, ptrdiff_t endpos
)
27543 int yb
= window_text_bottom_y (w
);
27544 struct glyph_row
*r
;
27545 struct glyph
*g
, *e
;
27549 /* Find the glyph row with at least one position in the range
27550 [STARTPOS..ENDPOS), and the first glyph in that row whose
27551 position belongs to that range. */
27552 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27553 r
->enabled_p
&& r
->y
< yb
;
27556 if (!r
->reversed_p
)
27558 g
= r
->glyphs
[TEXT_AREA
];
27559 e
= g
+ r
->used
[TEXT_AREA
];
27560 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27561 if (EQ (g
->object
, object
)
27562 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27564 hlinfo
->mouse_face_beg_row
27565 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27566 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27567 hlinfo
->mouse_face_beg_x
= gx
;
27576 e
= r
->glyphs
[TEXT_AREA
];
27577 g
= e
+ r
->used
[TEXT_AREA
];
27578 for ( ; g
> e
; --g
)
27579 if (EQ ((g
-1)->object
, object
)
27580 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27582 hlinfo
->mouse_face_beg_row
27583 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27584 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27585 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27586 gx
+= g1
->pixel_width
;
27587 hlinfo
->mouse_face_beg_x
= gx
;
27599 /* Starting with the next row, look for the first row which does NOT
27600 include any glyphs whose positions are in the range. */
27601 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27603 g
= r
->glyphs
[TEXT_AREA
];
27604 e
= g
+ r
->used
[TEXT_AREA
];
27606 for ( ; g
< e
; ++g
)
27607 if (EQ (g
->object
, object
)
27608 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27617 /* The highlighted region ends on the previous row. */
27620 /* Set the end row. */
27621 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27623 /* Compute and set the end column and the end column's horizontal
27624 pixel coordinate. */
27625 if (!r
->reversed_p
)
27627 g
= r
->glyphs
[TEXT_AREA
];
27628 e
= g
+ r
->used
[TEXT_AREA
];
27629 for ( ; e
> g
; --e
)
27630 if (EQ ((e
-1)->object
, object
)
27631 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27633 hlinfo
->mouse_face_end_col
= e
- g
;
27635 for (gx
= r
->x
; g
< e
; ++g
)
27636 gx
+= g
->pixel_width
;
27637 hlinfo
->mouse_face_end_x
= gx
;
27641 e
= r
->glyphs
[TEXT_AREA
];
27642 g
= e
+ r
->used
[TEXT_AREA
];
27643 for (gx
= r
->x
; e
< g
; ++e
)
27645 if (EQ (e
->object
, object
)
27646 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27648 gx
+= e
->pixel_width
;
27650 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27651 hlinfo
->mouse_face_end_x
= gx
;
27655 #ifdef HAVE_WINDOW_SYSTEM
27657 /* See if position X, Y is within a hot-spot of an image. */
27660 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27662 if (!CONSP (hot_spot
))
27665 if (EQ (XCAR (hot_spot
), Qrect
))
27667 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27668 Lisp_Object rect
= XCDR (hot_spot
);
27672 if (!CONSP (XCAR (rect
)))
27674 if (!CONSP (XCDR (rect
)))
27676 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27678 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27680 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27682 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27686 else if (EQ (XCAR (hot_spot
), Qcircle
))
27688 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27689 Lisp_Object circ
= XCDR (hot_spot
);
27690 Lisp_Object lr
, lx0
, ly0
;
27692 && CONSP (XCAR (circ
))
27693 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27694 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27695 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27697 double r
= XFLOATINT (lr
);
27698 double dx
= XINT (lx0
) - x
;
27699 double dy
= XINT (ly0
) - y
;
27700 return (dx
* dx
+ dy
* dy
<= r
* r
);
27703 else if (EQ (XCAR (hot_spot
), Qpoly
))
27705 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27706 if (VECTORP (XCDR (hot_spot
)))
27708 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27709 Lisp_Object
*poly
= v
->contents
;
27710 ptrdiff_t n
= v
->header
.size
;
27713 Lisp_Object lx
, ly
;
27716 /* Need an even number of coordinates, and at least 3 edges. */
27717 if (n
< 6 || n
& 1)
27720 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27721 If count is odd, we are inside polygon. Pixels on edges
27722 may or may not be included depending on actual geometry of the
27724 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27725 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27727 x0
= XINT (lx
), y0
= XINT (ly
);
27728 for (i
= 0; i
< n
; i
+= 2)
27730 int x1
= x0
, y1
= y0
;
27731 if ((lx
= poly
[i
], !INTEGERP (lx
))
27732 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27734 x0
= XINT (lx
), y0
= XINT (ly
);
27736 /* Does this segment cross the X line? */
27744 if (y
> y0
&& y
> y1
)
27746 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27756 find_hot_spot (Lisp_Object map
, int x
, int y
)
27758 while (CONSP (map
))
27760 if (CONSP (XCAR (map
))
27761 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27769 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27771 doc
: /* Lookup in image map MAP coordinates X and Y.
27772 An image map is an alist where each element has the format (AREA ID PLIST).
27773 An AREA is specified as either a rectangle, a circle, or a polygon:
27774 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27775 pixel coordinates of the upper left and bottom right corners.
27776 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27777 and the radius of the circle; r may be a float or integer.
27778 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27779 vector describes one corner in the polygon.
27780 Returns the alist element for the first matching AREA in MAP. */)
27781 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27789 return find_hot_spot (map
,
27790 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27791 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27795 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27797 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27799 /* Do not change cursor shape while dragging mouse. */
27800 if (!NILP (do_mouse_tracking
))
27803 if (!NILP (pointer
))
27805 if (EQ (pointer
, Qarrow
))
27806 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27807 else if (EQ (pointer
, Qhand
))
27808 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27809 else if (EQ (pointer
, Qtext
))
27810 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27811 else if (EQ (pointer
, intern ("hdrag")))
27812 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27813 #ifdef HAVE_X_WINDOWS
27814 else if (EQ (pointer
, intern ("vdrag")))
27815 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27817 else if (EQ (pointer
, intern ("hourglass")))
27818 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27819 else if (EQ (pointer
, Qmodeline
))
27820 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27822 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27825 if (cursor
!= No_Cursor
)
27826 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27829 #endif /* HAVE_WINDOW_SYSTEM */
27831 /* Take proper action when mouse has moved to the mode or header line
27832 or marginal area AREA of window W, x-position X and y-position Y.
27833 X is relative to the start of the text display area of W, so the
27834 width of bitmap areas and scroll bars must be subtracted to get a
27835 position relative to the start of the mode line. */
27838 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27839 enum window_part area
)
27841 struct window
*w
= XWINDOW (window
);
27842 struct frame
*f
= XFRAME (w
->frame
);
27843 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27844 #ifdef HAVE_WINDOW_SYSTEM
27845 Display_Info
*dpyinfo
;
27847 Cursor cursor
= No_Cursor
;
27848 Lisp_Object pointer
= Qnil
;
27849 int dx
, dy
, width
, height
;
27851 Lisp_Object string
, object
= Qnil
;
27852 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27854 Lisp_Object mouse_face
;
27855 int original_x_pixel
= x
;
27856 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27857 struct glyph_row
*row
IF_LINT (= 0);
27859 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27864 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27865 returns them in row/column units! */
27866 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27867 &object
, &dx
, &dy
, &width
, &height
);
27869 row
= (area
== ON_MODE_LINE
27870 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27871 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27873 /* Find the glyph under the mouse pointer. */
27874 if (row
->mode_line_p
&& row
->enabled_p
)
27876 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27877 end
= glyph
+ row
->used
[TEXT_AREA
];
27879 for (x0
= original_x_pixel
;
27880 glyph
< end
&& x0
>= glyph
->pixel_width
;
27882 x0
-= glyph
->pixel_width
;
27890 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27891 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27892 returns them in row/column units! */
27893 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27894 &object
, &dx
, &dy
, &width
, &height
);
27899 #ifdef HAVE_WINDOW_SYSTEM
27900 if (IMAGEP (object
))
27902 Lisp_Object image_map
, hotspot
;
27903 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27905 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27907 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27911 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27912 If so, we could look for mouse-enter, mouse-leave
27913 properties in PLIST (and do something...). */
27914 hotspot
= XCDR (hotspot
);
27915 if (CONSP (hotspot
)
27916 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27918 pointer
= Fplist_get (plist
, Qpointer
);
27919 if (NILP (pointer
))
27921 help
= Fplist_get (plist
, Qhelp_echo
);
27924 help_echo_string
= help
;
27925 XSETWINDOW (help_echo_window
, w
);
27926 help_echo_object
= w
->contents
;
27927 help_echo_pos
= charpos
;
27931 if (NILP (pointer
))
27932 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27934 #endif /* HAVE_WINDOW_SYSTEM */
27936 if (STRINGP (string
))
27937 pos
= make_number (charpos
);
27939 /* Set the help text and mouse pointer. If the mouse is on a part
27940 of the mode line without any text (e.g. past the right edge of
27941 the mode line text), use the default help text and pointer. */
27942 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27944 /* Arrange to display the help by setting the global variables
27945 help_echo_string, help_echo_object, and help_echo_pos. */
27948 if (STRINGP (string
))
27949 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27953 help_echo_string
= help
;
27954 XSETWINDOW (help_echo_window
, w
);
27955 help_echo_object
= string
;
27956 help_echo_pos
= charpos
;
27958 else if (area
== ON_MODE_LINE
)
27960 Lisp_Object default_help
27961 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27964 if (STRINGP (default_help
))
27966 help_echo_string
= default_help
;
27967 XSETWINDOW (help_echo_window
, w
);
27968 help_echo_object
= Qnil
;
27969 help_echo_pos
= -1;
27974 #ifdef HAVE_WINDOW_SYSTEM
27975 /* Change the mouse pointer according to what is under it. */
27976 if (FRAME_WINDOW_P (f
))
27978 dpyinfo
= FRAME_DISPLAY_INFO (f
);
27979 if (STRINGP (string
))
27981 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27983 if (NILP (pointer
))
27984 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27986 /* Change the mouse pointer according to what is under X/Y. */
27988 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27991 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27992 if (!KEYMAPP (map
))
27993 map
= Fget_text_property (pos
, Qkeymap
, string
);
27994 if (!KEYMAPP (map
))
27995 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27999 /* Default mode-line pointer. */
28000 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28005 /* Change the mouse face according to what is under X/Y. */
28006 if (STRINGP (string
))
28008 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28009 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28010 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28015 struct glyph
* tmp_glyph
;
28019 int total_pixel_width
;
28020 ptrdiff_t begpos
, endpos
, ignore
;
28024 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28025 Qmouse_face
, string
, Qnil
);
28031 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28033 endpos
= SCHARS (string
);
28037 /* Calculate the glyph position GPOS of GLYPH in the
28038 displayed string, relative to the beginning of the
28039 highlighted part of the string.
28041 Note: GPOS is different from CHARPOS. CHARPOS is the
28042 position of GLYPH in the internal string object. A mode
28043 line string format has structures which are converted to
28044 a flattened string by the Emacs Lisp interpreter. The
28045 internal string is an element of those structures. The
28046 displayed string is the flattened string. */
28047 tmp_glyph
= row_start_glyph
;
28048 while (tmp_glyph
< glyph
28049 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28050 && begpos
<= tmp_glyph
->charpos
28051 && tmp_glyph
->charpos
< endpos
)))
28053 gpos
= glyph
- tmp_glyph
;
28055 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28056 the highlighted part of the displayed string to which
28057 GLYPH belongs. Note: GSEQ_LENGTH is different from
28058 SCHARS (STRING), because the latter returns the length of
28059 the internal string. */
28060 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28062 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28063 && begpos
<= tmp_glyph
->charpos
28064 && tmp_glyph
->charpos
< endpos
));
28067 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28069 /* Calculate the total pixel width of all the glyphs between
28070 the beginning of the highlighted area and GLYPH. */
28071 total_pixel_width
= 0;
28072 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28073 total_pixel_width
+= tmp_glyph
->pixel_width
;
28075 /* Pre calculation of re-rendering position. Note: X is in
28076 column units here, after the call to mode_line_string or
28077 marginal_area_string. */
28079 vpos
= (area
== ON_MODE_LINE
28080 ? (w
->current_matrix
)->nrows
- 1
28083 /* If GLYPH's position is included in the region that is
28084 already drawn in mouse face, we have nothing to do. */
28085 if ( EQ (window
, hlinfo
->mouse_face_window
)
28086 && (!row
->reversed_p
28087 ? (hlinfo
->mouse_face_beg_col
<= hpos
28088 && hpos
< hlinfo
->mouse_face_end_col
)
28089 /* In R2L rows we swap BEG and END, see below. */
28090 : (hlinfo
->mouse_face_end_col
<= hpos
28091 && hpos
< hlinfo
->mouse_face_beg_col
))
28092 && hlinfo
->mouse_face_beg_row
== vpos
)
28095 if (clear_mouse_face (hlinfo
))
28096 cursor
= No_Cursor
;
28098 if (!row
->reversed_p
)
28100 hlinfo
->mouse_face_beg_col
= hpos
;
28101 hlinfo
->mouse_face_beg_x
= original_x_pixel
28102 - (total_pixel_width
+ dx
);
28103 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28104 hlinfo
->mouse_face_end_x
= 0;
28108 /* In R2L rows, show_mouse_face expects BEG and END
28109 coordinates to be swapped. */
28110 hlinfo
->mouse_face_end_col
= hpos
;
28111 hlinfo
->mouse_face_end_x
= original_x_pixel
28112 - (total_pixel_width
+ dx
);
28113 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28114 hlinfo
->mouse_face_beg_x
= 0;
28117 hlinfo
->mouse_face_beg_row
= vpos
;
28118 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28119 hlinfo
->mouse_face_past_end
= 0;
28120 hlinfo
->mouse_face_window
= window
;
28122 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28127 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28129 if (NILP (pointer
))
28132 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28133 clear_mouse_face (hlinfo
);
28135 #ifdef HAVE_WINDOW_SYSTEM
28136 if (FRAME_WINDOW_P (f
))
28137 define_frame_cursor1 (f
, cursor
, pointer
);
28143 Take proper action when the mouse has moved to position X, Y on
28144 frame F with regards to highlighting portions of display that have
28145 mouse-face properties. Also de-highlight portions of display where
28146 the mouse was before, set the mouse pointer shape as appropriate
28147 for the mouse coordinates, and activate help echo (tooltips).
28148 X and Y can be negative or out of range. */
28151 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28153 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28154 enum window_part part
= ON_NOTHING
;
28155 Lisp_Object window
;
28157 Cursor cursor
= No_Cursor
;
28158 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28161 /* When a menu is active, don't highlight because this looks odd. */
28162 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28163 if (popup_activated ())
28167 if (!f
->glyphs_initialized_p
28168 || f
->pointer_invisible
)
28171 hlinfo
->mouse_face_mouse_x
= x
;
28172 hlinfo
->mouse_face_mouse_y
= y
;
28173 hlinfo
->mouse_face_mouse_frame
= f
;
28175 if (hlinfo
->mouse_face_defer
)
28178 /* Which window is that in? */
28179 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28181 /* If displaying active text in another window, clear that. */
28182 if (! EQ (window
, hlinfo
->mouse_face_window
)
28183 /* Also clear if we move out of text area in same window. */
28184 || (!NILP (hlinfo
->mouse_face_window
)
28187 && part
!= ON_MODE_LINE
28188 && part
!= ON_HEADER_LINE
))
28189 clear_mouse_face (hlinfo
);
28191 /* Not on a window -> return. */
28192 if (!WINDOWP (window
))
28195 /* Reset help_echo_string. It will get recomputed below. */
28196 help_echo_string
= Qnil
;
28198 /* Convert to window-relative pixel coordinates. */
28199 w
= XWINDOW (window
);
28200 frame_to_window_pixel_xy (w
, &x
, &y
);
28202 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28203 /* Handle tool-bar window differently since it doesn't display a
28205 if (EQ (window
, f
->tool_bar_window
))
28207 note_tool_bar_highlight (f
, x
, y
);
28212 /* Mouse is on the mode, header line or margin? */
28213 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28214 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28216 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28220 #ifdef HAVE_WINDOW_SYSTEM
28221 if (part
== ON_VERTICAL_BORDER
)
28223 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28224 help_echo_string
= build_string ("drag-mouse-1: resize");
28226 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28227 || part
== ON_SCROLL_BAR
)
28228 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28230 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28233 /* Are we in a window whose display is up to date?
28234 And verify the buffer's text has not changed. */
28235 b
= XBUFFER (w
->contents
);
28236 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28238 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28240 struct glyph
*glyph
;
28241 Lisp_Object object
;
28242 Lisp_Object mouse_face
= Qnil
, position
;
28243 Lisp_Object
*overlay_vec
= NULL
;
28244 ptrdiff_t i
, noverlays
;
28245 struct buffer
*obuf
;
28246 ptrdiff_t obegv
, ozv
;
28249 /* Find the glyph under X/Y. */
28250 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28252 #ifdef HAVE_WINDOW_SYSTEM
28253 /* Look for :pointer property on image. */
28254 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28256 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28257 if (img
!= NULL
&& IMAGEP (img
->spec
))
28259 Lisp_Object image_map
, hotspot
;
28260 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28262 && (hotspot
= find_hot_spot (image_map
,
28263 glyph
->slice
.img
.x
+ dx
,
28264 glyph
->slice
.img
.y
+ dy
),
28266 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28270 /* Could check XCAR (hotspot) to see if we enter/leave
28272 If so, we could look for mouse-enter, mouse-leave
28273 properties in PLIST (and do something...). */
28274 hotspot
= XCDR (hotspot
);
28275 if (CONSP (hotspot
)
28276 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28278 pointer
= Fplist_get (plist
, Qpointer
);
28279 if (NILP (pointer
))
28281 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28282 if (!NILP (help_echo_string
))
28284 help_echo_window
= window
;
28285 help_echo_object
= glyph
->object
;
28286 help_echo_pos
= glyph
->charpos
;
28290 if (NILP (pointer
))
28291 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28294 #endif /* HAVE_WINDOW_SYSTEM */
28296 /* Clear mouse face if X/Y not over text. */
28298 || area
!= TEXT_AREA
28299 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28300 /* Glyph's OBJECT is an integer for glyphs inserted by the
28301 display engine for its internal purposes, like truncation
28302 and continuation glyphs and blanks beyond the end of
28303 line's text on text terminals. If we are over such a
28304 glyph, we are not over any text. */
28305 || INTEGERP (glyph
->object
)
28306 /* R2L rows have a stretch glyph at their front, which
28307 stands for no text, whereas L2R rows have no glyphs at
28308 all beyond the end of text. Treat such stretch glyphs
28309 like we do with NULL glyphs in L2R rows. */
28310 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28311 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28312 && glyph
->type
== STRETCH_GLYPH
28313 && glyph
->avoid_cursor_p
))
28315 if (clear_mouse_face (hlinfo
))
28316 cursor
= No_Cursor
;
28317 #ifdef HAVE_WINDOW_SYSTEM
28318 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28320 if (area
!= TEXT_AREA
)
28321 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28323 pointer
= Vvoid_text_area_pointer
;
28329 pos
= glyph
->charpos
;
28330 object
= glyph
->object
;
28331 if (!STRINGP (object
) && !BUFFERP (object
))
28334 /* If we get an out-of-range value, return now; avoid an error. */
28335 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28338 /* Make the window's buffer temporarily current for
28339 overlays_at and compute_char_face. */
28340 obuf
= current_buffer
;
28341 current_buffer
= b
;
28347 /* Is this char mouse-active or does it have help-echo? */
28348 position
= make_number (pos
);
28350 if (BUFFERP (object
))
28352 /* Put all the overlays we want in a vector in overlay_vec. */
28353 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28354 /* Sort overlays into increasing priority order. */
28355 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28360 if (NILP (Vmouse_highlight
))
28362 clear_mouse_face (hlinfo
);
28363 goto check_help_echo
;
28366 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28369 cursor
= No_Cursor
;
28371 /* Check mouse-face highlighting. */
28373 /* If there exists an overlay with mouse-face overlapping
28374 the one we are currently highlighting, we have to
28375 check if we enter the overlapping overlay, and then
28376 highlight only that. */
28377 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28378 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28380 /* Find the highest priority overlay with a mouse-face. */
28381 Lisp_Object overlay
= Qnil
;
28382 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28384 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28385 if (!NILP (mouse_face
))
28386 overlay
= overlay_vec
[i
];
28389 /* If we're highlighting the same overlay as before, there's
28390 no need to do that again. */
28391 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28392 goto check_help_echo
;
28393 hlinfo
->mouse_face_overlay
= overlay
;
28395 /* Clear the display of the old active region, if any. */
28396 if (clear_mouse_face (hlinfo
))
28397 cursor
= No_Cursor
;
28399 /* If no overlay applies, get a text property. */
28400 if (NILP (overlay
))
28401 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28403 /* Next, compute the bounds of the mouse highlighting and
28405 if (!NILP (mouse_face
) && STRINGP (object
))
28407 /* The mouse-highlighting comes from a display string
28408 with a mouse-face. */
28412 s
= Fprevious_single_property_change
28413 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28414 e
= Fnext_single_property_change
28415 (position
, Qmouse_face
, object
, Qnil
);
28417 s
= make_number (0);
28419 e
= make_number (SCHARS (object
));
28420 mouse_face_from_string_pos (w
, hlinfo
, object
,
28421 XINT (s
), XINT (e
));
28422 hlinfo
->mouse_face_past_end
= 0;
28423 hlinfo
->mouse_face_window
= window
;
28424 hlinfo
->mouse_face_face_id
28425 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28426 glyph
->face_id
, 1);
28427 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28428 cursor
= No_Cursor
;
28432 /* The mouse-highlighting, if any, comes from an overlay
28433 or text property in the buffer. */
28434 Lisp_Object buffer
IF_LINT (= Qnil
);
28435 Lisp_Object disp_string
IF_LINT (= Qnil
);
28437 if (STRINGP (object
))
28439 /* If we are on a display string with no mouse-face,
28440 check if the text under it has one. */
28441 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28442 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28443 pos
= string_buffer_position (object
, start
);
28446 mouse_face
= get_char_property_and_overlay
28447 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28448 buffer
= w
->contents
;
28449 disp_string
= object
;
28455 disp_string
= Qnil
;
28458 if (!NILP (mouse_face
))
28460 Lisp_Object before
, after
;
28461 Lisp_Object before_string
, after_string
;
28462 /* To correctly find the limits of mouse highlight
28463 in a bidi-reordered buffer, we must not use the
28464 optimization of limiting the search in
28465 previous-single-property-change and
28466 next-single-property-change, because
28467 rows_from_pos_range needs the real start and end
28468 positions to DTRT in this case. That's because
28469 the first row visible in a window does not
28470 necessarily display the character whose position
28471 is the smallest. */
28473 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28474 ? Fmarker_position (w
->start
)
28477 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28478 ? make_number (BUF_Z (XBUFFER (buffer
))
28479 - w
->window_end_pos
)
28482 if (NILP (overlay
))
28484 /* Handle the text property case. */
28485 before
= Fprevious_single_property_change
28486 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28487 after
= Fnext_single_property_change
28488 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28489 before_string
= after_string
= Qnil
;
28493 /* Handle the overlay case. */
28494 before
= Foverlay_start (overlay
);
28495 after
= Foverlay_end (overlay
);
28496 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28497 after_string
= Foverlay_get (overlay
, Qafter_string
);
28499 if (!STRINGP (before_string
)) before_string
= Qnil
;
28500 if (!STRINGP (after_string
)) after_string
= Qnil
;
28503 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28506 : XFASTINT (before
),
28508 ? BUF_Z (XBUFFER (buffer
))
28509 : XFASTINT (after
),
28510 before_string
, after_string
,
28512 cursor
= No_Cursor
;
28519 /* Look for a `help-echo' property. */
28520 if (NILP (help_echo_string
)) {
28521 Lisp_Object help
, overlay
;
28523 /* Check overlays first. */
28524 help
= overlay
= Qnil
;
28525 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28527 overlay
= overlay_vec
[i
];
28528 help
= Foverlay_get (overlay
, Qhelp_echo
);
28533 help_echo_string
= help
;
28534 help_echo_window
= window
;
28535 help_echo_object
= overlay
;
28536 help_echo_pos
= pos
;
28540 Lisp_Object obj
= glyph
->object
;
28541 ptrdiff_t charpos
= glyph
->charpos
;
28543 /* Try text properties. */
28546 && charpos
< SCHARS (obj
))
28548 help
= Fget_text_property (make_number (charpos
),
28552 /* If the string itself doesn't specify a help-echo,
28553 see if the buffer text ``under'' it does. */
28554 struct glyph_row
*r
28555 = MATRIX_ROW (w
->current_matrix
, vpos
);
28556 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28557 ptrdiff_t p
= string_buffer_position (obj
, start
);
28560 help
= Fget_char_property (make_number (p
),
28561 Qhelp_echo
, w
->contents
);
28570 else if (BUFFERP (obj
)
28573 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28578 help_echo_string
= help
;
28579 help_echo_window
= window
;
28580 help_echo_object
= obj
;
28581 help_echo_pos
= charpos
;
28586 #ifdef HAVE_WINDOW_SYSTEM
28587 /* Look for a `pointer' property. */
28588 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28590 /* Check overlays first. */
28591 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28592 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28594 if (NILP (pointer
))
28596 Lisp_Object obj
= glyph
->object
;
28597 ptrdiff_t charpos
= glyph
->charpos
;
28599 /* Try text properties. */
28602 && charpos
< SCHARS (obj
))
28604 pointer
= Fget_text_property (make_number (charpos
),
28606 if (NILP (pointer
))
28608 /* If the string itself doesn't specify a pointer,
28609 see if the buffer text ``under'' it does. */
28610 struct glyph_row
*r
28611 = MATRIX_ROW (w
->current_matrix
, vpos
);
28612 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28613 ptrdiff_t p
= string_buffer_position (obj
, start
);
28615 pointer
= Fget_char_property (make_number (p
),
28616 Qpointer
, w
->contents
);
28619 else if (BUFFERP (obj
)
28622 pointer
= Fget_text_property (make_number (charpos
),
28626 #endif /* HAVE_WINDOW_SYSTEM */
28630 current_buffer
= obuf
;
28635 #ifdef HAVE_WINDOW_SYSTEM
28636 if (FRAME_WINDOW_P (f
))
28637 define_frame_cursor1 (f
, cursor
, pointer
);
28639 /* This is here to prevent a compiler error, about "label at end of
28640 compound statement". */
28647 Clear any mouse-face on window W. This function is part of the
28648 redisplay interface, and is called from try_window_id and similar
28649 functions to ensure the mouse-highlight is off. */
28652 x_clear_window_mouse_face (struct window
*w
)
28654 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28655 Lisp_Object window
;
28658 XSETWINDOW (window
, w
);
28659 if (EQ (window
, hlinfo
->mouse_face_window
))
28660 clear_mouse_face (hlinfo
);
28666 Just discard the mouse face information for frame F, if any.
28667 This is used when the size of F is changed. */
28670 cancel_mouse_face (struct frame
*f
)
28672 Lisp_Object window
;
28673 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28675 window
= hlinfo
->mouse_face_window
;
28676 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28677 reset_mouse_highlight (hlinfo
);
28682 /***********************************************************************
28684 ***********************************************************************/
28686 #ifdef HAVE_WINDOW_SYSTEM
28688 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28689 which intersects rectangle R. R is in window-relative coordinates. */
28692 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28693 enum glyph_row_area area
)
28695 struct glyph
*first
= row
->glyphs
[area
];
28696 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28697 struct glyph
*last
;
28698 int first_x
, start_x
, x
;
28700 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28701 /* If row extends face to end of line write the whole line. */
28702 draw_glyphs (w
, 0, row
, area
,
28703 0, row
->used
[area
],
28704 DRAW_NORMAL_TEXT
, 0);
28707 /* Set START_X to the window-relative start position for drawing glyphs of
28708 AREA. The first glyph of the text area can be partially visible.
28709 The first glyphs of other areas cannot. */
28710 start_x
= window_box_left_offset (w
, area
);
28712 if (area
== TEXT_AREA
)
28715 /* Find the first glyph that must be redrawn. */
28717 && x
+ first
->pixel_width
< r
->x
)
28719 x
+= first
->pixel_width
;
28723 /* Find the last one. */
28727 && x
< r
->x
+ r
->width
)
28729 x
+= last
->pixel_width
;
28735 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28736 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28737 DRAW_NORMAL_TEXT
, 0);
28742 /* Redraw the parts of the glyph row ROW on window W intersecting
28743 rectangle R. R is in window-relative coordinates. Value is
28744 non-zero if mouse-face was overwritten. */
28747 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28749 eassert (row
->enabled_p
);
28751 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28752 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28753 0, row
->used
[TEXT_AREA
],
28754 DRAW_NORMAL_TEXT
, 0);
28757 if (row
->used
[LEFT_MARGIN_AREA
])
28758 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28759 if (row
->used
[TEXT_AREA
])
28760 expose_area (w
, row
, r
, TEXT_AREA
);
28761 if (row
->used
[RIGHT_MARGIN_AREA
])
28762 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28763 draw_row_fringe_bitmaps (w
, row
);
28766 return row
->mouse_face_p
;
28770 /* Redraw those parts of glyphs rows during expose event handling that
28771 overlap other rows. Redrawing of an exposed line writes over parts
28772 of lines overlapping that exposed line; this function fixes that.
28774 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28775 row in W's current matrix that is exposed and overlaps other rows.
28776 LAST_OVERLAPPING_ROW is the last such row. */
28779 expose_overlaps (struct window
*w
,
28780 struct glyph_row
*first_overlapping_row
,
28781 struct glyph_row
*last_overlapping_row
,
28784 struct glyph_row
*row
;
28786 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28787 if (row
->overlapping_p
)
28789 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28792 if (row
->used
[LEFT_MARGIN_AREA
])
28793 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28795 if (row
->used
[TEXT_AREA
])
28796 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28798 if (row
->used
[RIGHT_MARGIN_AREA
])
28799 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28805 /* Return non-zero if W's cursor intersects rectangle R. */
28808 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28810 XRectangle cr
, result
;
28811 struct glyph
*cursor_glyph
;
28812 struct glyph_row
*row
;
28814 if (w
->phys_cursor
.vpos
>= 0
28815 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28816 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28818 && row
->cursor_in_fringe_p
)
28820 /* Cursor is in the fringe. */
28821 cr
.x
= window_box_right_offset (w
,
28822 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28823 ? RIGHT_MARGIN_AREA
28826 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28827 cr
.height
= row
->height
;
28828 return x_intersect_rectangles (&cr
, r
, &result
);
28831 cursor_glyph
= get_phys_cursor_glyph (w
);
28834 /* r is relative to W's box, but w->phys_cursor.x is relative
28835 to left edge of W's TEXT area. Adjust it. */
28836 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28837 cr
.y
= w
->phys_cursor
.y
;
28838 cr
.width
= cursor_glyph
->pixel_width
;
28839 cr
.height
= w
->phys_cursor_height
;
28840 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28841 I assume the effect is the same -- and this is portable. */
28842 return x_intersect_rectangles (&cr
, r
, &result
);
28844 /* If we don't understand the format, pretend we're not in the hot-spot. */
28850 Draw a vertical window border to the right of window W if W doesn't
28851 have vertical scroll bars. */
28854 x_draw_vertical_border (struct window
*w
)
28856 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28858 /* We could do better, if we knew what type of scroll-bar the adjacent
28859 windows (on either side) have... But we don't :-(
28860 However, I think this works ok. ++KFS 2003-04-25 */
28862 /* Redraw borders between horizontally adjacent windows. Don't
28863 do it for frames with vertical scroll bars because either the
28864 right scroll bar of a window, or the left scroll bar of its
28865 neighbor will suffice as a border. */
28866 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28869 /* Note: It is necessary to redraw both the left and the right
28870 borders, for when only this single window W is being
28872 if (!WINDOW_RIGHTMOST_P (w
)
28873 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28875 int x0
, x1
, y0
, y1
;
28877 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28880 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28883 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28885 if (!WINDOW_LEFTMOST_P (w
)
28886 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28888 int x0
, x1
, y0
, y1
;
28890 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28893 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28896 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28901 /* Redraw the part of window W intersection rectangle FR. Pixel
28902 coordinates in FR are frame-relative. Call this function with
28903 input blocked. Value is non-zero if the exposure overwrites
28907 expose_window (struct window
*w
, XRectangle
*fr
)
28909 struct frame
*f
= XFRAME (w
->frame
);
28911 int mouse_face_overwritten_p
= 0;
28913 /* If window is not yet fully initialized, do nothing. This can
28914 happen when toolkit scroll bars are used and a window is split.
28915 Reconfiguring the scroll bar will generate an expose for a newly
28917 if (w
->current_matrix
== NULL
)
28920 /* When we're currently updating the window, display and current
28921 matrix usually don't agree. Arrange for a thorough display
28923 if (w
->must_be_updated_p
)
28925 SET_FRAME_GARBAGED (f
);
28929 /* Frame-relative pixel rectangle of W. */
28930 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28931 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28932 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28933 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28935 if (x_intersect_rectangles (fr
, &wr
, &r
))
28937 int yb
= window_text_bottom_y (w
);
28938 struct glyph_row
*row
;
28939 int cursor_cleared_p
, phys_cursor_on_p
;
28940 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28942 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28943 r
.x
, r
.y
, r
.width
, r
.height
));
28945 /* Convert to window coordinates. */
28946 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28947 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28949 /* Turn off the cursor. */
28950 if (!w
->pseudo_window_p
28951 && phys_cursor_in_rect_p (w
, &r
))
28953 x_clear_cursor (w
);
28954 cursor_cleared_p
= 1;
28957 cursor_cleared_p
= 0;
28959 /* If the row containing the cursor extends face to end of line,
28960 then expose_area might overwrite the cursor outside the
28961 rectangle and thus notice_overwritten_cursor might clear
28962 w->phys_cursor_on_p. We remember the original value and
28963 check later if it is changed. */
28964 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28966 /* Update lines intersecting rectangle R. */
28967 first_overlapping_row
= last_overlapping_row
= NULL
;
28968 for (row
= w
->current_matrix
->rows
;
28973 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28975 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28976 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28977 || (r
.y
>= y0
&& r
.y
< y1
)
28978 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28980 /* A header line may be overlapping, but there is no need
28981 to fix overlapping areas for them. KFS 2005-02-12 */
28982 if (row
->overlapping_p
&& !row
->mode_line_p
)
28984 if (first_overlapping_row
== NULL
)
28985 first_overlapping_row
= row
;
28986 last_overlapping_row
= row
;
28990 if (expose_line (w
, row
, &r
))
28991 mouse_face_overwritten_p
= 1;
28994 else if (row
->overlapping_p
)
28996 /* We must redraw a row overlapping the exposed area. */
28998 ? y0
+ row
->phys_height
> r
.y
28999 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29001 if (first_overlapping_row
== NULL
)
29002 first_overlapping_row
= row
;
29003 last_overlapping_row
= row
;
29011 /* Display the mode line if there is one. */
29012 if (WINDOW_WANTS_MODELINE_P (w
)
29013 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29015 && row
->y
< r
.y
+ r
.height
)
29017 if (expose_line (w
, row
, &r
))
29018 mouse_face_overwritten_p
= 1;
29021 if (!w
->pseudo_window_p
)
29023 /* Fix the display of overlapping rows. */
29024 if (first_overlapping_row
)
29025 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29028 /* Draw border between windows. */
29029 x_draw_vertical_border (w
);
29031 /* Turn the cursor on again. */
29032 if (cursor_cleared_p
29033 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29034 update_window_cursor (w
, 1);
29038 return mouse_face_overwritten_p
;
29043 /* Redraw (parts) of all windows in the window tree rooted at W that
29044 intersect R. R contains frame pixel coordinates. Value is
29045 non-zero if the exposure overwrites mouse-face. */
29048 expose_window_tree (struct window
*w
, XRectangle
*r
)
29050 struct frame
*f
= XFRAME (w
->frame
);
29051 int mouse_face_overwritten_p
= 0;
29053 while (w
&& !FRAME_GARBAGED_P (f
))
29055 if (WINDOWP (w
->contents
))
29056 mouse_face_overwritten_p
29057 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29059 mouse_face_overwritten_p
|= expose_window (w
, r
);
29061 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29064 return mouse_face_overwritten_p
;
29069 Redisplay an exposed area of frame F. X and Y are the upper-left
29070 corner of the exposed rectangle. W and H are width and height of
29071 the exposed area. All are pixel values. W or H zero means redraw
29072 the entire frame. */
29075 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29078 int mouse_face_overwritten_p
= 0;
29080 TRACE ((stderr
, "expose_frame "));
29082 /* No need to redraw if frame will be redrawn soon. */
29083 if (FRAME_GARBAGED_P (f
))
29085 TRACE ((stderr
, " garbaged\n"));
29089 /* If basic faces haven't been realized yet, there is no point in
29090 trying to redraw anything. This can happen when we get an expose
29091 event while Emacs is starting, e.g. by moving another window. */
29092 if (FRAME_FACE_CACHE (f
) == NULL
29093 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29095 TRACE ((stderr
, " no faces\n"));
29099 if (w
== 0 || h
== 0)
29102 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29103 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29113 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29114 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29116 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29117 if (WINDOWP (f
->tool_bar_window
))
29118 mouse_face_overwritten_p
29119 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29122 #ifdef HAVE_X_WINDOWS
29124 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29125 if (WINDOWP (f
->menu_bar_window
))
29126 mouse_face_overwritten_p
29127 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29128 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29132 /* Some window managers support a focus-follows-mouse style with
29133 delayed raising of frames. Imagine a partially obscured frame,
29134 and moving the mouse into partially obscured mouse-face on that
29135 frame. The visible part of the mouse-face will be highlighted,
29136 then the WM raises the obscured frame. With at least one WM, KDE
29137 2.1, Emacs is not getting any event for the raising of the frame
29138 (even tried with SubstructureRedirectMask), only Expose events.
29139 These expose events will draw text normally, i.e. not
29140 highlighted. Which means we must redo the highlight here.
29141 Subsume it under ``we love X''. --gerd 2001-08-15 */
29142 /* Included in Windows version because Windows most likely does not
29143 do the right thing if any third party tool offers
29144 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29145 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29147 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29148 if (f
== hlinfo
->mouse_face_mouse_frame
)
29150 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29151 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29152 clear_mouse_face (hlinfo
);
29153 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29160 Determine the intersection of two rectangles R1 and R2. Return
29161 the intersection in *RESULT. Value is non-zero if RESULT is not
29165 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29167 XRectangle
*left
, *right
;
29168 XRectangle
*upper
, *lower
;
29169 int intersection_p
= 0;
29171 /* Rearrange so that R1 is the left-most rectangle. */
29173 left
= r1
, right
= r2
;
29175 left
= r2
, right
= r1
;
29177 /* X0 of the intersection is right.x0, if this is inside R1,
29178 otherwise there is no intersection. */
29179 if (right
->x
<= left
->x
+ left
->width
)
29181 result
->x
= right
->x
;
29183 /* The right end of the intersection is the minimum of
29184 the right ends of left and right. */
29185 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29188 /* Same game for Y. */
29190 upper
= r1
, lower
= r2
;
29192 upper
= r2
, lower
= r1
;
29194 /* The upper end of the intersection is lower.y0, if this is inside
29195 of upper. Otherwise, there is no intersection. */
29196 if (lower
->y
<= upper
->y
+ upper
->height
)
29198 result
->y
= lower
->y
;
29200 /* The lower end of the intersection is the minimum of the lower
29201 ends of upper and lower. */
29202 result
->height
= (min (lower
->y
+ lower
->height
,
29203 upper
->y
+ upper
->height
)
29205 intersection_p
= 1;
29209 return intersection_p
;
29212 #endif /* HAVE_WINDOW_SYSTEM */
29215 /***********************************************************************
29217 ***********************************************************************/
29220 syms_of_xdisp (void)
29222 Vwith_echo_area_save_vector
= Qnil
;
29223 staticpro (&Vwith_echo_area_save_vector
);
29225 Vmessage_stack
= Qnil
;
29226 staticpro (&Vmessage_stack
);
29228 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29229 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29231 message_dolog_marker1
= Fmake_marker ();
29232 staticpro (&message_dolog_marker1
);
29233 message_dolog_marker2
= Fmake_marker ();
29234 staticpro (&message_dolog_marker2
);
29235 message_dolog_marker3
= Fmake_marker ();
29236 staticpro (&message_dolog_marker3
);
29239 defsubr (&Sdump_frame_glyph_matrix
);
29240 defsubr (&Sdump_glyph_matrix
);
29241 defsubr (&Sdump_glyph_row
);
29242 defsubr (&Sdump_tool_bar_row
);
29243 defsubr (&Strace_redisplay
);
29244 defsubr (&Strace_to_stderr
);
29246 #ifdef HAVE_WINDOW_SYSTEM
29247 defsubr (&Stool_bar_lines_needed
);
29248 defsubr (&Slookup_image_map
);
29250 defsubr (&Sline_pixel_height
);
29251 defsubr (&Sformat_mode_line
);
29252 defsubr (&Sinvisible_p
);
29253 defsubr (&Scurrent_bidi_paragraph_direction
);
29254 defsubr (&Smove_point_visually
);
29256 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29257 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29258 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29259 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29260 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29261 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29262 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29263 DEFSYM (Qeval
, "eval");
29264 DEFSYM (QCdata
, ":data");
29265 DEFSYM (Qdisplay
, "display");
29266 DEFSYM (Qspace_width
, "space-width");
29267 DEFSYM (Qraise
, "raise");
29268 DEFSYM (Qslice
, "slice");
29269 DEFSYM (Qspace
, "space");
29270 DEFSYM (Qmargin
, "margin");
29271 DEFSYM (Qpointer
, "pointer");
29272 DEFSYM (Qleft_margin
, "left-margin");
29273 DEFSYM (Qright_margin
, "right-margin");
29274 DEFSYM (Qcenter
, "center");
29275 DEFSYM (Qline_height
, "line-height");
29276 DEFSYM (QCalign_to
, ":align-to");
29277 DEFSYM (QCrelative_width
, ":relative-width");
29278 DEFSYM (QCrelative_height
, ":relative-height");
29279 DEFSYM (QCeval
, ":eval");
29280 DEFSYM (QCpropertize
, ":propertize");
29281 DEFSYM (QCfile
, ":file");
29282 DEFSYM (Qfontified
, "fontified");
29283 DEFSYM (Qfontification_functions
, "fontification-functions");
29284 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29285 DEFSYM (Qescape_glyph
, "escape-glyph");
29286 DEFSYM (Qnobreak_space
, "nobreak-space");
29287 DEFSYM (Qimage
, "image");
29288 DEFSYM (Qtext
, "text");
29289 DEFSYM (Qboth
, "both");
29290 DEFSYM (Qboth_horiz
, "both-horiz");
29291 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29292 DEFSYM (QCmap
, ":map");
29293 DEFSYM (QCpointer
, ":pointer");
29294 DEFSYM (Qrect
, "rect");
29295 DEFSYM (Qcircle
, "circle");
29296 DEFSYM (Qpoly
, "poly");
29297 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29298 DEFSYM (Qgrow_only
, "grow-only");
29299 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29300 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29301 DEFSYM (Qposition
, "position");
29302 DEFSYM (Qbuffer_position
, "buffer-position");
29303 DEFSYM (Qobject
, "object");
29304 DEFSYM (Qbar
, "bar");
29305 DEFSYM (Qhbar
, "hbar");
29306 DEFSYM (Qbox
, "box");
29307 DEFSYM (Qhollow
, "hollow");
29308 DEFSYM (Qhand
, "hand");
29309 DEFSYM (Qarrow
, "arrow");
29310 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29312 list_of_error
= list1 (list2 (intern_c_string ("error"),
29313 intern_c_string ("void-variable")));
29314 staticpro (&list_of_error
);
29316 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29317 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29318 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29319 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29321 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29322 staticpro (&echo_buffer
[0]);
29323 staticpro (&echo_buffer
[1]);
29325 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29326 staticpro (&echo_area_buffer
[0]);
29327 staticpro (&echo_area_buffer
[1]);
29329 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29330 staticpro (&Vmessages_buffer_name
);
29332 mode_line_proptrans_alist
= Qnil
;
29333 staticpro (&mode_line_proptrans_alist
);
29334 mode_line_string_list
= Qnil
;
29335 staticpro (&mode_line_string_list
);
29336 mode_line_string_face
= Qnil
;
29337 staticpro (&mode_line_string_face
);
29338 mode_line_string_face_prop
= Qnil
;
29339 staticpro (&mode_line_string_face_prop
);
29340 Vmode_line_unwind_vector
= Qnil
;
29341 staticpro (&Vmode_line_unwind_vector
);
29343 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29345 help_echo_string
= Qnil
;
29346 staticpro (&help_echo_string
);
29347 help_echo_object
= Qnil
;
29348 staticpro (&help_echo_object
);
29349 help_echo_window
= Qnil
;
29350 staticpro (&help_echo_window
);
29351 previous_help_echo_string
= Qnil
;
29352 staticpro (&previous_help_echo_string
);
29353 help_echo_pos
= -1;
29355 DEFSYM (Qright_to_left
, "right-to-left");
29356 DEFSYM (Qleft_to_right
, "left-to-right");
29358 #ifdef HAVE_WINDOW_SYSTEM
29359 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29360 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29361 For example, if a block cursor is over a tab, it will be drawn as
29362 wide as that tab on the display. */);
29363 x_stretch_cursor_p
= 0;
29366 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29367 doc
: /* Non-nil means highlight trailing whitespace.
29368 The face used for trailing whitespace is `trailing-whitespace'. */);
29369 Vshow_trailing_whitespace
= Qnil
;
29371 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29372 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29373 If the value is t, Emacs highlights non-ASCII chars which have the
29374 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29375 or `escape-glyph' face respectively.
29377 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29378 U+2011 (non-breaking hyphen) are affected.
29380 Any other non-nil value means to display these characters as a escape
29381 glyph followed by an ordinary space or hyphen.
29383 A value of nil means no special handling of these characters. */);
29384 Vnobreak_char_display
= Qt
;
29386 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29387 doc
: /* The pointer shape to show in void text areas.
29388 A value of nil means to show the text pointer. Other options are `arrow',
29389 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29390 Vvoid_text_area_pointer
= Qarrow
;
29392 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29393 doc
: /* Non-nil means don't actually do any redisplay.
29394 This is used for internal purposes. */);
29395 Vinhibit_redisplay
= Qnil
;
29397 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29398 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29399 Vglobal_mode_string
= Qnil
;
29401 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29402 doc
: /* Marker for where to display an arrow on top of the buffer text.
29403 This must be the beginning of a line in order to work.
29404 See also `overlay-arrow-string'. */);
29405 Voverlay_arrow_position
= Qnil
;
29407 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29408 doc
: /* String to display as an arrow in non-window frames.
29409 See also `overlay-arrow-position'. */);
29410 Voverlay_arrow_string
= build_pure_c_string ("=>");
29412 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29413 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29414 The symbols on this list are examined during redisplay to determine
29415 where to display overlay arrows. */);
29416 Voverlay_arrow_variable_list
29417 = list1 (intern_c_string ("overlay-arrow-position"));
29419 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29420 doc
: /* The number of lines to try scrolling a window by when point moves out.
29421 If that fails to bring point back on frame, point is centered instead.
29422 If this is zero, point is always centered after it moves off frame.
29423 If you want scrolling to always be a line at a time, you should set
29424 `scroll-conservatively' to a large value rather than set this to 1. */);
29426 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29427 doc
: /* Scroll up to this many lines, to bring point back on screen.
29428 If point moves off-screen, redisplay will scroll by up to
29429 `scroll-conservatively' lines in order to bring point just barely
29430 onto the screen again. If that cannot be done, then redisplay
29431 recenters point as usual.
29433 If the value is greater than 100, redisplay will never recenter point,
29434 but will always scroll just enough text to bring point into view, even
29435 if you move far away.
29437 A value of zero means always recenter point if it moves off screen. */);
29438 scroll_conservatively
= 0;
29440 DEFVAR_INT ("scroll-margin", scroll_margin
,
29441 doc
: /* Number of lines of margin at the top and bottom of a window.
29442 Recenter the window whenever point gets within this many lines
29443 of the top or bottom of the window. */);
29446 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29447 doc
: /* Pixels per inch value for non-window system displays.
29448 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29449 Vdisplay_pixels_per_inch
= make_float (72.0);
29452 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29455 DEFVAR_LISP ("truncate-partial-width-windows",
29456 Vtruncate_partial_width_windows
,
29457 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29458 For an integer value, truncate lines in each window narrower than the
29459 full frame width, provided the window width is less than that integer;
29460 otherwise, respect the value of `truncate-lines'.
29462 For any other non-nil value, truncate lines in all windows that do
29463 not span the full frame width.
29465 A value of nil means to respect the value of `truncate-lines'.
29467 If `word-wrap' is enabled, you might want to reduce this. */);
29468 Vtruncate_partial_width_windows
= make_number (50);
29470 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29471 doc
: /* Maximum buffer size for which line number should be displayed.
29472 If the buffer is bigger than this, the line number does not appear
29473 in the mode line. A value of nil means no limit. */);
29474 Vline_number_display_limit
= Qnil
;
29476 DEFVAR_INT ("line-number-display-limit-width",
29477 line_number_display_limit_width
,
29478 doc
: /* Maximum line width (in characters) for line number display.
29479 If the average length of the lines near point is bigger than this, then the
29480 line number may be omitted from the mode line. */);
29481 line_number_display_limit_width
= 200;
29483 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29484 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29485 highlight_nonselected_windows
= 0;
29487 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29488 doc
: /* Non-nil if more than one frame is visible on this display.
29489 Minibuffer-only frames don't count, but iconified frames do.
29490 This variable is not guaranteed to be accurate except while processing
29491 `frame-title-format' and `icon-title-format'. */);
29493 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29494 doc
: /* Template for displaying the title bar of visible frames.
29495 \(Assuming the window manager supports this feature.)
29497 This variable has the same structure as `mode-line-format', except that
29498 the %c and %l constructs are ignored. It is used only on frames for
29499 which no explicit name has been set \(see `modify-frame-parameters'). */);
29501 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29502 doc
: /* Template for displaying the title bar of an iconified frame.
29503 \(Assuming the window manager supports this feature.)
29504 This variable has the same structure as `mode-line-format' (which see),
29505 and is used only on frames for which no explicit name has been set
29506 \(see `modify-frame-parameters'). */);
29508 = Vframe_title_format
29509 = listn (CONSTYPE_PURE
, 3,
29510 intern_c_string ("multiple-frames"),
29511 build_pure_c_string ("%b"),
29512 listn (CONSTYPE_PURE
, 4,
29513 empty_unibyte_string
,
29514 intern_c_string ("invocation-name"),
29515 build_pure_c_string ("@"),
29516 intern_c_string ("system-name")));
29518 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29519 doc
: /* Maximum number of lines to keep in the message log buffer.
29520 If nil, disable message logging. If t, log messages but don't truncate
29521 the buffer when it becomes large. */);
29522 Vmessage_log_max
= make_number (1000);
29524 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29525 doc
: /* Functions called before redisplay, if window sizes have changed.
29526 The value should be a list of functions that take one argument.
29527 Just before redisplay, for each frame, if any of its windows have changed
29528 size since the last redisplay, or have been split or deleted,
29529 all the functions in the list are called, with the frame as argument. */);
29530 Vwindow_size_change_functions
= Qnil
;
29532 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29533 doc
: /* List of functions to call before redisplaying a window with scrolling.
29534 Each function is called with two arguments, the window and its new
29535 display-start position. Note that these functions are also called by
29536 `set-window-buffer'. Also note that the value of `window-end' is not
29537 valid when these functions are called.
29539 Warning: Do not use this feature to alter the way the window
29540 is scrolled. It is not designed for that, and such use probably won't
29542 Vwindow_scroll_functions
= Qnil
;
29544 DEFVAR_LISP ("window-text-change-functions",
29545 Vwindow_text_change_functions
,
29546 doc
: /* Functions to call in redisplay when text in the window might change. */);
29547 Vwindow_text_change_functions
= Qnil
;
29549 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29550 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29551 Each function is called with two arguments, the window and the end trigger value.
29552 See `set-window-redisplay-end-trigger'. */);
29553 Vredisplay_end_trigger_functions
= Qnil
;
29555 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29556 doc
: /* Non-nil means autoselect window with mouse pointer.
29557 If nil, do not autoselect windows.
29558 A positive number means delay autoselection by that many seconds: a
29559 window is autoselected only after the mouse has remained in that
29560 window for the duration of the delay.
29561 A negative number has a similar effect, but causes windows to be
29562 autoselected only after the mouse has stopped moving. \(Because of
29563 the way Emacs compares mouse events, you will occasionally wait twice
29564 that time before the window gets selected.\)
29565 Any other value means to autoselect window instantaneously when the
29566 mouse pointer enters it.
29568 Autoselection selects the minibuffer only if it is active, and never
29569 unselects the minibuffer if it is active.
29571 When customizing this variable make sure that the actual value of
29572 `focus-follows-mouse' matches the behavior of your window manager. */);
29573 Vmouse_autoselect_window
= Qnil
;
29575 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29576 doc
: /* Non-nil means automatically resize tool-bars.
29577 This dynamically changes the tool-bar's height to the minimum height
29578 that is needed to make all tool-bar items visible.
29579 If value is `grow-only', the tool-bar's height is only increased
29580 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29581 Vauto_resize_tool_bars
= Qt
;
29583 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29584 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29585 auto_raise_tool_bar_buttons_p
= 1;
29587 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29588 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29589 make_cursor_line_fully_visible_p
= 1;
29591 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29592 doc
: /* Border below tool-bar in pixels.
29593 If an integer, use it as the height of the border.
29594 If it is one of `internal-border-width' or `border-width', use the
29595 value of the corresponding frame parameter.
29596 Otherwise, no border is added below the tool-bar. */);
29597 Vtool_bar_border
= Qinternal_border_width
;
29599 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29600 doc
: /* Margin around tool-bar buttons in pixels.
29601 If an integer, use that for both horizontal and vertical margins.
29602 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29603 HORZ specifying the horizontal margin, and VERT specifying the
29604 vertical margin. */);
29605 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29607 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29608 doc
: /* Relief thickness of tool-bar buttons. */);
29609 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29611 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29612 doc
: /* Tool bar style to use.
29614 image - show images only
29615 text - show text only
29616 both - show both, text below image
29617 both-horiz - show text to the right of the image
29618 text-image-horiz - show text to the left of the image
29619 any other - use system default or image if no system default.
29621 This variable only affects the GTK+ toolkit version of Emacs. */);
29622 Vtool_bar_style
= Qnil
;
29624 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29625 doc
: /* Maximum number of characters a label can have to be shown.
29626 The tool bar style must also show labels for this to have any effect, see
29627 `tool-bar-style'. */);
29628 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29630 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29631 doc
: /* List of functions to call to fontify regions of text.
29632 Each function is called with one argument POS. Functions must
29633 fontify a region starting at POS in the current buffer, and give
29634 fontified regions the property `fontified'. */);
29635 Vfontification_functions
= Qnil
;
29636 Fmake_variable_buffer_local (Qfontification_functions
);
29638 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29639 unibyte_display_via_language_environment
,
29640 doc
: /* Non-nil means display unibyte text according to language environment.
29641 Specifically, this means that raw bytes in the range 160-255 decimal
29642 are displayed by converting them to the equivalent multibyte characters
29643 according to the current language environment. As a result, they are
29644 displayed according to the current fontset.
29646 Note that this variable affects only how these bytes are displayed,
29647 but does not change the fact they are interpreted as raw bytes. */);
29648 unibyte_display_via_language_environment
= 0;
29650 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29651 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29652 If a float, it specifies a fraction of the mini-window frame's height.
29653 If an integer, it specifies a number of lines. */);
29654 Vmax_mini_window_height
= make_float (0.25);
29656 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29657 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29658 A value of nil means don't automatically resize mini-windows.
29659 A value of t means resize them to fit the text displayed in them.
29660 A value of `grow-only', the default, means let mini-windows grow only;
29661 they return to their normal size when the minibuffer is closed, or the
29662 echo area becomes empty. */);
29663 Vresize_mini_windows
= Qgrow_only
;
29665 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29666 doc
: /* Alist specifying how to blink the cursor off.
29667 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29668 `cursor-type' frame-parameter or variable equals ON-STATE,
29669 comparing using `equal', Emacs uses OFF-STATE to specify
29670 how to blink it off. ON-STATE and OFF-STATE are values for
29671 the `cursor-type' frame parameter.
29673 If a frame's ON-STATE has no entry in this list,
29674 the frame's other specifications determine how to blink the cursor off. */);
29675 Vblink_cursor_alist
= Qnil
;
29677 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29678 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29679 If non-nil, windows are automatically scrolled horizontally to make
29680 point visible. */);
29681 automatic_hscrolling_p
= 1;
29682 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29684 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29685 doc
: /* How many columns away from the window edge point is allowed to get
29686 before automatic hscrolling will horizontally scroll the window. */);
29687 hscroll_margin
= 5;
29689 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29690 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29691 When point is less than `hscroll-margin' columns from the window
29692 edge, automatic hscrolling will scroll the window by the amount of columns
29693 determined by this variable. If its value is a positive integer, scroll that
29694 many columns. If it's a positive floating-point number, it specifies the
29695 fraction of the window's width to scroll. If it's nil or zero, point will be
29696 centered horizontally after the scroll. Any other value, including negative
29697 numbers, are treated as if the value were zero.
29699 Automatic hscrolling always moves point outside the scroll margin, so if
29700 point was more than scroll step columns inside the margin, the window will
29701 scroll more than the value given by the scroll step.
29703 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29704 and `scroll-right' overrides this variable's effect. */);
29705 Vhscroll_step
= make_number (0);
29707 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29708 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29709 Bind this around calls to `message' to let it take effect. */);
29710 message_truncate_lines
= 0;
29712 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29713 doc
: /* Normal hook run to update the menu bar definitions.
29714 Redisplay runs this hook before it redisplays the menu bar.
29715 This is used to update submenus such as Buffers,
29716 whose contents depend on various data. */);
29717 Vmenu_bar_update_hook
= Qnil
;
29719 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29720 doc
: /* Frame for which we are updating a menu.
29721 The enable predicate for a menu binding should check this variable. */);
29722 Vmenu_updating_frame
= Qnil
;
29724 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29725 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29726 inhibit_menubar_update
= 0;
29728 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29729 doc
: /* Prefix prepended to all continuation lines at display time.
29730 The value may be a string, an image, or a stretch-glyph; it is
29731 interpreted in the same way as the value of a `display' text property.
29733 This variable is overridden by any `wrap-prefix' text or overlay
29736 To add a prefix to non-continuation lines, use `line-prefix'. */);
29737 Vwrap_prefix
= Qnil
;
29738 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29739 Fmake_variable_buffer_local (Qwrap_prefix
);
29741 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29742 doc
: /* Prefix prepended to all non-continuation lines at display time.
29743 The value may be a string, an image, or a stretch-glyph; it is
29744 interpreted in the same way as the value of a `display' text property.
29746 This variable is overridden by any `line-prefix' text or overlay
29749 To add a prefix to continuation lines, use `wrap-prefix'. */);
29750 Vline_prefix
= Qnil
;
29751 DEFSYM (Qline_prefix
, "line-prefix");
29752 Fmake_variable_buffer_local (Qline_prefix
);
29754 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29755 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29756 inhibit_eval_during_redisplay
= 0;
29758 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29759 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29760 inhibit_free_realized_faces
= 0;
29763 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29764 doc
: /* Inhibit try_window_id display optimization. */);
29765 inhibit_try_window_id
= 0;
29767 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29768 doc
: /* Inhibit try_window_reusing display optimization. */);
29769 inhibit_try_window_reusing
= 0;
29771 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29772 doc
: /* Inhibit try_cursor_movement display optimization. */);
29773 inhibit_try_cursor_movement
= 0;
29774 #endif /* GLYPH_DEBUG */
29776 DEFVAR_INT ("overline-margin", overline_margin
,
29777 doc
: /* Space between overline and text, in pixels.
29778 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29779 margin to the character height. */);
29780 overline_margin
= 2;
29782 DEFVAR_INT ("underline-minimum-offset",
29783 underline_minimum_offset
,
29784 doc
: /* Minimum distance between baseline and underline.
29785 This can improve legibility of underlined text at small font sizes,
29786 particularly when using variable `x-use-underline-position-properties'
29787 with fonts that specify an UNDERLINE_POSITION relatively close to the
29788 baseline. The default value is 1. */);
29789 underline_minimum_offset
= 1;
29791 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29792 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29793 This feature only works when on a window system that can change
29794 cursor shapes. */);
29795 display_hourglass_p
= 1;
29797 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29798 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29799 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29801 #ifdef HAVE_WINDOW_SYSTEM
29802 hourglass_atimer
= NULL
;
29803 hourglass_shown_p
= 0;
29804 #endif /* HAVE_WINDOW_SYSTEM */
29806 DEFSYM (Qglyphless_char
, "glyphless-char");
29807 DEFSYM (Qhex_code
, "hex-code");
29808 DEFSYM (Qempty_box
, "empty-box");
29809 DEFSYM (Qthin_space
, "thin-space");
29810 DEFSYM (Qzero_width
, "zero-width");
29812 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
29813 doc
: /* Function run just before redisplay.
29814 It is called with one argument, which is the set of windows that are to
29815 be redisplayed. This set can be nil (meaning, only the selected window),
29816 or t (meaning all windows). */);
29817 Vpre_redisplay_function
= intern ("ignore");
29819 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29820 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29822 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29823 doc
: /* Char-table defining glyphless characters.
29824 Each element, if non-nil, should be one of the following:
29825 an ASCII acronym string: display this string in a box
29826 `hex-code': display the hexadecimal code of a character in a box
29827 `empty-box': display as an empty box
29828 `thin-space': display as 1-pixel width space
29829 `zero-width': don't display
29830 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29831 display method for graphical terminals and text terminals respectively.
29832 GRAPHICAL and TEXT should each have one of the values listed above.
29834 The char-table has one extra slot to control the display of a character for
29835 which no font is found. This slot only takes effect on graphical terminals.
29836 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29837 `thin-space'. The default is `empty-box'.
29839 If a character has a non-nil entry in an active display table, the
29840 display table takes effect; in this case, Emacs does not consult
29841 `glyphless-char-display' at all. */);
29842 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29843 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29846 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29847 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29848 Vdebug_on_message
= Qnil
;
29850 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
29852 Vredisplay__all_windows_cause
29853 = Fmake_vector (make_number (100), make_number (0));
29855 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
29857 Vredisplay__mode_lines_cause
29858 = Fmake_vector (make_number (100), make_number (0));
29862 /* Initialize this module when Emacs starts. */
29867 CHARPOS (this_line_start_pos
) = 0;
29869 if (!noninteractive
)
29871 struct window
*m
= XWINDOW (minibuf_window
);
29872 Lisp_Object frame
= m
->frame
;
29873 struct frame
*f
= XFRAME (frame
);
29874 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29875 struct window
*r
= XWINDOW (root
);
29878 echo_area_window
= minibuf_window
;
29880 r
->top_line
= FRAME_TOP_MARGIN (f
);
29881 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29882 r
->total_cols
= FRAME_COLS (f
);
29884 m
->top_line
= FRAME_LINES (f
) - 1;
29885 m
->total_lines
= 1;
29886 m
->total_cols
= FRAME_COLS (f
);
29888 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29889 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29890 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29892 /* The default ellipsis glyphs `...'. */
29893 for (i
= 0; i
< 3; ++i
)
29894 default_invis_vector
[i
] = make_number ('.');
29898 /* Allocate the buffer for frame titles.
29899 Also used for `format-mode-line'. */
29901 mode_line_noprop_buf
= xmalloc (size
);
29902 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29903 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29904 mode_line_target
= MODE_LINE_DISPLAY
;
29907 help_echo_showing_p
= 0;
29910 #ifdef HAVE_WINDOW_SYSTEM
29912 /* Platform-independent portion of hourglass implementation. */
29914 /* Cancel a currently active hourglass timer, and start a new one. */
29916 start_hourglass (void)
29918 struct timespec delay
;
29920 cancel_hourglass ();
29922 if (INTEGERP (Vhourglass_delay
)
29923 && XINT (Vhourglass_delay
) > 0)
29924 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29925 TYPE_MAXIMUM (time_t)),
29927 else if (FLOATP (Vhourglass_delay
)
29928 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29929 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29931 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29935 extern void w32_note_current_window (void);
29936 w32_note_current_window ();
29938 #endif /* HAVE_NTGUI */
29940 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29941 show_hourglass
, NULL
);
29945 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29948 cancel_hourglass (void)
29950 if (hourglass_atimer
)
29952 cancel_atimer (hourglass_atimer
);
29953 hourglass_atimer
= NULL
;
29956 if (hourglass_shown_p
)
29960 #endif /* HAVE_WINDOW_SYSTEM */