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_max_ascent
, 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 /* Beware: selected_window can be nil during early stages. */
624 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
625 redisplay_other_windows ();
630 fset_redisplay (struct frame
*f
)
632 redisplay_other_windows ();
637 bset_redisplay (struct buffer
*b
)
639 int count
= buffer_window_count (b
);
642 /* ... it's visible in other window than selected, */
643 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
644 redisplay_other_windows ();
645 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
646 so that if we later set windows_or_buffers_changed, this buffer will
648 b
->text
->redisplay
= true;
653 bset_update_mode_line (struct buffer
*b
)
655 if (!update_mode_lines
)
656 update_mode_lines
= REDISPLAY_SOME
;
657 b
->text
->redisplay
= true;
662 /* Non-zero means print traces of redisplay if compiled with
663 GLYPH_DEBUG defined. */
665 bool trace_redisplay_p
;
667 #endif /* GLYPH_DEBUG */
669 #ifdef DEBUG_TRACE_MOVE
670 /* Non-zero means trace with TRACE_MOVE to stderr. */
673 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
675 #define TRACE_MOVE(x) (void) 0
678 static Lisp_Object Qauto_hscroll_mode
;
680 /* Buffer being redisplayed -- for redisplay_window_error. */
682 static struct buffer
*displayed_buffer
;
684 /* Value returned from text property handlers (see below). */
689 HANDLED_RECOMPUTE_PROPS
,
690 HANDLED_OVERLAY_STRING_CONSUMED
,
694 /* A description of text properties that redisplay is interested
699 /* The name of the property. */
702 /* A unique index for the property. */
705 /* A handler function called to set up iterator IT from the property
706 at IT's current position. Value is used to steer handle_stop. */
707 enum prop_handled (*handler
) (struct it
*it
);
710 static enum prop_handled
handle_face_prop (struct it
*);
711 static enum prop_handled
handle_invisible_prop (struct it
*);
712 static enum prop_handled
handle_display_prop (struct it
*);
713 static enum prop_handled
handle_composition_prop (struct it
*);
714 static enum prop_handled
handle_overlay_change (struct it
*);
715 static enum prop_handled
handle_fontified_prop (struct it
*);
717 /* Properties handled by iterators. */
719 static struct props it_props
[] =
721 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
722 /* Handle `face' before `display' because some sub-properties of
723 `display' need to know the face. */
724 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
725 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
726 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
727 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
731 /* Value is the position described by X. If X is a marker, value is
732 the marker_position of X. Otherwise, value is X. */
734 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
736 /* Enumeration returned by some move_it_.* functions internally. */
740 /* Not used. Undefined value. */
743 /* Move ended at the requested buffer position or ZV. */
744 MOVE_POS_MATCH_OR_ZV
,
746 /* Move ended at the requested X pixel position. */
749 /* Move within a line ended at the end of a line that must be
753 /* Move within a line ended at the end of a line that would
754 be displayed truncated. */
757 /* Move within a line ended at a line end. */
761 /* This counter is used to clear the face cache every once in a while
762 in redisplay_internal. It is incremented for each redisplay.
763 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
766 #define CLEAR_FACE_CACHE_COUNT 500
767 static int clear_face_cache_count
;
769 /* Similarly for the image cache. */
771 #ifdef HAVE_WINDOW_SYSTEM
772 #define CLEAR_IMAGE_CACHE_COUNT 101
773 static int clear_image_cache_count
;
775 /* Null glyph slice */
776 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
779 /* True while redisplay_internal is in progress. */
783 static Lisp_Object Qinhibit_free_realized_faces
;
784 static Lisp_Object Qmode_line_default_help_echo
;
786 /* If a string, XTread_socket generates an event to display that string.
787 (The display is done in read_char.) */
789 Lisp_Object help_echo_string
;
790 Lisp_Object help_echo_window
;
791 Lisp_Object help_echo_object
;
792 ptrdiff_t help_echo_pos
;
794 /* Temporary variable for XTread_socket. */
796 Lisp_Object previous_help_echo_string
;
798 /* Platform-independent portion of hourglass implementation. */
800 #ifdef HAVE_WINDOW_SYSTEM
802 /* Non-zero means an hourglass cursor is currently shown. */
803 bool hourglass_shown_p
;
805 /* If non-null, an asynchronous timer that, when it expires, displays
806 an hourglass cursor on all frames. */
807 struct atimer
*hourglass_atimer
;
809 #endif /* HAVE_WINDOW_SYSTEM */
811 /* Name of the face used to display glyphless characters. */
812 static Lisp_Object Qglyphless_char
;
814 /* Symbol for the purpose of Vglyphless_char_display. */
815 static Lisp_Object Qglyphless_char_display
;
817 /* Method symbols for Vglyphless_char_display. */
818 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
820 /* Default number of seconds to wait before displaying an hourglass
822 #define DEFAULT_HOURGLASS_DELAY 1
824 #ifdef HAVE_WINDOW_SYSTEM
826 /* Default pixel width of `thin-space' display method. */
827 #define THIN_SPACE_WIDTH 1
829 #endif /* HAVE_WINDOW_SYSTEM */
831 /* Function prototypes. */
833 static void setup_for_ellipsis (struct it
*, int);
834 static void set_iterator_to_next (struct it
*, int);
835 static void mark_window_display_accurate_1 (struct window
*, int);
836 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
837 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
838 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
839 static int cursor_row_p (struct glyph_row
*);
840 static int redisplay_mode_lines (Lisp_Object
, bool);
841 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
843 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
845 static void handle_line_prefix (struct it
*);
847 static void pint2str (char *, int, ptrdiff_t);
848 static void pint2hrstr (char *, int, ptrdiff_t);
849 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
851 static int text_outside_line_unchanged_p (struct window
*,
852 ptrdiff_t, ptrdiff_t);
853 static void store_mode_line_noprop_char (char);
854 static int store_mode_line_noprop (const char *, int, int);
855 static void handle_stop (struct it
*);
856 static void handle_stop_backwards (struct it
*, ptrdiff_t);
857 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
858 static void ensure_echo_area_buffers (void);
859 static void unwind_with_echo_area_buffer (Lisp_Object
);
860 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
861 static int with_echo_area_buffer (struct window
*, int,
862 int (*) (ptrdiff_t, Lisp_Object
),
863 ptrdiff_t, Lisp_Object
);
864 static void clear_garbaged_frames (void);
865 static int current_message_1 (ptrdiff_t, Lisp_Object
);
866 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
867 static void set_message (Lisp_Object
);
868 static int set_message_1 (ptrdiff_t, Lisp_Object
);
869 static int display_echo_area (struct window
*);
870 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
871 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
872 static void unwind_redisplay (void);
873 static int string_char_and_length (const unsigned char *, int *);
874 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
876 static int compute_window_start_on_continuation_line (struct window
*);
877 static void insert_left_trunc_glyphs (struct it
*);
878 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
880 static void extend_face_to_end_of_line (struct it
*);
881 static int append_space_for_newline (struct it
*, int);
882 static int cursor_row_fully_visible_p (struct window
*, int, int);
883 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
884 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
885 static int trailing_whitespace_p (ptrdiff_t);
886 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
887 static void push_it (struct it
*, struct text_pos
*);
888 static void iterate_out_of_display_property (struct it
*);
889 static void pop_it (struct it
*);
890 static void sync_frame_with_window_matrix_rows (struct window
*);
891 static void redisplay_internal (void);
892 static int echo_area_display (int);
893 static void redisplay_windows (Lisp_Object
);
894 static void redisplay_window (Lisp_Object
, bool);
895 static Lisp_Object
redisplay_window_error (Lisp_Object
);
896 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
897 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
898 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
899 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
901 static int update_menu_bar (struct frame
*, int, int);
902 static int try_window_reusing_current_matrix (struct window
*);
903 static int try_window_id (struct window
*);
904 static int display_line (struct it
*);
905 static int display_mode_lines (struct window
*);
906 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
907 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
908 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
909 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
910 static void display_menu_bar (struct window
*);
911 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
913 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
914 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
915 static void compute_line_metrics (struct it
*);
916 static void run_redisplay_end_trigger_hook (struct it
*);
917 static int get_overlay_strings (struct it
*, ptrdiff_t);
918 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
919 static void next_overlay_string (struct it
*);
920 static void reseat (struct it
*, struct text_pos
, int);
921 static void reseat_1 (struct it
*, struct text_pos
, int);
922 static void back_to_previous_visible_line_start (struct it
*);
923 static void reseat_at_next_visible_line_start (struct it
*, int);
924 static int next_element_from_ellipsis (struct it
*);
925 static int next_element_from_display_vector (struct it
*);
926 static int next_element_from_string (struct it
*);
927 static int next_element_from_c_string (struct it
*);
928 static int next_element_from_buffer (struct it
*);
929 static int next_element_from_composition (struct it
*);
930 static int next_element_from_image (struct it
*);
931 static int next_element_from_stretch (struct it
*);
932 static void load_overlay_strings (struct it
*, ptrdiff_t);
933 static int init_from_display_pos (struct it
*, struct window
*,
934 struct display_pos
*);
935 static void reseat_to_string (struct it
*, const char *,
936 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
937 static int get_next_display_element (struct it
*);
938 static enum move_it_result
939 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
940 enum move_operation_enum
);
941 static void get_visually_first_element (struct it
*);
942 static void init_to_row_start (struct it
*, struct window
*,
944 static int init_to_row_end (struct it
*, struct window
*,
946 static void back_to_previous_line_start (struct it
*);
947 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
948 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
949 Lisp_Object
, ptrdiff_t);
950 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
951 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
952 static ptrdiff_t number_of_chars (const char *, bool);
953 static void compute_stop_pos (struct it
*);
954 static void compute_string_pos (struct text_pos
*, struct text_pos
,
956 static int face_before_or_after_it_pos (struct it
*, int);
957 static ptrdiff_t next_overlay_change (ptrdiff_t);
958 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
959 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
960 static int handle_single_display_spec (struct it
*, Lisp_Object
,
961 Lisp_Object
, Lisp_Object
,
962 struct text_pos
*, ptrdiff_t, int, int);
963 static int underlying_face_id (struct it
*);
964 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
967 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
968 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
970 #ifdef HAVE_WINDOW_SYSTEM
972 static void x_consider_frame_title (Lisp_Object
);
973 static void update_tool_bar (struct frame
*, int);
974 static int redisplay_tool_bar (struct frame
*);
975 static void x_draw_bottom_divider (struct window
*w
);
976 static void notice_overwritten_cursor (struct window
*,
979 static void append_stretch_glyph (struct it
*, Lisp_Object
,
983 #endif /* HAVE_WINDOW_SYSTEM */
985 static void produce_special_glyphs (struct it
*, enum display_element_type
);
986 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
987 static bool coords_in_mouse_face_p (struct window
*, int, int);
991 /***********************************************************************
992 Window display dimensions
993 ***********************************************************************/
995 /* Return the bottom boundary y-position for text lines in window W.
996 This is the first y position at which a line cannot start.
997 It is relative to the top of the window.
999 This is the height of W minus the height of a mode line, if any. */
1002 window_text_bottom_y (struct window
*w
)
1004 int height
= WINDOW_PIXEL_HEIGHT (w
);
1006 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1008 if (WINDOW_WANTS_MODELINE_P (w
))
1009 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1014 /* Return the pixel width of display area AREA of window W.
1015 ANY_AREA means return the total width of W, not including
1016 fringes to the left and right of the window. */
1019 window_box_width (struct window
*w
, enum glyph_row_area area
)
1021 int pixels
= w
->pixel_width
;
1023 if (!w
->pseudo_window_p
)
1025 pixels
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
1026 pixels
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
1028 if (area
== TEXT_AREA
)
1029 pixels
-= (WINDOW_MARGINS_WIDTH (w
)
1030 + WINDOW_FRINGES_WIDTH (w
));
1031 else if (area
== LEFT_MARGIN_AREA
)
1032 pixels
= WINDOW_LEFT_MARGIN_WIDTH (w
);
1033 else if (area
== RIGHT_MARGIN_AREA
)
1034 pixels
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
1041 /* Return the pixel height of the display area of window W, not
1042 including mode lines of W, if any. */
1045 window_box_height (struct window
*w
)
1047 struct frame
*f
= XFRAME (w
->frame
);
1048 int height
= WINDOW_PIXEL_HEIGHT (w
);
1050 eassert (height
>= 0);
1052 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1054 /* Note: the code below that determines the mode-line/header-line
1055 height is essentially the same as that contained in the macro
1056 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1057 the appropriate glyph row has its `mode_line_p' flag set,
1058 and if it doesn't, uses estimate_mode_line_height instead. */
1060 if (WINDOW_WANTS_MODELINE_P (w
))
1062 struct glyph_row
*ml_row
1063 = (w
->current_matrix
&& w
->current_matrix
->rows
1064 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1066 if (ml_row
&& ml_row
->mode_line_p
)
1067 height
-= ml_row
->height
;
1069 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1072 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1074 struct glyph_row
*hl_row
1075 = (w
->current_matrix
&& w
->current_matrix
->rows
1076 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1078 if (hl_row
&& hl_row
->mode_line_p
)
1079 height
-= hl_row
->height
;
1081 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1084 /* With a very small font and a mode-line that's taller than
1085 default, we might end up with a negative height. */
1086 return max (0, height
);
1089 /* Return the window-relative coordinate of the left edge of display
1090 area AREA of window W. ANY_AREA means return the left edge of the
1091 whole window, to the right of the left fringe of W. */
1094 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1098 if (w
->pseudo_window_p
)
1101 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1103 if (area
== TEXT_AREA
)
1104 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1105 + window_box_width (w
, LEFT_MARGIN_AREA
));
1106 else if (area
== RIGHT_MARGIN_AREA
)
1107 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1108 + window_box_width (w
, LEFT_MARGIN_AREA
)
1109 + window_box_width (w
, TEXT_AREA
)
1110 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1112 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1113 else if (area
== LEFT_MARGIN_AREA
1114 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1115 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1121 /* Return the window-relative coordinate of the right edge of display
1122 area AREA of window W. ANY_AREA means return the right edge of the
1123 whole window, to the left of the right fringe of W. */
1126 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1128 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1131 /* Return the frame-relative coordinate of the left edge of display
1132 area AREA of window W. ANY_AREA means return the left edge of the
1133 whole window, to the right of the left fringe of W. */
1136 window_box_left (struct window
*w
, enum glyph_row_area area
)
1138 struct frame
*f
= XFRAME (w
->frame
);
1141 if (w
->pseudo_window_p
)
1142 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1144 x
= (WINDOW_LEFT_EDGE_X (w
)
1145 + window_box_left_offset (w
, area
));
1151 /* Return the frame-relative coordinate of the right edge of display
1152 area AREA of window W. ANY_AREA means return the right edge of the
1153 whole window, to the left of the right fringe of W. */
1156 window_box_right (struct window
*w
, enum glyph_row_area area
)
1158 return window_box_left (w
, area
) + window_box_width (w
, area
);
1161 /* Get the bounding box of the display area AREA of window W, without
1162 mode lines, in frame-relative coordinates. ANY_AREA means the
1163 whole window, not including the left and right fringes of
1164 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1165 coordinates of the upper-left corner of the box. Return in
1166 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1169 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1170 int *box_y
, int *box_width
, int *box_height
)
1173 *box_width
= window_box_width (w
, area
);
1175 *box_height
= window_box_height (w
);
1177 *box_x
= window_box_left (w
, area
);
1180 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1181 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1182 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1186 #ifdef HAVE_WINDOW_SYSTEM
1188 /* Get the bounding box of the display area AREA of window W, without
1189 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1190 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1191 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1192 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1196 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1197 int *bottom_right_x
, int *bottom_right_y
)
1199 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1200 bottom_right_x
, bottom_right_y
);
1201 *bottom_right_x
+= *top_left_x
;
1202 *bottom_right_y
+= *top_left_y
;
1205 #endif /* HAVE_WINDOW_SYSTEM */
1207 /***********************************************************************
1209 ***********************************************************************/
1211 /* Return the bottom y-position of the line the iterator IT is in.
1212 This can modify IT's settings. */
1215 line_bottom_y (struct it
*it
)
1217 int line_height
= it
->max_ascent
+ it
->max_descent
;
1218 int line_top_y
= it
->current_y
;
1220 if (line_height
== 0)
1223 line_height
= last_height
;
1224 else if (IT_CHARPOS (*it
) < ZV
)
1226 move_it_by_lines (it
, 1);
1227 line_height
= (it
->max_ascent
|| it
->max_descent
1228 ? it
->max_ascent
+ it
->max_descent
1233 struct glyph_row
*row
= it
->glyph_row
;
1235 /* Use the default character height. */
1236 it
->glyph_row
= NULL
;
1237 it
->what
= IT_CHARACTER
;
1240 PRODUCE_GLYPHS (it
);
1241 line_height
= it
->ascent
+ it
->descent
;
1242 it
->glyph_row
= row
;
1246 return line_top_y
+ line_height
;
1249 DEFUN ("line-pixel-height", Fline_pixel_height
,
1250 Sline_pixel_height
, 0, 0, 0,
1251 doc
: /* Return height in pixels of text line in the selected window.
1253 Value is the height in pixels of the line at point. */)
1258 struct window
*w
= XWINDOW (selected_window
);
1260 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1261 start_display (&it
, w
, pt
);
1262 it
.vpos
= it
.current_y
= 0;
1264 return make_number (line_bottom_y (&it
));
1267 /* Return the default pixel height of text lines in window W. The
1268 value is the canonical height of the W frame's default font, plus
1269 any extra space required by the line-spacing variable or frame
1272 Implementation note: this ignores any line-spacing text properties
1273 put on the newline characters. This is because those properties
1274 only affect the _screen_ line ending in the newline (i.e., in a
1275 continued line, only the last screen line will be affected), which
1276 means only a small number of lines in a buffer can ever use this
1277 feature. Since this function is used to compute the default pixel
1278 equivalent of text lines in a window, we can safely ignore those
1279 few lines. For the same reasons, we ignore the line-height
1282 default_line_pixel_height (struct window
*w
)
1284 struct frame
*f
= WINDOW_XFRAME (w
);
1285 int height
= FRAME_LINE_HEIGHT (f
);
1287 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1289 struct buffer
*b
= XBUFFER (w
->contents
);
1290 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1293 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1296 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1297 height
+= XFASTINT (val
);
1298 else if (FLOATP (val
))
1300 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1307 height
+= f
->extra_line_spacing
;
1313 /* Subroutine of pos_visible_p below. Extracts a display string, if
1314 any, from the display spec given as its argument. */
1316 string_from_display_spec (Lisp_Object spec
)
1320 while (CONSP (spec
))
1322 if (STRINGP (XCAR (spec
)))
1327 else if (VECTORP (spec
))
1331 for (i
= 0; i
< ASIZE (spec
); i
++)
1333 if (STRINGP (AREF (spec
, i
)))
1334 return AREF (spec
, i
);
1343 /* Limit insanely large values of W->hscroll on frame F to the largest
1344 value that will still prevent first_visible_x and last_visible_x of
1345 'struct it' from overflowing an int. */
1347 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1349 ptrdiff_t window_hscroll
= w
->hscroll
;
1350 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1351 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1353 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1354 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1356 return window_hscroll
;
1359 /* Return 1 if position CHARPOS is visible in window W.
1360 CHARPOS < 0 means return info about WINDOW_END position.
1361 If visible, set *X and *Y to pixel coordinates of top left corner.
1362 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1363 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1366 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1367 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1370 void *itdata
= bidi_shelve_cache ();
1371 struct text_pos top
;
1373 struct buffer
*old_buffer
= NULL
;
1375 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1378 if (XBUFFER (w
->contents
) != current_buffer
)
1380 old_buffer
= current_buffer
;
1381 set_buffer_internal_1 (XBUFFER (w
->contents
));
1384 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1385 /* Scrolling a minibuffer window via scroll bar when the echo area
1386 shows long text sometimes resets the minibuffer contents behind
1388 if (CHARPOS (top
) > ZV
)
1389 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1391 /* Compute exact mode line heights. */
1392 if (WINDOW_WANTS_MODELINE_P (w
))
1394 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1395 BVAR (current_buffer
, mode_line_format
));
1397 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1398 w
->header_line_height
1399 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1400 BVAR (current_buffer
, header_line_format
));
1402 start_display (&it
, w
, top
);
1403 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1404 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1407 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1408 && IT_CHARPOS (it
) >= charpos
)
1409 /* When scanning backwards under bidi iteration, move_it_to
1410 stops at or _before_ CHARPOS, because it stops at or to
1411 the _right_ of the character at CHARPOS. */
1412 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1413 && IT_CHARPOS (it
) <= charpos
)))
1415 /* We have reached CHARPOS, or passed it. How the call to
1416 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1417 or covered by a display property, move_it_to stops at the end
1418 of the invisible text, to the right of CHARPOS. (ii) If
1419 CHARPOS is in a display vector, move_it_to stops on its last
1421 int top_x
= it
.current_x
;
1422 int top_y
= it
.current_y
;
1423 /* Calling line_bottom_y may change it.method, it.position, etc. */
1424 enum it_method it_method
= it
.method
;
1425 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1426 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1428 if (top_y
< window_top_y
)
1429 visible_p
= bottom_y
> window_top_y
;
1430 else if (top_y
< it
.last_visible_y
)
1432 if (bottom_y
>= it
.last_visible_y
1433 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1434 && IT_CHARPOS (it
) < charpos
)
1436 /* When the last line of the window is scanned backwards
1437 under bidi iteration, we could be duped into thinking
1438 that we have passed CHARPOS, when in fact move_it_to
1439 simply stopped short of CHARPOS because it reached
1440 last_visible_y. To see if that's what happened, we call
1441 move_it_to again with a slightly larger vertical limit,
1442 and see if it actually moved vertically; if it did, we
1443 didn't really reach CHARPOS, which is beyond window end. */
1444 struct it save_it
= it
;
1445 /* Why 10? because we don't know how many canonical lines
1446 will the height of the next line(s) be. So we guess. */
1447 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1449 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1450 MOVE_TO_POS
| MOVE_TO_Y
);
1451 if (it
.current_y
> top_y
)
1458 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1460 /* We stopped on the last glyph of a display vector.
1461 Try and recompute. Hack alert! */
1462 if (charpos
< 2 || top
.charpos
>= charpos
)
1463 top_x
= it
.glyph_row
->x
;
1466 struct it it2
, it2_prev
;
1467 /* The idea is to get to the previous buffer
1468 position, consume the character there, and use
1469 the pixel coordinates we get after that. But if
1470 the previous buffer position is also displayed
1471 from a display vector, we need to consume all of
1472 the glyphs from that display vector. */
1473 start_display (&it2
, w
, top
);
1474 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1475 /* If we didn't get to CHARPOS - 1, there's some
1476 replacing display property at that position, and
1477 we stopped after it. That is exactly the place
1478 whose coordinates we want. */
1479 if (IT_CHARPOS (it2
) != charpos
- 1)
1483 /* Iterate until we get out of the display
1484 vector that displays the character at
1487 get_next_display_element (&it2
);
1488 PRODUCE_GLYPHS (&it2
);
1490 set_iterator_to_next (&it2
, 1);
1491 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1492 && IT_CHARPOS (it2
) < charpos
);
1494 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1495 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1496 top_x
= it
.glyph_row
->x
;
1499 top_x
= it2_prev
.current_x
;
1500 top_y
= it2_prev
.current_y
;
1504 else if (IT_CHARPOS (it
) != charpos
)
1506 Lisp_Object cpos
= make_number (charpos
);
1507 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1508 Lisp_Object string
= string_from_display_spec (spec
);
1509 struct text_pos tpos
;
1510 int replacing_spec_p
;
1511 bool newline_in_string
1513 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1515 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1518 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1519 charpos
, FRAME_WINDOW_P (it
.f
)));
1520 /* The tricky code below is needed because there's a
1521 discrepancy between move_it_to and how we set cursor
1522 when PT is at the beginning of a portion of text
1523 covered by a display property or an overlay with a
1524 display property, or the display line ends in a
1525 newline from a display string. move_it_to will stop
1526 _after_ such display strings, whereas
1527 set_cursor_from_row conspires with cursor_row_p to
1528 place the cursor on the first glyph produced from the
1531 /* We have overshoot PT because it is covered by a
1532 display property that replaces the text it covers.
1533 If the string includes embedded newlines, we are also
1534 in the wrong display line. Backtrack to the correct
1535 line, where the display property begins. */
1536 if (replacing_spec_p
)
1538 Lisp_Object startpos
, endpos
;
1539 EMACS_INT start
, end
;
1543 /* Find the first and the last buffer positions
1544 covered by the display string. */
1546 Fnext_single_char_property_change (cpos
, Qdisplay
,
1549 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1551 start
= XFASTINT (startpos
);
1552 end
= XFASTINT (endpos
);
1553 /* Move to the last buffer position before the
1554 display property. */
1555 start_display (&it3
, w
, top
);
1556 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1557 /* Move forward one more line if the position before
1558 the display string is a newline or if it is the
1559 rightmost character on a line that is
1560 continued or word-wrapped. */
1561 if (it3
.method
== GET_FROM_BUFFER
1563 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1564 move_it_by_lines (&it3
, 1);
1565 else if (move_it_in_display_line_to (&it3
, -1,
1569 == MOVE_LINE_CONTINUED
)
1571 move_it_by_lines (&it3
, 1);
1572 /* When we are under word-wrap, the #$@%!
1573 move_it_by_lines moves 2 lines, so we need to
1575 if (it3
.line_wrap
== WORD_WRAP
)
1576 move_it_by_lines (&it3
, -1);
1579 /* Record the vertical coordinate of the display
1580 line where we wound up. */
1581 top_y
= it3
.current_y
;
1584 /* When characters are reordered for display,
1585 the character displayed to the left of the
1586 display string could be _after_ the display
1587 property in the logical order. Use the
1588 smallest vertical position of these two. */
1589 start_display (&it3
, w
, top
);
1590 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1591 if (it3
.current_y
< top_y
)
1592 top_y
= it3
.current_y
;
1594 /* Move from the top of the window to the beginning
1595 of the display line where the display string
1597 start_display (&it3
, w
, top
);
1598 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1599 /* If it3_moved stays zero after the 'while' loop
1600 below, that means we already were at a newline
1601 before the loop (e.g., the display string begins
1602 with a newline), so we don't need to (and cannot)
1603 inspect the glyphs of it3.glyph_row, because
1604 PRODUCE_GLYPHS will not produce anything for a
1605 newline, and thus it3.glyph_row stays at its
1606 stale content it got at top of the window. */
1608 /* Finally, advance the iterator until we hit the
1609 first display element whose character position is
1610 CHARPOS, or until the first newline from the
1611 display string, which signals the end of the
1613 while (get_next_display_element (&it3
))
1615 PRODUCE_GLYPHS (&it3
);
1616 if (IT_CHARPOS (it3
) == charpos
1617 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1620 set_iterator_to_next (&it3
, 0);
1622 top_x
= it3
.current_x
- it3
.pixel_width
;
1623 /* Normally, we would exit the above loop because we
1624 found the display element whose character
1625 position is CHARPOS. For the contingency that we
1626 didn't, and stopped at the first newline from the
1627 display string, move back over the glyphs
1628 produced from the string, until we find the
1629 rightmost glyph not from the string. */
1631 && newline_in_string
1632 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1634 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1635 + it3
.glyph_row
->used
[TEXT_AREA
];
1637 while (EQ ((g
- 1)->object
, string
))
1640 top_x
-= g
->pixel_width
;
1642 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1643 + it3
.glyph_row
->used
[TEXT_AREA
]);
1649 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1650 *rtop
= max (0, window_top_y
- top_y
);
1651 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1652 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1653 - max (top_y
, window_top_y
)));
1659 /* We were asked to provide info about WINDOW_END. */
1661 void *it2data
= NULL
;
1663 SAVE_IT (it2
, it
, it2data
);
1664 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1665 move_it_by_lines (&it
, 1);
1666 if (charpos
< IT_CHARPOS (it
)
1667 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1670 RESTORE_IT (&it2
, &it2
, it2data
);
1671 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1673 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1674 *rtop
= max (0, -it2
.current_y
);
1675 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1676 - it
.last_visible_y
));
1677 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1679 - max (it2
.current_y
,
1680 WINDOW_HEADER_LINE_HEIGHT (w
))));
1684 bidi_unshelve_cache (it2data
, 1);
1686 bidi_unshelve_cache (itdata
, 0);
1689 set_buffer_internal_1 (old_buffer
);
1691 if (visible_p
&& w
->hscroll
> 0)
1693 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1694 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1697 /* Debugging code. */
1699 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1700 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1702 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1709 /* Return the next character from STR. Return in *LEN the length of
1710 the character. This is like STRING_CHAR_AND_LENGTH but never
1711 returns an invalid character. If we find one, we return a `?', but
1712 with the length of the invalid character. */
1715 string_char_and_length (const unsigned char *str
, int *len
)
1719 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1720 if (!CHAR_VALID_P (c
))
1721 /* We may not change the length here because other places in Emacs
1722 don't use this function, i.e. they silently accept invalid
1731 /* Given a position POS containing a valid character and byte position
1732 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1734 static struct text_pos
1735 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1737 eassert (STRINGP (string
) && nchars
>= 0);
1739 if (STRING_MULTIBYTE (string
))
1741 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1746 string_char_and_length (p
, &len
);
1749 BYTEPOS (pos
) += len
;
1753 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1759 /* Value is the text position, i.e. character and byte position,
1760 for character position CHARPOS in STRING. */
1762 static struct text_pos
1763 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1765 struct text_pos pos
;
1766 eassert (STRINGP (string
));
1767 eassert (charpos
>= 0);
1768 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1773 /* Value is a text position, i.e. character and byte position, for
1774 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1775 means recognize multibyte characters. */
1777 static struct text_pos
1778 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1780 struct text_pos pos
;
1782 eassert (s
!= NULL
);
1783 eassert (charpos
>= 0);
1789 SET_TEXT_POS (pos
, 0, 0);
1792 string_char_and_length ((const unsigned char *) s
, &len
);
1795 BYTEPOS (pos
) += len
;
1799 SET_TEXT_POS (pos
, charpos
, charpos
);
1805 /* Value is the number of characters in C string S. MULTIBYTE_P
1806 non-zero means recognize multibyte characters. */
1809 number_of_chars (const char *s
, bool multibyte_p
)
1815 ptrdiff_t rest
= strlen (s
);
1817 const unsigned char *p
= (const unsigned char *) s
;
1819 for (nchars
= 0; rest
> 0; ++nchars
)
1821 string_char_and_length (p
, &len
);
1822 rest
-= len
, p
+= len
;
1826 nchars
= strlen (s
);
1832 /* Compute byte position NEWPOS->bytepos corresponding to
1833 NEWPOS->charpos. POS is a known position in string STRING.
1834 NEWPOS->charpos must be >= POS.charpos. */
1837 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1839 eassert (STRINGP (string
));
1840 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1842 if (STRING_MULTIBYTE (string
))
1843 *newpos
= string_pos_nchars_ahead (pos
, string
,
1844 CHARPOS (*newpos
) - CHARPOS (pos
));
1846 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1850 Return an estimation of the pixel height of mode or header lines on
1851 frame F. FACE_ID specifies what line's height to estimate. */
1854 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1856 #ifdef HAVE_WINDOW_SYSTEM
1857 if (FRAME_WINDOW_P (f
))
1859 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1861 /* This function is called so early when Emacs starts that the face
1862 cache and mode line face are not yet initialized. */
1863 if (FRAME_FACE_CACHE (f
))
1865 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1869 height
= FONT_HEIGHT (face
->font
);
1870 if (face
->box_line_width
> 0)
1871 height
+= 2 * face
->box_line_width
;
1882 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1883 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1884 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1885 not force the value into range. */
1888 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1889 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1892 #ifdef HAVE_WINDOW_SYSTEM
1893 if (FRAME_WINDOW_P (f
))
1895 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1896 even for negative values. */
1898 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1900 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1902 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1903 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1906 STORE_NATIVE_RECT (*bounds
,
1907 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1908 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1909 FRAME_COLUMN_WIDTH (f
) - 1,
1910 FRAME_LINE_HEIGHT (f
) - 1);
1912 /* PXW: Should we clip pixels before converting to columns/lines? */
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 if (s
->row
->mode_line_p
)
2054 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2056 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2058 /* Unless displaying a mode or menu bar line, which are always
2059 fully visible, clip to the visible part of the row. */
2060 if (s
->w
->pseudo_window_p
)
2061 r
.height
= s
->row
->visible_height
;
2063 r
.height
= s
->height
;
2067 /* This is a text line that may be partially visible. */
2068 r
.x
= window_box_left (s
->w
, s
->area
);
2069 r
.width
= window_box_width (s
->w
, s
->area
);
2070 r
.height
= s
->row
->visible_height
;
2074 if (r
.x
< s
->clip_head
->x
)
2076 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2077 r
.width
-= s
->clip_head
->x
- r
.x
;
2080 r
.x
= s
->clip_head
->x
;
2083 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2085 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2086 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2091 /* If S draws overlapping rows, it's sufficient to use the top and
2092 bottom of the window for clipping because this glyph string
2093 intentionally draws over other lines. */
2094 if (s
->for_overlaps
)
2096 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2097 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2099 /* Alas, the above simple strategy does not work for the
2100 environments with anti-aliased text: if the same text is
2101 drawn onto the same place multiple times, it gets thicker.
2102 If the overlap we are processing is for the erased cursor, we
2103 take the intersection with the rectangle of the cursor. */
2104 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2106 XRectangle rc
, r_save
= r
;
2108 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2109 rc
.y
= s
->w
->phys_cursor
.y
;
2110 rc
.width
= s
->w
->phys_cursor_width
;
2111 rc
.height
= s
->w
->phys_cursor_height
;
2113 x_intersect_rectangles (&r_save
, &rc
, &r
);
2118 /* Don't use S->y for clipping because it doesn't take partially
2119 visible lines into account. For example, it can be negative for
2120 partially visible lines at the top of a window. */
2121 if (!s
->row
->full_width_p
2122 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2123 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2125 r
.y
= max (0, s
->row
->y
);
2128 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2130 /* If drawing the cursor, don't let glyph draw outside its
2131 advertised boundaries. Cleartype does this under some circumstances. */
2132 if (s
->hl
== DRAW_CURSOR
)
2134 struct glyph
*glyph
= s
->first_glyph
;
2139 r
.width
-= s
->x
- r
.x
;
2142 r
.width
= min (r
.width
, glyph
->pixel_width
);
2144 /* If r.y is below window bottom, ensure that we still see a cursor. */
2145 height
= min (glyph
->ascent
+ glyph
->descent
,
2146 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2147 max_y
= window_text_bottom_y (s
->w
) - height
;
2148 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2149 if (s
->ybase
- glyph
->ascent
> max_y
)
2156 /* Don't draw cursor glyph taller than our actual glyph. */
2157 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2158 if (height
< r
.height
)
2160 max_y
= r
.y
+ r
.height
;
2161 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2162 r
.height
= min (max_y
- r
.y
, height
);
2169 XRectangle r_save
= r
;
2171 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2175 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2176 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2178 #ifdef CONVERT_FROM_XRECT
2179 CONVERT_FROM_XRECT (r
, *rects
);
2187 /* If we are processing overlapping and allowed to return
2188 multiple clipping rectangles, we exclude the row of the glyph
2189 string from the clipping rectangle. This is to avoid drawing
2190 the same text on the environment with anti-aliasing. */
2191 #ifdef CONVERT_FROM_XRECT
2194 XRectangle
*rs
= rects
;
2196 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2198 if (s
->for_overlaps
& OVERLAPS_PRED
)
2201 if (r
.y
+ r
.height
> row_y
)
2204 rs
[i
].height
= row_y
- r
.y
;
2210 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2213 if (r
.y
< row_y
+ s
->row
->visible_height
)
2215 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2217 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2218 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2227 #ifdef CONVERT_FROM_XRECT
2228 for (i
= 0; i
< n
; i
++)
2229 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2236 Return in *NR the clipping rectangle for glyph string S. */
2239 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2241 get_glyph_string_clip_rects (s
, nr
, 1);
2246 Return the position and height of the phys cursor in window W.
2247 Set w->phys_cursor_width to width of phys cursor.
2251 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2252 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2254 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2255 int x
, y
, wd
, h
, h0
, y0
;
2257 /* Compute the width of the rectangle to draw. If on a stretch
2258 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2259 rectangle as wide as the glyph, but use a canonical character
2261 wd
= glyph
->pixel_width
- 1;
2262 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2266 x
= w
->phys_cursor
.x
;
2273 if (glyph
->type
== STRETCH_GLYPH
2274 && !x_stretch_cursor_p
)
2275 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2276 w
->phys_cursor_width
= wd
;
2278 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2280 /* If y is below window bottom, ensure that we still see a cursor. */
2281 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2283 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2284 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2286 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2289 h
= max (h
- (y0
- y
) + 1, h0
);
2294 y0
= window_text_bottom_y (w
) - h0
;
2302 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2303 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2308 * Remember which glyph the mouse is over.
2312 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2316 struct glyph_row
*r
, *gr
, *end_row
;
2317 enum window_part part
;
2318 enum glyph_row_area area
;
2319 int x
, y
, width
, height
;
2321 /* Try to determine frame pixel position and size of the glyph under
2322 frame pixel coordinates X/Y on frame F. */
2324 if (window_resize_pixelwise
)
2329 else if (!f
->glyphs_initialized_p
2330 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2333 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2334 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2338 w
= XWINDOW (window
);
2339 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2340 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2342 x
= window_relative_x_coord (w
, part
, gx
);
2343 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2345 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2346 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2348 if (w
->pseudo_window_p
)
2351 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2357 case ON_LEFT_MARGIN
:
2358 area
= LEFT_MARGIN_AREA
;
2361 case ON_RIGHT_MARGIN
:
2362 area
= RIGHT_MARGIN_AREA
;
2365 case ON_HEADER_LINE
:
2367 gr
= (part
== ON_HEADER_LINE
2368 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2369 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2372 goto text_glyph_row_found
;
2379 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2380 if (r
->y
+ r
->height
> y
)
2386 text_glyph_row_found
:
2389 struct glyph
*g
= gr
->glyphs
[area
];
2390 struct glyph
*end
= g
+ gr
->used
[area
];
2392 height
= gr
->height
;
2393 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2394 if (gx
+ g
->pixel_width
> x
)
2399 if (g
->type
== IMAGE_GLYPH
)
2401 /* Don't remember when mouse is over image, as
2402 image may have hot-spots. */
2403 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2406 width
= g
->pixel_width
;
2410 /* Use nominal char spacing at end of line. */
2412 gx
+= (x
/ width
) * width
;
2415 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2416 gx
+= window_box_left_offset (w
, area
);
2420 /* Use nominal line height at end of window. */
2421 gx
= (x
/ width
) * width
;
2423 gy
+= (y
/ height
) * height
;
2427 case ON_LEFT_FRINGE
:
2428 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2429 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2430 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2431 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2434 case ON_RIGHT_FRINGE
:
2435 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2436 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2437 : window_box_right_offset (w
, TEXT_AREA
));
2438 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2442 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2444 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2445 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2446 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2448 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2452 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2453 if (r
->y
+ r
->height
> y
)
2460 height
= gr
->height
;
2463 /* Use nominal line height at end of window. */
2465 gy
+= (y
/ height
) * height
;
2472 /* If there is no glyph under the mouse, then we divide the screen
2473 into a grid of the smallest glyph in the frame, and use that
2476 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2477 round down even for negative values. */
2483 gx
= (gx
/ width
) * width
;
2484 gy
= (gy
/ height
) * height
;
2489 gx
+= WINDOW_LEFT_EDGE_X (w
);
2490 gy
+= WINDOW_TOP_EDGE_Y (w
);
2493 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2495 /* Visible feedback for debugging. */
2498 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2499 f
->output_data
.x
->normal_gc
,
2500 gx
, gy
, width
, height
);
2506 #endif /* HAVE_WINDOW_SYSTEM */
2509 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2512 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2513 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2515 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2518 /***********************************************************************
2519 Lisp form evaluation
2520 ***********************************************************************/
2522 /* Error handler for safe_eval and safe_call. */
2525 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2527 add_to_log ("Error during redisplay: %S signaled %S",
2528 Flist (nargs
, args
), arg
);
2532 /* Call function FUNC with the rest of NARGS - 1 arguments
2533 following. Return the result, or nil if something went
2534 wrong. Prevent redisplay during the evaluation. */
2537 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2541 if (inhibit_eval_during_redisplay
)
2547 ptrdiff_t count
= SPECPDL_INDEX ();
2548 struct gcpro gcpro1
;
2549 Lisp_Object
*args
= alloca (nargs
* word_size
);
2552 va_start (ap
, func
);
2553 for (i
= 1; i
< nargs
; i
++)
2554 args
[i
] = va_arg (ap
, Lisp_Object
);
2558 gcpro1
.nvars
= nargs
;
2559 specbind (Qinhibit_redisplay
, Qt
);
2560 /* Use Qt to ensure debugger does not run,
2561 so there is no possibility of wanting to redisplay. */
2562 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2565 val
= unbind_to (count
, val
);
2572 /* Call function FN with one argument ARG.
2573 Return the result, or nil if something went wrong. */
2576 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2578 return safe_call (2, fn
, arg
);
2581 static Lisp_Object Qeval
;
2584 safe_eval (Lisp_Object sexpr
)
2586 return safe_call1 (Qeval
, sexpr
);
2589 /* Call function FN with two arguments ARG1 and ARG2.
2590 Return the result, or nil if something went wrong. */
2593 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2595 return safe_call (3, fn
, arg1
, arg2
);
2600 /***********************************************************************
2602 ***********************************************************************/
2606 /* Define CHECK_IT to perform sanity checks on iterators.
2607 This is for debugging. It is too slow to do unconditionally. */
2610 check_it (struct it
*it
)
2612 if (it
->method
== GET_FROM_STRING
)
2614 eassert (STRINGP (it
->string
));
2615 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2619 eassert (IT_STRING_CHARPOS (*it
) < 0);
2620 if (it
->method
== GET_FROM_BUFFER
)
2622 /* Check that character and byte positions agree. */
2623 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2628 eassert (it
->current
.dpvec_index
>= 0);
2630 eassert (it
->current
.dpvec_index
< 0);
2633 #define CHECK_IT(IT) check_it ((IT))
2637 #define CHECK_IT(IT) (void) 0
2642 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2644 /* Check that the window end of window W is what we expect it
2645 to be---the last row in the current matrix displaying text. */
2648 check_window_end (struct window
*w
)
2650 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2652 struct glyph_row
*row
;
2653 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2655 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2656 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2660 #define CHECK_WINDOW_END(W) check_window_end ((W))
2664 #define CHECK_WINDOW_END(W) (void) 0
2666 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2668 /***********************************************************************
2669 Iterator initialization
2670 ***********************************************************************/
2672 /* Initialize IT for displaying current_buffer in window W, starting
2673 at character position CHARPOS. CHARPOS < 0 means that no buffer
2674 position is specified which is useful when the iterator is assigned
2675 a position later. BYTEPOS is the byte position corresponding to
2678 If ROW is not null, calls to produce_glyphs with IT as parameter
2679 will produce glyphs in that row.
2681 BASE_FACE_ID is the id of a base face to use. It must be one of
2682 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2683 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2684 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2686 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2687 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2688 will be initialized to use the corresponding mode line glyph row of
2689 the desired matrix of W. */
2692 init_iterator (struct it
*it
, struct window
*w
,
2693 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2694 struct glyph_row
*row
, enum face_id base_face_id
)
2696 enum face_id remapped_base_face_id
= base_face_id
;
2698 /* Some precondition checks. */
2699 eassert (w
!= NULL
&& it
!= NULL
);
2700 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2703 /* If face attributes have been changed since the last redisplay,
2704 free realized faces now because they depend on face definitions
2705 that might have changed. Don't free faces while there might be
2706 desired matrices pending which reference these faces. */
2707 if (face_change_count
&& !inhibit_free_realized_faces
)
2709 face_change_count
= 0;
2710 free_all_realized_faces (Qnil
);
2713 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2714 if (! NILP (Vface_remapping_alist
))
2715 remapped_base_face_id
2716 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2718 /* Use one of the mode line rows of W's desired matrix if
2722 if (base_face_id
== MODE_LINE_FACE_ID
2723 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2724 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2725 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2726 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2730 memset (it
, 0, sizeof *it
);
2731 it
->current
.overlay_string_index
= -1;
2732 it
->current
.dpvec_index
= -1;
2733 it
->base_face_id
= remapped_base_face_id
;
2735 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2736 it
->paragraph_embedding
= L2R
;
2737 it
->bidi_it
.string
.lstring
= Qnil
;
2738 it
->bidi_it
.string
.s
= NULL
;
2739 it
->bidi_it
.string
.bufpos
= 0;
2742 /* The window in which we iterate over current_buffer: */
2743 XSETWINDOW (it
->window
, w
);
2745 it
->f
= XFRAME (w
->frame
);
2749 /* Extra space between lines (on window systems only). */
2750 if (base_face_id
== DEFAULT_FACE_ID
2751 && FRAME_WINDOW_P (it
->f
))
2753 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2754 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2755 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2756 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2757 * FRAME_LINE_HEIGHT (it
->f
));
2758 else if (it
->f
->extra_line_spacing
> 0)
2759 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2760 it
->max_extra_line_spacing
= 0;
2763 /* If realized faces have been removed, e.g. because of face
2764 attribute changes of named faces, recompute them. When running
2765 in batch mode, the face cache of the initial frame is null. If
2766 we happen to get called, make a dummy face cache. */
2767 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2768 init_frame_faces (it
->f
);
2769 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2770 recompute_basic_faces (it
->f
);
2772 /* Current value of the `slice', `space-width', and 'height' properties. */
2773 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2774 it
->space_width
= Qnil
;
2775 it
->font_height
= Qnil
;
2776 it
->override_ascent
= -1;
2778 /* Are control characters displayed as `^C'? */
2779 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2781 /* -1 means everything between a CR and the following line end
2782 is invisible. >0 means lines indented more than this value are
2784 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2786 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2788 : (!NILP (BVAR (current_buffer
, selective_display
))
2790 it
->selective_display_ellipsis_p
2791 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2793 /* Display table to use. */
2794 it
->dp
= window_display_table (w
);
2796 /* Are multibyte characters enabled in current_buffer? */
2797 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2799 /* Get the position at which the redisplay_end_trigger hook should
2800 be run, if it is to be run at all. */
2801 if (MARKERP (w
->redisplay_end_trigger
)
2802 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2803 it
->redisplay_end_trigger_charpos
2804 = marker_position (w
->redisplay_end_trigger
);
2805 else if (INTEGERP (w
->redisplay_end_trigger
))
2806 it
->redisplay_end_trigger_charpos
=
2807 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2809 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2811 /* Are lines in the display truncated? */
2812 if (base_face_id
!= DEFAULT_FACE_ID
2814 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2815 && ((!NILP (Vtruncate_partial_width_windows
)
2816 && !INTEGERP (Vtruncate_partial_width_windows
))
2817 || (INTEGERP (Vtruncate_partial_width_windows
)
2818 /* PXW: Shall we do something about this? */
2819 && (WINDOW_TOTAL_COLS (it
->w
)
2820 < XINT (Vtruncate_partial_width_windows
))))))
2821 it
->line_wrap
= TRUNCATE
;
2822 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2823 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2824 ? WINDOW_WRAP
: WORD_WRAP
;
2826 it
->line_wrap
= TRUNCATE
;
2828 /* Get dimensions of truncation and continuation glyphs. These are
2829 displayed as fringe bitmaps under X, but we need them for such
2830 frames when the fringes are turned off. But leave the dimensions
2831 zero for tooltip frames, as these glyphs look ugly there and also
2832 sabotage calculations of tooltip dimensions in x-show-tip. */
2833 #ifdef HAVE_WINDOW_SYSTEM
2834 if (!(FRAME_WINDOW_P (it
->f
)
2835 && FRAMEP (tip_frame
)
2836 && it
->f
== XFRAME (tip_frame
)))
2839 if (it
->line_wrap
== TRUNCATE
)
2841 /* We will need the truncation glyph. */
2842 eassert (it
->glyph_row
== NULL
);
2843 produce_special_glyphs (it
, IT_TRUNCATION
);
2844 it
->truncation_pixel_width
= it
->pixel_width
;
2848 /* We will need the continuation glyph. */
2849 eassert (it
->glyph_row
== NULL
);
2850 produce_special_glyphs (it
, IT_CONTINUATION
);
2851 it
->continuation_pixel_width
= it
->pixel_width
;
2855 /* Reset these values to zero because the produce_special_glyphs
2856 above has changed them. */
2857 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2858 it
->phys_ascent
= it
->phys_descent
= 0;
2860 /* Set this after getting the dimensions of truncation and
2861 continuation glyphs, so that we don't produce glyphs when calling
2862 produce_special_glyphs, above. */
2863 it
->glyph_row
= row
;
2864 it
->area
= TEXT_AREA
;
2866 /* Forget any previous info about this row being reversed. */
2868 it
->glyph_row
->reversed_p
= 0;
2870 /* Get the dimensions of the display area. The display area
2871 consists of the visible window area plus a horizontally scrolled
2872 part to the left of the window. All x-values are relative to the
2873 start of this total display area. */
2874 if (base_face_id
!= DEFAULT_FACE_ID
)
2876 /* Mode lines, menu bar in terminal frames. */
2877 it
->first_visible_x
= 0;
2878 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2883 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2884 it
->last_visible_x
= (it
->first_visible_x
2885 + window_box_width (w
, TEXT_AREA
));
2887 /* If we truncate lines, leave room for the truncation glyph(s) at
2888 the right margin. Otherwise, leave room for the continuation
2889 glyph(s). Done only if the window has no fringes. Since we
2890 don't know at this point whether there will be any R2L lines in
2891 the window, we reserve space for truncation/continuation glyphs
2892 even if only one of the fringes is absent. */
2893 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2894 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2896 if (it
->line_wrap
== TRUNCATE
)
2897 it
->last_visible_x
-= it
->truncation_pixel_width
;
2899 it
->last_visible_x
-= it
->continuation_pixel_width
;
2902 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2903 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2906 /* Leave room for a border glyph. */
2907 if (!FRAME_WINDOW_P (it
->f
)
2908 && !WINDOW_RIGHTMOST_P (it
->w
))
2909 it
->last_visible_x
-= 1;
2911 it
->last_visible_y
= window_text_bottom_y (w
);
2913 /* For mode lines and alike, arrange for the first glyph having a
2914 left box line if the face specifies a box. */
2915 if (base_face_id
!= DEFAULT_FACE_ID
)
2919 it
->face_id
= remapped_base_face_id
;
2921 /* If we have a boxed mode line, make the first character appear
2922 with a left box line. */
2923 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2924 if (face
->box
!= FACE_NO_BOX
)
2925 it
->start_of_box_run_p
= true;
2928 /* If a buffer position was specified, set the iterator there,
2929 getting overlays and face properties from that position. */
2930 if (charpos
>= BUF_BEG (current_buffer
))
2932 it
->end_charpos
= ZV
;
2933 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2934 IT_CHARPOS (*it
) = charpos
;
2935 IT_BYTEPOS (*it
) = bytepos
;
2937 /* We will rely on `reseat' to set this up properly, via
2938 handle_face_prop. */
2939 it
->face_id
= it
->base_face_id
;
2941 it
->start
= it
->current
;
2942 /* Do we need to reorder bidirectional text? Not if this is a
2943 unibyte buffer: by definition, none of the single-byte
2944 characters are strong R2L, so no reordering is needed. And
2945 bidi.c doesn't support unibyte buffers anyway. Also, don't
2946 reorder while we are loading loadup.el, since the tables of
2947 character properties needed for reordering are not yet
2951 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2954 /* If we are to reorder bidirectional text, init the bidi
2958 /* Note the paragraph direction that this buffer wants to
2960 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2962 it
->paragraph_embedding
= L2R
;
2963 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2965 it
->paragraph_embedding
= R2L
;
2967 it
->paragraph_embedding
= NEUTRAL_DIR
;
2968 bidi_unshelve_cache (NULL
, 0);
2969 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2973 /* Compute faces etc. */
2974 reseat (it
, it
->current
.pos
, 1);
2981 /* Initialize IT for the display of window W with window start POS. */
2984 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2986 struct glyph_row
*row
;
2987 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2989 row
= w
->desired_matrix
->rows
+ first_vpos
;
2990 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2991 it
->first_vpos
= first_vpos
;
2993 /* Don't reseat to previous visible line start if current start
2994 position is in a string or image. */
2995 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2997 int start_at_line_beg_p
;
2998 int first_y
= it
->current_y
;
3000 /* If window start is not at a line start, skip forward to POS to
3001 get the correct continuation lines width. */
3002 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3003 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3004 if (!start_at_line_beg_p
)
3008 reseat_at_previous_visible_line_start (it
);
3009 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3011 new_x
= it
->current_x
+ it
->pixel_width
;
3013 /* If lines are continued, this line may end in the middle
3014 of a multi-glyph character (e.g. a control character
3015 displayed as \003, or in the middle of an overlay
3016 string). In this case move_it_to above will not have
3017 taken us to the start of the continuation line but to the
3018 end of the continued line. */
3019 if (it
->current_x
> 0
3020 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3021 && (/* And glyph doesn't fit on the line. */
3022 new_x
> it
->last_visible_x
3023 /* Or it fits exactly and we're on a window
3025 || (new_x
== it
->last_visible_x
3026 && FRAME_WINDOW_P (it
->f
)
3027 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3028 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3029 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3031 if ((it
->current
.dpvec_index
>= 0
3032 || it
->current
.overlay_string_index
>= 0)
3033 /* If we are on a newline from a display vector or
3034 overlay string, then we are already at the end of
3035 a screen line; no need to go to the next line in
3036 that case, as this line is not really continued.
3037 (If we do go to the next line, C-e will not DTRT.) */
3040 set_iterator_to_next (it
, 1);
3041 move_it_in_display_line_to (it
, -1, -1, 0);
3044 it
->continuation_lines_width
+= it
->current_x
;
3046 /* If the character at POS is displayed via a display
3047 vector, move_it_to above stops at the final glyph of
3048 IT->dpvec. To make the caller redisplay that character
3049 again (a.k.a. start at POS), we need to reset the
3050 dpvec_index to the beginning of IT->dpvec. */
3051 else if (it
->current
.dpvec_index
>= 0)
3052 it
->current
.dpvec_index
= 0;
3054 /* We're starting a new display line, not affected by the
3055 height of the continued line, so clear the appropriate
3056 fields in the iterator structure. */
3057 it
->max_ascent
= it
->max_descent
= 0;
3058 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3060 it
->current_y
= first_y
;
3062 it
->current_x
= it
->hpos
= 0;
3068 /* Return 1 if POS is a position in ellipses displayed for invisible
3069 text. W is the window we display, for text property lookup. */
3072 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3074 Lisp_Object prop
, window
;
3076 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3078 /* If POS specifies a position in a display vector, this might
3079 be for an ellipsis displayed for invisible text. We won't
3080 get the iterator set up for delivering that ellipsis unless
3081 we make sure that it gets aware of the invisible text. */
3082 if (pos
->dpvec_index
>= 0
3083 && pos
->overlay_string_index
< 0
3084 && CHARPOS (pos
->string_pos
) < 0
3086 && (XSETWINDOW (window
, w
),
3087 prop
= Fget_char_property (make_number (charpos
),
3088 Qinvisible
, window
),
3089 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3091 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3093 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3100 /* Initialize IT for stepping through current_buffer in window W,
3101 starting at position POS that includes overlay string and display
3102 vector/ control character translation position information. Value
3103 is zero if there are overlay strings with newlines at POS. */
3106 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3108 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3109 int i
, overlay_strings_with_newlines
= 0;
3111 /* If POS specifies a position in a display vector, this might
3112 be for an ellipsis displayed for invisible text. We won't
3113 get the iterator set up for delivering that ellipsis unless
3114 we make sure that it gets aware of the invisible text. */
3115 if (in_ellipses_for_invisible_text_p (pos
, w
))
3121 /* Keep in mind: the call to reseat in init_iterator skips invisible
3122 text, so we might end up at a position different from POS. This
3123 is only a problem when POS is a row start after a newline and an
3124 overlay starts there with an after-string, and the overlay has an
3125 invisible property. Since we don't skip invisible text in
3126 display_line and elsewhere immediately after consuming the
3127 newline before the row start, such a POS will not be in a string,
3128 but the call to init_iterator below will move us to the
3130 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3132 /* This only scans the current chunk -- it should scan all chunks.
3133 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3134 to 16 in 22.1 to make this a lesser problem. */
3135 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3137 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3138 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3140 while (s
< e
&& *s
!= '\n')
3145 overlay_strings_with_newlines
= 1;
3150 /* If position is within an overlay string, set up IT to the right
3152 if (pos
->overlay_string_index
>= 0)
3156 /* If the first overlay string happens to have a `display'
3157 property for an image, the iterator will be set up for that
3158 image, and we have to undo that setup first before we can
3159 correct the overlay string index. */
3160 if (it
->method
== GET_FROM_IMAGE
)
3163 /* We already have the first chunk of overlay strings in
3164 IT->overlay_strings. Load more until the one for
3165 pos->overlay_string_index is in IT->overlay_strings. */
3166 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3168 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3169 it
->current
.overlay_string_index
= 0;
3172 load_overlay_strings (it
, 0);
3173 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3177 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3178 relative_index
= (it
->current
.overlay_string_index
3179 % OVERLAY_STRING_CHUNK_SIZE
);
3180 it
->string
= it
->overlay_strings
[relative_index
];
3181 eassert (STRINGP (it
->string
));
3182 it
->current
.string_pos
= pos
->string_pos
;
3183 it
->method
= GET_FROM_STRING
;
3184 it
->end_charpos
= SCHARS (it
->string
);
3185 /* Set up the bidi iterator for this overlay string. */
3188 it
->bidi_it
.string
.lstring
= it
->string
;
3189 it
->bidi_it
.string
.s
= NULL
;
3190 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3191 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3192 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3193 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3194 it
->bidi_it
.w
= it
->w
;
3195 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3196 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3198 /* Synchronize the state of the bidi iterator with
3199 pos->string_pos. For any string position other than
3200 zero, this will be done automagically when we resume
3201 iteration over the string and get_visually_first_element
3202 is called. But if string_pos is zero, and the string is
3203 to be reordered for display, we need to resync manually,
3204 since it could be that the iteration state recorded in
3205 pos ended at string_pos of 0 moving backwards in string. */
3206 if (CHARPOS (pos
->string_pos
) == 0)
3208 get_visually_first_element (it
);
3209 if (IT_STRING_CHARPOS (*it
) != 0)
3212 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3213 bidi_move_to_visually_next (&it
->bidi_it
);
3214 } while (it
->bidi_it
.charpos
!= 0);
3216 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3217 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3221 if (CHARPOS (pos
->string_pos
) >= 0)
3223 /* Recorded position is not in an overlay string, but in another
3224 string. This can only be a string from a `display' property.
3225 IT should already be filled with that string. */
3226 it
->current
.string_pos
= pos
->string_pos
;
3227 eassert (STRINGP (it
->string
));
3229 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3230 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3233 /* Restore position in display vector translations, control
3234 character translations or ellipses. */
3235 if (pos
->dpvec_index
>= 0)
3237 if (it
->dpvec
== NULL
)
3238 get_next_display_element (it
);
3239 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3240 it
->current
.dpvec_index
= pos
->dpvec_index
;
3244 return !overlay_strings_with_newlines
;
3248 /* Initialize IT for stepping through current_buffer in window W
3249 starting at ROW->start. */
3252 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3254 init_from_display_pos (it
, w
, &row
->start
);
3255 it
->start
= row
->start
;
3256 it
->continuation_lines_width
= row
->continuation_lines_width
;
3261 /* Initialize IT for stepping through current_buffer in window W
3262 starting in the line following ROW, i.e. starting at ROW->end.
3263 Value is zero if there are overlay strings with newlines at ROW's
3267 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3271 if (init_from_display_pos (it
, w
, &row
->end
))
3273 if (row
->continued_p
)
3274 it
->continuation_lines_width
3275 = row
->continuation_lines_width
+ row
->pixel_width
;
3286 /***********************************************************************
3288 ***********************************************************************/
3290 /* Called when IT reaches IT->stop_charpos. Handle text property and
3291 overlay changes. Set IT->stop_charpos to the next position where
3295 handle_stop (struct it
*it
)
3297 enum prop_handled handled
;
3298 int handle_overlay_change_p
;
3302 it
->current
.dpvec_index
= -1;
3303 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3304 it
->ignore_overlay_strings_at_pos_p
= 0;
3307 /* Use face of preceding text for ellipsis (if invisible) */
3308 if (it
->selective_display_ellipsis_p
)
3309 it
->saved_face_id
= it
->face_id
;
3313 handled
= HANDLED_NORMALLY
;
3315 /* Call text property handlers. */
3316 for (p
= it_props
; p
->handler
; ++p
)
3318 handled
= p
->handler (it
);
3320 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3322 else if (handled
== HANDLED_RETURN
)
3324 /* We still want to show before and after strings from
3325 overlays even if the actual buffer text is replaced. */
3326 if (!handle_overlay_change_p
3328 /* Don't call get_overlay_strings_1 if we already
3329 have overlay strings loaded, because doing so
3330 will load them again and push the iterator state
3331 onto the stack one more time, which is not
3332 expected by the rest of the code that processes
3334 || (it
->current
.overlay_string_index
< 0
3335 ? !get_overlay_strings_1 (it
, 0, 0)
3339 setup_for_ellipsis (it
, 0);
3340 /* When handling a display spec, we might load an
3341 empty string. In that case, discard it here. We
3342 used to discard it in handle_single_display_spec,
3343 but that causes get_overlay_strings_1, above, to
3344 ignore overlay strings that we must check. */
3345 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3349 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3353 it
->ignore_overlay_strings_at_pos_p
= true;
3354 it
->string_from_display_prop_p
= 0;
3355 it
->from_disp_prop_p
= 0;
3356 handle_overlay_change_p
= 0;
3358 handled
= HANDLED_RECOMPUTE_PROPS
;
3361 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3362 handle_overlay_change_p
= 0;
3365 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3367 /* Don't check for overlay strings below when set to deliver
3368 characters from a display vector. */
3369 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3370 handle_overlay_change_p
= 0;
3372 /* Handle overlay changes.
3373 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3374 if it finds overlays. */
3375 if (handle_overlay_change_p
)
3376 handled
= handle_overlay_change (it
);
3381 setup_for_ellipsis (it
, 0);
3385 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3387 /* Determine where to stop next. */
3388 if (handled
== HANDLED_NORMALLY
)
3389 compute_stop_pos (it
);
3393 /* Compute IT->stop_charpos from text property and overlay change
3394 information for IT's current position. */
3397 compute_stop_pos (struct it
*it
)
3399 register INTERVAL iv
, next_iv
;
3400 Lisp_Object object
, limit
, position
;
3401 ptrdiff_t charpos
, bytepos
;
3403 if (STRINGP (it
->string
))
3405 /* Strings are usually short, so don't limit the search for
3407 it
->stop_charpos
= it
->end_charpos
;
3408 object
= it
->string
;
3410 charpos
= IT_STRING_CHARPOS (*it
);
3411 bytepos
= IT_STRING_BYTEPOS (*it
);
3417 /* If end_charpos is out of range for some reason, such as a
3418 misbehaving display function, rationalize it (Bug#5984). */
3419 if (it
->end_charpos
> ZV
)
3420 it
->end_charpos
= ZV
;
3421 it
->stop_charpos
= it
->end_charpos
;
3423 /* If next overlay change is in front of the current stop pos
3424 (which is IT->end_charpos), stop there. Note: value of
3425 next_overlay_change is point-max if no overlay change
3427 charpos
= IT_CHARPOS (*it
);
3428 bytepos
= IT_BYTEPOS (*it
);
3429 pos
= next_overlay_change (charpos
);
3430 if (pos
< it
->stop_charpos
)
3431 it
->stop_charpos
= pos
;
3433 /* Set up variables for computing the stop position from text
3434 property changes. */
3435 XSETBUFFER (object
, current_buffer
);
3436 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3439 /* Get the interval containing IT's position. Value is a null
3440 interval if there isn't such an interval. */
3441 position
= make_number (charpos
);
3442 iv
= validate_interval_range (object
, &position
, &position
, 0);
3445 Lisp_Object values_here
[LAST_PROP_IDX
];
3448 /* Get properties here. */
3449 for (p
= it_props
; p
->handler
; ++p
)
3450 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3452 /* Look for an interval following iv that has different
3454 for (next_iv
= next_interval (iv
);
3457 || XFASTINT (limit
) > next_iv
->position
));
3458 next_iv
= next_interval (next_iv
))
3460 for (p
= it_props
; p
->handler
; ++p
)
3462 Lisp_Object new_value
;
3464 new_value
= textget (next_iv
->plist
, *p
->name
);
3465 if (!EQ (values_here
[p
->idx
], new_value
))
3475 if (INTEGERP (limit
)
3476 && next_iv
->position
>= XFASTINT (limit
))
3477 /* No text property change up to limit. */
3478 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3480 /* Text properties change in next_iv. */
3481 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3485 if (it
->cmp_it
.id
< 0)
3487 ptrdiff_t stoppos
= it
->end_charpos
;
3489 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3491 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3492 stoppos
, it
->string
);
3495 eassert (STRINGP (it
->string
)
3496 || (it
->stop_charpos
>= BEGV
3497 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3501 /* Return the position of the next overlay change after POS in
3502 current_buffer. Value is point-max if no overlay change
3503 follows. This is like `next-overlay-change' but doesn't use
3507 next_overlay_change (ptrdiff_t pos
)
3509 ptrdiff_t i
, noverlays
;
3511 Lisp_Object
*overlays
;
3513 /* Get all overlays at the given position. */
3514 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3516 /* If any of these overlays ends before endpos,
3517 use its ending point instead. */
3518 for (i
= 0; i
< noverlays
; ++i
)
3523 oend
= OVERLAY_END (overlays
[i
]);
3524 oendpos
= OVERLAY_POSITION (oend
);
3525 endpos
= min (endpos
, oendpos
);
3531 /* How many characters forward to search for a display property or
3532 display string. Searching too far forward makes the bidi display
3533 sluggish, especially in small windows. */
3534 #define MAX_DISP_SCAN 250
3536 /* Return the character position of a display string at or after
3537 position specified by POSITION. If no display string exists at or
3538 after POSITION, return ZV. A display string is either an overlay
3539 with `display' property whose value is a string, or a `display'
3540 text property whose value is a string. STRING is data about the
3541 string to iterate; if STRING->lstring is nil, we are iterating a
3542 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3543 on a GUI frame. DISP_PROP is set to zero if we searched
3544 MAX_DISP_SCAN characters forward without finding any display
3545 strings, non-zero otherwise. It is set to 2 if the display string
3546 uses any kind of `(space ...)' spec that will produce a stretch of
3547 white space in the text area. */
3549 compute_display_string_pos (struct text_pos
*position
,
3550 struct bidi_string_data
*string
,
3552 int frame_window_p
, int *disp_prop
)
3554 /* OBJECT = nil means current buffer. */
3555 Lisp_Object object
, object1
;
3556 Lisp_Object pos
, spec
, limpos
;
3557 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3558 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3559 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3560 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3562 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3563 struct text_pos tpos
;
3566 if (string
&& STRINGP (string
->lstring
))
3567 object1
= object
= string
->lstring
;
3568 else if (w
&& !string_p
)
3570 XSETWINDOW (object
, w
);
3574 object1
= object
= Qnil
;
3579 /* We don't support display properties whose values are strings
3580 that have display string properties. */
3581 || string
->from_disp_str
3582 /* C strings cannot have display properties. */
3583 || (string
->s
&& !STRINGP (object
)))
3589 /* If the character at CHARPOS is where the display string begins,
3591 pos
= make_number (charpos
);
3592 if (STRINGP (object
))
3593 bufpos
= string
->bufpos
;
3597 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3599 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3602 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3610 /* Look forward for the first character with a `display' property
3611 that will replace the underlying text when displayed. */
3612 limpos
= make_number (lim
);
3614 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3615 CHARPOS (tpos
) = XFASTINT (pos
);
3616 if (CHARPOS (tpos
) >= lim
)
3621 if (STRINGP (object
))
3622 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3624 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3625 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3626 if (!STRINGP (object
))
3627 bufpos
= CHARPOS (tpos
);
3628 } while (NILP (spec
)
3629 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3630 bufpos
, frame_window_p
)));
3634 return CHARPOS (tpos
);
3637 /* Return the character position of the end of the display string that
3638 started at CHARPOS. If there's no display string at CHARPOS,
3639 return -1. A display string is either an overlay with `display'
3640 property whose value is a string or a `display' text property whose
3641 value is a string. */
3643 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3645 /* OBJECT = nil means current buffer. */
3646 Lisp_Object object
=
3647 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3648 Lisp_Object pos
= make_number (charpos
);
3650 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3652 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3655 /* It could happen that the display property or overlay was removed
3656 since we found it in compute_display_string_pos above. One way
3657 this can happen is if JIT font-lock was called (through
3658 handle_fontified_prop), and jit-lock-functions remove text
3659 properties or overlays from the portion of buffer that includes
3660 CHARPOS. Muse mode is known to do that, for example. In this
3661 case, we return -1 to the caller, to signal that no display
3662 string is actually present at CHARPOS. See bidi_fetch_char for
3663 how this is handled.
3665 An alternative would be to never look for display properties past
3666 it->stop_charpos. But neither compute_display_string_pos nor
3667 bidi_fetch_char that calls it know or care where the next
3669 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3672 /* Look forward for the first character where the `display' property
3674 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3676 return XFASTINT (pos
);
3681 /***********************************************************************
3683 ***********************************************************************/
3685 /* Handle changes in the `fontified' property of the current buffer by
3686 calling hook functions from Qfontification_functions to fontify
3689 static enum prop_handled
3690 handle_fontified_prop (struct it
*it
)
3692 Lisp_Object prop
, pos
;
3693 enum prop_handled handled
= HANDLED_NORMALLY
;
3695 if (!NILP (Vmemory_full
))
3698 /* Get the value of the `fontified' property at IT's current buffer
3699 position. (The `fontified' property doesn't have a special
3700 meaning in strings.) If the value is nil, call functions from
3701 Qfontification_functions. */
3702 if (!STRINGP (it
->string
)
3704 && !NILP (Vfontification_functions
)
3705 && !NILP (Vrun_hooks
)
3706 && (pos
= make_number (IT_CHARPOS (*it
)),
3707 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3708 /* Ignore the special cased nil value always present at EOB since
3709 no amount of fontifying will be able to change it. */
3710 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3712 ptrdiff_t count
= SPECPDL_INDEX ();
3714 struct buffer
*obuf
= current_buffer
;
3715 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3716 bool old_clip_changed
= current_buffer
->clip_changed
;
3718 val
= Vfontification_functions
;
3719 specbind (Qfontification_functions
, Qnil
);
3721 eassert (it
->end_charpos
== ZV
);
3723 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3724 safe_call1 (val
, pos
);
3727 Lisp_Object fns
, fn
;
3728 struct gcpro gcpro1
, gcpro2
;
3733 for (; CONSP (val
); val
= XCDR (val
))
3739 /* A value of t indicates this hook has a local
3740 binding; it means to run the global binding too.
3741 In a global value, t should not occur. If it
3742 does, we must ignore it to avoid an endless
3744 for (fns
= Fdefault_value (Qfontification_functions
);
3750 safe_call1 (fn
, pos
);
3754 safe_call1 (fn
, pos
);
3760 unbind_to (count
, Qnil
);
3762 /* Fontification functions routinely call `save-restriction'.
3763 Normally, this tags clip_changed, which can confuse redisplay
3764 (see discussion in Bug#6671). Since we don't perform any
3765 special handling of fontification changes in the case where
3766 `save-restriction' isn't called, there's no point doing so in
3767 this case either. So, if the buffer's restrictions are
3768 actually left unchanged, reset clip_changed. */
3769 if (obuf
== current_buffer
)
3771 if (begv
== BEGV
&& zv
== ZV
)
3772 current_buffer
->clip_changed
= old_clip_changed
;
3774 /* There isn't much we can reasonably do to protect against
3775 misbehaving fontification, but here's a fig leaf. */
3776 else if (BUFFER_LIVE_P (obuf
))
3777 set_buffer_internal_1 (obuf
);
3779 /* The fontification code may have added/removed text.
3780 It could do even a lot worse, but let's at least protect against
3781 the most obvious case where only the text past `pos' gets changed',
3782 as is/was done in grep.el where some escapes sequences are turned
3783 into face properties (bug#7876). */
3784 it
->end_charpos
= ZV
;
3786 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3787 something. This avoids an endless loop if they failed to
3788 fontify the text for which reason ever. */
3789 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3790 handled
= HANDLED_RECOMPUTE_PROPS
;
3798 /***********************************************************************
3800 ***********************************************************************/
3802 /* Set up iterator IT from face properties at its current position.
3803 Called from handle_stop. */
3805 static enum prop_handled
3806 handle_face_prop (struct it
*it
)
3809 ptrdiff_t next_stop
;
3811 if (!STRINGP (it
->string
))
3814 = face_at_buffer_position (it
->w
,
3818 + TEXT_PROP_DISTANCE_LIMIT
),
3819 0, it
->base_face_id
);
3821 /* Is this a start of a run of characters with box face?
3822 Caveat: this can be called for a freshly initialized
3823 iterator; face_id is -1 in this case. We know that the new
3824 face will not change until limit, i.e. if the new face has a
3825 box, all characters up to limit will have one. But, as
3826 usual, we don't know whether limit is really the end. */
3827 if (new_face_id
!= it
->face_id
)
3829 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3830 /* If it->face_id is -1, old_face below will be NULL, see
3831 the definition of FACE_FROM_ID. This will happen if this
3832 is the initial call that gets the face. */
3833 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3835 /* If the value of face_id of the iterator is -1, we have to
3836 look in front of IT's position and see whether there is a
3837 face there that's different from new_face_id. */
3838 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3840 int prev_face_id
= face_before_it_pos (it
);
3842 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3845 /* If the new face has a box, but the old face does not,
3846 this is the start of a run of characters with box face,
3847 i.e. this character has a shadow on the left side. */
3848 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3849 && (old_face
== NULL
|| !old_face
->box
));
3850 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3858 Lisp_Object from_overlay
3859 = (it
->current
.overlay_string_index
>= 0
3860 ? it
->string_overlays
[it
->current
.overlay_string_index
3861 % OVERLAY_STRING_CHUNK_SIZE
]
3864 /* See if we got to this string directly or indirectly from
3865 an overlay property. That includes the before-string or
3866 after-string of an overlay, strings in display properties
3867 provided by an overlay, their text properties, etc.
3869 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3870 if (! NILP (from_overlay
))
3871 for (i
= it
->sp
- 1; i
>= 0; i
--)
3873 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3875 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3876 % OVERLAY_STRING_CHUNK_SIZE
];
3877 else if (! NILP (it
->stack
[i
].from_overlay
))
3878 from_overlay
= it
->stack
[i
].from_overlay
;
3880 if (!NILP (from_overlay
))
3884 if (! NILP (from_overlay
))
3886 bufpos
= IT_CHARPOS (*it
);
3887 /* For a string from an overlay, the base face depends
3888 only on text properties and ignores overlays. */
3890 = face_for_overlay_string (it
->w
,
3894 + TEXT_PROP_DISTANCE_LIMIT
),
3902 /* For strings from a `display' property, use the face at
3903 IT's current buffer position as the base face to merge
3904 with, so that overlay strings appear in the same face as
3905 surrounding text, unless they specify their own faces.
3906 For strings from wrap-prefix and line-prefix properties,
3907 use the default face, possibly remapped via
3908 Vface_remapping_alist. */
3909 base_face_id
= it
->string_from_prefix_prop_p
3910 ? (!NILP (Vface_remapping_alist
)
3911 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3913 : underlying_face_id (it
);
3916 new_face_id
= face_at_string_position (it
->w
,
3918 IT_STRING_CHARPOS (*it
),
3923 /* Is this a start of a run of characters with box? Caveat:
3924 this can be called for a freshly allocated iterator; face_id
3925 is -1 is this case. We know that the new face will not
3926 change until the next check pos, i.e. if the new face has a
3927 box, all characters up to that position will have a
3928 box. But, as usual, we don't know whether that position
3929 is really the end. */
3930 if (new_face_id
!= it
->face_id
)
3932 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3933 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3935 /* If new face has a box but old face hasn't, this is the
3936 start of a run of characters with box, i.e. it has a
3937 shadow on the left side. */
3938 it
->start_of_box_run_p
3939 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3940 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3944 it
->face_id
= new_face_id
;
3945 return HANDLED_NORMALLY
;
3949 /* Return the ID of the face ``underlying'' IT's current position,
3950 which is in a string. If the iterator is associated with a
3951 buffer, return the face at IT's current buffer position.
3952 Otherwise, use the iterator's base_face_id. */
3955 underlying_face_id (struct it
*it
)
3957 int face_id
= it
->base_face_id
, i
;
3959 eassert (STRINGP (it
->string
));
3961 for (i
= it
->sp
- 1; i
>= 0; --i
)
3962 if (NILP (it
->stack
[i
].string
))
3963 face_id
= it
->stack
[i
].face_id
;
3969 /* Compute the face one character before or after the current position
3970 of IT, in the visual order. BEFORE_P non-zero means get the face
3971 in front (to the left in L2R paragraphs, to the right in R2L
3972 paragraphs) of IT's screen position. Value is the ID of the face. */
3975 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3978 ptrdiff_t next_check_charpos
;
3980 void *it_copy_data
= NULL
;
3982 eassert (it
->s
== NULL
);
3984 if (STRINGP (it
->string
))
3986 ptrdiff_t bufpos
, charpos
;
3989 /* No face change past the end of the string (for the case
3990 we are padding with spaces). No face change before the
3992 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3993 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3998 /* Set charpos to the position before or after IT's current
3999 position, in the logical order, which in the non-bidi
4000 case is the same as the visual order. */
4002 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4003 else if (it
->what
== IT_COMPOSITION
)
4004 /* For composition, we must check the character after the
4006 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4008 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4014 /* With bidi iteration, the character before the current
4015 in the visual order cannot be found by simple
4016 iteration, because "reverse" reordering is not
4017 supported. Instead, we need to use the move_it_*
4018 family of functions. */
4019 /* Ignore face changes before the first visible
4020 character on this display line. */
4021 if (it
->current_x
<= it
->first_visible_x
)
4023 SAVE_IT (it_copy
, *it
, it_copy_data
);
4024 /* Implementation note: Since move_it_in_display_line
4025 works in the iterator geometry, and thinks the first
4026 character is always the leftmost, even in R2L lines,
4027 we don't need to distinguish between the R2L and L2R
4029 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4030 it_copy
.current_x
- 1, MOVE_TO_X
);
4031 charpos
= IT_STRING_CHARPOS (it_copy
);
4032 RESTORE_IT (it
, it
, it_copy_data
);
4036 /* Set charpos to the string position of the character
4037 that comes after IT's current position in the visual
4039 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4043 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4045 charpos
= it_copy
.bidi_it
.charpos
;
4048 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4050 if (it
->current
.overlay_string_index
>= 0)
4051 bufpos
= IT_CHARPOS (*it
);
4055 base_face_id
= underlying_face_id (it
);
4057 /* Get the face for ASCII, or unibyte. */
4058 face_id
= face_at_string_position (it
->w
,
4062 &next_check_charpos
,
4065 /* Correct the face for charsets different from ASCII. Do it
4066 for the multibyte case only. The face returned above is
4067 suitable for unibyte text if IT->string is unibyte. */
4068 if (STRING_MULTIBYTE (it
->string
))
4070 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4071 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4073 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4075 c
= string_char_and_length (p
, &len
);
4076 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4081 struct text_pos pos
;
4083 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4084 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4087 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4088 pos
= it
->current
.pos
;
4093 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4096 if (it
->what
== IT_COMPOSITION
)
4098 /* For composition, we must check the position after
4100 pos
.charpos
+= it
->cmp_it
.nchars
;
4101 pos
.bytepos
+= it
->len
;
4104 INC_TEXT_POS (pos
, it
->multibyte_p
);
4111 /* With bidi iteration, the character before the current
4112 in the visual order cannot be found by simple
4113 iteration, because "reverse" reordering is not
4114 supported. Instead, we need to use the move_it_*
4115 family of functions. */
4116 /* Ignore face changes before the first visible
4117 character on this display line. */
4118 if (it
->current_x
<= it
->first_visible_x
)
4120 SAVE_IT (it_copy
, *it
, it_copy_data
);
4121 /* Implementation note: Since move_it_in_display_line
4122 works in the iterator geometry, and thinks the first
4123 character is always the leftmost, even in R2L lines,
4124 we don't need to distinguish between the R2L and L2R
4126 move_it_in_display_line (&it_copy
, ZV
,
4127 it_copy
.current_x
- 1, MOVE_TO_X
);
4128 pos
= it_copy
.current
.pos
;
4129 RESTORE_IT (it
, it
, it_copy_data
);
4133 /* Set charpos to the buffer position of the character
4134 that comes after IT's current position in the visual
4136 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4140 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4143 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4146 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4148 /* Determine face for CHARSET_ASCII, or unibyte. */
4149 face_id
= face_at_buffer_position (it
->w
,
4151 &next_check_charpos
,
4154 /* Correct the face for charsets different from ASCII. Do it
4155 for the multibyte case only. The face returned above is
4156 suitable for unibyte text if current_buffer is unibyte. */
4157 if (it
->multibyte_p
)
4159 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4160 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4161 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4170 /***********************************************************************
4172 ***********************************************************************/
4174 /* Set up iterator IT from invisible properties at its current
4175 position. Called from handle_stop. */
4177 static enum prop_handled
4178 handle_invisible_prop (struct it
*it
)
4180 enum prop_handled handled
= HANDLED_NORMALLY
;
4184 if (STRINGP (it
->string
))
4186 Lisp_Object end_charpos
, limit
, charpos
;
4188 /* Get the value of the invisible text property at the
4189 current position. Value will be nil if there is no such
4191 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4192 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4193 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4195 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4197 /* Record whether we have to display an ellipsis for the
4199 int display_ellipsis_p
= (invis_p
== 2);
4200 ptrdiff_t len
, endpos
;
4202 handled
= HANDLED_RECOMPUTE_PROPS
;
4204 /* Get the position at which the next visible text can be
4205 found in IT->string, if any. */
4206 endpos
= len
= SCHARS (it
->string
);
4207 XSETINT (limit
, len
);
4210 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4212 if (INTEGERP (end_charpos
))
4214 endpos
= XFASTINT (end_charpos
);
4215 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4216 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4218 display_ellipsis_p
= true;
4221 while (invis_p
&& endpos
< len
);
4223 if (display_ellipsis_p
)
4224 it
->ellipsis_p
= true;
4228 /* Text at END_CHARPOS is visible. Move IT there. */
4229 struct text_pos old
;
4232 old
= it
->current
.string_pos
;
4233 oldpos
= CHARPOS (old
);
4236 if (it
->bidi_it
.first_elt
4237 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4238 bidi_paragraph_init (it
->paragraph_embedding
,
4240 /* Bidi-iterate out of the invisible text. */
4243 bidi_move_to_visually_next (&it
->bidi_it
);
4245 while (oldpos
<= it
->bidi_it
.charpos
4246 && it
->bidi_it
.charpos
< endpos
);
4248 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4249 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4250 if (IT_CHARPOS (*it
) >= endpos
)
4251 it
->prev_stop
= endpos
;
4255 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4256 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4261 /* The rest of the string is invisible. If this is an
4262 overlay string, proceed with the next overlay string
4263 or whatever comes and return a character from there. */
4264 if (it
->current
.overlay_string_index
>= 0
4265 && !display_ellipsis_p
)
4267 next_overlay_string (it
);
4268 /* Don't check for overlay strings when we just
4269 finished processing them. */
4270 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4274 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4275 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4282 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4283 Lisp_Object pos
, overlay
;
4285 /* First of all, is there invisible text at this position? */
4286 tem
= start_charpos
= IT_CHARPOS (*it
);
4287 pos
= make_number (tem
);
4288 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4290 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4292 /* If we are on invisible text, skip over it. */
4293 if (invis_p
&& start_charpos
< it
->end_charpos
)
4295 /* Record whether we have to display an ellipsis for the
4297 int display_ellipsis_p
= invis_p
== 2;
4299 handled
= HANDLED_RECOMPUTE_PROPS
;
4301 /* Loop skipping over invisible text. The loop is left at
4302 ZV or with IT on the first char being visible again. */
4305 /* Try to skip some invisible text. Return value is the
4306 position reached which can be equal to where we start
4307 if there is nothing invisible there. This skips both
4308 over invisible text properties and overlays with
4309 invisible property. */
4310 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4312 /* If we skipped nothing at all we weren't at invisible
4313 text in the first place. If everything to the end of
4314 the buffer was skipped, end the loop. */
4315 if (newpos
== tem
|| newpos
>= ZV
)
4319 /* We skipped some characters but not necessarily
4320 all there are. Check if we ended up on visible
4321 text. Fget_char_property returns the property of
4322 the char before the given position, i.e. if we
4323 get invis_p = 0, this means that the char at
4324 newpos is visible. */
4325 pos
= make_number (newpos
);
4326 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4327 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4330 /* If we ended up on invisible text, proceed to
4331 skip starting with next_stop. */
4335 /* If there are adjacent invisible texts, don't lose the
4336 second one's ellipsis. */
4338 display_ellipsis_p
= true;
4342 /* The position newpos is now either ZV or on visible text. */
4345 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4347 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4349 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4351 /* If the invisible text ends on a newline or on a
4352 character after a newline, we can avoid the costly,
4353 character by character, bidi iteration to NEWPOS, and
4354 instead simply reseat the iterator there. That's
4355 because all bidi reordering information is tossed at
4356 the newline. This is a big win for modes that hide
4357 complete lines, like Outline, Org, etc. */
4358 if (on_newline
|| after_newline
)
4360 struct text_pos tpos
;
4361 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4363 SET_TEXT_POS (tpos
, newpos
, bpos
);
4364 reseat_1 (it
, tpos
, 0);
4365 /* If we reseat on a newline/ZV, we need to prep the
4366 bidi iterator for advancing to the next character
4367 after the newline/EOB, keeping the current paragraph
4368 direction (so that PRODUCE_GLYPHS does TRT wrt
4369 prepending/appending glyphs to a glyph row). */
4372 it
->bidi_it
.first_elt
= 0;
4373 it
->bidi_it
.paragraph_dir
= pdir
;
4374 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4375 it
->bidi_it
.nchars
= 1;
4376 it
->bidi_it
.ch_len
= 1;
4379 else /* Must use the slow method. */
4381 /* With bidi iteration, the region of invisible text
4382 could start and/or end in the middle of a
4383 non-base embedding level. Therefore, we need to
4384 skip invisible text using the bidi iterator,
4385 starting at IT's current position, until we find
4386 ourselves outside of the invisible text.
4387 Skipping invisible text _after_ bidi iteration
4388 avoids affecting the visual order of the
4389 displayed text when invisible properties are
4390 added or removed. */
4391 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4393 /* If we were `reseat'ed to a new paragraph,
4394 determine the paragraph base direction. We
4395 need to do it now because
4396 next_element_from_buffer may not have a
4397 chance to do it, if we are going to skip any
4398 text at the beginning, which resets the
4400 bidi_paragraph_init (it
->paragraph_embedding
,
4405 bidi_move_to_visually_next (&it
->bidi_it
);
4407 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4408 && it
->bidi_it
.charpos
< newpos
);
4409 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4410 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4411 /* If we overstepped NEWPOS, record its position in
4412 the iterator, so that we skip invisible text if
4413 later the bidi iteration lands us in the
4414 invisible region again. */
4415 if (IT_CHARPOS (*it
) >= newpos
)
4416 it
->prev_stop
= newpos
;
4421 IT_CHARPOS (*it
) = newpos
;
4422 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4425 /* If there are before-strings at the start of invisible
4426 text, and the text is invisible because of a text
4427 property, arrange to show before-strings because 20.x did
4428 it that way. (If the text is invisible because of an
4429 overlay property instead of a text property, this is
4430 already handled in the overlay code.) */
4432 && get_overlay_strings (it
, it
->stop_charpos
))
4434 handled
= HANDLED_RECOMPUTE_PROPS
;
4435 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4437 else if (display_ellipsis_p
)
4439 /* Make sure that the glyphs of the ellipsis will get
4440 correct `charpos' values. If we would not update
4441 it->position here, the glyphs would belong to the
4442 last visible character _before_ the invisible
4443 text, which confuses `set_cursor_from_row'.
4445 We use the last invisible position instead of the
4446 first because this way the cursor is always drawn on
4447 the first "." of the ellipsis, whenever PT is inside
4448 the invisible text. Otherwise the cursor would be
4449 placed _after_ the ellipsis when the point is after the
4450 first invisible character. */
4451 if (!STRINGP (it
->object
))
4453 it
->position
.charpos
= newpos
- 1;
4454 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4456 it
->ellipsis_p
= true;
4457 /* Let the ellipsis display before
4458 considering any properties of the following char.
4459 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4460 handled
= HANDLED_RETURN
;
4469 /* Make iterator IT return `...' next.
4470 Replaces LEN characters from buffer. */
4473 setup_for_ellipsis (struct it
*it
, int len
)
4475 /* Use the display table definition for `...'. Invalid glyphs
4476 will be handled by the method returning elements from dpvec. */
4477 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4479 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4480 it
->dpvec
= v
->contents
;
4481 it
->dpend
= v
->contents
+ v
->header
.size
;
4485 /* Default `...'. */
4486 it
->dpvec
= default_invis_vector
;
4487 it
->dpend
= default_invis_vector
+ 3;
4490 it
->dpvec_char_len
= len
;
4491 it
->current
.dpvec_index
= 0;
4492 it
->dpvec_face_id
= -1;
4494 /* Remember the current face id in case glyphs specify faces.
4495 IT's face is restored in set_iterator_to_next.
4496 saved_face_id was set to preceding char's face in handle_stop. */
4497 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4498 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4500 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4501 it
->ellipsis_p
= true;
4506 /***********************************************************************
4508 ***********************************************************************/
4510 /* Set up iterator IT from `display' property at its current position.
4511 Called from handle_stop.
4512 We return HANDLED_RETURN if some part of the display property
4513 overrides the display of the buffer text itself.
4514 Otherwise we return HANDLED_NORMALLY. */
4516 static enum prop_handled
4517 handle_display_prop (struct it
*it
)
4519 Lisp_Object propval
, object
, overlay
;
4520 struct text_pos
*position
;
4522 /* Nonzero if some property replaces the display of the text itself. */
4523 int display_replaced_p
= 0;
4525 if (STRINGP (it
->string
))
4527 object
= it
->string
;
4528 position
= &it
->current
.string_pos
;
4529 bufpos
= CHARPOS (it
->current
.pos
);
4533 XSETWINDOW (object
, it
->w
);
4534 position
= &it
->current
.pos
;
4535 bufpos
= CHARPOS (*position
);
4538 /* Reset those iterator values set from display property values. */
4539 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4540 it
->space_width
= Qnil
;
4541 it
->font_height
= Qnil
;
4544 /* We don't support recursive `display' properties, i.e. string
4545 values that have a string `display' property, that have a string
4546 `display' property etc. */
4547 if (!it
->string_from_display_prop_p
)
4548 it
->area
= TEXT_AREA
;
4550 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4551 Qdisplay
, object
, &overlay
);
4553 return HANDLED_NORMALLY
;
4554 /* Now OVERLAY is the overlay that gave us this property, or nil
4555 if it was a text property. */
4557 if (!STRINGP (it
->string
))
4558 object
= it
->w
->contents
;
4560 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4562 FRAME_WINDOW_P (it
->f
));
4564 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4567 /* Subroutine of handle_display_prop. Returns non-zero if the display
4568 specification in SPEC is a replacing specification, i.e. it would
4569 replace the text covered by `display' property with something else,
4570 such as an image or a display string. If SPEC includes any kind or
4571 `(space ...) specification, the value is 2; this is used by
4572 compute_display_string_pos, which see.
4574 See handle_single_display_spec for documentation of arguments.
4575 frame_window_p is non-zero if the window being redisplayed is on a
4576 GUI frame; this argument is used only if IT is NULL, see below.
4578 IT can be NULL, if this is called by the bidi reordering code
4579 through compute_display_string_pos, which see. In that case, this
4580 function only examines SPEC, but does not otherwise "handle" it, in
4581 the sense that it doesn't set up members of IT from the display
4584 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4585 Lisp_Object overlay
, struct text_pos
*position
,
4586 ptrdiff_t bufpos
, int frame_window_p
)
4588 int replacing_p
= 0;
4592 /* Simple specifications. */
4593 && !EQ (XCAR (spec
), Qimage
)
4594 && !EQ (XCAR (spec
), Qspace
)
4595 && !EQ (XCAR (spec
), Qwhen
)
4596 && !EQ (XCAR (spec
), Qslice
)
4597 && !EQ (XCAR (spec
), Qspace_width
)
4598 && !EQ (XCAR (spec
), Qheight
)
4599 && !EQ (XCAR (spec
), Qraise
)
4600 /* Marginal area specifications. */
4601 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4602 && !EQ (XCAR (spec
), Qleft_fringe
)
4603 && !EQ (XCAR (spec
), Qright_fringe
)
4604 && !NILP (XCAR (spec
)))
4606 for (; CONSP (spec
); spec
= XCDR (spec
))
4608 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4609 overlay
, position
, bufpos
,
4610 replacing_p
, frame_window_p
)))
4613 /* If some text in a string is replaced, `position' no
4614 longer points to the position of `object'. */
4615 if (!it
|| STRINGP (object
))
4620 else if (VECTORP (spec
))
4623 for (i
= 0; i
< ASIZE (spec
); ++i
)
4624 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4625 overlay
, position
, bufpos
,
4626 replacing_p
, frame_window_p
)))
4629 /* If some text in a string is replaced, `position' no
4630 longer points to the position of `object'. */
4631 if (!it
|| STRINGP (object
))
4637 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4638 position
, bufpos
, 0,
4646 /* Value is the position of the end of the `display' property starting
4647 at START_POS in OBJECT. */
4649 static struct text_pos
4650 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4653 struct text_pos end_pos
;
4655 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4656 Qdisplay
, object
, Qnil
);
4657 CHARPOS (end_pos
) = XFASTINT (end
);
4658 if (STRINGP (object
))
4659 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4661 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4667 /* Set up IT from a single `display' property specification SPEC. OBJECT
4668 is the object in which the `display' property was found. *POSITION
4669 is the position in OBJECT at which the `display' property was found.
4670 BUFPOS is the buffer position of OBJECT (different from POSITION if
4671 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4672 previously saw a display specification which already replaced text
4673 display with something else, for example an image; we ignore such
4674 properties after the first one has been processed.
4676 OVERLAY is the overlay this `display' property came from,
4677 or nil if it was a text property.
4679 If SPEC is a `space' or `image' specification, and in some other
4680 cases too, set *POSITION to the position where the `display'
4683 If IT is NULL, only examine the property specification in SPEC, but
4684 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4685 is intended to be displayed in a window on a GUI frame.
4687 Value is non-zero if something was found which replaces the display
4688 of buffer or string text. */
4691 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4692 Lisp_Object overlay
, struct text_pos
*position
,
4693 ptrdiff_t bufpos
, int display_replaced_p
,
4697 Lisp_Object location
, value
;
4698 struct text_pos start_pos
= *position
;
4701 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4702 If the result is non-nil, use VALUE instead of SPEC. */
4704 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4713 if (!NILP (form
) && !EQ (form
, Qt
))
4715 ptrdiff_t count
= SPECPDL_INDEX ();
4716 struct gcpro gcpro1
;
4718 /* Bind `object' to the object having the `display' property, a
4719 buffer or string. Bind `position' to the position in the
4720 object where the property was found, and `buffer-position'
4721 to the current position in the buffer. */
4724 XSETBUFFER (object
, current_buffer
);
4725 specbind (Qobject
, object
);
4726 specbind (Qposition
, make_number (CHARPOS (*position
)));
4727 specbind (Qbuffer_position
, make_number (bufpos
));
4729 form
= safe_eval (form
);
4731 unbind_to (count
, Qnil
);
4737 /* Handle `(height HEIGHT)' specifications. */
4739 && EQ (XCAR (spec
), Qheight
)
4740 && CONSP (XCDR (spec
)))
4744 if (!FRAME_WINDOW_P (it
->f
))
4747 it
->font_height
= XCAR (XCDR (spec
));
4748 if (!NILP (it
->font_height
))
4750 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4751 int new_height
= -1;
4753 if (CONSP (it
->font_height
)
4754 && (EQ (XCAR (it
->font_height
), Qplus
)
4755 || EQ (XCAR (it
->font_height
), Qminus
))
4756 && CONSP (XCDR (it
->font_height
))
4757 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4759 /* `(+ N)' or `(- N)' where N is an integer. */
4760 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4761 if (EQ (XCAR (it
->font_height
), Qplus
))
4763 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4765 else if (FUNCTIONP (it
->font_height
))
4767 /* Call function with current height as argument.
4768 Value is the new height. */
4770 height
= safe_call1 (it
->font_height
,
4771 face
->lface
[LFACE_HEIGHT_INDEX
]);
4772 if (NUMBERP (height
))
4773 new_height
= XFLOATINT (height
);
4775 else if (NUMBERP (it
->font_height
))
4777 /* Value is a multiple of the canonical char height. */
4780 f
= FACE_FROM_ID (it
->f
,
4781 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4782 new_height
= (XFLOATINT (it
->font_height
)
4783 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4787 /* Evaluate IT->font_height with `height' bound to the
4788 current specified height to get the new height. */
4789 ptrdiff_t count
= SPECPDL_INDEX ();
4791 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4792 value
= safe_eval (it
->font_height
);
4793 unbind_to (count
, Qnil
);
4795 if (NUMBERP (value
))
4796 new_height
= XFLOATINT (value
);
4800 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4807 /* Handle `(space-width WIDTH)'. */
4809 && EQ (XCAR (spec
), Qspace_width
)
4810 && CONSP (XCDR (spec
)))
4814 if (!FRAME_WINDOW_P (it
->f
))
4817 value
= XCAR (XCDR (spec
));
4818 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4819 it
->space_width
= value
;
4825 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4827 && EQ (XCAR (spec
), Qslice
))
4833 if (!FRAME_WINDOW_P (it
->f
))
4836 if (tem
= XCDR (spec
), CONSP (tem
))
4838 it
->slice
.x
= XCAR (tem
);
4839 if (tem
= XCDR (tem
), CONSP (tem
))
4841 it
->slice
.y
= XCAR (tem
);
4842 if (tem
= XCDR (tem
), CONSP (tem
))
4844 it
->slice
.width
= XCAR (tem
);
4845 if (tem
= XCDR (tem
), CONSP (tem
))
4846 it
->slice
.height
= XCAR (tem
);
4855 /* Handle `(raise FACTOR)'. */
4857 && EQ (XCAR (spec
), Qraise
)
4858 && CONSP (XCDR (spec
)))
4862 if (!FRAME_WINDOW_P (it
->f
))
4865 #ifdef HAVE_WINDOW_SYSTEM
4866 value
= XCAR (XCDR (spec
));
4867 if (NUMBERP (value
))
4869 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4870 it
->voffset
= - (XFLOATINT (value
)
4871 * (FONT_HEIGHT (face
->font
)));
4873 #endif /* HAVE_WINDOW_SYSTEM */
4879 /* Don't handle the other kinds of display specifications
4880 inside a string that we got from a `display' property. */
4881 if (it
&& it
->string_from_display_prop_p
)
4884 /* Characters having this form of property are not displayed, so
4885 we have to find the end of the property. */
4888 start_pos
= *position
;
4889 *position
= display_prop_end (it
, object
, start_pos
);
4893 /* Stop the scan at that end position--we assume that all
4894 text properties change there. */
4896 it
->stop_charpos
= position
->charpos
;
4898 /* Handle `(left-fringe BITMAP [FACE])'
4899 and `(right-fringe BITMAP [FACE])'. */
4901 && (EQ (XCAR (spec
), Qleft_fringe
)
4902 || EQ (XCAR (spec
), Qright_fringe
))
4903 && CONSP (XCDR (spec
)))
4909 if (!FRAME_WINDOW_P (it
->f
))
4910 /* If we return here, POSITION has been advanced
4911 across the text with this property. */
4913 /* Synchronize the bidi iterator with POSITION. This is
4914 needed because we are not going to push the iterator
4915 on behalf of this display property, so there will be
4916 no pop_it call to do this synchronization for us. */
4919 it
->position
= *position
;
4920 iterate_out_of_display_property (it
);
4921 *position
= it
->position
;
4926 else if (!frame_window_p
)
4929 #ifdef HAVE_WINDOW_SYSTEM
4930 value
= XCAR (XCDR (spec
));
4931 if (!SYMBOLP (value
)
4932 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4933 /* If we return here, POSITION has been advanced
4934 across the text with this property. */
4936 if (it
&& it
->bidi_p
)
4938 it
->position
= *position
;
4939 iterate_out_of_display_property (it
);
4940 *position
= it
->position
;
4947 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4949 if (CONSP (XCDR (XCDR (spec
))))
4951 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4952 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4958 /* Save current settings of IT so that we can restore them
4959 when we are finished with the glyph property value. */
4960 push_it (it
, position
);
4962 it
->area
= TEXT_AREA
;
4963 it
->what
= IT_IMAGE
;
4964 it
->image_id
= -1; /* no image */
4965 it
->position
= start_pos
;
4966 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4967 it
->method
= GET_FROM_IMAGE
;
4968 it
->from_overlay
= Qnil
;
4969 it
->face_id
= face_id
;
4970 it
->from_disp_prop_p
= true;
4972 /* Say that we haven't consumed the characters with
4973 `display' property yet. The call to pop_it in
4974 set_iterator_to_next will clean this up. */
4975 *position
= start_pos
;
4977 if (EQ (XCAR (spec
), Qleft_fringe
))
4979 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4980 it
->left_user_fringe_face_id
= face_id
;
4984 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4985 it
->right_user_fringe_face_id
= face_id
;
4988 #endif /* HAVE_WINDOW_SYSTEM */
4992 /* Prepare to handle `((margin left-margin) ...)',
4993 `((margin right-margin) ...)' and `((margin nil) ...)'
4994 prefixes for display specifications. */
4995 location
= Qunbound
;
4996 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5000 value
= XCDR (spec
);
5002 value
= XCAR (value
);
5005 if (EQ (XCAR (tem
), Qmargin
)
5006 && (tem
= XCDR (tem
),
5007 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5009 || EQ (tem
, Qleft_margin
)
5010 || EQ (tem
, Qright_margin
))))
5014 if (EQ (location
, Qunbound
))
5020 /* After this point, VALUE is the property after any
5021 margin prefix has been stripped. It must be a string,
5022 an image specification, or `(space ...)'.
5024 LOCATION specifies where to display: `left-margin',
5025 `right-margin' or nil. */
5027 valid_p
= (STRINGP (value
)
5028 #ifdef HAVE_WINDOW_SYSTEM
5029 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5030 && valid_image_p (value
))
5031 #endif /* not HAVE_WINDOW_SYSTEM */
5032 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5034 if (valid_p
&& !display_replaced_p
)
5040 /* Callers need to know whether the display spec is any kind
5041 of `(space ...)' spec that is about to affect text-area
5043 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5048 /* Save current settings of IT so that we can restore them
5049 when we are finished with the glyph property value. */
5050 push_it (it
, position
);
5051 it
->from_overlay
= overlay
;
5052 it
->from_disp_prop_p
= true;
5054 if (NILP (location
))
5055 it
->area
= TEXT_AREA
;
5056 else if (EQ (location
, Qleft_margin
))
5057 it
->area
= LEFT_MARGIN_AREA
;
5059 it
->area
= RIGHT_MARGIN_AREA
;
5061 if (STRINGP (value
))
5064 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5065 it
->current
.overlay_string_index
= -1;
5066 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5067 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5068 it
->method
= GET_FROM_STRING
;
5069 it
->stop_charpos
= 0;
5071 it
->base_level_stop
= 0;
5072 it
->string_from_display_prop_p
= true;
5073 /* Say that we haven't consumed the characters with
5074 `display' property yet. The call to pop_it in
5075 set_iterator_to_next will clean this up. */
5076 if (BUFFERP (object
))
5077 *position
= start_pos
;
5079 /* Force paragraph direction to be that of the parent
5080 object. If the parent object's paragraph direction is
5081 not yet determined, default to L2R. */
5082 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5083 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5085 it
->paragraph_embedding
= L2R
;
5087 /* Set up the bidi iterator for this display string. */
5090 it
->bidi_it
.string
.lstring
= it
->string
;
5091 it
->bidi_it
.string
.s
= NULL
;
5092 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5093 it
->bidi_it
.string
.bufpos
= bufpos
;
5094 it
->bidi_it
.string
.from_disp_str
= 1;
5095 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5096 it
->bidi_it
.w
= it
->w
;
5097 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5100 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5102 it
->method
= GET_FROM_STRETCH
;
5104 *position
= it
->position
= start_pos
;
5105 retval
= 1 + (it
->area
== TEXT_AREA
);
5107 #ifdef HAVE_WINDOW_SYSTEM
5110 it
->what
= IT_IMAGE
;
5111 it
->image_id
= lookup_image (it
->f
, value
);
5112 it
->position
= start_pos
;
5113 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5114 it
->method
= GET_FROM_IMAGE
;
5116 /* Say that we haven't consumed the characters with
5117 `display' property yet. The call to pop_it in
5118 set_iterator_to_next will clean this up. */
5119 *position
= start_pos
;
5121 #endif /* HAVE_WINDOW_SYSTEM */
5126 /* Invalid property or property not supported. Restore
5127 POSITION to what it was before. */
5128 *position
= start_pos
;
5132 /* Check if PROP is a display property value whose text should be
5133 treated as intangible. OVERLAY is the overlay from which PROP
5134 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5135 specify the buffer position covered by PROP. */
5138 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5139 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5141 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5142 struct text_pos position
;
5144 SET_TEXT_POS (position
, charpos
, bytepos
);
5145 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5146 &position
, charpos
, frame_window_p
);
5150 /* Return 1 if PROP is a display sub-property value containing STRING.
5152 Implementation note: this and the following function are really
5153 special cases of handle_display_spec and
5154 handle_single_display_spec, and should ideally use the same code.
5155 Until they do, these two pairs must be consistent and must be
5156 modified in sync. */
5159 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5161 if (EQ (string
, prop
))
5164 /* Skip over `when FORM'. */
5165 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5170 /* Actually, the condition following `when' should be eval'ed,
5171 like handle_single_display_spec does, and we should return
5172 zero if it evaluates to nil. However, this function is
5173 called only when the buffer was already displayed and some
5174 glyph in the glyph matrix was found to come from a display
5175 string. Therefore, the condition was already evaluated, and
5176 the result was non-nil, otherwise the display string wouldn't
5177 have been displayed and we would have never been called for
5178 this property. Thus, we can skip the evaluation and assume
5179 its result is non-nil. */
5184 /* Skip over `margin LOCATION'. */
5185 if (EQ (XCAR (prop
), Qmargin
))
5196 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5200 /* Return 1 if STRING appears in the `display' property PROP. */
5203 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5206 && !EQ (XCAR (prop
), Qwhen
)
5207 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5209 /* A list of sub-properties. */
5210 while (CONSP (prop
))
5212 if (single_display_spec_string_p (XCAR (prop
), string
))
5217 else if (VECTORP (prop
))
5219 /* A vector of sub-properties. */
5221 for (i
= 0; i
< ASIZE (prop
); ++i
)
5222 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5226 return single_display_spec_string_p (prop
, string
);
5231 /* Look for STRING in overlays and text properties in the current
5232 buffer, between character positions FROM and TO (excluding TO).
5233 BACK_P non-zero means look back (in this case, TO is supposed to be
5235 Value is the first character position where STRING was found, or
5236 zero if it wasn't found before hitting TO.
5238 This function may only use code that doesn't eval because it is
5239 called asynchronously from note_mouse_highlight. */
5242 string_buffer_position_lim (Lisp_Object string
,
5243 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5245 Lisp_Object limit
, prop
, pos
;
5248 pos
= make_number (max (from
, BEGV
));
5250 if (!back_p
) /* looking forward */
5252 limit
= make_number (min (to
, ZV
));
5253 while (!found
&& !EQ (pos
, limit
))
5255 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5256 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5259 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5263 else /* looking back */
5265 limit
= make_number (max (to
, BEGV
));
5266 while (!found
&& !EQ (pos
, limit
))
5268 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5269 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5272 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5277 return found
? XINT (pos
) : 0;
5280 /* Determine which buffer position in current buffer STRING comes from.
5281 AROUND_CHARPOS is an approximate position where it could come from.
5282 Value is the buffer position or 0 if it couldn't be determined.
5284 This function is necessary because we don't record buffer positions
5285 in glyphs generated from strings (to keep struct glyph small).
5286 This function may only use code that doesn't eval because it is
5287 called asynchronously from note_mouse_highlight. */
5290 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5292 const int MAX_DISTANCE
= 1000;
5293 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5294 around_charpos
+ MAX_DISTANCE
,
5298 found
= string_buffer_position_lim (string
, around_charpos
,
5299 around_charpos
- MAX_DISTANCE
, 1);
5305 /***********************************************************************
5306 `composition' property
5307 ***********************************************************************/
5309 /* Set up iterator IT from `composition' property at its current
5310 position. Called from handle_stop. */
5312 static enum prop_handled
5313 handle_composition_prop (struct it
*it
)
5315 Lisp_Object prop
, string
;
5316 ptrdiff_t pos
, pos_byte
, start
, end
;
5318 if (STRINGP (it
->string
))
5322 pos
= IT_STRING_CHARPOS (*it
);
5323 pos_byte
= IT_STRING_BYTEPOS (*it
);
5324 string
= it
->string
;
5325 s
= SDATA (string
) + pos_byte
;
5326 it
->c
= STRING_CHAR (s
);
5330 pos
= IT_CHARPOS (*it
);
5331 pos_byte
= IT_BYTEPOS (*it
);
5333 it
->c
= FETCH_CHAR (pos_byte
);
5336 /* If there's a valid composition and point is not inside of the
5337 composition (in the case that the composition is from the current
5338 buffer), draw a glyph composed from the composition components. */
5339 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5340 && composition_valid_p (start
, end
, prop
)
5341 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5344 /* As we can't handle this situation (perhaps font-lock added
5345 a new composition), we just return here hoping that next
5346 redisplay will detect this composition much earlier. */
5347 return HANDLED_NORMALLY
;
5350 if (STRINGP (it
->string
))
5351 pos_byte
= string_char_to_byte (it
->string
, start
);
5353 pos_byte
= CHAR_TO_BYTE (start
);
5355 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5358 if (it
->cmp_it
.id
>= 0)
5361 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5362 it
->cmp_it
.nglyphs
= -1;
5366 return HANDLED_NORMALLY
;
5371 /***********************************************************************
5373 ***********************************************************************/
5375 /* The following structure is used to record overlay strings for
5376 later sorting in load_overlay_strings. */
5378 struct overlay_entry
5380 Lisp_Object overlay
;
5387 /* Set up iterator IT from overlay strings at its current position.
5388 Called from handle_stop. */
5390 static enum prop_handled
5391 handle_overlay_change (struct it
*it
)
5393 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5394 return HANDLED_RECOMPUTE_PROPS
;
5396 return HANDLED_NORMALLY
;
5400 /* Set up the next overlay string for delivery by IT, if there is an
5401 overlay string to deliver. Called by set_iterator_to_next when the
5402 end of the current overlay string is reached. If there are more
5403 overlay strings to display, IT->string and
5404 IT->current.overlay_string_index are set appropriately here.
5405 Otherwise IT->string is set to nil. */
5408 next_overlay_string (struct it
*it
)
5410 ++it
->current
.overlay_string_index
;
5411 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5413 /* No more overlay strings. Restore IT's settings to what
5414 they were before overlay strings were processed, and
5415 continue to deliver from current_buffer. */
5417 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5420 || (NILP (it
->string
)
5421 && it
->method
== GET_FROM_BUFFER
5422 && it
->stop_charpos
>= BEGV
5423 && it
->stop_charpos
<= it
->end_charpos
));
5424 it
->current
.overlay_string_index
= -1;
5425 it
->n_overlay_strings
= 0;
5426 it
->overlay_strings_charpos
= -1;
5427 /* If there's an empty display string on the stack, pop the
5428 stack, to resync the bidi iterator with IT's position. Such
5429 empty strings are pushed onto the stack in
5430 get_overlay_strings_1. */
5431 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5434 /* If we're at the end of the buffer, record that we have
5435 processed the overlay strings there already, so that
5436 next_element_from_buffer doesn't try it again. */
5437 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5438 it
->overlay_strings_at_end_processed_p
= true;
5442 /* There are more overlay strings to process. If
5443 IT->current.overlay_string_index has advanced to a position
5444 where we must load IT->overlay_strings with more strings, do
5445 it. We must load at the IT->overlay_strings_charpos where
5446 IT->n_overlay_strings was originally computed; when invisible
5447 text is present, this might not be IT_CHARPOS (Bug#7016). */
5448 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5450 if (it
->current
.overlay_string_index
&& i
== 0)
5451 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5453 /* Initialize IT to deliver display elements from the overlay
5455 it
->string
= it
->overlay_strings
[i
];
5456 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5457 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5458 it
->method
= GET_FROM_STRING
;
5459 it
->stop_charpos
= 0;
5460 it
->end_charpos
= SCHARS (it
->string
);
5461 if (it
->cmp_it
.stop_pos
>= 0)
5462 it
->cmp_it
.stop_pos
= 0;
5464 it
->base_level_stop
= 0;
5466 /* Set up the bidi iterator for this overlay string. */
5469 it
->bidi_it
.string
.lstring
= it
->string
;
5470 it
->bidi_it
.string
.s
= NULL
;
5471 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5472 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5473 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5474 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5475 it
->bidi_it
.w
= it
->w
;
5476 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5484 /* Compare two overlay_entry structures E1 and E2. Used as a
5485 comparison function for qsort in load_overlay_strings. Overlay
5486 strings for the same position are sorted so that
5488 1. All after-strings come in front of before-strings, except
5489 when they come from the same overlay.
5491 2. Within after-strings, strings are sorted so that overlay strings
5492 from overlays with higher priorities come first.
5494 2. Within before-strings, strings are sorted so that overlay
5495 strings from overlays with higher priorities come last.
5497 Value is analogous to strcmp. */
5501 compare_overlay_entries (const void *e1
, const void *e2
)
5503 struct overlay_entry
const *entry1
= e1
;
5504 struct overlay_entry
const *entry2
= e2
;
5507 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5509 /* Let after-strings appear in front of before-strings if
5510 they come from different overlays. */
5511 if (EQ (entry1
->overlay
, entry2
->overlay
))
5512 result
= entry1
->after_string_p
? 1 : -1;
5514 result
= entry1
->after_string_p
? -1 : 1;
5516 else if (entry1
->priority
!= entry2
->priority
)
5518 if (entry1
->after_string_p
)
5519 /* After-strings sorted in order of decreasing priority. */
5520 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5522 /* Before-strings sorted in order of increasing priority. */
5523 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5532 /* Load the vector IT->overlay_strings with overlay strings from IT's
5533 current buffer position, or from CHARPOS if that is > 0. Set
5534 IT->n_overlays to the total number of overlay strings found.
5536 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5537 a time. On entry into load_overlay_strings,
5538 IT->current.overlay_string_index gives the number of overlay
5539 strings that have already been loaded by previous calls to this
5542 IT->add_overlay_start contains an additional overlay start
5543 position to consider for taking overlay strings from, if non-zero.
5544 This position comes into play when the overlay has an `invisible'
5545 property, and both before and after-strings. When we've skipped to
5546 the end of the overlay, because of its `invisible' property, we
5547 nevertheless want its before-string to appear.
5548 IT->add_overlay_start will contain the overlay start position
5551 Overlay strings are sorted so that after-string strings come in
5552 front of before-string strings. Within before and after-strings,
5553 strings are sorted by overlay priority. See also function
5554 compare_overlay_entries. */
5557 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5559 Lisp_Object overlay
, window
, str
, invisible
;
5560 struct Lisp_Overlay
*ov
;
5561 ptrdiff_t start
, end
;
5562 ptrdiff_t size
= 20;
5563 ptrdiff_t n
= 0, i
, j
;
5565 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5569 charpos
= IT_CHARPOS (*it
);
5571 /* Append the overlay string STRING of overlay OVERLAY to vector
5572 `entries' which has size `size' and currently contains `n'
5573 elements. AFTER_P non-zero means STRING is an after-string of
5575 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5578 Lisp_Object priority; \
5582 struct overlay_entry *old = entries; \
5583 SAFE_NALLOCA (entries, 2, size); \
5584 memcpy (entries, old, size * sizeof *entries); \
5588 entries[n].string = (STRING); \
5589 entries[n].overlay = (OVERLAY); \
5590 priority = Foverlay_get ((OVERLAY), Qpriority); \
5591 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5592 entries[n].after_string_p = (AFTER_P); \
5597 /* Process overlay before the overlay center. */
5598 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5600 XSETMISC (overlay
, ov
);
5601 eassert (OVERLAYP (overlay
));
5602 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5603 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5608 /* Skip this overlay if it doesn't start or end at IT's current
5610 if (end
!= charpos
&& start
!= charpos
)
5613 /* Skip this overlay if it doesn't apply to IT->w. */
5614 window
= Foverlay_get (overlay
, Qwindow
);
5615 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5618 /* If the text ``under'' the overlay is invisible, both before-
5619 and after-strings from this overlay are visible; start and
5620 end position are indistinguishable. */
5621 invisible
= Foverlay_get (overlay
, Qinvisible
);
5622 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5624 /* If overlay has a non-empty before-string, record it. */
5625 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5626 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5628 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5630 /* If overlay has a non-empty after-string, record it. */
5631 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5632 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5634 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5637 /* Process overlays after the overlay center. */
5638 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5640 XSETMISC (overlay
, ov
);
5641 eassert (OVERLAYP (overlay
));
5642 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5643 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5645 if (start
> charpos
)
5648 /* Skip this overlay if it doesn't start or end at IT's current
5650 if (end
!= charpos
&& start
!= charpos
)
5653 /* Skip this overlay if it doesn't apply to IT->w. */
5654 window
= Foverlay_get (overlay
, Qwindow
);
5655 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5658 /* If the text ``under'' the overlay is invisible, it has a zero
5659 dimension, and both before- and after-strings apply. */
5660 invisible
= Foverlay_get (overlay
, Qinvisible
);
5661 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5663 /* If overlay has a non-empty before-string, record it. */
5664 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5665 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5667 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5669 /* If overlay has a non-empty after-string, record it. */
5670 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5671 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5673 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5676 #undef RECORD_OVERLAY_STRING
5680 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5682 /* Record number of overlay strings, and where we computed it. */
5683 it
->n_overlay_strings
= n
;
5684 it
->overlay_strings_charpos
= charpos
;
5686 /* IT->current.overlay_string_index is the number of overlay strings
5687 that have already been consumed by IT. Copy some of the
5688 remaining overlay strings to IT->overlay_strings. */
5690 j
= it
->current
.overlay_string_index
;
5691 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5693 it
->overlay_strings
[i
] = entries
[j
].string
;
5694 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5702 /* Get the first chunk of overlay strings at IT's current buffer
5703 position, or at CHARPOS if that is > 0. Value is non-zero if at
5704 least one overlay string was found. */
5707 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5709 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5710 process. This fills IT->overlay_strings with strings, and sets
5711 IT->n_overlay_strings to the total number of strings to process.
5712 IT->pos.overlay_string_index has to be set temporarily to zero
5713 because load_overlay_strings needs this; it must be set to -1
5714 when no overlay strings are found because a zero value would
5715 indicate a position in the first overlay string. */
5716 it
->current
.overlay_string_index
= 0;
5717 load_overlay_strings (it
, charpos
);
5719 /* If we found overlay strings, set up IT to deliver display
5720 elements from the first one. Otherwise set up IT to deliver
5721 from current_buffer. */
5722 if (it
->n_overlay_strings
)
5724 /* Make sure we know settings in current_buffer, so that we can
5725 restore meaningful values when we're done with the overlay
5728 compute_stop_pos (it
);
5729 eassert (it
->face_id
>= 0);
5731 /* Save IT's settings. They are restored after all overlay
5732 strings have been processed. */
5733 eassert (!compute_stop_p
|| it
->sp
== 0);
5735 /* When called from handle_stop, there might be an empty display
5736 string loaded. In that case, don't bother saving it. But
5737 don't use this optimization with the bidi iterator, since we
5738 need the corresponding pop_it call to resync the bidi
5739 iterator's position with IT's position, after we are done
5740 with the overlay strings. (The corresponding call to pop_it
5741 in case of an empty display string is in
5742 next_overlay_string.) */
5744 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5747 /* Set up IT to deliver display elements from the first overlay
5749 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5750 it
->string
= it
->overlay_strings
[0];
5751 it
->from_overlay
= Qnil
;
5752 it
->stop_charpos
= 0;
5753 eassert (STRINGP (it
->string
));
5754 it
->end_charpos
= SCHARS (it
->string
);
5756 it
->base_level_stop
= 0;
5757 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5758 it
->method
= GET_FROM_STRING
;
5759 it
->from_disp_prop_p
= 0;
5761 /* Force paragraph direction to be that of the parent
5763 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5764 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5766 it
->paragraph_embedding
= L2R
;
5768 /* Set up the bidi iterator for this overlay string. */
5771 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5773 it
->bidi_it
.string
.lstring
= it
->string
;
5774 it
->bidi_it
.string
.s
= NULL
;
5775 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5776 it
->bidi_it
.string
.bufpos
= pos
;
5777 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5778 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5779 it
->bidi_it
.w
= it
->w
;
5780 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5785 it
->current
.overlay_string_index
= -1;
5790 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5793 it
->method
= GET_FROM_BUFFER
;
5795 (void) get_overlay_strings_1 (it
, charpos
, 1);
5799 /* Value is non-zero if we found at least one overlay string. */
5800 return STRINGP (it
->string
);
5805 /***********************************************************************
5806 Saving and restoring state
5807 ***********************************************************************/
5809 /* Save current settings of IT on IT->stack. Called, for example,
5810 before setting up IT for an overlay string, to be able to restore
5811 IT's settings to what they were after the overlay string has been
5812 processed. If POSITION is non-NULL, it is the position to save on
5813 the stack instead of IT->position. */
5816 push_it (struct it
*it
, struct text_pos
*position
)
5818 struct iterator_stack_entry
*p
;
5820 eassert (it
->sp
< IT_STACK_SIZE
);
5821 p
= it
->stack
+ it
->sp
;
5823 p
->stop_charpos
= it
->stop_charpos
;
5824 p
->prev_stop
= it
->prev_stop
;
5825 p
->base_level_stop
= it
->base_level_stop
;
5826 p
->cmp_it
= it
->cmp_it
;
5827 eassert (it
->face_id
>= 0);
5828 p
->face_id
= it
->face_id
;
5829 p
->string
= it
->string
;
5830 p
->method
= it
->method
;
5831 p
->from_overlay
= it
->from_overlay
;
5834 case GET_FROM_IMAGE
:
5835 p
->u
.image
.object
= it
->object
;
5836 p
->u
.image
.image_id
= it
->image_id
;
5837 p
->u
.image
.slice
= it
->slice
;
5839 case GET_FROM_STRETCH
:
5840 p
->u
.stretch
.object
= it
->object
;
5843 p
->position
= position
? *position
: it
->position
;
5844 p
->current
= it
->current
;
5845 p
->end_charpos
= it
->end_charpos
;
5846 p
->string_nchars
= it
->string_nchars
;
5848 p
->multibyte_p
= it
->multibyte_p
;
5849 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5850 p
->space_width
= it
->space_width
;
5851 p
->font_height
= it
->font_height
;
5852 p
->voffset
= it
->voffset
;
5853 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5854 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5855 p
->display_ellipsis_p
= 0;
5856 p
->line_wrap
= it
->line_wrap
;
5857 p
->bidi_p
= it
->bidi_p
;
5858 p
->paragraph_embedding
= it
->paragraph_embedding
;
5859 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5862 /* Save the state of the bidi iterator as well. */
5864 bidi_push_it (&it
->bidi_it
);
5868 iterate_out_of_display_property (struct it
*it
)
5870 int buffer_p
= !STRINGP (it
->string
);
5871 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5872 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5874 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5876 /* Maybe initialize paragraph direction. If we are at the beginning
5877 of a new paragraph, next_element_from_buffer may not have a
5878 chance to do that. */
5879 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5880 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5881 /* prev_stop can be zero, so check against BEGV as well. */
5882 while (it
->bidi_it
.charpos
>= bob
5883 && it
->prev_stop
<= it
->bidi_it
.charpos
5884 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5885 && it
->bidi_it
.charpos
< eob
)
5886 bidi_move_to_visually_next (&it
->bidi_it
);
5887 /* Record the stop_pos we just crossed, for when we cross it
5889 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5890 it
->prev_stop
= CHARPOS (it
->position
);
5891 /* If we ended up not where pop_it put us, resync IT's
5892 positional members with the bidi iterator. */
5893 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5894 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5896 it
->current
.pos
= it
->position
;
5898 it
->current
.string_pos
= it
->position
;
5901 /* Restore IT's settings from IT->stack. Called, for example, when no
5902 more overlay strings must be processed, and we return to delivering
5903 display elements from a buffer, or when the end of a string from a
5904 `display' property is reached and we return to delivering display
5905 elements from an overlay string, or from a buffer. */
5908 pop_it (struct it
*it
)
5910 struct iterator_stack_entry
*p
;
5911 int from_display_prop
= it
->from_disp_prop_p
;
5913 eassert (it
->sp
> 0);
5915 p
= it
->stack
+ it
->sp
;
5916 it
->stop_charpos
= p
->stop_charpos
;
5917 it
->prev_stop
= p
->prev_stop
;
5918 it
->base_level_stop
= p
->base_level_stop
;
5919 it
->cmp_it
= p
->cmp_it
;
5920 it
->face_id
= p
->face_id
;
5921 it
->current
= p
->current
;
5922 it
->position
= p
->position
;
5923 it
->string
= p
->string
;
5924 it
->from_overlay
= p
->from_overlay
;
5925 if (NILP (it
->string
))
5926 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5927 it
->method
= p
->method
;
5930 case GET_FROM_IMAGE
:
5931 it
->image_id
= p
->u
.image
.image_id
;
5932 it
->object
= p
->u
.image
.object
;
5933 it
->slice
= p
->u
.image
.slice
;
5935 case GET_FROM_STRETCH
:
5936 it
->object
= p
->u
.stretch
.object
;
5938 case GET_FROM_BUFFER
:
5939 it
->object
= it
->w
->contents
;
5941 case GET_FROM_STRING
:
5942 it
->object
= it
->string
;
5944 case GET_FROM_DISPLAY_VECTOR
:
5946 it
->method
= GET_FROM_C_STRING
;
5947 else if (STRINGP (it
->string
))
5948 it
->method
= GET_FROM_STRING
;
5951 it
->method
= GET_FROM_BUFFER
;
5952 it
->object
= it
->w
->contents
;
5955 it
->end_charpos
= p
->end_charpos
;
5956 it
->string_nchars
= p
->string_nchars
;
5958 it
->multibyte_p
= p
->multibyte_p
;
5959 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5960 it
->space_width
= p
->space_width
;
5961 it
->font_height
= p
->font_height
;
5962 it
->voffset
= p
->voffset
;
5963 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5964 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5965 it
->line_wrap
= p
->line_wrap
;
5966 it
->bidi_p
= p
->bidi_p
;
5967 it
->paragraph_embedding
= p
->paragraph_embedding
;
5968 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5971 bidi_pop_it (&it
->bidi_it
);
5972 /* Bidi-iterate until we get out of the portion of text, if any,
5973 covered by a `display' text property or by an overlay with
5974 `display' property. (We cannot just jump there, because the
5975 internal coherency of the bidi iterator state can not be
5976 preserved across such jumps.) We also must determine the
5977 paragraph base direction if the overlay we just processed is
5978 at the beginning of a new paragraph. */
5979 if (from_display_prop
5980 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5981 iterate_out_of_display_property (it
);
5983 eassert ((BUFFERP (it
->object
)
5984 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5985 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5986 || (STRINGP (it
->object
)
5987 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5988 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5989 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5995 /***********************************************************************
5997 ***********************************************************************/
5999 /* Set IT's current position to the previous line start. */
6002 back_to_previous_line_start (struct it
*it
)
6004 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6007 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6011 /* Move IT to the next line start.
6013 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6014 we skipped over part of the text (as opposed to moving the iterator
6015 continuously over the text). Otherwise, don't change the value
6018 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6019 iterator on the newline, if it was found.
6021 Newlines may come from buffer text, overlay strings, or strings
6022 displayed via the `display' property. That's the reason we can't
6023 simply use find_newline_no_quit.
6025 Note that this function may not skip over invisible text that is so
6026 because of text properties and immediately follows a newline. If
6027 it would, function reseat_at_next_visible_line_start, when called
6028 from set_iterator_to_next, would effectively make invisible
6029 characters following a newline part of the wrong glyph row, which
6030 leads to wrong cursor motion. */
6033 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6034 struct bidi_it
*bidi_it_prev
)
6036 ptrdiff_t old_selective
;
6037 int newline_found_p
, n
;
6038 const int MAX_NEWLINE_DISTANCE
= 500;
6040 /* If already on a newline, just consume it to avoid unintended
6041 skipping over invisible text below. */
6042 if (it
->what
== IT_CHARACTER
6044 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6046 if (it
->bidi_p
&& bidi_it_prev
)
6047 *bidi_it_prev
= it
->bidi_it
;
6048 set_iterator_to_next (it
, 0);
6053 /* Don't handle selective display in the following. It's (a)
6054 unnecessary because it's done by the caller, and (b) leads to an
6055 infinite recursion because next_element_from_ellipsis indirectly
6056 calls this function. */
6057 old_selective
= it
->selective
;
6060 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6061 from buffer text. */
6062 for (n
= newline_found_p
= 0;
6063 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6064 n
+= STRINGP (it
->string
) ? 0 : 1)
6066 if (!get_next_display_element (it
))
6068 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6069 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6070 *bidi_it_prev
= it
->bidi_it
;
6071 set_iterator_to_next (it
, 0);
6074 /* If we didn't find a newline near enough, see if we can use a
6076 if (!newline_found_p
)
6078 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6079 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6083 eassert (!STRINGP (it
->string
));
6085 /* If there isn't any `display' property in sight, and no
6086 overlays, we can just use the position of the newline in
6088 if (it
->stop_charpos
>= limit
6089 || ((pos
= Fnext_single_property_change (make_number (start
),
6091 make_number (limit
)),
6093 && next_overlay_change (start
) == ZV
))
6097 IT_CHARPOS (*it
) = limit
;
6098 IT_BYTEPOS (*it
) = bytepos
;
6102 struct bidi_it bprev
;
6104 /* Help bidi.c avoid expensive searches for display
6105 properties and overlays, by telling it that there are
6106 none up to `limit'. */
6107 if (it
->bidi_it
.disp_pos
< limit
)
6109 it
->bidi_it
.disp_pos
= limit
;
6110 it
->bidi_it
.disp_prop
= 0;
6113 bprev
= it
->bidi_it
;
6114 bidi_move_to_visually_next (&it
->bidi_it
);
6115 } while (it
->bidi_it
.charpos
!= limit
);
6116 IT_CHARPOS (*it
) = limit
;
6117 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6119 *bidi_it_prev
= bprev
;
6121 *skipped_p
= newline_found_p
= true;
6125 while (get_next_display_element (it
)
6126 && !newline_found_p
)
6128 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6129 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6130 *bidi_it_prev
= it
->bidi_it
;
6131 set_iterator_to_next (it
, 0);
6136 it
->selective
= old_selective
;
6137 return newline_found_p
;
6141 /* Set IT's current position to the previous visible line start. Skip
6142 invisible text that is so either due to text properties or due to
6143 selective display. Caution: this does not change IT->current_x and
6147 back_to_previous_visible_line_start (struct it
*it
)
6149 while (IT_CHARPOS (*it
) > BEGV
)
6151 back_to_previous_line_start (it
);
6153 if (IT_CHARPOS (*it
) <= BEGV
)
6156 /* If selective > 0, then lines indented more than its value are
6158 if (it
->selective
> 0
6159 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6163 /* Check the newline before point for invisibility. */
6166 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6167 Qinvisible
, it
->window
);
6168 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6172 if (IT_CHARPOS (*it
) <= BEGV
)
6177 void *it2data
= NULL
;
6180 Lisp_Object val
, overlay
;
6182 SAVE_IT (it2
, *it
, it2data
);
6184 /* If newline is part of a composition, continue from start of composition */
6185 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6186 && beg
< IT_CHARPOS (*it
))
6189 /* If newline is replaced by a display property, find start of overlay
6190 or interval and continue search from that point. */
6191 pos
= --IT_CHARPOS (it2
);
6194 bidi_unshelve_cache (NULL
, 0);
6195 it2
.string_from_display_prop_p
= 0;
6196 it2
.from_disp_prop_p
= 0;
6197 if (handle_display_prop (&it2
) == HANDLED_RETURN
6198 && !NILP (val
= get_char_property_and_overlay
6199 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6200 && (OVERLAYP (overlay
)
6201 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6202 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6204 RESTORE_IT (it
, it
, it2data
);
6208 /* Newline is not replaced by anything -- so we are done. */
6209 RESTORE_IT (it
, it
, it2data
);
6215 IT_CHARPOS (*it
) = beg
;
6216 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6220 it
->continuation_lines_width
= 0;
6222 eassert (IT_CHARPOS (*it
) >= BEGV
);
6223 eassert (IT_CHARPOS (*it
) == BEGV
6224 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6229 /* Reseat iterator IT at the previous visible line start. Skip
6230 invisible text that is so either due to text properties or due to
6231 selective display. At the end, update IT's overlay information,
6232 face information etc. */
6235 reseat_at_previous_visible_line_start (struct it
*it
)
6237 back_to_previous_visible_line_start (it
);
6238 reseat (it
, it
->current
.pos
, 1);
6243 /* Reseat iterator IT on the next visible line start in the current
6244 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6245 preceding the line start. Skip over invisible text that is so
6246 because of selective display. Compute faces, overlays etc at the
6247 new position. Note that this function does not skip over text that
6248 is invisible because of text properties. */
6251 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6253 int newline_found_p
, skipped_p
= 0;
6254 struct bidi_it bidi_it_prev
;
6256 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6258 /* Skip over lines that are invisible because they are indented
6259 more than the value of IT->selective. */
6260 if (it
->selective
> 0)
6261 while (IT_CHARPOS (*it
) < ZV
6262 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6265 eassert (IT_BYTEPOS (*it
) == BEGV
6266 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6268 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6271 /* Position on the newline if that's what's requested. */
6272 if (on_newline_p
&& newline_found_p
)
6274 if (STRINGP (it
->string
))
6276 if (IT_STRING_CHARPOS (*it
) > 0)
6280 --IT_STRING_CHARPOS (*it
);
6281 --IT_STRING_BYTEPOS (*it
);
6285 /* We need to restore the bidi iterator to the state
6286 it had on the newline, and resync the IT's
6287 position with that. */
6288 it
->bidi_it
= bidi_it_prev
;
6289 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6290 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6294 else if (IT_CHARPOS (*it
) > BEGV
)
6303 /* We need to restore the bidi iterator to the state it
6304 had on the newline and resync IT with that. */
6305 it
->bidi_it
= bidi_it_prev
;
6306 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6307 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6309 reseat (it
, it
->current
.pos
, 0);
6313 reseat (it
, it
->current
.pos
, 0);
6320 /***********************************************************************
6321 Changing an iterator's position
6322 ***********************************************************************/
6324 /* Change IT's current position to POS in current_buffer. If FORCE_P
6325 is non-zero, always check for text properties at the new position.
6326 Otherwise, text properties are only looked up if POS >=
6327 IT->check_charpos of a property. */
6330 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6332 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6334 reseat_1 (it
, pos
, 0);
6336 /* Determine where to check text properties. Avoid doing it
6337 where possible because text property lookup is very expensive. */
6339 || CHARPOS (pos
) > it
->stop_charpos
6340 || CHARPOS (pos
) < original_pos
)
6344 /* For bidi iteration, we need to prime prev_stop and
6345 base_level_stop with our best estimations. */
6346 /* Implementation note: Of course, POS is not necessarily a
6347 stop position, so assigning prev_pos to it is a lie; we
6348 should have called compute_stop_backwards. However, if
6349 the current buffer does not include any R2L characters,
6350 that call would be a waste of cycles, because the
6351 iterator will never move back, and thus never cross this
6352 "fake" stop position. So we delay that backward search
6353 until the time we really need it, in next_element_from_buffer. */
6354 if (CHARPOS (pos
) != it
->prev_stop
)
6355 it
->prev_stop
= CHARPOS (pos
);
6356 if (CHARPOS (pos
) < it
->base_level_stop
)
6357 it
->base_level_stop
= 0; /* meaning it's unknown */
6363 it
->prev_stop
= it
->base_level_stop
= 0;
6372 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6373 IT->stop_pos to POS, also. */
6376 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6378 /* Don't call this function when scanning a C string. */
6379 eassert (it
->s
== NULL
);
6381 /* POS must be a reasonable value. */
6382 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6384 it
->current
.pos
= it
->position
= pos
;
6385 it
->end_charpos
= ZV
;
6387 it
->current
.dpvec_index
= -1;
6388 it
->current
.overlay_string_index
= -1;
6389 IT_STRING_CHARPOS (*it
) = -1;
6390 IT_STRING_BYTEPOS (*it
) = -1;
6392 it
->method
= GET_FROM_BUFFER
;
6393 it
->object
= it
->w
->contents
;
6394 it
->area
= TEXT_AREA
;
6395 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6397 it
->string_from_display_prop_p
= 0;
6398 it
->string_from_prefix_prop_p
= 0;
6400 it
->from_disp_prop_p
= 0;
6401 it
->face_before_selective_p
= 0;
6404 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6406 bidi_unshelve_cache (NULL
, 0);
6407 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6408 it
->bidi_it
.string
.s
= NULL
;
6409 it
->bidi_it
.string
.lstring
= Qnil
;
6410 it
->bidi_it
.string
.bufpos
= 0;
6411 it
->bidi_it
.string
.unibyte
= 0;
6412 it
->bidi_it
.w
= it
->w
;
6417 it
->stop_charpos
= CHARPOS (pos
);
6418 it
->base_level_stop
= CHARPOS (pos
);
6420 /* This make the information stored in it->cmp_it invalidate. */
6425 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6426 If S is non-null, it is a C string to iterate over. Otherwise,
6427 STRING gives a Lisp string to iterate over.
6429 If PRECISION > 0, don't return more then PRECISION number of
6430 characters from the string.
6432 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6433 characters have been returned. FIELD_WIDTH < 0 means an infinite
6436 MULTIBYTE = 0 means disable processing of multibyte characters,
6437 MULTIBYTE > 0 means enable it,
6438 MULTIBYTE < 0 means use IT->multibyte_p.
6440 IT must be initialized via a prior call to init_iterator before
6441 calling this function. */
6444 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6445 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6448 /* No text property checks performed by default, but see below. */
6449 it
->stop_charpos
= -1;
6451 /* Set iterator position and end position. */
6452 memset (&it
->current
, 0, sizeof it
->current
);
6453 it
->current
.overlay_string_index
= -1;
6454 it
->current
.dpvec_index
= -1;
6455 eassert (charpos
>= 0);
6457 /* If STRING is specified, use its multibyteness, otherwise use the
6458 setting of MULTIBYTE, if specified. */
6460 it
->multibyte_p
= multibyte
> 0;
6462 /* Bidirectional reordering of strings is controlled by the default
6463 value of bidi-display-reordering. Don't try to reorder while
6464 loading loadup.el, as the necessary character property tables are
6465 not yet available. */
6468 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6472 eassert (STRINGP (string
));
6473 it
->string
= string
;
6475 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6476 it
->method
= GET_FROM_STRING
;
6477 it
->current
.string_pos
= string_pos (charpos
, string
);
6481 it
->bidi_it
.string
.lstring
= string
;
6482 it
->bidi_it
.string
.s
= NULL
;
6483 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6484 it
->bidi_it
.string
.bufpos
= 0;
6485 it
->bidi_it
.string
.from_disp_str
= 0;
6486 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6487 it
->bidi_it
.w
= it
->w
;
6488 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6489 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6494 it
->s
= (const unsigned char *) s
;
6497 /* Note that we use IT->current.pos, not it->current.string_pos,
6498 for displaying C strings. */
6499 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6500 if (it
->multibyte_p
)
6502 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6503 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6507 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6508 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6513 it
->bidi_it
.string
.lstring
= Qnil
;
6514 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6515 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6516 it
->bidi_it
.string
.bufpos
= 0;
6517 it
->bidi_it
.string
.from_disp_str
= 0;
6518 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6519 it
->bidi_it
.w
= it
->w
;
6520 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6523 it
->method
= GET_FROM_C_STRING
;
6526 /* PRECISION > 0 means don't return more than PRECISION characters
6528 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6530 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6532 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6535 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6536 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6537 FIELD_WIDTH < 0 means infinite field width. This is useful for
6538 padding with `-' at the end of a mode line. */
6539 if (field_width
< 0)
6540 field_width
= INFINITY
;
6541 /* Implementation note: We deliberately don't enlarge
6542 it->bidi_it.string.schars here to fit it->end_charpos, because
6543 the bidi iterator cannot produce characters out of thin air. */
6544 if (field_width
> it
->end_charpos
- charpos
)
6545 it
->end_charpos
= charpos
+ field_width
;
6547 /* Use the standard display table for displaying strings. */
6548 if (DISP_TABLE_P (Vstandard_display_table
))
6549 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6551 it
->stop_charpos
= charpos
;
6552 it
->prev_stop
= charpos
;
6553 it
->base_level_stop
= 0;
6556 it
->bidi_it
.first_elt
= 1;
6557 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6558 it
->bidi_it
.disp_pos
= -1;
6560 if (s
== NULL
&& it
->multibyte_p
)
6562 ptrdiff_t endpos
= SCHARS (it
->string
);
6563 if (endpos
> it
->end_charpos
)
6564 endpos
= it
->end_charpos
;
6565 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6573 /***********************************************************************
6575 ***********************************************************************/
6577 /* Map enum it_method value to corresponding next_element_from_* function. */
6579 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6581 next_element_from_buffer
,
6582 next_element_from_display_vector
,
6583 next_element_from_string
,
6584 next_element_from_c_string
,
6585 next_element_from_image
,
6586 next_element_from_stretch
6589 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6592 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6593 (possibly with the following characters). */
6595 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6596 ((IT)->cmp_it.id >= 0 \
6597 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6598 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6599 END_CHARPOS, (IT)->w, \
6600 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6604 /* Lookup the char-table Vglyphless_char_display for character C (-1
6605 if we want information for no-font case), and return the display
6606 method symbol. By side-effect, update it->what and
6607 it->glyphless_method. This function is called from
6608 get_next_display_element for each character element, and from
6609 x_produce_glyphs when no suitable font was found. */
6612 lookup_glyphless_char_display (int c
, struct it
*it
)
6614 Lisp_Object glyphless_method
= Qnil
;
6616 if (CHAR_TABLE_P (Vglyphless_char_display
)
6617 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6621 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6622 if (CONSP (glyphless_method
))
6623 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6624 ? XCAR (glyphless_method
)
6625 : XCDR (glyphless_method
);
6628 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6632 if (NILP (glyphless_method
))
6635 /* The default is to display the character by a proper font. */
6637 /* The default for the no-font case is to display an empty box. */
6638 glyphless_method
= Qempty_box
;
6640 if (EQ (glyphless_method
, Qzero_width
))
6643 return glyphless_method
;
6644 /* This method can't be used for the no-font case. */
6645 glyphless_method
= Qempty_box
;
6647 if (EQ (glyphless_method
, Qthin_space
))
6648 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6649 else if (EQ (glyphless_method
, Qempty_box
))
6650 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6651 else if (EQ (glyphless_method
, Qhex_code
))
6652 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6653 else if (STRINGP (glyphless_method
))
6654 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6657 /* Invalid value. We use the default method. */
6658 glyphless_method
= Qnil
;
6661 it
->what
= IT_GLYPHLESS
;
6662 return glyphless_method
;
6665 /* Merge escape glyph face and cache the result. */
6667 static struct frame
*last_escape_glyph_frame
= NULL
;
6668 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6669 static int last_escape_glyph_merged_face_id
= 0;
6672 merge_escape_glyph_face (struct it
*it
)
6676 if (it
->f
== last_escape_glyph_frame
6677 && it
->face_id
== last_escape_glyph_face_id
)
6678 face_id
= last_escape_glyph_merged_face_id
;
6681 /* Merge the `escape-glyph' face into the current face. */
6682 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6683 last_escape_glyph_frame
= it
->f
;
6684 last_escape_glyph_face_id
= it
->face_id
;
6685 last_escape_glyph_merged_face_id
= face_id
;
6690 /* Likewise for glyphless glyph face. */
6692 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6693 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6694 static int last_glyphless_glyph_merged_face_id
= 0;
6697 merge_glyphless_glyph_face (struct it
*it
)
6701 if (it
->f
== last_glyphless_glyph_frame
6702 && it
->face_id
== last_glyphless_glyph_face_id
)
6703 face_id
= last_glyphless_glyph_merged_face_id
;
6706 /* Merge the `glyphless-char' face into the current face. */
6707 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6708 last_glyphless_glyph_frame
= it
->f
;
6709 last_glyphless_glyph_face_id
= it
->face_id
;
6710 last_glyphless_glyph_merged_face_id
= face_id
;
6715 /* Load IT's display element fields with information about the next
6716 display element from the current position of IT. Value is zero if
6717 end of buffer (or C string) is reached. */
6720 get_next_display_element (struct it
*it
)
6722 /* Non-zero means that we found a display element. Zero means that
6723 we hit the end of what we iterate over. Performance note: the
6724 function pointer `method' used here turns out to be faster than
6725 using a sequence of if-statements. */
6729 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6731 if (it
->what
== IT_CHARACTER
)
6733 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6734 and only if (a) the resolved directionality of that character
6736 /* FIXME: Do we need an exception for characters from display
6738 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6739 it
->c
= bidi_mirror_char (it
->c
);
6740 /* Map via display table or translate control characters.
6741 IT->c, IT->len etc. have been set to the next character by
6742 the function call above. If we have a display table, and it
6743 contains an entry for IT->c, translate it. Don't do this if
6744 IT->c itself comes from a display table, otherwise we could
6745 end up in an infinite recursion. (An alternative could be to
6746 count the recursion depth of this function and signal an
6747 error when a certain maximum depth is reached.) Is it worth
6749 if (success_p
&& it
->dpvec
== NULL
)
6752 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6753 int nonascii_space_p
= 0;
6754 int nonascii_hyphen_p
= 0;
6755 int c
= it
->c
; /* This is the character to display. */
6757 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6759 eassert (SINGLE_BYTE_CHAR_P (c
));
6760 if (unibyte_display_via_language_environment
)
6762 c
= DECODE_CHAR (unibyte
, c
);
6764 c
= BYTE8_TO_CHAR (it
->c
);
6767 c
= BYTE8_TO_CHAR (it
->c
);
6771 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6774 struct Lisp_Vector
*v
= XVECTOR (dv
);
6776 /* Return the first character from the display table
6777 entry, if not empty. If empty, don't display the
6778 current character. */
6781 it
->dpvec_char_len
= it
->len
;
6782 it
->dpvec
= v
->contents
;
6783 it
->dpend
= v
->contents
+ v
->header
.size
;
6784 it
->current
.dpvec_index
= 0;
6785 it
->dpvec_face_id
= -1;
6786 it
->saved_face_id
= it
->face_id
;
6787 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6792 set_iterator_to_next (it
, 0);
6797 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6799 if (it
->what
== IT_GLYPHLESS
)
6801 /* Don't display this character. */
6802 set_iterator_to_next (it
, 0);
6806 /* If `nobreak-char-display' is non-nil, we display
6807 non-ASCII spaces and hyphens specially. */
6808 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6811 nonascii_space_p
= true;
6812 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6813 nonascii_hyphen_p
= true;
6816 /* Translate control characters into `\003' or `^C' form.
6817 Control characters coming from a display table entry are
6818 currently not translated because we use IT->dpvec to hold
6819 the translation. This could easily be changed but I
6820 don't believe that it is worth doing.
6822 The characters handled by `nobreak-char-display' must be
6825 Non-printable characters and raw-byte characters are also
6826 translated to octal form. */
6827 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6828 ? (it
->area
!= TEXT_AREA
6829 /* In mode line, treat \n, \t like other crl chars. */
6832 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6833 || (c
!= '\n' && c
!= '\t'))
6835 || nonascii_hyphen_p
6837 || ! CHAR_PRINTABLE_P (c
))))
6839 /* C is a control character, non-ASCII space/hyphen,
6840 raw-byte, or a non-printable character which must be
6841 displayed either as '\003' or as `^C' where the '\\'
6842 and '^' can be defined in the display table. Fill
6843 IT->ctl_chars with glyphs for what we have to
6844 display. Then, set IT->dpvec to these glyphs. */
6851 /* Handle control characters with ^. */
6853 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6857 g
= '^'; /* default glyph for Control */
6858 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6860 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6862 g
= GLYPH_CODE_CHAR (gc
);
6863 lface_id
= GLYPH_CODE_FACE (gc
);
6867 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6868 : merge_escape_glyph_face (it
));
6870 XSETINT (it
->ctl_chars
[0], g
);
6871 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6873 goto display_control
;
6876 /* Handle non-ascii space in the mode where it only gets
6879 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6881 /* Merge `nobreak-space' into the current face. */
6882 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6884 XSETINT (it
->ctl_chars
[0], ' ');
6886 goto display_control
;
6889 /* Handle sequences that start with the "escape glyph". */
6891 /* the default escape glyph is \. */
6892 escape_glyph
= '\\';
6895 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6897 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6898 lface_id
= GLYPH_CODE_FACE (gc
);
6902 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6903 : merge_escape_glyph_face (it
));
6905 /* Draw non-ASCII hyphen with just highlighting: */
6907 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6909 XSETINT (it
->ctl_chars
[0], '-');
6911 goto display_control
;
6914 /* Draw non-ASCII space/hyphen with escape glyph: */
6916 if (nonascii_space_p
|| nonascii_hyphen_p
)
6918 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6919 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6921 goto display_control
;
6928 if (CHAR_BYTE8_P (c
))
6929 /* Display \200 instead of \17777600. */
6930 c
= CHAR_TO_BYTE8 (c
);
6931 len
= sprintf (str
, "%03o", c
);
6933 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6934 for (i
= 0; i
< len
; i
++)
6935 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6940 /* Set up IT->dpvec and return first character from it. */
6941 it
->dpvec_char_len
= it
->len
;
6942 it
->dpvec
= it
->ctl_chars
;
6943 it
->dpend
= it
->dpvec
+ ctl_len
;
6944 it
->current
.dpvec_index
= 0;
6945 it
->dpvec_face_id
= face_id
;
6946 it
->saved_face_id
= it
->face_id
;
6947 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6951 it
->char_to_display
= c
;
6955 it
->char_to_display
= it
->c
;
6959 #ifdef HAVE_WINDOW_SYSTEM
6960 /* Adjust face id for a multibyte character. There are no multibyte
6961 character in unibyte text. */
6962 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6965 && FRAME_WINDOW_P (it
->f
))
6967 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6969 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6971 /* Automatic composition with glyph-string. */
6972 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6974 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6978 ptrdiff_t pos
= (it
->s
? -1
6979 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6980 : IT_CHARPOS (*it
));
6983 if (it
->what
== IT_CHARACTER
)
6984 c
= it
->char_to_display
;
6987 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6991 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6992 /* TAB in a composition means display glyphs with
6993 padding space on the left or right. */
6994 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6997 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7000 #endif /* HAVE_WINDOW_SYSTEM */
7003 /* Is this character the last one of a run of characters with
7004 box? If yes, set IT->end_of_box_run_p to 1. */
7008 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7010 int face_id
= underlying_face_id (it
);
7011 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7015 if (face
->box
== FACE_NO_BOX
)
7017 /* If the box comes from face properties in a
7018 display string, check faces in that string. */
7019 int string_face_id
= face_after_it_pos (it
);
7020 it
->end_of_box_run_p
7021 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7024 /* Otherwise, the box comes from the underlying face.
7025 If this is the last string character displayed, check
7026 the next buffer location. */
7027 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7028 && (it
->current
.overlay_string_index
7029 == it
->n_overlay_strings
- 1))
7033 struct text_pos pos
= it
->current
.pos
;
7034 INC_TEXT_POS (pos
, it
->multibyte_p
);
7036 next_face_id
= face_at_buffer_position
7037 (it
->w
, CHARPOS (pos
), &ignore
,
7038 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7040 it
->end_of_box_run_p
7041 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7046 /* next_element_from_display_vector sets this flag according to
7047 faces of the display vector glyphs, see there. */
7048 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7050 int face_id
= face_after_it_pos (it
);
7051 it
->end_of_box_run_p
7052 = (face_id
!= it
->face_id
7053 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7056 /* If we reached the end of the object we've been iterating (e.g., a
7057 display string or an overlay string), and there's something on
7058 IT->stack, proceed with what's on the stack. It doesn't make
7059 sense to return zero if there's unprocessed stuff on the stack,
7060 because otherwise that stuff will never be displayed. */
7061 if (!success_p
&& it
->sp
> 0)
7063 set_iterator_to_next (it
, 0);
7064 success_p
= get_next_display_element (it
);
7067 /* Value is 0 if end of buffer or string reached. */
7072 /* Move IT to the next display element.
7074 RESEAT_P non-zero means if called on a newline in buffer text,
7075 skip to the next visible line start.
7077 Functions get_next_display_element and set_iterator_to_next are
7078 separate because I find this arrangement easier to handle than a
7079 get_next_display_element function that also increments IT's
7080 position. The way it is we can first look at an iterator's current
7081 display element, decide whether it fits on a line, and if it does,
7082 increment the iterator position. The other way around we probably
7083 would either need a flag indicating whether the iterator has to be
7084 incremented the next time, or we would have to implement a
7085 decrement position function which would not be easy to write. */
7088 set_iterator_to_next (struct it
*it
, int reseat_p
)
7090 /* Reset flags indicating start and end of a sequence of characters
7091 with box. Reset them at the start of this function because
7092 moving the iterator to a new position might set them. */
7093 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7097 case GET_FROM_BUFFER
:
7098 /* The current display element of IT is a character from
7099 current_buffer. Advance in the buffer, and maybe skip over
7100 invisible lines that are so because of selective display. */
7101 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7102 reseat_at_next_visible_line_start (it
, 0);
7103 else if (it
->cmp_it
.id
>= 0)
7105 /* We are currently getting glyphs from a composition. */
7110 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7111 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7112 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7114 it
->cmp_it
.from
= it
->cmp_it
.to
;
7119 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7121 it
->end_charpos
, Qnil
);
7124 else if (! it
->cmp_it
.reversed_p
)
7126 /* Composition created while scanning forward. */
7127 /* Update IT's char/byte positions to point to the first
7128 character of the next grapheme cluster, or to the
7129 character visually after the current composition. */
7130 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7131 bidi_move_to_visually_next (&it
->bidi_it
);
7132 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7133 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7135 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7137 /* Proceed to the next grapheme cluster. */
7138 it
->cmp_it
.from
= it
->cmp_it
.to
;
7142 /* No more grapheme clusters in this composition.
7143 Find the next stop position. */
7144 ptrdiff_t stop
= it
->end_charpos
;
7145 if (it
->bidi_it
.scan_dir
< 0)
7146 /* Now we are scanning backward and don't know
7149 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7150 IT_BYTEPOS (*it
), stop
, Qnil
);
7155 /* Composition created while scanning backward. */
7156 /* Update IT's char/byte positions to point to the last
7157 character of the previous grapheme cluster, or the
7158 character visually after the current composition. */
7159 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7160 bidi_move_to_visually_next (&it
->bidi_it
);
7161 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7162 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7163 if (it
->cmp_it
.from
> 0)
7165 /* Proceed to the previous grapheme cluster. */
7166 it
->cmp_it
.to
= it
->cmp_it
.from
;
7170 /* No more grapheme clusters in this composition.
7171 Find the next stop position. */
7172 ptrdiff_t stop
= it
->end_charpos
;
7173 if (it
->bidi_it
.scan_dir
< 0)
7174 /* Now we are scanning backward and don't know
7177 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7178 IT_BYTEPOS (*it
), stop
, Qnil
);
7184 eassert (it
->len
!= 0);
7188 IT_BYTEPOS (*it
) += it
->len
;
7189 IT_CHARPOS (*it
) += 1;
7193 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7194 /* If this is a new paragraph, determine its base
7195 direction (a.k.a. its base embedding level). */
7196 if (it
->bidi_it
.new_paragraph
)
7197 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7198 bidi_move_to_visually_next (&it
->bidi_it
);
7199 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7200 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7201 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7203 /* As the scan direction was changed, we must
7204 re-compute the stop position for composition. */
7205 ptrdiff_t stop
= it
->end_charpos
;
7206 if (it
->bidi_it
.scan_dir
< 0)
7208 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7209 IT_BYTEPOS (*it
), stop
, Qnil
);
7212 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7216 case GET_FROM_C_STRING
:
7217 /* Current display element of IT is from a C string. */
7219 /* If the string position is beyond string's end, it means
7220 next_element_from_c_string is padding the string with
7221 blanks, in which case we bypass the bidi iterator,
7222 because it cannot deal with such virtual characters. */
7223 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7225 IT_BYTEPOS (*it
) += it
->len
;
7226 IT_CHARPOS (*it
) += 1;
7230 bidi_move_to_visually_next (&it
->bidi_it
);
7231 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7232 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7236 case GET_FROM_DISPLAY_VECTOR
:
7237 /* Current display element of IT is from a display table entry.
7238 Advance in the display table definition. Reset it to null if
7239 end reached, and continue with characters from buffers/
7241 ++it
->current
.dpvec_index
;
7243 /* Restore face of the iterator to what they were before the
7244 display vector entry (these entries may contain faces). */
7245 it
->face_id
= it
->saved_face_id
;
7247 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7249 int recheck_faces
= it
->ellipsis_p
;
7252 it
->method
= GET_FROM_C_STRING
;
7253 else if (STRINGP (it
->string
))
7254 it
->method
= GET_FROM_STRING
;
7257 it
->method
= GET_FROM_BUFFER
;
7258 it
->object
= it
->w
->contents
;
7262 it
->current
.dpvec_index
= -1;
7264 /* Skip over characters which were displayed via IT->dpvec. */
7265 if (it
->dpvec_char_len
< 0)
7266 reseat_at_next_visible_line_start (it
, 1);
7267 else if (it
->dpvec_char_len
> 0)
7269 if (it
->method
== GET_FROM_STRING
7270 && it
->current
.overlay_string_index
>= 0
7271 && it
->n_overlay_strings
> 0)
7272 it
->ignore_overlay_strings_at_pos_p
= true;
7273 it
->len
= it
->dpvec_char_len
;
7274 set_iterator_to_next (it
, reseat_p
);
7277 /* Maybe recheck faces after display vector. */
7279 it
->stop_charpos
= IT_CHARPOS (*it
);
7283 case GET_FROM_STRING
:
7284 /* Current display element is a character from a Lisp string. */
7285 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7286 /* Don't advance past string end. These conditions are true
7287 when set_iterator_to_next is called at the end of
7288 get_next_display_element, in which case the Lisp string is
7289 already exhausted, and all we want is pop the iterator
7291 if (it
->current
.overlay_string_index
>= 0)
7293 /* This is an overlay string, so there's no padding with
7294 spaces, and the number of characters in the string is
7295 where the string ends. */
7296 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7297 goto consider_string_end
;
7301 /* Not an overlay string. There could be padding, so test
7302 against it->end_charpos. */
7303 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7304 goto consider_string_end
;
7306 if (it
->cmp_it
.id
>= 0)
7312 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7313 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7314 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7315 it
->cmp_it
.from
= it
->cmp_it
.to
;
7319 composition_compute_stop_pos (&it
->cmp_it
,
7320 IT_STRING_CHARPOS (*it
),
7321 IT_STRING_BYTEPOS (*it
),
7322 it
->end_charpos
, it
->string
);
7325 else if (! it
->cmp_it
.reversed_p
)
7327 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7328 bidi_move_to_visually_next (&it
->bidi_it
);
7329 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7330 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7332 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7333 it
->cmp_it
.from
= it
->cmp_it
.to
;
7336 ptrdiff_t stop
= it
->end_charpos
;
7337 if (it
->bidi_it
.scan_dir
< 0)
7339 composition_compute_stop_pos (&it
->cmp_it
,
7340 IT_STRING_CHARPOS (*it
),
7341 IT_STRING_BYTEPOS (*it
), stop
,
7347 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7348 bidi_move_to_visually_next (&it
->bidi_it
);
7349 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7350 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7351 if (it
->cmp_it
.from
> 0)
7352 it
->cmp_it
.to
= it
->cmp_it
.from
;
7355 ptrdiff_t stop
= it
->end_charpos
;
7356 if (it
->bidi_it
.scan_dir
< 0)
7358 composition_compute_stop_pos (&it
->cmp_it
,
7359 IT_STRING_CHARPOS (*it
),
7360 IT_STRING_BYTEPOS (*it
), stop
,
7368 /* If the string position is beyond string's end, it
7369 means next_element_from_string is padding the string
7370 with blanks, in which case we bypass the bidi
7371 iterator, because it cannot deal with such virtual
7373 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7375 IT_STRING_BYTEPOS (*it
) += it
->len
;
7376 IT_STRING_CHARPOS (*it
) += 1;
7380 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7382 bidi_move_to_visually_next (&it
->bidi_it
);
7383 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7384 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7385 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7387 ptrdiff_t stop
= it
->end_charpos
;
7389 if (it
->bidi_it
.scan_dir
< 0)
7391 composition_compute_stop_pos (&it
->cmp_it
,
7392 IT_STRING_CHARPOS (*it
),
7393 IT_STRING_BYTEPOS (*it
), stop
,
7399 consider_string_end
:
7401 if (it
->current
.overlay_string_index
>= 0)
7403 /* IT->string is an overlay string. Advance to the
7404 next, if there is one. */
7405 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7408 next_overlay_string (it
);
7410 setup_for_ellipsis (it
, 0);
7415 /* IT->string is not an overlay string. If we reached
7416 its end, and there is something on IT->stack, proceed
7417 with what is on the stack. This can be either another
7418 string, this time an overlay string, or a buffer. */
7419 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7423 if (it
->method
== GET_FROM_STRING
)
7424 goto consider_string_end
;
7429 case GET_FROM_IMAGE
:
7430 case GET_FROM_STRETCH
:
7431 /* The position etc with which we have to proceed are on
7432 the stack. The position may be at the end of a string,
7433 if the `display' property takes up the whole string. */
7434 eassert (it
->sp
> 0);
7436 if (it
->method
== GET_FROM_STRING
)
7437 goto consider_string_end
;
7441 /* There are no other methods defined, so this should be a bug. */
7445 eassert (it
->method
!= GET_FROM_STRING
7446 || (STRINGP (it
->string
)
7447 && IT_STRING_CHARPOS (*it
) >= 0));
7450 /* Load IT's display element fields with information about the next
7451 display element which comes from a display table entry or from the
7452 result of translating a control character to one of the forms `^C'
7455 IT->dpvec holds the glyphs to return as characters.
7456 IT->saved_face_id holds the face id before the display vector--it
7457 is restored into IT->face_id in set_iterator_to_next. */
7460 next_element_from_display_vector (struct it
*it
)
7463 int prev_face_id
= it
->face_id
;
7467 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7469 it
->face_id
= it
->saved_face_id
;
7471 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7472 That seemed totally bogus - so I changed it... */
7473 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7475 if (GLYPH_CODE_P (gc
))
7477 struct face
*this_face
, *prev_face
, *next_face
;
7479 it
->c
= GLYPH_CODE_CHAR (gc
);
7480 it
->len
= CHAR_BYTES (it
->c
);
7482 /* The entry may contain a face id to use. Such a face id is
7483 the id of a Lisp face, not a realized face. A face id of
7484 zero means no face is specified. */
7485 if (it
->dpvec_face_id
>= 0)
7486 it
->face_id
= it
->dpvec_face_id
;
7489 int lface_id
= GLYPH_CODE_FACE (gc
);
7491 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7495 /* Glyphs in the display vector could have the box face, so we
7496 need to set the related flags in the iterator, as
7498 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7499 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7501 /* Is this character the first character of a box-face run? */
7502 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7504 || prev_face
->box
== FACE_NO_BOX
));
7506 /* For the last character of the box-face run, we need to look
7507 either at the next glyph from the display vector, or at the
7508 face we saw before the display vector. */
7509 next_face_id
= it
->saved_face_id
;
7510 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7512 if (it
->dpvec_face_id
>= 0)
7513 next_face_id
= it
->dpvec_face_id
;
7517 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7520 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7524 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7525 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7527 || next_face
->box
== FACE_NO_BOX
));
7528 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7531 /* Display table entry is invalid. Return a space. */
7532 it
->c
= ' ', it
->len
= 1;
7534 /* Don't change position and object of the iterator here. They are
7535 still the values of the character that had this display table
7536 entry or was translated, and that's what we want. */
7537 it
->what
= IT_CHARACTER
;
7541 /* Get the first element of string/buffer in the visual order, after
7542 being reseated to a new position in a string or a buffer. */
7544 get_visually_first_element (struct it
*it
)
7546 int string_p
= STRINGP (it
->string
) || it
->s
;
7547 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7548 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7550 if (STRINGP (it
->string
))
7552 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7553 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7557 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7558 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7561 if (it
->bidi_it
.charpos
== eob
)
7563 /* Nothing to do, but reset the FIRST_ELT flag, like
7564 bidi_paragraph_init does, because we are not going to
7566 it
->bidi_it
.first_elt
= 0;
7568 else if (it
->bidi_it
.charpos
== bob
7570 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7571 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7573 /* If we are at the beginning of a line/string, we can produce
7574 the next element right away. */
7575 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7576 bidi_move_to_visually_next (&it
->bidi_it
);
7580 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7582 /* We need to prime the bidi iterator starting at the line's or
7583 string's beginning, before we will be able to produce the
7586 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7588 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7589 IT_BYTEPOS (*it
), -1,
7590 &it
->bidi_it
.bytepos
);
7591 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7594 /* Now return to buffer/string position where we were asked
7595 to get the next display element, and produce that. */
7596 bidi_move_to_visually_next (&it
->bidi_it
);
7598 while (it
->bidi_it
.bytepos
!= orig_bytepos
7599 && it
->bidi_it
.charpos
< eob
);
7602 /* Adjust IT's position information to where we ended up. */
7603 if (STRINGP (it
->string
))
7605 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7606 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7610 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7611 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7614 if (STRINGP (it
->string
) || !it
->s
)
7616 ptrdiff_t stop
, charpos
, bytepos
;
7618 if (STRINGP (it
->string
))
7621 stop
= SCHARS (it
->string
);
7622 if (stop
> it
->end_charpos
)
7623 stop
= it
->end_charpos
;
7624 charpos
= IT_STRING_CHARPOS (*it
);
7625 bytepos
= IT_STRING_BYTEPOS (*it
);
7629 stop
= it
->end_charpos
;
7630 charpos
= IT_CHARPOS (*it
);
7631 bytepos
= IT_BYTEPOS (*it
);
7633 if (it
->bidi_it
.scan_dir
< 0)
7635 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7640 /* Load IT with the next display element from Lisp string IT->string.
7641 IT->current.string_pos is the current position within the string.
7642 If IT->current.overlay_string_index >= 0, the Lisp string is an
7646 next_element_from_string (struct it
*it
)
7648 struct text_pos position
;
7650 eassert (STRINGP (it
->string
));
7651 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7652 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7653 position
= it
->current
.string_pos
;
7655 /* With bidi reordering, the character to display might not be the
7656 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7657 that we were reseat()ed to a new string, whose paragraph
7658 direction is not known. */
7659 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7661 get_visually_first_element (it
);
7662 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7665 /* Time to check for invisible text? */
7666 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7668 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7671 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7672 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7674 /* With bidi non-linear iteration, we could find
7675 ourselves far beyond the last computed stop_charpos,
7676 with several other stop positions in between that we
7677 missed. Scan them all now, in buffer's logical
7678 order, until we find and handle the last stop_charpos
7679 that precedes our current position. */
7680 handle_stop_backwards (it
, it
->stop_charpos
);
7681 return GET_NEXT_DISPLAY_ELEMENT (it
);
7687 /* Take note of the stop position we just moved
7688 across, for when we will move back across it. */
7689 it
->prev_stop
= it
->stop_charpos
;
7690 /* If we are at base paragraph embedding level, take
7691 note of the last stop position seen at this
7693 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7694 it
->base_level_stop
= it
->stop_charpos
;
7698 /* Since a handler may have changed IT->method, we must
7700 return GET_NEXT_DISPLAY_ELEMENT (it
);
7704 /* If we are before prev_stop, we may have overstepped
7705 on our way backwards a stop_pos, and if so, we need
7706 to handle that stop_pos. */
7707 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7708 /* We can sometimes back up for reasons that have nothing
7709 to do with bidi reordering. E.g., compositions. The
7710 code below is only needed when we are above the base
7711 embedding level, so test for that explicitly. */
7712 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7714 /* If we lost track of base_level_stop, we have no better
7715 place for handle_stop_backwards to start from than string
7716 beginning. This happens, e.g., when we were reseated to
7717 the previous screenful of text by vertical-motion. */
7718 if (it
->base_level_stop
<= 0
7719 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7720 it
->base_level_stop
= 0;
7721 handle_stop_backwards (it
, it
->base_level_stop
);
7722 return GET_NEXT_DISPLAY_ELEMENT (it
);
7726 if (it
->current
.overlay_string_index
>= 0)
7728 /* Get the next character from an overlay string. In overlay
7729 strings, there is no field width or padding with spaces to
7731 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7736 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7737 IT_STRING_BYTEPOS (*it
),
7738 it
->bidi_it
.scan_dir
< 0
7740 : SCHARS (it
->string
))
7741 && next_element_from_composition (it
))
7745 else if (STRING_MULTIBYTE (it
->string
))
7747 const unsigned char *s
= (SDATA (it
->string
)
7748 + IT_STRING_BYTEPOS (*it
));
7749 it
->c
= string_char_and_length (s
, &it
->len
);
7753 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7759 /* Get the next character from a Lisp string that is not an
7760 overlay string. Such strings come from the mode line, for
7761 example. We may have to pad with spaces, or truncate the
7762 string. See also next_element_from_c_string. */
7763 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7768 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7770 /* Pad with spaces. */
7771 it
->c
= ' ', it
->len
= 1;
7772 CHARPOS (position
) = BYTEPOS (position
) = -1;
7774 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7775 IT_STRING_BYTEPOS (*it
),
7776 it
->bidi_it
.scan_dir
< 0
7778 : it
->string_nchars
)
7779 && next_element_from_composition (it
))
7783 else if (STRING_MULTIBYTE (it
->string
))
7785 const unsigned char *s
= (SDATA (it
->string
)
7786 + IT_STRING_BYTEPOS (*it
));
7787 it
->c
= string_char_and_length (s
, &it
->len
);
7791 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7796 /* Record what we have and where it came from. */
7797 it
->what
= IT_CHARACTER
;
7798 it
->object
= it
->string
;
7799 it
->position
= position
;
7804 /* Load IT with next display element from C string IT->s.
7805 IT->string_nchars is the maximum number of characters to return
7806 from the string. IT->end_charpos may be greater than
7807 IT->string_nchars when this function is called, in which case we
7808 may have to return padding spaces. Value is zero if end of string
7809 reached, including padding spaces. */
7812 next_element_from_c_string (struct it
*it
)
7814 bool success_p
= true;
7817 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7818 it
->what
= IT_CHARACTER
;
7819 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7822 /* With bidi reordering, the character to display might not be the
7823 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7824 we were reseated to a new string, whose paragraph direction is
7826 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7827 get_visually_first_element (it
);
7829 /* IT's position can be greater than IT->string_nchars in case a
7830 field width or precision has been specified when the iterator was
7832 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7834 /* End of the game. */
7838 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7840 /* Pad with spaces. */
7841 it
->c
= ' ', it
->len
= 1;
7842 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7844 else if (it
->multibyte_p
)
7845 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7847 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7853 /* Set up IT to return characters from an ellipsis, if appropriate.
7854 The definition of the ellipsis glyphs may come from a display table
7855 entry. This function fills IT with the first glyph from the
7856 ellipsis if an ellipsis is to be displayed. */
7859 next_element_from_ellipsis (struct it
*it
)
7861 if (it
->selective_display_ellipsis_p
)
7862 setup_for_ellipsis (it
, it
->len
);
7865 /* The face at the current position may be different from the
7866 face we find after the invisible text. Remember what it
7867 was in IT->saved_face_id, and signal that it's there by
7868 setting face_before_selective_p. */
7869 it
->saved_face_id
= it
->face_id
;
7870 it
->method
= GET_FROM_BUFFER
;
7871 it
->object
= it
->w
->contents
;
7872 reseat_at_next_visible_line_start (it
, 1);
7873 it
->face_before_selective_p
= true;
7876 return GET_NEXT_DISPLAY_ELEMENT (it
);
7880 /* Deliver an image display element. The iterator IT is already
7881 filled with image information (done in handle_display_prop). Value
7886 next_element_from_image (struct it
*it
)
7888 it
->what
= IT_IMAGE
;
7889 it
->ignore_overlay_strings_at_pos_p
= 0;
7894 /* Fill iterator IT with next display element from a stretch glyph
7895 property. IT->object is the value of the text property. Value is
7899 next_element_from_stretch (struct it
*it
)
7901 it
->what
= IT_STRETCH
;
7905 /* Scan backwards from IT's current position until we find a stop
7906 position, or until BEGV. This is called when we find ourself
7907 before both the last known prev_stop and base_level_stop while
7908 reordering bidirectional text. */
7911 compute_stop_pos_backwards (struct it
*it
)
7913 const int SCAN_BACK_LIMIT
= 1000;
7914 struct text_pos pos
;
7915 struct display_pos save_current
= it
->current
;
7916 struct text_pos save_position
= it
->position
;
7917 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7918 ptrdiff_t where_we_are
= charpos
;
7919 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7920 ptrdiff_t save_end_pos
= it
->end_charpos
;
7922 eassert (NILP (it
->string
) && !it
->s
);
7923 eassert (it
->bidi_p
);
7927 it
->end_charpos
= min (charpos
+ 1, ZV
);
7928 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7929 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7930 reseat_1 (it
, pos
, 0);
7931 compute_stop_pos (it
);
7932 /* We must advance forward, right? */
7933 if (it
->stop_charpos
<= charpos
)
7936 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7938 if (it
->stop_charpos
<= where_we_are
)
7939 it
->prev_stop
= it
->stop_charpos
;
7941 it
->prev_stop
= BEGV
;
7943 it
->current
= save_current
;
7944 it
->position
= save_position
;
7945 it
->stop_charpos
= save_stop_pos
;
7946 it
->end_charpos
= save_end_pos
;
7949 /* Scan forward from CHARPOS in the current buffer/string, until we
7950 find a stop position > current IT's position. Then handle the stop
7951 position before that. This is called when we bump into a stop
7952 position while reordering bidirectional text. CHARPOS should be
7953 the last previously processed stop_pos (or BEGV/0, if none were
7954 processed yet) whose position is less that IT's current
7958 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7960 int bufp
= !STRINGP (it
->string
);
7961 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7962 struct display_pos save_current
= it
->current
;
7963 struct text_pos save_position
= it
->position
;
7964 struct text_pos pos1
;
7965 ptrdiff_t next_stop
;
7967 /* Scan in strict logical order. */
7968 eassert (it
->bidi_p
);
7972 it
->prev_stop
= charpos
;
7975 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7976 reseat_1 (it
, pos1
, 0);
7979 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7980 compute_stop_pos (it
);
7981 /* We must advance forward, right? */
7982 if (it
->stop_charpos
<= it
->prev_stop
)
7984 charpos
= it
->stop_charpos
;
7986 while (charpos
<= where_we_are
);
7989 it
->current
= save_current
;
7990 it
->position
= save_position
;
7991 next_stop
= it
->stop_charpos
;
7992 it
->stop_charpos
= it
->prev_stop
;
7994 it
->stop_charpos
= next_stop
;
7997 /* Load IT with the next display element from current_buffer. Value
7998 is zero if end of buffer reached. IT->stop_charpos is the next
7999 position at which to stop and check for text properties or buffer
8003 next_element_from_buffer (struct it
*it
)
8005 bool success_p
= true;
8007 eassert (IT_CHARPOS (*it
) >= BEGV
);
8008 eassert (NILP (it
->string
) && !it
->s
);
8009 eassert (!it
->bidi_p
8010 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8011 && it
->bidi_it
.string
.s
== NULL
));
8013 /* With bidi reordering, the character to display might not be the
8014 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8015 we were reseat()ed to a new buffer position, which is potentially
8016 a different paragraph. */
8017 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8019 get_visually_first_element (it
);
8020 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8023 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8025 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8027 int overlay_strings_follow_p
;
8029 /* End of the game, except when overlay strings follow that
8030 haven't been returned yet. */
8031 if (it
->overlay_strings_at_end_processed_p
)
8032 overlay_strings_follow_p
= 0;
8035 it
->overlay_strings_at_end_processed_p
= true;
8036 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8039 if (overlay_strings_follow_p
)
8040 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8044 it
->position
= it
->current
.pos
;
8048 else if (!(!it
->bidi_p
8049 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8050 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8052 /* With bidi non-linear iteration, we could find ourselves
8053 far beyond the last computed stop_charpos, with several
8054 other stop positions in between that we missed. Scan
8055 them all now, in buffer's logical order, until we find
8056 and handle the last stop_charpos that precedes our
8057 current position. */
8058 handle_stop_backwards (it
, it
->stop_charpos
);
8059 return GET_NEXT_DISPLAY_ELEMENT (it
);
8065 /* Take note of the stop position we just moved across,
8066 for when we will move back across it. */
8067 it
->prev_stop
= it
->stop_charpos
;
8068 /* If we are at base paragraph embedding level, take
8069 note of the last stop position seen at this
8071 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8072 it
->base_level_stop
= it
->stop_charpos
;
8075 return GET_NEXT_DISPLAY_ELEMENT (it
);
8079 /* If we are before prev_stop, we may have overstepped on
8080 our way backwards a stop_pos, and if so, we need to
8081 handle that stop_pos. */
8082 && IT_CHARPOS (*it
) < it
->prev_stop
8083 /* We can sometimes back up for reasons that have nothing
8084 to do with bidi reordering. E.g., compositions. The
8085 code below is only needed when we are above the base
8086 embedding level, so test for that explicitly. */
8087 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8089 if (it
->base_level_stop
<= 0
8090 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8092 /* If we lost track of base_level_stop, we need to find
8093 prev_stop by looking backwards. This happens, e.g., when
8094 we were reseated to the previous screenful of text by
8096 it
->base_level_stop
= BEGV
;
8097 compute_stop_pos_backwards (it
);
8098 handle_stop_backwards (it
, it
->prev_stop
);
8101 handle_stop_backwards (it
, it
->base_level_stop
);
8102 return GET_NEXT_DISPLAY_ELEMENT (it
);
8106 /* No face changes, overlays etc. in sight, so just return a
8107 character from current_buffer. */
8111 /* Maybe run the redisplay end trigger hook. Performance note:
8112 This doesn't seem to cost measurable time. */
8113 if (it
->redisplay_end_trigger_charpos
8115 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8116 run_redisplay_end_trigger_hook (it
);
8118 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8119 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8121 && next_element_from_composition (it
))
8126 /* Get the next character, maybe multibyte. */
8127 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8128 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8129 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8131 it
->c
= *p
, it
->len
= 1;
8133 /* Record what we have and where it came from. */
8134 it
->what
= IT_CHARACTER
;
8135 it
->object
= it
->w
->contents
;
8136 it
->position
= it
->current
.pos
;
8138 /* Normally we return the character found above, except when we
8139 really want to return an ellipsis for selective display. */
8144 /* A value of selective > 0 means hide lines indented more
8145 than that number of columns. */
8146 if (it
->selective
> 0
8147 && IT_CHARPOS (*it
) + 1 < ZV
8148 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8149 IT_BYTEPOS (*it
) + 1,
8152 success_p
= next_element_from_ellipsis (it
);
8153 it
->dpvec_char_len
= -1;
8156 else if (it
->c
== '\r' && it
->selective
== -1)
8158 /* A value of selective == -1 means that everything from the
8159 CR to the end of the line is invisible, with maybe an
8160 ellipsis displayed for it. */
8161 success_p
= next_element_from_ellipsis (it
);
8162 it
->dpvec_char_len
= -1;
8167 /* Value is zero if end of buffer reached. */
8168 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8173 /* Run the redisplay end trigger hook for IT. */
8176 run_redisplay_end_trigger_hook (struct it
*it
)
8178 Lisp_Object args
[3];
8180 /* IT->glyph_row should be non-null, i.e. we should be actually
8181 displaying something, or otherwise we should not run the hook. */
8182 eassert (it
->glyph_row
);
8184 /* Set up hook arguments. */
8185 args
[0] = Qredisplay_end_trigger_functions
;
8186 args
[1] = it
->window
;
8187 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8188 it
->redisplay_end_trigger_charpos
= 0;
8190 /* Since we are *trying* to run these functions, don't try to run
8191 them again, even if they get an error. */
8192 wset_redisplay_end_trigger (it
->w
, Qnil
);
8193 Frun_hook_with_args (3, args
);
8195 /* Notice if it changed the face of the character we are on. */
8196 handle_face_prop (it
);
8200 /* Deliver a composition display element. Unlike the other
8201 next_element_from_XXX, this function is not registered in the array
8202 get_next_element[]. It is called from next_element_from_buffer and
8203 next_element_from_string when necessary. */
8206 next_element_from_composition (struct it
*it
)
8208 it
->what
= IT_COMPOSITION
;
8209 it
->len
= it
->cmp_it
.nbytes
;
8210 if (STRINGP (it
->string
))
8214 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8215 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8218 it
->position
= it
->current
.string_pos
;
8219 it
->object
= it
->string
;
8220 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8221 IT_STRING_BYTEPOS (*it
), it
->string
);
8227 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8228 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8231 if (it
->bidi_it
.new_paragraph
)
8232 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8233 /* Resync the bidi iterator with IT's new position.
8234 FIXME: this doesn't support bidirectional text. */
8235 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8236 bidi_move_to_visually_next (&it
->bidi_it
);
8240 it
->position
= it
->current
.pos
;
8241 it
->object
= it
->w
->contents
;
8242 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8243 IT_BYTEPOS (*it
), Qnil
);
8250 /***********************************************************************
8251 Moving an iterator without producing glyphs
8252 ***********************************************************************/
8254 /* Check if iterator is at a position corresponding to a valid buffer
8255 position after some move_it_ call. */
8257 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8258 ((it)->method == GET_FROM_STRING \
8259 ? IT_STRING_CHARPOS (*it) == 0 \
8263 /* Move iterator IT to a specified buffer or X position within one
8264 line on the display without producing glyphs.
8266 OP should be a bit mask including some or all of these bits:
8267 MOVE_TO_X: Stop upon reaching x-position TO_X.
8268 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8269 Regardless of OP's value, stop upon reaching the end of the display line.
8271 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8272 This means, in particular, that TO_X includes window's horizontal
8275 The return value has several possible values that
8276 say what condition caused the scan to stop:
8278 MOVE_POS_MATCH_OR_ZV
8279 - when TO_POS or ZV was reached.
8282 -when TO_X was reached before TO_POS or ZV were reached.
8285 - when we reached the end of the display area and the line must
8289 - when we reached the end of the display area and the line is
8293 - when we stopped at a line end, i.e. a newline or a CR and selective
8296 static enum move_it_result
8297 move_it_in_display_line_to (struct it
*it
,
8298 ptrdiff_t to_charpos
, int to_x
,
8299 enum move_operation_enum op
)
8301 enum move_it_result result
= MOVE_UNDEFINED
;
8302 struct glyph_row
*saved_glyph_row
;
8303 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8304 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8305 void *ppos_data
= NULL
;
8307 enum it_method prev_method
= it
->method
;
8308 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8309 int saw_smaller_pos
= prev_pos
< to_charpos
;
8311 /* Don't produce glyphs in produce_glyphs. */
8312 saved_glyph_row
= it
->glyph_row
;
8313 it
->glyph_row
= NULL
;
8315 /* Use wrap_it to save a copy of IT wherever a word wrap could
8316 occur. Use atpos_it to save a copy of IT at the desired buffer
8317 position, if found, so that we can scan ahead and check if the
8318 word later overshoots the window edge. Use atx_it similarly, for
8324 /* Use ppos_it under bidi reordering to save a copy of IT for the
8325 position > CHARPOS that is the closest to CHARPOS. We restore
8326 that position in IT when we have scanned the entire display line
8327 without finding a match for CHARPOS and all the character
8328 positions are greater than CHARPOS. */
8331 SAVE_IT (ppos_it
, *it
, ppos_data
);
8332 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8333 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8334 SAVE_IT (ppos_it
, *it
, ppos_data
);
8337 #define BUFFER_POS_REACHED_P() \
8338 ((op & MOVE_TO_POS) != 0 \
8339 && BUFFERP (it->object) \
8340 && (IT_CHARPOS (*it) == to_charpos \
8342 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8343 && IT_CHARPOS (*it) > to_charpos) \
8344 || (it->what == IT_COMPOSITION \
8345 && ((IT_CHARPOS (*it) > to_charpos \
8346 && to_charpos >= it->cmp_it.charpos) \
8347 || (IT_CHARPOS (*it) < to_charpos \
8348 && to_charpos <= it->cmp_it.charpos)))) \
8349 && (it->method == GET_FROM_BUFFER \
8350 || (it->method == GET_FROM_DISPLAY_VECTOR \
8351 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8353 /* If there's a line-/wrap-prefix, handle it. */
8354 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8355 && it
->current_y
< it
->last_visible_y
)
8356 handle_line_prefix (it
);
8358 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8359 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8363 int x
, i
, ascent
= 0, descent
= 0;
8365 /* Utility macro to reset an iterator with x, ascent, and descent. */
8366 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8367 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8368 (IT)->max_descent = descent)
8370 /* Stop if we move beyond TO_CHARPOS (after an image or a
8371 display string or stretch glyph). */
8372 if ((op
& MOVE_TO_POS
) != 0
8373 && BUFFERP (it
->object
)
8374 && it
->method
== GET_FROM_BUFFER
8376 /* When the iterator is at base embedding level, we
8377 are guaranteed that characters are delivered for
8378 display in strictly increasing order of their
8379 buffer positions. */
8380 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8381 && IT_CHARPOS (*it
) > to_charpos
)
8383 && (prev_method
== GET_FROM_IMAGE
8384 || prev_method
== GET_FROM_STRETCH
8385 || prev_method
== GET_FROM_STRING
)
8386 /* Passed TO_CHARPOS from left to right. */
8387 && ((prev_pos
< to_charpos
8388 && IT_CHARPOS (*it
) > to_charpos
)
8389 /* Passed TO_CHARPOS from right to left. */
8390 || (prev_pos
> to_charpos
8391 && IT_CHARPOS (*it
) < to_charpos
)))))
8393 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8395 result
= MOVE_POS_MATCH_OR_ZV
;
8398 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8399 /* If wrap_it is valid, the current position might be in a
8400 word that is wrapped. So, save the iterator in
8401 atpos_it and continue to see if wrapping happens. */
8402 SAVE_IT (atpos_it
, *it
, atpos_data
);
8405 /* Stop when ZV reached.
8406 We used to stop here when TO_CHARPOS reached as well, but that is
8407 too soon if this glyph does not fit on this line. So we handle it
8408 explicitly below. */
8409 if (!get_next_display_element (it
))
8411 result
= MOVE_POS_MATCH_OR_ZV
;
8415 if (it
->line_wrap
== TRUNCATE
)
8417 if (BUFFER_POS_REACHED_P ())
8419 result
= MOVE_POS_MATCH_OR_ZV
;
8425 if (it
->line_wrap
== WORD_WRAP
)
8427 if (IT_DISPLAYING_WHITESPACE (it
))
8431 /* We have reached a glyph that follows one or more
8432 whitespace characters. If the position is
8433 already found, we are done. */
8434 if (atpos_it
.sp
>= 0)
8436 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8437 result
= MOVE_POS_MATCH_OR_ZV
;
8442 RESTORE_IT (it
, &atx_it
, atx_data
);
8443 result
= MOVE_X_REACHED
;
8446 /* Otherwise, we can wrap here. */
8447 SAVE_IT (wrap_it
, *it
, wrap_data
);
8453 /* Remember the line height for the current line, in case
8454 the next element doesn't fit on the line. */
8455 ascent
= it
->max_ascent
;
8456 descent
= it
->max_descent
;
8458 /* The call to produce_glyphs will get the metrics of the
8459 display element IT is loaded with. Record the x-position
8460 before this display element, in case it doesn't fit on the
8464 PRODUCE_GLYPHS (it
);
8466 if (it
->area
!= TEXT_AREA
)
8468 prev_method
= it
->method
;
8469 if (it
->method
== GET_FROM_BUFFER
)
8470 prev_pos
= IT_CHARPOS (*it
);
8471 set_iterator_to_next (it
, 1);
8472 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8473 SET_TEXT_POS (this_line_min_pos
,
8474 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8476 && (op
& MOVE_TO_POS
)
8477 && IT_CHARPOS (*it
) > to_charpos
8478 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8479 SAVE_IT (ppos_it
, *it
, ppos_data
);
8483 /* The number of glyphs we get back in IT->nglyphs will normally
8484 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8485 character on a terminal frame, or (iii) a line end. For the
8486 second case, IT->nglyphs - 1 padding glyphs will be present.
8487 (On X frames, there is only one glyph produced for a
8488 composite character.)
8490 The behavior implemented below means, for continuation lines,
8491 that as many spaces of a TAB as fit on the current line are
8492 displayed there. For terminal frames, as many glyphs of a
8493 multi-glyph character are displayed in the current line, too.
8494 This is what the old redisplay code did, and we keep it that
8495 way. Under X, the whole shape of a complex character must
8496 fit on the line or it will be completely displayed in the
8499 Note that both for tabs and padding glyphs, all glyphs have
8503 /* More than one glyph or glyph doesn't fit on line. All
8504 glyphs have the same width. */
8505 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8507 int x_before_this_char
= x
;
8508 int hpos_before_this_char
= it
->hpos
;
8510 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8512 new_x
= x
+ single_glyph_width
;
8514 /* We want to leave anything reaching TO_X to the caller. */
8515 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8517 if (BUFFER_POS_REACHED_P ())
8519 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8520 goto buffer_pos_reached
;
8521 if (atpos_it
.sp
< 0)
8523 SAVE_IT (atpos_it
, *it
, atpos_data
);
8524 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8529 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8532 result
= MOVE_X_REACHED
;
8537 SAVE_IT (atx_it
, *it
, atx_data
);
8538 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8543 if (/* Lines are continued. */
8544 it
->line_wrap
!= TRUNCATE
8545 && (/* And glyph doesn't fit on the line. */
8546 new_x
> it
->last_visible_x
8547 /* Or it fits exactly and we're on a window
8549 || (new_x
== it
->last_visible_x
8550 && FRAME_WINDOW_P (it
->f
)
8551 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8552 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8553 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8555 if (/* IT->hpos == 0 means the very first glyph
8556 doesn't fit on the line, e.g. a wide image. */
8558 || (new_x
== it
->last_visible_x
8559 && FRAME_WINDOW_P (it
->f
)))
8562 it
->current_x
= new_x
;
8564 /* The character's last glyph just barely fits
8566 if (i
== it
->nglyphs
- 1)
8568 /* If this is the destination position,
8569 return a position *before* it in this row,
8570 now that we know it fits in this row. */
8571 if (BUFFER_POS_REACHED_P ())
8573 if (it
->line_wrap
!= WORD_WRAP
8576 it
->hpos
= hpos_before_this_char
;
8577 it
->current_x
= x_before_this_char
;
8578 result
= MOVE_POS_MATCH_OR_ZV
;
8581 if (it
->line_wrap
== WORD_WRAP
8584 SAVE_IT (atpos_it
, *it
, atpos_data
);
8585 atpos_it
.current_x
= x_before_this_char
;
8586 atpos_it
.hpos
= hpos_before_this_char
;
8590 prev_method
= it
->method
;
8591 if (it
->method
== GET_FROM_BUFFER
)
8592 prev_pos
= IT_CHARPOS (*it
);
8593 set_iterator_to_next (it
, 1);
8594 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8595 SET_TEXT_POS (this_line_min_pos
,
8596 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8597 /* On graphical terminals, newlines may
8598 "overflow" into the fringe if
8599 overflow-newline-into-fringe is non-nil.
8600 On text terminals, and on graphical
8601 terminals with no right margin, newlines
8602 may overflow into the last glyph on the
8604 if (!FRAME_WINDOW_P (it
->f
)
8606 && it
->bidi_it
.paragraph_dir
== R2L
)
8607 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8608 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8609 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8611 if (!get_next_display_element (it
))
8613 result
= MOVE_POS_MATCH_OR_ZV
;
8616 if (BUFFER_POS_REACHED_P ())
8618 if (ITERATOR_AT_END_OF_LINE_P (it
))
8619 result
= MOVE_POS_MATCH_OR_ZV
;
8621 result
= MOVE_LINE_CONTINUED
;
8624 if (ITERATOR_AT_END_OF_LINE_P (it
)
8625 && (it
->line_wrap
!= WORD_WRAP
8628 result
= MOVE_NEWLINE_OR_CR
;
8635 IT_RESET_X_ASCENT_DESCENT (it
);
8637 if (wrap_it
.sp
>= 0)
8639 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8644 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8646 result
= MOVE_LINE_CONTINUED
;
8650 if (BUFFER_POS_REACHED_P ())
8652 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8653 goto buffer_pos_reached
;
8654 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8656 SAVE_IT (atpos_it
, *it
, atpos_data
);
8657 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8661 if (new_x
> it
->first_visible_x
)
8663 /* Glyph is visible. Increment number of glyphs that
8664 would be displayed. */
8669 if (result
!= MOVE_UNDEFINED
)
8672 else if (BUFFER_POS_REACHED_P ())
8675 IT_RESET_X_ASCENT_DESCENT (it
);
8676 result
= MOVE_POS_MATCH_OR_ZV
;
8679 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8681 /* Stop when TO_X specified and reached. This check is
8682 necessary here because of lines consisting of a line end,
8683 only. The line end will not produce any glyphs and we
8684 would never get MOVE_X_REACHED. */
8685 eassert (it
->nglyphs
== 0);
8686 result
= MOVE_X_REACHED
;
8690 /* Is this a line end? If yes, we're done. */
8691 if (ITERATOR_AT_END_OF_LINE_P (it
))
8693 /* If we are past TO_CHARPOS, but never saw any character
8694 positions smaller than TO_CHARPOS, return
8695 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8697 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8699 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8701 if (IT_CHARPOS (ppos_it
) < ZV
)
8703 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8704 result
= MOVE_POS_MATCH_OR_ZV
;
8707 goto buffer_pos_reached
;
8709 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8710 && IT_CHARPOS (*it
) > to_charpos
)
8711 goto buffer_pos_reached
;
8713 result
= MOVE_NEWLINE_OR_CR
;
8716 result
= MOVE_NEWLINE_OR_CR
;
8720 prev_method
= it
->method
;
8721 if (it
->method
== GET_FROM_BUFFER
)
8722 prev_pos
= IT_CHARPOS (*it
);
8723 /* The current display element has been consumed. Advance
8725 set_iterator_to_next (it
, 1);
8726 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8727 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8728 if (IT_CHARPOS (*it
) < to_charpos
)
8729 saw_smaller_pos
= 1;
8731 && (op
& MOVE_TO_POS
)
8732 && IT_CHARPOS (*it
) >= to_charpos
8733 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8734 SAVE_IT (ppos_it
, *it
, ppos_data
);
8736 /* Stop if lines are truncated and IT's current x-position is
8737 past the right edge of the window now. */
8738 if (it
->line_wrap
== TRUNCATE
8739 && it
->current_x
>= it
->last_visible_x
)
8741 if (!FRAME_WINDOW_P (it
->f
)
8742 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8743 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8744 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8745 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8749 if ((at_eob_p
= !get_next_display_element (it
))
8750 || BUFFER_POS_REACHED_P ()
8751 /* If we are past TO_CHARPOS, but never saw any
8752 character positions smaller than TO_CHARPOS,
8753 return MOVE_POS_MATCH_OR_ZV, like the
8754 unidirectional display did. */
8755 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8757 && IT_CHARPOS (*it
) > to_charpos
))
8760 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8761 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8762 result
= MOVE_POS_MATCH_OR_ZV
;
8765 if (ITERATOR_AT_END_OF_LINE_P (it
))
8767 result
= MOVE_NEWLINE_OR_CR
;
8771 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8773 && IT_CHARPOS (*it
) > to_charpos
)
8775 if (IT_CHARPOS (ppos_it
) < ZV
)
8776 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8777 result
= MOVE_POS_MATCH_OR_ZV
;
8780 result
= MOVE_LINE_TRUNCATED
;
8783 #undef IT_RESET_X_ASCENT_DESCENT
8786 #undef BUFFER_POS_REACHED_P
8788 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8789 restore the saved iterator. */
8790 if (atpos_it
.sp
>= 0)
8791 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8792 else if (atx_it
.sp
>= 0)
8793 RESTORE_IT (it
, &atx_it
, atx_data
);
8798 bidi_unshelve_cache (atpos_data
, 1);
8800 bidi_unshelve_cache (atx_data
, 1);
8802 bidi_unshelve_cache (wrap_data
, 1);
8804 bidi_unshelve_cache (ppos_data
, 1);
8806 /* Restore the iterator settings altered at the beginning of this
8808 it
->glyph_row
= saved_glyph_row
;
8812 /* For external use. */
8814 move_it_in_display_line (struct it
*it
,
8815 ptrdiff_t to_charpos
, int to_x
,
8816 enum move_operation_enum op
)
8818 if (it
->line_wrap
== WORD_WRAP
8819 && (op
& MOVE_TO_X
))
8822 void *save_data
= NULL
;
8825 SAVE_IT (save_it
, *it
, save_data
);
8826 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8827 /* When word-wrap is on, TO_X may lie past the end
8828 of a wrapped line. Then it->current is the
8829 character on the next line, so backtrack to the
8830 space before the wrap point. */
8831 if (skip
== MOVE_LINE_CONTINUED
)
8833 int prev_x
= max (it
->current_x
- 1, 0);
8834 RESTORE_IT (it
, &save_it
, save_data
);
8835 move_it_in_display_line_to
8836 (it
, -1, prev_x
, MOVE_TO_X
);
8839 bidi_unshelve_cache (save_data
, 1);
8842 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8846 /* Move IT forward until it satisfies one or more of the criteria in
8847 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8849 OP is a bit-mask that specifies where to stop, and in particular,
8850 which of those four position arguments makes a difference. See the
8851 description of enum move_operation_enum.
8853 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8854 screen line, this function will set IT to the next position that is
8855 displayed to the right of TO_CHARPOS on the screen.
8857 Return the maximum pixel length of any line scanned but never more
8858 than it.last_visible_x. */
8861 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8863 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8864 int line_height
, line_start_x
= 0, reached
= 0;
8865 int max_current_x
= 0;
8866 void *backup_data
= NULL
;
8870 if (op
& MOVE_TO_VPOS
)
8872 /* If no TO_CHARPOS and no TO_X specified, stop at the
8873 start of the line TO_VPOS. */
8874 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8876 if (it
->vpos
== to_vpos
)
8882 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8886 /* TO_VPOS >= 0 means stop at TO_X in the line at
8887 TO_VPOS, or at TO_POS, whichever comes first. */
8888 if (it
->vpos
== to_vpos
)
8894 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8896 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8901 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8903 /* We have reached TO_X but not in the line we want. */
8904 skip
= move_it_in_display_line_to (it
, to_charpos
,
8906 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8914 else if (op
& MOVE_TO_Y
)
8916 struct it it_backup
;
8918 if (it
->line_wrap
== WORD_WRAP
)
8919 SAVE_IT (it_backup
, *it
, backup_data
);
8921 /* TO_Y specified means stop at TO_X in the line containing
8922 TO_Y---or at TO_CHARPOS if this is reached first. The
8923 problem is that we can't really tell whether the line
8924 contains TO_Y before we have completely scanned it, and
8925 this may skip past TO_X. What we do is to first scan to
8928 If TO_X is not specified, use a TO_X of zero. The reason
8929 is to make the outcome of this function more predictable.
8930 If we didn't use TO_X == 0, we would stop at the end of
8931 the line which is probably not what a caller would expect
8933 skip
= move_it_in_display_line_to
8934 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8935 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8937 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8938 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8940 else if (skip
== MOVE_X_REACHED
)
8942 /* If TO_X was reached, we want to know whether TO_Y is
8943 in the line. We know this is the case if the already
8944 scanned glyphs make the line tall enough. Otherwise,
8945 we must check by scanning the rest of the line. */
8946 line_height
= it
->max_ascent
+ it
->max_descent
;
8947 if (to_y
>= it
->current_y
8948 && to_y
< it
->current_y
+ line_height
)
8953 SAVE_IT (it_backup
, *it
, backup_data
);
8954 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8955 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8957 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8958 line_height
= it
->max_ascent
+ it
->max_descent
;
8959 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8961 if (to_y
>= it
->current_y
8962 && to_y
< it
->current_y
+ line_height
)
8964 /* If TO_Y is in this line and TO_X was reached
8965 above, we scanned too far. We have to restore
8966 IT's settings to the ones before skipping. But
8967 keep the more accurate values of max_ascent and
8968 max_descent we've found while skipping the rest
8969 of the line, for the sake of callers, such as
8970 pos_visible_p, that need to know the line
8972 int max_ascent
= it
->max_ascent
;
8973 int max_descent
= it
->max_descent
;
8975 RESTORE_IT (it
, &it_backup
, backup_data
);
8976 it
->max_ascent
= max_ascent
;
8977 it
->max_descent
= max_descent
;
8983 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8989 /* Check whether TO_Y is in this line. */
8990 line_height
= it
->max_ascent
+ it
->max_descent
;
8991 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8993 if (to_y
>= it
->current_y
8994 && to_y
< it
->current_y
+ line_height
)
8996 if (to_y
> it
->current_y
)
8997 max_current_x
= max (it
->current_x
, max_current_x
);
8999 /* When word-wrap is on, TO_X may lie past the end
9000 of a wrapped line. Then it->current is the
9001 character on the next line, so backtrack to the
9002 space before the wrap point. */
9003 if (skip
== MOVE_LINE_CONTINUED
9004 && it
->line_wrap
== WORD_WRAP
)
9006 int prev_x
= max (it
->current_x
- 1, 0);
9007 RESTORE_IT (it
, &it_backup
, backup_data
);
9008 skip
= move_it_in_display_line_to
9009 (it
, -1, prev_x
, MOVE_TO_X
);
9018 max_current_x
= max (it
->current_x
, max_current_x
);
9022 else if (BUFFERP (it
->object
)
9023 && (it
->method
== GET_FROM_BUFFER
9024 || it
->method
== GET_FROM_STRETCH
)
9025 && IT_CHARPOS (*it
) >= to_charpos
9026 /* Under bidi iteration, a call to set_iterator_to_next
9027 can scan far beyond to_charpos if the initial
9028 portion of the next line needs to be reordered. In
9029 that case, give move_it_in_display_line_to another
9032 && it
->bidi_it
.scan_dir
== -1))
9033 skip
= MOVE_POS_MATCH_OR_ZV
;
9035 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9039 case MOVE_POS_MATCH_OR_ZV
:
9040 max_current_x
= max (it
->current_x
, max_current_x
);
9044 case MOVE_NEWLINE_OR_CR
:
9045 max_current_x
= max (it
->current_x
, max_current_x
);
9046 set_iterator_to_next (it
, 1);
9047 it
->continuation_lines_width
= 0;
9050 case MOVE_LINE_TRUNCATED
:
9051 max_current_x
= it
->last_visible_x
;
9052 it
->continuation_lines_width
= 0;
9053 reseat_at_next_visible_line_start (it
, 0);
9054 if ((op
& MOVE_TO_POS
) != 0
9055 && IT_CHARPOS (*it
) > to_charpos
)
9062 case MOVE_LINE_CONTINUED
:
9063 max_current_x
= it
->last_visible_x
;
9064 /* For continued lines ending in a tab, some of the glyphs
9065 associated with the tab are displayed on the current
9066 line. Since it->current_x does not include these glyphs,
9067 we use it->last_visible_x instead. */
9070 it
->continuation_lines_width
+= it
->last_visible_x
;
9071 /* When moving by vpos, ensure that the iterator really
9072 advances to the next line (bug#847, bug#969). Fixme:
9073 do we need to do this in other circumstances? */
9074 if (it
->current_x
!= it
->last_visible_x
9075 && (op
& MOVE_TO_VPOS
)
9076 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9078 line_start_x
= it
->current_x
+ it
->pixel_width
9079 - it
->last_visible_x
;
9080 set_iterator_to_next (it
, 0);
9084 it
->continuation_lines_width
+= it
->current_x
;
9091 /* Reset/increment for the next run. */
9092 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9093 it
->current_x
= line_start_x
;
9096 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9098 last_height
= it
->max_ascent
+ it
->max_descent
;
9099 last_max_ascent
= it
->max_ascent
;
9100 it
->max_ascent
= it
->max_descent
= 0;
9105 /* On text terminals, we may stop at the end of a line in the middle
9106 of a multi-character glyph. If the glyph itself is continued,
9107 i.e. it is actually displayed on the next line, don't treat this
9108 stopping point as valid; move to the next line instead (unless
9109 that brings us offscreen). */
9110 if (!FRAME_WINDOW_P (it
->f
)
9112 && IT_CHARPOS (*it
) == to_charpos
9113 && it
->what
== IT_CHARACTER
9115 && it
->line_wrap
== WINDOW_WRAP
9116 && it
->current_x
== it
->last_visible_x
- 1
9119 && it
->vpos
< it
->w
->window_end_vpos
)
9121 it
->continuation_lines_width
+= it
->current_x
;
9122 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9123 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9125 last_height
= it
->max_ascent
+ it
->max_descent
;
9126 last_max_ascent
= it
->max_ascent
;
9130 bidi_unshelve_cache (backup_data
, 1);
9132 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9134 return max_current_x
;
9138 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9140 If DY > 0, move IT backward at least that many pixels. DY = 0
9141 means move IT backward to the preceding line start or BEGV. This
9142 function may move over more than DY pixels if IT->current_y - DY
9143 ends up in the middle of a line; in this case IT->current_y will be
9144 set to the top of the line moved to. */
9147 move_it_vertically_backward (struct it
*it
, int dy
)
9151 void *it2data
= NULL
, *it3data
= NULL
;
9152 ptrdiff_t start_pos
;
9154 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9155 ptrdiff_t pos_limit
;
9160 start_pos
= IT_CHARPOS (*it
);
9162 /* Estimate how many newlines we must move back. */
9163 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9164 if (it
->line_wrap
== TRUNCATE
)
9167 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9169 /* Set the iterator's position that many lines back. But don't go
9170 back more than NLINES full screen lines -- this wins a day with
9171 buffers which have very long lines. */
9172 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9173 back_to_previous_visible_line_start (it
);
9175 /* Reseat the iterator here. When moving backward, we don't want
9176 reseat to skip forward over invisible text, set up the iterator
9177 to deliver from overlay strings at the new position etc. So,
9178 use reseat_1 here. */
9179 reseat_1 (it
, it
->current
.pos
, 1);
9181 /* We are now surely at a line start. */
9182 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9183 reordering is in effect. */
9184 it
->continuation_lines_width
= 0;
9186 /* Move forward and see what y-distance we moved. First move to the
9187 start of the next line so that we get its height. We need this
9188 height to be able to tell whether we reached the specified
9190 SAVE_IT (it2
, *it
, it2data
);
9191 it2
.max_ascent
= it2
.max_descent
= 0;
9194 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9195 MOVE_TO_POS
| MOVE_TO_VPOS
);
9197 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9198 /* If we are in a display string which starts at START_POS,
9199 and that display string includes a newline, and we are
9200 right after that newline (i.e. at the beginning of a
9201 display line), exit the loop, because otherwise we will
9202 infloop, since move_it_to will see that it is already at
9203 START_POS and will not move. */
9204 || (it2
.method
== GET_FROM_STRING
9205 && IT_CHARPOS (it2
) == start_pos
9206 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9207 eassert (IT_CHARPOS (*it
) >= BEGV
);
9208 SAVE_IT (it3
, it2
, it3data
);
9210 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9211 eassert (IT_CHARPOS (*it
) >= BEGV
);
9212 /* H is the actual vertical distance from the position in *IT
9213 and the starting position. */
9214 h
= it2
.current_y
- it
->current_y
;
9215 /* NLINES is the distance in number of lines. */
9216 nlines
= it2
.vpos
- it
->vpos
;
9218 /* Correct IT's y and vpos position
9219 so that they are relative to the starting point. */
9225 /* DY == 0 means move to the start of the screen line. The
9226 value of nlines is > 0 if continuation lines were involved,
9227 or if the original IT position was at start of a line. */
9228 RESTORE_IT (it
, it
, it2data
);
9230 move_it_by_lines (it
, nlines
);
9231 /* The above code moves us to some position NLINES down,
9232 usually to its first glyph (leftmost in an L2R line), but
9233 that's not necessarily the start of the line, under bidi
9234 reordering. We want to get to the character position
9235 that is immediately after the newline of the previous
9238 && !it
->continuation_lines_width
9239 && !STRINGP (it
->string
)
9240 && IT_CHARPOS (*it
) > BEGV
9241 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9243 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9246 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9247 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9249 bidi_unshelve_cache (it3data
, 1);
9253 /* The y-position we try to reach, relative to *IT.
9254 Note that H has been subtracted in front of the if-statement. */
9255 int target_y
= it
->current_y
+ h
- dy
;
9256 int y0
= it3
.current_y
;
9260 RESTORE_IT (&it3
, &it3
, it3data
);
9261 y1
= line_bottom_y (&it3
);
9262 line_height
= y1
- y0
;
9263 RESTORE_IT (it
, it
, it2data
);
9264 /* If we did not reach target_y, try to move further backward if
9265 we can. If we moved too far backward, try to move forward. */
9266 if (target_y
< it
->current_y
9267 /* This is heuristic. In a window that's 3 lines high, with
9268 a line height of 13 pixels each, recentering with point
9269 on the bottom line will try to move -39/2 = 19 pixels
9270 backward. Try to avoid moving into the first line. */
9271 && (it
->current_y
- target_y
9272 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9273 && IT_CHARPOS (*it
) > BEGV
)
9275 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9276 target_y
- it
->current_y
));
9277 dy
= it
->current_y
- target_y
;
9278 goto move_further_back
;
9280 else if (target_y
>= it
->current_y
+ line_height
9281 && IT_CHARPOS (*it
) < ZV
)
9283 /* Should move forward by at least one line, maybe more.
9285 Note: Calling move_it_by_lines can be expensive on
9286 terminal frames, where compute_motion is used (via
9287 vmotion) to do the job, when there are very long lines
9288 and truncate-lines is nil. That's the reason for
9289 treating terminal frames specially here. */
9291 if (!FRAME_WINDOW_P (it
->f
))
9292 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9297 move_it_by_lines (it
, 1);
9299 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9306 /* Move IT by a specified amount of pixel lines DY. DY negative means
9307 move backwards. DY = 0 means move to start of screen line. At the
9308 end, IT will be on the start of a screen line. */
9311 move_it_vertically (struct it
*it
, int dy
)
9314 move_it_vertically_backward (it
, -dy
);
9317 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9318 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9319 MOVE_TO_POS
| MOVE_TO_Y
);
9320 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9322 /* If buffer ends in ZV without a newline, move to the start of
9323 the line to satisfy the post-condition. */
9324 if (IT_CHARPOS (*it
) == ZV
9326 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9327 move_it_by_lines (it
, 0);
9332 /* Move iterator IT past the end of the text line it is in. */
9335 move_it_past_eol (struct it
*it
)
9337 enum move_it_result rc
;
9339 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9340 if (rc
== MOVE_NEWLINE_OR_CR
)
9341 set_iterator_to_next (it
, 0);
9345 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9346 negative means move up. DVPOS == 0 means move to the start of the
9349 Optimization idea: If we would know that IT->f doesn't use
9350 a face with proportional font, we could be faster for
9351 truncate-lines nil. */
9354 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9357 /* The commented-out optimization uses vmotion on terminals. This
9358 gives bad results, because elements like it->what, on which
9359 callers such as pos_visible_p rely, aren't updated. */
9360 /* struct position pos;
9361 if (!FRAME_WINDOW_P (it->f))
9363 struct text_pos textpos;
9365 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9366 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9367 reseat (it, textpos, 1);
9368 it->vpos += pos.vpos;
9369 it->current_y += pos.vpos;
9375 /* DVPOS == 0 means move to the start of the screen line. */
9376 move_it_vertically_backward (it
, 0);
9377 /* Let next call to line_bottom_y calculate real line height. */
9382 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9383 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9385 /* Only move to the next buffer position if we ended up in a
9386 string from display property, not in an overlay string
9387 (before-string or after-string). That is because the
9388 latter don't conceal the underlying buffer position, so
9389 we can ask to move the iterator to the exact position we
9390 are interested in. Note that, even if we are already at
9391 IT_CHARPOS (*it), the call below is not a no-op, as it
9392 will detect that we are at the end of the string, pop the
9393 iterator, and compute it->current_x and it->hpos
9395 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9396 -1, -1, -1, MOVE_TO_POS
);
9402 void *it2data
= NULL
;
9403 ptrdiff_t start_charpos
, i
;
9405 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9406 ptrdiff_t pos_limit
;
9408 /* Start at the beginning of the screen line containing IT's
9409 position. This may actually move vertically backwards,
9410 in case of overlays, so adjust dvpos accordingly. */
9412 move_it_vertically_backward (it
, 0);
9415 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9416 screen lines, and reseat the iterator there. */
9417 start_charpos
= IT_CHARPOS (*it
);
9418 if (it
->line_wrap
== TRUNCATE
)
9421 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9422 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9423 back_to_previous_visible_line_start (it
);
9424 reseat (it
, it
->current
.pos
, 1);
9426 /* Move further back if we end up in a string or an image. */
9427 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9429 /* First try to move to start of display line. */
9431 move_it_vertically_backward (it
, 0);
9433 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9435 /* If start of line is still in string or image,
9436 move further back. */
9437 back_to_previous_visible_line_start (it
);
9438 reseat (it
, it
->current
.pos
, 1);
9442 it
->current_x
= it
->hpos
= 0;
9444 /* Above call may have moved too far if continuation lines
9445 are involved. Scan forward and see if it did. */
9446 SAVE_IT (it2
, *it
, it2data
);
9447 it2
.vpos
= it2
.current_y
= 0;
9448 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9449 it
->vpos
-= it2
.vpos
;
9450 it
->current_y
-= it2
.current_y
;
9451 it
->current_x
= it
->hpos
= 0;
9453 /* If we moved too far back, move IT some lines forward. */
9454 if (it2
.vpos
> -dvpos
)
9456 int delta
= it2
.vpos
+ dvpos
;
9458 RESTORE_IT (&it2
, &it2
, it2data
);
9459 SAVE_IT (it2
, *it
, it2data
);
9460 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9461 /* Move back again if we got too far ahead. */
9462 if (IT_CHARPOS (*it
) >= start_charpos
)
9463 RESTORE_IT (it
, &it2
, it2data
);
9465 bidi_unshelve_cache (it2data
, 1);
9468 RESTORE_IT (it
, it
, it2data
);
9472 /* Return true if IT points into the middle of a display vector. */
9475 in_display_vector_p (struct it
*it
)
9477 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9478 && it
->current
.dpvec_index
> 0
9479 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9482 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9483 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9484 WINDOW must be a live window and defaults to the selected one. The
9485 return value is a cons of the maximum pixel-width of any text line and
9486 the maximum pixel-height of all text lines.
9488 The optional argument FROM, if non-nil, specifies the first text
9489 position and defaults to the minimum accessible position of the buffer.
9490 If FROM is t, use the minimum accessible position that is not a newline
9491 character. TO, if non-nil, specifies the last text position and
9492 defaults to the maximum accessible position of the buffer. If TO is t,
9493 use the maximum accessible position that is not a newline character.
9495 The optional argument X_LIMIT, if non-nil, specifies the maximum text
9496 width that can be returned. X_LIMIT nil or omitted, means to use the
9497 pixel-width of WINDOW's body; use this if you do not intend to change
9498 the width of WINDOW. Use the maximum width WINDOW may assume if you
9499 intend to change WINDOW's width.
9501 The optional argument Y_LIMIT, if non-nil, specifies the maximum text
9502 height that can be returned. Text lines whose y-coordinate is beyond
9503 Y_LIMIT are ignored. Since calculating the text height of a large
9504 buffer can take some time, it makes sense to specify this argument if
9505 the size of the buffer is unknown.
9507 Optional argument MODE_AND_HEADER_LINE nil or omitted means do not
9508 include the height of the mode- or header-line of WINDOW in the return
9509 value. If it is either the symbol `mode-line' or `header-line', include
9510 only the height of that line, if present, in the return value. If t,
9511 include the height of any of these lines in the return value. */)
9512 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9513 Lisp_Object mode_and_header_line
)
9515 struct window
*w
= decode_live_window (window
);
9519 struct buffer
*old_buffer
= NULL
;
9520 ptrdiff_t start
, end
, pos
;
9521 struct text_pos startp
;
9522 void *itdata
= NULL
;
9523 int c
, max_y
= -1, x
= 0, y
= 0;
9529 if (b
!= current_buffer
)
9531 old_buffer
= current_buffer
;
9532 set_buffer_internal (b
);
9537 else if (EQ (from
, Qt
))
9540 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9541 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9543 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9548 CHECK_NUMBER_COERCE_MARKER (from
);
9549 start
= min (max (XINT (from
), BEGV
), ZV
);
9554 else if (EQ (to
, Qt
))
9557 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9558 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9560 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9565 CHECK_NUMBER_COERCE_MARKER (to
);
9566 end
= max (start
, min (XINT (to
), ZV
));
9569 if (!NILP (y_limit
))
9571 CHECK_NUMBER (y_limit
);
9572 max_y
= min (XINT (y_limit
), INT_MAX
);
9575 itdata
= bidi_shelve_cache ();
9576 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9577 start_display (&it
, w
, startp
);
9579 /** move_it_vertically_backward (&it, 0); **/
9581 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9584 CHECK_NUMBER (x_limit
);
9585 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9586 /* Actually, we never want move_it_to stop at to_x. But to make
9587 sure that move_it_in_display_line_to always moves far enough,
9588 we set it to INT_MAX and specify MOVE_TO_X. */
9589 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9590 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9597 /* Count last line. */
9599 y
= line_bottom_y (&it
); /* - y; */
9602 if (!EQ (mode_and_header_line
, Qheader_line
)
9603 && !EQ (mode_and_header_line
, Qt
))
9604 /* Do not count the header-line which was counted automatically by
9606 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9608 if (EQ (mode_and_header_line
, Qmode_line
)
9609 || EQ (mode_and_header_line
, Qt
))
9610 /* Do count the mode-line which is not included automatically by
9612 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9614 bidi_unshelve_cache (itdata
, 0);
9617 set_buffer_internal (old_buffer
);
9619 return Fcons (make_number (x
), make_number (y
));
9622 /***********************************************************************
9624 ***********************************************************************/
9627 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9631 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9633 Lisp_Object args
[3];
9634 Lisp_Object msg
, fmt
;
9637 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9641 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9643 args
[0] = fmt
= build_string (format
);
9646 msg
= Fformat (3, args
);
9648 len
= SBYTES (msg
) + 1;
9649 buffer
= SAFE_ALLOCA (len
);
9650 memcpy (buffer
, SDATA (msg
), len
);
9652 message_dolog (buffer
, len
- 1, 1, 0);
9659 /* Output a newline in the *Messages* buffer if "needs" one. */
9662 message_log_maybe_newline (void)
9664 if (message_log_need_newline
)
9665 message_dolog ("", 0, 1, 0);
9669 /* Add a string M of length NBYTES to the message log, optionally
9670 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9671 true, means interpret the contents of M as multibyte. This
9672 function calls low-level routines in order to bypass text property
9673 hooks, etc. which might not be safe to run.
9675 This may GC (insert may run before/after change hooks),
9676 so the buffer M must NOT point to a Lisp string. */
9679 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9681 const unsigned char *msg
= (const unsigned char *) m
;
9683 if (!NILP (Vmemory_full
))
9686 if (!NILP (Vmessage_log_max
))
9688 struct buffer
*oldbuf
;
9689 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9690 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9691 ptrdiff_t point_at_end
= 0;
9692 ptrdiff_t zv_at_end
= 0;
9693 Lisp_Object old_deactivate_mark
;
9694 struct gcpro gcpro1
;
9696 old_deactivate_mark
= Vdeactivate_mark
;
9697 oldbuf
= current_buffer
;
9699 /* Ensure the Messages buffer exists, and switch to it.
9700 If we created it, set the major-mode. */
9703 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9705 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9708 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9709 call0 (intern ("messages-buffer-mode"));
9712 bset_undo_list (current_buffer
, Qt
);
9713 bset_cache_long_scans (current_buffer
, Qnil
);
9715 oldpoint
= message_dolog_marker1
;
9716 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9717 oldbegv
= message_dolog_marker2
;
9718 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9719 oldzv
= message_dolog_marker3
;
9720 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9721 GCPRO1 (old_deactivate_mark
);
9729 BEGV_BYTE
= BEG_BYTE
;
9732 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9734 /* Insert the string--maybe converting multibyte to single byte
9735 or vice versa, so that all the text fits the buffer. */
9737 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9743 /* Convert a multibyte string to single-byte
9744 for the *Message* buffer. */
9745 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9747 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9748 work
[0] = (ASCII_CHAR_P (c
)
9750 : multibyte_char_to_unibyte (c
));
9751 insert_1_both (work
, 1, 1, 1, 0, 0);
9754 else if (! multibyte
9755 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9759 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9760 /* Convert a single-byte string to multibyte
9761 for the *Message* buffer. */
9762 for (i
= 0; i
< nbytes
; i
++)
9765 MAKE_CHAR_MULTIBYTE (c
);
9766 char_bytes
= CHAR_STRING (c
, str
);
9767 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9771 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9775 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9778 insert_1_both ("\n", 1, 1, 1, 0, 0);
9780 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9782 this_bol_byte
= PT_BYTE
;
9784 /* See if this line duplicates the previous one.
9785 If so, combine duplicates. */
9788 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9790 prev_bol_byte
= PT_BYTE
;
9792 dups
= message_log_check_duplicate (prev_bol_byte
,
9796 del_range_both (prev_bol
, prev_bol_byte
,
9797 this_bol
, this_bol_byte
, 0);
9800 char dupstr
[sizeof " [ times]"
9801 + INT_STRLEN_BOUND (printmax_t
)];
9803 /* If you change this format, don't forget to also
9804 change message_log_check_duplicate. */
9805 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9806 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9807 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9812 /* If we have more than the desired maximum number of lines
9813 in the *Messages* buffer now, delete the oldest ones.
9814 This is safe because we don't have undo in this buffer. */
9816 if (NATNUMP (Vmessage_log_max
))
9818 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9819 -XFASTINT (Vmessage_log_max
) - 1, 0);
9820 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9823 BEGV
= marker_position (oldbegv
);
9824 BEGV_BYTE
= marker_byte_position (oldbegv
);
9833 ZV
= marker_position (oldzv
);
9834 ZV_BYTE
= marker_byte_position (oldzv
);
9838 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9840 /* We can't do Fgoto_char (oldpoint) because it will run some
9842 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9843 marker_byte_position (oldpoint
));
9846 unchain_marker (XMARKER (oldpoint
));
9847 unchain_marker (XMARKER (oldbegv
));
9848 unchain_marker (XMARKER (oldzv
));
9850 /* We called insert_1_both above with its 5th argument (PREPARE)
9851 zero, which prevents insert_1_both from calling
9852 prepare_to_modify_buffer, which in turns prevents us from
9853 incrementing windows_or_buffers_changed even if *Messages* is
9854 shown in some window. So we must manually set
9855 windows_or_buffers_changed here to make up for that. */
9856 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9857 bset_redisplay (current_buffer
);
9859 set_buffer_internal (oldbuf
);
9861 message_log_need_newline
= !nlflag
;
9862 Vdeactivate_mark
= old_deactivate_mark
;
9867 /* We are at the end of the buffer after just having inserted a newline.
9868 (Note: We depend on the fact we won't be crossing the gap.)
9869 Check to see if the most recent message looks a lot like the previous one.
9870 Return 0 if different, 1 if the new one should just replace it, or a
9871 value N > 1 if we should also append " [N times]". */
9874 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9877 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9879 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9880 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9882 for (i
= 0; i
< len
; i
++)
9884 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9892 if (*p1
++ == ' ' && *p1
++ == '[')
9895 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9896 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9903 /* Display an echo area message M with a specified length of NBYTES
9904 bytes. The string may include null characters. If M is not a
9905 string, clear out any existing message, and let the mini-buffer
9908 This function cancels echoing. */
9911 message3 (Lisp_Object m
)
9913 struct gcpro gcpro1
;
9916 clear_message (true, true);
9919 /* First flush out any partial line written with print. */
9920 message_log_maybe_newline ();
9923 ptrdiff_t nbytes
= SBYTES (m
);
9924 bool multibyte
= STRING_MULTIBYTE (m
);
9926 char *buffer
= SAFE_ALLOCA (nbytes
);
9927 memcpy (buffer
, SDATA (m
), nbytes
);
9928 message_dolog (buffer
, nbytes
, 1, multibyte
);
9937 /* The non-logging version of message3.
9938 This does not cancel echoing, because it is used for echoing.
9939 Perhaps we need to make a separate function for echoing
9940 and make this cancel echoing. */
9943 message3_nolog (Lisp_Object m
)
9945 struct frame
*sf
= SELECTED_FRAME ();
9947 if (FRAME_INITIAL_P (sf
))
9949 if (noninteractive_need_newline
)
9950 putc ('\n', stderr
);
9951 noninteractive_need_newline
= 0;
9954 Lisp_Object s
= ENCODE_SYSTEM (m
);
9956 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9958 if (cursor_in_echo_area
== 0)
9959 fprintf (stderr
, "\n");
9962 /* Error messages get reported properly by cmd_error, so this must be just an
9963 informative message; if the frame hasn't really been initialized yet, just
9965 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9967 /* Get the frame containing the mini-buffer
9968 that the selected frame is using. */
9969 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9970 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9971 struct frame
*f
= XFRAME (frame
);
9973 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9974 Fmake_frame_visible (frame
);
9976 if (STRINGP (m
) && SCHARS (m
) > 0)
9979 if (minibuffer_auto_raise
)
9980 Fraise_frame (frame
);
9981 /* Assume we are not echoing.
9982 (If we are, echo_now will override this.) */
9983 echo_message_buffer
= Qnil
;
9986 clear_message (true, true);
9988 do_pending_window_change (0);
9989 echo_area_display (1);
9990 do_pending_window_change (0);
9991 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9992 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9997 /* Display a null-terminated echo area message M. If M is 0, clear
9998 out any existing message, and let the mini-buffer text show through.
10000 The buffer M must continue to exist until after the echo area gets
10001 cleared or some other message gets displayed there. Do not pass
10002 text that is stored in a Lisp string. Do not pass text in a buffer
10003 that was alloca'd. */
10006 message1 (const char *m
)
10008 message3 (m
? build_unibyte_string (m
) : Qnil
);
10012 /* The non-logging counterpart of message1. */
10015 message1_nolog (const char *m
)
10017 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10020 /* Display a message M which contains a single %s
10021 which gets replaced with STRING. */
10024 message_with_string (const char *m
, Lisp_Object string
, int log
)
10026 CHECK_STRING (string
);
10028 if (noninteractive
)
10032 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
10033 String whose data pointer might be passed to us in M. So
10034 we use a local copy. */
10035 char *fmt
= xstrdup (m
);
10037 if (noninteractive_need_newline
)
10038 putc ('\n', stderr
);
10039 noninteractive_need_newline
= 0;
10040 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
10041 if (!cursor_in_echo_area
)
10042 fprintf (stderr
, "\n");
10047 else if (INTERACTIVE
)
10049 /* The frame whose minibuffer we're going to display the message on.
10050 It may be larger than the selected frame, so we need
10051 to use its buffer, not the selected frame's buffer. */
10052 Lisp_Object mini_window
;
10053 struct frame
*f
, *sf
= SELECTED_FRAME ();
10055 /* Get the frame containing the minibuffer
10056 that the selected frame is using. */
10057 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10058 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10060 /* Error messages get reported properly by cmd_error, so this must be
10061 just an informative message; if the frame hasn't really been
10062 initialized yet, just toss it. */
10063 if (f
->glyphs_initialized_p
)
10065 Lisp_Object args
[2], msg
;
10066 struct gcpro gcpro1
, gcpro2
;
10068 args
[0] = build_string (m
);
10069 args
[1] = msg
= string
;
10070 GCPRO2 (args
[0], msg
);
10073 msg
= Fformat (2, args
);
10078 message3_nolog (msg
);
10082 /* Print should start at the beginning of the message
10083 buffer next time. */
10084 message_buf_print
= 0;
10090 /* Dump an informative message to the minibuf. If M is 0, clear out
10091 any existing message, and let the mini-buffer text show through. */
10094 vmessage (const char *m
, va_list ap
)
10096 if (noninteractive
)
10100 if (noninteractive_need_newline
)
10101 putc ('\n', stderr
);
10102 noninteractive_need_newline
= 0;
10103 vfprintf (stderr
, m
, ap
);
10104 if (cursor_in_echo_area
== 0)
10105 fprintf (stderr
, "\n");
10109 else if (INTERACTIVE
)
10111 /* The frame whose mini-buffer we're going to display the message
10112 on. It may be larger than the selected frame, so we need to
10113 use its buffer, not the selected frame's buffer. */
10114 Lisp_Object mini_window
;
10115 struct frame
*f
, *sf
= SELECTED_FRAME ();
10117 /* Get the frame containing the mini-buffer
10118 that the selected frame is using. */
10119 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10120 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10122 /* Error messages get reported properly by cmd_error, so this must be
10123 just an informative message; if the frame hasn't really been
10124 initialized yet, just toss it. */
10125 if (f
->glyphs_initialized_p
)
10130 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10131 char *message_buf
= alloca (maxsize
+ 1);
10133 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10135 message3 (make_string (message_buf
, len
));
10140 /* Print should start at the beginning of the message
10141 buffer next time. */
10142 message_buf_print
= 0;
10148 message (const char *m
, ...)
10158 /* The non-logging version of message. */
10161 message_nolog (const char *m
, ...)
10163 Lisp_Object old_log_max
;
10166 old_log_max
= Vmessage_log_max
;
10167 Vmessage_log_max
= Qnil
;
10169 Vmessage_log_max
= old_log_max
;
10175 /* Display the current message in the current mini-buffer. This is
10176 only called from error handlers in process.c, and is not time
10180 update_echo_area (void)
10182 if (!NILP (echo_area_buffer
[0]))
10184 Lisp_Object string
;
10185 string
= Fcurrent_message ();
10191 /* Make sure echo area buffers in `echo_buffers' are live.
10192 If they aren't, make new ones. */
10195 ensure_echo_area_buffers (void)
10199 for (i
= 0; i
< 2; ++i
)
10200 if (!BUFFERP (echo_buffer
[i
])
10201 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10204 Lisp_Object old_buffer
;
10207 old_buffer
= echo_buffer
[i
];
10208 echo_buffer
[i
] = Fget_buffer_create
10209 (make_formatted_string (name
, " *Echo Area %d*", i
));
10210 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10211 /* to force word wrap in echo area -
10212 it was decided to postpone this*/
10213 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10215 for (j
= 0; j
< 2; ++j
)
10216 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10217 echo_area_buffer
[j
] = echo_buffer
[i
];
10222 /* Call FN with args A1..A2 with either the current or last displayed
10223 echo_area_buffer as current buffer.
10225 WHICH zero means use the current message buffer
10226 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10227 from echo_buffer[] and clear it.
10229 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10230 suitable buffer from echo_buffer[] and clear it.
10232 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10233 that the current message becomes the last displayed one, make
10234 choose a suitable buffer for echo_area_buffer[0], and clear it.
10236 Value is what FN returns. */
10239 with_echo_area_buffer (struct window
*w
, int which
,
10240 int (*fn
) (ptrdiff_t, Lisp_Object
),
10241 ptrdiff_t a1
, Lisp_Object a2
)
10243 Lisp_Object buffer
;
10244 int this_one
, the_other
, clear_buffer_p
, rc
;
10245 ptrdiff_t count
= SPECPDL_INDEX ();
10247 /* If buffers aren't live, make new ones. */
10248 ensure_echo_area_buffers ();
10250 clear_buffer_p
= 0;
10253 this_one
= 0, the_other
= 1;
10254 else if (which
> 0)
10255 this_one
= 1, the_other
= 0;
10258 this_one
= 0, the_other
= 1;
10259 clear_buffer_p
= true;
10261 /* We need a fresh one in case the current echo buffer equals
10262 the one containing the last displayed echo area message. */
10263 if (!NILP (echo_area_buffer
[this_one
])
10264 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10265 echo_area_buffer
[this_one
] = Qnil
;
10268 /* Choose a suitable buffer from echo_buffer[] is we don't
10270 if (NILP (echo_area_buffer
[this_one
]))
10272 echo_area_buffer
[this_one
]
10273 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10274 ? echo_buffer
[the_other
]
10275 : echo_buffer
[this_one
]);
10276 clear_buffer_p
= true;
10279 buffer
= echo_area_buffer
[this_one
];
10281 /* Don't get confused by reusing the buffer used for echoing
10282 for a different purpose. */
10283 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10286 record_unwind_protect (unwind_with_echo_area_buffer
,
10287 with_echo_area_buffer_unwind_data (w
));
10289 /* Make the echo area buffer current. Note that for display
10290 purposes, it is not necessary that the displayed window's buffer
10291 == current_buffer, except for text property lookup. So, let's
10292 only set that buffer temporarily here without doing a full
10293 Fset_window_buffer. We must also change w->pointm, though,
10294 because otherwise an assertions in unshow_buffer fails, and Emacs
10296 set_buffer_internal_1 (XBUFFER (buffer
));
10299 wset_buffer (w
, buffer
);
10300 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10303 bset_undo_list (current_buffer
, Qt
);
10304 bset_read_only (current_buffer
, Qnil
);
10305 specbind (Qinhibit_read_only
, Qt
);
10306 specbind (Qinhibit_modification_hooks
, Qt
);
10308 if (clear_buffer_p
&& Z
> BEG
)
10309 del_range (BEG
, Z
);
10311 eassert (BEGV
>= BEG
);
10312 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10316 eassert (BEGV
>= BEG
);
10317 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10319 unbind_to (count
, Qnil
);
10324 /* Save state that should be preserved around the call to the function
10325 FN called in with_echo_area_buffer. */
10328 with_echo_area_buffer_unwind_data (struct window
*w
)
10331 Lisp_Object vector
, tmp
;
10333 /* Reduce consing by keeping one vector in
10334 Vwith_echo_area_save_vector. */
10335 vector
= Vwith_echo_area_save_vector
;
10336 Vwith_echo_area_save_vector
= Qnil
;
10339 vector
= Fmake_vector (make_number (9), Qnil
);
10341 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10342 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10343 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10347 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10348 ASET (vector
, i
, w
->contents
); ++i
;
10349 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10350 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10351 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10352 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10357 for (; i
< end
; ++i
)
10358 ASET (vector
, i
, Qnil
);
10361 eassert (i
== ASIZE (vector
));
10366 /* Restore global state from VECTOR which was created by
10367 with_echo_area_buffer_unwind_data. */
10370 unwind_with_echo_area_buffer (Lisp_Object vector
)
10372 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10373 Vdeactivate_mark
= AREF (vector
, 1);
10374 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10376 if (WINDOWP (AREF (vector
, 3)))
10379 Lisp_Object buffer
;
10381 w
= XWINDOW (AREF (vector
, 3));
10382 buffer
= AREF (vector
, 4);
10384 wset_buffer (w
, buffer
);
10385 set_marker_both (w
->pointm
, buffer
,
10386 XFASTINT (AREF (vector
, 5)),
10387 XFASTINT (AREF (vector
, 6)));
10388 set_marker_both (w
->start
, buffer
,
10389 XFASTINT (AREF (vector
, 7)),
10390 XFASTINT (AREF (vector
, 8)));
10393 Vwith_echo_area_save_vector
= vector
;
10397 /* Set up the echo area for use by print functions. MULTIBYTE_P
10398 non-zero means we will print multibyte. */
10401 setup_echo_area_for_printing (int multibyte_p
)
10403 /* If we can't find an echo area any more, exit. */
10404 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10405 Fkill_emacs (Qnil
);
10407 ensure_echo_area_buffers ();
10409 if (!message_buf_print
)
10411 /* A message has been output since the last time we printed.
10412 Choose a fresh echo area buffer. */
10413 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10414 echo_area_buffer
[0] = echo_buffer
[1];
10416 echo_area_buffer
[0] = echo_buffer
[0];
10418 /* Switch to that buffer and clear it. */
10419 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10420 bset_truncate_lines (current_buffer
, Qnil
);
10424 ptrdiff_t count
= SPECPDL_INDEX ();
10425 specbind (Qinhibit_read_only
, Qt
);
10426 /* Note that undo recording is always disabled. */
10427 del_range (BEG
, Z
);
10428 unbind_to (count
, Qnil
);
10430 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10432 /* Set up the buffer for the multibyteness we need. */
10434 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10435 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10437 /* Raise the frame containing the echo area. */
10438 if (minibuffer_auto_raise
)
10440 struct frame
*sf
= SELECTED_FRAME ();
10441 Lisp_Object mini_window
;
10442 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10443 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10446 message_log_maybe_newline ();
10447 message_buf_print
= 1;
10451 if (NILP (echo_area_buffer
[0]))
10453 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10454 echo_area_buffer
[0] = echo_buffer
[1];
10456 echo_area_buffer
[0] = echo_buffer
[0];
10459 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10461 /* Someone switched buffers between print requests. */
10462 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10463 bset_truncate_lines (current_buffer
, Qnil
);
10469 /* Display an echo area message in window W. Value is non-zero if W's
10470 height is changed. If display_last_displayed_message_p is
10471 non-zero, display the message that was last displayed, otherwise
10472 display the current message. */
10475 display_echo_area (struct window
*w
)
10477 int i
, no_message_p
, window_height_changed_p
;
10479 /* Temporarily disable garbage collections while displaying the echo
10480 area. This is done because a GC can print a message itself.
10481 That message would modify the echo area buffer's contents while a
10482 redisplay of the buffer is going on, and seriously confuse
10484 ptrdiff_t count
= inhibit_garbage_collection ();
10486 /* If there is no message, we must call display_echo_area_1
10487 nevertheless because it resizes the window. But we will have to
10488 reset the echo_area_buffer in question to nil at the end because
10489 with_echo_area_buffer will sets it to an empty buffer. */
10490 i
= display_last_displayed_message_p
? 1 : 0;
10491 no_message_p
= NILP (echo_area_buffer
[i
]);
10493 window_height_changed_p
10494 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10495 display_echo_area_1
,
10496 (intptr_t) w
, Qnil
);
10499 echo_area_buffer
[i
] = Qnil
;
10501 unbind_to (count
, Qnil
);
10502 return window_height_changed_p
;
10506 /* Helper for display_echo_area. Display the current buffer which
10507 contains the current echo area message in window W, a mini-window,
10508 a pointer to which is passed in A1. A2..A4 are currently not used.
10509 Change the height of W so that all of the message is displayed.
10510 Value is non-zero if height of W was changed. */
10513 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10516 struct window
*w
= (struct window
*) i1
;
10517 Lisp_Object window
;
10518 struct text_pos start
;
10519 int window_height_changed_p
= 0;
10521 /* Do this before displaying, so that we have a large enough glyph
10522 matrix for the display. If we can't get enough space for the
10523 whole text, display the last N lines. That works by setting w->start. */
10524 window_height_changed_p
= resize_mini_window (w
, 0);
10526 /* Use the starting position chosen by resize_mini_window. */
10527 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10530 clear_glyph_matrix (w
->desired_matrix
);
10531 XSETWINDOW (window
, w
);
10532 try_window (window
, start
, 0);
10534 return window_height_changed_p
;
10538 /* Resize the echo area window to exactly the size needed for the
10539 currently displayed message, if there is one. If a mini-buffer
10540 is active, don't shrink it. */
10543 resize_echo_area_exactly (void)
10545 if (BUFFERP (echo_area_buffer
[0])
10546 && WINDOWP (echo_area_window
))
10548 struct window
*w
= XWINDOW (echo_area_window
);
10549 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10550 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10551 (intptr_t) w
, resize_exactly
);
10554 windows_or_buffers_changed
= 42;
10555 update_mode_lines
= 30;
10556 redisplay_internal ();
10562 /* Callback function for with_echo_area_buffer, when used from
10563 resize_echo_area_exactly. A1 contains a pointer to the window to
10564 resize, EXACTLY non-nil means resize the mini-window exactly to the
10565 size of the text displayed. A3 and A4 are not used. Value is what
10566 resize_mini_window returns. */
10569 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10572 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10576 /* Resize mini-window W to fit the size of its contents. EXACT_P
10577 means size the window exactly to the size needed. Otherwise, it's
10578 only enlarged until W's buffer is empty.
10580 Set W->start to the right place to begin display. If the whole
10581 contents fit, start at the beginning. Otherwise, start so as
10582 to make the end of the contents appear. This is particularly
10583 important for y-or-n-p, but seems desirable generally.
10585 Value is non-zero if the window height has been changed. */
10588 resize_mini_window (struct window
*w
, int exact_p
)
10590 struct frame
*f
= XFRAME (w
->frame
);
10591 int window_height_changed_p
= 0;
10593 eassert (MINI_WINDOW_P (w
));
10595 /* By default, start display at the beginning. */
10596 set_marker_both (w
->start
, w
->contents
,
10597 BUF_BEGV (XBUFFER (w
->contents
)),
10598 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10600 /* Don't resize windows while redisplaying a window; it would
10601 confuse redisplay functions when the size of the window they are
10602 displaying changes from under them. Such a resizing can happen,
10603 for instance, when which-func prints a long message while
10604 we are running fontification-functions. We're running these
10605 functions with safe_call which binds inhibit-redisplay to t. */
10606 if (!NILP (Vinhibit_redisplay
))
10609 /* Nil means don't try to resize. */
10610 if (NILP (Vresize_mini_windows
)
10611 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10614 if (!FRAME_MINIBUF_ONLY_P (f
))
10617 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10618 + WINDOW_PIXEL_HEIGHT (w
));
10619 int unit
= FRAME_LINE_HEIGHT (f
);
10620 int height
, max_height
;
10621 struct text_pos start
;
10622 struct buffer
*old_current_buffer
= NULL
;
10624 if (current_buffer
!= XBUFFER (w
->contents
))
10626 old_current_buffer
= current_buffer
;
10627 set_buffer_internal (XBUFFER (w
->contents
));
10630 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10632 /* Compute the max. number of lines specified by the user. */
10633 if (FLOATP (Vmax_mini_window_height
))
10634 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10635 else if (INTEGERP (Vmax_mini_window_height
))
10636 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10638 max_height
= total_height
/ 4;
10640 /* Correct that max. height if it's bogus. */
10641 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10643 /* Find out the height of the text in the window. */
10644 if (it
.line_wrap
== TRUNCATE
)
10649 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10650 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10651 height
= it
.current_y
+ last_height
;
10653 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10654 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10657 /* Compute a suitable window start. */
10658 if (height
> max_height
)
10660 height
= max_height
;
10661 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10662 move_it_vertically_backward (&it
, height
);
10663 start
= it
.current
.pos
;
10666 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10667 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10669 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10671 /* Let it grow only, until we display an empty message, in which
10672 case the window shrinks again. */
10673 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10675 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10677 FRAME_WINDOWS_FROZEN (f
) = 1;
10678 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10679 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10681 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10682 && (exact_p
|| BEGV
== ZV
))
10684 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10686 FRAME_WINDOWS_FROZEN (f
) = 0;
10687 shrink_mini_window (w
, 1);
10688 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10693 /* Always resize to exact size needed. */
10694 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10696 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10698 FRAME_WINDOWS_FROZEN (f
) = 1;
10699 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10700 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10702 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10704 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10706 FRAME_WINDOWS_FROZEN (f
) = 0;
10707 shrink_mini_window (w
, 1);
10711 FRAME_WINDOWS_FROZEN (f
) = 1;
10712 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10715 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10719 if (old_current_buffer
)
10720 set_buffer_internal (old_current_buffer
);
10723 return window_height_changed_p
;
10727 /* Value is the current message, a string, or nil if there is no
10728 current message. */
10731 current_message (void)
10735 if (!BUFFERP (echo_area_buffer
[0]))
10739 with_echo_area_buffer (0, 0, current_message_1
,
10740 (intptr_t) &msg
, Qnil
);
10742 echo_area_buffer
[0] = Qnil
;
10750 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10753 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10756 *msg
= make_buffer_string (BEG
, Z
, 1);
10763 /* Push the current message on Vmessage_stack for later restoration
10764 by restore_message. Value is non-zero if the current message isn't
10765 empty. This is a relatively infrequent operation, so it's not
10766 worth optimizing. */
10769 push_message (void)
10771 Lisp_Object msg
= current_message ();
10772 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10773 return STRINGP (msg
);
10777 /* Restore message display from the top of Vmessage_stack. */
10780 restore_message (void)
10782 eassert (CONSP (Vmessage_stack
));
10783 message3_nolog (XCAR (Vmessage_stack
));
10787 /* Handler for unwind-protect calling pop_message. */
10790 pop_message_unwind (void)
10792 /* Pop the top-most entry off Vmessage_stack. */
10793 eassert (CONSP (Vmessage_stack
));
10794 Vmessage_stack
= XCDR (Vmessage_stack
);
10798 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10799 exits. If the stack is not empty, we have a missing pop_message
10803 check_message_stack (void)
10805 if (!NILP (Vmessage_stack
))
10810 /* Truncate to NCHARS what will be displayed in the echo area the next
10811 time we display it---but don't redisplay it now. */
10814 truncate_echo_area (ptrdiff_t nchars
)
10817 echo_area_buffer
[0] = Qnil
;
10818 else if (!noninteractive
10820 && !NILP (echo_area_buffer
[0]))
10822 struct frame
*sf
= SELECTED_FRAME ();
10823 /* Error messages get reported properly by cmd_error, so this must be
10824 just an informative message; if the frame hasn't really been
10825 initialized yet, just toss it. */
10826 if (sf
->glyphs_initialized_p
)
10827 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10832 /* Helper function for truncate_echo_area. Truncate the current
10833 message to at most NCHARS characters. */
10836 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10838 if (BEG
+ nchars
< Z
)
10839 del_range (BEG
+ nchars
, Z
);
10841 echo_area_buffer
[0] = Qnil
;
10845 /* Set the current message to STRING. */
10848 set_message (Lisp_Object string
)
10850 eassert (STRINGP (string
));
10852 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10854 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10855 message_buf_print
= 0;
10856 help_echo_showing_p
= 0;
10858 if (STRINGP (Vdebug_on_message
)
10859 && STRINGP (string
)
10860 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10861 call_debugger (list2 (Qerror
, string
));
10865 /* Helper function for set_message. First argument is ignored and second
10866 argument has the same meaning as for set_message.
10867 This function is called with the echo area buffer being current. */
10870 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10872 eassert (STRINGP (string
));
10874 /* Change multibyteness of the echo buffer appropriately. */
10875 if (message_enable_multibyte
10876 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10877 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10879 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10880 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10881 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10883 /* Insert new message at BEG. */
10884 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10886 /* This function takes care of single/multibyte conversion.
10887 We just have to ensure that the echo area buffer has the right
10888 setting of enable_multibyte_characters. */
10889 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10895 /* Clear messages. CURRENT_P non-zero means clear the current
10896 message. LAST_DISPLAYED_P non-zero means clear the message
10900 clear_message (bool current_p
, bool last_displayed_p
)
10904 echo_area_buffer
[0] = Qnil
;
10905 message_cleared_p
= true;
10908 if (last_displayed_p
)
10909 echo_area_buffer
[1] = Qnil
;
10911 message_buf_print
= 0;
10914 /* Clear garbaged frames.
10916 This function is used where the old redisplay called
10917 redraw_garbaged_frames which in turn called redraw_frame which in
10918 turn called clear_frame. The call to clear_frame was a source of
10919 flickering. I believe a clear_frame is not necessary. It should
10920 suffice in the new redisplay to invalidate all current matrices,
10921 and ensure a complete redisplay of all windows. */
10924 clear_garbaged_frames (void)
10926 if (frame_garbaged
)
10928 Lisp_Object tail
, frame
;
10930 FOR_EACH_FRAME (tail
, frame
)
10932 struct frame
*f
= XFRAME (frame
);
10934 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10939 clear_current_matrices (f
);
10940 fset_redisplay (f
);
10941 f
->garbaged
= false;
10942 f
->resized_p
= false;
10946 frame_garbaged
= false;
10951 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10952 is non-zero update selected_frame. Value is non-zero if the
10953 mini-windows height has been changed. */
10956 echo_area_display (int update_frame_p
)
10958 Lisp_Object mini_window
;
10961 int window_height_changed_p
= 0;
10962 struct frame
*sf
= SELECTED_FRAME ();
10964 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10965 w
= XWINDOW (mini_window
);
10966 f
= XFRAME (WINDOW_FRAME (w
));
10968 /* Don't display if frame is invisible or not yet initialized. */
10969 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10972 #ifdef HAVE_WINDOW_SYSTEM
10973 /* When Emacs starts, selected_frame may be the initial terminal
10974 frame. If we let this through, a message would be displayed on
10976 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10978 #endif /* HAVE_WINDOW_SYSTEM */
10980 /* Redraw garbaged frames. */
10981 clear_garbaged_frames ();
10983 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10985 echo_area_window
= mini_window
;
10986 window_height_changed_p
= display_echo_area (w
);
10987 w
->must_be_updated_p
= true;
10989 /* Update the display, unless called from redisplay_internal.
10990 Also don't update the screen during redisplay itself. The
10991 update will happen at the end of redisplay, and an update
10992 here could cause confusion. */
10993 if (update_frame_p
&& !redisplaying_p
)
10997 /* If the display update has been interrupted by pending
10998 input, update mode lines in the frame. Due to the
10999 pending input, it might have been that redisplay hasn't
11000 been called, so that mode lines above the echo area are
11001 garbaged. This looks odd, so we prevent it here. */
11002 if (!display_completed
)
11003 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11005 if (window_height_changed_p
11006 /* Don't do this if Emacs is shutting down. Redisplay
11007 needs to run hooks. */
11008 && !NILP (Vrun_hooks
))
11010 /* Must update other windows. Likewise as in other
11011 cases, don't let this update be interrupted by
11013 ptrdiff_t count
= SPECPDL_INDEX ();
11014 specbind (Qredisplay_dont_pause
, Qt
);
11015 windows_or_buffers_changed
= 44;
11016 redisplay_internal ();
11017 unbind_to (count
, Qnil
);
11019 else if (FRAME_WINDOW_P (f
) && n
== 0)
11021 /* Window configuration is the same as before.
11022 Can do with a display update of the echo area,
11023 unless we displayed some mode lines. */
11024 update_single_window (w
, 1);
11028 update_frame (f
, 1, 1);
11030 /* If cursor is in the echo area, make sure that the next
11031 redisplay displays the minibuffer, so that the cursor will
11032 be replaced with what the minibuffer wants. */
11033 if (cursor_in_echo_area
)
11034 wset_redisplay (XWINDOW (mini_window
));
11037 else if (!EQ (mini_window
, selected_window
))
11038 wset_redisplay (XWINDOW (mini_window
));
11040 /* Last displayed message is now the current message. */
11041 echo_area_buffer
[1] = echo_area_buffer
[0];
11042 /* Inform read_char that we're not echoing. */
11043 echo_message_buffer
= Qnil
;
11045 /* Prevent redisplay optimization in redisplay_internal by resetting
11046 this_line_start_pos. This is done because the mini-buffer now
11047 displays the message instead of its buffer text. */
11048 if (EQ (mini_window
, selected_window
))
11049 CHARPOS (this_line_start_pos
) = 0;
11051 return window_height_changed_p
;
11054 /* Nonzero if W's buffer was changed but not saved. */
11057 window_buffer_changed (struct window
*w
)
11059 struct buffer
*b
= XBUFFER (w
->contents
);
11061 eassert (BUFFER_LIVE_P (b
));
11063 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11066 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11069 mode_line_update_needed (struct window
*w
)
11071 return (w
->column_number_displayed
!= -1
11072 && !(PT
== w
->last_point
&& !window_outdated (w
))
11073 && (w
->column_number_displayed
!= current_column ()));
11076 /* Nonzero if window start of W is frozen and may not be changed during
11080 window_frozen_p (struct window
*w
)
11082 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11084 Lisp_Object window
;
11086 XSETWINDOW (window
, w
);
11087 if (MINI_WINDOW_P (w
))
11089 else if (EQ (window
, selected_window
))
11091 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11092 && EQ (window
, Vminibuf_scroll_window
))
11093 /* This special window can't be frozen too. */
11101 /***********************************************************************
11102 Mode Lines and Frame Titles
11103 ***********************************************************************/
11105 /* A buffer for constructing non-propertized mode-line strings and
11106 frame titles in it; allocated from the heap in init_xdisp and
11107 resized as needed in store_mode_line_noprop_char. */
11109 static char *mode_line_noprop_buf
;
11111 /* The buffer's end, and a current output position in it. */
11113 static char *mode_line_noprop_buf_end
;
11114 static char *mode_line_noprop_ptr
;
11116 #define MODE_LINE_NOPROP_LEN(start) \
11117 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11120 MODE_LINE_DISPLAY
= 0,
11124 } mode_line_target
;
11126 /* Alist that caches the results of :propertize.
11127 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11128 static Lisp_Object mode_line_proptrans_alist
;
11130 /* List of strings making up the mode-line. */
11131 static Lisp_Object mode_line_string_list
;
11133 /* Base face property when building propertized mode line string. */
11134 static Lisp_Object mode_line_string_face
;
11135 static Lisp_Object mode_line_string_face_prop
;
11138 /* Unwind data for mode line strings */
11140 static Lisp_Object Vmode_line_unwind_vector
;
11143 format_mode_line_unwind_data (struct frame
*target_frame
,
11144 struct buffer
*obuf
,
11146 int save_proptrans
)
11148 Lisp_Object vector
, tmp
;
11150 /* Reduce consing by keeping one vector in
11151 Vwith_echo_area_save_vector. */
11152 vector
= Vmode_line_unwind_vector
;
11153 Vmode_line_unwind_vector
= Qnil
;
11156 vector
= Fmake_vector (make_number (10), Qnil
);
11158 ASET (vector
, 0, make_number (mode_line_target
));
11159 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11160 ASET (vector
, 2, mode_line_string_list
);
11161 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11162 ASET (vector
, 4, mode_line_string_face
);
11163 ASET (vector
, 5, mode_line_string_face_prop
);
11166 XSETBUFFER (tmp
, obuf
);
11169 ASET (vector
, 6, tmp
);
11170 ASET (vector
, 7, owin
);
11173 /* Similarly to `with-selected-window', if the operation selects
11174 a window on another frame, we must restore that frame's
11175 selected window, and (for a tty) the top-frame. */
11176 ASET (vector
, 8, target_frame
->selected_window
);
11177 if (FRAME_TERMCAP_P (target_frame
))
11178 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11185 unwind_format_mode_line (Lisp_Object vector
)
11187 Lisp_Object old_window
= AREF (vector
, 7);
11188 Lisp_Object target_frame_window
= AREF (vector
, 8);
11189 Lisp_Object old_top_frame
= AREF (vector
, 9);
11191 mode_line_target
= XINT (AREF (vector
, 0));
11192 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11193 mode_line_string_list
= AREF (vector
, 2);
11194 if (! EQ (AREF (vector
, 3), Qt
))
11195 mode_line_proptrans_alist
= AREF (vector
, 3);
11196 mode_line_string_face
= AREF (vector
, 4);
11197 mode_line_string_face_prop
= AREF (vector
, 5);
11199 /* Select window before buffer, since it may change the buffer. */
11200 if (!NILP (old_window
))
11202 /* If the operation that we are unwinding had selected a window
11203 on a different frame, reset its frame-selected-window. For a
11204 text terminal, reset its top-frame if necessary. */
11205 if (!NILP (target_frame_window
))
11208 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11210 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11211 Fselect_window (target_frame_window
, Qt
);
11213 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11214 Fselect_frame (old_top_frame
, Qt
);
11217 Fselect_window (old_window
, Qt
);
11220 if (!NILP (AREF (vector
, 6)))
11222 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11223 ASET (vector
, 6, Qnil
);
11226 Vmode_line_unwind_vector
= vector
;
11230 /* Store a single character C for the frame title in mode_line_noprop_buf.
11231 Re-allocate mode_line_noprop_buf if necessary. */
11234 store_mode_line_noprop_char (char c
)
11236 /* If output position has reached the end of the allocated buffer,
11237 increase the buffer's size. */
11238 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11240 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11241 ptrdiff_t size
= len
;
11242 mode_line_noprop_buf
=
11243 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11244 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11245 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11248 *mode_line_noprop_ptr
++ = c
;
11252 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11253 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11254 characters that yield more columns than PRECISION; PRECISION <= 0
11255 means copy the whole string. Pad with spaces until FIELD_WIDTH
11256 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11257 pad. Called from display_mode_element when it is used to build a
11261 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11263 const unsigned char *str
= (const unsigned char *) string
;
11265 ptrdiff_t dummy
, nbytes
;
11267 /* Copy at most PRECISION chars from STR. */
11268 nbytes
= strlen (string
);
11269 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11271 store_mode_line_noprop_char (*str
++);
11273 /* Fill up with spaces until FIELD_WIDTH reached. */
11274 while (field_width
> 0
11275 && n
< field_width
)
11277 store_mode_line_noprop_char (' ');
11284 /***********************************************************************
11286 ***********************************************************************/
11288 #ifdef HAVE_WINDOW_SYSTEM
11290 /* Set the title of FRAME, if it has changed. The title format is
11291 Vicon_title_format if FRAME is iconified, otherwise it is
11292 frame_title_format. */
11295 x_consider_frame_title (Lisp_Object frame
)
11297 struct frame
*f
= XFRAME (frame
);
11299 if (FRAME_WINDOW_P (f
)
11300 || FRAME_MINIBUF_ONLY_P (f
)
11301 || f
->explicit_name
)
11303 /* Do we have more than one visible frame on this X display? */
11304 Lisp_Object tail
, other_frame
, fmt
;
11305 ptrdiff_t title_start
;
11309 ptrdiff_t count
= SPECPDL_INDEX ();
11311 FOR_EACH_FRAME (tail
, other_frame
)
11313 struct frame
*tf
= XFRAME (other_frame
);
11316 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11317 && !FRAME_MINIBUF_ONLY_P (tf
)
11318 && !EQ (other_frame
, tip_frame
)
11319 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11323 /* Set global variable indicating that multiple frames exist. */
11324 multiple_frames
= CONSP (tail
);
11326 /* Switch to the buffer of selected window of the frame. Set up
11327 mode_line_target so that display_mode_element will output into
11328 mode_line_noprop_buf; then display the title. */
11329 record_unwind_protect (unwind_format_mode_line
,
11330 format_mode_line_unwind_data
11331 (f
, current_buffer
, selected_window
, 0));
11333 Fselect_window (f
->selected_window
, Qt
);
11334 set_buffer_internal_1
11335 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11336 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11338 mode_line_target
= MODE_LINE_TITLE
;
11339 title_start
= MODE_LINE_NOPROP_LEN (0);
11340 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11341 NULL
, DEFAULT_FACE_ID
);
11342 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11343 len
= MODE_LINE_NOPROP_LEN (title_start
);
11344 title
= mode_line_noprop_buf
+ title_start
;
11345 unbind_to (count
, Qnil
);
11347 /* Set the title only if it's changed. This avoids consing in
11348 the common case where it hasn't. (If it turns out that we've
11349 already wasted too much time by walking through the list with
11350 display_mode_element, then we might need to optimize at a
11351 higher level than this.) */
11352 if (! STRINGP (f
->name
)
11353 || SBYTES (f
->name
) != len
11354 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11355 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11359 #endif /* not HAVE_WINDOW_SYSTEM */
11362 /***********************************************************************
11364 ***********************************************************************/
11366 /* Non-zero if we will not redisplay all visible windows. */
11367 #define REDISPLAY_SOME_P() \
11368 ((windows_or_buffers_changed == 0 \
11369 || windows_or_buffers_changed == REDISPLAY_SOME) \
11370 && (update_mode_lines == 0 \
11371 || update_mode_lines == REDISPLAY_SOME))
11373 /* Prepare for redisplay by updating menu-bar item lists when
11374 appropriate. This can call eval. */
11377 prepare_menu_bars (void)
11379 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11380 bool some_windows
= REDISPLAY_SOME_P ();
11381 struct gcpro gcpro1
, gcpro2
;
11382 Lisp_Object tooltip_frame
;
11384 #ifdef HAVE_WINDOW_SYSTEM
11385 tooltip_frame
= tip_frame
;
11387 tooltip_frame
= Qnil
;
11390 if (FUNCTIONP (Vpre_redisplay_function
))
11392 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11393 if (all_windows
&& some_windows
)
11395 Lisp_Object ws
= window_list ();
11396 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11398 Lisp_Object
this = XCAR (ws
);
11399 struct window
*w
= XWINDOW (this);
11401 || XFRAME (w
->frame
)->redisplay
11402 || XBUFFER (w
->contents
)->text
->redisplay
)
11404 windows
= Fcons (this, windows
);
11408 safe_call1 (Vpre_redisplay_function
, windows
);
11411 /* Update all frame titles based on their buffer names, etc. We do
11412 this before the menu bars so that the buffer-menu will show the
11413 up-to-date frame titles. */
11414 #ifdef HAVE_WINDOW_SYSTEM
11417 Lisp_Object tail
, frame
;
11419 FOR_EACH_FRAME (tail
, frame
)
11421 struct frame
*f
= XFRAME (frame
);
11422 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11426 && !XBUFFER (w
->contents
)->text
->redisplay
)
11429 if (!EQ (frame
, tooltip_frame
)
11430 && (FRAME_ICONIFIED_P (f
)
11431 || FRAME_VISIBLE_P (f
) == 1
11432 /* Exclude TTY frames that are obscured because they
11433 are not the top frame on their console. This is
11434 because x_consider_frame_title actually switches
11435 to the frame, which for TTY frames means it is
11436 marked as garbaged, and will be completely
11437 redrawn on the next redisplay cycle. This causes
11438 TTY frames to be completely redrawn, when there
11439 are more than one of them, even though nothing
11440 should be changed on display. */
11441 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11442 x_consider_frame_title (frame
);
11445 #endif /* HAVE_WINDOW_SYSTEM */
11447 /* Update the menu bar item lists, if appropriate. This has to be
11448 done before any actual redisplay or generation of display lines. */
11452 Lisp_Object tail
, frame
;
11453 ptrdiff_t count
= SPECPDL_INDEX ();
11454 /* 1 means that update_menu_bar has run its hooks
11455 so any further calls to update_menu_bar shouldn't do so again. */
11456 int menu_bar_hooks_run
= 0;
11458 record_unwind_save_match_data ();
11460 FOR_EACH_FRAME (tail
, frame
)
11462 struct frame
*f
= XFRAME (frame
);
11463 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11465 /* Ignore tooltip frame. */
11466 if (EQ (frame
, tooltip_frame
))
11472 && !XBUFFER (w
->contents
)->text
->redisplay
)
11475 /* If a window on this frame changed size, report that to
11476 the user and clear the size-change flag. */
11477 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11479 Lisp_Object functions
;
11481 /* Clear flag first in case we get an error below. */
11482 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11483 functions
= Vwindow_size_change_functions
;
11484 GCPRO2 (tail
, functions
);
11486 while (CONSP (functions
))
11488 if (!EQ (XCAR (functions
), Qt
))
11489 call1 (XCAR (functions
), frame
);
11490 functions
= XCDR (functions
);
11496 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11497 #ifdef HAVE_WINDOW_SYSTEM
11498 update_tool_bar (f
, 0);
11501 if (windows_or_buffers_changed
11504 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11509 unbind_to (count
, Qnil
);
11513 struct frame
*sf
= SELECTED_FRAME ();
11514 update_menu_bar (sf
, 1, 0);
11515 #ifdef HAVE_WINDOW_SYSTEM
11516 update_tool_bar (sf
, 1);
11522 /* Update the menu bar item list for frame F. This has to be done
11523 before we start to fill in any display lines, because it can call
11526 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11528 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11529 already ran the menu bar hooks for this redisplay, so there
11530 is no need to run them again. The return value is the
11531 updated value of this flag, to pass to the next call. */
11534 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11536 Lisp_Object window
;
11537 register struct window
*w
;
11539 /* If called recursively during a menu update, do nothing. This can
11540 happen when, for instance, an activate-menubar-hook causes a
11542 if (inhibit_menubar_update
)
11545 window
= FRAME_SELECTED_WINDOW (f
);
11546 w
= XWINDOW (window
);
11548 if (FRAME_WINDOW_P (f
)
11550 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11551 || defined (HAVE_NS) || defined (USE_GTK)
11552 FRAME_EXTERNAL_MENU_BAR (f
)
11554 FRAME_MENU_BAR_LINES (f
) > 0
11556 : FRAME_MENU_BAR_LINES (f
) > 0)
11558 /* If the user has switched buffers or windows, we need to
11559 recompute to reflect the new bindings. But we'll
11560 recompute when update_mode_lines is set too; that means
11561 that people can use force-mode-line-update to request
11562 that the menu bar be recomputed. The adverse effect on
11563 the rest of the redisplay algorithm is about the same as
11564 windows_or_buffers_changed anyway. */
11565 if (windows_or_buffers_changed
11566 /* This used to test w->update_mode_line, but we believe
11567 there is no need to recompute the menu in that case. */
11568 || update_mode_lines
11569 || window_buffer_changed (w
))
11571 struct buffer
*prev
= current_buffer
;
11572 ptrdiff_t count
= SPECPDL_INDEX ();
11574 specbind (Qinhibit_menubar_update
, Qt
);
11576 set_buffer_internal_1 (XBUFFER (w
->contents
));
11577 if (save_match_data
)
11578 record_unwind_save_match_data ();
11579 if (NILP (Voverriding_local_map_menu_flag
))
11581 specbind (Qoverriding_terminal_local_map
, Qnil
);
11582 specbind (Qoverriding_local_map
, Qnil
);
11587 /* Run the Lucid hook. */
11588 safe_run_hooks (Qactivate_menubar_hook
);
11590 /* If it has changed current-menubar from previous value,
11591 really recompute the menu-bar from the value. */
11592 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11593 call0 (Qrecompute_lucid_menubar
);
11595 safe_run_hooks (Qmenu_bar_update_hook
);
11600 XSETFRAME (Vmenu_updating_frame
, f
);
11601 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11603 /* Redisplay the menu bar in case we changed it. */
11604 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11605 || defined (HAVE_NS) || defined (USE_GTK)
11606 if (FRAME_WINDOW_P (f
))
11608 #if defined (HAVE_NS)
11609 /* All frames on Mac OS share the same menubar. So only
11610 the selected frame should be allowed to set it. */
11611 if (f
== SELECTED_FRAME ())
11613 set_frame_menubar (f
, 0, 0);
11616 /* On a terminal screen, the menu bar is an ordinary screen
11617 line, and this makes it get updated. */
11618 w
->update_mode_line
= 1;
11619 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11620 /* In the non-toolkit version, the menu bar is an ordinary screen
11621 line, and this makes it get updated. */
11622 w
->update_mode_line
= 1;
11623 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11625 unbind_to (count
, Qnil
);
11626 set_buffer_internal_1 (prev
);
11633 /***********************************************************************
11635 ***********************************************************************/
11637 #ifdef HAVE_WINDOW_SYSTEM
11639 /* Tool-bar item index of the item on which a mouse button was pressed
11642 int last_tool_bar_item
;
11644 /* Select `frame' temporarily without running all the code in
11646 FIXME: Maybe do_switch_frame should be trimmed down similarly
11647 when `norecord' is set. */
11649 fast_set_selected_frame (Lisp_Object frame
)
11651 if (!EQ (selected_frame
, frame
))
11653 selected_frame
= frame
;
11654 selected_window
= XFRAME (frame
)->selected_window
;
11658 /* Update the tool-bar item list for frame F. This has to be done
11659 before we start to fill in any display lines. Called from
11660 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11661 and restore it here. */
11664 update_tool_bar (struct frame
*f
, int save_match_data
)
11666 #if defined (USE_GTK) || defined (HAVE_NS)
11667 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11669 int do_update
= (WINDOWP (f
->tool_bar_window
)
11670 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0);
11675 Lisp_Object window
;
11678 window
= FRAME_SELECTED_WINDOW (f
);
11679 w
= XWINDOW (window
);
11681 /* If the user has switched buffers or windows, we need to
11682 recompute to reflect the new bindings. But we'll
11683 recompute when update_mode_lines is set too; that means
11684 that people can use force-mode-line-update to request
11685 that the menu bar be recomputed. The adverse effect on
11686 the rest of the redisplay algorithm is about the same as
11687 windows_or_buffers_changed anyway. */
11688 if (windows_or_buffers_changed
11689 || w
->update_mode_line
11690 || update_mode_lines
11691 || window_buffer_changed (w
))
11693 struct buffer
*prev
= current_buffer
;
11694 ptrdiff_t count
= SPECPDL_INDEX ();
11695 Lisp_Object frame
, new_tool_bar
;
11696 int new_n_tool_bar
;
11697 struct gcpro gcpro1
;
11699 /* Set current_buffer to the buffer of the selected
11700 window of the frame, so that we get the right local
11702 set_buffer_internal_1 (XBUFFER (w
->contents
));
11704 /* Save match data, if we must. */
11705 if (save_match_data
)
11706 record_unwind_save_match_data ();
11708 /* Make sure that we don't accidentally use bogus keymaps. */
11709 if (NILP (Voverriding_local_map_menu_flag
))
11711 specbind (Qoverriding_terminal_local_map
, Qnil
);
11712 specbind (Qoverriding_local_map
, Qnil
);
11715 GCPRO1 (new_tool_bar
);
11717 /* We must temporarily set the selected frame to this frame
11718 before calling tool_bar_items, because the calculation of
11719 the tool-bar keymap uses the selected frame (see
11720 `tool-bar-make-keymap' in tool-bar.el). */
11721 eassert (EQ (selected_window
,
11722 /* Since we only explicitly preserve selected_frame,
11723 check that selected_window would be redundant. */
11724 XFRAME (selected_frame
)->selected_window
));
11725 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11726 XSETFRAME (frame
, f
);
11727 fast_set_selected_frame (frame
);
11729 /* Build desired tool-bar items from keymaps. */
11731 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11734 /* Redisplay the tool-bar if we changed it. */
11735 if (new_n_tool_bar
!= f
->n_tool_bar_items
11736 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11738 /* Redisplay that happens asynchronously due to an expose event
11739 may access f->tool_bar_items. Make sure we update both
11740 variables within BLOCK_INPUT so no such event interrupts. */
11742 fset_tool_bar_items (f
, new_tool_bar
);
11743 f
->n_tool_bar_items
= new_n_tool_bar
;
11744 w
->update_mode_line
= 1;
11750 unbind_to (count
, Qnil
);
11751 set_buffer_internal_1 (prev
);
11756 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11758 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11759 F's desired tool-bar contents. F->tool_bar_items must have
11760 been set up previously by calling prepare_menu_bars. */
11763 build_desired_tool_bar_string (struct frame
*f
)
11765 int i
, size
, size_needed
;
11766 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11767 Lisp_Object image
, plist
, props
;
11769 image
= plist
= props
= Qnil
;
11770 GCPRO3 (image
, plist
, props
);
11772 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11773 Otherwise, make a new string. */
11775 /* The size of the string we might be able to reuse. */
11776 size
= (STRINGP (f
->desired_tool_bar_string
)
11777 ? SCHARS (f
->desired_tool_bar_string
)
11780 /* We need one space in the string for each image. */
11781 size_needed
= f
->n_tool_bar_items
;
11783 /* Reuse f->desired_tool_bar_string, if possible. */
11784 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11785 fset_desired_tool_bar_string
11786 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11789 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11790 Fremove_text_properties (make_number (0), make_number (size
),
11791 props
, f
->desired_tool_bar_string
);
11794 /* Put a `display' property on the string for the images to display,
11795 put a `menu_item' property on tool-bar items with a value that
11796 is the index of the item in F's tool-bar item vector. */
11797 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11799 #define PROP(IDX) \
11800 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11802 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11803 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11804 int hmargin
, vmargin
, relief
, idx
, end
;
11806 /* If image is a vector, choose the image according to the
11808 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11809 if (VECTORP (image
))
11813 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11814 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11817 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11818 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11820 eassert (ASIZE (image
) >= idx
);
11821 image
= AREF (image
, idx
);
11826 /* Ignore invalid image specifications. */
11827 if (!valid_image_p (image
))
11830 /* Display the tool-bar button pressed, or depressed. */
11831 plist
= Fcopy_sequence (XCDR (image
));
11833 /* Compute margin and relief to draw. */
11834 relief
= (tool_bar_button_relief
>= 0
11835 ? tool_bar_button_relief
11836 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11837 hmargin
= vmargin
= relief
;
11839 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11840 INT_MAX
- max (hmargin
, vmargin
)))
11842 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11843 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11845 else if (CONSP (Vtool_bar_button_margin
))
11847 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11848 INT_MAX
- hmargin
))
11849 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11851 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11852 INT_MAX
- vmargin
))
11853 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11856 if (auto_raise_tool_bar_buttons_p
)
11858 /* Add a `:relief' property to the image spec if the item is
11862 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11869 /* If image is selected, display it pressed, i.e. with a
11870 negative relief. If it's not selected, display it with a
11872 plist
= Fplist_put (plist
, QCrelief
,
11874 ? make_number (-relief
)
11875 : make_number (relief
)));
11880 /* Put a margin around the image. */
11881 if (hmargin
|| vmargin
)
11883 if (hmargin
== vmargin
)
11884 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11886 plist
= Fplist_put (plist
, QCmargin
,
11887 Fcons (make_number (hmargin
),
11888 make_number (vmargin
)));
11891 /* If button is not enabled, and we don't have special images
11892 for the disabled state, make the image appear disabled by
11893 applying an appropriate algorithm to it. */
11894 if (!enabled_p
&& idx
< 0)
11895 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11897 /* Put a `display' text property on the string for the image to
11898 display. Put a `menu-item' property on the string that gives
11899 the start of this item's properties in the tool-bar items
11901 image
= Fcons (Qimage
, plist
);
11902 props
= list4 (Qdisplay
, image
,
11903 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11905 /* Let the last image hide all remaining spaces in the tool bar
11906 string. The string can be longer than needed when we reuse a
11907 previous string. */
11908 if (i
+ 1 == f
->n_tool_bar_items
)
11909 end
= SCHARS (f
->desired_tool_bar_string
);
11912 Fadd_text_properties (make_number (i
), make_number (end
),
11913 props
, f
->desired_tool_bar_string
);
11921 /* Display one line of the tool-bar of frame IT->f.
11923 HEIGHT specifies the desired height of the tool-bar line.
11924 If the actual height of the glyph row is less than HEIGHT, the
11925 row's height is increased to HEIGHT, and the icons are centered
11926 vertically in the new height.
11928 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11929 count a final empty row in case the tool-bar width exactly matches
11934 display_tool_bar_line (struct it
*it
, int height
)
11936 struct glyph_row
*row
= it
->glyph_row
;
11937 int max_x
= it
->last_visible_x
;
11938 struct glyph
*last
;
11940 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
11941 clear_glyph_row (row
);
11942 row
->enabled_p
= true;
11943 row
->y
= it
->current_y
;
11945 /* Note that this isn't made use of if the face hasn't a box,
11946 so there's no need to check the face here. */
11947 it
->start_of_box_run_p
= 1;
11949 while (it
->current_x
< max_x
)
11951 int x
, n_glyphs_before
, i
, nglyphs
;
11952 struct it it_before
;
11954 /* Get the next display element. */
11955 if (!get_next_display_element (it
))
11957 /* Don't count empty row if we are counting needed tool-bar lines. */
11958 if (height
< 0 && !it
->hpos
)
11963 /* Produce glyphs. */
11964 n_glyphs_before
= row
->used
[TEXT_AREA
];
11967 PRODUCE_GLYPHS (it
);
11969 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11971 x
= it_before
.current_x
;
11972 while (i
< nglyphs
)
11974 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11976 if (x
+ glyph
->pixel_width
> max_x
)
11978 /* Glyph doesn't fit on line. Backtrack. */
11979 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11981 /* If this is the only glyph on this line, it will never fit on the
11982 tool-bar, so skip it. But ensure there is at least one glyph,
11983 so we don't accidentally disable the tool-bar. */
11984 if (n_glyphs_before
== 0
11985 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11991 x
+= glyph
->pixel_width
;
11995 /* Stop at line end. */
11996 if (ITERATOR_AT_END_OF_LINE_P (it
))
11999 set_iterator_to_next (it
, 1);
12004 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12006 /* Use default face for the border below the tool bar.
12008 FIXME: When auto-resize-tool-bars is grow-only, there is
12009 no additional border below the possibly empty tool-bar lines.
12010 So to make the extra empty lines look "normal", we have to
12011 use the tool-bar face for the border too. */
12012 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12013 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12014 it
->face_id
= DEFAULT_FACE_ID
;
12016 extend_face_to_end_of_line (it
);
12017 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12018 last
->right_box_line_p
= 1;
12019 if (last
== row
->glyphs
[TEXT_AREA
])
12020 last
->left_box_line_p
= 1;
12022 /* Make line the desired height and center it vertically. */
12023 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12025 /* Don't add more than one line height. */
12026 height
%= FRAME_LINE_HEIGHT (it
->f
);
12027 it
->max_ascent
+= height
/ 2;
12028 it
->max_descent
+= (height
+ 1) / 2;
12031 compute_line_metrics (it
);
12033 /* If line is empty, make it occupy the rest of the tool-bar. */
12034 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12036 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12037 row
->visible_height
= row
->height
;
12038 row
->ascent
= row
->phys_ascent
= 0;
12039 row
->extra_line_spacing
= 0;
12042 row
->full_width_p
= 1;
12043 row
->continued_p
= 0;
12044 row
->truncated_on_left_p
= 0;
12045 row
->truncated_on_right_p
= 0;
12047 it
->current_x
= it
->hpos
= 0;
12048 it
->current_y
+= row
->height
;
12054 /* Max tool-bar height. Basically, this is what makes all other windows
12055 disappear when the frame gets too small. Rethink this! */
12057 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
12058 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
12060 /* Value is the number of screen lines needed to make all tool-bar
12061 items of frame F visible. The number of actual rows needed is
12062 returned in *N_ROWS if non-NULL. */
12065 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12067 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12069 /* tool_bar_height is called from redisplay_tool_bar after building
12070 the desired matrix, so use (unused) mode-line row as temporary row to
12071 avoid destroying the first tool-bar row. */
12072 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12074 /* Initialize an iterator for iteration over
12075 F->desired_tool_bar_string in the tool-bar window of frame F. */
12076 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12077 it
.first_visible_x
= 0;
12078 /* PXW: Use FRAME_PIXEL_WIDTH (f) here? */
12079 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12080 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12081 it
.paragraph_embedding
= L2R
;
12083 while (!ITERATOR_AT_END_P (&it
))
12085 clear_glyph_row (temp_row
);
12086 it
.glyph_row
= temp_row
;
12087 display_tool_bar_line (&it
, -1);
12089 clear_glyph_row (temp_row
);
12091 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12093 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12096 return it
.current_y
;
12098 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12101 #endif /* !USE_GTK && !HAVE_NS */
12103 #if defined USE_GTK || defined HAVE_NS
12104 EXFUN (Ftool_bar_height
, 2) ATTRIBUTE_CONST
;
12105 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
12108 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12110 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12111 If FRAME is nil or omitted, use the selected frame. Optional argument
12112 PIXELWISE non-nil means return the height of the tool bar inpixels. */)
12113 (Lisp_Object frame
, Lisp_Object pixelwise
)
12117 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12118 struct frame
*f
= decode_any_frame (frame
);
12120 if (WINDOWP (f
->tool_bar_window
)
12121 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12123 update_tool_bar (f
, 1);
12124 if (f
->n_tool_bar_items
)
12126 build_desired_tool_bar_string (f
);
12127 height
= tool_bar_height (f
, NULL
, NILP (pixelwise
) ? 0 : 1);
12132 return make_number (height
);
12136 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12137 height should be changed. */
12140 redisplay_tool_bar (struct frame
*f
)
12142 #if defined (USE_GTK) || defined (HAVE_NS)
12144 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12145 update_frame_tool_bar (f
);
12148 #else /* !USE_GTK && !HAVE_NS */
12152 struct glyph_row
*row
;
12154 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12155 do anything. This means you must start with tool-bar-lines
12156 non-zero to get the auto-sizing effect. Or in other words, you
12157 can turn off tool-bars by specifying tool-bar-lines zero. */
12158 if (!WINDOWP (f
->tool_bar_window
)
12159 || (w
= XWINDOW (f
->tool_bar_window
),
12160 WINDOW_PIXEL_HEIGHT (w
) == 0))
12163 /* Set up an iterator for the tool-bar window. */
12164 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12165 it
.first_visible_x
= 0;
12166 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12167 row
= it
.glyph_row
;
12169 /* Build a string that represents the contents of the tool-bar. */
12170 build_desired_tool_bar_string (f
);
12171 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12172 /* FIXME: This should be controlled by a user option. But it
12173 doesn't make sense to have an R2L tool bar if the menu bar cannot
12174 be drawn also R2L, and making the menu bar R2L is tricky due
12175 toolkit-specific code that implements it. If an R2L tool bar is
12176 ever supported, display_tool_bar_line should also be augmented to
12177 call unproduce_glyphs like display_line and display_string
12179 it
.paragraph_embedding
= L2R
;
12181 if (f
->n_tool_bar_rows
== 0)
12183 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, 1);
12185 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12188 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12189 / FRAME_LINE_HEIGHT (f
));
12191 XSETFRAME (frame
, f
);
12192 Fmodify_frame_parameters (frame
,
12193 list1 (Fcons (Qtool_bar_lines
,
12194 make_number (new_lines
))));
12195 /* Always do that now. */
12196 clear_glyph_matrix (w
->desired_matrix
);
12197 f
->fonts_changed
= 1;
12202 /* Display as many lines as needed to display all tool-bar items. */
12204 if (f
->n_tool_bar_rows
> 0)
12206 int border
, rows
, height
, extra
;
12208 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12209 border
= XINT (Vtool_bar_border
);
12210 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12211 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12212 else if (EQ (Vtool_bar_border
, Qborder_width
))
12213 border
= f
->border_width
;
12219 rows
= f
->n_tool_bar_rows
;
12220 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12221 extra
= it
.last_visible_y
- border
- height
* rows
;
12223 while (it
.current_y
< it
.last_visible_y
)
12226 if (extra
> 0 && rows
-- > 0)
12228 h
= (extra
+ rows
- 1) / rows
;
12231 display_tool_bar_line (&it
, height
+ h
);
12236 while (it
.current_y
< it
.last_visible_y
)
12237 display_tool_bar_line (&it
, 0);
12240 /* It doesn't make much sense to try scrolling in the tool-bar
12241 window, so don't do it. */
12242 w
->desired_matrix
->no_scrolling_p
= 1;
12243 w
->must_be_updated_p
= 1;
12245 if (!NILP (Vauto_resize_tool_bars
))
12247 /* Do we really allow the toolbar to occupy the whole frame? */
12248 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12249 int change_height_p
= 0;
12251 /* If we couldn't display everything, change the tool-bar's
12252 height if there is room for more. */
12253 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12254 && it
.current_y
< max_tool_bar_height
)
12255 change_height_p
= 1;
12257 row
= it
.glyph_row
- 1;
12259 /* If there are blank lines at the end, except for a partially
12260 visible blank line at the end that is smaller than
12261 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12262 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12263 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12264 change_height_p
= 1;
12266 /* If row displays tool-bar items, but is partially visible,
12267 change the tool-bar's height. */
12268 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12269 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12270 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12271 change_height_p
= 1;
12273 /* Resize windows as needed by changing the `tool-bar-lines'
12274 frame parameter. */
12275 if (change_height_p
)
12279 int new_height
= tool_bar_height (f
, &nrows
, 1);
12281 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12282 && !f
->minimize_tool_bar_window_p
)
12283 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12284 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12285 f
->minimize_tool_bar_window_p
= 0;
12287 if (change_height_p
)
12289 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12290 / FRAME_LINE_HEIGHT (f
));
12292 XSETFRAME (frame
, f
);
12293 Fmodify_frame_parameters (frame
,
12294 list1 (Fcons (Qtool_bar_lines
,
12295 make_number (new_lines
))));
12296 /* Always do that now. */
12297 clear_glyph_matrix (w
->desired_matrix
);
12298 f
->n_tool_bar_rows
= nrows
;
12299 f
->fonts_changed
= 1;
12305 f
->minimize_tool_bar_window_p
= 0;
12308 #endif /* USE_GTK || HAVE_NS */
12311 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12313 /* Get information about the tool-bar item which is displayed in GLYPH
12314 on frame F. Return in *PROP_IDX the index where tool-bar item
12315 properties start in F->tool_bar_items. Value is zero if
12316 GLYPH doesn't display a tool-bar item. */
12319 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12325 /* This function can be called asynchronously, which means we must
12326 exclude any possibility that Fget_text_property signals an
12328 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12329 charpos
= max (0, charpos
);
12331 /* Get the text property `menu-item' at pos. The value of that
12332 property is the start index of this item's properties in
12333 F->tool_bar_items. */
12334 prop
= Fget_text_property (make_number (charpos
),
12335 Qmenu_item
, f
->current_tool_bar_string
);
12336 if (INTEGERP (prop
))
12338 *prop_idx
= XINT (prop
);
12348 /* Get information about the tool-bar item at position X/Y on frame F.
12349 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12350 the current matrix of the tool-bar window of F, or NULL if not
12351 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12352 item in F->tool_bar_items. Value is
12354 -1 if X/Y is not on a tool-bar item
12355 0 if X/Y is on the same item that was highlighted before.
12359 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12360 int *hpos
, int *vpos
, int *prop_idx
)
12362 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12363 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12366 /* Find the glyph under X/Y. */
12367 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12368 if (*glyph
== NULL
)
12371 /* Get the start of this tool-bar item's properties in
12372 f->tool_bar_items. */
12373 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12376 /* Is mouse on the highlighted item? */
12377 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12378 && *vpos
>= hlinfo
->mouse_face_beg_row
12379 && *vpos
<= hlinfo
->mouse_face_end_row
12380 && (*vpos
> hlinfo
->mouse_face_beg_row
12381 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12382 && (*vpos
< hlinfo
->mouse_face_end_row
12383 || *hpos
< hlinfo
->mouse_face_end_col
12384 || hlinfo
->mouse_face_past_end
))
12392 Handle mouse button event on the tool-bar of frame F, at
12393 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12394 0 for button release. MODIFIERS is event modifiers for button
12398 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12401 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12402 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12403 int hpos
, vpos
, prop_idx
;
12404 struct glyph
*glyph
;
12405 Lisp_Object enabled_p
;
12408 /* If not on the highlighted tool-bar item, and mouse-highlight is
12409 non-nil, return. This is so we generate the tool-bar button
12410 click only when the mouse button is released on the same item as
12411 where it was pressed. However, when mouse-highlight is disabled,
12412 generate the click when the button is released regardless of the
12413 highlight, since tool-bar items are not highlighted in that
12415 frame_to_window_pixel_xy (w
, &x
, &y
);
12416 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12418 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12421 /* When mouse-highlight is off, generate the click for the item
12422 where the button was pressed, disregarding where it was
12424 if (NILP (Vmouse_highlight
) && !down_p
)
12425 prop_idx
= last_tool_bar_item
;
12427 /* If item is disabled, do nothing. */
12428 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12429 if (NILP (enabled_p
))
12434 /* Show item in pressed state. */
12435 if (!NILP (Vmouse_highlight
))
12436 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12437 last_tool_bar_item
= prop_idx
;
12441 Lisp_Object key
, frame
;
12442 struct input_event event
;
12443 EVENT_INIT (event
);
12445 /* Show item in released state. */
12446 if (!NILP (Vmouse_highlight
))
12447 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12449 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12451 XSETFRAME (frame
, f
);
12452 event
.kind
= TOOL_BAR_EVENT
;
12453 event
.frame_or_window
= frame
;
12455 kbd_buffer_store_event (&event
);
12457 event
.kind
= TOOL_BAR_EVENT
;
12458 event
.frame_or_window
= frame
;
12460 event
.modifiers
= modifiers
;
12461 kbd_buffer_store_event (&event
);
12462 last_tool_bar_item
= -1;
12467 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12468 tool-bar window-relative coordinates X/Y. Called from
12469 note_mouse_highlight. */
12472 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12474 Lisp_Object window
= f
->tool_bar_window
;
12475 struct window
*w
= XWINDOW (window
);
12476 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12477 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12479 struct glyph
*glyph
;
12480 struct glyph_row
*row
;
12482 Lisp_Object enabled_p
;
12484 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12485 int mouse_down_p
, rc
;
12487 /* Function note_mouse_highlight is called with negative X/Y
12488 values when mouse moves outside of the frame. */
12489 if (x
<= 0 || y
<= 0)
12491 clear_mouse_face (hlinfo
);
12495 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12498 /* Not on tool-bar item. */
12499 clear_mouse_face (hlinfo
);
12503 /* On same tool-bar item as before. */
12504 goto set_help_echo
;
12506 clear_mouse_face (hlinfo
);
12508 /* Mouse is down, but on different tool-bar item? */
12509 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12510 && f
== dpyinfo
->last_mouse_frame
);
12513 && last_tool_bar_item
!= prop_idx
)
12516 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12518 /* If tool-bar item is not enabled, don't highlight it. */
12519 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12520 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12522 /* Compute the x-position of the glyph. In front and past the
12523 image is a space. We include this in the highlighted area. */
12524 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12525 for (i
= x
= 0; i
< hpos
; ++i
)
12526 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12528 /* Record this as the current active region. */
12529 hlinfo
->mouse_face_beg_col
= hpos
;
12530 hlinfo
->mouse_face_beg_row
= vpos
;
12531 hlinfo
->mouse_face_beg_x
= x
;
12532 hlinfo
->mouse_face_past_end
= 0;
12534 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12535 hlinfo
->mouse_face_end_row
= vpos
;
12536 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12537 hlinfo
->mouse_face_window
= window
;
12538 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12540 /* Display it as active. */
12541 show_mouse_face (hlinfo
, draw
);
12546 /* Set help_echo_string to a help string to display for this tool-bar item.
12547 XTread_socket does the rest. */
12548 help_echo_object
= help_echo_window
= Qnil
;
12549 help_echo_pos
= -1;
12550 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12551 if (NILP (help_echo_string
))
12552 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12555 #endif /* !USE_GTK && !HAVE_NS */
12557 #endif /* HAVE_WINDOW_SYSTEM */
12561 /************************************************************************
12562 Horizontal scrolling
12563 ************************************************************************/
12565 static int hscroll_window_tree (Lisp_Object
);
12566 static int hscroll_windows (Lisp_Object
);
12568 /* For all leaf windows in the window tree rooted at WINDOW, set their
12569 hscroll value so that PT is (i) visible in the window, and (ii) so
12570 that it is not within a certain margin at the window's left and
12571 right border. Value is non-zero if any window's hscroll has been
12575 hscroll_window_tree (Lisp_Object window
)
12577 int hscrolled_p
= 0;
12578 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12579 int hscroll_step_abs
= 0;
12580 double hscroll_step_rel
= 0;
12582 if (hscroll_relative_p
)
12584 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12585 if (hscroll_step_rel
< 0)
12587 hscroll_relative_p
= 0;
12588 hscroll_step_abs
= 0;
12591 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12593 hscroll_step_abs
= XINT (Vhscroll_step
);
12594 if (hscroll_step_abs
< 0)
12595 hscroll_step_abs
= 0;
12598 hscroll_step_abs
= 0;
12600 while (WINDOWP (window
))
12602 struct window
*w
= XWINDOW (window
);
12604 if (WINDOWP (w
->contents
))
12605 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12606 else if (w
->cursor
.vpos
>= 0)
12609 int text_area_width
;
12610 struct glyph_row
*current_cursor_row
12611 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12612 struct glyph_row
*desired_cursor_row
12613 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12614 struct glyph_row
*cursor_row
12615 = (desired_cursor_row
->enabled_p
12616 ? desired_cursor_row
12617 : current_cursor_row
);
12618 int row_r2l_p
= cursor_row
->reversed_p
;
12620 text_area_width
= window_box_width (w
, TEXT_AREA
);
12622 /* Scroll when cursor is inside this scroll margin. */
12623 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12625 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12626 /* For left-to-right rows, hscroll when cursor is either
12627 (i) inside the right hscroll margin, or (ii) if it is
12628 inside the left margin and the window is already
12632 && w
->cursor
.x
<= h_margin
)
12633 || (cursor_row
->enabled_p
12634 && cursor_row
->truncated_on_right_p
12635 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12636 /* For right-to-left rows, the logic is similar,
12637 except that rules for scrolling to left and right
12638 are reversed. E.g., if cursor.x <= h_margin, we
12639 need to hscroll "to the right" unconditionally,
12640 and that will scroll the screen to the left so as
12641 to reveal the next portion of the row. */
12643 && ((cursor_row
->enabled_p
12644 /* FIXME: It is confusing to set the
12645 truncated_on_right_p flag when R2L rows
12646 are actually truncated on the left. */
12647 && cursor_row
->truncated_on_right_p
12648 && w
->cursor
.x
<= h_margin
)
12650 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12654 struct buffer
*saved_current_buffer
;
12658 /* Find point in a display of infinite width. */
12659 saved_current_buffer
= current_buffer
;
12660 current_buffer
= XBUFFER (w
->contents
);
12662 if (w
== XWINDOW (selected_window
))
12665 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12667 /* Move iterator to pt starting at cursor_row->start in
12668 a line with infinite width. */
12669 init_to_row_start (&it
, w
, cursor_row
);
12670 it
.last_visible_x
= INFINITY
;
12671 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12672 current_buffer
= saved_current_buffer
;
12674 /* Position cursor in window. */
12675 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12676 hscroll
= max (0, (it
.current_x
12677 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12678 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12679 : (text_area_width
/ 2))))
12680 / FRAME_COLUMN_WIDTH (it
.f
);
12681 else if ((!row_r2l_p
12682 && w
->cursor
.x
>= text_area_width
- h_margin
)
12683 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12685 if (hscroll_relative_p
)
12686 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12689 wanted_x
= text_area_width
12690 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12693 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12697 if (hscroll_relative_p
)
12698 wanted_x
= text_area_width
* hscroll_step_rel
12701 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12704 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12706 hscroll
= max (hscroll
, w
->min_hscroll
);
12708 /* Don't prevent redisplay optimizations if hscroll
12709 hasn't changed, as it will unnecessarily slow down
12711 if (w
->hscroll
!= hscroll
)
12713 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12714 w
->hscroll
= hscroll
;
12723 /* Value is non-zero if hscroll of any leaf window has been changed. */
12724 return hscrolled_p
;
12728 /* Set hscroll so that cursor is visible and not inside horizontal
12729 scroll margins for all windows in the tree rooted at WINDOW. See
12730 also hscroll_window_tree above. Value is non-zero if any window's
12731 hscroll has been changed. If it has, desired matrices on the frame
12732 of WINDOW are cleared. */
12735 hscroll_windows (Lisp_Object window
)
12737 int hscrolled_p
= hscroll_window_tree (window
);
12739 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12740 return hscrolled_p
;
12745 /************************************************************************
12747 ************************************************************************/
12749 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12750 to a non-zero value. This is sometimes handy to have in a debugger
12755 /* First and last unchanged row for try_window_id. */
12757 static int debug_first_unchanged_at_end_vpos
;
12758 static int debug_last_unchanged_at_beg_vpos
;
12760 /* Delta vpos and y. */
12762 static int debug_dvpos
, debug_dy
;
12764 /* Delta in characters and bytes for try_window_id. */
12766 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12768 /* Values of window_end_pos and window_end_vpos at the end of
12771 static ptrdiff_t debug_end_vpos
;
12773 /* Append a string to W->desired_matrix->method. FMT is a printf
12774 format string. If trace_redisplay_p is true also printf the
12775 resulting string to stderr. */
12777 static void debug_method_add (struct window
*, char const *, ...)
12778 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12781 debug_method_add (struct window
*w
, char const *fmt
, ...)
12784 char *method
= w
->desired_matrix
->method
;
12785 int len
= strlen (method
);
12786 int size
= sizeof w
->desired_matrix
->method
;
12787 int remaining
= size
- len
- 1;
12790 if (len
&& remaining
)
12793 --remaining
, ++len
;
12796 va_start (ap
, fmt
);
12797 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12800 if (trace_redisplay_p
)
12801 fprintf (stderr
, "%p (%s): %s\n",
12803 ((BUFFERP (w
->contents
)
12804 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12805 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12810 #endif /* GLYPH_DEBUG */
12813 /* Value is non-zero if all changes in window W, which displays
12814 current_buffer, are in the text between START and END. START is a
12815 buffer position, END is given as a distance from Z. Used in
12816 redisplay_internal for display optimization. */
12819 text_outside_line_unchanged_p (struct window
*w
,
12820 ptrdiff_t start
, ptrdiff_t end
)
12822 int unchanged_p
= 1;
12824 /* If text or overlays have changed, see where. */
12825 if (window_outdated (w
))
12827 /* Gap in the line? */
12828 if (GPT
< start
|| Z
- GPT
< end
)
12831 /* Changes start in front of the line, or end after it? */
12833 && (BEG_UNCHANGED
< start
- 1
12834 || END_UNCHANGED
< end
))
12837 /* If selective display, can't optimize if changes start at the
12838 beginning of the line. */
12840 && INTEGERP (BVAR (current_buffer
, selective_display
))
12841 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12842 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12845 /* If there are overlays at the start or end of the line, these
12846 may have overlay strings with newlines in them. A change at
12847 START, for instance, may actually concern the display of such
12848 overlay strings as well, and they are displayed on different
12849 lines. So, quickly rule out this case. (For the future, it
12850 might be desirable to implement something more telling than
12851 just BEG/END_UNCHANGED.) */
12854 if (BEG
+ BEG_UNCHANGED
== start
12855 && overlay_touches_p (start
))
12857 if (END_UNCHANGED
== end
12858 && overlay_touches_p (Z
- end
))
12862 /* Under bidi reordering, adding or deleting a character in the
12863 beginning of a paragraph, before the first strong directional
12864 character, can change the base direction of the paragraph (unless
12865 the buffer specifies a fixed paragraph direction), which will
12866 require to redisplay the whole paragraph. It might be worthwhile
12867 to find the paragraph limits and widen the range of redisplayed
12868 lines to that, but for now just give up this optimization. */
12869 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12870 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12874 return unchanged_p
;
12878 /* Do a frame update, taking possible shortcuts into account. This is
12879 the main external entry point for redisplay.
12881 If the last redisplay displayed an echo area message and that message
12882 is no longer requested, we clear the echo area or bring back the
12883 mini-buffer if that is in use. */
12888 redisplay_internal ();
12893 overlay_arrow_string_or_property (Lisp_Object var
)
12897 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12900 return Voverlay_arrow_string
;
12903 /* Return 1 if there are any overlay-arrows in current_buffer. */
12905 overlay_arrow_in_current_buffer_p (void)
12909 for (vlist
= Voverlay_arrow_variable_list
;
12911 vlist
= XCDR (vlist
))
12913 Lisp_Object var
= XCAR (vlist
);
12916 if (!SYMBOLP (var
))
12918 val
= find_symbol_value (var
);
12920 && current_buffer
== XMARKER (val
)->buffer
)
12927 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12931 overlay_arrows_changed_p (void)
12935 for (vlist
= Voverlay_arrow_variable_list
;
12937 vlist
= XCDR (vlist
))
12939 Lisp_Object var
= XCAR (vlist
);
12940 Lisp_Object val
, pstr
;
12942 if (!SYMBOLP (var
))
12944 val
= find_symbol_value (var
);
12945 if (!MARKERP (val
))
12947 if (! EQ (COERCE_MARKER (val
),
12948 Fget (var
, Qlast_arrow_position
))
12949 || ! (pstr
= overlay_arrow_string_or_property (var
),
12950 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12956 /* Mark overlay arrows to be updated on next redisplay. */
12959 update_overlay_arrows (int up_to_date
)
12963 for (vlist
= Voverlay_arrow_variable_list
;
12965 vlist
= XCDR (vlist
))
12967 Lisp_Object var
= XCAR (vlist
);
12969 if (!SYMBOLP (var
))
12972 if (up_to_date
> 0)
12974 Lisp_Object val
= find_symbol_value (var
);
12975 Fput (var
, Qlast_arrow_position
,
12976 COERCE_MARKER (val
));
12977 Fput (var
, Qlast_arrow_string
,
12978 overlay_arrow_string_or_property (var
));
12980 else if (up_to_date
< 0
12981 || !NILP (Fget (var
, Qlast_arrow_position
)))
12983 Fput (var
, Qlast_arrow_position
, Qt
);
12984 Fput (var
, Qlast_arrow_string
, Qt
);
12990 /* Return overlay arrow string to display at row.
12991 Return integer (bitmap number) for arrow bitmap in left fringe.
12992 Return nil if no overlay arrow. */
12995 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12999 for (vlist
= Voverlay_arrow_variable_list
;
13001 vlist
= XCDR (vlist
))
13003 Lisp_Object var
= XCAR (vlist
);
13006 if (!SYMBOLP (var
))
13009 val
= find_symbol_value (var
);
13012 && current_buffer
== XMARKER (val
)->buffer
13013 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13015 if (FRAME_WINDOW_P (it
->f
)
13016 /* FIXME: if ROW->reversed_p is set, this should test
13017 the right fringe, not the left one. */
13018 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13020 #ifdef HAVE_WINDOW_SYSTEM
13021 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13024 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
13025 return make_number (fringe_bitmap
);
13028 return make_number (-1); /* Use default arrow bitmap. */
13030 return overlay_arrow_string_or_property (var
);
13037 /* Return 1 if point moved out of or into a composition. Otherwise
13038 return 0. PREV_BUF and PREV_PT are the last point buffer and
13039 position. BUF and PT are the current point buffer and position. */
13042 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13043 struct buffer
*buf
, ptrdiff_t pt
)
13045 ptrdiff_t start
, end
;
13047 Lisp_Object buffer
;
13049 XSETBUFFER (buffer
, buf
);
13050 /* Check a composition at the last point if point moved within the
13052 if (prev_buf
== buf
)
13055 /* Point didn't move. */
13058 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13059 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13060 && composition_valid_p (start
, end
, prop
)
13061 && start
< prev_pt
&& end
> prev_pt
)
13062 /* The last point was within the composition. Return 1 iff
13063 point moved out of the composition. */
13064 return (pt
<= start
|| pt
>= end
);
13067 /* Check a composition at the current point. */
13068 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13069 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13070 && composition_valid_p (start
, end
, prop
)
13071 && start
< pt
&& end
> pt
);
13074 /* Reconsider the clip changes of buffer which is displayed in W. */
13077 reconsider_clip_changes (struct window
*w
)
13079 struct buffer
*b
= XBUFFER (w
->contents
);
13081 if (b
->clip_changed
13082 && w
->window_end_valid
13083 && w
->current_matrix
->buffer
== b
13084 && w
->current_matrix
->zv
== BUF_ZV (b
)
13085 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13086 b
->clip_changed
= 0;
13088 /* If display wasn't paused, and W is not a tool bar window, see if
13089 point has been moved into or out of a composition. In that case,
13090 we set b->clip_changed to 1 to force updating the screen. If
13091 b->clip_changed has already been set to 1, we can skip this
13093 if (!b
->clip_changed
&& w
->window_end_valid
)
13095 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13096 ? PT
: marker_position (w
->pointm
));
13098 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13099 && check_point_in_composition (w
->current_matrix
->buffer
,
13100 w
->last_point
, b
, pt
))
13101 b
->clip_changed
= 1;
13106 propagate_buffer_redisplay (void)
13107 { /* Resetting b->text->redisplay is problematic!
13108 We can't just reset it in the case that some window that displays
13109 it has not been redisplayed; and such a window can stay
13110 unredisplayed for a long time if it's currently invisible.
13111 But we do want to reset it at the end of redisplay otherwise
13112 its displayed windows will keep being redisplayed over and over
13114 So we copy all b->text->redisplay flags up to their windows here,
13115 such that mark_window_display_accurate can safely reset
13116 b->text->redisplay. */
13117 Lisp_Object ws
= window_list ();
13118 for (; CONSP (ws
); ws
= XCDR (ws
))
13120 struct window
*thisw
= XWINDOW (XCAR (ws
));
13121 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13122 if (thisb
->text
->redisplay
)
13123 thisw
->redisplay
= true;
13127 #define STOP_POLLING \
13128 do { if (! polling_stopped_here) stop_polling (); \
13129 polling_stopped_here = 1; } while (0)
13131 #define RESUME_POLLING \
13132 do { if (polling_stopped_here) start_polling (); \
13133 polling_stopped_here = 0; } while (0)
13136 /* Perhaps in the future avoid recentering windows if it
13137 is not necessary; currently that causes some problems. */
13140 redisplay_internal (void)
13142 struct window
*w
= XWINDOW (selected_window
);
13146 bool must_finish
= 0, match_p
;
13147 struct text_pos tlbufpos
, tlendpos
;
13148 int number_of_visible_frames
;
13151 int polling_stopped_here
= 0;
13152 Lisp_Object tail
, frame
;
13154 /* True means redisplay has to consider all windows on all
13155 frames. False, only selected_window is considered. */
13156 bool consider_all_windows_p
;
13158 /* True means redisplay has to redisplay the miniwindow. */
13159 bool update_miniwindow_p
= false;
13161 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13163 /* No redisplay if running in batch mode or frame is not yet fully
13164 initialized, or redisplay is explicitly turned off by setting
13165 Vinhibit_redisplay. */
13166 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13167 || !NILP (Vinhibit_redisplay
))
13170 /* Don't examine these until after testing Vinhibit_redisplay.
13171 When Emacs is shutting down, perhaps because its connection to
13172 X has dropped, we should not look at them at all. */
13173 fr
= XFRAME (w
->frame
);
13174 sf
= SELECTED_FRAME ();
13176 if (!fr
->glyphs_initialized_p
)
13179 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13180 if (popup_activated ())
13184 /* I don't think this happens but let's be paranoid. */
13185 if (redisplaying_p
)
13188 /* Record a function that clears redisplaying_p
13189 when we leave this function. */
13190 count
= SPECPDL_INDEX ();
13191 record_unwind_protect_void (unwind_redisplay
);
13192 redisplaying_p
= 1;
13193 specbind (Qinhibit_free_realized_faces
, Qnil
);
13195 /* Record this function, so it appears on the profiler's backtraces. */
13196 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13198 FOR_EACH_FRAME (tail
, frame
)
13199 XFRAME (frame
)->already_hscrolled_p
= 0;
13202 /* Remember the currently selected window. */
13206 last_escape_glyph_frame
= NULL
;
13207 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13208 last_glyphless_glyph_frame
= NULL
;
13209 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13211 /* If face_change_count is non-zero, init_iterator will free all
13212 realized faces, which includes the faces referenced from current
13213 matrices. So, we can't reuse current matrices in this case. */
13214 if (face_change_count
)
13215 windows_or_buffers_changed
= 47;
13217 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13218 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13220 /* Since frames on a single ASCII terminal share the same
13221 display area, displaying a different frame means redisplay
13222 the whole thing. */
13223 SET_FRAME_GARBAGED (sf
);
13225 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13227 FRAME_TTY (sf
)->previous_frame
= sf
;
13230 /* Set the visible flags for all frames. Do this before checking for
13231 resized or garbaged frames; they want to know if their frames are
13232 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13233 number_of_visible_frames
= 0;
13235 FOR_EACH_FRAME (tail
, frame
)
13237 struct frame
*f
= XFRAME (frame
);
13239 if (FRAME_VISIBLE_P (f
))
13241 ++number_of_visible_frames
;
13242 /* Adjust matrices for visible frames only. */
13243 if (f
->fonts_changed
)
13245 adjust_frame_glyphs (f
);
13246 f
->fonts_changed
= 0;
13248 /* If cursor type has been changed on the frame
13249 other than selected, consider all frames. */
13250 if (f
!= sf
&& f
->cursor_type_changed
)
13251 update_mode_lines
= 31;
13253 clear_desired_matrices (f
);
13256 /* Notice any pending interrupt request to change frame size. */
13257 do_pending_window_change (1);
13259 /* do_pending_window_change could change the selected_window due to
13260 frame resizing which makes the selected window too small. */
13261 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13264 /* Clear frames marked as garbaged. */
13265 clear_garbaged_frames ();
13267 /* Build menubar and tool-bar items. */
13268 if (NILP (Vmemory_full
))
13269 prepare_menu_bars ();
13271 reconsider_clip_changes (w
);
13273 /* In most cases selected window displays current buffer. */
13274 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13277 /* Detect case that we need to write or remove a star in the mode line. */
13278 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13279 w
->update_mode_line
= 1;
13281 if (mode_line_update_needed (w
))
13282 w
->update_mode_line
= 1;
13285 /* Normally the message* functions will have already displayed and
13286 updated the echo area, but the frame may have been trashed, or
13287 the update may have been preempted, so display the echo area
13288 again here. Checking message_cleared_p captures the case that
13289 the echo area should be cleared. */
13290 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13291 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13292 || (message_cleared_p
13293 && minibuf_level
== 0
13294 /* If the mini-window is currently selected, this means the
13295 echo-area doesn't show through. */
13296 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13298 int window_height_changed_p
= echo_area_display (0);
13300 if (message_cleared_p
)
13301 update_miniwindow_p
= true;
13305 /* If we don't display the current message, don't clear the
13306 message_cleared_p flag, because, if we did, we wouldn't clear
13307 the echo area in the next redisplay which doesn't preserve
13309 if (!display_last_displayed_message_p
)
13310 message_cleared_p
= 0;
13312 if (window_height_changed_p
)
13314 windows_or_buffers_changed
= 50;
13316 /* If window configuration was changed, frames may have been
13317 marked garbaged. Clear them or we will experience
13318 surprises wrt scrolling. */
13319 clear_garbaged_frames ();
13322 else if (EQ (selected_window
, minibuf_window
)
13323 && (current_buffer
->clip_changed
|| window_outdated (w
))
13324 && resize_mini_window (w
, 0))
13326 /* Resized active mini-window to fit the size of what it is
13327 showing if its contents might have changed. */
13330 /* If window configuration was changed, frames may have been
13331 marked garbaged. Clear them or we will experience
13332 surprises wrt scrolling. */
13333 clear_garbaged_frames ();
13336 if (windows_or_buffers_changed
&& !update_mode_lines
)
13337 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13338 only the windows's contents needs to be refreshed, or whether the
13339 mode-lines also need a refresh. */
13340 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13341 ? REDISPLAY_SOME
: 32);
13343 /* If specs for an arrow have changed, do thorough redisplay
13344 to ensure we remove any arrow that should no longer exist. */
13345 if (overlay_arrows_changed_p ())
13346 /* Apparently, this is the only case where we update other windows,
13347 without updating other mode-lines. */
13348 windows_or_buffers_changed
= 49;
13350 consider_all_windows_p
= (update_mode_lines
13351 || windows_or_buffers_changed
);
13353 #define AINC(a,i) \
13354 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13355 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13357 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13358 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13360 /* Optimize the case that only the line containing the cursor in the
13361 selected window has changed. Variables starting with this_ are
13362 set in display_line and record information about the line
13363 containing the cursor. */
13364 tlbufpos
= this_line_start_pos
;
13365 tlendpos
= this_line_end_pos
;
13366 if (!consider_all_windows_p
13367 && CHARPOS (tlbufpos
) > 0
13368 && !w
->update_mode_line
13369 && !current_buffer
->clip_changed
13370 && !current_buffer
->prevent_redisplay_optimizations_p
13371 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13372 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13373 && !XFRAME (w
->frame
)->cursor_type_changed
13374 /* Make sure recorded data applies to current buffer, etc. */
13375 && this_line_buffer
== current_buffer
13378 && !w
->optional_new_start
13379 /* Point must be on the line that we have info recorded about. */
13380 && PT
>= CHARPOS (tlbufpos
)
13381 && PT
<= Z
- CHARPOS (tlendpos
)
13382 /* All text outside that line, including its final newline,
13383 must be unchanged. */
13384 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13385 CHARPOS (tlendpos
)))
13387 if (CHARPOS (tlbufpos
) > BEGV
13388 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13389 && (CHARPOS (tlbufpos
) == ZV
13390 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13391 /* Former continuation line has disappeared by becoming empty. */
13393 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13395 /* We have to handle the case of continuation around a
13396 wide-column character (see the comment in indent.c around
13399 For instance, in the following case:
13401 -------- Insert --------
13402 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13403 J_I_ ==> J_I_ `^^' are cursors.
13407 As we have to redraw the line above, we cannot use this
13411 int line_height_before
= this_line_pixel_height
;
13413 /* Note that start_display will handle the case that the
13414 line starting at tlbufpos is a continuation line. */
13415 start_display (&it
, w
, tlbufpos
);
13417 /* Implementation note: It this still necessary? */
13418 if (it
.current_x
!= this_line_start_x
)
13421 TRACE ((stderr
, "trying display optimization 1\n"));
13422 w
->cursor
.vpos
= -1;
13423 overlay_arrow_seen
= 0;
13424 it
.vpos
= this_line_vpos
;
13425 it
.current_y
= this_line_y
;
13426 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13427 display_line (&it
);
13429 /* If line contains point, is not continued,
13430 and ends at same distance from eob as before, we win. */
13431 if (w
->cursor
.vpos
>= 0
13432 /* Line is not continued, otherwise this_line_start_pos
13433 would have been set to 0 in display_line. */
13434 && CHARPOS (this_line_start_pos
)
13435 /* Line ends as before. */
13436 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13437 /* Line has same height as before. Otherwise other lines
13438 would have to be shifted up or down. */
13439 && this_line_pixel_height
== line_height_before
)
13441 /* If this is not the window's last line, we must adjust
13442 the charstarts of the lines below. */
13443 if (it
.current_y
< it
.last_visible_y
)
13445 struct glyph_row
*row
13446 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13447 ptrdiff_t delta
, delta_bytes
;
13449 /* We used to distinguish between two cases here,
13450 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13451 when the line ends in a newline or the end of the
13452 buffer's accessible portion. But both cases did
13453 the same, so they were collapsed. */
13455 - CHARPOS (tlendpos
)
13456 - MATRIX_ROW_START_CHARPOS (row
));
13457 delta_bytes
= (Z_BYTE
13458 - BYTEPOS (tlendpos
)
13459 - MATRIX_ROW_START_BYTEPOS (row
));
13461 increment_matrix_positions (w
->current_matrix
,
13462 this_line_vpos
+ 1,
13463 w
->current_matrix
->nrows
,
13464 delta
, delta_bytes
);
13467 /* If this row displays text now but previously didn't,
13468 or vice versa, w->window_end_vpos may have to be
13470 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13472 if (w
->window_end_vpos
< this_line_vpos
)
13473 w
->window_end_vpos
= this_line_vpos
;
13475 else if (w
->window_end_vpos
== this_line_vpos
13476 && this_line_vpos
> 0)
13477 w
->window_end_vpos
= this_line_vpos
- 1;
13478 w
->window_end_valid
= 0;
13480 /* Update hint: No need to try to scroll in update_window. */
13481 w
->desired_matrix
->no_scrolling_p
= 1;
13484 *w
->desired_matrix
->method
= 0;
13485 debug_method_add (w
, "optimization 1");
13487 #ifdef HAVE_WINDOW_SYSTEM
13488 update_window_fringes (w
, 0);
13495 else if (/* Cursor position hasn't changed. */
13496 PT
== w
->last_point
13497 /* Make sure the cursor was last displayed
13498 in this window. Otherwise we have to reposition it. */
13500 /* PXW: Must be converted to pixels, probably. */
13501 && 0 <= w
->cursor
.vpos
13502 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13506 do_pending_window_change (1);
13507 /* If selected_window changed, redisplay again. */
13508 if (WINDOWP (selected_window
)
13509 && (w
= XWINDOW (selected_window
)) != sw
)
13512 /* We used to always goto end_of_redisplay here, but this
13513 isn't enough if we have a blinking cursor. */
13514 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13515 goto end_of_redisplay
;
13519 /* If highlighting the region, or if the cursor is in the echo area,
13520 then we can't just move the cursor. */
13521 else if (NILP (Vshow_trailing_whitespace
)
13522 && !cursor_in_echo_area
)
13525 struct glyph_row
*row
;
13527 /* Skip from tlbufpos to PT and see where it is. Note that
13528 PT may be in invisible text. If so, we will end at the
13529 next visible position. */
13530 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13531 NULL
, DEFAULT_FACE_ID
);
13532 it
.current_x
= this_line_start_x
;
13533 it
.current_y
= this_line_y
;
13534 it
.vpos
= this_line_vpos
;
13536 /* The call to move_it_to stops in front of PT, but
13537 moves over before-strings. */
13538 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13540 if (it
.vpos
== this_line_vpos
13541 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13544 eassert (this_line_vpos
== it
.vpos
);
13545 eassert (this_line_y
== it
.current_y
);
13546 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13548 *w
->desired_matrix
->method
= 0;
13549 debug_method_add (w
, "optimization 3");
13558 /* Text changed drastically or point moved off of line. */
13559 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13562 CHARPOS (this_line_start_pos
) = 0;
13563 ++clear_face_cache_count
;
13564 #ifdef HAVE_WINDOW_SYSTEM
13565 ++clear_image_cache_count
;
13568 /* Build desired matrices, and update the display. If
13569 consider_all_windows_p is non-zero, do it for all windows on all
13570 frames. Otherwise do it for selected_window, only. */
13572 if (consider_all_windows_p
)
13574 FOR_EACH_FRAME (tail
, frame
)
13575 XFRAME (frame
)->updated_p
= 0;
13577 propagate_buffer_redisplay ();
13579 FOR_EACH_FRAME (tail
, frame
)
13581 struct frame
*f
= XFRAME (frame
);
13583 /* We don't have to do anything for unselected terminal
13585 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13586 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13591 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13594 /* Only GC scrollbars when we redisplay the whole frame. */
13595 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13596 /* Mark all the scroll bars to be removed; we'll redeem
13597 the ones we want when we redisplay their windows. */
13598 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13599 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13601 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13602 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13603 /* Remember that the invisible frames need to be redisplayed next
13604 time they're visible. */
13605 else if (!REDISPLAY_SOME_P ())
13606 f
->redisplay
= true;
13608 /* The X error handler may have deleted that frame. */
13609 if (!FRAME_LIVE_P (f
))
13612 /* Any scroll bars which redisplay_windows should have
13613 nuked should now go away. */
13614 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13615 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13617 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13619 /* If fonts changed on visible frame, display again. */
13620 if (f
->fonts_changed
)
13622 adjust_frame_glyphs (f
);
13623 f
->fonts_changed
= 0;
13627 /* See if we have to hscroll. */
13628 if (!f
->already_hscrolled_p
)
13630 f
->already_hscrolled_p
= 1;
13631 if (hscroll_windows (f
->root_window
))
13635 /* Prevent various kinds of signals during display
13636 update. stdio is not robust about handling
13637 signals, which can cause an apparent I/O error. */
13638 if (interrupt_input
)
13639 unrequest_sigio ();
13642 pending
|= update_frame (f
, 0, 0);
13643 f
->cursor_type_changed
= 0;
13649 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13653 /* Do the mark_window_display_accurate after all windows have
13654 been redisplayed because this call resets flags in buffers
13655 which are needed for proper redisplay. */
13656 FOR_EACH_FRAME (tail
, frame
)
13658 struct frame
*f
= XFRAME (frame
);
13661 f
->redisplay
= false;
13662 mark_window_display_accurate (f
->root_window
, 1);
13663 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13664 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13669 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13671 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13672 struct frame
*mini_frame
;
13674 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13675 /* Use list_of_error, not Qerror, so that
13676 we catch only errors and don't run the debugger. */
13677 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13679 redisplay_window_error
);
13680 if (update_miniwindow_p
)
13681 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13683 redisplay_window_error
);
13685 /* Compare desired and current matrices, perform output. */
13688 /* If fonts changed, display again. */
13689 if (sf
->fonts_changed
)
13692 /* Prevent various kinds of signals during display update.
13693 stdio is not robust about handling signals,
13694 which can cause an apparent I/O error. */
13695 if (interrupt_input
)
13696 unrequest_sigio ();
13699 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13701 if (hscroll_windows (selected_window
))
13704 XWINDOW (selected_window
)->must_be_updated_p
= true;
13705 pending
= update_frame (sf
, 0, 0);
13706 sf
->cursor_type_changed
= 0;
13709 /* We may have called echo_area_display at the top of this
13710 function. If the echo area is on another frame, that may
13711 have put text on a frame other than the selected one, so the
13712 above call to update_frame would not have caught it. Catch
13714 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13715 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13717 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13719 XWINDOW (mini_window
)->must_be_updated_p
= true;
13720 pending
|= update_frame (mini_frame
, 0, 0);
13721 mini_frame
->cursor_type_changed
= 0;
13722 if (!pending
&& hscroll_windows (mini_window
))
13727 /* If display was paused because of pending input, make sure we do a
13728 thorough update the next time. */
13731 /* Prevent the optimization at the beginning of
13732 redisplay_internal that tries a single-line update of the
13733 line containing the cursor in the selected window. */
13734 CHARPOS (this_line_start_pos
) = 0;
13736 /* Let the overlay arrow be updated the next time. */
13737 update_overlay_arrows (0);
13739 /* If we pause after scrolling, some rows in the current
13740 matrices of some windows are not valid. */
13741 if (!WINDOW_FULL_WIDTH_P (w
)
13742 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13743 update_mode_lines
= 36;
13747 if (!consider_all_windows_p
)
13749 /* This has already been done above if
13750 consider_all_windows_p is set. */
13751 if (XBUFFER (w
->contents
)->text
->redisplay
13752 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13753 /* This can happen if b->text->redisplay was set during
13755 propagate_buffer_redisplay ();
13756 mark_window_display_accurate_1 (w
, 1);
13758 /* Say overlay arrows are up to date. */
13759 update_overlay_arrows (1);
13761 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13762 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13765 update_mode_lines
= 0;
13766 windows_or_buffers_changed
= 0;
13769 /* Start SIGIO interrupts coming again. Having them off during the
13770 code above makes it less likely one will discard output, but not
13771 impossible, since there might be stuff in the system buffer here.
13772 But it is much hairier to try to do anything about that. */
13773 if (interrupt_input
)
13777 /* If a frame has become visible which was not before, redisplay
13778 again, so that we display it. Expose events for such a frame
13779 (which it gets when becoming visible) don't call the parts of
13780 redisplay constructing glyphs, so simply exposing a frame won't
13781 display anything in this case. So, we have to display these
13782 frames here explicitly. */
13787 FOR_EACH_FRAME (tail
, frame
)
13789 if (XFRAME (frame
)->visible
)
13793 if (new_count
!= number_of_visible_frames
)
13794 windows_or_buffers_changed
= 52;
13797 /* Change frame size now if a change is pending. */
13798 do_pending_window_change (1);
13800 /* If we just did a pending size change, or have additional
13801 visible frames, or selected_window changed, redisplay again. */
13802 if ((windows_or_buffers_changed
&& !pending
)
13803 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13806 /* Clear the face and image caches.
13808 We used to do this only if consider_all_windows_p. But the cache
13809 needs to be cleared if a timer creates images in the current
13810 buffer (e.g. the test case in Bug#6230). */
13812 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13814 clear_face_cache (0);
13815 clear_face_cache_count
= 0;
13818 #ifdef HAVE_WINDOW_SYSTEM
13819 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13821 clear_image_caches (Qnil
);
13822 clear_image_cache_count
= 0;
13824 #endif /* HAVE_WINDOW_SYSTEM */
13827 if (interrupt_input
&& interrupts_deferred
)
13830 unbind_to (count
, Qnil
);
13835 /* Redisplay, but leave alone any recent echo area message unless
13836 another message has been requested in its place.
13838 This is useful in situations where you need to redisplay but no
13839 user action has occurred, making it inappropriate for the message
13840 area to be cleared. See tracking_off and
13841 wait_reading_process_output for examples of these situations.
13843 FROM_WHERE is an integer saying from where this function was
13844 called. This is useful for debugging. */
13847 redisplay_preserve_echo_area (int from_where
)
13849 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13851 if (!NILP (echo_area_buffer
[1]))
13853 /* We have a previously displayed message, but no current
13854 message. Redisplay the previous message. */
13855 display_last_displayed_message_p
= 1;
13856 redisplay_internal ();
13857 display_last_displayed_message_p
= 0;
13860 redisplay_internal ();
13862 flush_frame (SELECTED_FRAME ());
13866 /* Function registered with record_unwind_protect in redisplay_internal. */
13869 unwind_redisplay (void)
13871 redisplaying_p
= 0;
13875 /* Mark the display of leaf window W as accurate or inaccurate.
13876 If ACCURATE_P is non-zero mark display of W as accurate. If
13877 ACCURATE_P is zero, arrange for W to be redisplayed the next
13878 time redisplay_internal is called. */
13881 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13883 struct buffer
*b
= XBUFFER (w
->contents
);
13885 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13886 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13887 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13891 b
->clip_changed
= false;
13892 b
->prevent_redisplay_optimizations_p
= false;
13893 eassert (buffer_window_count (b
) > 0);
13894 /* Resetting b->text->redisplay is problematic!
13895 In order to make it safer to do it here, redisplay_internal must
13896 have copied all b->text->redisplay to their respective windows. */
13897 b
->text
->redisplay
= false;
13899 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13900 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13901 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13902 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13904 w
->current_matrix
->buffer
= b
;
13905 w
->current_matrix
->begv
= BUF_BEGV (b
);
13906 w
->current_matrix
->zv
= BUF_ZV (b
);
13908 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13909 w
->last_cursor_off_p
= w
->cursor_off_p
;
13911 if (w
== XWINDOW (selected_window
))
13912 w
->last_point
= BUF_PT (b
);
13914 w
->last_point
= marker_position (w
->pointm
);
13916 w
->window_end_valid
= true;
13917 w
->update_mode_line
= false;
13920 w
->redisplay
= !accurate_p
;
13924 /* Mark the display of windows in the window tree rooted at WINDOW as
13925 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13926 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13927 be redisplayed the next time redisplay_internal is called. */
13930 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13934 for (; !NILP (window
); window
= w
->next
)
13936 w
= XWINDOW (window
);
13937 if (WINDOWP (w
->contents
))
13938 mark_window_display_accurate (w
->contents
, accurate_p
);
13940 mark_window_display_accurate_1 (w
, accurate_p
);
13944 update_overlay_arrows (1);
13946 /* Force a thorough redisplay the next time by setting
13947 last_arrow_position and last_arrow_string to t, which is
13948 unequal to any useful value of Voverlay_arrow_... */
13949 update_overlay_arrows (-1);
13953 /* Return value in display table DP (Lisp_Char_Table *) for character
13954 C. Since a display table doesn't have any parent, we don't have to
13955 follow parent. Do not call this function directly but use the
13956 macro DISP_CHAR_VECTOR. */
13959 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13963 if (ASCII_CHAR_P (c
))
13966 if (SUB_CHAR_TABLE_P (val
))
13967 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13973 XSETCHAR_TABLE (table
, dp
);
13974 val
= char_table_ref (table
, c
);
13983 /***********************************************************************
13985 ***********************************************************************/
13987 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13990 redisplay_windows (Lisp_Object window
)
13992 while (!NILP (window
))
13994 struct window
*w
= XWINDOW (window
);
13996 if (WINDOWP (w
->contents
))
13997 redisplay_windows (w
->contents
);
13998 else if (BUFFERP (w
->contents
))
14000 displayed_buffer
= XBUFFER (w
->contents
);
14001 /* Use list_of_error, not Qerror, so that
14002 we catch only errors and don't run the debugger. */
14003 internal_condition_case_1 (redisplay_window_0
, window
,
14005 redisplay_window_error
);
14013 redisplay_window_error (Lisp_Object ignore
)
14015 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14020 redisplay_window_0 (Lisp_Object window
)
14022 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14023 redisplay_window (window
, false);
14028 redisplay_window_1 (Lisp_Object window
)
14030 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14031 redisplay_window (window
, true);
14036 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14037 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14038 which positions recorded in ROW differ from current buffer
14041 Return 0 if cursor is not on this row, 1 otherwise. */
14044 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14045 struct glyph_matrix
*matrix
,
14046 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14049 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14050 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14051 struct glyph
*cursor
= NULL
;
14052 /* The last known character position in row. */
14053 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14055 ptrdiff_t pt_old
= PT
- delta
;
14056 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14057 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14058 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14059 /* A glyph beyond the edge of TEXT_AREA which we should never
14061 struct glyph
*glyphs_end
= end
;
14062 /* Non-zero means we've found a match for cursor position, but that
14063 glyph has the avoid_cursor_p flag set. */
14064 int match_with_avoid_cursor
= 0;
14065 /* Non-zero means we've seen at least one glyph that came from a
14067 int string_seen
= 0;
14068 /* Largest and smallest buffer positions seen so far during scan of
14070 ptrdiff_t bpos_max
= pos_before
;
14071 ptrdiff_t bpos_min
= pos_after
;
14072 /* Last buffer position covered by an overlay string with an integer
14073 `cursor' property. */
14074 ptrdiff_t bpos_covered
= 0;
14075 /* Non-zero means the display string on which to display the cursor
14076 comes from a text property, not from an overlay. */
14077 int string_from_text_prop
= 0;
14079 /* Don't even try doing anything if called for a mode-line or
14080 header-line row, since the rest of the code isn't prepared to
14081 deal with such calamities. */
14082 eassert (!row
->mode_line_p
);
14083 if (row
->mode_line_p
)
14086 /* Skip over glyphs not having an object at the start and the end of
14087 the row. These are special glyphs like truncation marks on
14088 terminal frames. */
14089 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14091 if (!row
->reversed_p
)
14094 && INTEGERP (glyph
->object
)
14095 && glyph
->charpos
< 0)
14097 x
+= glyph
->pixel_width
;
14101 && INTEGERP ((end
- 1)->object
)
14102 /* CHARPOS is zero for blanks and stretch glyphs
14103 inserted by extend_face_to_end_of_line. */
14104 && (end
- 1)->charpos
<= 0)
14106 glyph_before
= glyph
- 1;
14113 /* If the glyph row is reversed, we need to process it from back
14114 to front, so swap the edge pointers. */
14115 glyphs_end
= end
= glyph
- 1;
14116 glyph
+= row
->used
[TEXT_AREA
] - 1;
14118 while (glyph
> end
+ 1
14119 && INTEGERP (glyph
->object
)
14120 && glyph
->charpos
< 0)
14123 x
-= glyph
->pixel_width
;
14125 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14127 /* By default, in reversed rows we put the cursor on the
14128 rightmost (first in the reading order) glyph. */
14129 for (g
= end
+ 1; g
< glyph
; g
++)
14130 x
+= g
->pixel_width
;
14132 && INTEGERP ((end
+ 1)->object
)
14133 && (end
+ 1)->charpos
<= 0)
14135 glyph_before
= glyph
+ 1;
14139 else if (row
->reversed_p
)
14141 /* In R2L rows that don't display text, put the cursor on the
14142 rightmost glyph. Case in point: an empty last line that is
14143 part of an R2L paragraph. */
14145 /* Avoid placing the cursor on the last glyph of the row, where
14146 on terminal frames we hold the vertical border between
14147 adjacent windows. */
14148 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14149 && !WINDOW_RIGHTMOST_P (w
)
14150 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14152 x
= -1; /* will be computed below, at label compute_x */
14155 /* Step 1: Try to find the glyph whose character position
14156 corresponds to point. If that's not possible, find 2 glyphs
14157 whose character positions are the closest to point, one before
14158 point, the other after it. */
14159 if (!row
->reversed_p
)
14160 while (/* not marched to end of glyph row */
14162 /* glyph was not inserted by redisplay for internal purposes */
14163 && !INTEGERP (glyph
->object
))
14165 if (BUFFERP (glyph
->object
))
14167 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14169 if (glyph
->charpos
> bpos_max
)
14170 bpos_max
= glyph
->charpos
;
14171 if (glyph
->charpos
< bpos_min
)
14172 bpos_min
= glyph
->charpos
;
14173 if (!glyph
->avoid_cursor_p
)
14175 /* If we hit point, we've found the glyph on which to
14176 display the cursor. */
14179 match_with_avoid_cursor
= 0;
14182 /* See if we've found a better approximation to
14183 POS_BEFORE or to POS_AFTER. */
14184 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14186 pos_before
= glyph
->charpos
;
14187 glyph_before
= glyph
;
14189 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14191 pos_after
= glyph
->charpos
;
14192 glyph_after
= glyph
;
14195 else if (dpos
== 0)
14196 match_with_avoid_cursor
= 1;
14198 else if (STRINGP (glyph
->object
))
14200 Lisp_Object chprop
;
14201 ptrdiff_t glyph_pos
= glyph
->charpos
;
14203 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14205 if (!NILP (chprop
))
14207 /* If the string came from a `display' text property,
14208 look up the buffer position of that property and
14209 use that position to update bpos_max, as if we
14210 actually saw such a position in one of the row's
14211 glyphs. This helps with supporting integer values
14212 of `cursor' property on the display string in
14213 situations where most or all of the row's buffer
14214 text is completely covered by display properties,
14215 so that no glyph with valid buffer positions is
14216 ever seen in the row. */
14217 ptrdiff_t prop_pos
=
14218 string_buffer_position_lim (glyph
->object
, pos_before
,
14221 if (prop_pos
>= pos_before
)
14222 bpos_max
= prop_pos
- 1;
14224 if (INTEGERP (chprop
))
14226 bpos_covered
= bpos_max
+ XINT (chprop
);
14227 /* If the `cursor' property covers buffer positions up
14228 to and including point, we should display cursor on
14229 this glyph. Note that, if a `cursor' property on one
14230 of the string's characters has an integer value, we
14231 will break out of the loop below _before_ we get to
14232 the position match above. IOW, integer values of
14233 the `cursor' property override the "exact match for
14234 point" strategy of positioning the cursor. */
14235 /* Implementation note: bpos_max == pt_old when, e.g.,
14236 we are in an empty line, where bpos_max is set to
14237 MATRIX_ROW_START_CHARPOS, see above. */
14238 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14247 x
+= glyph
->pixel_width
;
14250 else if (glyph
> end
) /* row is reversed */
14251 while (!INTEGERP (glyph
->object
))
14253 if (BUFFERP (glyph
->object
))
14255 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14257 if (glyph
->charpos
> bpos_max
)
14258 bpos_max
= glyph
->charpos
;
14259 if (glyph
->charpos
< bpos_min
)
14260 bpos_min
= glyph
->charpos
;
14261 if (!glyph
->avoid_cursor_p
)
14265 match_with_avoid_cursor
= 0;
14268 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14270 pos_before
= glyph
->charpos
;
14271 glyph_before
= glyph
;
14273 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14275 pos_after
= glyph
->charpos
;
14276 glyph_after
= glyph
;
14279 else if (dpos
== 0)
14280 match_with_avoid_cursor
= 1;
14282 else if (STRINGP (glyph
->object
))
14284 Lisp_Object chprop
;
14285 ptrdiff_t glyph_pos
= glyph
->charpos
;
14287 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14289 if (!NILP (chprop
))
14291 ptrdiff_t prop_pos
=
14292 string_buffer_position_lim (glyph
->object
, pos_before
,
14295 if (prop_pos
>= pos_before
)
14296 bpos_max
= prop_pos
- 1;
14298 if (INTEGERP (chprop
))
14300 bpos_covered
= bpos_max
+ XINT (chprop
);
14301 /* If the `cursor' property covers buffer positions up
14302 to and including point, we should display cursor on
14304 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14313 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14315 x
--; /* can't use any pixel_width */
14318 x
-= glyph
->pixel_width
;
14321 /* Step 2: If we didn't find an exact match for point, we need to
14322 look for a proper place to put the cursor among glyphs between
14323 GLYPH_BEFORE and GLYPH_AFTER. */
14324 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14325 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14326 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14328 /* An empty line has a single glyph whose OBJECT is zero and
14329 whose CHARPOS is the position of a newline on that line.
14330 Note that on a TTY, there are more glyphs after that, which
14331 were produced by extend_face_to_end_of_line, but their
14332 CHARPOS is zero or negative. */
14334 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14335 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14336 /* On a TTY, continued and truncated rows also have a glyph at
14337 their end whose OBJECT is zero and whose CHARPOS is
14338 positive (the continuation and truncation glyphs), but such
14339 rows are obviously not "empty". */
14340 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14342 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14344 ptrdiff_t ellipsis_pos
;
14346 /* Scan back over the ellipsis glyphs. */
14347 if (!row
->reversed_p
)
14349 ellipsis_pos
= (glyph
- 1)->charpos
;
14350 while (glyph
> row
->glyphs
[TEXT_AREA
]
14351 && (glyph
- 1)->charpos
== ellipsis_pos
)
14352 glyph
--, x
-= glyph
->pixel_width
;
14353 /* That loop always goes one position too far, including
14354 the glyph before the ellipsis. So scan forward over
14356 x
+= glyph
->pixel_width
;
14359 else /* row is reversed */
14361 ellipsis_pos
= (glyph
+ 1)->charpos
;
14362 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14363 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14364 glyph
++, x
+= glyph
->pixel_width
;
14365 x
-= glyph
->pixel_width
;
14369 else if (match_with_avoid_cursor
)
14371 cursor
= glyph_after
;
14374 else if (string_seen
)
14376 int incr
= row
->reversed_p
? -1 : +1;
14378 /* Need to find the glyph that came out of a string which is
14379 present at point. That glyph is somewhere between
14380 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14381 positioned between POS_BEFORE and POS_AFTER in the
14383 struct glyph
*start
, *stop
;
14384 ptrdiff_t pos
= pos_before
;
14388 /* If the row ends in a newline from a display string,
14389 reordering could have moved the glyphs belonging to the
14390 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14391 in this case we extend the search to the last glyph in
14392 the row that was not inserted by redisplay. */
14393 if (row
->ends_in_newline_from_string_p
)
14396 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14399 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14400 correspond to POS_BEFORE and POS_AFTER, respectively. We
14401 need START and STOP in the order that corresponds to the
14402 row's direction as given by its reversed_p flag. If the
14403 directionality of characters between POS_BEFORE and
14404 POS_AFTER is the opposite of the row's base direction,
14405 these characters will have been reordered for display,
14406 and we need to reverse START and STOP. */
14407 if (!row
->reversed_p
)
14409 start
= min (glyph_before
, glyph_after
);
14410 stop
= max (glyph_before
, glyph_after
);
14414 start
= max (glyph_before
, glyph_after
);
14415 stop
= min (glyph_before
, glyph_after
);
14417 for (glyph
= start
+ incr
;
14418 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14421 /* Any glyphs that come from the buffer are here because
14422 of bidi reordering. Skip them, and only pay
14423 attention to glyphs that came from some string. */
14424 if (STRINGP (glyph
->object
))
14428 /* If the display property covers the newline, we
14429 need to search for it one position farther. */
14430 ptrdiff_t lim
= pos_after
14431 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14433 string_from_text_prop
= 0;
14434 str
= glyph
->object
;
14435 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14436 if (tem
== 0 /* from overlay */
14439 /* If the string from which this glyph came is
14440 found in the buffer at point, or at position
14441 that is closer to point than pos_after, then
14442 we've found the glyph we've been looking for.
14443 If it comes from an overlay (tem == 0), and
14444 it has the `cursor' property on one of its
14445 glyphs, record that glyph as a candidate for
14446 displaying the cursor. (As in the
14447 unidirectional version, we will display the
14448 cursor on the last candidate we find.) */
14451 || (tem
- pt_old
> 0 && tem
< pos_after
))
14453 /* The glyphs from this string could have
14454 been reordered. Find the one with the
14455 smallest string position. Or there could
14456 be a character in the string with the
14457 `cursor' property, which means display
14458 cursor on that character's glyph. */
14459 ptrdiff_t strpos
= glyph
->charpos
;
14464 string_from_text_prop
= 1;
14467 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14468 && EQ (glyph
->object
, str
);
14472 ptrdiff_t gpos
= glyph
->charpos
;
14474 cprop
= Fget_char_property (make_number (gpos
),
14482 if (tem
&& glyph
->charpos
< strpos
)
14484 strpos
= glyph
->charpos
;
14490 || (tem
- pt_old
> 0 && tem
< pos_after
))
14494 pos
= tem
+ 1; /* don't find previous instances */
14496 /* This string is not what we want; skip all of the
14497 glyphs that came from it. */
14498 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14499 && EQ (glyph
->object
, str
))
14506 /* If we reached the end of the line, and END was from a string,
14507 the cursor is not on this line. */
14509 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14510 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14511 && STRINGP (end
->object
)
14512 && row
->continued_p
)
14515 /* A truncated row may not include PT among its character positions.
14516 Setting the cursor inside the scroll margin will trigger
14517 recalculation of hscroll in hscroll_window_tree. But if a
14518 display string covers point, defer to the string-handling
14519 code below to figure this out. */
14520 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14522 cursor
= glyph_before
;
14525 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14526 /* Zero-width characters produce no glyphs. */
14528 && (row
->reversed_p
14529 ? glyph_after
> glyphs_end
14530 : glyph_after
< glyphs_end
)))
14532 cursor
= glyph_after
;
14538 if (cursor
!= NULL
)
14540 else if (glyph
== glyphs_end
14541 && pos_before
== pos_after
14542 && STRINGP ((row
->reversed_p
14543 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14544 : row
->glyphs
[TEXT_AREA
])->object
))
14546 /* If all the glyphs of this row came from strings, put the
14547 cursor on the first glyph of the row. This avoids having the
14548 cursor outside of the text area in this very rare and hard
14552 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14553 : row
->glyphs
[TEXT_AREA
];
14559 /* Need to compute x that corresponds to GLYPH. */
14560 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14562 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14564 x
+= g
->pixel_width
;
14568 /* ROW could be part of a continued line, which, under bidi
14569 reordering, might have other rows whose start and end charpos
14570 occlude point. Only set w->cursor if we found a better
14571 approximation to the cursor position than we have from previously
14572 examined candidate rows belonging to the same continued line. */
14573 if (/* We already have a candidate row. */
14574 w
->cursor
.vpos
>= 0
14575 /* That candidate is not the row we are processing. */
14576 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14577 /* Make sure cursor.vpos specifies a row whose start and end
14578 charpos occlude point, and it is valid candidate for being a
14579 cursor-row. This is because some callers of this function
14580 leave cursor.vpos at the row where the cursor was displayed
14581 during the last redisplay cycle. */
14582 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14583 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14584 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14587 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14589 /* Don't consider glyphs that are outside TEXT_AREA. */
14590 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14592 /* Keep the candidate whose buffer position is the closest to
14593 point or has the `cursor' property. */
14594 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14595 w
->cursor
.hpos
>= 0
14596 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14597 && ((BUFFERP (g1
->object
)
14598 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14599 || (BUFFERP (glyph
->object
)
14600 && eabs (g1
->charpos
- pt_old
)
14601 < eabs (glyph
->charpos
- pt_old
))))
14602 /* Previous candidate is a glyph from a string that has
14603 a non-nil `cursor' property. */
14604 || (STRINGP (g1
->object
)
14605 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14606 Qcursor
, g1
->object
))
14607 /* Previous candidate is from the same display
14608 string as this one, and the display string
14609 came from a text property. */
14610 || (EQ (g1
->object
, glyph
->object
)
14611 && string_from_text_prop
)
14612 /* this candidate is from newline and its
14613 position is not an exact match */
14614 || (INTEGERP (glyph
->object
)
14615 && glyph
->charpos
!= pt_old
)))))
14617 /* If this candidate gives an exact match, use that. */
14618 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14619 /* If this candidate is a glyph created for the
14620 terminating newline of a line, and point is on that
14621 newline, it wins because it's an exact match. */
14622 || (!row
->continued_p
14623 && INTEGERP (glyph
->object
)
14624 && glyph
->charpos
== 0
14625 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14626 /* Otherwise, keep the candidate that comes from a row
14627 spanning less buffer positions. This may win when one or
14628 both candidate positions are on glyphs that came from
14629 display strings, for which we cannot compare buffer
14631 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14632 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14633 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14636 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14638 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14639 w
->cursor
.y
= row
->y
+ dy
;
14641 if (w
== XWINDOW (selected_window
))
14643 if (!row
->continued_p
14644 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14647 this_line_buffer
= XBUFFER (w
->contents
);
14649 CHARPOS (this_line_start_pos
)
14650 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14651 BYTEPOS (this_line_start_pos
)
14652 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14654 CHARPOS (this_line_end_pos
)
14655 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14656 BYTEPOS (this_line_end_pos
)
14657 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14659 this_line_y
= w
->cursor
.y
;
14660 this_line_pixel_height
= row
->height
;
14661 this_line_vpos
= w
->cursor
.vpos
;
14662 this_line_start_x
= row
->x
;
14665 CHARPOS (this_line_start_pos
) = 0;
14672 /* Run window scroll functions, if any, for WINDOW with new window
14673 start STARTP. Sets the window start of WINDOW to that position.
14675 We assume that the window's buffer is really current. */
14677 static struct text_pos
14678 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14680 struct window
*w
= XWINDOW (window
);
14681 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14683 eassert (current_buffer
== XBUFFER (w
->contents
));
14685 if (!NILP (Vwindow_scroll_functions
))
14687 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14688 make_number (CHARPOS (startp
)));
14689 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14690 /* In case the hook functions switch buffers. */
14691 set_buffer_internal (XBUFFER (w
->contents
));
14698 /* Make sure the line containing the cursor is fully visible.
14699 A value of 1 means there is nothing to be done.
14700 (Either the line is fully visible, or it cannot be made so,
14701 or we cannot tell.)
14703 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14704 is higher than window.
14706 A value of 0 means the caller should do scrolling
14707 as if point had gone off the screen. */
14710 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14712 struct glyph_matrix
*matrix
;
14713 struct glyph_row
*row
;
14716 if (!make_cursor_line_fully_visible_p
)
14719 /* It's not always possible to find the cursor, e.g, when a window
14720 is full of overlay strings. Don't do anything in that case. */
14721 if (w
->cursor
.vpos
< 0)
14724 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14725 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14727 /* If the cursor row is not partially visible, there's nothing to do. */
14728 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14731 /* If the row the cursor is in is taller than the window's height,
14732 it's not clear what to do, so do nothing. */
14733 window_height
= window_box_height (w
);
14734 if (row
->height
>= window_height
)
14736 if (!force_p
|| MINI_WINDOW_P (w
)
14737 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14744 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14745 non-zero means only WINDOW is redisplayed in redisplay_internal.
14746 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14747 in redisplay_window to bring a partially visible line into view in
14748 the case that only the cursor has moved.
14750 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14751 last screen line's vertical height extends past the end of the screen.
14755 1 if scrolling succeeded
14757 0 if scrolling didn't find point.
14759 -1 if new fonts have been loaded so that we must interrupt
14760 redisplay, adjust glyph matrices, and try again. */
14766 SCROLLING_NEED_LARGER_MATRICES
14769 /* If scroll-conservatively is more than this, never recenter.
14771 If you change this, don't forget to update the doc string of
14772 `scroll-conservatively' and the Emacs manual. */
14773 #define SCROLL_LIMIT 100
14776 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14777 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14778 int temp_scroll_step
, int last_line_misfit
)
14780 struct window
*w
= XWINDOW (window
);
14781 struct frame
*f
= XFRAME (w
->frame
);
14782 struct text_pos pos
, startp
;
14784 int this_scroll_margin
, scroll_max
, rc
, height
;
14785 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14786 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14787 Lisp_Object aggressive
;
14788 /* We will never try scrolling more than this number of lines. */
14789 int scroll_limit
= SCROLL_LIMIT
;
14790 int frame_line_height
= default_line_pixel_height (w
);
14791 int window_total_lines
14792 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14795 debug_method_add (w
, "try_scrolling");
14798 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14800 /* Compute scroll margin height in pixels. We scroll when point is
14801 within this distance from the top or bottom of the window. */
14802 if (scroll_margin
> 0)
14803 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14804 * frame_line_height
;
14806 this_scroll_margin
= 0;
14808 /* Force arg_scroll_conservatively to have a reasonable value, to
14809 avoid scrolling too far away with slow move_it_* functions. Note
14810 that the user can supply scroll-conservatively equal to
14811 `most-positive-fixnum', which can be larger than INT_MAX. */
14812 if (arg_scroll_conservatively
> scroll_limit
)
14814 arg_scroll_conservatively
= scroll_limit
+ 1;
14815 scroll_max
= scroll_limit
* frame_line_height
;
14817 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14818 /* Compute how much we should try to scroll maximally to bring
14819 point into view. */
14820 scroll_max
= (max (scroll_step
,
14821 max (arg_scroll_conservatively
, temp_scroll_step
))
14822 * frame_line_height
);
14823 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14824 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14825 /* We're trying to scroll because of aggressive scrolling but no
14826 scroll_step is set. Choose an arbitrary one. */
14827 scroll_max
= 10 * frame_line_height
;
14833 /* Decide whether to scroll down. */
14834 if (PT
> CHARPOS (startp
))
14836 int scroll_margin_y
;
14838 /* Compute the pixel ypos of the scroll margin, then move IT to
14839 either that ypos or PT, whichever comes first. */
14840 start_display (&it
, w
, startp
);
14841 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14842 - frame_line_height
* extra_scroll_margin_lines
;
14843 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14844 (MOVE_TO_POS
| MOVE_TO_Y
));
14846 if (PT
> CHARPOS (it
.current
.pos
))
14848 int y0
= line_bottom_y (&it
);
14849 /* Compute how many pixels below window bottom to stop searching
14850 for PT. This avoids costly search for PT that is far away if
14851 the user limited scrolling by a small number of lines, but
14852 always finds PT if scroll_conservatively is set to a large
14853 number, such as most-positive-fixnum. */
14854 int slack
= max (scroll_max
, 10 * frame_line_height
);
14855 int y_to_move
= it
.last_visible_y
+ slack
;
14857 /* Compute the distance from the scroll margin to PT or to
14858 the scroll limit, whichever comes first. This should
14859 include the height of the cursor line, to make that line
14861 move_it_to (&it
, PT
, -1, y_to_move
,
14862 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14863 dy
= line_bottom_y (&it
) - y0
;
14865 if (dy
> scroll_max
)
14866 return SCROLLING_FAILED
;
14875 /* Point is in or below the bottom scroll margin, so move the
14876 window start down. If scrolling conservatively, move it just
14877 enough down to make point visible. If scroll_step is set,
14878 move it down by scroll_step. */
14879 if (arg_scroll_conservatively
)
14881 = min (max (dy
, frame_line_height
),
14882 frame_line_height
* arg_scroll_conservatively
);
14883 else if (scroll_step
|| temp_scroll_step
)
14884 amount_to_scroll
= scroll_max
;
14887 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14888 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14889 if (NUMBERP (aggressive
))
14891 double float_amount
= XFLOATINT (aggressive
) * height
;
14892 int aggressive_scroll
= float_amount
;
14893 if (aggressive_scroll
== 0 && float_amount
> 0)
14894 aggressive_scroll
= 1;
14895 /* Don't let point enter the scroll margin near top of
14896 the window. This could happen if the value of
14897 scroll_up_aggressively is too large and there are
14898 non-zero margins, because scroll_up_aggressively
14899 means put point that fraction of window height
14900 _from_the_bottom_margin_. */
14901 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14902 aggressive_scroll
= height
- 2*this_scroll_margin
;
14903 amount_to_scroll
= dy
+ aggressive_scroll
;
14907 if (amount_to_scroll
<= 0)
14908 return SCROLLING_FAILED
;
14910 start_display (&it
, w
, startp
);
14911 if (arg_scroll_conservatively
<= scroll_limit
)
14912 move_it_vertically (&it
, amount_to_scroll
);
14915 /* Extra precision for users who set scroll-conservatively
14916 to a large number: make sure the amount we scroll
14917 the window start is never less than amount_to_scroll,
14918 which was computed as distance from window bottom to
14919 point. This matters when lines at window top and lines
14920 below window bottom have different height. */
14922 void *it1data
= NULL
;
14923 /* We use a temporary it1 because line_bottom_y can modify
14924 its argument, if it moves one line down; see there. */
14927 SAVE_IT (it1
, it
, it1data
);
14928 start_y
= line_bottom_y (&it1
);
14930 RESTORE_IT (&it
, &it
, it1data
);
14931 move_it_by_lines (&it
, 1);
14932 SAVE_IT (it1
, it
, it1data
);
14933 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14936 /* If STARTP is unchanged, move it down another screen line. */
14937 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14938 move_it_by_lines (&it
, 1);
14939 startp
= it
.current
.pos
;
14943 struct text_pos scroll_margin_pos
= startp
;
14946 /* See if point is inside the scroll margin at the top of the
14948 if (this_scroll_margin
)
14952 start_display (&it
, w
, startp
);
14953 y_start
= it
.current_y
;
14954 move_it_vertically (&it
, this_scroll_margin
);
14955 scroll_margin_pos
= it
.current
.pos
;
14956 /* If we didn't move enough before hitting ZV, request
14957 additional amount of scroll, to move point out of the
14959 if (IT_CHARPOS (it
) == ZV
14960 && it
.current_y
- y_start
< this_scroll_margin
)
14961 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14964 if (PT
< CHARPOS (scroll_margin_pos
))
14966 /* Point is in the scroll margin at the top of the window or
14967 above what is displayed in the window. */
14970 /* Compute the vertical distance from PT to the scroll
14971 margin position. Move as far as scroll_max allows, or
14972 one screenful, or 10 screen lines, whichever is largest.
14973 Give up if distance is greater than scroll_max or if we
14974 didn't reach the scroll margin position. */
14975 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14976 start_display (&it
, w
, pos
);
14978 y_to_move
= max (it
.last_visible_y
,
14979 max (scroll_max
, 10 * frame_line_height
));
14980 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14982 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14983 dy
= it
.current_y
- y0
;
14984 if (dy
> scroll_max
14985 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14986 return SCROLLING_FAILED
;
14988 /* Additional scroll for when ZV was too close to point. */
14991 /* Compute new window start. */
14992 start_display (&it
, w
, startp
);
14994 if (arg_scroll_conservatively
)
14995 amount_to_scroll
= max (dy
, frame_line_height
*
14996 max (scroll_step
, temp_scroll_step
));
14997 else if (scroll_step
|| temp_scroll_step
)
14998 amount_to_scroll
= scroll_max
;
15001 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15002 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15003 if (NUMBERP (aggressive
))
15005 double float_amount
= XFLOATINT (aggressive
) * height
;
15006 int aggressive_scroll
= float_amount
;
15007 if (aggressive_scroll
== 0 && float_amount
> 0)
15008 aggressive_scroll
= 1;
15009 /* Don't let point enter the scroll margin near
15010 bottom of the window, if the value of
15011 scroll_down_aggressively happens to be too
15013 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
15014 aggressive_scroll
= height
- 2*this_scroll_margin
;
15015 amount_to_scroll
= dy
+ aggressive_scroll
;
15019 if (amount_to_scroll
<= 0)
15020 return SCROLLING_FAILED
;
15022 move_it_vertically_backward (&it
, amount_to_scroll
);
15023 startp
= it
.current
.pos
;
15027 /* Run window scroll functions. */
15028 startp
= run_window_scroll_functions (window
, startp
);
15030 /* Display the window. Give up if new fonts are loaded, or if point
15032 if (!try_window (window
, startp
, 0))
15033 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15034 else if (w
->cursor
.vpos
< 0)
15036 clear_glyph_matrix (w
->desired_matrix
);
15037 rc
= SCROLLING_FAILED
;
15041 /* Maybe forget recorded base line for line number display. */
15042 if (!just_this_one_p
15043 || current_buffer
->clip_changed
15044 || BEG_UNCHANGED
< CHARPOS (startp
))
15045 w
->base_line_number
= 0;
15047 /* If cursor ends up on a partially visible line,
15048 treat that as being off the bottom of the screen. */
15049 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15050 /* It's possible that the cursor is on the first line of the
15051 buffer, which is partially obscured due to a vscroll
15052 (Bug#7537). In that case, avoid looping forever. */
15053 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15055 clear_glyph_matrix (w
->desired_matrix
);
15056 ++extra_scroll_margin_lines
;
15059 rc
= SCROLLING_SUCCESS
;
15066 /* Compute a suitable window start for window W if display of W starts
15067 on a continuation line. Value is non-zero if a new window start
15070 The new window start will be computed, based on W's width, starting
15071 from the start of the continued line. It is the start of the
15072 screen line with the minimum distance from the old start W->start. */
15075 compute_window_start_on_continuation_line (struct window
*w
)
15077 struct text_pos pos
, start_pos
;
15078 int window_start_changed_p
= 0;
15080 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15082 /* If window start is on a continuation line... Window start may be
15083 < BEGV in case there's invisible text at the start of the
15084 buffer (M-x rmail, for example). */
15085 if (CHARPOS (start_pos
) > BEGV
15086 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15089 struct glyph_row
*row
;
15091 /* Handle the case that the window start is out of range. */
15092 if (CHARPOS (start_pos
) < BEGV
)
15093 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15094 else if (CHARPOS (start_pos
) > ZV
)
15095 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15097 /* Find the start of the continued line. This should be fast
15098 because find_newline is fast (newline cache). */
15099 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15100 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15101 row
, DEFAULT_FACE_ID
);
15102 reseat_at_previous_visible_line_start (&it
);
15104 /* If the line start is "too far" away from the window start,
15105 say it takes too much time to compute a new window start. */
15106 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15107 /* PXW: Do we need upper bounds here? */
15108 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15110 int min_distance
, distance
;
15112 /* Move forward by display lines to find the new window
15113 start. If window width was enlarged, the new start can
15114 be expected to be > the old start. If window width was
15115 decreased, the new window start will be < the old start.
15116 So, we're looking for the display line start with the
15117 minimum distance from the old window start. */
15118 pos
= it
.current
.pos
;
15119 min_distance
= INFINITY
;
15120 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15121 distance
< min_distance
)
15123 min_distance
= distance
;
15124 pos
= it
.current
.pos
;
15125 if (it
.line_wrap
== WORD_WRAP
)
15127 /* Under WORD_WRAP, move_it_by_lines is likely to
15128 overshoot and stop not at the first, but the
15129 second character from the left margin. So in
15130 that case, we need a more tight control on the X
15131 coordinate of the iterator than move_it_by_lines
15132 promises in its contract. The method is to first
15133 go to the last (rightmost) visible character of a
15134 line, then move to the leftmost character on the
15135 next line in a separate call. */
15136 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15137 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15138 move_it_to (&it
, ZV
, 0,
15139 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15140 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15143 move_it_by_lines (&it
, 1);
15146 /* Set the window start there. */
15147 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15148 window_start_changed_p
= 1;
15152 return window_start_changed_p
;
15156 /* Try cursor movement in case text has not changed in window WINDOW,
15157 with window start STARTP. Value is
15159 CURSOR_MOVEMENT_SUCCESS if successful
15161 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15163 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15164 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15165 we want to scroll as if scroll-step were set to 1. See the code.
15167 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15168 which case we have to abort this redisplay, and adjust matrices
15173 CURSOR_MOVEMENT_SUCCESS
,
15174 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15175 CURSOR_MOVEMENT_MUST_SCROLL
,
15176 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15180 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15182 struct window
*w
= XWINDOW (window
);
15183 struct frame
*f
= XFRAME (w
->frame
);
15184 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15187 if (inhibit_try_cursor_movement
)
15191 /* Previously, there was a check for Lisp integer in the
15192 if-statement below. Now, this field is converted to
15193 ptrdiff_t, thus zero means invalid position in a buffer. */
15194 eassert (w
->last_point
> 0);
15195 /* Likewise there was a check whether window_end_vpos is nil or larger
15196 than the window. Now window_end_vpos is int and so never nil, but
15197 let's leave eassert to check whether it fits in the window. */
15198 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15200 /* Handle case where text has not changed, only point, and it has
15201 not moved off the frame. */
15202 if (/* Point may be in this window. */
15203 PT
>= CHARPOS (startp
)
15204 /* Selective display hasn't changed. */
15205 && !current_buffer
->clip_changed
15206 /* Function force-mode-line-update is used to force a thorough
15207 redisplay. It sets either windows_or_buffers_changed or
15208 update_mode_lines. So don't take a shortcut here for these
15210 && !update_mode_lines
15211 && !windows_or_buffers_changed
15212 && !f
->cursor_type_changed
15213 && NILP (Vshow_trailing_whitespace
)
15214 /* This code is not used for mini-buffer for the sake of the case
15215 of redisplaying to replace an echo area message; since in
15216 that case the mini-buffer contents per se are usually
15217 unchanged. This code is of no real use in the mini-buffer
15218 since the handling of this_line_start_pos, etc., in redisplay
15219 handles the same cases. */
15220 && !EQ (window
, minibuf_window
)
15221 && (FRAME_WINDOW_P (f
)
15222 || !overlay_arrow_in_current_buffer_p ()))
15224 int this_scroll_margin
, top_scroll_margin
;
15225 struct glyph_row
*row
= NULL
;
15226 int frame_line_height
= default_line_pixel_height (w
);
15227 int window_total_lines
15228 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15231 debug_method_add (w
, "cursor movement");
15234 /* Scroll if point within this distance from the top or bottom
15235 of the window. This is a pixel value. */
15236 if (scroll_margin
> 0)
15238 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15239 this_scroll_margin
*= frame_line_height
;
15242 this_scroll_margin
= 0;
15244 top_scroll_margin
= this_scroll_margin
;
15245 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15246 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15248 /* Start with the row the cursor was displayed during the last
15249 not paused redisplay. Give up if that row is not valid. */
15250 if (w
->last_cursor_vpos
< 0
15251 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15252 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15255 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15256 if (row
->mode_line_p
)
15258 if (!row
->enabled_p
)
15259 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15262 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15264 int scroll_p
= 0, must_scroll
= 0;
15265 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15267 if (PT
> w
->last_point
)
15269 /* Point has moved forward. */
15270 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15271 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15273 eassert (row
->enabled_p
);
15277 /* If the end position of a row equals the start
15278 position of the next row, and PT is at that position,
15279 we would rather display cursor in the next line. */
15280 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15281 && MATRIX_ROW_END_CHARPOS (row
) == PT
15282 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15283 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15284 && !cursor_row_p (row
))
15287 /* If within the scroll margin, scroll. Note that
15288 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15289 the next line would be drawn, and that
15290 this_scroll_margin can be zero. */
15291 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15292 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15293 /* Line is completely visible last line in window
15294 and PT is to be set in the next line. */
15295 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15296 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15297 && !row
->ends_at_zv_p
15298 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15301 else if (PT
< w
->last_point
)
15303 /* Cursor has to be moved backward. Note that PT >=
15304 CHARPOS (startp) because of the outer if-statement. */
15305 while (!row
->mode_line_p
15306 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15307 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15308 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15309 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15310 row
> w
->current_matrix
->rows
15311 && (row
-1)->ends_in_newline_from_string_p
))))
15312 && (row
->y
> top_scroll_margin
15313 || CHARPOS (startp
) == BEGV
))
15315 eassert (row
->enabled_p
);
15319 /* Consider the following case: Window starts at BEGV,
15320 there is invisible, intangible text at BEGV, so that
15321 display starts at some point START > BEGV. It can
15322 happen that we are called with PT somewhere between
15323 BEGV and START. Try to handle that case. */
15324 if (row
< w
->current_matrix
->rows
15325 || row
->mode_line_p
)
15327 row
= w
->current_matrix
->rows
;
15328 if (row
->mode_line_p
)
15332 /* Due to newlines in overlay strings, we may have to
15333 skip forward over overlay strings. */
15334 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15335 && MATRIX_ROW_END_CHARPOS (row
) == PT
15336 && !cursor_row_p (row
))
15339 /* If within the scroll margin, scroll. */
15340 if (row
->y
< top_scroll_margin
15341 && CHARPOS (startp
) != BEGV
)
15346 /* Cursor did not move. So don't scroll even if cursor line
15347 is partially visible, as it was so before. */
15348 rc
= CURSOR_MOVEMENT_SUCCESS
;
15351 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15352 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15354 /* if PT is not in the glyph row, give up. */
15355 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15358 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15359 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15361 struct glyph_row
*row1
;
15363 /* If rows are bidi-reordered and point moved, back up
15364 until we find a row that does not belong to a
15365 continuation line. This is because we must consider
15366 all rows of a continued line as candidates for the
15367 new cursor positioning, since row start and end
15368 positions change non-linearly with vertical position
15370 /* FIXME: Revisit this when glyph ``spilling'' in
15371 continuation lines' rows is implemented for
15372 bidi-reordered rows. */
15373 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15374 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15377 /* If we hit the beginning of the displayed portion
15378 without finding the first row of a continued
15382 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15385 eassert (row
->enabled_p
);
15390 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15391 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15392 /* Make sure this isn't a header line by any chance, since
15393 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15394 && !row
->mode_line_p
15395 && make_cursor_line_fully_visible_p
)
15397 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15398 && !row
->ends_at_zv_p
15399 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15400 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15401 else if (row
->height
> window_box_height (w
))
15403 /* If we end up in a partially visible line, let's
15404 make it fully visible, except when it's taller
15405 than the window, in which case we can't do much
15408 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15412 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15413 if (!cursor_row_fully_visible_p (w
, 0, 1))
15414 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15416 rc
= CURSOR_MOVEMENT_SUCCESS
;
15420 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15421 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15422 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15424 /* With bidi-reordered rows, there could be more than
15425 one candidate row whose start and end positions
15426 occlude point. We need to let set_cursor_from_row
15427 find the best candidate. */
15428 /* FIXME: Revisit this when glyph ``spilling'' in
15429 continuation lines' rows is implemented for
15430 bidi-reordered rows. */
15435 int at_zv_p
= 0, exact_match_p
= 0;
15437 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15438 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15439 && cursor_row_p (row
))
15440 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15442 /* As soon as we've found the exact match for point,
15443 or the first suitable row whose ends_at_zv_p flag
15444 is set, we are done. */
15446 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15448 && w
->cursor
.hpos
>= 0
15449 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15452 struct glyph_row
*candidate
=
15453 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15455 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15456 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15459 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15460 || (INTEGERP (g
->object
)
15461 && (g
->charpos
== PT
15462 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15464 if (rv
&& (at_zv_p
|| exact_match_p
))
15466 rc
= CURSOR_MOVEMENT_SUCCESS
;
15469 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15473 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15474 || row
->continued_p
)
15475 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15476 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15477 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15478 /* If we didn't find any candidate rows, or exited the
15479 loop before all the candidates were examined, signal
15480 to the caller that this method failed. */
15481 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15483 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15484 && !row
->continued_p
))
15485 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15487 rc
= CURSOR_MOVEMENT_SUCCESS
;
15493 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15495 rc
= CURSOR_MOVEMENT_SUCCESS
;
15500 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15501 && MATRIX_ROW_START_CHARPOS (row
) == PT
15502 && cursor_row_p (row
));
15510 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15514 set_vertical_scroll_bar (struct window
*w
)
15516 ptrdiff_t start
, end
, whole
;
15518 /* Calculate the start and end positions for the current window.
15519 At some point, it would be nice to choose between scrollbars
15520 which reflect the whole buffer size, with special markers
15521 indicating narrowing, and scrollbars which reflect only the
15524 Note that mini-buffers sometimes aren't displaying any text. */
15525 if (!MINI_WINDOW_P (w
)
15526 || (w
== XWINDOW (minibuf_window
)
15527 && NILP (echo_area_buffer
[0])))
15529 struct buffer
*buf
= XBUFFER (w
->contents
);
15530 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15531 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15532 /* I don't think this is guaranteed to be right. For the
15533 moment, we'll pretend it is. */
15534 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15538 if (whole
< (end
- start
))
15539 whole
= end
- start
;
15542 start
= end
= whole
= 0;
15544 /* Indicate what this scroll bar ought to be displaying now. */
15545 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15546 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15547 (w
, end
- start
, whole
, start
);
15551 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15552 selected_window is redisplayed.
15554 We can return without actually redisplaying the window if fonts has been
15555 changed on window's frame. In that case, redisplay_internal will retry. */
15558 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15560 struct window
*w
= XWINDOW (window
);
15561 struct frame
*f
= XFRAME (w
->frame
);
15562 struct buffer
*buffer
= XBUFFER (w
->contents
);
15563 struct buffer
*old
= current_buffer
;
15564 struct text_pos lpoint
, opoint
, startp
;
15565 int update_mode_line
;
15568 /* Record it now because it's overwritten. */
15569 bool current_matrix_up_to_date_p
= false;
15570 bool used_current_matrix_p
= false;
15571 /* This is less strict than current_matrix_up_to_date_p.
15572 It indicates that the buffer contents and narrowing are unchanged. */
15573 bool buffer_unchanged_p
= false;
15574 int temp_scroll_step
= 0;
15575 ptrdiff_t count
= SPECPDL_INDEX ();
15577 int centering_position
= -1;
15578 int last_line_misfit
= 0;
15579 ptrdiff_t beg_unchanged
, end_unchanged
;
15580 int frame_line_height
;
15582 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15586 *w
->desired_matrix
->method
= 0;
15589 if (!just_this_one_p
15590 && REDISPLAY_SOME_P ()
15593 && !buffer
->text
->redisplay
)
15596 /* Make sure that both W's markers are valid. */
15597 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15598 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15601 reconsider_clip_changes (w
);
15602 frame_line_height
= default_line_pixel_height (w
);
15604 /* Has the mode line to be updated? */
15605 update_mode_line
= (w
->update_mode_line
15606 || update_mode_lines
15607 || buffer
->clip_changed
15608 || buffer
->prevent_redisplay_optimizations_p
);
15610 if (!just_this_one_p
)
15611 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15612 cleverly elsewhere. */
15613 w
->must_be_updated_p
= true;
15615 if (MINI_WINDOW_P (w
))
15617 if (w
== XWINDOW (echo_area_window
)
15618 && !NILP (echo_area_buffer
[0]))
15620 if (update_mode_line
)
15621 /* We may have to update a tty frame's menu bar or a
15622 tool-bar. Example `M-x C-h C-h C-g'. */
15623 goto finish_menu_bars
;
15625 /* We've already displayed the echo area glyphs in this window. */
15626 goto finish_scroll_bars
;
15628 else if ((w
!= XWINDOW (minibuf_window
)
15629 || minibuf_level
== 0)
15630 /* When buffer is nonempty, redisplay window normally. */
15631 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15632 /* Quail displays non-mini buffers in minibuffer window.
15633 In that case, redisplay the window normally. */
15634 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15636 /* W is a mini-buffer window, but it's not active, so clear
15638 int yb
= window_text_bottom_y (w
);
15639 struct glyph_row
*row
;
15642 for (y
= 0, row
= w
->desired_matrix
->rows
;
15644 y
+= row
->height
, ++row
)
15645 blank_row (w
, row
, y
);
15646 goto finish_scroll_bars
;
15649 clear_glyph_matrix (w
->desired_matrix
);
15652 /* Otherwise set up data on this window; select its buffer and point
15654 /* Really select the buffer, for the sake of buffer-local
15656 set_buffer_internal_1 (XBUFFER (w
->contents
));
15658 current_matrix_up_to_date_p
15659 = (w
->window_end_valid
15660 && !current_buffer
->clip_changed
15661 && !current_buffer
->prevent_redisplay_optimizations_p
15662 && !window_outdated (w
));
15664 /* Run the window-bottom-change-functions
15665 if it is possible that the text on the screen has changed
15666 (either due to modification of the text, or any other reason). */
15667 if (!current_matrix_up_to_date_p
15668 && !NILP (Vwindow_text_change_functions
))
15670 safe_run_hooks (Qwindow_text_change_functions
);
15674 beg_unchanged
= BEG_UNCHANGED
;
15675 end_unchanged
= END_UNCHANGED
;
15677 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15679 specbind (Qinhibit_point_motion_hooks
, Qt
);
15682 = (w
->window_end_valid
15683 && !current_buffer
->clip_changed
15684 && !window_outdated (w
));
15686 /* When windows_or_buffers_changed is non-zero, we can't rely
15687 on the window end being valid, so set it to zero there. */
15688 if (windows_or_buffers_changed
)
15690 /* If window starts on a continuation line, maybe adjust the
15691 window start in case the window's width changed. */
15692 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15693 compute_window_start_on_continuation_line (w
);
15695 w
->window_end_valid
= false;
15696 /* If so, we also can't rely on current matrix
15697 and should not fool try_cursor_movement below. */
15698 current_matrix_up_to_date_p
= false;
15701 /* Some sanity checks. */
15702 CHECK_WINDOW_END (w
);
15703 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15705 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15708 if (mode_line_update_needed (w
))
15709 update_mode_line
= 1;
15711 /* Point refers normally to the selected window. For any other
15712 window, set up appropriate value. */
15713 if (!EQ (window
, selected_window
))
15715 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15716 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15720 new_pt_byte
= BEGV_BYTE
;
15721 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15723 else if (new_pt
> (ZV
- 1))
15726 new_pt_byte
= ZV_BYTE
;
15727 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15730 /* We don't use SET_PT so that the point-motion hooks don't run. */
15731 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15734 /* If any of the character widths specified in the display table
15735 have changed, invalidate the width run cache. It's true that
15736 this may be a bit late to catch such changes, but the rest of
15737 redisplay goes (non-fatally) haywire when the display table is
15738 changed, so why should we worry about doing any better? */
15739 if (current_buffer
->width_run_cache
)
15741 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15743 if (! disptab_matches_widthtab
15744 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15746 invalidate_region_cache (current_buffer
,
15747 current_buffer
->width_run_cache
,
15749 recompute_width_table (current_buffer
, disptab
);
15753 /* If window-start is screwed up, choose a new one. */
15754 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15757 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15759 /* If someone specified a new starting point but did not insist,
15760 check whether it can be used. */
15761 if (w
->optional_new_start
15762 && CHARPOS (startp
) >= BEGV
15763 && CHARPOS (startp
) <= ZV
)
15765 w
->optional_new_start
= 0;
15766 start_display (&it
, w
, startp
);
15767 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15768 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15769 if (IT_CHARPOS (it
) == PT
)
15770 w
->force_start
= 1;
15771 /* IT may overshoot PT if text at PT is invisible. */
15772 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15773 w
->force_start
= 1;
15778 /* Handle case where place to start displaying has been specified,
15779 unless the specified location is outside the accessible range. */
15780 if (w
->force_start
|| window_frozen_p (w
))
15782 /* We set this later on if we have to adjust point. */
15785 w
->force_start
= 0;
15787 w
->window_end_valid
= 0;
15789 /* Forget any recorded base line for line number display. */
15790 if (!buffer_unchanged_p
)
15791 w
->base_line_number
= 0;
15793 /* Redisplay the mode line. Select the buffer properly for that.
15794 Also, run the hook window-scroll-functions
15795 because we have scrolled. */
15796 /* Note, we do this after clearing force_start because
15797 if there's an error, it is better to forget about force_start
15798 than to get into an infinite loop calling the hook functions
15799 and having them get more errors. */
15800 if (!update_mode_line
15801 || ! NILP (Vwindow_scroll_functions
))
15803 update_mode_line
= 1;
15804 w
->update_mode_line
= 1;
15805 startp
= run_window_scroll_functions (window
, startp
);
15808 if (CHARPOS (startp
) < BEGV
)
15809 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15810 else if (CHARPOS (startp
) > ZV
)
15811 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15813 /* Redisplay, then check if cursor has been set during the
15814 redisplay. Give up if new fonts were loaded. */
15815 /* We used to issue a CHECK_MARGINS argument to try_window here,
15816 but this causes scrolling to fail when point begins inside
15817 the scroll margin (bug#148) -- cyd */
15818 if (!try_window (window
, startp
, 0))
15820 w
->force_start
= 1;
15821 clear_glyph_matrix (w
->desired_matrix
);
15822 goto need_larger_matrices
;
15825 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15827 /* If point does not appear, try to move point so it does
15828 appear. The desired matrix has been built above, so we
15829 can use it here. */
15830 new_vpos
= window_box_height (w
) / 2;
15833 if (!cursor_row_fully_visible_p (w
, 0, 0))
15835 /* Point does appear, but on a line partly visible at end of window.
15836 Move it back to a fully-visible line. */
15837 new_vpos
= window_box_height (w
);
15839 else if (w
->cursor
.vpos
>= 0)
15841 /* Some people insist on not letting point enter the scroll
15842 margin, even though this part handles windows that didn't
15844 int window_total_lines
15845 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15846 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15847 int pixel_margin
= margin
* frame_line_height
;
15848 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15850 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15851 below, which finds the row to move point to, advances by
15852 the Y coordinate of the _next_ row, see the definition of
15853 MATRIX_ROW_BOTTOM_Y. */
15854 if (w
->cursor
.vpos
< margin
+ header_line
)
15856 w
->cursor
.vpos
= -1;
15857 clear_glyph_matrix (w
->desired_matrix
);
15858 goto try_to_scroll
;
15862 int window_height
= window_box_height (w
);
15865 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15866 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15868 w
->cursor
.vpos
= -1;
15869 clear_glyph_matrix (w
->desired_matrix
);
15870 goto try_to_scroll
;
15875 /* If we need to move point for either of the above reasons,
15876 now actually do it. */
15879 struct glyph_row
*row
;
15881 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15882 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15885 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15886 MATRIX_ROW_START_BYTEPOS (row
));
15888 if (w
!= XWINDOW (selected_window
))
15889 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15890 else if (current_buffer
== old
)
15891 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15893 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15895 /* If we are highlighting the region, then we just changed
15896 the region, so redisplay to show it. */
15897 /* FIXME: We need to (re)run pre-redisplay-function! */
15898 /* if (markpos_of_region () >= 0)
15900 clear_glyph_matrix (w->desired_matrix);
15901 if (!try_window (window, startp, 0))
15902 goto need_larger_matrices;
15908 debug_method_add (w
, "forced window start");
15913 /* Handle case where text has not changed, only point, and it has
15914 not moved off the frame, and we are not retrying after hscroll.
15915 (current_matrix_up_to_date_p is nonzero when retrying.) */
15916 if (current_matrix_up_to_date_p
15917 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15918 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15922 case CURSOR_MOVEMENT_SUCCESS
:
15923 used_current_matrix_p
= 1;
15926 case CURSOR_MOVEMENT_MUST_SCROLL
:
15927 goto try_to_scroll
;
15933 /* If current starting point was originally the beginning of a line
15934 but no longer is, find a new starting point. */
15935 else if (w
->start_at_line_beg
15936 && !(CHARPOS (startp
) <= BEGV
15937 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15940 debug_method_add (w
, "recenter 1");
15945 /* Try scrolling with try_window_id. Value is > 0 if update has
15946 been done, it is -1 if we know that the same window start will
15947 not work. It is 0 if unsuccessful for some other reason. */
15948 else if ((tem
= try_window_id (w
)) != 0)
15951 debug_method_add (w
, "try_window_id %d", tem
);
15954 if (f
->fonts_changed
)
15955 goto need_larger_matrices
;
15959 /* Otherwise try_window_id has returned -1 which means that we
15960 don't want the alternative below this comment to execute. */
15962 else if (CHARPOS (startp
) >= BEGV
15963 && CHARPOS (startp
) <= ZV
15964 && PT
>= CHARPOS (startp
)
15965 && (CHARPOS (startp
) < ZV
15966 /* Avoid starting at end of buffer. */
15967 || CHARPOS (startp
) == BEGV
15968 || !window_outdated (w
)))
15970 int d1
, d2
, d3
, d4
, d5
, d6
;
15972 /* If first window line is a continuation line, and window start
15973 is inside the modified region, but the first change is before
15974 current window start, we must select a new window start.
15976 However, if this is the result of a down-mouse event (e.g. by
15977 extending the mouse-drag-overlay), we don't want to select a
15978 new window start, since that would change the position under
15979 the mouse, resulting in an unwanted mouse-movement rather
15980 than a simple mouse-click. */
15981 if (!w
->start_at_line_beg
15982 && NILP (do_mouse_tracking
)
15983 && CHARPOS (startp
) > BEGV
15984 && CHARPOS (startp
) > BEG
+ beg_unchanged
15985 && CHARPOS (startp
) <= Z
- end_unchanged
15986 /* Even if w->start_at_line_beg is nil, a new window may
15987 start at a line_beg, since that's how set_buffer_window
15988 sets it. So, we need to check the return value of
15989 compute_window_start_on_continuation_line. (See also
15991 && XMARKER (w
->start
)->buffer
== current_buffer
15992 && compute_window_start_on_continuation_line (w
)
15993 /* It doesn't make sense to force the window start like we
15994 do at label force_start if it is already known that point
15995 will not be visible in the resulting window, because
15996 doing so will move point from its correct position
15997 instead of scrolling the window to bring point into view.
15999 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
16001 w
->force_start
= 1;
16002 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16007 debug_method_add (w
, "same window start");
16010 /* Try to redisplay starting at same place as before.
16011 If point has not moved off frame, accept the results. */
16012 if (!current_matrix_up_to_date_p
16013 /* Don't use try_window_reusing_current_matrix in this case
16014 because a window scroll function can have changed the
16016 || !NILP (Vwindow_scroll_functions
)
16017 || MINI_WINDOW_P (w
)
16018 || !(used_current_matrix_p
16019 = try_window_reusing_current_matrix (w
)))
16021 IF_DEBUG (debug_method_add (w
, "1"));
16022 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16023 /* -1 means we need to scroll.
16024 0 means we need new matrices, but fonts_changed
16025 is set in that case, so we will detect it below. */
16026 goto try_to_scroll
;
16029 if (f
->fonts_changed
)
16030 goto need_larger_matrices
;
16032 if (w
->cursor
.vpos
>= 0)
16034 if (!just_this_one_p
16035 || current_buffer
->clip_changed
16036 || BEG_UNCHANGED
< CHARPOS (startp
))
16037 /* Forget any recorded base line for line number display. */
16038 w
->base_line_number
= 0;
16040 if (!cursor_row_fully_visible_p (w
, 1, 0))
16042 clear_glyph_matrix (w
->desired_matrix
);
16043 last_line_misfit
= 1;
16045 /* Drop through and scroll. */
16050 clear_glyph_matrix (w
->desired_matrix
);
16055 /* Redisplay the mode line. Select the buffer properly for that. */
16056 if (!update_mode_line
)
16058 update_mode_line
= 1;
16059 w
->update_mode_line
= 1;
16062 /* Try to scroll by specified few lines. */
16063 if ((scroll_conservatively
16064 || emacs_scroll_step
16065 || temp_scroll_step
16066 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16067 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16068 && CHARPOS (startp
) >= BEGV
16069 && CHARPOS (startp
) <= ZV
)
16071 /* The function returns -1 if new fonts were loaded, 1 if
16072 successful, 0 if not successful. */
16073 int ss
= try_scrolling (window
, just_this_one_p
,
16074 scroll_conservatively
,
16076 temp_scroll_step
, last_line_misfit
);
16079 case SCROLLING_SUCCESS
:
16082 case SCROLLING_NEED_LARGER_MATRICES
:
16083 goto need_larger_matrices
;
16085 case SCROLLING_FAILED
:
16093 /* Finally, just choose a place to start which positions point
16094 according to user preferences. */
16099 debug_method_add (w
, "recenter");
16102 /* Forget any previously recorded base line for line number display. */
16103 if (!buffer_unchanged_p
)
16104 w
->base_line_number
= 0;
16106 /* Determine the window start relative to point. */
16107 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16108 it
.current_y
= it
.last_visible_y
;
16109 if (centering_position
< 0)
16111 int window_total_lines
16112 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16115 ? min (scroll_margin
, window_total_lines
/ 4)
16117 ptrdiff_t margin_pos
= CHARPOS (startp
);
16118 Lisp_Object aggressive
;
16121 /* If there is a scroll margin at the top of the window, find
16122 its character position. */
16124 /* Cannot call start_display if startp is not in the
16125 accessible region of the buffer. This can happen when we
16126 have just switched to a different buffer and/or changed
16127 its restriction. In that case, startp is initialized to
16128 the character position 1 (BEGV) because we did not yet
16129 have chance to display the buffer even once. */
16130 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16133 void *it1data
= NULL
;
16135 SAVE_IT (it1
, it
, it1data
);
16136 start_display (&it1
, w
, startp
);
16137 move_it_vertically (&it1
, margin
* frame_line_height
);
16138 margin_pos
= IT_CHARPOS (it1
);
16139 RESTORE_IT (&it
, &it
, it1data
);
16141 scrolling_up
= PT
> margin_pos
;
16144 ? BVAR (current_buffer
, scroll_up_aggressively
)
16145 : BVAR (current_buffer
, scroll_down_aggressively
);
16147 if (!MINI_WINDOW_P (w
)
16148 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16152 /* Setting scroll-conservatively overrides
16153 scroll-*-aggressively. */
16154 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16156 double float_amount
= XFLOATINT (aggressive
);
16158 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16159 if (pt_offset
== 0 && float_amount
> 0)
16161 if (pt_offset
&& margin
> 0)
16164 /* Compute how much to move the window start backward from
16165 point so that point will be displayed where the user
16169 centering_position
= it
.last_visible_y
;
16171 centering_position
-= pt_offset
;
16172 centering_position
-=
16173 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16174 + WINDOW_HEADER_LINE_HEIGHT (w
);
16175 /* Don't let point enter the scroll margin near top of
16177 if (centering_position
< margin
* frame_line_height
)
16178 centering_position
= margin
* frame_line_height
;
16181 centering_position
= margin
* frame_line_height
+ pt_offset
;
16184 /* Set the window start half the height of the window backward
16186 centering_position
= window_box_height (w
) / 2;
16188 move_it_vertically_backward (&it
, centering_position
);
16190 eassert (IT_CHARPOS (it
) >= BEGV
);
16192 /* The function move_it_vertically_backward may move over more
16193 than the specified y-distance. If it->w is small, e.g. a
16194 mini-buffer window, we may end up in front of the window's
16195 display area. Start displaying at the start of the line
16196 containing PT in this case. */
16197 if (it
.current_y
<= 0)
16199 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16200 move_it_vertically_backward (&it
, 0);
16204 it
.current_x
= it
.hpos
= 0;
16206 /* Set the window start position here explicitly, to avoid an
16207 infinite loop in case the functions in window-scroll-functions
16209 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16211 /* Run scroll hooks. */
16212 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16214 /* Redisplay the window. */
16215 if (!current_matrix_up_to_date_p
16216 || windows_or_buffers_changed
16217 || f
->cursor_type_changed
16218 /* Don't use try_window_reusing_current_matrix in this case
16219 because it can have changed the buffer. */
16220 || !NILP (Vwindow_scroll_functions
)
16221 || !just_this_one_p
16222 || MINI_WINDOW_P (w
)
16223 || !(used_current_matrix_p
16224 = try_window_reusing_current_matrix (w
)))
16225 try_window (window
, startp
, 0);
16227 /* If new fonts have been loaded (due to fontsets), give up. We
16228 have to start a new redisplay since we need to re-adjust glyph
16230 if (f
->fonts_changed
)
16231 goto need_larger_matrices
;
16233 /* If cursor did not appear assume that the middle of the window is
16234 in the first line of the window. Do it again with the next line.
16235 (Imagine a window of height 100, displaying two lines of height
16236 60. Moving back 50 from it->last_visible_y will end in the first
16238 if (w
->cursor
.vpos
< 0)
16240 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16242 clear_glyph_matrix (w
->desired_matrix
);
16243 move_it_by_lines (&it
, 1);
16244 try_window (window
, it
.current
.pos
, 0);
16246 else if (PT
< IT_CHARPOS (it
))
16248 clear_glyph_matrix (w
->desired_matrix
);
16249 move_it_by_lines (&it
, -1);
16250 try_window (window
, it
.current
.pos
, 0);
16254 /* Not much we can do about it. */
16258 /* Consider the following case: Window starts at BEGV, there is
16259 invisible, intangible text at BEGV, so that display starts at
16260 some point START > BEGV. It can happen that we are called with
16261 PT somewhere between BEGV and START. Try to handle that case. */
16262 if (w
->cursor
.vpos
< 0)
16264 struct glyph_row
*row
= w
->current_matrix
->rows
;
16265 if (row
->mode_line_p
)
16267 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16270 if (!cursor_row_fully_visible_p (w
, 0, 0))
16272 /* If vscroll is enabled, disable it and try again. */
16276 clear_glyph_matrix (w
->desired_matrix
);
16280 /* Users who set scroll-conservatively to a large number want
16281 point just above/below the scroll margin. If we ended up
16282 with point's row partially visible, move the window start to
16283 make that row fully visible and out of the margin. */
16284 if (scroll_conservatively
> SCROLL_LIMIT
)
16286 int window_total_lines
16287 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16290 ? min (scroll_margin
, window_total_lines
/ 4)
16292 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16294 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16295 clear_glyph_matrix (w
->desired_matrix
);
16296 if (1 == try_window (window
, it
.current
.pos
,
16297 TRY_WINDOW_CHECK_MARGINS
))
16301 /* If centering point failed to make the whole line visible,
16302 put point at the top instead. That has to make the whole line
16303 visible, if it can be done. */
16304 if (centering_position
== 0)
16307 clear_glyph_matrix (w
->desired_matrix
);
16308 centering_position
= 0;
16314 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16315 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16316 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16318 /* Display the mode line, if we must. */
16319 if ((update_mode_line
16320 /* If window not full width, must redo its mode line
16321 if (a) the window to its side is being redone and
16322 (b) we do a frame-based redisplay. This is a consequence
16323 of how inverted lines are drawn in frame-based redisplay. */
16324 || (!just_this_one_p
16325 && !FRAME_WINDOW_P (f
)
16326 && !WINDOW_FULL_WIDTH_P (w
))
16327 /* Line number to display. */
16328 || w
->base_line_pos
> 0
16329 /* Column number is displayed and different from the one displayed. */
16330 || (w
->column_number_displayed
!= -1
16331 && (w
->column_number_displayed
!= current_column ())))
16332 /* This means that the window has a mode line. */
16333 && (WINDOW_WANTS_MODELINE_P (w
)
16334 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16337 display_mode_lines (w
);
16339 /* If mode line height has changed, arrange for a thorough
16340 immediate redisplay using the correct mode line height. */
16341 if (WINDOW_WANTS_MODELINE_P (w
)
16342 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16344 f
->fonts_changed
= 1;
16345 w
->mode_line_height
= -1;
16346 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16347 = DESIRED_MODE_LINE_HEIGHT (w
);
16350 /* If header line height has changed, arrange for a thorough
16351 immediate redisplay using the correct header line height. */
16352 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16353 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16355 f
->fonts_changed
= 1;
16356 w
->header_line_height
= -1;
16357 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16358 = DESIRED_HEADER_LINE_HEIGHT (w
);
16361 if (f
->fonts_changed
)
16362 goto need_larger_matrices
;
16365 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16367 w
->base_line_pos
= 0;
16368 w
->base_line_number
= 0;
16373 /* When we reach a frame's selected window, redo the frame's menu bar. */
16374 if (update_mode_line
16375 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16377 int redisplay_menu_p
= 0;
16379 if (FRAME_WINDOW_P (f
))
16381 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16382 || defined (HAVE_NS) || defined (USE_GTK)
16383 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16385 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16389 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16391 if (redisplay_menu_p
)
16392 display_menu_bar (w
);
16394 #ifdef HAVE_WINDOW_SYSTEM
16395 if (FRAME_WINDOW_P (f
))
16397 #if defined (USE_GTK) || defined (HAVE_NS)
16398 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16399 redisplay_tool_bar (f
);
16401 if (WINDOWP (f
->tool_bar_window
)
16402 && (FRAME_TOOL_BAR_HEIGHT (f
) > 0
16403 || !NILP (Vauto_resize_tool_bars
))
16404 && redisplay_tool_bar (f
))
16405 ignore_mouse_drag_p
= 1;
16411 #ifdef HAVE_WINDOW_SYSTEM
16412 if (FRAME_WINDOW_P (f
)
16413 && update_window_fringes (w
, (just_this_one_p
16414 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16415 || w
->pseudo_window_p
)))
16419 if (draw_window_fringes (w
, 1))
16421 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16422 x_draw_right_divider (w
);
16424 x_draw_vertical_border (w
);
16430 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16431 x_draw_bottom_divider (w
);
16432 #endif /* HAVE_WINDOW_SYSTEM */
16434 /* We go to this label, with fonts_changed set, if it is
16435 necessary to try again using larger glyph matrices.
16436 We have to redeem the scroll bar even in this case,
16437 because the loop in redisplay_internal expects that. */
16438 need_larger_matrices
:
16440 finish_scroll_bars
:
16442 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16444 /* Set the thumb's position and size. */
16445 set_vertical_scroll_bar (w
);
16447 /* Note that we actually used the scroll bar attached to this
16448 window, so it shouldn't be deleted at the end of redisplay. */
16449 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16450 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16453 /* Restore current_buffer and value of point in it. The window
16454 update may have changed the buffer, so first make sure `opoint'
16455 is still valid (Bug#6177). */
16456 if (CHARPOS (opoint
) < BEGV
)
16457 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16458 else if (CHARPOS (opoint
) > ZV
)
16459 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16461 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16463 set_buffer_internal_1 (old
);
16464 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16465 shorter. This can be caused by log truncation in *Messages*. */
16466 if (CHARPOS (lpoint
) <= ZV
)
16467 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16469 unbind_to (count
, Qnil
);
16473 /* Build the complete desired matrix of WINDOW with a window start
16474 buffer position POS.
16476 Value is 1 if successful. It is zero if fonts were loaded during
16477 redisplay which makes re-adjusting glyph matrices necessary, and -1
16478 if point would appear in the scroll margins.
16479 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16480 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16484 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16486 struct window
*w
= XWINDOW (window
);
16488 struct glyph_row
*last_text_row
= NULL
;
16489 struct frame
*f
= XFRAME (w
->frame
);
16490 int frame_line_height
= default_line_pixel_height (w
);
16492 /* Make POS the new window start. */
16493 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16495 /* Mark cursor position as unknown. No overlay arrow seen. */
16496 w
->cursor
.vpos
= -1;
16497 overlay_arrow_seen
= 0;
16499 /* Initialize iterator and info to start at POS. */
16500 start_display (&it
, w
, pos
);
16502 /* Display all lines of W. */
16503 while (it
.current_y
< it
.last_visible_y
)
16505 if (display_line (&it
))
16506 last_text_row
= it
.glyph_row
- 1;
16507 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16511 /* Don't let the cursor end in the scroll margins. */
16512 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16513 && !MINI_WINDOW_P (w
))
16515 int this_scroll_margin
;
16516 int window_total_lines
16517 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16519 if (scroll_margin
> 0)
16521 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16522 this_scroll_margin
*= frame_line_height
;
16525 this_scroll_margin
= 0;
16527 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16528 && w
->cursor
.y
< this_scroll_margin
16529 && CHARPOS (pos
) > BEGV
16530 && IT_CHARPOS (it
) < ZV
)
16531 /* rms: considering make_cursor_line_fully_visible_p here
16532 seems to give wrong results. We don't want to recenter
16533 when the last line is partly visible, we want to allow
16534 that case to be handled in the usual way. */
16535 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16537 w
->cursor
.vpos
= -1;
16538 clear_glyph_matrix (w
->desired_matrix
);
16543 /* If bottom moved off end of frame, change mode line percentage. */
16544 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16545 w
->update_mode_line
= 1;
16547 /* Set window_end_pos to the offset of the last character displayed
16548 on the window from the end of current_buffer. Set
16549 window_end_vpos to its row number. */
16552 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16553 adjust_window_ends (w
, last_text_row
, 0);
16555 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16556 w
->window_end_vpos
)));
16560 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16561 w
->window_end_pos
= Z
- ZV
;
16562 w
->window_end_vpos
= 0;
16565 /* But that is not valid info until redisplay finishes. */
16566 w
->window_end_valid
= 0;
16572 /************************************************************************
16573 Window redisplay reusing current matrix when buffer has not changed
16574 ************************************************************************/
16576 /* Try redisplay of window W showing an unchanged buffer with a
16577 different window start than the last time it was displayed by
16578 reusing its current matrix. Value is non-zero if successful.
16579 W->start is the new window start. */
16582 try_window_reusing_current_matrix (struct window
*w
)
16584 struct frame
*f
= XFRAME (w
->frame
);
16585 struct glyph_row
*bottom_row
;
16588 struct text_pos start
, new_start
;
16589 int nrows_scrolled
, i
;
16590 struct glyph_row
*last_text_row
;
16591 struct glyph_row
*last_reused_text_row
;
16592 struct glyph_row
*start_row
;
16593 int start_vpos
, min_y
, max_y
;
16596 if (inhibit_try_window_reusing
)
16600 if (/* This function doesn't handle terminal frames. */
16601 !FRAME_WINDOW_P (f
)
16602 /* Don't try to reuse the display if windows have been split
16604 || windows_or_buffers_changed
16605 || f
->cursor_type_changed
)
16608 /* Can't do this if showing trailing whitespace. */
16609 if (!NILP (Vshow_trailing_whitespace
))
16612 /* If top-line visibility has changed, give up. */
16613 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16614 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16617 /* Give up if old or new display is scrolled vertically. We could
16618 make this function handle this, but right now it doesn't. */
16619 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16620 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16623 /* The variable new_start now holds the new window start. The old
16624 start `start' can be determined from the current matrix. */
16625 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16626 start
= start_row
->minpos
;
16627 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16629 /* Clear the desired matrix for the display below. */
16630 clear_glyph_matrix (w
->desired_matrix
);
16632 if (CHARPOS (new_start
) <= CHARPOS (start
))
16634 /* Don't use this method if the display starts with an ellipsis
16635 displayed for invisible text. It's not easy to handle that case
16636 below, and it's certainly not worth the effort since this is
16637 not a frequent case. */
16638 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16641 IF_DEBUG (debug_method_add (w
, "twu1"));
16643 /* Display up to a row that can be reused. The variable
16644 last_text_row is set to the last row displayed that displays
16645 text. Note that it.vpos == 0 if or if not there is a
16646 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16647 start_display (&it
, w
, new_start
);
16648 w
->cursor
.vpos
= -1;
16649 last_text_row
= last_reused_text_row
= NULL
;
16651 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16653 /* If we have reached into the characters in the START row,
16654 that means the line boundaries have changed. So we
16655 can't start copying with the row START. Maybe it will
16656 work to start copying with the following row. */
16657 while (IT_CHARPOS (it
) > CHARPOS (start
))
16659 /* Advance to the next row as the "start". */
16661 start
= start_row
->minpos
;
16662 /* If there are no more rows to try, or just one, give up. */
16663 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16664 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16665 || CHARPOS (start
) == ZV
)
16667 clear_glyph_matrix (w
->desired_matrix
);
16671 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16673 /* If we have reached alignment, we can copy the rest of the
16675 if (IT_CHARPOS (it
) == CHARPOS (start
)
16676 /* Don't accept "alignment" inside a display vector,
16677 since start_row could have started in the middle of
16678 that same display vector (thus their character
16679 positions match), and we have no way of telling if
16680 that is the case. */
16681 && it
.current
.dpvec_index
< 0)
16684 if (display_line (&it
))
16685 last_text_row
= it
.glyph_row
- 1;
16689 /* A value of current_y < last_visible_y means that we stopped
16690 at the previous window start, which in turn means that we
16691 have at least one reusable row. */
16692 if (it
.current_y
< it
.last_visible_y
)
16694 struct glyph_row
*row
;
16696 /* IT.vpos always starts from 0; it counts text lines. */
16697 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16699 /* Find PT if not already found in the lines displayed. */
16700 if (w
->cursor
.vpos
< 0)
16702 int dy
= it
.current_y
- start_row
->y
;
16704 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16705 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16707 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16708 dy
, nrows_scrolled
);
16711 clear_glyph_matrix (w
->desired_matrix
);
16716 /* Scroll the display. Do it before the current matrix is
16717 changed. The problem here is that update has not yet
16718 run, i.e. part of the current matrix is not up to date.
16719 scroll_run_hook will clear the cursor, and use the
16720 current matrix to get the height of the row the cursor is
16722 run
.current_y
= start_row
->y
;
16723 run
.desired_y
= it
.current_y
;
16724 run
.height
= it
.last_visible_y
- it
.current_y
;
16726 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16729 FRAME_RIF (f
)->update_window_begin_hook (w
);
16730 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16731 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16732 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16736 /* Shift current matrix down by nrows_scrolled lines. */
16737 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16738 rotate_matrix (w
->current_matrix
,
16740 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16743 /* Disable lines that must be updated. */
16744 for (i
= 0; i
< nrows_scrolled
; ++i
)
16745 (start_row
+ i
)->enabled_p
= false;
16747 /* Re-compute Y positions. */
16748 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16749 max_y
= it
.last_visible_y
;
16750 for (row
= start_row
+ nrows_scrolled
;
16754 row
->y
= it
.current_y
;
16755 row
->visible_height
= row
->height
;
16757 if (row
->y
< min_y
)
16758 row
->visible_height
-= min_y
- row
->y
;
16759 if (row
->y
+ row
->height
> max_y
)
16760 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16761 if (row
->fringe_bitmap_periodic_p
)
16762 row
->redraw_fringe_bitmaps_p
= 1;
16764 it
.current_y
+= row
->height
;
16766 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16767 last_reused_text_row
= row
;
16768 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16772 /* Disable lines in the current matrix which are now
16773 below the window. */
16774 for (++row
; row
< bottom_row
; ++row
)
16775 row
->enabled_p
= row
->mode_line_p
= 0;
16778 /* Update window_end_pos etc.; last_reused_text_row is the last
16779 reused row from the current matrix containing text, if any.
16780 The value of last_text_row is the last displayed line
16781 containing text. */
16782 if (last_reused_text_row
)
16783 adjust_window_ends (w
, last_reused_text_row
, 1);
16784 else if (last_text_row
)
16785 adjust_window_ends (w
, last_text_row
, 0);
16788 /* This window must be completely empty. */
16789 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16790 w
->window_end_pos
= Z
- ZV
;
16791 w
->window_end_vpos
= 0;
16793 w
->window_end_valid
= 0;
16795 /* Update hint: don't try scrolling again in update_window. */
16796 w
->desired_matrix
->no_scrolling_p
= 1;
16799 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16803 else if (CHARPOS (new_start
) > CHARPOS (start
))
16805 struct glyph_row
*pt_row
, *row
;
16806 struct glyph_row
*first_reusable_row
;
16807 struct glyph_row
*first_row_to_display
;
16809 int yb
= window_text_bottom_y (w
);
16811 /* Find the row starting at new_start, if there is one. Don't
16812 reuse a partially visible line at the end. */
16813 first_reusable_row
= start_row
;
16814 while (first_reusable_row
->enabled_p
16815 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16816 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16817 < CHARPOS (new_start
)))
16818 ++first_reusable_row
;
16820 /* Give up if there is no row to reuse. */
16821 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16822 || !first_reusable_row
->enabled_p
16823 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16824 != CHARPOS (new_start
)))
16827 /* We can reuse fully visible rows beginning with
16828 first_reusable_row to the end of the window. Set
16829 first_row_to_display to the first row that cannot be reused.
16830 Set pt_row to the row containing point, if there is any. */
16832 for (first_row_to_display
= first_reusable_row
;
16833 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16834 ++first_row_to_display
)
16836 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16837 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16838 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16839 && first_row_to_display
->ends_at_zv_p
16840 && pt_row
== NULL
)))
16841 pt_row
= first_row_to_display
;
16844 /* Start displaying at the start of first_row_to_display. */
16845 eassert (first_row_to_display
->y
< yb
);
16846 init_to_row_start (&it
, w
, first_row_to_display
);
16848 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16850 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16852 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16853 + WINDOW_HEADER_LINE_HEIGHT (w
));
16855 /* Display lines beginning with first_row_to_display in the
16856 desired matrix. Set last_text_row to the last row displayed
16857 that displays text. */
16858 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16859 if (pt_row
== NULL
)
16860 w
->cursor
.vpos
= -1;
16861 last_text_row
= NULL
;
16862 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16863 if (display_line (&it
))
16864 last_text_row
= it
.glyph_row
- 1;
16866 /* If point is in a reused row, adjust y and vpos of the cursor
16870 w
->cursor
.vpos
-= nrows_scrolled
;
16871 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16874 /* Give up if point isn't in a row displayed or reused. (This
16875 also handles the case where w->cursor.vpos < nrows_scrolled
16876 after the calls to display_line, which can happen with scroll
16877 margins. See bug#1295.) */
16878 if (w
->cursor
.vpos
< 0)
16880 clear_glyph_matrix (w
->desired_matrix
);
16884 /* Scroll the display. */
16885 run
.current_y
= first_reusable_row
->y
;
16886 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16887 run
.height
= it
.last_visible_y
- run
.current_y
;
16888 dy
= run
.current_y
- run
.desired_y
;
16893 FRAME_RIF (f
)->update_window_begin_hook (w
);
16894 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16895 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16896 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16900 /* Adjust Y positions of reused rows. */
16901 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16902 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16903 max_y
= it
.last_visible_y
;
16904 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16907 row
->visible_height
= row
->height
;
16908 if (row
->y
< min_y
)
16909 row
->visible_height
-= min_y
- row
->y
;
16910 if (row
->y
+ row
->height
> max_y
)
16911 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16912 if (row
->fringe_bitmap_periodic_p
)
16913 row
->redraw_fringe_bitmaps_p
= 1;
16916 /* Scroll the current matrix. */
16917 eassert (nrows_scrolled
> 0);
16918 rotate_matrix (w
->current_matrix
,
16920 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16923 /* Disable rows not reused. */
16924 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16925 row
->enabled_p
= false;
16927 /* Point may have moved to a different line, so we cannot assume that
16928 the previous cursor position is valid; locate the correct row. */
16931 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16933 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16934 && !row
->ends_at_zv_p
;
16938 w
->cursor
.y
= row
->y
;
16940 if (row
< bottom_row
)
16942 /* Can't simply scan the row for point with
16943 bidi-reordered glyph rows. Let set_cursor_from_row
16944 figure out where to put the cursor, and if it fails,
16946 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16948 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16951 clear_glyph_matrix (w
->desired_matrix
);
16957 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16958 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16961 && (!BUFFERP (glyph
->object
)
16962 || glyph
->charpos
< PT
);
16966 w
->cursor
.x
+= glyph
->pixel_width
;
16972 /* Adjust window end. A null value of last_text_row means that
16973 the window end is in reused rows which in turn means that
16974 only its vpos can have changed. */
16976 adjust_window_ends (w
, last_text_row
, 0);
16978 w
->window_end_vpos
-= nrows_scrolled
;
16980 w
->window_end_valid
= 0;
16981 w
->desired_matrix
->no_scrolling_p
= 1;
16984 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16994 /************************************************************************
16995 Window redisplay reusing current matrix when buffer has changed
16996 ************************************************************************/
16998 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16999 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17000 ptrdiff_t *, ptrdiff_t *);
17001 static struct glyph_row
*
17002 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17003 struct glyph_row
*);
17006 /* Return the last row in MATRIX displaying text. If row START is
17007 non-null, start searching with that row. IT gives the dimensions
17008 of the display. Value is null if matrix is empty; otherwise it is
17009 a pointer to the row found. */
17011 static struct glyph_row
*
17012 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17013 struct glyph_row
*start
)
17015 struct glyph_row
*row
, *row_found
;
17017 /* Set row_found to the last row in IT->w's current matrix
17018 displaying text. The loop looks funny but think of partially
17021 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17022 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17024 eassert (row
->enabled_p
);
17026 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17035 /* Return the last row in the current matrix of W that is not affected
17036 by changes at the start of current_buffer that occurred since W's
17037 current matrix was built. Value is null if no such row exists.
17039 BEG_UNCHANGED us the number of characters unchanged at the start of
17040 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17041 first changed character in current_buffer. Characters at positions <
17042 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17043 when the current matrix was built. */
17045 static struct glyph_row
*
17046 find_last_unchanged_at_beg_row (struct window
*w
)
17048 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17049 struct glyph_row
*row
;
17050 struct glyph_row
*row_found
= NULL
;
17051 int yb
= window_text_bottom_y (w
);
17053 /* Find the last row displaying unchanged text. */
17054 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17055 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17056 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17059 if (/* If row ends before first_changed_pos, it is unchanged,
17060 except in some case. */
17061 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17062 /* When row ends in ZV and we write at ZV it is not
17064 && !row
->ends_at_zv_p
17065 /* When first_changed_pos is the end of a continued line,
17066 row is not unchanged because it may be no longer
17068 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17069 && (row
->continued_p
17070 || row
->exact_window_width_line_p
))
17071 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17072 needs to be recomputed, so don't consider this row as
17073 unchanged. This happens when the last line was
17074 bidi-reordered and was killed immediately before this
17075 redisplay cycle. In that case, ROW->end stores the
17076 buffer position of the first visual-order character of
17077 the killed text, which is now beyond ZV. */
17078 && CHARPOS (row
->end
.pos
) <= ZV
)
17081 /* Stop if last visible row. */
17082 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17090 /* Find the first glyph row in the current matrix of W that is not
17091 affected by changes at the end of current_buffer since the
17092 time W's current matrix was built.
17094 Return in *DELTA the number of chars by which buffer positions in
17095 unchanged text at the end of current_buffer must be adjusted.
17097 Return in *DELTA_BYTES the corresponding number of bytes.
17099 Value is null if no such row exists, i.e. all rows are affected by
17102 static struct glyph_row
*
17103 find_first_unchanged_at_end_row (struct window
*w
,
17104 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17106 struct glyph_row
*row
;
17107 struct glyph_row
*row_found
= NULL
;
17109 *delta
= *delta_bytes
= 0;
17111 /* Display must not have been paused, otherwise the current matrix
17112 is not up to date. */
17113 eassert (w
->window_end_valid
);
17115 /* A value of window_end_pos >= END_UNCHANGED means that the window
17116 end is in the range of changed text. If so, there is no
17117 unchanged row at the end of W's current matrix. */
17118 if (w
->window_end_pos
>= END_UNCHANGED
)
17121 /* Set row to the last row in W's current matrix displaying text. */
17122 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17124 /* If matrix is entirely empty, no unchanged row exists. */
17125 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17127 /* The value of row is the last glyph row in the matrix having a
17128 meaningful buffer position in it. The end position of row
17129 corresponds to window_end_pos. This allows us to translate
17130 buffer positions in the current matrix to current buffer
17131 positions for characters not in changed text. */
17133 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17134 ptrdiff_t Z_BYTE_old
=
17135 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17136 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17137 struct glyph_row
*first_text_row
17138 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17140 *delta
= Z
- Z_old
;
17141 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17143 /* Set last_unchanged_pos to the buffer position of the last
17144 character in the buffer that has not been changed. Z is the
17145 index + 1 of the last character in current_buffer, i.e. by
17146 subtracting END_UNCHANGED we get the index of the last
17147 unchanged character, and we have to add BEG to get its buffer
17149 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17150 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17152 /* Search backward from ROW for a row displaying a line that
17153 starts at a minimum position >= last_unchanged_pos_old. */
17154 for (; row
> first_text_row
; --row
)
17156 /* This used to abort, but it can happen.
17157 It is ok to just stop the search instead here. KFS. */
17158 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17161 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17166 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17172 /* Make sure that glyph rows in the current matrix of window W
17173 reference the same glyph memory as corresponding rows in the
17174 frame's frame matrix. This function is called after scrolling W's
17175 current matrix on a terminal frame in try_window_id and
17176 try_window_reusing_current_matrix. */
17179 sync_frame_with_window_matrix_rows (struct window
*w
)
17181 struct frame
*f
= XFRAME (w
->frame
);
17182 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17184 /* Preconditions: W must be a leaf window and full-width. Its frame
17185 must have a frame matrix. */
17186 eassert (BUFFERP (w
->contents
));
17187 eassert (WINDOW_FULL_WIDTH_P (w
));
17188 eassert (!FRAME_WINDOW_P (f
));
17190 /* If W is a full-width window, glyph pointers in W's current matrix
17191 have, by definition, to be the same as glyph pointers in the
17192 corresponding frame matrix. Note that frame matrices have no
17193 marginal areas (see build_frame_matrix). */
17194 window_row
= w
->current_matrix
->rows
;
17195 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17196 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17197 while (window_row
< window_row_end
)
17199 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17200 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17202 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17203 frame_row
->glyphs
[TEXT_AREA
] = start
;
17204 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17205 frame_row
->glyphs
[LAST_AREA
] = end
;
17207 /* Disable frame rows whose corresponding window rows have
17208 been disabled in try_window_id. */
17209 if (!window_row
->enabled_p
)
17210 frame_row
->enabled_p
= false;
17212 ++window_row
, ++frame_row
;
17217 /* Find the glyph row in window W containing CHARPOS. Consider all
17218 rows between START and END (not inclusive). END null means search
17219 all rows to the end of the display area of W. Value is the row
17220 containing CHARPOS or null. */
17223 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17224 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17226 struct glyph_row
*row
= start
;
17227 struct glyph_row
*best_row
= NULL
;
17228 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17231 /* If we happen to start on a header-line, skip that. */
17232 if (row
->mode_line_p
)
17235 if ((end
&& row
>= end
) || !row
->enabled_p
)
17238 last_y
= window_text_bottom_y (w
) - dy
;
17242 /* Give up if we have gone too far. */
17243 if (end
&& row
>= end
)
17245 /* This formerly returned if they were equal.
17246 I think that both quantities are of a "last plus one" type;
17247 if so, when they are equal, the row is within the screen. -- rms. */
17248 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17251 /* If it is in this row, return this row. */
17252 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17253 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17254 /* The end position of a row equals the start
17255 position of the next row. If CHARPOS is there, we
17256 would rather consider it displayed in the next
17257 line, except when this line ends in ZV. */
17258 && !row_for_charpos_p (row
, charpos
)))
17259 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17263 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17264 || (!best_row
&& !row
->continued_p
))
17266 /* In bidi-reordered rows, there could be several rows whose
17267 edges surround CHARPOS, all of these rows belonging to
17268 the same continued line. We need to find the row which
17269 fits CHARPOS the best. */
17270 for (g
= row
->glyphs
[TEXT_AREA
];
17271 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17274 if (!STRINGP (g
->object
))
17276 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17278 mindif
= eabs (g
->charpos
- charpos
);
17280 /* Exact match always wins. */
17287 else if (best_row
&& !row
->continued_p
)
17294 /* Try to redisplay window W by reusing its existing display. W's
17295 current matrix must be up to date when this function is called,
17296 i.e. window_end_valid must be nonzero.
17300 1 if display has been updated
17301 0 if otherwise unsuccessful
17302 -1 if redisplay with same window start is known not to succeed
17304 The following steps are performed:
17306 1. Find the last row in the current matrix of W that is not
17307 affected by changes at the start of current_buffer. If no such row
17310 2. Find the first row in W's current matrix that is not affected by
17311 changes at the end of current_buffer. Maybe there is no such row.
17313 3. Display lines beginning with the row + 1 found in step 1 to the
17314 row found in step 2 or, if step 2 didn't find a row, to the end of
17317 4. If cursor is not known to appear on the window, give up.
17319 5. If display stopped at the row found in step 2, scroll the
17320 display and current matrix as needed.
17322 6. Maybe display some lines at the end of W, if we must. This can
17323 happen under various circumstances, like a partially visible line
17324 becoming fully visible, or because newly displayed lines are displayed
17325 in smaller font sizes.
17327 7. Update W's window end information. */
17330 try_window_id (struct window
*w
)
17332 struct frame
*f
= XFRAME (w
->frame
);
17333 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17334 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17335 struct glyph_row
*last_unchanged_at_beg_row
;
17336 struct glyph_row
*first_unchanged_at_end_row
;
17337 struct glyph_row
*row
;
17338 struct glyph_row
*bottom_row
;
17341 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17343 struct text_pos start_pos
;
17345 int first_unchanged_at_end_vpos
= 0;
17346 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17347 struct text_pos start
;
17348 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17351 if (inhibit_try_window_id
)
17355 /* This is handy for debugging. */
17357 #define GIVE_UP(X) \
17359 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17363 #define GIVE_UP(X) return 0
17366 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17368 /* Don't use this for mini-windows because these can show
17369 messages and mini-buffers, and we don't handle that here. */
17370 if (MINI_WINDOW_P (w
))
17373 /* This flag is used to prevent redisplay optimizations. */
17374 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17377 /* Verify that narrowing has not changed.
17378 Also verify that we were not told to prevent redisplay optimizations.
17379 It would be nice to further
17380 reduce the number of cases where this prevents try_window_id. */
17381 if (current_buffer
->clip_changed
17382 || current_buffer
->prevent_redisplay_optimizations_p
)
17385 /* Window must either use window-based redisplay or be full width. */
17386 if (!FRAME_WINDOW_P (f
)
17387 && (!FRAME_LINE_INS_DEL_OK (f
)
17388 || !WINDOW_FULL_WIDTH_P (w
)))
17391 /* Give up if point is known NOT to appear in W. */
17392 if (PT
< CHARPOS (start
))
17395 /* Another way to prevent redisplay optimizations. */
17396 if (w
->last_modified
== 0)
17399 /* Verify that window is not hscrolled. */
17400 if (w
->hscroll
!= 0)
17403 /* Verify that display wasn't paused. */
17404 if (!w
->window_end_valid
)
17407 /* Likewise if highlighting trailing whitespace. */
17408 if (!NILP (Vshow_trailing_whitespace
))
17411 /* Can't use this if overlay arrow position and/or string have
17413 if (overlay_arrows_changed_p ())
17416 /* When word-wrap is on, adding a space to the first word of a
17417 wrapped line can change the wrap position, altering the line
17418 above it. It might be worthwhile to handle this more
17419 intelligently, but for now just redisplay from scratch. */
17420 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17423 /* Under bidi reordering, adding or deleting a character in the
17424 beginning of a paragraph, before the first strong directional
17425 character, can change the base direction of the paragraph (unless
17426 the buffer specifies a fixed paragraph direction), which will
17427 require to redisplay the whole paragraph. It might be worthwhile
17428 to find the paragraph limits and widen the range of redisplayed
17429 lines to that, but for now just give up this optimization and
17430 redisplay from scratch. */
17431 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17432 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17435 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17436 only if buffer has really changed. The reason is that the gap is
17437 initially at Z for freshly visited files. The code below would
17438 set end_unchanged to 0 in that case. */
17439 if (MODIFF
> SAVE_MODIFF
17440 /* This seems to happen sometimes after saving a buffer. */
17441 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17443 if (GPT
- BEG
< BEG_UNCHANGED
)
17444 BEG_UNCHANGED
= GPT
- BEG
;
17445 if (Z
- GPT
< END_UNCHANGED
)
17446 END_UNCHANGED
= Z
- GPT
;
17449 /* The position of the first and last character that has been changed. */
17450 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17451 last_changed_charpos
= Z
- END_UNCHANGED
;
17453 /* If window starts after a line end, and the last change is in
17454 front of that newline, then changes don't affect the display.
17455 This case happens with stealth-fontification. Note that although
17456 the display is unchanged, glyph positions in the matrix have to
17457 be adjusted, of course. */
17458 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17459 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17460 && ((last_changed_charpos
< CHARPOS (start
)
17461 && CHARPOS (start
) == BEGV
)
17462 || (last_changed_charpos
< CHARPOS (start
) - 1
17463 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17465 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17466 struct glyph_row
*r0
;
17468 /* Compute how many chars/bytes have been added to or removed
17469 from the buffer. */
17470 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17471 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17472 Z_delta
= Z
- Z_old
;
17473 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17475 /* Give up if PT is not in the window. Note that it already has
17476 been checked at the start of try_window_id that PT is not in
17477 front of the window start. */
17478 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17481 /* If window start is unchanged, we can reuse the whole matrix
17482 as is, after adjusting glyph positions. No need to compute
17483 the window end again, since its offset from Z hasn't changed. */
17484 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17485 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17486 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17487 /* PT must not be in a partially visible line. */
17488 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17489 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17491 /* Adjust positions in the glyph matrix. */
17492 if (Z_delta
|| Z_delta_bytes
)
17494 struct glyph_row
*r1
17495 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17496 increment_matrix_positions (w
->current_matrix
,
17497 MATRIX_ROW_VPOS (r0
, current_matrix
),
17498 MATRIX_ROW_VPOS (r1
, current_matrix
),
17499 Z_delta
, Z_delta_bytes
);
17502 /* Set the cursor. */
17503 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17505 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17510 /* Handle the case that changes are all below what is displayed in
17511 the window, and that PT is in the window. This shortcut cannot
17512 be taken if ZV is visible in the window, and text has been added
17513 there that is visible in the window. */
17514 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17515 /* ZV is not visible in the window, or there are no
17516 changes at ZV, actually. */
17517 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17518 || first_changed_charpos
== last_changed_charpos
))
17520 struct glyph_row
*r0
;
17522 /* Give up if PT is not in the window. Note that it already has
17523 been checked at the start of try_window_id that PT is not in
17524 front of the window start. */
17525 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17528 /* If window start is unchanged, we can reuse the whole matrix
17529 as is, without changing glyph positions since no text has
17530 been added/removed in front of the window end. */
17531 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17532 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17533 /* PT must not be in a partially visible line. */
17534 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17535 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17537 /* We have to compute the window end anew since text
17538 could have been added/removed after it. */
17539 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17540 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17542 /* Set the cursor. */
17543 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17545 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17550 /* Give up if window start is in the changed area.
17552 The condition used to read
17554 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17556 but why that was tested escapes me at the moment. */
17557 if (CHARPOS (start
) >= first_changed_charpos
17558 && CHARPOS (start
) <= last_changed_charpos
)
17561 /* Check that window start agrees with the start of the first glyph
17562 row in its current matrix. Check this after we know the window
17563 start is not in changed text, otherwise positions would not be
17565 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17566 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17569 /* Give up if the window ends in strings. Overlay strings
17570 at the end are difficult to handle, so don't try. */
17571 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17572 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17575 /* Compute the position at which we have to start displaying new
17576 lines. Some of the lines at the top of the window might be
17577 reusable because they are not displaying changed text. Find the
17578 last row in W's current matrix not affected by changes at the
17579 start of current_buffer. Value is null if changes start in the
17580 first line of window. */
17581 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17582 if (last_unchanged_at_beg_row
)
17584 /* Avoid starting to display in the middle of a character, a TAB
17585 for instance. This is easier than to set up the iterator
17586 exactly, and it's not a frequent case, so the additional
17587 effort wouldn't really pay off. */
17588 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17589 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17590 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17591 --last_unchanged_at_beg_row
;
17593 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17596 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17598 start_pos
= it
.current
.pos
;
17600 /* Start displaying new lines in the desired matrix at the same
17601 vpos we would use in the current matrix, i.e. below
17602 last_unchanged_at_beg_row. */
17603 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17605 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17606 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17608 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17612 /* There are no reusable lines at the start of the window.
17613 Start displaying in the first text line. */
17614 start_display (&it
, w
, start
);
17615 it
.vpos
= it
.first_vpos
;
17616 start_pos
= it
.current
.pos
;
17619 /* Find the first row that is not affected by changes at the end of
17620 the buffer. Value will be null if there is no unchanged row, in
17621 which case we must redisplay to the end of the window. delta
17622 will be set to the value by which buffer positions beginning with
17623 first_unchanged_at_end_row have to be adjusted due to text
17625 first_unchanged_at_end_row
17626 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17627 IF_DEBUG (debug_delta
= delta
);
17628 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17630 /* Set stop_pos to the buffer position up to which we will have to
17631 display new lines. If first_unchanged_at_end_row != NULL, this
17632 is the buffer position of the start of the line displayed in that
17633 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17634 that we don't stop at a buffer position. */
17636 if (first_unchanged_at_end_row
)
17638 eassert (last_unchanged_at_beg_row
== NULL
17639 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17641 /* If this is a continuation line, move forward to the next one
17642 that isn't. Changes in lines above affect this line.
17643 Caution: this may move first_unchanged_at_end_row to a row
17644 not displaying text. */
17645 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17646 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17647 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17648 < it
.last_visible_y
))
17649 ++first_unchanged_at_end_row
;
17651 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17652 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17653 >= it
.last_visible_y
))
17654 first_unchanged_at_end_row
= NULL
;
17657 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17659 first_unchanged_at_end_vpos
17660 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17661 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17664 else if (last_unchanged_at_beg_row
== NULL
)
17670 /* Either there is no unchanged row at the end, or the one we have
17671 now displays text. This is a necessary condition for the window
17672 end pos calculation at the end of this function. */
17673 eassert (first_unchanged_at_end_row
== NULL
17674 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17676 debug_last_unchanged_at_beg_vpos
17677 = (last_unchanged_at_beg_row
17678 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17680 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17682 #endif /* GLYPH_DEBUG */
17685 /* Display new lines. Set last_text_row to the last new line
17686 displayed which has text on it, i.e. might end up as being the
17687 line where the window_end_vpos is. */
17688 w
->cursor
.vpos
= -1;
17689 last_text_row
= NULL
;
17690 overlay_arrow_seen
= 0;
17691 while (it
.current_y
< it
.last_visible_y
17692 && !f
->fonts_changed
17693 && (first_unchanged_at_end_row
== NULL
17694 || IT_CHARPOS (it
) < stop_pos
))
17696 if (display_line (&it
))
17697 last_text_row
= it
.glyph_row
- 1;
17700 if (f
->fonts_changed
)
17704 /* Compute differences in buffer positions, y-positions etc. for
17705 lines reused at the bottom of the window. Compute what we can
17707 if (first_unchanged_at_end_row
17708 /* No lines reused because we displayed everything up to the
17709 bottom of the window. */
17710 && it
.current_y
< it
.last_visible_y
)
17713 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17715 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17716 run
.current_y
= first_unchanged_at_end_row
->y
;
17717 run
.desired_y
= run
.current_y
+ dy
;
17718 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17722 delta
= delta_bytes
= dvpos
= dy
17723 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17724 first_unchanged_at_end_row
= NULL
;
17726 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
17729 /* Find the cursor if not already found. We have to decide whether
17730 PT will appear on this window (it sometimes doesn't, but this is
17731 not a very frequent case.) This decision has to be made before
17732 the current matrix is altered. A value of cursor.vpos < 0 means
17733 that PT is either in one of the lines beginning at
17734 first_unchanged_at_end_row or below the window. Don't care for
17735 lines that might be displayed later at the window end; as
17736 mentioned, this is not a frequent case. */
17737 if (w
->cursor
.vpos
< 0)
17739 /* Cursor in unchanged rows at the top? */
17740 if (PT
< CHARPOS (start_pos
)
17741 && last_unchanged_at_beg_row
)
17743 row
= row_containing_pos (w
, PT
,
17744 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17745 last_unchanged_at_beg_row
+ 1, 0);
17747 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17750 /* Start from first_unchanged_at_end_row looking for PT. */
17751 else if (first_unchanged_at_end_row
)
17753 row
= row_containing_pos (w
, PT
- delta
,
17754 first_unchanged_at_end_row
, NULL
, 0);
17756 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17757 delta_bytes
, dy
, dvpos
);
17760 /* Give up if cursor was not found. */
17761 if (w
->cursor
.vpos
< 0)
17763 clear_glyph_matrix (w
->desired_matrix
);
17768 /* Don't let the cursor end in the scroll margins. */
17770 int this_scroll_margin
, cursor_height
;
17771 int frame_line_height
= default_line_pixel_height (w
);
17772 int window_total_lines
17773 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17775 this_scroll_margin
=
17776 max (0, min (scroll_margin
, window_total_lines
/ 4));
17777 this_scroll_margin
*= frame_line_height
;
17778 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17780 if ((w
->cursor
.y
< this_scroll_margin
17781 && CHARPOS (start
) > BEGV
)
17782 /* Old redisplay didn't take scroll margin into account at the bottom,
17783 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17784 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17785 ? cursor_height
+ this_scroll_margin
17786 : 1)) > it
.last_visible_y
)
17788 w
->cursor
.vpos
= -1;
17789 clear_glyph_matrix (w
->desired_matrix
);
17794 /* Scroll the display. Do it before changing the current matrix so
17795 that xterm.c doesn't get confused about where the cursor glyph is
17797 if (dy
&& run
.height
)
17801 if (FRAME_WINDOW_P (f
))
17803 FRAME_RIF (f
)->update_window_begin_hook (w
);
17804 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17805 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17806 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17810 /* Terminal frame. In this case, dvpos gives the number of
17811 lines to scroll by; dvpos < 0 means scroll up. */
17813 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17814 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17815 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17816 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17817 + window_internal_height (w
));
17819 #if defined (HAVE_GPM) || defined (MSDOS)
17820 x_clear_window_mouse_face (w
);
17822 /* Perform the operation on the screen. */
17825 /* Scroll last_unchanged_at_beg_row to the end of the
17826 window down dvpos lines. */
17827 set_terminal_window (f
, end
);
17829 /* On dumb terminals delete dvpos lines at the end
17830 before inserting dvpos empty lines. */
17831 if (!FRAME_SCROLL_REGION_OK (f
))
17832 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17834 /* Insert dvpos empty lines in front of
17835 last_unchanged_at_beg_row. */
17836 ins_del_lines (f
, from
, dvpos
);
17838 else if (dvpos
< 0)
17840 /* Scroll up last_unchanged_at_beg_vpos to the end of
17841 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17842 set_terminal_window (f
, end
);
17844 /* Delete dvpos lines in front of
17845 last_unchanged_at_beg_vpos. ins_del_lines will set
17846 the cursor to the given vpos and emit |dvpos| delete
17848 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17850 /* On a dumb terminal insert dvpos empty lines at the
17852 if (!FRAME_SCROLL_REGION_OK (f
))
17853 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17856 set_terminal_window (f
, 0);
17862 /* Shift reused rows of the current matrix to the right position.
17863 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17865 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17866 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17869 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17870 bottom_vpos
, dvpos
);
17871 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17874 else if (dvpos
> 0)
17876 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17877 bottom_vpos
, dvpos
);
17878 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17879 first_unchanged_at_end_vpos
+ dvpos
);
17882 /* For frame-based redisplay, make sure that current frame and window
17883 matrix are in sync with respect to glyph memory. */
17884 if (!FRAME_WINDOW_P (f
))
17885 sync_frame_with_window_matrix_rows (w
);
17887 /* Adjust buffer positions in reused rows. */
17888 if (delta
|| delta_bytes
)
17889 increment_matrix_positions (current_matrix
,
17890 first_unchanged_at_end_vpos
+ dvpos
,
17891 bottom_vpos
, delta
, delta_bytes
);
17893 /* Adjust Y positions. */
17895 shift_glyph_matrix (w
, current_matrix
,
17896 first_unchanged_at_end_vpos
+ dvpos
,
17899 if (first_unchanged_at_end_row
)
17901 first_unchanged_at_end_row
+= dvpos
;
17902 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17903 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17904 first_unchanged_at_end_row
= NULL
;
17907 /* If scrolling up, there may be some lines to display at the end of
17909 last_text_row_at_end
= NULL
;
17912 /* Scrolling up can leave for example a partially visible line
17913 at the end of the window to be redisplayed. */
17914 /* Set last_row to the glyph row in the current matrix where the
17915 window end line is found. It has been moved up or down in
17916 the matrix by dvpos. */
17917 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17918 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17920 /* If last_row is the window end line, it should display text. */
17921 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17923 /* If window end line was partially visible before, begin
17924 displaying at that line. Otherwise begin displaying with the
17925 line following it. */
17926 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17928 init_to_row_start (&it
, w
, last_row
);
17929 it
.vpos
= last_vpos
;
17930 it
.current_y
= last_row
->y
;
17934 init_to_row_end (&it
, w
, last_row
);
17935 it
.vpos
= 1 + last_vpos
;
17936 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17940 /* We may start in a continuation line. If so, we have to
17941 get the right continuation_lines_width and current_x. */
17942 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17943 it
.hpos
= it
.current_x
= 0;
17945 /* Display the rest of the lines at the window end. */
17946 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17947 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17949 /* Is it always sure that the display agrees with lines in
17950 the current matrix? I don't think so, so we mark rows
17951 displayed invalid in the current matrix by setting their
17952 enabled_p flag to zero. */
17953 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
17954 if (display_line (&it
))
17955 last_text_row_at_end
= it
.glyph_row
- 1;
17959 /* Update window_end_pos and window_end_vpos. */
17960 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17962 /* Window end line if one of the preserved rows from the current
17963 matrix. Set row to the last row displaying text in current
17964 matrix starting at first_unchanged_at_end_row, after
17966 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17967 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17968 first_unchanged_at_end_row
);
17969 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17970 adjust_window_ends (w
, row
, 1);
17971 eassert (w
->window_end_bytepos
>= 0);
17972 IF_DEBUG (debug_method_add (w
, "A"));
17974 else if (last_text_row_at_end
)
17976 adjust_window_ends (w
, last_text_row_at_end
, 0);
17977 eassert (w
->window_end_bytepos
>= 0);
17978 IF_DEBUG (debug_method_add (w
, "B"));
17980 else if (last_text_row
)
17982 /* We have displayed either to the end of the window or at the
17983 end of the window, i.e. the last row with text is to be found
17984 in the desired matrix. */
17985 adjust_window_ends (w
, last_text_row
, 0);
17986 eassert (w
->window_end_bytepos
>= 0);
17988 else if (first_unchanged_at_end_row
== NULL
17989 && last_text_row
== NULL
17990 && last_text_row_at_end
== NULL
)
17992 /* Displayed to end of window, but no line containing text was
17993 displayed. Lines were deleted at the end of the window. */
17994 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17995 int vpos
= w
->window_end_vpos
;
17996 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17997 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18000 row
== NULL
&& vpos
>= first_vpos
;
18001 --vpos
, --current_row
, --desired_row
)
18003 if (desired_row
->enabled_p
)
18005 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18008 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18012 eassert (row
!= NULL
);
18013 w
->window_end_vpos
= vpos
+ 1;
18014 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18015 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18016 eassert (w
->window_end_bytepos
>= 0);
18017 IF_DEBUG (debug_method_add (w
, "C"));
18022 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18023 debug_end_vpos
= w
->window_end_vpos
));
18025 /* Record that display has not been completed. */
18026 w
->window_end_valid
= 0;
18027 w
->desired_matrix
->no_scrolling_p
= 1;
18035 /***********************************************************************
18036 More debugging support
18037 ***********************************************************************/
18041 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18042 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18043 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18046 /* Dump the contents of glyph matrix MATRIX on stderr.
18048 GLYPHS 0 means don't show glyph contents.
18049 GLYPHS 1 means show glyphs in short form
18050 GLYPHS > 1 means show glyphs in long form. */
18053 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18056 for (i
= 0; i
< matrix
->nrows
; ++i
)
18057 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18061 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18062 the glyph row and area where the glyph comes from. */
18065 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18067 if (glyph
->type
== CHAR_GLYPH
18068 || glyph
->type
== GLYPHLESS_GLYPH
)
18071 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18072 glyph
- row
->glyphs
[TEXT_AREA
],
18073 (glyph
->type
== CHAR_GLYPH
18077 (BUFFERP (glyph
->object
)
18079 : (STRINGP (glyph
->object
)
18081 : (INTEGERP (glyph
->object
)
18084 glyph
->pixel_width
,
18086 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18090 glyph
->left_box_line_p
,
18091 glyph
->right_box_line_p
);
18093 else if (glyph
->type
== STRETCH_GLYPH
)
18096 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18097 glyph
- row
->glyphs
[TEXT_AREA
],
18100 (BUFFERP (glyph
->object
)
18102 : (STRINGP (glyph
->object
)
18104 : (INTEGERP (glyph
->object
)
18107 glyph
->pixel_width
,
18111 glyph
->left_box_line_p
,
18112 glyph
->right_box_line_p
);
18114 else if (glyph
->type
== IMAGE_GLYPH
)
18117 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18118 glyph
- row
->glyphs
[TEXT_AREA
],
18121 (BUFFERP (glyph
->object
)
18123 : (STRINGP (glyph
->object
)
18125 : (INTEGERP (glyph
->object
)
18128 glyph
->pixel_width
,
18132 glyph
->left_box_line_p
,
18133 glyph
->right_box_line_p
);
18135 else if (glyph
->type
== COMPOSITE_GLYPH
)
18138 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18139 glyph
- row
->glyphs
[TEXT_AREA
],
18142 (BUFFERP (glyph
->object
)
18144 : (STRINGP (glyph
->object
)
18146 : (INTEGERP (glyph
->object
)
18149 glyph
->pixel_width
,
18151 if (glyph
->u
.cmp
.automatic
)
18154 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18155 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18157 glyph
->left_box_line_p
,
18158 glyph
->right_box_line_p
);
18163 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18164 GLYPHS 0 means don't show glyph contents.
18165 GLYPHS 1 means show glyphs in short form
18166 GLYPHS > 1 means show glyphs in long form. */
18169 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18173 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18174 fprintf (stderr
, "==============================================================================\n");
18176 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18177 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18179 MATRIX_ROW_START_CHARPOS (row
),
18180 MATRIX_ROW_END_CHARPOS (row
),
18181 row
->used
[TEXT_AREA
],
18182 row
->contains_overlapping_glyphs_p
,
18184 row
->truncated_on_left_p
,
18185 row
->truncated_on_right_p
,
18187 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18188 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18191 row
->ends_in_middle_of_char_p
,
18192 row
->starts_in_middle_of_char_p
,
18198 row
->visible_height
,
18201 /* The next 3 lines should align to "Start" in the header. */
18202 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18203 row
->end
.overlay_string_index
,
18204 row
->continuation_lines_width
);
18205 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18206 CHARPOS (row
->start
.string_pos
),
18207 CHARPOS (row
->end
.string_pos
));
18208 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18209 row
->end
.dpvec_index
);
18216 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18218 struct glyph
*glyph
= row
->glyphs
[area
];
18219 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18221 /* Glyph for a line end in text. */
18222 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18225 if (glyph
< glyph_end
)
18226 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18228 for (; glyph
< glyph_end
; ++glyph
)
18229 dump_glyph (row
, glyph
, area
);
18232 else if (glyphs
== 1)
18236 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18238 char *s
= alloca (row
->used
[area
] + 4);
18241 for (i
= 0; i
< row
->used
[area
]; ++i
)
18243 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18244 if (i
== row
->used
[area
] - 1
18245 && area
== TEXT_AREA
18246 && INTEGERP (glyph
->object
)
18247 && glyph
->type
== CHAR_GLYPH
18248 && glyph
->u
.ch
== ' ')
18250 strcpy (&s
[i
], "[\\n]");
18253 else if (glyph
->type
== CHAR_GLYPH
18254 && glyph
->u
.ch
< 0x80
18255 && glyph
->u
.ch
>= ' ')
18256 s
[i
] = glyph
->u
.ch
;
18262 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18268 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18269 Sdump_glyph_matrix
, 0, 1, "p",
18270 doc
: /* Dump the current matrix of the selected window to stderr.
18271 Shows contents of glyph row structures. With non-nil
18272 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18273 glyphs in short form, otherwise show glyphs in long form. */)
18274 (Lisp_Object glyphs
)
18276 struct window
*w
= XWINDOW (selected_window
);
18277 struct buffer
*buffer
= XBUFFER (w
->contents
);
18279 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18280 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18281 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18282 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18283 fprintf (stderr
, "=============================================\n");
18284 dump_glyph_matrix (w
->current_matrix
,
18285 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18290 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18291 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18294 struct frame
*f
= XFRAME (selected_frame
);
18295 dump_glyph_matrix (f
->current_matrix
, 1);
18300 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18301 doc
: /* Dump glyph row ROW to stderr.
18302 GLYPH 0 means don't dump glyphs.
18303 GLYPH 1 means dump glyphs in short form.
18304 GLYPH > 1 or omitted means dump glyphs in long form. */)
18305 (Lisp_Object row
, Lisp_Object glyphs
)
18307 struct glyph_matrix
*matrix
;
18310 CHECK_NUMBER (row
);
18311 matrix
= XWINDOW (selected_window
)->current_matrix
;
18313 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18314 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18316 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18321 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18322 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18323 GLYPH 0 means don't dump glyphs.
18324 GLYPH 1 means dump glyphs in short form.
18325 GLYPH > 1 or omitted means dump glyphs in long form.
18327 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18329 (Lisp_Object row
, Lisp_Object glyphs
)
18331 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18332 struct frame
*sf
= SELECTED_FRAME ();
18333 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18336 CHECK_NUMBER (row
);
18338 if (vpos
>= 0 && vpos
< m
->nrows
)
18339 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18340 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18346 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18347 doc
: /* Toggle tracing of redisplay.
18348 With ARG, turn tracing on if and only if ARG is positive. */)
18352 trace_redisplay_p
= !trace_redisplay_p
;
18355 arg
= Fprefix_numeric_value (arg
);
18356 trace_redisplay_p
= XINT (arg
) > 0;
18363 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18364 doc
: /* Like `format', but print result to stderr.
18365 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18366 (ptrdiff_t nargs
, Lisp_Object
*args
)
18368 Lisp_Object s
= Fformat (nargs
, args
);
18369 fprintf (stderr
, "%s", SDATA (s
));
18373 #endif /* GLYPH_DEBUG */
18377 /***********************************************************************
18378 Building Desired Matrix Rows
18379 ***********************************************************************/
18381 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18382 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18384 static struct glyph_row
*
18385 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18387 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18388 struct buffer
*buffer
= XBUFFER (w
->contents
);
18389 struct buffer
*old
= current_buffer
;
18390 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18391 int arrow_len
= SCHARS (overlay_arrow_string
);
18392 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18393 const unsigned char *p
;
18396 int n_glyphs_before
;
18398 set_buffer_temp (buffer
);
18399 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18400 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18401 SET_TEXT_POS (it
.position
, 0, 0);
18403 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18405 while (p
< arrow_end
)
18407 Lisp_Object face
, ilisp
;
18409 /* Get the next character. */
18411 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18414 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18415 if (! ASCII_CHAR_P (it
.c
))
18416 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18420 /* Get its face. */
18421 ilisp
= make_number (p
- arrow_string
);
18422 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18423 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18425 /* Compute its width, get its glyphs. */
18426 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18427 SET_TEXT_POS (it
.position
, -1, -1);
18428 PRODUCE_GLYPHS (&it
);
18430 /* If this character doesn't fit any more in the line, we have
18431 to remove some glyphs. */
18432 if (it
.current_x
> it
.last_visible_x
)
18434 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18439 set_buffer_temp (old
);
18440 return it
.glyph_row
;
18444 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18445 glyphs to insert is determined by produce_special_glyphs. */
18448 insert_left_trunc_glyphs (struct it
*it
)
18450 struct it truncate_it
;
18451 struct glyph
*from
, *end
, *to
, *toend
;
18453 eassert (!FRAME_WINDOW_P (it
->f
)
18454 || (!it
->glyph_row
->reversed_p
18455 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18456 || (it
->glyph_row
->reversed_p
18457 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18459 /* Get the truncation glyphs. */
18461 truncate_it
.current_x
= 0;
18462 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18463 truncate_it
.glyph_row
= &scratch_glyph_row
;
18464 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18465 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18466 truncate_it
.object
= make_number (0);
18467 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18469 /* Overwrite glyphs from IT with truncation glyphs. */
18470 if (!it
->glyph_row
->reversed_p
)
18472 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18474 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18475 end
= from
+ tused
;
18476 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18477 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18478 if (FRAME_WINDOW_P (it
->f
))
18480 /* On GUI frames, when variable-size fonts are displayed,
18481 the truncation glyphs may need more pixels than the row's
18482 glyphs they overwrite. We overwrite more glyphs to free
18483 enough screen real estate, and enlarge the stretch glyph
18484 on the right (see display_line), if there is one, to
18485 preserve the screen position of the truncation glyphs on
18488 struct glyph
*g
= to
;
18491 /* The first glyph could be partially visible, in which case
18492 it->glyph_row->x will be negative. But we want the left
18493 truncation glyphs to be aligned at the left margin of the
18494 window, so we override the x coordinate at which the row
18496 it
->glyph_row
->x
= 0;
18497 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18499 w
+= g
->pixel_width
;
18502 if (g
- to
- tused
> 0)
18504 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18505 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18507 used
= it
->glyph_row
->used
[TEXT_AREA
];
18508 if (it
->glyph_row
->truncated_on_right_p
18509 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18510 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18513 int extra
= w
- it
->truncation_pixel_width
;
18515 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18522 /* There may be padding glyphs left over. Overwrite them too. */
18523 if (!FRAME_WINDOW_P (it
->f
))
18525 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18527 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18534 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18538 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18540 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18541 that back to front. */
18542 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18543 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18544 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18545 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18546 if (FRAME_WINDOW_P (it
->f
))
18549 struct glyph
*g
= to
;
18551 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18553 w
+= g
->pixel_width
;
18556 if (to
- g
- tused
> 0)
18558 if (it
->glyph_row
->truncated_on_right_p
18559 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18560 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18562 int extra
= w
- it
->truncation_pixel_width
;
18564 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18568 while (from
>= end
&& to
>= toend
)
18570 if (!FRAME_WINDOW_P (it
->f
))
18572 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18575 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18576 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18577 while (from
>= end
&& to
>= toend
)
18583 /* Need to free some room before prepending additional
18585 int move_by
= from
- end
+ 1;
18586 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18587 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18589 for ( ; g
>= g0
; g
--)
18591 while (from
>= end
)
18593 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18598 /* Compute the hash code for ROW. */
18600 row_hash (struct glyph_row
*row
)
18603 unsigned hashval
= 0;
18605 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18606 for (k
= 0; k
< row
->used
[area
]; ++k
)
18607 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18608 + row
->glyphs
[area
][k
].u
.val
18609 + row
->glyphs
[area
][k
].face_id
18610 + row
->glyphs
[area
][k
].padding_p
18611 + (row
->glyphs
[area
][k
].type
<< 2));
18616 /* Compute the pixel height and width of IT->glyph_row.
18618 Most of the time, ascent and height of a display line will be equal
18619 to the max_ascent and max_height values of the display iterator
18620 structure. This is not the case if
18622 1. We hit ZV without displaying anything. In this case, max_ascent
18623 and max_height will be zero.
18625 2. We have some glyphs that don't contribute to the line height.
18626 (The glyph row flag contributes_to_line_height_p is for future
18627 pixmap extensions).
18629 The first case is easily covered by using default values because in
18630 these cases, the line height does not really matter, except that it
18631 must not be zero. */
18634 compute_line_metrics (struct it
*it
)
18636 struct glyph_row
*row
= it
->glyph_row
;
18638 if (FRAME_WINDOW_P (it
->f
))
18640 int i
, min_y
, max_y
;
18642 /* The line may consist of one space only, that was added to
18643 place the cursor on it. If so, the row's height hasn't been
18645 if (row
->height
== 0)
18647 if (it
->max_ascent
+ it
->max_descent
== 0)
18648 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18649 row
->ascent
= it
->max_ascent
;
18650 row
->height
= it
->max_ascent
+ it
->max_descent
;
18651 row
->phys_ascent
= it
->max_phys_ascent
;
18652 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18653 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18656 /* Compute the width of this line. */
18657 row
->pixel_width
= row
->x
;
18658 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18659 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18661 eassert (row
->pixel_width
>= 0);
18662 eassert (row
->ascent
>= 0 && row
->height
> 0);
18664 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18665 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18667 /* If first line's physical ascent is larger than its logical
18668 ascent, use the physical ascent, and make the row taller.
18669 This makes accented characters fully visible. */
18670 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18671 && row
->phys_ascent
> row
->ascent
)
18673 row
->height
+= row
->phys_ascent
- row
->ascent
;
18674 row
->ascent
= row
->phys_ascent
;
18677 /* Compute how much of the line is visible. */
18678 row
->visible_height
= row
->height
;
18680 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18681 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18683 if (row
->y
< min_y
)
18684 row
->visible_height
-= min_y
- row
->y
;
18685 if (row
->y
+ row
->height
> max_y
)
18686 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18690 row
->pixel_width
= row
->used
[TEXT_AREA
];
18691 if (row
->continued_p
)
18692 row
->pixel_width
-= it
->continuation_pixel_width
;
18693 else if (row
->truncated_on_right_p
)
18694 row
->pixel_width
-= it
->truncation_pixel_width
;
18695 row
->ascent
= row
->phys_ascent
= 0;
18696 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18697 row
->extra_line_spacing
= 0;
18700 /* Compute a hash code for this row. */
18701 row
->hash
= row_hash (row
);
18703 it
->max_ascent
= it
->max_descent
= 0;
18704 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18708 /* Append one space to the glyph row of iterator IT if doing a
18709 window-based redisplay. The space has the same face as
18710 IT->face_id. Value is non-zero if a space was added.
18712 This function is called to make sure that there is always one glyph
18713 at the end of a glyph row that the cursor can be set on under
18714 window-systems. (If there weren't such a glyph we would not know
18715 how wide and tall a box cursor should be displayed).
18717 At the same time this space let's a nicely handle clearing to the
18718 end of the line if the row ends in italic text. */
18721 append_space_for_newline (struct it
*it
, int default_face_p
)
18723 if (FRAME_WINDOW_P (it
->f
))
18725 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18727 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18728 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18730 /* Save some values that must not be changed.
18731 Must save IT->c and IT->len because otherwise
18732 ITERATOR_AT_END_P wouldn't work anymore after
18733 append_space_for_newline has been called. */
18734 enum display_element_type saved_what
= it
->what
;
18735 int saved_c
= it
->c
, saved_len
= it
->len
;
18736 int saved_char_to_display
= it
->char_to_display
;
18737 int saved_x
= it
->current_x
;
18738 int saved_face_id
= it
->face_id
;
18739 int saved_box_end
= it
->end_of_box_run_p
;
18740 struct text_pos saved_pos
;
18741 Lisp_Object saved_object
;
18744 saved_object
= it
->object
;
18745 saved_pos
= it
->position
;
18747 it
->what
= IT_CHARACTER
;
18748 memset (&it
->position
, 0, sizeof it
->position
);
18749 it
->object
= make_number (0);
18750 it
->c
= it
->char_to_display
= ' ';
18753 /* If the default face was remapped, be sure to use the
18754 remapped face for the appended newline. */
18755 if (default_face_p
)
18756 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18757 else if (it
->face_before_selective_p
)
18758 it
->face_id
= it
->saved_face_id
;
18759 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18760 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18761 /* In R2L rows, we will prepend a stretch glyph that will
18762 have the end_of_box_run_p flag set for it, so there's no
18763 need for the appended newline glyph to have that flag
18765 if (it
->glyph_row
->reversed_p
18766 /* But if the appended newline glyph goes all the way to
18767 the end of the row, there will be no stretch glyph,
18768 so leave the box flag set. */
18769 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18770 it
->end_of_box_run_p
= 0;
18772 PRODUCE_GLYPHS (it
);
18774 it
->override_ascent
= -1;
18775 it
->constrain_row_ascent_descent_p
= 0;
18776 it
->current_x
= saved_x
;
18777 it
->object
= saved_object
;
18778 it
->position
= saved_pos
;
18779 it
->what
= saved_what
;
18780 it
->face_id
= saved_face_id
;
18781 it
->len
= saved_len
;
18783 it
->char_to_display
= saved_char_to_display
;
18784 it
->end_of_box_run_p
= saved_box_end
;
18793 /* Extend the face of the last glyph in the text area of IT->glyph_row
18794 to the end of the display line. Called from display_line. If the
18795 glyph row is empty, add a space glyph to it so that we know the
18796 face to draw. Set the glyph row flag fill_line_p. If the glyph
18797 row is R2L, prepend a stretch glyph to cover the empty space to the
18798 left of the leftmost glyph. */
18801 extend_face_to_end_of_line (struct it
*it
)
18803 struct face
*face
, *default_face
;
18804 struct frame
*f
= it
->f
;
18806 /* If line is already filled, do nothing. Non window-system frames
18807 get a grace of one more ``pixel'' because their characters are
18808 1-``pixel'' wide, so they hit the equality too early. This grace
18809 is needed only for R2L rows that are not continued, to produce
18810 one extra blank where we could display the cursor. */
18811 if ((it
->current_x
>= it
->last_visible_x
18812 + (!FRAME_WINDOW_P (f
)
18813 && it
->glyph_row
->reversed_p
18814 && !it
->glyph_row
->continued_p
))
18815 /* If the window has display margins, we will need to extend
18816 their face even if the text area is filled. */
18817 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18818 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
18821 /* The default face, possibly remapped. */
18822 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18824 /* Face extension extends the background and box of IT->face_id
18825 to the end of the line. If the background equals the background
18826 of the frame, we don't have to do anything. */
18827 if (it
->face_before_selective_p
)
18828 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18830 face
= FACE_FROM_ID (f
, it
->face_id
);
18832 if (FRAME_WINDOW_P (f
)
18833 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18834 && face
->box
== FACE_NO_BOX
18835 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18836 #ifdef HAVE_WINDOW_SYSTEM
18839 && !it
->glyph_row
->reversed_p
)
18842 /* Set the glyph row flag indicating that the face of the last glyph
18843 in the text area has to be drawn to the end of the text area. */
18844 it
->glyph_row
->fill_line_p
= 1;
18846 /* If current character of IT is not ASCII, make sure we have the
18847 ASCII face. This will be automatically undone the next time
18848 get_next_display_element returns a multibyte character. Note
18849 that the character will always be single byte in unibyte
18851 if (!ASCII_CHAR_P (it
->c
))
18853 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18856 if (FRAME_WINDOW_P (f
))
18858 /* If the row is empty, add a space with the current face of IT,
18859 so that we know which face to draw. */
18860 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18862 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18863 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18864 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18866 /* Mode line and the header line don't have margins, and
18867 likewise the frame's tool-bar window, if there is any. */
18868 if (!(it
->glyph_row
->mode_line_p
18869 || (WINDOWP (f
->tool_bar_window
)
18870 && it
->w
== XWINDOW (f
->tool_bar_window
))))
18872 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18873 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
18875 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
18876 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
= face
->id
;
18877 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
18879 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
18880 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
18882 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
18883 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
= face
->id
;
18884 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
18887 #ifdef HAVE_WINDOW_SYSTEM
18888 if (it
->glyph_row
->reversed_p
)
18890 /* Prepend a stretch glyph to the row, such that the
18891 rightmost glyph will be drawn flushed all the way to the
18892 right margin of the window. The stretch glyph that will
18893 occupy the empty space, if any, to the left of the
18895 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18896 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18897 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18899 int row_width
, stretch_ascent
, stretch_width
;
18900 struct text_pos saved_pos
;
18901 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18903 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18904 row_width
+= g
->pixel_width
;
18905 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18906 if (stretch_width
> 0)
18909 (((it
->ascent
+ it
->descent
)
18910 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18911 saved_pos
= it
->position
;
18912 memset (&it
->position
, 0, sizeof it
->position
);
18913 saved_avoid_cursor
= it
->avoid_cursor_p
;
18914 it
->avoid_cursor_p
= 1;
18915 saved_face_id
= it
->face_id
;
18916 saved_box_start
= it
->start_of_box_run_p
;
18917 /* The last row's stretch glyph should get the default
18918 face, to avoid painting the rest of the window with
18919 the region face, if the region ends at ZV. */
18920 if (it
->glyph_row
->ends_at_zv_p
)
18921 it
->face_id
= default_face
->id
;
18923 it
->face_id
= face
->id
;
18924 it
->start_of_box_run_p
= 0;
18925 append_stretch_glyph (it
, make_number (0), stretch_width
,
18926 it
->ascent
+ it
->descent
, stretch_ascent
);
18927 it
->position
= saved_pos
;
18928 it
->avoid_cursor_p
= saved_avoid_cursor
;
18929 it
->face_id
= saved_face_id
;
18930 it
->start_of_box_run_p
= saved_box_start
;
18933 #endif /* HAVE_WINDOW_SYSTEM */
18937 /* Save some values that must not be changed. */
18938 int saved_x
= it
->current_x
;
18939 struct text_pos saved_pos
;
18940 Lisp_Object saved_object
;
18941 enum display_element_type saved_what
= it
->what
;
18942 int saved_face_id
= it
->face_id
;
18944 saved_object
= it
->object
;
18945 saved_pos
= it
->position
;
18947 it
->what
= IT_CHARACTER
;
18948 memset (&it
->position
, 0, sizeof it
->position
);
18949 it
->object
= make_number (0);
18950 it
->c
= it
->char_to_display
= ' ';
18952 /* The last row's blank glyphs should get the default face, to
18953 avoid painting the rest of the window with the region face,
18954 if the region ends at ZV. */
18955 if (it
->glyph_row
->ends_at_zv_p
)
18956 it
->face_id
= default_face
->id
;
18958 it
->face_id
= face
->id
;
18960 face
= FACE_FROM_ID (f
, it
->face_id
);
18961 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18962 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
18963 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
18964 && !it
->glyph_row
->mode_line_p
18965 && face
&& face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
18967 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
18968 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
18970 for (it
->current_x
= 0; g
< e
; g
++)
18971 it
->current_x
+= g
->pixel_width
;
18973 it
->area
= LEFT_MARGIN_AREA
;
18974 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
18975 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
18977 PRODUCE_GLYPHS (it
);
18978 /* term.c:produce_glyphs advances it->current_x only for
18980 it
->current_x
+= it
->pixel_width
;
18983 it
->current_x
= saved_x
;
18984 it
->area
= TEXT_AREA
;
18987 PRODUCE_GLYPHS (it
);
18989 while (it
->current_x
<= it
->last_visible_x
)
18990 PRODUCE_GLYPHS (it
);
18992 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
18993 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
18994 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
18995 && !it
->glyph_row
->mode_line_p
18996 && face
&& face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
18998 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
18999 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19001 for ( ; g
< e
; g
++)
19002 it
->current_x
+= g
->pixel_width
;
19004 it
->area
= RIGHT_MARGIN_AREA
;
19005 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19006 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19008 PRODUCE_GLYPHS (it
);
19009 it
->current_x
+= it
->pixel_width
;
19012 it
->area
= TEXT_AREA
;
19015 /* Don't count these blanks really. It would let us insert a left
19016 truncation glyph below and make us set the cursor on them, maybe. */
19017 it
->current_x
= saved_x
;
19018 it
->object
= saved_object
;
19019 it
->position
= saved_pos
;
19020 it
->what
= saved_what
;
19021 it
->face_id
= saved_face_id
;
19026 /* Value is non-zero if text starting at CHARPOS in current_buffer is
19027 trailing whitespace. */
19030 trailing_whitespace_p (ptrdiff_t charpos
)
19032 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19035 while (bytepos
< ZV_BYTE
19036 && (c
= FETCH_CHAR (bytepos
),
19037 c
== ' ' || c
== '\t'))
19040 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19042 if (bytepos
!= PT_BYTE
)
19049 /* Highlight trailing whitespace, if any, in ROW. */
19052 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19054 int used
= row
->used
[TEXT_AREA
];
19058 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19059 struct glyph
*glyph
= start
+ used
- 1;
19061 if (row
->reversed_p
)
19063 /* Right-to-left rows need to be processed in the opposite
19064 direction, so swap the edge pointers. */
19066 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19069 /* Skip over glyphs inserted to display the cursor at the
19070 end of a line, for extending the face of the last glyph
19071 to the end of the line on terminals, and for truncation
19072 and continuation glyphs. */
19073 if (!row
->reversed_p
)
19075 while (glyph
>= start
19076 && glyph
->type
== CHAR_GLYPH
19077 && INTEGERP (glyph
->object
))
19082 while (glyph
<= start
19083 && glyph
->type
== CHAR_GLYPH
19084 && INTEGERP (glyph
->object
))
19088 /* If last glyph is a space or stretch, and it's trailing
19089 whitespace, set the face of all trailing whitespace glyphs in
19090 IT->glyph_row to `trailing-whitespace'. */
19091 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19092 && BUFFERP (glyph
->object
)
19093 && (glyph
->type
== STRETCH_GLYPH
19094 || (glyph
->type
== CHAR_GLYPH
19095 && glyph
->u
.ch
== ' '))
19096 && trailing_whitespace_p (glyph
->charpos
))
19098 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19102 if (!row
->reversed_p
)
19104 while (glyph
>= start
19105 && BUFFERP (glyph
->object
)
19106 && (glyph
->type
== STRETCH_GLYPH
19107 || (glyph
->type
== CHAR_GLYPH
19108 && glyph
->u
.ch
== ' ')))
19109 (glyph
--)->face_id
= face_id
;
19113 while (glyph
<= start
19114 && BUFFERP (glyph
->object
)
19115 && (glyph
->type
== STRETCH_GLYPH
19116 || (glyph
->type
== CHAR_GLYPH
19117 && glyph
->u
.ch
== ' ')))
19118 (glyph
++)->face_id
= face_id
;
19125 /* Value is non-zero if glyph row ROW should be
19126 considered to hold the buffer position CHARPOS. */
19129 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19133 if (charpos
== CHARPOS (row
->end
.pos
)
19134 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19136 /* Suppose the row ends on a string.
19137 Unless the row is continued, that means it ends on a newline
19138 in the string. If it's anything other than a display string
19139 (e.g., a before-string from an overlay), we don't want the
19140 cursor there. (This heuristic seems to give the optimal
19141 behavior for the various types of multi-line strings.)
19142 One exception: if the string has `cursor' property on one of
19143 its characters, we _do_ want the cursor there. */
19144 if (CHARPOS (row
->end
.string_pos
) >= 0)
19146 if (row
->continued_p
)
19150 /* Check for `display' property. */
19151 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19152 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19153 struct glyph
*glyph
;
19156 for (glyph
= end
; glyph
>= beg
; --glyph
)
19157 if (STRINGP (glyph
->object
))
19160 = Fget_char_property (make_number (charpos
),
19164 && display_prop_string_p (prop
, glyph
->object
));
19165 /* If there's a `cursor' property on one of the
19166 string's characters, this row is a cursor row,
19167 even though this is not a display string. */
19170 Lisp_Object s
= glyph
->object
;
19172 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19174 ptrdiff_t gpos
= glyph
->charpos
;
19176 if (!NILP (Fget_char_property (make_number (gpos
),
19188 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19190 /* If the row ends in middle of a real character,
19191 and the line is continued, we want the cursor here.
19192 That's because CHARPOS (ROW->end.pos) would equal
19193 PT if PT is before the character. */
19194 if (!row
->ends_in_ellipsis_p
)
19195 result
= row
->continued_p
;
19197 /* If the row ends in an ellipsis, then
19198 CHARPOS (ROW->end.pos) will equal point after the
19199 invisible text. We want that position to be displayed
19200 after the ellipsis. */
19203 /* If the row ends at ZV, display the cursor at the end of that
19204 row instead of at the start of the row below. */
19205 else if (row
->ends_at_zv_p
)
19214 /* Value is non-zero if glyph row ROW should be
19215 used to hold the cursor. */
19218 cursor_row_p (struct glyph_row
*row
)
19220 return row_for_charpos_p (row
, PT
);
19225 /* Push the property PROP so that it will be rendered at the current
19226 position in IT. Return 1 if PROP was successfully pushed, 0
19227 otherwise. Called from handle_line_prefix to handle the
19228 `line-prefix' and `wrap-prefix' properties. */
19231 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19233 struct text_pos pos
=
19234 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19236 eassert (it
->method
== GET_FROM_BUFFER
19237 || it
->method
== GET_FROM_DISPLAY_VECTOR
19238 || it
->method
== GET_FROM_STRING
);
19240 /* We need to save the current buffer/string position, so it will be
19241 restored by pop_it, because iterate_out_of_display_property
19242 depends on that being set correctly, but some situations leave
19243 it->position not yet set when this function is called. */
19244 push_it (it
, &pos
);
19246 if (STRINGP (prop
))
19248 if (SCHARS (prop
) == 0)
19255 it
->string_from_prefix_prop_p
= 1;
19256 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19257 it
->current
.overlay_string_index
= -1;
19258 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19259 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19260 it
->method
= GET_FROM_STRING
;
19261 it
->stop_charpos
= 0;
19263 it
->base_level_stop
= 0;
19265 /* Force paragraph direction to be that of the parent
19267 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19268 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19270 it
->paragraph_embedding
= L2R
;
19272 /* Set up the bidi iterator for this display string. */
19275 it
->bidi_it
.string
.lstring
= it
->string
;
19276 it
->bidi_it
.string
.s
= NULL
;
19277 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19278 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19279 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19280 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19281 it
->bidi_it
.w
= it
->w
;
19282 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19285 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19287 it
->method
= GET_FROM_STRETCH
;
19290 #ifdef HAVE_WINDOW_SYSTEM
19291 else if (IMAGEP (prop
))
19293 it
->what
= IT_IMAGE
;
19294 it
->image_id
= lookup_image (it
->f
, prop
);
19295 it
->method
= GET_FROM_IMAGE
;
19297 #endif /* HAVE_WINDOW_SYSTEM */
19300 pop_it (it
); /* bogus display property, give up */
19307 /* Return the character-property PROP at the current position in IT. */
19310 get_it_property (struct it
*it
, Lisp_Object prop
)
19312 Lisp_Object position
, object
= it
->object
;
19314 if (STRINGP (object
))
19315 position
= make_number (IT_STRING_CHARPOS (*it
));
19316 else if (BUFFERP (object
))
19318 position
= make_number (IT_CHARPOS (*it
));
19319 object
= it
->window
;
19324 return Fget_char_property (position
, prop
, object
);
19327 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19330 handle_line_prefix (struct it
*it
)
19332 Lisp_Object prefix
;
19334 if (it
->continuation_lines_width
> 0)
19336 prefix
= get_it_property (it
, Qwrap_prefix
);
19338 prefix
= Vwrap_prefix
;
19342 prefix
= get_it_property (it
, Qline_prefix
);
19344 prefix
= Vline_prefix
;
19346 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19348 /* If the prefix is wider than the window, and we try to wrap
19349 it, it would acquire its own wrap prefix, and so on till the
19350 iterator stack overflows. So, don't wrap the prefix. */
19351 it
->line_wrap
= TRUNCATE
;
19352 it
->avoid_cursor_p
= 1;
19358 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19359 only for R2L lines from display_line and display_string, when they
19360 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19361 the line/string needs to be continued on the next glyph row. */
19363 unproduce_glyphs (struct it
*it
, int n
)
19365 struct glyph
*glyph
, *end
;
19367 eassert (it
->glyph_row
);
19368 eassert (it
->glyph_row
->reversed_p
);
19369 eassert (it
->area
== TEXT_AREA
);
19370 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19372 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19373 n
= it
->glyph_row
->used
[TEXT_AREA
];
19374 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19375 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19376 for ( ; glyph
< end
; glyph
++)
19377 glyph
[-n
] = *glyph
;
19380 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19381 and ROW->maxpos. */
19383 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19384 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19385 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19387 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19388 lines' rows is implemented for bidi-reordered rows. */
19390 /* ROW->minpos is the value of min_pos, the minimal buffer position
19391 we have in ROW, or ROW->start.pos if that is smaller. */
19392 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19393 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19395 /* We didn't find buffer positions smaller than ROW->start, or
19396 didn't find _any_ valid buffer positions in any of the glyphs,
19397 so we must trust the iterator's computed positions. */
19398 row
->minpos
= row
->start
.pos
;
19401 max_pos
= CHARPOS (it
->current
.pos
);
19402 max_bpos
= BYTEPOS (it
->current
.pos
);
19405 /* Here are the various use-cases for ending the row, and the
19406 corresponding values for ROW->maxpos:
19408 Line ends in a newline from buffer eol_pos + 1
19409 Line is continued from buffer max_pos + 1
19410 Line is truncated on right it->current.pos
19411 Line ends in a newline from string max_pos + 1(*)
19412 (*) + 1 only when line ends in a forward scan
19413 Line is continued from string max_pos
19414 Line is continued from display vector max_pos
19415 Line is entirely from a string min_pos == max_pos
19416 Line is entirely from a display vector min_pos == max_pos
19417 Line that ends at ZV ZV
19419 If you discover other use-cases, please add them here as
19421 if (row
->ends_at_zv_p
)
19422 row
->maxpos
= it
->current
.pos
;
19423 else if (row
->used
[TEXT_AREA
])
19425 int seen_this_string
= 0;
19426 struct glyph_row
*r1
= row
- 1;
19428 /* Did we see the same display string on the previous row? */
19429 if (STRINGP (it
->object
)
19430 /* this is not the first row */
19431 && row
> it
->w
->desired_matrix
->rows
19432 /* previous row is not the header line */
19433 && !r1
->mode_line_p
19434 /* previous row also ends in a newline from a string */
19435 && r1
->ends_in_newline_from_string_p
)
19437 struct glyph
*start
, *end
;
19439 /* Search for the last glyph of the previous row that came
19440 from buffer or string. Depending on whether the row is
19441 L2R or R2L, we need to process it front to back or the
19442 other way round. */
19443 if (!r1
->reversed_p
)
19445 start
= r1
->glyphs
[TEXT_AREA
];
19446 end
= start
+ r1
->used
[TEXT_AREA
];
19447 /* Glyphs inserted by redisplay have an integer (zero)
19448 as their object. */
19450 && INTEGERP ((end
- 1)->object
)
19451 && (end
- 1)->charpos
<= 0)
19455 if (EQ ((end
- 1)->object
, it
->object
))
19456 seen_this_string
= 1;
19459 /* If all the glyphs of the previous row were inserted
19460 by redisplay, it means the previous row was
19461 produced from a single newline, which is only
19462 possible if that newline came from the same string
19463 as the one which produced this ROW. */
19464 seen_this_string
= 1;
19468 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19469 start
= end
+ r1
->used
[TEXT_AREA
];
19471 && INTEGERP ((end
+ 1)->object
)
19472 && (end
+ 1)->charpos
<= 0)
19476 if (EQ ((end
+ 1)->object
, it
->object
))
19477 seen_this_string
= 1;
19480 seen_this_string
= 1;
19483 /* Take note of each display string that covers a newline only
19484 once, the first time we see it. This is for when a display
19485 string includes more than one newline in it. */
19486 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19488 /* If we were scanning the buffer forward when we displayed
19489 the string, we want to account for at least one buffer
19490 position that belongs to this row (position covered by
19491 the display string), so that cursor positioning will
19492 consider this row as a candidate when point is at the end
19493 of the visual line represented by this row. This is not
19494 required when scanning back, because max_pos will already
19495 have a much larger value. */
19496 if (CHARPOS (row
->end
.pos
) > max_pos
)
19497 INC_BOTH (max_pos
, max_bpos
);
19498 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19500 else if (CHARPOS (it
->eol_pos
) > 0)
19501 SET_TEXT_POS (row
->maxpos
,
19502 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19503 else if (row
->continued_p
)
19505 /* If max_pos is different from IT's current position, it
19506 means IT->method does not belong to the display element
19507 at max_pos. However, it also means that the display
19508 element at max_pos was displayed in its entirety on this
19509 line, which is equivalent to saying that the next line
19510 starts at the next buffer position. */
19511 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19512 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19515 INC_BOTH (max_pos
, max_bpos
);
19516 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19519 else if (row
->truncated_on_right_p
)
19520 /* display_line already called reseat_at_next_visible_line_start,
19521 which puts the iterator at the beginning of the next line, in
19522 the logical order. */
19523 row
->maxpos
= it
->current
.pos
;
19524 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19525 /* A line that is entirely from a string/image/stretch... */
19526 row
->maxpos
= row
->minpos
;
19531 row
->maxpos
= it
->current
.pos
;
19534 /* Construct the glyph row IT->glyph_row in the desired matrix of
19535 IT->w from text at the current position of IT. See dispextern.h
19536 for an overview of struct it. Value is non-zero if
19537 IT->glyph_row displays text, as opposed to a line displaying ZV
19541 display_line (struct it
*it
)
19543 struct glyph_row
*row
= it
->glyph_row
;
19544 Lisp_Object overlay_arrow_string
;
19546 void *wrap_data
= NULL
;
19547 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19548 int wrap_row_used
= -1;
19549 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19550 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19551 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19552 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19553 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19555 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19556 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19558 /* We always start displaying at hpos zero even if hscrolled. */
19559 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19561 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19562 >= it
->w
->desired_matrix
->nrows
)
19564 it
->w
->nrows_scale_factor
++;
19565 it
->f
->fonts_changed
= 1;
19569 /* Clear the result glyph row and enable it. */
19570 prepare_desired_row (row
);
19572 row
->y
= it
->current_y
;
19573 row
->start
= it
->start
;
19574 row
->continuation_lines_width
= it
->continuation_lines_width
;
19575 row
->displays_text_p
= 1;
19576 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19577 it
->starts_in_middle_of_char_p
= 0;
19579 /* Arrange the overlays nicely for our purposes. Usually, we call
19580 display_line on only one line at a time, in which case this
19581 can't really hurt too much, or we call it on lines which appear
19582 one after another in the buffer, in which case all calls to
19583 recenter_overlay_lists but the first will be pretty cheap. */
19584 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19586 /* Move over display elements that are not visible because we are
19587 hscrolled. This may stop at an x-position < IT->first_visible_x
19588 if the first glyph is partially visible or if we hit a line end. */
19589 if (it
->current_x
< it
->first_visible_x
)
19591 enum move_it_result move_result
;
19593 this_line_min_pos
= row
->start
.pos
;
19594 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19595 MOVE_TO_POS
| MOVE_TO_X
);
19596 /* If we are under a large hscroll, move_it_in_display_line_to
19597 could hit the end of the line without reaching
19598 it->first_visible_x. Pretend that we did reach it. This is
19599 especially important on a TTY, where we will call
19600 extend_face_to_end_of_line, which needs to know how many
19601 blank glyphs to produce. */
19602 if (it
->current_x
< it
->first_visible_x
19603 && (move_result
== MOVE_NEWLINE_OR_CR
19604 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19605 it
->current_x
= it
->first_visible_x
;
19607 /* Record the smallest positions seen while we moved over
19608 display elements that are not visible. This is needed by
19609 redisplay_internal for optimizing the case where the cursor
19610 stays inside the same line. The rest of this function only
19611 considers positions that are actually displayed, so
19612 RECORD_MAX_MIN_POS will not otherwise record positions that
19613 are hscrolled to the left of the left edge of the window. */
19614 min_pos
= CHARPOS (this_line_min_pos
);
19615 min_bpos
= BYTEPOS (this_line_min_pos
);
19619 /* We only do this when not calling `move_it_in_display_line_to'
19620 above, because move_it_in_display_line_to calls
19621 handle_line_prefix itself. */
19622 handle_line_prefix (it
);
19625 /* Get the initial row height. This is either the height of the
19626 text hscrolled, if there is any, or zero. */
19627 row
->ascent
= it
->max_ascent
;
19628 row
->height
= it
->max_ascent
+ it
->max_descent
;
19629 row
->phys_ascent
= it
->max_phys_ascent
;
19630 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19631 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19633 /* Utility macro to record max and min buffer positions seen until now. */
19634 #define RECORD_MAX_MIN_POS(IT) \
19637 int composition_p = !STRINGP ((IT)->string) \
19638 && ((IT)->what == IT_COMPOSITION); \
19639 ptrdiff_t current_pos = \
19640 composition_p ? (IT)->cmp_it.charpos \
19641 : IT_CHARPOS (*(IT)); \
19642 ptrdiff_t current_bpos = \
19643 composition_p ? CHAR_TO_BYTE (current_pos) \
19644 : IT_BYTEPOS (*(IT)); \
19645 if (current_pos < min_pos) \
19647 min_pos = current_pos; \
19648 min_bpos = current_bpos; \
19650 if (IT_CHARPOS (*it) > max_pos) \
19652 max_pos = IT_CHARPOS (*it); \
19653 max_bpos = IT_BYTEPOS (*it); \
19658 /* Loop generating characters. The loop is left with IT on the next
19659 character to display. */
19662 int n_glyphs_before
, hpos_before
, x_before
;
19664 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19666 /* Retrieve the next thing to display. Value is zero if end of
19668 if (!get_next_display_element (it
))
19670 /* Maybe add a space at the end of this line that is used to
19671 display the cursor there under X. Set the charpos of the
19672 first glyph of blank lines not corresponding to any text
19674 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19675 row
->exact_window_width_line_p
= 1;
19676 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19677 || row
->used
[TEXT_AREA
] == 0)
19679 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19680 row
->displays_text_p
= 0;
19682 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19683 && (!MINI_WINDOW_P (it
->w
)
19684 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19685 row
->indicate_empty_line_p
= 1;
19688 it
->continuation_lines_width
= 0;
19689 row
->ends_at_zv_p
= 1;
19690 /* A row that displays right-to-left text must always have
19691 its last face extended all the way to the end of line,
19692 even if this row ends in ZV, because we still write to
19693 the screen left to right. We also need to extend the
19694 last face if the default face is remapped to some
19695 different face, otherwise the functions that clear
19696 portions of the screen will clear with the default face's
19697 background color. */
19698 if (row
->reversed_p
19699 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19700 extend_face_to_end_of_line (it
);
19704 /* Now, get the metrics of what we want to display. This also
19705 generates glyphs in `row' (which is IT->glyph_row). */
19706 n_glyphs_before
= row
->used
[TEXT_AREA
];
19709 /* Remember the line height so far in case the next element doesn't
19710 fit on the line. */
19711 if (it
->line_wrap
!= TRUNCATE
)
19713 ascent
= it
->max_ascent
;
19714 descent
= it
->max_descent
;
19715 phys_ascent
= it
->max_phys_ascent
;
19716 phys_descent
= it
->max_phys_descent
;
19718 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19720 if (IT_DISPLAYING_WHITESPACE (it
))
19724 SAVE_IT (wrap_it
, *it
, wrap_data
);
19726 wrap_row_used
= row
->used
[TEXT_AREA
];
19727 wrap_row_ascent
= row
->ascent
;
19728 wrap_row_height
= row
->height
;
19729 wrap_row_phys_ascent
= row
->phys_ascent
;
19730 wrap_row_phys_height
= row
->phys_height
;
19731 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19732 wrap_row_min_pos
= min_pos
;
19733 wrap_row_min_bpos
= min_bpos
;
19734 wrap_row_max_pos
= max_pos
;
19735 wrap_row_max_bpos
= max_bpos
;
19741 PRODUCE_GLYPHS (it
);
19743 /* If this display element was in marginal areas, continue with
19745 if (it
->area
!= TEXT_AREA
)
19747 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19748 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19749 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19750 row
->phys_height
= max (row
->phys_height
,
19751 it
->max_phys_ascent
+ it
->max_phys_descent
);
19752 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19753 it
->max_extra_line_spacing
);
19754 set_iterator_to_next (it
, 1);
19758 /* Does the display element fit on the line? If we truncate
19759 lines, we should draw past the right edge of the window. If
19760 we don't truncate, we want to stop so that we can display the
19761 continuation glyph before the right margin. If lines are
19762 continued, there are two possible strategies for characters
19763 resulting in more than 1 glyph (e.g. tabs): Display as many
19764 glyphs as possible in this line and leave the rest for the
19765 continuation line, or display the whole element in the next
19766 line. Original redisplay did the former, so we do it also. */
19767 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19768 hpos_before
= it
->hpos
;
19771 if (/* Not a newline. */
19773 /* Glyphs produced fit entirely in the line. */
19774 && it
->current_x
< it
->last_visible_x
)
19776 it
->hpos
+= nglyphs
;
19777 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19778 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19779 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19780 row
->phys_height
= max (row
->phys_height
,
19781 it
->max_phys_ascent
+ it
->max_phys_descent
);
19782 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19783 it
->max_extra_line_spacing
);
19784 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19785 row
->x
= x
- it
->first_visible_x
;
19786 /* Record the maximum and minimum buffer positions seen so
19787 far in glyphs that will be displayed by this row. */
19789 RECORD_MAX_MIN_POS (it
);
19794 struct glyph
*glyph
;
19796 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19798 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19799 new_x
= x
+ glyph
->pixel_width
;
19801 if (/* Lines are continued. */
19802 it
->line_wrap
!= TRUNCATE
19803 && (/* Glyph doesn't fit on the line. */
19804 new_x
> it
->last_visible_x
19805 /* Or it fits exactly on a window system frame. */
19806 || (new_x
== it
->last_visible_x
19807 && FRAME_WINDOW_P (it
->f
)
19808 && (row
->reversed_p
19809 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19810 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19812 /* End of a continued line. */
19815 || (new_x
== it
->last_visible_x
19816 && FRAME_WINDOW_P (it
->f
)
19817 && (row
->reversed_p
19818 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19819 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19821 /* Current glyph is the only one on the line or
19822 fits exactly on the line. We must continue
19823 the line because we can't draw the cursor
19824 after the glyph. */
19825 row
->continued_p
= 1;
19826 it
->current_x
= new_x
;
19827 it
->continuation_lines_width
+= new_x
;
19829 if (i
== nglyphs
- 1)
19831 /* If line-wrap is on, check if a previous
19832 wrap point was found. */
19833 if (wrap_row_used
> 0
19834 /* Even if there is a previous wrap
19835 point, continue the line here as
19836 usual, if (i) the previous character
19837 was a space or tab AND (ii) the
19838 current character is not. */
19840 || IT_DISPLAYING_WHITESPACE (it
)))
19843 /* Record the maximum and minimum buffer
19844 positions seen so far in glyphs that will be
19845 displayed by this row. */
19847 RECORD_MAX_MIN_POS (it
);
19848 set_iterator_to_next (it
, 1);
19849 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19851 if (!get_next_display_element (it
))
19853 row
->exact_window_width_line_p
= 1;
19854 it
->continuation_lines_width
= 0;
19855 row
->continued_p
= 0;
19856 row
->ends_at_zv_p
= 1;
19858 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19860 row
->continued_p
= 0;
19861 row
->exact_window_width_line_p
= 1;
19865 else if (it
->bidi_p
)
19866 RECORD_MAX_MIN_POS (it
);
19867 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19868 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19869 extend_face_to_end_of_line (it
);
19871 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19872 && !FRAME_WINDOW_P (it
->f
))
19874 /* A padding glyph that doesn't fit on this line.
19875 This means the whole character doesn't fit
19877 if (row
->reversed_p
)
19878 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19879 - n_glyphs_before
);
19880 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19882 /* Fill the rest of the row with continuation
19883 glyphs like in 20.x. */
19884 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19885 < row
->glyphs
[1 + TEXT_AREA
])
19886 produce_special_glyphs (it
, IT_CONTINUATION
);
19888 row
->continued_p
= 1;
19889 it
->current_x
= x_before
;
19890 it
->continuation_lines_width
+= x_before
;
19892 /* Restore the height to what it was before the
19893 element not fitting on the line. */
19894 it
->max_ascent
= ascent
;
19895 it
->max_descent
= descent
;
19896 it
->max_phys_ascent
= phys_ascent
;
19897 it
->max_phys_descent
= phys_descent
;
19898 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19899 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19900 extend_face_to_end_of_line (it
);
19902 else if (wrap_row_used
> 0)
19905 if (row
->reversed_p
)
19906 unproduce_glyphs (it
,
19907 row
->used
[TEXT_AREA
] - wrap_row_used
);
19908 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19909 it
->continuation_lines_width
+= wrap_x
;
19910 row
->used
[TEXT_AREA
] = wrap_row_used
;
19911 row
->ascent
= wrap_row_ascent
;
19912 row
->height
= wrap_row_height
;
19913 row
->phys_ascent
= wrap_row_phys_ascent
;
19914 row
->phys_height
= wrap_row_phys_height
;
19915 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19916 min_pos
= wrap_row_min_pos
;
19917 min_bpos
= wrap_row_min_bpos
;
19918 max_pos
= wrap_row_max_pos
;
19919 max_bpos
= wrap_row_max_bpos
;
19920 row
->continued_p
= 1;
19921 row
->ends_at_zv_p
= 0;
19922 row
->exact_window_width_line_p
= 0;
19923 it
->continuation_lines_width
+= x
;
19925 /* Make sure that a non-default face is extended
19926 up to the right margin of the window. */
19927 extend_face_to_end_of_line (it
);
19929 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19931 /* A TAB that extends past the right edge of the
19932 window. This produces a single glyph on
19933 window system frames. We leave the glyph in
19934 this row and let it fill the row, but don't
19935 consume the TAB. */
19936 if ((row
->reversed_p
19937 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19938 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19939 produce_special_glyphs (it
, IT_CONTINUATION
);
19940 it
->continuation_lines_width
+= it
->last_visible_x
;
19941 row
->ends_in_middle_of_char_p
= 1;
19942 row
->continued_p
= 1;
19943 glyph
->pixel_width
= it
->last_visible_x
- x
;
19944 it
->starts_in_middle_of_char_p
= 1;
19945 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19946 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19947 extend_face_to_end_of_line (it
);
19951 /* Something other than a TAB that draws past
19952 the right edge of the window. Restore
19953 positions to values before the element. */
19954 if (row
->reversed_p
)
19955 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19956 - (n_glyphs_before
+ i
));
19957 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19959 /* Display continuation glyphs. */
19960 it
->current_x
= x_before
;
19961 it
->continuation_lines_width
+= x
;
19962 if (!FRAME_WINDOW_P (it
->f
)
19963 || (row
->reversed_p
19964 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19965 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19966 produce_special_glyphs (it
, IT_CONTINUATION
);
19967 row
->continued_p
= 1;
19969 extend_face_to_end_of_line (it
);
19971 if (nglyphs
> 1 && i
> 0)
19973 row
->ends_in_middle_of_char_p
= 1;
19974 it
->starts_in_middle_of_char_p
= 1;
19977 /* Restore the height to what it was before the
19978 element not fitting on the line. */
19979 it
->max_ascent
= ascent
;
19980 it
->max_descent
= descent
;
19981 it
->max_phys_ascent
= phys_ascent
;
19982 it
->max_phys_descent
= phys_descent
;
19987 else if (new_x
> it
->first_visible_x
)
19989 /* Increment number of glyphs actually displayed. */
19992 /* Record the maximum and minimum buffer positions
19993 seen so far in glyphs that will be displayed by
19996 RECORD_MAX_MIN_POS (it
);
19998 if (x
< it
->first_visible_x
)
19999 /* Glyph is partially visible, i.e. row starts at
20000 negative X position. */
20001 row
->x
= x
- it
->first_visible_x
;
20005 /* Glyph is completely off the left margin of the
20006 window. This should not happen because of the
20007 move_it_in_display_line at the start of this
20008 function, unless the text display area of the
20009 window is empty. */
20010 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20013 /* Even if this display element produced no glyphs at all,
20014 we want to record its position. */
20015 if (it
->bidi_p
&& nglyphs
== 0)
20016 RECORD_MAX_MIN_POS (it
);
20018 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20019 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20020 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20021 row
->phys_height
= max (row
->phys_height
,
20022 it
->max_phys_ascent
+ it
->max_phys_descent
);
20023 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20024 it
->max_extra_line_spacing
);
20026 /* End of this display line if row is continued. */
20027 if (row
->continued_p
|| row
->ends_at_zv_p
)
20032 /* Is this a line end? If yes, we're also done, after making
20033 sure that a non-default face is extended up to the right
20034 margin of the window. */
20035 if (ITERATOR_AT_END_OF_LINE_P (it
))
20037 int used_before
= row
->used
[TEXT_AREA
];
20039 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20041 /* Add a space at the end of the line that is used to
20042 display the cursor there. */
20043 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20044 append_space_for_newline (it
, 0);
20046 /* Extend the face to the end of the line. */
20047 extend_face_to_end_of_line (it
);
20049 /* Make sure we have the position. */
20050 if (used_before
== 0)
20051 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20053 /* Record the position of the newline, for use in
20055 it
->eol_pos
= it
->current
.pos
;
20057 /* Consume the line end. This skips over invisible lines. */
20058 set_iterator_to_next (it
, 1);
20059 it
->continuation_lines_width
= 0;
20063 /* Proceed with next display element. Note that this skips
20064 over lines invisible because of selective display. */
20065 set_iterator_to_next (it
, 1);
20067 /* If we truncate lines, we are done when the last displayed
20068 glyphs reach past the right margin of the window. */
20069 if (it
->line_wrap
== TRUNCATE
20070 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20071 ? (it
->current_x
>= it
->last_visible_x
)
20072 : (it
->current_x
> it
->last_visible_x
)))
20074 /* Maybe add truncation glyphs. */
20075 if (!FRAME_WINDOW_P (it
->f
)
20076 || (row
->reversed_p
20077 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20078 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20082 if (!row
->reversed_p
)
20084 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20085 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20090 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20091 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20093 /* Remove any padding glyphs at the front of ROW, to
20094 make room for the truncation glyphs we will be
20095 adding below. The loop below always inserts at
20096 least one truncation glyph, so also remove the
20097 last glyph added to ROW. */
20098 unproduce_glyphs (it
, i
+ 1);
20099 /* Adjust i for the loop below. */
20100 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20103 it
->current_x
= x_before
;
20104 if (!FRAME_WINDOW_P (it
->f
))
20106 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20108 row
->used
[TEXT_AREA
] = i
;
20109 produce_special_glyphs (it
, IT_TRUNCATION
);
20114 row
->used
[TEXT_AREA
] = i
;
20115 produce_special_glyphs (it
, IT_TRUNCATION
);
20118 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20120 /* Don't truncate if we can overflow newline into fringe. */
20121 if (!get_next_display_element (it
))
20123 it
->continuation_lines_width
= 0;
20124 row
->ends_at_zv_p
= 1;
20125 row
->exact_window_width_line_p
= 1;
20128 if (ITERATOR_AT_END_OF_LINE_P (it
))
20130 row
->exact_window_width_line_p
= 1;
20131 goto at_end_of_line
;
20133 it
->current_x
= x_before
;
20136 row
->truncated_on_right_p
= 1;
20137 it
->continuation_lines_width
= 0;
20138 reseat_at_next_visible_line_start (it
, 0);
20139 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20140 it
->hpos
= hpos_before
;
20146 bidi_unshelve_cache (wrap_data
, 1);
20148 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20149 at the left window margin. */
20150 if (it
->first_visible_x
20151 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20153 if (!FRAME_WINDOW_P (it
->f
)
20154 || (row
->reversed_p
20155 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20156 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20157 insert_left_trunc_glyphs (it
);
20158 row
->truncated_on_left_p
= 1;
20161 /* Remember the position at which this line ends.
20163 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20164 cannot be before the call to find_row_edges below, since that is
20165 where these positions are determined. */
20166 row
->end
= it
->current
;
20169 row
->minpos
= row
->start
.pos
;
20170 row
->maxpos
= row
->end
.pos
;
20174 /* ROW->minpos and ROW->maxpos must be the smallest and
20175 `1 + the largest' buffer positions in ROW. But if ROW was
20176 bidi-reordered, these two positions can be anywhere in the
20177 row, so we must determine them now. */
20178 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20181 /* If the start of this line is the overlay arrow-position, then
20182 mark this glyph row as the one containing the overlay arrow.
20183 This is clearly a mess with variable size fonts. It would be
20184 better to let it be displayed like cursors under X. */
20185 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20186 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20187 !NILP (overlay_arrow_string
)))
20189 /* Overlay arrow in window redisplay is a fringe bitmap. */
20190 if (STRINGP (overlay_arrow_string
))
20192 struct glyph_row
*arrow_row
20193 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20194 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20195 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20196 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20197 struct glyph
*p2
, *end
;
20199 /* Copy the arrow glyphs. */
20200 while (glyph
< arrow_end
)
20203 /* Throw away padding glyphs. */
20205 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20206 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20212 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20217 eassert (INTEGERP (overlay_arrow_string
));
20218 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20220 overlay_arrow_seen
= 1;
20223 /* Highlight trailing whitespace. */
20224 if (!NILP (Vshow_trailing_whitespace
))
20225 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20227 /* Compute pixel dimensions of this line. */
20228 compute_line_metrics (it
);
20230 /* Implementation note: No changes in the glyphs of ROW or in their
20231 faces can be done past this point, because compute_line_metrics
20232 computes ROW's hash value and stores it within the glyph_row
20235 /* Record whether this row ends inside an ellipsis. */
20236 row
->ends_in_ellipsis_p
20237 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20238 && it
->ellipsis_p
);
20240 /* Save fringe bitmaps in this row. */
20241 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20242 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20243 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20244 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20246 it
->left_user_fringe_bitmap
= 0;
20247 it
->left_user_fringe_face_id
= 0;
20248 it
->right_user_fringe_bitmap
= 0;
20249 it
->right_user_fringe_face_id
= 0;
20251 /* Maybe set the cursor. */
20252 cvpos
= it
->w
->cursor
.vpos
;
20254 /* In bidi-reordered rows, keep checking for proper cursor
20255 position even if one has been found already, because buffer
20256 positions in such rows change non-linearly with ROW->VPOS,
20257 when a line is continued. One exception: when we are at ZV,
20258 display cursor on the first suitable glyph row, since all
20259 the empty rows after that also have their position set to ZV. */
20260 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20261 lines' rows is implemented for bidi-reordered rows. */
20263 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20264 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20265 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20266 && cursor_row_p (row
))
20267 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20269 /* Prepare for the next line. This line starts horizontally at (X
20270 HPOS) = (0 0). Vertical positions are incremented. As a
20271 convenience for the caller, IT->glyph_row is set to the next
20273 it
->current_x
= it
->hpos
= 0;
20274 it
->current_y
+= row
->height
;
20275 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20278 /* The next row should by default use the same value of the
20279 reversed_p flag as this one. set_iterator_to_next decides when
20280 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20281 the flag accordingly. */
20282 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20283 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20284 it
->start
= row
->end
;
20285 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20287 #undef RECORD_MAX_MIN_POS
20290 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20291 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20292 doc
: /* Return paragraph direction at point in BUFFER.
20293 Value is either `left-to-right' or `right-to-left'.
20294 If BUFFER is omitted or nil, it defaults to the current buffer.
20296 Paragraph direction determines how the text in the paragraph is displayed.
20297 In left-to-right paragraphs, text begins at the left margin of the window
20298 and the reading direction is generally left to right. In right-to-left
20299 paragraphs, text begins at the right margin and is read from right to left.
20301 See also `bidi-paragraph-direction'. */)
20302 (Lisp_Object buffer
)
20304 struct buffer
*buf
= current_buffer
;
20305 struct buffer
*old
= buf
;
20307 if (! NILP (buffer
))
20309 CHECK_BUFFER (buffer
);
20310 buf
= XBUFFER (buffer
);
20313 if (NILP (BVAR (buf
, bidi_display_reordering
))
20314 || NILP (BVAR (buf
, enable_multibyte_characters
))
20315 /* When we are loading loadup.el, the character property tables
20316 needed for bidi iteration are not yet available. */
20317 || !NILP (Vpurify_flag
))
20318 return Qleft_to_right
;
20319 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20320 return BVAR (buf
, bidi_paragraph_direction
);
20323 /* Determine the direction from buffer text. We could try to
20324 use current_matrix if it is up to date, but this seems fast
20325 enough as it is. */
20326 struct bidi_it itb
;
20327 ptrdiff_t pos
= BUF_PT (buf
);
20328 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20330 void *itb_data
= bidi_shelve_cache ();
20332 set_buffer_temp (buf
);
20333 /* bidi_paragraph_init finds the base direction of the paragraph
20334 by searching forward from paragraph start. We need the base
20335 direction of the current or _previous_ paragraph, so we need
20336 to make sure we are within that paragraph. To that end, find
20337 the previous non-empty line. */
20338 if (pos
>= ZV
&& pos
> BEGV
)
20339 DEC_BOTH (pos
, bytepos
);
20340 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20341 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20343 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20344 || c
== ' ' || c
== '\t' || c
== '\f')
20346 if (bytepos
<= BEGV_BYTE
)
20351 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20354 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20355 itb
.paragraph_dir
= NEUTRAL_DIR
;
20356 itb
.string
.s
= NULL
;
20357 itb
.string
.lstring
= Qnil
;
20358 itb
.string
.bufpos
= 0;
20359 itb
.string
.unibyte
= 0;
20360 /* We have no window to use here for ignoring window-specific
20361 overlays. Using NULL for window pointer will cause
20362 compute_display_string_pos to use the current buffer. */
20364 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20365 bidi_unshelve_cache (itb_data
, 0);
20366 set_buffer_temp (old
);
20367 switch (itb
.paragraph_dir
)
20370 return Qleft_to_right
;
20373 return Qright_to_left
;
20381 DEFUN ("move-point-visually", Fmove_point_visually
,
20382 Smove_point_visually
, 1, 1, 0,
20383 doc
: /* Move point in the visual order in the specified DIRECTION.
20384 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20387 Value is the new character position of point. */)
20388 (Lisp_Object direction
)
20390 struct window
*w
= XWINDOW (selected_window
);
20391 struct buffer
*b
= XBUFFER (w
->contents
);
20392 struct glyph_row
*row
;
20394 Lisp_Object paragraph_dir
;
20396 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20397 (!(ROW)->continued_p \
20398 && INTEGERP ((GLYPH)->object) \
20399 && (GLYPH)->type == CHAR_GLYPH \
20400 && (GLYPH)->u.ch == ' ' \
20401 && (GLYPH)->charpos >= 0 \
20402 && !(GLYPH)->avoid_cursor_p)
20404 CHECK_NUMBER (direction
);
20405 dir
= XINT (direction
);
20411 /* If current matrix is up-to-date, we can use the information
20412 recorded in the glyphs, at least as long as the goal is on the
20414 if (w
->window_end_valid
20415 && !windows_or_buffers_changed
20417 && !b
->clip_changed
20418 && !b
->prevent_redisplay_optimizations_p
20419 && !window_outdated (w
)
20420 && w
->cursor
.vpos
>= 0
20421 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20422 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20424 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20425 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20426 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20428 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20430 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20432 SET_PT (g
->charpos
);
20433 w
->cursor
.vpos
= -1;
20434 return make_number (PT
);
20436 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20440 if (BUFFERP (gpt
->object
))
20443 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20444 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20446 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20448 else if (BUFFERP (g
->object
))
20449 new_pos
= g
->charpos
;
20453 w
->cursor
.vpos
= -1;
20454 return make_number (PT
);
20456 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20458 /* Glyphs inserted at the end of a non-empty line for
20459 positioning the cursor have zero charpos, so we must
20460 deduce the value of point by other means. */
20461 if (g
->charpos
> 0)
20462 SET_PT (g
->charpos
);
20463 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20465 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20466 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20469 w
->cursor
.vpos
= -1;
20470 return make_number (PT
);
20473 if (g
== e
|| INTEGERP (g
->object
))
20475 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20476 goto simulate_display
;
20477 if (!row
->reversed_p
)
20481 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20482 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20483 goto simulate_display
;
20487 if (row
->reversed_p
&& !row
->continued_p
)
20489 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20490 w
->cursor
.vpos
= -1;
20491 return make_number (PT
);
20493 g
= row
->glyphs
[TEXT_AREA
];
20494 e
= g
+ row
->used
[TEXT_AREA
];
20495 for ( ; g
< e
; g
++)
20497 if (BUFFERP (g
->object
)
20498 /* Empty lines have only one glyph, which stands
20499 for the newline, and whose charpos is the
20500 buffer position of the newline. */
20501 || ROW_GLYPH_NEWLINE_P (row
, g
)
20502 /* When the buffer ends in a newline, the line at
20503 EOB also has one glyph, but its charpos is -1. */
20504 || (row
->ends_at_zv_p
20505 && !row
->reversed_p
20506 && INTEGERP (g
->object
)
20507 && g
->type
== CHAR_GLYPH
20508 && g
->u
.ch
== ' '))
20510 if (g
->charpos
> 0)
20511 SET_PT (g
->charpos
);
20512 else if (!row
->reversed_p
20513 && row
->ends_at_zv_p
20518 w
->cursor
.vpos
= -1;
20519 return make_number (PT
);
20525 if (!row
->reversed_p
&& !row
->continued_p
)
20527 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20528 w
->cursor
.vpos
= -1;
20529 return make_number (PT
);
20531 e
= row
->glyphs
[TEXT_AREA
];
20532 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20533 for ( ; g
>= e
; g
--)
20535 if (BUFFERP (g
->object
)
20536 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20538 /* Empty R2L lines on GUI frames have the buffer
20539 position of the newline stored in the stretch
20541 || g
->type
== STRETCH_GLYPH
20542 || (row
->ends_at_zv_p
20544 && INTEGERP (g
->object
)
20545 && g
->type
== CHAR_GLYPH
20546 && g
->u
.ch
== ' '))
20548 if (g
->charpos
> 0)
20549 SET_PT (g
->charpos
);
20550 else if (row
->reversed_p
20551 && row
->ends_at_zv_p
20556 w
->cursor
.vpos
= -1;
20557 return make_number (PT
);
20566 /* If we wind up here, we failed to move by using the glyphs, so we
20567 need to simulate display instead. */
20570 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20572 paragraph_dir
= Qleft_to_right
;
20573 if (EQ (paragraph_dir
, Qright_to_left
))
20575 if (PT
<= BEGV
&& dir
< 0)
20576 xsignal0 (Qbeginning_of_buffer
);
20577 else if (PT
>= ZV
&& dir
> 0)
20578 xsignal0 (Qend_of_buffer
);
20581 struct text_pos pt
;
20583 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20585 bool overshoot_expected
= false;
20586 bool target_is_eol_p
= false;
20588 /* Setup the arena. */
20589 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20590 start_display (&it
, w
, pt
);
20592 if ((it
.cmp_it
.id
< 0
20593 && it
.method
== GET_FROM_STRING
20594 && it
.area
== TEXT_AREA
20595 && it
.string_from_display_prop_p
20596 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20597 || it
.method
== GET_FROM_DISPLAY_VECTOR
)
20598 overshoot_expected
= true;
20600 /* Find the X coordinate of point. We start from the beginning
20601 of this or previous line to make sure we are before point in
20602 the logical order (since the move_it_* functions can only
20604 reseat_at_previous_visible_line_start (&it
);
20605 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20606 if (IT_CHARPOS (it
) != PT
)
20607 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20608 -1, -1, -1, MOVE_TO_POS
);
20609 pt_x
= it
.current_x
;
20611 if (dir
> 0 || overshoot_expected
)
20613 struct glyph_row
*row
= it
.glyph_row
;
20615 /* When point is at beginning of line, we don't have
20616 information about the glyph there loaded into struct
20617 it. Calling get_next_display_element fixes that. */
20619 get_next_display_element (&it
);
20620 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20621 it
.glyph_row
= NULL
;
20622 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20623 it
.glyph_row
= row
;
20624 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20625 it, lest it will become out of sync with it's buffer
20627 it
.current_x
= pt_x
;
20630 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20631 pixel_width
= it
.pixel_width
;
20632 if (overshoot_expected
&& at_eol_p
)
20634 else if (pixel_width
<= 0)
20637 /* If there's a display string at point, we are actually at the
20638 glyph to the left of point, so we need to correct the X
20640 if (overshoot_expected
)
20643 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
20645 pt_x
+= pixel_width
;
20648 /* Compute target X coordinate, either to the left or to the
20649 right of point. On TTY frames, all characters have the same
20650 pixel width of 1, so we can use that. On GUI frames we don't
20651 have an easy way of getting at the pixel width of the
20652 character to the left of point, so we use a different method
20653 of getting to that place. */
20655 target_x
= pt_x
+ pixel_width
;
20657 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20659 /* Target X coordinate could be one line above or below the line
20660 of point, in which case we need to adjust the target X
20661 coordinate. Also, if moving to the left, we need to begin at
20662 the left edge of the point's screen line. */
20667 start_display (&it
, w
, pt
);
20668 reseat_at_previous_visible_line_start (&it
);
20669 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20671 move_it_by_lines (&it
, pt_vpos
);
20675 move_it_by_lines (&it
, -1);
20676 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20677 target_is_eol_p
= true;
20683 || (target_x
>= it
.last_visible_x
20684 && it
.line_wrap
!= TRUNCATE
))
20687 move_it_by_lines (&it
, 0);
20688 move_it_by_lines (&it
, 1);
20693 /* Move to the target X coordinate. */
20694 #ifdef HAVE_WINDOW_SYSTEM
20695 /* On GUI frames, as we don't know the X coordinate of the
20696 character to the left of point, moving point to the left
20697 requires walking, one grapheme cluster at a time, until we
20698 find ourself at a place immediately to the left of the
20699 character at point. */
20700 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20702 struct text_pos new_pos
= it
.current
.pos
;
20703 enum move_it_result rc
= MOVE_X_REACHED
;
20705 while (it
.current_x
+ it
.pixel_width
<= target_x
20706 && rc
== MOVE_X_REACHED
)
20708 int new_x
= it
.current_x
+ it
.pixel_width
;
20710 new_pos
= it
.current
.pos
;
20711 if (new_x
== it
.current_x
)
20713 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20714 MOVE_TO_POS
| MOVE_TO_X
);
20715 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20718 /* If we ended up on a composed character inside
20719 bidi-reordered text (e.g., Hebrew text with diacritics),
20720 the iterator gives us the buffer position of the last (in
20721 logical order) character of the composed grapheme cluster,
20722 which is not what we want. So we cheat: we compute the
20723 character position of the character that follows (in the
20724 logical order) the one where the above loop stopped. That
20725 character will appear on display to the left of point. */
20727 && it
.bidi_it
.scan_dir
== -1
20728 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20730 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20731 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20733 it
.current
.pos
= new_pos
;
20737 if (it
.current_x
!= target_x
)
20738 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20740 /* When lines are truncated, the above loop will stop at the
20741 window edge. But we want to get to the end of line, even if
20742 it is beyond the window edge; automatic hscroll will then
20743 scroll the window to show point as appropriate. */
20744 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20745 && get_next_display_element (&it
))
20747 struct text_pos new_pos
= it
.current
.pos
;
20749 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20751 set_iterator_to_next (&it
, 0);
20752 if (it
.method
== GET_FROM_BUFFER
)
20753 new_pos
= it
.current
.pos
;
20754 if (!get_next_display_element (&it
))
20758 it
.current
.pos
= new_pos
;
20761 /* If we ended up in a display string that covers point, move to
20762 buffer position to the right in the visual order. */
20765 while (IT_CHARPOS (it
) == PT
)
20767 set_iterator_to_next (&it
, 0);
20768 if (!get_next_display_element (&it
))
20773 /* Move point to that position. */
20774 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20777 return make_number (PT
);
20779 #undef ROW_GLYPH_NEWLINE_P
20783 /***********************************************************************
20785 ***********************************************************************/
20787 /* Redisplay the menu bar in the frame for window W.
20789 The menu bar of X frames that don't have X toolkit support is
20790 displayed in a special window W->frame->menu_bar_window.
20792 The menu bar of terminal frames is treated specially as far as
20793 glyph matrices are concerned. Menu bar lines are not part of
20794 windows, so the update is done directly on the frame matrix rows
20795 for the menu bar. */
20798 display_menu_bar (struct window
*w
)
20800 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20805 /* Don't do all this for graphical frames. */
20807 if (FRAME_W32_P (f
))
20810 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20816 if (FRAME_NS_P (f
))
20818 #endif /* HAVE_NS */
20820 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20821 eassert (!FRAME_WINDOW_P (f
));
20822 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20823 it
.first_visible_x
= 0;
20824 /* PXW: Use FRAME_PIXEL_WIDTH (f) here? */
20825 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20826 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20827 if (FRAME_WINDOW_P (f
))
20829 /* Menu bar lines are displayed in the desired matrix of the
20830 dummy window menu_bar_window. */
20831 struct window
*menu_w
;
20832 menu_w
= XWINDOW (f
->menu_bar_window
);
20833 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20835 it
.first_visible_x
= 0;
20836 /* PXW: Use FRAME_PIXEL_WIDTH (f) here? */
20837 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20840 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20842 /* This is a TTY frame, i.e. character hpos/vpos are used as
20844 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20846 it
.first_visible_x
= 0;
20847 it
.last_visible_x
= FRAME_COLS (f
);
20850 /* FIXME: This should be controlled by a user option. See the
20851 comments in redisplay_tool_bar and display_mode_line about
20853 it
.paragraph_embedding
= L2R
;
20855 /* Clear all rows of the menu bar. */
20856 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20858 struct glyph_row
*row
= it
.glyph_row
+ i
;
20859 clear_glyph_row (row
);
20860 row
->enabled_p
= true;
20861 row
->full_width_p
= 1;
20864 /* Display all items of the menu bar. */
20865 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20866 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20868 Lisp_Object string
;
20870 /* Stop at nil string. */
20871 string
= AREF (items
, i
+ 1);
20875 /* Remember where item was displayed. */
20876 ASET (items
, i
+ 3, make_number (it
.hpos
));
20878 /* Display the item, pad with one space. */
20879 if (it
.current_x
< it
.last_visible_x
)
20880 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20881 SCHARS (string
) + 1, 0, 0, -1);
20884 /* Fill out the line with spaces. */
20885 if (it
.current_x
< it
.last_visible_x
)
20886 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20888 /* Compute the total height of the lines. */
20889 compute_line_metrics (&it
);
20892 /* Deep copy of a glyph row, including the glyphs. */
20894 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20896 struct glyph
*pointers
[1 + LAST_AREA
];
20897 int to_used
= to
->used
[TEXT_AREA
];
20899 /* Save glyph pointers of TO. */
20900 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20902 /* Do a structure assignment. */
20905 /* Restore original glyph pointers of TO. */
20906 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20908 /* Copy the glyphs. */
20909 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20910 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20912 /* If we filled only part of the TO row, fill the rest with
20913 space_glyph (which will display as empty space). */
20914 if (to_used
> from
->used
[TEXT_AREA
])
20915 fill_up_frame_row_with_spaces (to
, to_used
);
20918 /* Display one menu item on a TTY, by overwriting the glyphs in the
20919 frame F's desired glyph matrix with glyphs produced from the menu
20920 item text. Called from term.c to display TTY drop-down menus one
20923 ITEM_TEXT is the menu item text as a C string.
20925 FACE_ID is the face ID to be used for this menu item. FACE_ID
20926 could specify one of 3 faces: a face for an enabled item, a face
20927 for a disabled item, or a face for a selected item.
20929 X and Y are coordinates of the first glyph in the frame's desired
20930 matrix to be overwritten by the menu item. Since this is a TTY, Y
20931 is the zero-based number of the glyph row and X is the zero-based
20932 glyph number in the row, starting from left, where to start
20933 displaying the item.
20935 SUBMENU non-zero means this menu item drops down a submenu, which
20936 should be indicated by displaying a proper visual cue after the
20940 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20941 int x
, int y
, int submenu
)
20944 struct frame
*f
= SELECTED_FRAME ();
20945 struct window
*w
= XWINDOW (f
->selected_window
);
20946 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20947 struct glyph_row
*row
;
20948 size_t item_len
= strlen (item_text
);
20950 eassert (FRAME_TERMCAP_P (f
));
20952 /* Don't write beyond the matrix's last row. This can happen for
20953 TTY screens that are not high enough to show the entire menu.
20954 (This is actually a bit of defensive programming, as
20955 tty_menu_display already limits the number of menu items to one
20956 less than the number of screen lines.) */
20957 if (y
>= f
->desired_matrix
->nrows
)
20960 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20961 it
.first_visible_x
= 0;
20962 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20963 row
= it
.glyph_row
;
20964 /* Start with the row contents from the current matrix. */
20965 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20966 saved_width
= row
->full_width_p
;
20967 row
->full_width_p
= 1;
20968 saved_reversed
= row
->reversed_p
;
20969 row
->reversed_p
= 0;
20970 row
->enabled_p
= true;
20972 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20974 eassert (x
< f
->desired_matrix
->matrix_w
);
20975 it
.current_x
= it
.hpos
= x
;
20976 it
.current_y
= it
.vpos
= y
;
20977 saved_used
= row
->used
[TEXT_AREA
];
20978 saved_truncated
= row
->truncated_on_right_p
;
20979 row
->used
[TEXT_AREA
] = x
;
20980 it
.face_id
= face_id
;
20981 it
.line_wrap
= TRUNCATE
;
20983 /* FIXME: This should be controlled by a user option. See the
20984 comments in redisplay_tool_bar and display_mode_line about this.
20985 Also, if paragraph_embedding could ever be R2L, changes will be
20986 needed to avoid shifting to the right the row characters in
20987 term.c:append_glyph. */
20988 it
.paragraph_embedding
= L2R
;
20990 /* Pad with a space on the left. */
20991 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20993 /* Display the menu item, pad with spaces to WIDTH. */
20996 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20997 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20999 /* Indicate with " >" that there's a submenu. */
21000 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
21001 FRAME_COLS (f
) - 1, -1);
21004 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21005 width
, 0, FRAME_COLS (f
) - 1, -1);
21007 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
21008 row
->truncated_on_right_p
= saved_truncated
;
21009 row
->hash
= row_hash (row
);
21010 row
->full_width_p
= saved_width
;
21011 row
->reversed_p
= saved_reversed
;
21014 /***********************************************************************
21016 ***********************************************************************/
21018 /* Redisplay mode lines in the window tree whose root is WINDOW. If
21019 FORCE is non-zero, redisplay mode lines unconditionally.
21020 Otherwise, redisplay only mode lines that are garbaged. Value is
21021 the number of windows whose mode lines were redisplayed. */
21024 redisplay_mode_lines (Lisp_Object window
, bool force
)
21028 while (!NILP (window
))
21030 struct window
*w
= XWINDOW (window
);
21032 if (WINDOWP (w
->contents
))
21033 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
21035 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
21036 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
21038 struct text_pos lpoint
;
21039 struct buffer
*old
= current_buffer
;
21041 /* Set the window's buffer for the mode line display. */
21042 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
21043 set_buffer_internal_1 (XBUFFER (w
->contents
));
21045 /* Point refers normally to the selected window. For any
21046 other window, set up appropriate value. */
21047 if (!EQ (window
, selected_window
))
21049 struct text_pos pt
;
21051 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
21052 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
21055 /* Display mode lines. */
21056 clear_glyph_matrix (w
->desired_matrix
);
21057 if (display_mode_lines (w
))
21060 /* Restore old settings. */
21061 set_buffer_internal_1 (old
);
21062 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
21072 /* Display the mode and/or header line of window W. Value is the
21073 sum number of mode lines and header lines displayed. */
21076 display_mode_lines (struct window
*w
)
21078 Lisp_Object old_selected_window
= selected_window
;
21079 Lisp_Object old_selected_frame
= selected_frame
;
21080 Lisp_Object new_frame
= w
->frame
;
21081 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
21084 selected_frame
= new_frame
;
21085 /* FIXME: If we were to allow the mode-line's computation changing the buffer
21086 or window's point, then we'd need select_window_1 here as well. */
21087 XSETWINDOW (selected_window
, w
);
21088 XFRAME (new_frame
)->selected_window
= selected_window
;
21090 /* These will be set while the mode line specs are processed. */
21091 line_number_displayed
= 0;
21092 w
->column_number_displayed
= -1;
21094 if (WINDOW_WANTS_MODELINE_P (w
))
21096 struct window
*sel_w
= XWINDOW (old_selected_window
);
21098 /* Select mode line face based on the real selected window. */
21099 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21100 BVAR (current_buffer
, mode_line_format
));
21104 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21106 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21107 BVAR (current_buffer
, header_line_format
));
21111 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21112 selected_frame
= old_selected_frame
;
21113 selected_window
= old_selected_window
;
21115 w
->must_be_updated_p
= true;
21120 /* Display mode or header line of window W. FACE_ID specifies which
21121 line to display; it is either MODE_LINE_FACE_ID or
21122 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21123 display. Value is the pixel height of the mode/header line
21127 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21131 ptrdiff_t count
= SPECPDL_INDEX ();
21133 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21134 /* Don't extend on a previously drawn mode-line.
21135 This may happen if called from pos_visible_p. */
21136 it
.glyph_row
->enabled_p
= false;
21137 prepare_desired_row (it
.glyph_row
);
21139 it
.glyph_row
->mode_line_p
= 1;
21141 /* FIXME: This should be controlled by a user option. But
21142 supporting such an option is not trivial, since the mode line is
21143 made up of many separate strings. */
21144 it
.paragraph_embedding
= L2R
;
21146 record_unwind_protect (unwind_format_mode_line
,
21147 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
21149 mode_line_target
= MODE_LINE_DISPLAY
;
21151 /* Temporarily make frame's keyboard the current kboard so that
21152 kboard-local variables in the mode_line_format will get the right
21154 push_kboard (FRAME_KBOARD (it
.f
));
21155 record_unwind_save_match_data ();
21156 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21159 unbind_to (count
, Qnil
);
21161 /* Fill up with spaces. */
21162 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
21164 compute_line_metrics (&it
);
21165 it
.glyph_row
->full_width_p
= 1;
21166 it
.glyph_row
->continued_p
= 0;
21167 it
.glyph_row
->truncated_on_left_p
= 0;
21168 it
.glyph_row
->truncated_on_right_p
= 0;
21170 /* Make a 3D mode-line have a shadow at its right end. */
21171 face
= FACE_FROM_ID (it
.f
, face_id
);
21172 extend_face_to_end_of_line (&it
);
21173 if (face
->box
!= FACE_NO_BOX
)
21175 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
21176 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
21177 last
->right_box_line_p
= 1;
21180 return it
.glyph_row
->height
;
21183 /* Move element ELT in LIST to the front of LIST.
21184 Return the updated list. */
21187 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
21189 register Lisp_Object tail
, prev
;
21190 register Lisp_Object tem
;
21194 while (CONSP (tail
))
21200 /* Splice out the link TAIL. */
21202 list
= XCDR (tail
);
21204 Fsetcdr (prev
, XCDR (tail
));
21206 /* Now make it the first. */
21207 Fsetcdr (tail
, list
);
21212 tail
= XCDR (tail
);
21216 /* Not found--return unchanged LIST. */
21220 /* Contribute ELT to the mode line for window IT->w. How it
21221 translates into text depends on its data type.
21223 IT describes the display environment in which we display, as usual.
21225 DEPTH is the depth in recursion. It is used to prevent
21226 infinite recursion here.
21228 FIELD_WIDTH is the number of characters the display of ELT should
21229 occupy in the mode line, and PRECISION is the maximum number of
21230 characters to display from ELT's representation. See
21231 display_string for details.
21233 Returns the hpos of the end of the text generated by ELT.
21235 PROPS is a property list to add to any string we encounter.
21237 If RISKY is nonzero, remove (disregard) any properties in any string
21238 we encounter, and ignore :eval and :propertize.
21240 The global variable `mode_line_target' determines whether the
21241 output is passed to `store_mode_line_noprop',
21242 `store_mode_line_string', or `display_string'. */
21245 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
21246 Lisp_Object elt
, Lisp_Object props
, int risky
)
21248 int n
= 0, field
, prec
;
21253 elt
= build_string ("*too-deep*");
21257 switch (XTYPE (elt
))
21261 /* A string: output it and check for %-constructs within it. */
21263 ptrdiff_t offset
= 0;
21265 if (SCHARS (elt
) > 0
21266 && (!NILP (props
) || risky
))
21268 Lisp_Object oprops
, aelt
;
21269 oprops
= Ftext_properties_at (make_number (0), elt
);
21271 /* If the starting string's properties are not what
21272 we want, translate the string. Also, if the string
21273 is risky, do that anyway. */
21275 if (NILP (Fequal (props
, oprops
)) || risky
)
21277 /* If the starting string has properties,
21278 merge the specified ones onto the existing ones. */
21279 if (! NILP (oprops
) && !risky
)
21283 oprops
= Fcopy_sequence (oprops
);
21285 while (CONSP (tem
))
21287 oprops
= Fplist_put (oprops
, XCAR (tem
),
21288 XCAR (XCDR (tem
)));
21289 tem
= XCDR (XCDR (tem
));
21294 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21295 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21297 /* AELT is what we want. Move it to the front
21298 without consing. */
21300 mode_line_proptrans_alist
21301 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21307 /* If AELT has the wrong props, it is useless.
21308 so get rid of it. */
21310 mode_line_proptrans_alist
21311 = Fdelq (aelt
, mode_line_proptrans_alist
);
21313 elt
= Fcopy_sequence (elt
);
21314 Fset_text_properties (make_number (0), Flength (elt
),
21316 /* Add this item to mode_line_proptrans_alist. */
21317 mode_line_proptrans_alist
21318 = Fcons (Fcons (elt
, props
),
21319 mode_line_proptrans_alist
);
21320 /* Truncate mode_line_proptrans_alist
21321 to at most 50 elements. */
21322 tem
= Fnthcdr (make_number (50),
21323 mode_line_proptrans_alist
);
21325 XSETCDR (tem
, Qnil
);
21334 prec
= precision
- n
;
21335 switch (mode_line_target
)
21337 case MODE_LINE_NOPROP
:
21338 case MODE_LINE_TITLE
:
21339 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21341 case MODE_LINE_STRING
:
21342 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21344 case MODE_LINE_DISPLAY
:
21345 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21346 0, prec
, 0, STRING_MULTIBYTE (elt
));
21353 /* Handle the non-literal case. */
21355 while ((precision
<= 0 || n
< precision
)
21356 && SREF (elt
, offset
) != 0
21357 && (mode_line_target
!= MODE_LINE_DISPLAY
21358 || it
->current_x
< it
->last_visible_x
))
21360 ptrdiff_t last_offset
= offset
;
21362 /* Advance to end of string or next format specifier. */
21363 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21366 if (offset
- 1 != last_offset
)
21368 ptrdiff_t nchars
, nbytes
;
21370 /* Output to end of string or up to '%'. Field width
21371 is length of string. Don't output more than
21372 PRECISION allows us. */
21375 prec
= c_string_width (SDATA (elt
) + last_offset
,
21376 offset
- last_offset
, precision
- n
,
21379 switch (mode_line_target
)
21381 case MODE_LINE_NOPROP
:
21382 case MODE_LINE_TITLE
:
21383 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21385 case MODE_LINE_STRING
:
21387 ptrdiff_t bytepos
= last_offset
;
21388 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21389 ptrdiff_t endpos
= (precision
<= 0
21390 ? string_byte_to_char (elt
, offset
)
21391 : charpos
+ nchars
);
21393 n
+= store_mode_line_string (NULL
,
21394 Fsubstring (elt
, make_number (charpos
),
21395 make_number (endpos
)),
21399 case MODE_LINE_DISPLAY
:
21401 ptrdiff_t bytepos
= last_offset
;
21402 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21404 if (precision
<= 0)
21405 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21406 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21408 STRING_MULTIBYTE (elt
));
21413 else /* c == '%' */
21415 ptrdiff_t percent_position
= offset
;
21417 /* Get the specified minimum width. Zero means
21420 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21421 field
= field
* 10 + c
- '0';
21423 /* Don't pad beyond the total padding allowed. */
21424 if (field_width
- n
> 0 && field
> field_width
- n
)
21425 field
= field_width
- n
;
21427 /* Note that either PRECISION <= 0 or N < PRECISION. */
21428 prec
= precision
- n
;
21431 n
+= display_mode_element (it
, depth
, field
, prec
,
21432 Vglobal_mode_string
, props
,
21437 ptrdiff_t bytepos
, charpos
;
21439 Lisp_Object string
;
21441 bytepos
= percent_position
;
21442 charpos
= (STRING_MULTIBYTE (elt
)
21443 ? string_byte_to_char (elt
, bytepos
)
21445 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21446 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21448 switch (mode_line_target
)
21450 case MODE_LINE_NOPROP
:
21451 case MODE_LINE_TITLE
:
21452 n
+= store_mode_line_noprop (spec
, field
, prec
);
21454 case MODE_LINE_STRING
:
21456 Lisp_Object tem
= build_string (spec
);
21457 props
= Ftext_properties_at (make_number (charpos
), elt
);
21458 /* Should only keep face property in props */
21459 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21462 case MODE_LINE_DISPLAY
:
21464 int nglyphs_before
, nwritten
;
21466 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21467 nwritten
= display_string (spec
, string
, elt
,
21472 /* Assign to the glyphs written above the
21473 string where the `%x' came from, position
21477 struct glyph
*glyph
21478 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21482 for (i
= 0; i
< nwritten
; ++i
)
21484 glyph
[i
].object
= elt
;
21485 glyph
[i
].charpos
= charpos
;
21502 /* A symbol: process the value of the symbol recursively
21503 as if it appeared here directly. Avoid error if symbol void.
21504 Special case: if value of symbol is a string, output the string
21507 register Lisp_Object tem
;
21509 /* If the variable is not marked as risky to set
21510 then its contents are risky to use. */
21511 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21514 tem
= Fboundp (elt
);
21517 tem
= Fsymbol_value (elt
);
21518 /* If value is a string, output that string literally:
21519 don't check for % within it. */
21523 if (!EQ (tem
, elt
))
21525 /* Give up right away for nil or t. */
21535 register Lisp_Object car
, tem
;
21537 /* A cons cell: five distinct cases.
21538 If first element is :eval or :propertize, do something special.
21539 If first element is a string or a cons, process all the elements
21540 and effectively concatenate them.
21541 If first element is a negative number, truncate displaying cdr to
21542 at most that many characters. If positive, pad (with spaces)
21543 to at least that many characters.
21544 If first element is a symbol, process the cadr or caddr recursively
21545 according to whether the symbol's value is non-nil or nil. */
21547 if (EQ (car
, QCeval
))
21549 /* An element of the form (:eval FORM) means evaluate FORM
21550 and use the result as mode line elements. */
21555 if (CONSP (XCDR (elt
)))
21558 spec
= safe_eval (XCAR (XCDR (elt
)));
21559 n
+= display_mode_element (it
, depth
, field_width
- n
,
21560 precision
- n
, spec
, props
,
21564 else if (EQ (car
, QCpropertize
))
21566 /* An element of the form (:propertize ELT PROPS...)
21567 means display ELT but applying properties PROPS. */
21572 if (CONSP (XCDR (elt
)))
21573 n
+= display_mode_element (it
, depth
, field_width
- n
,
21574 precision
- n
, XCAR (XCDR (elt
)),
21575 XCDR (XCDR (elt
)), risky
);
21577 else if (SYMBOLP (car
))
21579 tem
= Fboundp (car
);
21583 /* elt is now the cdr, and we know it is a cons cell.
21584 Use its car if CAR has a non-nil value. */
21587 tem
= Fsymbol_value (car
);
21594 /* Symbol's value is nil (or symbol is unbound)
21595 Get the cddr of the original list
21596 and if possible find the caddr and use that. */
21600 else if (!CONSP (elt
))
21605 else if (INTEGERP (car
))
21607 register int lim
= XINT (car
);
21611 /* Negative int means reduce maximum width. */
21612 if (precision
<= 0)
21615 precision
= min (precision
, -lim
);
21619 /* Padding specified. Don't let it be more than
21620 current maximum. */
21622 lim
= min (precision
, lim
);
21624 /* If that's more padding than already wanted, queue it.
21625 But don't reduce padding already specified even if
21626 that is beyond the current truncation point. */
21627 field_width
= max (lim
, field_width
);
21631 else if (STRINGP (car
) || CONSP (car
))
21633 Lisp_Object halftail
= elt
;
21637 && (precision
<= 0 || n
< precision
))
21639 n
+= display_mode_element (it
, depth
,
21640 /* Do padding only after the last
21641 element in the list. */
21642 (! CONSP (XCDR (elt
))
21645 precision
- n
, XCAR (elt
),
21649 if ((len
& 1) == 0)
21650 halftail
= XCDR (halftail
);
21651 /* Check for cycle. */
21652 if (EQ (halftail
, elt
))
21661 elt
= build_string ("*invalid*");
21665 /* Pad to FIELD_WIDTH. */
21666 if (field_width
> 0 && n
< field_width
)
21668 switch (mode_line_target
)
21670 case MODE_LINE_NOPROP
:
21671 case MODE_LINE_TITLE
:
21672 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21674 case MODE_LINE_STRING
:
21675 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21677 case MODE_LINE_DISPLAY
:
21678 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21687 /* Store a mode-line string element in mode_line_string_list.
21689 If STRING is non-null, display that C string. Otherwise, the Lisp
21690 string LISP_STRING is displayed.
21692 FIELD_WIDTH is the minimum number of output glyphs to produce.
21693 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21694 with spaces. FIELD_WIDTH <= 0 means don't pad.
21696 PRECISION is the maximum number of characters to output from
21697 STRING. PRECISION <= 0 means don't truncate the string.
21699 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21700 properties to the string.
21702 PROPS are the properties to add to the string.
21703 The mode_line_string_face face property is always added to the string.
21707 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21708 int field_width
, int precision
, Lisp_Object props
)
21713 if (string
!= NULL
)
21715 len
= strlen (string
);
21716 if (precision
> 0 && len
> precision
)
21718 lisp_string
= make_string (string
, len
);
21720 props
= mode_line_string_face_prop
;
21721 else if (!NILP (mode_line_string_face
))
21723 Lisp_Object face
= Fplist_get (props
, Qface
);
21724 props
= Fcopy_sequence (props
);
21726 face
= mode_line_string_face
;
21728 face
= list2 (face
, mode_line_string_face
);
21729 props
= Fplist_put (props
, Qface
, face
);
21731 Fadd_text_properties (make_number (0), make_number (len
),
21732 props
, lisp_string
);
21736 len
= XFASTINT (Flength (lisp_string
));
21737 if (precision
> 0 && len
> precision
)
21740 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21743 if (!NILP (mode_line_string_face
))
21747 props
= Ftext_properties_at (make_number (0), lisp_string
);
21748 face
= Fplist_get (props
, Qface
);
21750 face
= mode_line_string_face
;
21752 face
= list2 (face
, mode_line_string_face
);
21753 props
= list2 (Qface
, face
);
21755 lisp_string
= Fcopy_sequence (lisp_string
);
21758 Fadd_text_properties (make_number (0), make_number (len
),
21759 props
, lisp_string
);
21764 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21768 if (field_width
> len
)
21770 field_width
-= len
;
21771 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21773 Fadd_text_properties (make_number (0), make_number (field_width
),
21774 props
, lisp_string
);
21775 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21783 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21785 doc
: /* Format a string out of a mode line format specification.
21786 First arg FORMAT specifies the mode line format (see `mode-line-format'
21787 for details) to use.
21789 By default, the format is evaluated for the currently selected window.
21791 Optional second arg FACE specifies the face property to put on all
21792 characters for which no face is specified. The value nil means the
21793 default face. The value t means whatever face the window's mode line
21794 currently uses (either `mode-line' or `mode-line-inactive',
21795 depending on whether the window is the selected window or not).
21796 An integer value means the value string has no text
21799 Optional third and fourth args WINDOW and BUFFER specify the window
21800 and buffer to use as the context for the formatting (defaults
21801 are the selected window and the WINDOW's buffer). */)
21802 (Lisp_Object format
, Lisp_Object face
,
21803 Lisp_Object window
, Lisp_Object buffer
)
21808 struct buffer
*old_buffer
= NULL
;
21810 int no_props
= INTEGERP (face
);
21811 ptrdiff_t count
= SPECPDL_INDEX ();
21813 int string_start
= 0;
21815 w
= decode_any_window (window
);
21816 XSETWINDOW (window
, w
);
21819 buffer
= w
->contents
;
21820 CHECK_BUFFER (buffer
);
21822 /* Make formatting the modeline a non-op when noninteractive, otherwise
21823 there will be problems later caused by a partially initialized frame. */
21824 if (NILP (format
) || noninteractive
)
21825 return empty_unibyte_string
;
21830 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21831 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21832 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21833 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21834 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21835 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21836 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21839 old_buffer
= current_buffer
;
21841 /* Save things including mode_line_proptrans_alist,
21842 and set that to nil so that we don't alter the outer value. */
21843 record_unwind_protect (unwind_format_mode_line
,
21844 format_mode_line_unwind_data
21845 (XFRAME (WINDOW_FRAME (w
)),
21846 old_buffer
, selected_window
, 1));
21847 mode_line_proptrans_alist
= Qnil
;
21849 Fselect_window (window
, Qt
);
21850 set_buffer_internal_1 (XBUFFER (buffer
));
21852 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21856 mode_line_target
= MODE_LINE_NOPROP
;
21857 mode_line_string_face_prop
= Qnil
;
21858 mode_line_string_list
= Qnil
;
21859 string_start
= MODE_LINE_NOPROP_LEN (0);
21863 mode_line_target
= MODE_LINE_STRING
;
21864 mode_line_string_list
= Qnil
;
21865 mode_line_string_face
= face
;
21866 mode_line_string_face_prop
21867 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21870 push_kboard (FRAME_KBOARD (it
.f
));
21871 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21876 len
= MODE_LINE_NOPROP_LEN (string_start
);
21877 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21881 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21882 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21883 empty_unibyte_string
);
21886 unbind_to (count
, Qnil
);
21890 /* Write a null-terminated, right justified decimal representation of
21891 the positive integer D to BUF using a minimal field width WIDTH. */
21894 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21896 register char *p
= buf
;
21904 *p
++ = d
% 10 + '0';
21909 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21920 /* Write a null-terminated, right justified decimal and "human
21921 readable" representation of the nonnegative integer D to BUF using
21922 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21924 static const char power_letter
[] =
21938 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21940 /* We aim to represent the nonnegative integer D as
21941 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21942 ptrdiff_t quotient
= d
;
21944 /* -1 means: do not use TENTHS. */
21948 /* Length of QUOTIENT.TENTHS as a string. */
21954 if (quotient
>= 1000)
21956 /* Scale to the appropriate EXPONENT. */
21959 remainder
= quotient
% 1000;
21963 while (quotient
>= 1000);
21965 /* Round to nearest and decide whether to use TENTHS or not. */
21968 tenths
= remainder
/ 100;
21969 if (remainder
% 100 >= 50)
21976 if (quotient
== 10)
21984 if (remainder
>= 500)
21986 if (quotient
< 999)
21997 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21998 if (tenths
== -1 && quotient
<= 99)
22005 p
= psuffix
= buf
+ max (width
, length
);
22007 /* Print EXPONENT. */
22008 *psuffix
++ = power_letter
[exponent
];
22011 /* Print TENTHS. */
22014 *--p
= '0' + tenths
;
22018 /* Print QUOTIENT. */
22021 int digit
= quotient
% 10;
22022 *--p
= '0' + digit
;
22024 while ((quotient
/= 10) != 0);
22026 /* Print leading spaces. */
22031 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
22032 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
22033 type of CODING_SYSTEM. Return updated pointer into BUF. */
22035 static unsigned char invalid_eol_type
[] = "(*invalid*)";
22038 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
22041 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
22042 const unsigned char *eol_str
;
22044 /* The EOL conversion we are using. */
22045 Lisp_Object eoltype
;
22047 val
= CODING_SYSTEM_SPEC (coding_system
);
22050 if (!VECTORP (val
)) /* Not yet decided. */
22052 *buf
++ = multibyte
? '-' : ' ';
22054 eoltype
= eol_mnemonic_undecided
;
22055 /* Don't mention EOL conversion if it isn't decided. */
22060 Lisp_Object eolvalue
;
22062 attrs
= AREF (val
, 0);
22063 eolvalue
= AREF (val
, 2);
22066 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
22071 /* The EOL conversion that is normal on this system. */
22073 if (NILP (eolvalue
)) /* Not yet decided. */
22074 eoltype
= eol_mnemonic_undecided
;
22075 else if (VECTORP (eolvalue
)) /* Not yet decided. */
22076 eoltype
= eol_mnemonic_undecided
;
22077 else /* eolvalue is Qunix, Qdos, or Qmac. */
22078 eoltype
= (EQ (eolvalue
, Qunix
)
22079 ? eol_mnemonic_unix
22080 : (EQ (eolvalue
, Qdos
) == 1
22081 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
22087 /* Mention the EOL conversion if it is not the usual one. */
22088 if (STRINGP (eoltype
))
22090 eol_str
= SDATA (eoltype
);
22091 eol_str_len
= SBYTES (eoltype
);
22093 else if (CHARACTERP (eoltype
))
22095 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
22096 int c
= XFASTINT (eoltype
);
22097 eol_str_len
= CHAR_STRING (c
, tmp
);
22102 eol_str
= invalid_eol_type
;
22103 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22105 memcpy (buf
, eol_str
, eol_str_len
);
22106 buf
+= eol_str_len
;
22112 /* Return a string for the output of a mode line %-spec for window W,
22113 generated by character C. FIELD_WIDTH > 0 means pad the string
22114 returned with spaces to that value. Return a Lisp string in
22115 *STRING if the resulting string is taken from that Lisp string.
22117 Note we operate on the current buffer for most purposes. */
22119 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22121 static const char *
22122 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22123 Lisp_Object
*string
)
22126 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22127 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22128 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22129 produce strings from numerical values, so limit preposterously
22130 large values of FIELD_WIDTH to avoid overrunning the buffer's
22131 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22132 bytes plus the terminating null. */
22133 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22134 struct buffer
*b
= current_buffer
;
22142 if (!NILP (BVAR (b
, read_only
)))
22144 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22149 /* This differs from %* only for a modified read-only buffer. */
22150 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22152 if (!NILP (BVAR (b
, read_only
)))
22157 /* This differs from %* in ignoring read-only-ness. */
22158 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22170 if (command_loop_level
> 5)
22172 p
= decode_mode_spec_buf
;
22173 for (i
= 0; i
< command_loop_level
; i
++)
22176 return decode_mode_spec_buf
;
22184 if (command_loop_level
> 5)
22186 p
= decode_mode_spec_buf
;
22187 for (i
= 0; i
< command_loop_level
; i
++)
22190 return decode_mode_spec_buf
;
22197 /* Let lots_of_dashes be a string of infinite length. */
22198 if (mode_line_target
== MODE_LINE_NOPROP
22199 || mode_line_target
== MODE_LINE_STRING
)
22201 if (field_width
<= 0
22202 || field_width
> sizeof (lots_of_dashes
))
22204 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
22205 decode_mode_spec_buf
[i
] = '-';
22206 decode_mode_spec_buf
[i
] = '\0';
22207 return decode_mode_spec_buf
;
22210 return lots_of_dashes
;
22214 obj
= BVAR (b
, name
);
22218 /* %c and %l are ignored in `frame-title-format'.
22219 (In redisplay_internal, the frame title is drawn _before_ the
22220 windows are updated, so the stuff which depends on actual
22221 window contents (such as %l) may fail to render properly, or
22222 even crash emacs.) */
22223 if (mode_line_target
== MODE_LINE_TITLE
)
22227 ptrdiff_t col
= current_column ();
22228 w
->column_number_displayed
= col
;
22229 pint2str (decode_mode_spec_buf
, width
, col
);
22230 return decode_mode_spec_buf
;
22234 #ifndef SYSTEM_MALLOC
22236 if (NILP (Vmemory_full
))
22239 return "!MEM FULL! ";
22246 /* %F displays the frame name. */
22247 if (!NILP (f
->title
))
22248 return SSDATA (f
->title
);
22249 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
22250 return SSDATA (f
->name
);
22254 obj
= BVAR (b
, filename
);
22259 ptrdiff_t size
= ZV
- BEGV
;
22260 pint2str (decode_mode_spec_buf
, width
, size
);
22261 return decode_mode_spec_buf
;
22266 ptrdiff_t size
= ZV
- BEGV
;
22267 pint2hrstr (decode_mode_spec_buf
, width
, size
);
22268 return decode_mode_spec_buf
;
22273 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22274 ptrdiff_t topline
, nlines
, height
;
22277 /* %c and %l are ignored in `frame-title-format'. */
22278 if (mode_line_target
== MODE_LINE_TITLE
)
22281 startpos
= marker_position (w
->start
);
22282 startpos_byte
= marker_byte_position (w
->start
);
22283 height
= WINDOW_TOTAL_LINES (w
);
22285 /* If we decided that this buffer isn't suitable for line numbers,
22286 don't forget that too fast. */
22287 if (w
->base_line_pos
== -1)
22290 /* If the buffer is very big, don't waste time. */
22291 if (INTEGERP (Vline_number_display_limit
)
22292 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22294 w
->base_line_pos
= 0;
22295 w
->base_line_number
= 0;
22299 if (w
->base_line_number
> 0
22300 && w
->base_line_pos
> 0
22301 && w
->base_line_pos
<= startpos
)
22303 line
= w
->base_line_number
;
22304 linepos
= w
->base_line_pos
;
22305 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22310 linepos
= BUF_BEGV (b
);
22311 linepos_byte
= BUF_BEGV_BYTE (b
);
22314 /* Count lines from base line to window start position. */
22315 nlines
= display_count_lines (linepos_byte
,
22319 topline
= nlines
+ line
;
22321 /* Determine a new base line, if the old one is too close
22322 or too far away, or if we did not have one.
22323 "Too close" means it's plausible a scroll-down would
22324 go back past it. */
22325 if (startpos
== BUF_BEGV (b
))
22327 w
->base_line_number
= topline
;
22328 w
->base_line_pos
= BUF_BEGV (b
);
22330 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22331 || linepos
== BUF_BEGV (b
))
22333 ptrdiff_t limit
= BUF_BEGV (b
);
22334 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22335 ptrdiff_t position
;
22336 ptrdiff_t distance
=
22337 (height
* 2 + 30) * line_number_display_limit_width
;
22339 if (startpos
- distance
> limit
)
22341 limit
= startpos
- distance
;
22342 limit_byte
= CHAR_TO_BYTE (limit
);
22345 nlines
= display_count_lines (startpos_byte
,
22347 - (height
* 2 + 30),
22349 /* If we couldn't find the lines we wanted within
22350 line_number_display_limit_width chars per line,
22351 give up on line numbers for this window. */
22352 if (position
== limit_byte
&& limit
== startpos
- distance
)
22354 w
->base_line_pos
= -1;
22355 w
->base_line_number
= 0;
22359 w
->base_line_number
= topline
- nlines
;
22360 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22363 /* Now count lines from the start pos to point. */
22364 nlines
= display_count_lines (startpos_byte
,
22365 PT_BYTE
, PT
, &junk
);
22367 /* Record that we did display the line number. */
22368 line_number_displayed
= 1;
22370 /* Make the string to show. */
22371 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22372 return decode_mode_spec_buf
;
22375 char* p
= decode_mode_spec_buf
;
22376 int pad
= width
- 2;
22382 return decode_mode_spec_buf
;
22388 obj
= BVAR (b
, mode_name
);
22392 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22398 ptrdiff_t pos
= marker_position (w
->start
);
22399 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22401 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22403 if (pos
<= BUF_BEGV (b
))
22408 else if (pos
<= BUF_BEGV (b
))
22412 if (total
> 1000000)
22413 /* Do it differently for a large value, to avoid overflow. */
22414 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22416 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22417 /* We can't normally display a 3-digit number,
22418 so get us a 2-digit number that is close. */
22421 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22422 return decode_mode_spec_buf
;
22426 /* Display percentage of size above the bottom of the screen. */
22429 ptrdiff_t toppos
= marker_position (w
->start
);
22430 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22431 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22433 if (botpos
>= BUF_ZV (b
))
22435 if (toppos
<= BUF_BEGV (b
))
22442 if (total
> 1000000)
22443 /* Do it differently for a large value, to avoid overflow. */
22444 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22446 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22447 /* We can't normally display a 3-digit number,
22448 so get us a 2-digit number that is close. */
22451 if (toppos
<= BUF_BEGV (b
))
22452 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22454 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22455 return decode_mode_spec_buf
;
22460 /* status of process */
22461 obj
= Fget_buffer_process (Fcurrent_buffer ());
22463 return "no process";
22465 obj
= Fsymbol_name (Fprocess_status (obj
));
22471 ptrdiff_t count
= inhibit_garbage_collection ();
22472 Lisp_Object val
= call1 (intern ("file-remote-p"),
22473 BVAR (current_buffer
, directory
));
22474 unbind_to (count
, Qnil
);
22483 /* coding-system (not including end-of-line format) */
22485 /* coding-system (including end-of-line type) */
22487 int eol_flag
= (c
== 'Z');
22488 char *p
= decode_mode_spec_buf
;
22490 if (! FRAME_WINDOW_P (f
))
22492 /* No need to mention EOL here--the terminal never needs
22493 to do EOL conversion. */
22494 p
= decode_mode_spec_coding (CODING_ID_NAME
22495 (FRAME_KEYBOARD_CODING (f
)->id
),
22497 p
= decode_mode_spec_coding (CODING_ID_NAME
22498 (FRAME_TERMINAL_CODING (f
)->id
),
22501 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22504 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22505 #ifdef subprocesses
22506 obj
= Fget_buffer_process (Fcurrent_buffer ());
22507 if (PROCESSP (obj
))
22509 p
= decode_mode_spec_coding
22510 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22511 p
= decode_mode_spec_coding
22512 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22514 #endif /* subprocesses */
22517 return decode_mode_spec_buf
;
22524 return SSDATA (obj
);
22531 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22532 means count lines back from START_BYTE. But don't go beyond
22533 LIMIT_BYTE. Return the number of lines thus found (always
22536 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22537 either the position COUNT lines after/before START_BYTE, if we
22538 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22542 display_count_lines (ptrdiff_t start_byte
,
22543 ptrdiff_t limit_byte
, ptrdiff_t count
,
22544 ptrdiff_t *byte_pos_ptr
)
22546 register unsigned char *cursor
;
22547 unsigned char *base
;
22549 register ptrdiff_t ceiling
;
22550 register unsigned char *ceiling_addr
;
22551 ptrdiff_t orig_count
= count
;
22553 /* If we are not in selective display mode,
22554 check only for newlines. */
22555 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22556 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22560 while (start_byte
< limit_byte
)
22562 ceiling
= BUFFER_CEILING_OF (start_byte
);
22563 ceiling
= min (limit_byte
- 1, ceiling
);
22564 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22565 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22569 if (selective_display
)
22571 while (*cursor
!= '\n' && *cursor
!= 015
22572 && ++cursor
!= ceiling_addr
)
22574 if (cursor
== ceiling_addr
)
22579 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22588 start_byte
+= cursor
- base
;
22589 *byte_pos_ptr
= start_byte
;
22593 while (cursor
< ceiling_addr
);
22595 start_byte
+= ceiling_addr
- base
;
22600 while (start_byte
> limit_byte
)
22602 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22603 ceiling
= max (limit_byte
, ceiling
);
22604 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22605 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22608 if (selective_display
)
22610 while (--cursor
>= ceiling_addr
22611 && *cursor
!= '\n' && *cursor
!= 015)
22613 if (cursor
< ceiling_addr
)
22618 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22625 start_byte
+= cursor
- base
+ 1;
22626 *byte_pos_ptr
= start_byte
;
22627 /* When scanning backwards, we should
22628 not count the newline posterior to which we stop. */
22629 return - orig_count
- 1;
22632 start_byte
+= ceiling_addr
- base
;
22636 *byte_pos_ptr
= limit_byte
;
22639 return - orig_count
+ count
;
22640 return orig_count
- count
;
22646 /***********************************************************************
22648 ***********************************************************************/
22650 /* Display a NUL-terminated string, starting with index START.
22652 If STRING is non-null, display that C string. Otherwise, the Lisp
22653 string LISP_STRING is displayed. There's a case that STRING is
22654 non-null and LISP_STRING is not nil. It means STRING is a string
22655 data of LISP_STRING. In that case, we display LISP_STRING while
22656 ignoring its text properties.
22658 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22659 FACE_STRING. Display STRING or LISP_STRING with the face at
22660 FACE_STRING_POS in FACE_STRING:
22662 Display the string in the environment given by IT, but use the
22663 standard display table, temporarily.
22665 FIELD_WIDTH is the minimum number of output glyphs to produce.
22666 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22667 with spaces. If STRING has more characters, more than FIELD_WIDTH
22668 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22670 PRECISION is the maximum number of characters to output from
22671 STRING. PRECISION < 0 means don't truncate the string.
22673 This is roughly equivalent to printf format specifiers:
22675 FIELD_WIDTH PRECISION PRINTF
22676 ----------------------------------------
22682 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22683 display them, and < 0 means obey the current buffer's value of
22684 enable_multibyte_characters.
22686 Value is the number of columns displayed. */
22689 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22690 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22691 int field_width
, int precision
, int max_x
, int multibyte
)
22693 int hpos_at_start
= it
->hpos
;
22694 int saved_face_id
= it
->face_id
;
22695 struct glyph_row
*row
= it
->glyph_row
;
22696 ptrdiff_t it_charpos
;
22698 /* Initialize the iterator IT for iteration over STRING beginning
22699 with index START. */
22700 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22701 precision
, field_width
, multibyte
);
22702 if (string
&& STRINGP (lisp_string
))
22703 /* LISP_STRING is the one returned by decode_mode_spec. We should
22704 ignore its text properties. */
22705 it
->stop_charpos
= it
->end_charpos
;
22707 /* If displaying STRING, set up the face of the iterator from
22708 FACE_STRING, if that's given. */
22709 if (STRINGP (face_string
))
22715 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22716 0, &endptr
, it
->base_face_id
, 0);
22717 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22718 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22721 /* Set max_x to the maximum allowed X position. Don't let it go
22722 beyond the right edge of the window. */
22724 max_x
= it
->last_visible_x
;
22726 max_x
= min (max_x
, it
->last_visible_x
);
22728 /* Skip over display elements that are not visible. because IT->w is
22730 if (it
->current_x
< it
->first_visible_x
)
22731 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22732 MOVE_TO_POS
| MOVE_TO_X
);
22734 row
->ascent
= it
->max_ascent
;
22735 row
->height
= it
->max_ascent
+ it
->max_descent
;
22736 row
->phys_ascent
= it
->max_phys_ascent
;
22737 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22738 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22740 if (STRINGP (it
->string
))
22741 it_charpos
= IT_STRING_CHARPOS (*it
);
22743 it_charpos
= IT_CHARPOS (*it
);
22745 /* This condition is for the case that we are called with current_x
22746 past last_visible_x. */
22747 while (it
->current_x
< max_x
)
22749 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22751 /* Get the next display element. */
22752 if (!get_next_display_element (it
))
22755 /* Produce glyphs. */
22756 x_before
= it
->current_x
;
22757 n_glyphs_before
= row
->used
[TEXT_AREA
];
22758 PRODUCE_GLYPHS (it
);
22760 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22763 while (i
< nglyphs
)
22765 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22767 if (it
->line_wrap
!= TRUNCATE
22768 && x
+ glyph
->pixel_width
> max_x
)
22770 /* End of continued line or max_x reached. */
22771 if (CHAR_GLYPH_PADDING_P (*glyph
))
22773 /* A wide character is unbreakable. */
22774 if (row
->reversed_p
)
22775 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22776 - n_glyphs_before
);
22777 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22778 it
->current_x
= x_before
;
22782 if (row
->reversed_p
)
22783 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22784 - (n_glyphs_before
+ i
));
22785 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22790 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22792 /* Glyph is at least partially visible. */
22794 if (x
< it
->first_visible_x
)
22795 row
->x
= x
- it
->first_visible_x
;
22799 /* Glyph is off the left margin of the display area.
22800 Should not happen. */
22804 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22805 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22806 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22807 row
->phys_height
= max (row
->phys_height
,
22808 it
->max_phys_ascent
+ it
->max_phys_descent
);
22809 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22810 it
->max_extra_line_spacing
);
22811 x
+= glyph
->pixel_width
;
22815 /* Stop if max_x reached. */
22819 /* Stop at line ends. */
22820 if (ITERATOR_AT_END_OF_LINE_P (it
))
22822 it
->continuation_lines_width
= 0;
22826 set_iterator_to_next (it
, 1);
22827 if (STRINGP (it
->string
))
22828 it_charpos
= IT_STRING_CHARPOS (*it
);
22830 it_charpos
= IT_CHARPOS (*it
);
22832 /* Stop if truncating at the right edge. */
22833 if (it
->line_wrap
== TRUNCATE
22834 && it
->current_x
>= it
->last_visible_x
)
22836 /* Add truncation mark, but don't do it if the line is
22837 truncated at a padding space. */
22838 if (it_charpos
< it
->string_nchars
)
22840 if (!FRAME_WINDOW_P (it
->f
))
22844 if (it
->current_x
> it
->last_visible_x
)
22846 if (!row
->reversed_p
)
22848 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22849 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22854 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22855 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22857 unproduce_glyphs (it
, ii
+ 1);
22858 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22860 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22862 row
->used
[TEXT_AREA
] = ii
;
22863 produce_special_glyphs (it
, IT_TRUNCATION
);
22866 produce_special_glyphs (it
, IT_TRUNCATION
);
22868 row
->truncated_on_right_p
= 1;
22874 /* Maybe insert a truncation at the left. */
22875 if (it
->first_visible_x
22878 if (!FRAME_WINDOW_P (it
->f
)
22879 || (row
->reversed_p
22880 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22881 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22882 insert_left_trunc_glyphs (it
);
22883 row
->truncated_on_left_p
= 1;
22886 it
->face_id
= saved_face_id
;
22888 /* Value is number of columns displayed. */
22889 return it
->hpos
- hpos_at_start
;
22894 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22895 appears as an element of LIST or as the car of an element of LIST.
22896 If PROPVAL is a list, compare each element against LIST in that
22897 way, and return 1/2 if any element of PROPVAL is found in LIST.
22898 Otherwise return 0. This function cannot quit.
22899 The return value is 2 if the text is invisible but with an ellipsis
22900 and 1 if it's invisible and without an ellipsis. */
22903 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22905 register Lisp_Object tail
, proptail
;
22907 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22909 register Lisp_Object tem
;
22911 if (EQ (propval
, tem
))
22913 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22914 return NILP (XCDR (tem
)) ? 1 : 2;
22917 if (CONSP (propval
))
22919 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22921 Lisp_Object propelt
;
22922 propelt
= XCAR (proptail
);
22923 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22925 register Lisp_Object tem
;
22927 if (EQ (propelt
, tem
))
22929 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22930 return NILP (XCDR (tem
)) ? 1 : 2;
22938 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22939 doc
: /* Non-nil if the property makes the text invisible.
22940 POS-OR-PROP can be a marker or number, in which case it is taken to be
22941 a position in the current buffer and the value of the `invisible' property
22942 is checked; or it can be some other value, which is then presumed to be the
22943 value of the `invisible' property of the text of interest.
22944 The non-nil value returned can be t for truly invisible text or something
22945 else if the text is replaced by an ellipsis. */)
22946 (Lisp_Object pos_or_prop
)
22949 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22950 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22952 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22953 return (invis
== 0 ? Qnil
22955 : make_number (invis
));
22958 /* Calculate a width or height in pixels from a specification using
22959 the following elements:
22962 NUM - a (fractional) multiple of the default font width/height
22963 (NUM) - specifies exactly NUM pixels
22964 UNIT - a fixed number of pixels, see below.
22965 ELEMENT - size of a display element in pixels, see below.
22966 (NUM . SPEC) - equals NUM * SPEC
22967 (+ SPEC SPEC ...) - add pixel values
22968 (- SPEC SPEC ...) - subtract pixel values
22969 (- SPEC) - negate pixel value
22972 INT or FLOAT - a number constant
22973 SYMBOL - use symbol's (buffer local) variable binding.
22976 in - pixels per inch *)
22977 mm - pixels per 1/1000 meter *)
22978 cm - pixels per 1/100 meter *)
22979 width - width of current font in pixels.
22980 height - height of current font in pixels.
22982 *) using the ratio(s) defined in display-pixels-per-inch.
22986 left-fringe - left fringe width in pixels
22987 right-fringe - right fringe width in pixels
22989 left-margin - left margin width in pixels
22990 right-margin - right margin width in pixels
22992 scroll-bar - scroll-bar area width in pixels
22996 Pixels corresponding to 5 inches:
22999 Total width of non-text areas on left side of window (if scroll-bar is on left):
23000 '(space :width (+ left-fringe left-margin scroll-bar))
23002 Align to first text column (in header line):
23003 '(space :align-to 0)
23005 Align to middle of text area minus half the width of variable `my-image'
23006 containing a loaded image:
23007 '(space :align-to (0.5 . (- text my-image)))
23009 Width of left margin minus width of 1 character in the default font:
23010 '(space :width (- left-margin 1))
23012 Width of left margin minus width of 2 characters in the current font:
23013 '(space :width (- left-margin (2 . width)))
23015 Center 1 character over left-margin (in header line):
23016 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
23018 Different ways to express width of left fringe plus left margin minus one pixel:
23019 '(space :width (- (+ left-fringe left-margin) (1)))
23020 '(space :width (+ left-fringe left-margin (- (1))))
23021 '(space :width (+ left-fringe left-margin (-1)))
23026 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
23027 struct font
*font
, int width_p
, int *align_to
)
23031 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
23032 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
23035 return OK_PIXELS (0);
23037 eassert (FRAME_LIVE_P (it
->f
));
23039 if (SYMBOLP (prop
))
23041 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
23043 char *unit
= SSDATA (SYMBOL_NAME (prop
));
23045 if (unit
[0] == 'i' && unit
[1] == 'n')
23047 else if (unit
[0] == 'm' && unit
[1] == 'm')
23049 else if (unit
[0] == 'c' && unit
[1] == 'm')
23055 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
23056 : FRAME_RES_Y (it
->f
));
23059 return OK_PIXELS (ppi
/ pixels
);
23064 #ifdef HAVE_WINDOW_SYSTEM
23065 if (EQ (prop
, Qheight
))
23066 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
23067 if (EQ (prop
, Qwidth
))
23068 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
23070 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
23071 return OK_PIXELS (1);
23074 if (EQ (prop
, Qtext
))
23075 return OK_PIXELS (width_p
23076 ? window_box_width (it
->w
, TEXT_AREA
)
23077 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
23079 if (align_to
&& *align_to
< 0)
23082 if (EQ (prop
, Qleft
))
23083 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
23084 if (EQ (prop
, Qright
))
23085 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
23086 if (EQ (prop
, Qcenter
))
23087 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
23088 + window_box_width (it
->w
, TEXT_AREA
) / 2);
23089 if (EQ (prop
, Qleft_fringe
))
23090 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23091 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
23092 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
23093 if (EQ (prop
, Qright_fringe
))
23094 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23095 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23096 : window_box_right_offset (it
->w
, TEXT_AREA
));
23097 if (EQ (prop
, Qleft_margin
))
23098 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23099 if (EQ (prop
, Qright_margin
))
23100 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23101 if (EQ (prop
, Qscroll_bar
))
23102 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23104 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23105 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23106 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23111 if (EQ (prop
, Qleft_fringe
))
23112 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23113 if (EQ (prop
, Qright_fringe
))
23114 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23115 if (EQ (prop
, Qleft_margin
))
23116 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23117 if (EQ (prop
, Qright_margin
))
23118 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23119 if (EQ (prop
, Qscroll_bar
))
23120 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23123 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
23124 if (EQ (prop
, Qunbound
))
23128 if (INTEGERP (prop
) || FLOATP (prop
))
23130 int base_unit
= (width_p
23131 ? FRAME_COLUMN_WIDTH (it
->f
)
23132 : FRAME_LINE_HEIGHT (it
->f
));
23133 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23138 Lisp_Object car
= XCAR (prop
);
23139 Lisp_Object cdr
= XCDR (prop
);
23143 #ifdef HAVE_WINDOW_SYSTEM
23144 if (FRAME_WINDOW_P (it
->f
)
23145 && valid_image_p (prop
))
23147 ptrdiff_t id
= lookup_image (it
->f
, prop
);
23148 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
23150 return OK_PIXELS (width_p
? img
->width
: img
->height
);
23153 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
23159 while (CONSP (cdr
))
23161 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
23162 font
, width_p
, align_to
))
23165 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
23170 if (EQ (car
, Qminus
))
23172 return OK_PIXELS (pixels
);
23175 car
= buffer_local_value_1 (car
, it
->w
->contents
);
23176 if (EQ (car
, Qunbound
))
23180 if (INTEGERP (car
) || FLOATP (car
))
23183 pixels
= XFLOATINT (car
);
23185 return OK_PIXELS (pixels
);
23186 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
23187 font
, width_p
, align_to
))
23188 return OK_PIXELS (pixels
* fact
);
23199 /***********************************************************************
23201 ***********************************************************************/
23203 #ifdef HAVE_WINDOW_SYSTEM
23208 dump_glyph_string (struct glyph_string
*s
)
23210 fprintf (stderr
, "glyph string\n");
23211 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
23212 s
->x
, s
->y
, s
->width
, s
->height
);
23213 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
23214 fprintf (stderr
, " hl = %d\n", s
->hl
);
23215 fprintf (stderr
, " left overhang = %d, right = %d\n",
23216 s
->left_overhang
, s
->right_overhang
);
23217 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
23218 fprintf (stderr
, " extends to end of line = %d\n",
23219 s
->extends_to_end_of_line_p
);
23220 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
23221 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
23224 #endif /* GLYPH_DEBUG */
23226 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
23227 of XChar2b structures for S; it can't be allocated in
23228 init_glyph_string because it must be allocated via `alloca'. W
23229 is the window on which S is drawn. ROW and AREA are the glyph row
23230 and area within the row from which S is constructed. START is the
23231 index of the first glyph structure covered by S. HL is a
23232 face-override for drawing S. */
23235 #define OPTIONAL_HDC(hdc) HDC hdc,
23236 #define DECLARE_HDC(hdc) HDC hdc;
23237 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
23238 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
23241 #ifndef OPTIONAL_HDC
23242 #define OPTIONAL_HDC(hdc)
23243 #define DECLARE_HDC(hdc)
23244 #define ALLOCATE_HDC(hdc, f)
23245 #define RELEASE_HDC(hdc, f)
23249 init_glyph_string (struct glyph_string
*s
,
23251 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
23252 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
23254 memset (s
, 0, sizeof *s
);
23256 s
->f
= XFRAME (w
->frame
);
23260 s
->display
= FRAME_X_DISPLAY (s
->f
);
23261 s
->window
= FRAME_X_WINDOW (s
->f
);
23262 s
->char2b
= char2b
;
23266 s
->first_glyph
= row
->glyphs
[area
] + start
;
23267 s
->height
= row
->height
;
23268 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23269 s
->ybase
= s
->y
+ row
->ascent
;
23273 /* Append the list of glyph strings with head H and tail T to the list
23274 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23277 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23278 struct glyph_string
*h
, struct glyph_string
*t
)
23292 /* Prepend the list of glyph strings with head H and tail T to the
23293 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23297 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23298 struct glyph_string
*h
, struct glyph_string
*t
)
23312 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23313 Set *HEAD and *TAIL to the resulting list. */
23316 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23317 struct glyph_string
*s
)
23319 s
->next
= s
->prev
= NULL
;
23320 append_glyph_string_lists (head
, tail
, s
, s
);
23324 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23325 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23326 make sure that X resources for the face returned are allocated.
23327 Value is a pointer to a realized face that is ready for display if
23328 DISPLAY_P is non-zero. */
23330 static struct face
*
23331 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23332 XChar2b
*char2b
, int display_p
)
23334 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23339 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23341 if (code
== FONT_INVALID_CODE
)
23344 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23346 /* Make sure X resources of the face are allocated. */
23347 #ifdef HAVE_X_WINDOWS
23351 eassert (face
!= NULL
);
23352 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23359 /* Get face and two-byte form of character glyph GLYPH on frame F.
23360 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23361 a pointer to a realized face that is ready for display. */
23363 static struct face
*
23364 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23365 XChar2b
*char2b
, int *two_byte_p
)
23370 eassert (glyph
->type
== CHAR_GLYPH
);
23371 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23373 /* Make sure X resources of the face are allocated. */
23374 eassert (face
!= NULL
);
23375 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23382 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23383 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23385 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23387 if (code
== FONT_INVALID_CODE
)
23391 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23396 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23397 Return 1 if FONT has a glyph for C, otherwise return 0. */
23400 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23404 if (CHAR_BYTE8_P (c
))
23405 code
= CHAR_TO_BYTE8 (c
);
23407 code
= font
->driver
->encode_char (font
, c
);
23409 if (code
== FONT_INVALID_CODE
)
23411 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23416 /* Fill glyph string S with composition components specified by S->cmp.
23418 BASE_FACE is the base face of the composition.
23419 S->cmp_from is the index of the first component for S.
23421 OVERLAPS non-zero means S should draw the foreground only, and use
23422 its physical height for clipping. See also draw_glyphs.
23424 Value is the index of a component not in S. */
23427 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23431 /* For all glyphs of this composition, starting at the offset
23432 S->cmp_from, until we reach the end of the definition or encounter a
23433 glyph that requires the different face, add it to S. */
23438 s
->for_overlaps
= overlaps
;
23441 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23443 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23445 /* TAB in a composition means display glyphs with padding space
23446 on the left or right. */
23449 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23452 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23459 s
->font
= s
->face
->font
;
23461 else if (s
->face
!= face
)
23469 if (s
->face
== NULL
)
23471 s
->face
= base_face
->ascii_face
;
23472 s
->font
= s
->face
->font
;
23475 /* All glyph strings for the same composition has the same width,
23476 i.e. the width set for the first component of the composition. */
23477 s
->width
= s
->first_glyph
->pixel_width
;
23479 /* If the specified font could not be loaded, use the frame's
23480 default font, but record the fact that we couldn't load it in
23481 the glyph string so that we can draw rectangles for the
23482 characters of the glyph string. */
23483 if (s
->font
== NULL
)
23485 s
->font_not_found_p
= 1;
23486 s
->font
= FRAME_FONT (s
->f
);
23489 /* Adjust base line for subscript/superscript text. */
23490 s
->ybase
+= s
->first_glyph
->voffset
;
23492 /* This glyph string must always be drawn with 16-bit functions. */
23499 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23500 int start
, int end
, int overlaps
)
23502 struct glyph
*glyph
, *last
;
23503 Lisp_Object lgstring
;
23506 s
->for_overlaps
= overlaps
;
23507 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23508 last
= s
->row
->glyphs
[s
->area
] + end
;
23509 s
->cmp_id
= glyph
->u
.cmp
.id
;
23510 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23511 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23512 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23513 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23514 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23516 while (glyph
< last
23517 && glyph
->u
.cmp
.automatic
23518 && glyph
->u
.cmp
.id
== s
->cmp_id
23519 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23520 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23522 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23524 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23525 unsigned code
= LGLYPH_CODE (lglyph
);
23527 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23529 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23530 return glyph
- s
->row
->glyphs
[s
->area
];
23534 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23535 See the comment of fill_glyph_string for arguments.
23536 Value is the index of the first glyph not in S. */
23540 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23541 int start
, int end
, int overlaps
)
23543 struct glyph
*glyph
, *last
;
23546 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23547 s
->for_overlaps
= overlaps
;
23548 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23549 last
= s
->row
->glyphs
[s
->area
] + end
;
23550 voffset
= glyph
->voffset
;
23551 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23552 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23554 s
->width
= glyph
->pixel_width
;
23556 while (glyph
< last
23557 && glyph
->type
== GLYPHLESS_GLYPH
23558 && glyph
->voffset
== voffset
23559 && glyph
->face_id
== face_id
)
23562 s
->width
+= glyph
->pixel_width
;
23565 s
->ybase
+= voffset
;
23566 return glyph
- s
->row
->glyphs
[s
->area
];
23570 /* Fill glyph string S from a sequence of character glyphs.
23572 FACE_ID is the face id of the string. START is the index of the
23573 first glyph to consider, END is the index of the last + 1.
23574 OVERLAPS non-zero means S should draw the foreground only, and use
23575 its physical height for clipping. See also draw_glyphs.
23577 Value is the index of the first glyph not in S. */
23580 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23581 int start
, int end
, int overlaps
)
23583 struct glyph
*glyph
, *last
;
23585 int glyph_not_available_p
;
23587 eassert (s
->f
== XFRAME (s
->w
->frame
));
23588 eassert (s
->nchars
== 0);
23589 eassert (start
>= 0 && end
> start
);
23591 s
->for_overlaps
= overlaps
;
23592 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23593 last
= s
->row
->glyphs
[s
->area
] + end
;
23594 voffset
= glyph
->voffset
;
23595 s
->padding_p
= glyph
->padding_p
;
23596 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23598 while (glyph
< last
23599 && glyph
->type
== CHAR_GLYPH
23600 && glyph
->voffset
== voffset
23601 /* Same face id implies same font, nowadays. */
23602 && glyph
->face_id
== face_id
23603 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23607 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23608 s
->char2b
+ s
->nchars
,
23610 s
->two_byte_p
= two_byte_p
;
23612 eassert (s
->nchars
<= end
- start
);
23613 s
->width
+= glyph
->pixel_width
;
23614 if (glyph
++->padding_p
!= s
->padding_p
)
23618 s
->font
= s
->face
->font
;
23620 /* If the specified font could not be loaded, use the frame's font,
23621 but record the fact that we couldn't load it in
23622 S->font_not_found_p so that we can draw rectangles for the
23623 characters of the glyph string. */
23624 if (s
->font
== NULL
|| glyph_not_available_p
)
23626 s
->font_not_found_p
= 1;
23627 s
->font
= FRAME_FONT (s
->f
);
23630 /* Adjust base line for subscript/superscript text. */
23631 s
->ybase
+= voffset
;
23633 eassert (s
->face
&& s
->face
->gc
);
23634 return glyph
- s
->row
->glyphs
[s
->area
];
23638 /* Fill glyph string S from image glyph S->first_glyph. */
23641 fill_image_glyph_string (struct glyph_string
*s
)
23643 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23644 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23646 s
->slice
= s
->first_glyph
->slice
.img
;
23647 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23648 s
->font
= s
->face
->font
;
23649 s
->width
= s
->first_glyph
->pixel_width
;
23651 /* Adjust base line for subscript/superscript text. */
23652 s
->ybase
+= s
->first_glyph
->voffset
;
23656 /* Fill glyph string S from a sequence of stretch glyphs.
23658 START is the index of the first glyph to consider,
23659 END is the index of the last + 1.
23661 Value is the index of the first glyph not in S. */
23664 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23666 struct glyph
*glyph
, *last
;
23667 int voffset
, face_id
;
23669 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23671 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23672 last
= s
->row
->glyphs
[s
->area
] + end
;
23673 face_id
= glyph
->face_id
;
23674 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23675 s
->font
= s
->face
->font
;
23676 s
->width
= glyph
->pixel_width
;
23678 voffset
= glyph
->voffset
;
23682 && glyph
->type
== STRETCH_GLYPH
23683 && glyph
->voffset
== voffset
23684 && glyph
->face_id
== face_id
);
23686 s
->width
+= glyph
->pixel_width
;
23688 /* Adjust base line for subscript/superscript text. */
23689 s
->ybase
+= voffset
;
23691 /* The case that face->gc == 0 is handled when drawing the glyph
23692 string by calling PREPARE_FACE_FOR_DISPLAY. */
23694 return glyph
- s
->row
->glyphs
[s
->area
];
23697 static struct font_metrics
*
23698 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23700 static struct font_metrics metrics
;
23705 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23706 if (code
== FONT_INVALID_CODE
)
23708 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23713 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23714 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23715 assumed to be zero. */
23718 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23720 *left
= *right
= 0;
23722 if (glyph
->type
== CHAR_GLYPH
)
23726 struct font_metrics
*pcm
;
23728 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23729 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23731 if (pcm
->rbearing
> pcm
->width
)
23732 *right
= pcm
->rbearing
- pcm
->width
;
23733 if (pcm
->lbearing
< 0)
23734 *left
= -pcm
->lbearing
;
23737 else if (glyph
->type
== COMPOSITE_GLYPH
)
23739 if (! glyph
->u
.cmp
.automatic
)
23741 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23743 if (cmp
->rbearing
> cmp
->pixel_width
)
23744 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23745 if (cmp
->lbearing
< 0)
23746 *left
= - cmp
->lbearing
;
23750 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23751 struct font_metrics metrics
;
23753 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23754 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23755 if (metrics
.rbearing
> metrics
.width
)
23756 *right
= metrics
.rbearing
- metrics
.width
;
23757 if (metrics
.lbearing
< 0)
23758 *left
= - metrics
.lbearing
;
23764 /* Return the index of the first glyph preceding glyph string S that
23765 is overwritten by S because of S's left overhang. Value is -1
23766 if no glyphs are overwritten. */
23769 left_overwritten (struct glyph_string
*s
)
23773 if (s
->left_overhang
)
23776 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23777 int first
= s
->first_glyph
- glyphs
;
23779 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23780 x
-= glyphs
[i
].pixel_width
;
23791 /* Return the index of the first glyph preceding glyph string S that
23792 is overwriting S because of its right overhang. Value is -1 if no
23793 glyph in front of S overwrites S. */
23796 left_overwriting (struct glyph_string
*s
)
23799 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23800 int first
= s
->first_glyph
- glyphs
;
23804 for (i
= first
- 1; i
>= 0; --i
)
23807 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23810 x
-= glyphs
[i
].pixel_width
;
23817 /* Return the index of the last glyph following glyph string S that is
23818 overwritten by S because of S's right overhang. Value is -1 if
23819 no such glyph is found. */
23822 right_overwritten (struct glyph_string
*s
)
23826 if (s
->right_overhang
)
23829 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23830 int first
= (s
->first_glyph
- glyphs
23831 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23832 int end
= s
->row
->used
[s
->area
];
23834 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23835 x
+= glyphs
[i
].pixel_width
;
23844 /* Return the index of the last glyph following glyph string S that
23845 overwrites S because of its left overhang. Value is negative
23846 if no such glyph is found. */
23849 right_overwriting (struct glyph_string
*s
)
23852 int end
= s
->row
->used
[s
->area
];
23853 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23854 int first
= (s
->first_glyph
- glyphs
23855 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23859 for (i
= first
; i
< end
; ++i
)
23862 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23865 x
+= glyphs
[i
].pixel_width
;
23872 /* Set background width of glyph string S. START is the index of the
23873 first glyph following S. LAST_X is the right-most x-position + 1
23874 in the drawing area. */
23877 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23879 /* If the face of this glyph string has to be drawn to the end of
23880 the drawing area, set S->extends_to_end_of_line_p. */
23882 if (start
== s
->row
->used
[s
->area
]
23883 && ((s
->row
->fill_line_p
23884 && (s
->hl
== DRAW_NORMAL_TEXT
23885 || s
->hl
== DRAW_IMAGE_RAISED
23886 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23887 || s
->hl
== DRAW_MOUSE_FACE
))
23888 s
->extends_to_end_of_line_p
= 1;
23890 /* If S extends its face to the end of the line, set its
23891 background_width to the distance to the right edge of the drawing
23893 if (s
->extends_to_end_of_line_p
)
23894 s
->background_width
= last_x
- s
->x
+ 1;
23896 s
->background_width
= s
->width
;
23900 /* Compute overhangs and x-positions for glyph string S and its
23901 predecessors, or successors. X is the starting x-position for S.
23902 BACKWARD_P non-zero means process predecessors. */
23905 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23911 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23912 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23922 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23923 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23933 /* The following macros are only called from draw_glyphs below.
23934 They reference the following parameters of that function directly:
23935 `w', `row', `area', and `overlap_p'
23936 as well as the following local variables:
23937 `s', `f', and `hdc' (in W32) */
23940 /* On W32, silently add local `hdc' variable to argument list of
23941 init_glyph_string. */
23942 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23943 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23945 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23946 init_glyph_string (s, char2b, w, row, area, start, hl)
23949 /* Add a glyph string for a stretch glyph to the list of strings
23950 between HEAD and TAIL. START is the index of the stretch glyph in
23951 row area AREA of glyph row ROW. END is the index of the last glyph
23952 in that glyph row area. X is the current output position assigned
23953 to the new glyph string constructed. HL overrides that face of the
23954 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23955 is the right-most x-position of the drawing area. */
23957 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23958 and below -- keep them on one line. */
23959 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23962 s = alloca (sizeof *s); \
23963 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23964 START = fill_stretch_glyph_string (s, START, END); \
23965 append_glyph_string (&HEAD, &TAIL, s); \
23971 /* Add a glyph string for an image glyph to the list of strings
23972 between HEAD and TAIL. START is the index of the image glyph in
23973 row area AREA of glyph row ROW. END is the index of the last glyph
23974 in that glyph row area. X is the current output position assigned
23975 to the new glyph string constructed. HL overrides that face of the
23976 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23977 is the right-most x-position of the drawing area. */
23979 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23982 s = alloca (sizeof *s); \
23983 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23984 fill_image_glyph_string (s); \
23985 append_glyph_string (&HEAD, &TAIL, s); \
23992 /* Add a glyph string for a sequence of character glyphs to the list
23993 of strings between HEAD and TAIL. START is the index of the first
23994 glyph in row area AREA of glyph row ROW that is part of the new
23995 glyph string. END is the index of the last glyph in that glyph row
23996 area. X is the current output position assigned to the new glyph
23997 string constructed. HL overrides that face of the glyph; e.g. it
23998 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23999 right-most x-position of the drawing area. */
24001 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24007 face_id = (row)->glyphs[area][START].face_id; \
24009 s = alloca (sizeof *s); \
24010 char2b = alloca ((END - START) * sizeof *char2b); \
24011 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24012 append_glyph_string (&HEAD, &TAIL, s); \
24014 START = fill_glyph_string (s, face_id, START, END, overlaps); \
24019 /* Add a glyph string for a composite sequence to the list of strings
24020 between HEAD and TAIL. START is the index of the first glyph in
24021 row area AREA of glyph row ROW that is part of the new glyph
24022 string. END is the index of the last glyph in that glyph row area.
24023 X is the current output position assigned to the new glyph string
24024 constructed. HL overrides that face of the glyph; e.g. it is
24025 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
24026 x-position of the drawing area. */
24028 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24030 int face_id = (row)->glyphs[area][START].face_id; \
24031 struct face *base_face = FACE_FROM_ID (f, face_id); \
24032 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
24033 struct composition *cmp = composition_table[cmp_id]; \
24035 struct glyph_string *first_s = NULL; \
24038 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
24040 /* Make glyph_strings for each glyph sequence that is drawable by \
24041 the same face, and append them to HEAD/TAIL. */ \
24042 for (n = 0; n < cmp->glyph_len;) \
24044 s = alloca (sizeof *s); \
24045 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24046 append_glyph_string (&(HEAD), &(TAIL), s); \
24052 n = fill_composite_glyph_string (s, base_face, overlaps); \
24060 /* Add a glyph string for a glyph-string sequence to the list of strings
24061 between HEAD and TAIL. */
24063 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24067 Lisp_Object gstring; \
24069 face_id = (row)->glyphs[area][START].face_id; \
24070 gstring = (composition_gstring_from_id \
24071 ((row)->glyphs[area][START].u.cmp.id)); \
24072 s = alloca (sizeof *s); \
24073 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
24074 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24075 append_glyph_string (&(HEAD), &(TAIL), s); \
24077 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
24081 /* Add a glyph string for a sequence of glyphless character's glyphs
24082 to the list of strings between HEAD and TAIL. The meanings of
24083 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
24085 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24090 face_id = (row)->glyphs[area][START].face_id; \
24092 s = alloca (sizeof *s); \
24093 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24094 append_glyph_string (&HEAD, &TAIL, s); \
24096 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24102 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24103 of AREA of glyph row ROW on window W between indices START and END.
24104 HL overrides the face for drawing glyph strings, e.g. it is
24105 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24106 x-positions of the drawing area.
24108 This is an ugly monster macro construct because we must use alloca
24109 to allocate glyph strings (because draw_glyphs can be called
24110 asynchronously). */
24112 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24115 HEAD = TAIL = NULL; \
24116 while (START < END) \
24118 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24119 switch (first_glyph->type) \
24122 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24126 case COMPOSITE_GLYPH: \
24127 if (first_glyph->u.cmp.automatic) \
24128 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24131 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24135 case STRETCH_GLYPH: \
24136 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24140 case IMAGE_GLYPH: \
24141 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24145 case GLYPHLESS_GLYPH: \
24146 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
24156 set_glyph_string_background_width (s, START, LAST_X); \
24163 /* Draw glyphs between START and END in AREA of ROW on window W,
24164 starting at x-position X. X is relative to AREA in W. HL is a
24165 face-override with the following meaning:
24167 DRAW_NORMAL_TEXT draw normally
24168 DRAW_CURSOR draw in cursor face
24169 DRAW_MOUSE_FACE draw in mouse face.
24170 DRAW_INVERSE_VIDEO draw in mode line face
24171 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
24172 DRAW_IMAGE_RAISED draw an image with a raised relief around it
24174 If OVERLAPS is non-zero, draw only the foreground of characters and
24175 clip to the physical height of ROW. Non-zero value also defines
24176 the overlapping part to be drawn:
24178 OVERLAPS_PRED overlap with preceding rows
24179 OVERLAPS_SUCC overlap with succeeding rows
24180 OVERLAPS_BOTH overlap with both preceding/succeeding rows
24181 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
24183 Value is the x-position reached, relative to AREA of W. */
24186 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
24187 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
24188 enum draw_glyphs_face hl
, int overlaps
)
24190 struct glyph_string
*head
, *tail
;
24191 struct glyph_string
*s
;
24192 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
24193 int i
, j
, x_reached
, last_x
, area_left
= 0;
24194 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24197 ALLOCATE_HDC (hdc
, f
);
24199 /* Let's rather be paranoid than getting a SEGV. */
24200 end
= min (end
, row
->used
[area
]);
24201 start
= clip_to_bounds (0, start
, end
);
24203 /* Translate X to frame coordinates. Set last_x to the right
24204 end of the drawing area. */
24205 if (row
->full_width_p
)
24207 /* X is relative to the left edge of W, without scroll bars
24209 area_left
= WINDOW_LEFT_EDGE_X (w
);
24210 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
24211 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
24215 area_left
= window_box_left (w
, area
);
24216 last_x
= area_left
+ window_box_width (w
, area
);
24220 /* Build a doubly-linked list of glyph_string structures between
24221 head and tail from what we have to draw. Note that the macro
24222 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24223 the reason we use a separate variable `i'. */
24225 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24227 x_reached
= tail
->x
+ tail
->background_width
;
24231 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24232 the row, redraw some glyphs in front or following the glyph
24233 strings built above. */
24234 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24236 struct glyph_string
*h
, *t
;
24237 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24238 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24239 int check_mouse_face
= 0;
24242 /* If mouse highlighting is on, we may need to draw adjacent
24243 glyphs using mouse-face highlighting. */
24244 if (area
== TEXT_AREA
&& row
->mouse_face_p
24245 && hlinfo
->mouse_face_beg_row
>= 0
24246 && hlinfo
->mouse_face_end_row
>= 0)
24248 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24250 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24251 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24253 check_mouse_face
= 1;
24254 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24255 ? hlinfo
->mouse_face_beg_col
: 0;
24256 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24257 ? hlinfo
->mouse_face_end_col
24258 : row
->used
[TEXT_AREA
];
24262 /* Compute overhangs for all glyph strings. */
24263 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24264 for (s
= head
; s
; s
= s
->next
)
24265 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24267 /* Prepend glyph strings for glyphs in front of the first glyph
24268 string that are overwritten because of the first glyph
24269 string's left overhang. The background of all strings
24270 prepended must be drawn because the first glyph string
24272 i
= left_overwritten (head
);
24275 enum draw_glyphs_face overlap_hl
;
24277 /* If this row contains mouse highlighting, attempt to draw
24278 the overlapped glyphs with the correct highlight. This
24279 code fails if the overlap encompasses more than one glyph
24280 and mouse-highlight spans only some of these glyphs.
24281 However, making it work perfectly involves a lot more
24282 code, and I don't know if the pathological case occurs in
24283 practice, so we'll stick to this for now. --- cyd */
24284 if (check_mouse_face
24285 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24286 overlap_hl
= DRAW_MOUSE_FACE
;
24288 overlap_hl
= DRAW_NORMAL_TEXT
;
24291 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24292 overlap_hl
, dummy_x
, last_x
);
24294 compute_overhangs_and_x (t
, head
->x
, 1);
24295 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24299 /* Prepend glyph strings for glyphs in front of the first glyph
24300 string that overwrite that glyph string because of their
24301 right overhang. For these strings, only the foreground must
24302 be drawn, because it draws over the glyph string at `head'.
24303 The background must not be drawn because this would overwrite
24304 right overhangs of preceding glyphs for which no glyph
24306 i
= left_overwriting (head
);
24309 enum draw_glyphs_face overlap_hl
;
24311 if (check_mouse_face
24312 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24313 overlap_hl
= DRAW_MOUSE_FACE
;
24315 overlap_hl
= DRAW_NORMAL_TEXT
;
24318 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24319 overlap_hl
, dummy_x
, last_x
);
24320 for (s
= h
; s
; s
= s
->next
)
24321 s
->background_filled_p
= 1;
24322 compute_overhangs_and_x (t
, head
->x
, 1);
24323 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24326 /* Append glyphs strings for glyphs following the last glyph
24327 string tail that are overwritten by tail. The background of
24328 these strings has to be drawn because tail's foreground draws
24330 i
= right_overwritten (tail
);
24333 enum draw_glyphs_face overlap_hl
;
24335 if (check_mouse_face
24336 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24337 overlap_hl
= DRAW_MOUSE_FACE
;
24339 overlap_hl
= DRAW_NORMAL_TEXT
;
24341 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24342 overlap_hl
, x
, last_x
);
24343 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24344 we don't have `end = i;' here. */
24345 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24346 append_glyph_string_lists (&head
, &tail
, h
, t
);
24350 /* Append glyph strings for glyphs following the last glyph
24351 string tail that overwrite tail. The foreground of such
24352 glyphs has to be drawn because it writes into the background
24353 of tail. The background must not be drawn because it could
24354 paint over the foreground of following glyphs. */
24355 i
= right_overwriting (tail
);
24358 enum draw_glyphs_face overlap_hl
;
24359 if (check_mouse_face
24360 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24361 overlap_hl
= DRAW_MOUSE_FACE
;
24363 overlap_hl
= DRAW_NORMAL_TEXT
;
24366 i
++; /* We must include the Ith glyph. */
24367 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24368 overlap_hl
, x
, last_x
);
24369 for (s
= h
; s
; s
= s
->next
)
24370 s
->background_filled_p
= 1;
24371 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24372 append_glyph_string_lists (&head
, &tail
, h
, t
);
24374 if (clip_head
|| clip_tail
)
24375 for (s
= head
; s
; s
= s
->next
)
24377 s
->clip_head
= clip_head
;
24378 s
->clip_tail
= clip_tail
;
24382 /* Draw all strings. */
24383 for (s
= head
; s
; s
= s
->next
)
24384 FRAME_RIF (f
)->draw_glyph_string (s
);
24387 /* When focus a sole frame and move horizontally, this sets on_p to 0
24388 causing a failure to erase prev cursor position. */
24389 if (area
== TEXT_AREA
24390 && !row
->full_width_p
24391 /* When drawing overlapping rows, only the glyph strings'
24392 foreground is drawn, which doesn't erase a cursor
24396 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24397 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24398 : (tail
? tail
->x
+ tail
->background_width
: x
));
24402 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24403 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24407 /* Value is the x-position up to which drawn, relative to AREA of W.
24408 This doesn't include parts drawn because of overhangs. */
24409 if (row
->full_width_p
)
24410 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24412 x_reached
-= area_left
;
24414 RELEASE_HDC (hdc
, f
);
24419 /* Expand row matrix if too narrow. Don't expand if area
24422 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24424 if (!it->f->fonts_changed \
24425 && (it->glyph_row->glyphs[area] \
24426 < it->glyph_row->glyphs[area + 1])) \
24428 it->w->ncols_scale_factor++; \
24429 it->f->fonts_changed = 1; \
24433 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24434 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24437 append_glyph (struct it
*it
)
24439 struct glyph
*glyph
;
24440 enum glyph_row_area area
= it
->area
;
24442 eassert (it
->glyph_row
);
24443 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24445 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24446 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24448 /* If the glyph row is reversed, we need to prepend the glyph
24449 rather than append it. */
24450 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24454 /* Make room for the additional glyph. */
24455 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24457 glyph
= it
->glyph_row
->glyphs
[area
];
24459 glyph
->charpos
= CHARPOS (it
->position
);
24460 glyph
->object
= it
->object
;
24461 if (it
->pixel_width
> 0)
24463 glyph
->pixel_width
= it
->pixel_width
;
24464 glyph
->padding_p
= 0;
24468 /* Assure at least 1-pixel width. Otherwise, cursor can't
24469 be displayed correctly. */
24470 glyph
->pixel_width
= 1;
24471 glyph
->padding_p
= 1;
24473 glyph
->ascent
= it
->ascent
;
24474 glyph
->descent
= it
->descent
;
24475 glyph
->voffset
= it
->voffset
;
24476 glyph
->type
= CHAR_GLYPH
;
24477 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24478 glyph
->multibyte_p
= it
->multibyte_p
;
24479 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24481 /* In R2L rows, the left and the right box edges need to be
24482 drawn in reverse direction. */
24483 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24484 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24488 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24489 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24491 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24492 || it
->phys_descent
> it
->descent
);
24493 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24494 glyph
->face_id
= it
->face_id
;
24495 glyph
->u
.ch
= it
->char_to_display
;
24496 glyph
->slice
.img
= null_glyph_slice
;
24497 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24500 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24501 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24503 glyph
->bidi_type
= it
->bidi_it
.type
;
24507 glyph
->resolved_level
= 0;
24508 glyph
->bidi_type
= UNKNOWN_BT
;
24510 ++it
->glyph_row
->used
[area
];
24513 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24516 /* Store one glyph for the composition IT->cmp_it.id in
24517 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24521 append_composite_glyph (struct it
*it
)
24523 struct glyph
*glyph
;
24524 enum glyph_row_area area
= it
->area
;
24526 eassert (it
->glyph_row
);
24528 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24529 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24531 /* If the glyph row is reversed, we need to prepend the glyph
24532 rather than append it. */
24533 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24537 /* Make room for the new glyph. */
24538 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24540 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24542 glyph
->charpos
= it
->cmp_it
.charpos
;
24543 glyph
->object
= it
->object
;
24544 glyph
->pixel_width
= it
->pixel_width
;
24545 glyph
->ascent
= it
->ascent
;
24546 glyph
->descent
= it
->descent
;
24547 glyph
->voffset
= it
->voffset
;
24548 glyph
->type
= COMPOSITE_GLYPH
;
24549 if (it
->cmp_it
.ch
< 0)
24551 glyph
->u
.cmp
.automatic
= 0;
24552 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24553 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24557 glyph
->u
.cmp
.automatic
= 1;
24558 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24559 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24560 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24562 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24563 glyph
->multibyte_p
= it
->multibyte_p
;
24564 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24566 /* In R2L rows, the left and the right box edges need to be
24567 drawn in reverse direction. */
24568 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24569 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24573 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24574 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24576 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24577 || it
->phys_descent
> it
->descent
);
24578 glyph
->padding_p
= 0;
24579 glyph
->glyph_not_available_p
= 0;
24580 glyph
->face_id
= it
->face_id
;
24581 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24584 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24585 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24587 glyph
->bidi_type
= it
->bidi_it
.type
;
24589 ++it
->glyph_row
->used
[area
];
24592 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24596 /* Change IT->ascent and IT->height according to the setting of
24600 take_vertical_position_into_account (struct it
*it
)
24604 if (it
->voffset
< 0)
24605 /* Increase the ascent so that we can display the text higher
24607 it
->ascent
-= it
->voffset
;
24609 /* Increase the descent so that we can display the text lower
24611 it
->descent
+= it
->voffset
;
24616 /* Produce glyphs/get display metrics for the image IT is loaded with.
24617 See the description of struct display_iterator in dispextern.h for
24618 an overview of struct display_iterator. */
24621 produce_image_glyph (struct it
*it
)
24625 int glyph_ascent
, crop
;
24626 struct glyph_slice slice
;
24628 eassert (it
->what
== IT_IMAGE
);
24630 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24632 /* Make sure X resources of the face is loaded. */
24633 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24635 if (it
->image_id
< 0)
24637 /* Fringe bitmap. */
24638 it
->ascent
= it
->phys_ascent
= 0;
24639 it
->descent
= it
->phys_descent
= 0;
24640 it
->pixel_width
= 0;
24645 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24647 /* Make sure X resources of the image is loaded. */
24648 prepare_image_for_display (it
->f
, img
);
24650 slice
.x
= slice
.y
= 0;
24651 slice
.width
= img
->width
;
24652 slice
.height
= img
->height
;
24654 if (INTEGERP (it
->slice
.x
))
24655 slice
.x
= XINT (it
->slice
.x
);
24656 else if (FLOATP (it
->slice
.x
))
24657 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24659 if (INTEGERP (it
->slice
.y
))
24660 slice
.y
= XINT (it
->slice
.y
);
24661 else if (FLOATP (it
->slice
.y
))
24662 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24664 if (INTEGERP (it
->slice
.width
))
24665 slice
.width
= XINT (it
->slice
.width
);
24666 else if (FLOATP (it
->slice
.width
))
24667 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24669 if (INTEGERP (it
->slice
.height
))
24670 slice
.height
= XINT (it
->slice
.height
);
24671 else if (FLOATP (it
->slice
.height
))
24672 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24674 if (slice
.x
>= img
->width
)
24675 slice
.x
= img
->width
;
24676 if (slice
.y
>= img
->height
)
24677 slice
.y
= img
->height
;
24678 if (slice
.x
+ slice
.width
>= img
->width
)
24679 slice
.width
= img
->width
- slice
.x
;
24680 if (slice
.y
+ slice
.height
> img
->height
)
24681 slice
.height
= img
->height
- slice
.y
;
24683 if (slice
.width
== 0 || slice
.height
== 0)
24686 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24688 it
->descent
= slice
.height
- glyph_ascent
;
24690 it
->descent
+= img
->vmargin
;
24691 if (slice
.y
+ slice
.height
== img
->height
)
24692 it
->descent
+= img
->vmargin
;
24693 it
->phys_descent
= it
->descent
;
24695 it
->pixel_width
= slice
.width
;
24697 it
->pixel_width
+= img
->hmargin
;
24698 if (slice
.x
+ slice
.width
== img
->width
)
24699 it
->pixel_width
+= img
->hmargin
;
24701 /* It's quite possible for images to have an ascent greater than
24702 their height, so don't get confused in that case. */
24703 if (it
->descent
< 0)
24708 if (face
->box
!= FACE_NO_BOX
)
24710 if (face
->box_line_width
> 0)
24713 it
->ascent
+= face
->box_line_width
;
24714 if (slice
.y
+ slice
.height
== img
->height
)
24715 it
->descent
+= face
->box_line_width
;
24718 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24719 it
->pixel_width
+= eabs (face
->box_line_width
);
24720 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24721 it
->pixel_width
+= eabs (face
->box_line_width
);
24724 take_vertical_position_into_account (it
);
24726 /* Automatically crop wide image glyphs at right edge so we can
24727 draw the cursor on same display row. */
24728 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24729 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24731 it
->pixel_width
-= crop
;
24732 slice
.width
-= crop
;
24737 struct glyph
*glyph
;
24738 enum glyph_row_area area
= it
->area
;
24740 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24741 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24743 glyph
->charpos
= CHARPOS (it
->position
);
24744 glyph
->object
= it
->object
;
24745 glyph
->pixel_width
= it
->pixel_width
;
24746 glyph
->ascent
= glyph_ascent
;
24747 glyph
->descent
= it
->descent
;
24748 glyph
->voffset
= it
->voffset
;
24749 glyph
->type
= IMAGE_GLYPH
;
24750 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24751 glyph
->multibyte_p
= it
->multibyte_p
;
24752 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24754 /* In R2L rows, the left and the right box edges need to be
24755 drawn in reverse direction. */
24756 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24757 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24761 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24762 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24764 glyph
->overlaps_vertically_p
= 0;
24765 glyph
->padding_p
= 0;
24766 glyph
->glyph_not_available_p
= 0;
24767 glyph
->face_id
= it
->face_id
;
24768 glyph
->u
.img_id
= img
->id
;
24769 glyph
->slice
.img
= slice
;
24770 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24773 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24774 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24776 glyph
->bidi_type
= it
->bidi_it
.type
;
24778 ++it
->glyph_row
->used
[area
];
24781 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24786 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24787 of the glyph, WIDTH and HEIGHT are the width and height of the
24788 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24791 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24792 int width
, int height
, int ascent
)
24794 struct glyph
*glyph
;
24795 enum glyph_row_area area
= it
->area
;
24797 eassert (ascent
>= 0 && ascent
<= height
);
24799 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24800 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24802 /* If the glyph row is reversed, we need to prepend the glyph
24803 rather than append it. */
24804 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24808 /* Make room for the additional glyph. */
24809 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24811 glyph
= it
->glyph_row
->glyphs
[area
];
24813 glyph
->charpos
= CHARPOS (it
->position
);
24814 glyph
->object
= object
;
24815 glyph
->pixel_width
= width
;
24816 glyph
->ascent
= ascent
;
24817 glyph
->descent
= height
- ascent
;
24818 glyph
->voffset
= it
->voffset
;
24819 glyph
->type
= STRETCH_GLYPH
;
24820 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24821 glyph
->multibyte_p
= it
->multibyte_p
;
24822 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24824 /* In R2L rows, the left and the right box edges need to be
24825 drawn in reverse direction. */
24826 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24827 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24831 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24832 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24834 glyph
->overlaps_vertically_p
= 0;
24835 glyph
->padding_p
= 0;
24836 glyph
->glyph_not_available_p
= 0;
24837 glyph
->face_id
= it
->face_id
;
24838 glyph
->u
.stretch
.ascent
= ascent
;
24839 glyph
->u
.stretch
.height
= height
;
24840 glyph
->slice
.img
= null_glyph_slice
;
24841 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24844 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24845 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24847 glyph
->bidi_type
= it
->bidi_it
.type
;
24851 glyph
->resolved_level
= 0;
24852 glyph
->bidi_type
= UNKNOWN_BT
;
24854 ++it
->glyph_row
->used
[area
];
24857 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24860 #endif /* HAVE_WINDOW_SYSTEM */
24862 /* Produce a stretch glyph for iterator IT. IT->object is the value
24863 of the glyph property displayed. The value must be a list
24864 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24867 1. `:width WIDTH' specifies that the space should be WIDTH *
24868 canonical char width wide. WIDTH may be an integer or floating
24871 2. `:relative-width FACTOR' specifies that the width of the stretch
24872 should be computed from the width of the first character having the
24873 `glyph' property, and should be FACTOR times that width.
24875 3. `:align-to HPOS' specifies that the space should be wide enough
24876 to reach HPOS, a value in canonical character units.
24878 Exactly one of the above pairs must be present.
24880 4. `:height HEIGHT' specifies that the height of the stretch produced
24881 should be HEIGHT, measured in canonical character units.
24883 5. `:relative-height FACTOR' specifies that the height of the
24884 stretch should be FACTOR times the height of the characters having
24885 the glyph property.
24887 Either none or exactly one of 4 or 5 must be present.
24889 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24890 of the stretch should be used for the ascent of the stretch.
24891 ASCENT must be in the range 0 <= ASCENT <= 100. */
24894 produce_stretch_glyph (struct it
*it
)
24896 /* (space :width WIDTH :height HEIGHT ...) */
24897 Lisp_Object prop
, plist
;
24898 int width
= 0, height
= 0, align_to
= -1;
24899 int zero_width_ok_p
= 0;
24901 struct font
*font
= NULL
;
24903 #ifdef HAVE_WINDOW_SYSTEM
24905 int zero_height_ok_p
= 0;
24907 if (FRAME_WINDOW_P (it
->f
))
24909 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24910 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24911 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24915 /* List should start with `space'. */
24916 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24917 plist
= XCDR (it
->object
);
24919 /* Compute the width of the stretch. */
24920 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24921 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24923 /* Absolute width `:width WIDTH' specified and valid. */
24924 zero_width_ok_p
= 1;
24927 #ifdef HAVE_WINDOW_SYSTEM
24928 else if (FRAME_WINDOW_P (it
->f
)
24929 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24931 /* Relative width `:relative-width FACTOR' specified and valid.
24932 Compute the width of the characters having the `glyph'
24935 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24938 if (it
->multibyte_p
)
24939 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24942 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24943 if (! ASCII_CHAR_P (it2
.c
))
24944 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24947 it2
.glyph_row
= NULL
;
24948 it2
.what
= IT_CHARACTER
;
24949 x_produce_glyphs (&it2
);
24950 width
= NUMVAL (prop
) * it2
.pixel_width
;
24952 #endif /* HAVE_WINDOW_SYSTEM */
24953 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24954 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24956 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24957 align_to
= (align_to
< 0
24959 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24960 else if (align_to
< 0)
24961 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24962 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24963 zero_width_ok_p
= 1;
24966 /* Nothing specified -> width defaults to canonical char width. */
24967 width
= FRAME_COLUMN_WIDTH (it
->f
);
24969 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24972 #ifdef HAVE_WINDOW_SYSTEM
24973 /* Compute height. */
24974 if (FRAME_WINDOW_P (it
->f
))
24976 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24977 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24980 zero_height_ok_p
= 1;
24982 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24984 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24986 height
= FONT_HEIGHT (font
);
24988 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24991 /* Compute percentage of height used for ascent. If
24992 `:ascent ASCENT' is present and valid, use that. Otherwise,
24993 derive the ascent from the font in use. */
24994 if (prop
= Fplist_get (plist
, QCascent
),
24995 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24996 ascent
= height
* NUMVAL (prop
) / 100.0;
24997 else if (!NILP (prop
)
24998 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24999 ascent
= min (max (0, (int)tem
), height
);
25001 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
25004 #endif /* HAVE_WINDOW_SYSTEM */
25007 if (width
> 0 && it
->line_wrap
!= TRUNCATE
25008 && it
->current_x
+ width
> it
->last_visible_x
)
25010 width
= it
->last_visible_x
- it
->current_x
;
25011 #ifdef HAVE_WINDOW_SYSTEM
25012 /* Subtract one more pixel from the stretch width, but only on
25013 GUI frames, since on a TTY each glyph is one "pixel" wide. */
25014 width
-= FRAME_WINDOW_P (it
->f
);
25018 if (width
> 0 && height
> 0 && it
->glyph_row
)
25020 Lisp_Object o_object
= it
->object
;
25021 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
25024 if (!STRINGP (object
))
25025 object
= it
->w
->contents
;
25026 #ifdef HAVE_WINDOW_SYSTEM
25027 if (FRAME_WINDOW_P (it
->f
))
25028 append_stretch_glyph (it
, object
, width
, height
, ascent
);
25032 it
->object
= object
;
25033 it
->char_to_display
= ' ';
25034 it
->pixel_width
= it
->len
= 1;
25036 tty_append_glyph (it
);
25037 it
->object
= o_object
;
25041 it
->pixel_width
= width
;
25042 #ifdef HAVE_WINDOW_SYSTEM
25043 if (FRAME_WINDOW_P (it
->f
))
25045 it
->ascent
= it
->phys_ascent
= ascent
;
25046 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
25047 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
25048 take_vertical_position_into_account (it
);
25052 it
->nglyphs
= width
;
25055 /* Get information about special display element WHAT in an
25056 environment described by IT. WHAT is one of IT_TRUNCATION or
25057 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
25058 non-null glyph_row member. This function ensures that fields like
25059 face_id, c, len of IT are left untouched. */
25062 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
25069 temp_it
.object
= make_number (0);
25070 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
25072 if (what
== IT_CONTINUATION
)
25074 /* Continuation glyph. For R2L lines, we mirror it by hand. */
25075 if (it
->bidi_it
.paragraph_dir
== R2L
)
25076 SET_GLYPH_FROM_CHAR (glyph
, '/');
25078 SET_GLYPH_FROM_CHAR (glyph
, '\\');
25080 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25082 /* FIXME: Should we mirror GC for R2L lines? */
25083 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25084 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25087 else if (what
== IT_TRUNCATION
)
25089 /* Truncation glyph. */
25090 SET_GLYPH_FROM_CHAR (glyph
, '$');
25092 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25094 /* FIXME: Should we mirror GC for R2L lines? */
25095 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25096 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25102 #ifdef HAVE_WINDOW_SYSTEM
25103 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25104 is turned off, we precede the truncation/continuation glyphs by a
25105 stretch glyph whose width is computed such that these special
25106 glyphs are aligned at the window margin, even when very different
25107 fonts are used in different glyph rows. */
25108 if (FRAME_WINDOW_P (temp_it
.f
)
25109 /* init_iterator calls this with it->glyph_row == NULL, and it
25110 wants only the pixel width of the truncation/continuation
25112 && temp_it
.glyph_row
25113 /* insert_left_trunc_glyphs calls us at the beginning of the
25114 row, and it has its own calculation of the stretch glyph
25116 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25117 && (temp_it
.glyph_row
->reversed_p
25118 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25119 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25121 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
25123 if (stretch_width
> 0)
25125 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
25126 struct font
*font
=
25127 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
25128 int stretch_ascent
=
25129 (((temp_it
.ascent
+ temp_it
.descent
)
25130 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
25132 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25133 temp_it
.ascent
+ temp_it
.descent
,
25140 temp_it
.what
= IT_CHARACTER
;
25142 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25143 temp_it
.face_id
= GLYPH_FACE (glyph
);
25144 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25146 PRODUCE_GLYPHS (&temp_it
);
25147 it
->pixel_width
= temp_it
.pixel_width
;
25148 it
->nglyphs
= temp_it
.pixel_width
;
25151 #ifdef HAVE_WINDOW_SYSTEM
25153 /* Calculate line-height and line-spacing properties.
25154 An integer value specifies explicit pixel value.
25155 A float value specifies relative value to current face height.
25156 A cons (float . face-name) specifies relative value to
25157 height of specified face font.
25159 Returns height in pixels, or nil. */
25163 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25164 int boff
, int override
)
25166 Lisp_Object face_name
= Qnil
;
25167 int ascent
, descent
, height
;
25169 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25174 face_name
= XCAR (val
);
25176 if (!NUMBERP (val
))
25177 val
= make_number (1);
25178 if (NILP (face_name
))
25180 height
= it
->ascent
+ it
->descent
;
25185 if (NILP (face_name
))
25187 font
= FRAME_FONT (it
->f
);
25188 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25190 else if (EQ (face_name
, Qt
))
25199 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25201 return make_number (-1);
25203 face
= FACE_FROM_ID (it
->f
, face_id
);
25206 return make_number (-1);
25207 boff
= font
->baseline_offset
;
25208 if (font
->vertical_centering
)
25209 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25212 ascent
= FONT_BASE (font
) + boff
;
25213 descent
= FONT_DESCENT (font
) - boff
;
25217 it
->override_ascent
= ascent
;
25218 it
->override_descent
= descent
;
25219 it
->override_boff
= boff
;
25222 height
= ascent
+ descent
;
25226 height
= (int)(XFLOAT_DATA (val
) * height
);
25227 else if (INTEGERP (val
))
25228 height
*= XINT (val
);
25230 return make_number (height
);
25234 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25235 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25236 and only if this is for a character for which no font was found.
25238 If the display method (it->glyphless_method) is
25239 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25240 length of the acronym or the hexadecimal string, UPPER_XOFF and
25241 UPPER_YOFF are pixel offsets for the upper part of the string,
25242 LOWER_XOFF and LOWER_YOFF are for the lower part.
25244 For the other display methods, LEN through LOWER_YOFF are zero. */
25247 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25248 short upper_xoff
, short upper_yoff
,
25249 short lower_xoff
, short lower_yoff
)
25251 struct glyph
*glyph
;
25252 enum glyph_row_area area
= it
->area
;
25254 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25255 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25257 /* If the glyph row is reversed, we need to prepend the glyph
25258 rather than append it. */
25259 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25263 /* Make room for the additional glyph. */
25264 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25266 glyph
= it
->glyph_row
->glyphs
[area
];
25268 glyph
->charpos
= CHARPOS (it
->position
);
25269 glyph
->object
= it
->object
;
25270 glyph
->pixel_width
= it
->pixel_width
;
25271 glyph
->ascent
= it
->ascent
;
25272 glyph
->descent
= it
->descent
;
25273 glyph
->voffset
= it
->voffset
;
25274 glyph
->type
= GLYPHLESS_GLYPH
;
25275 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25276 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25277 glyph
->u
.glyphless
.len
= len
;
25278 glyph
->u
.glyphless
.ch
= it
->c
;
25279 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25280 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25281 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25282 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25283 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25284 glyph
->multibyte_p
= it
->multibyte_p
;
25285 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25287 /* In R2L rows, the left and the right box edges need to be
25288 drawn in reverse direction. */
25289 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25290 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25294 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25295 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25297 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25298 || it
->phys_descent
> it
->descent
);
25299 glyph
->padding_p
= 0;
25300 glyph
->glyph_not_available_p
= 0;
25301 glyph
->face_id
= face_id
;
25302 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25305 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25306 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25308 glyph
->bidi_type
= it
->bidi_it
.type
;
25310 ++it
->glyph_row
->used
[area
];
25313 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25317 /* Produce a glyph for a glyphless character for iterator IT.
25318 IT->glyphless_method specifies which method to use for displaying
25319 the character. See the description of enum
25320 glyphless_display_method in dispextern.h for the detail.
25322 FOR_NO_FONT is nonzero if and only if this is for a character for
25323 which no font was found. ACRONYM, if non-nil, is an acronym string
25324 for the character. */
25327 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25332 int base_width
, base_height
, width
, height
;
25333 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25336 /* Get the metrics of the base font. We always refer to the current
25338 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25339 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25340 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25341 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25342 base_height
= it
->ascent
+ it
->descent
;
25343 base_width
= font
->average_width
;
25345 face_id
= merge_glyphless_glyph_face (it
);
25347 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25349 it
->pixel_width
= THIN_SPACE_WIDTH
;
25351 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25353 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25355 width
= CHAR_WIDTH (it
->c
);
25358 else if (width
> 4)
25360 it
->pixel_width
= base_width
* width
;
25362 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25368 unsigned int code
[6];
25370 int ascent
, descent
;
25371 struct font_metrics metrics_upper
, metrics_lower
;
25373 face
= FACE_FROM_ID (it
->f
, face_id
);
25374 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25375 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25377 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25379 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25380 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25381 if (CONSP (acronym
))
25382 acronym
= XCAR (acronym
);
25383 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25387 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25388 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25391 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25392 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25393 upper_len
= (len
+ 1) / 2;
25394 font
->driver
->text_extents (font
, code
, upper_len
,
25396 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25401 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25402 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25403 upper_xoff
= upper_yoff
= 2; /* the typical case */
25404 if (base_width
>= width
)
25406 /* Align the upper to the left, the lower to the right. */
25407 it
->pixel_width
= base_width
;
25408 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25412 /* Center the shorter one. */
25413 it
->pixel_width
= width
;
25414 if (metrics_upper
.width
>= metrics_lower
.width
)
25415 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25418 /* FIXME: This code doesn't look right. It formerly was
25419 missing the "lower_xoff = 0;", which couldn't have
25420 been right since it left lower_xoff uninitialized. */
25422 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25426 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25427 top, bottom, and between upper and lower strings. */
25428 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25429 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25430 /* Center vertically.
25431 H:base_height, D:base_descent
25432 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25434 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25435 descent = D - H/2 + h/2;
25436 lower_yoff = descent - 2 - ld;
25437 upper_yoff = lower_yoff - la - 1 - ud; */
25438 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25439 descent
= it
->descent
- (base_height
- height
) / 2;
25440 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25441 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25442 - metrics_upper
.descent
);
25443 /* Don't make the height shorter than the base height. */
25444 if (height
> base_height
)
25446 it
->ascent
= ascent
;
25447 it
->descent
= descent
;
25451 it
->phys_ascent
= it
->ascent
;
25452 it
->phys_descent
= it
->descent
;
25454 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25455 upper_xoff
, upper_yoff
,
25456 lower_xoff
, lower_yoff
);
25458 take_vertical_position_into_account (it
);
25463 Produce glyphs/get display metrics for the display element IT is
25464 loaded with. See the description of struct it in dispextern.h
25465 for an overview of struct it. */
25468 x_produce_glyphs (struct it
*it
)
25470 int extra_line_spacing
= it
->extra_line_spacing
;
25472 it
->glyph_not_available_p
= 0;
25474 if (it
->what
== IT_CHARACTER
)
25477 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25478 struct font
*font
= face
->font
;
25479 struct font_metrics
*pcm
= NULL
;
25480 int boff
; /* Baseline offset. */
25484 /* When no suitable font is found, display this character by
25485 the method specified in the first extra slot of
25486 Vglyphless_char_display. */
25487 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25489 eassert (it
->what
== IT_GLYPHLESS
);
25490 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25494 boff
= font
->baseline_offset
;
25495 if (font
->vertical_centering
)
25496 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25498 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25504 if (it
->override_ascent
>= 0)
25506 it
->ascent
= it
->override_ascent
;
25507 it
->descent
= it
->override_descent
;
25508 boff
= it
->override_boff
;
25512 it
->ascent
= FONT_BASE (font
) + boff
;
25513 it
->descent
= FONT_DESCENT (font
) - boff
;
25516 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25518 pcm
= get_per_char_metric (font
, &char2b
);
25519 if (pcm
->width
== 0
25520 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25526 it
->phys_ascent
= pcm
->ascent
+ boff
;
25527 it
->phys_descent
= pcm
->descent
- boff
;
25528 it
->pixel_width
= pcm
->width
;
25532 it
->glyph_not_available_p
= 1;
25533 it
->phys_ascent
= it
->ascent
;
25534 it
->phys_descent
= it
->descent
;
25535 it
->pixel_width
= font
->space_width
;
25538 if (it
->constrain_row_ascent_descent_p
)
25540 if (it
->descent
> it
->max_descent
)
25542 it
->ascent
+= it
->descent
- it
->max_descent
;
25543 it
->descent
= it
->max_descent
;
25545 if (it
->ascent
> it
->max_ascent
)
25547 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25548 it
->ascent
= it
->max_ascent
;
25550 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25551 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25552 extra_line_spacing
= 0;
25555 /* If this is a space inside a region of text with
25556 `space-width' property, change its width. */
25557 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25559 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25561 /* If face has a box, add the box thickness to the character
25562 height. If character has a box line to the left and/or
25563 right, add the box line width to the character's width. */
25564 if (face
->box
!= FACE_NO_BOX
)
25566 int thick
= face
->box_line_width
;
25570 it
->ascent
+= thick
;
25571 it
->descent
+= thick
;
25576 if (it
->start_of_box_run_p
)
25577 it
->pixel_width
+= thick
;
25578 if (it
->end_of_box_run_p
)
25579 it
->pixel_width
+= thick
;
25582 /* If face has an overline, add the height of the overline
25583 (1 pixel) and a 1 pixel margin to the character height. */
25584 if (face
->overline_p
)
25585 it
->ascent
+= overline_margin
;
25587 if (it
->constrain_row_ascent_descent_p
)
25589 if (it
->ascent
> it
->max_ascent
)
25590 it
->ascent
= it
->max_ascent
;
25591 if (it
->descent
> it
->max_descent
)
25592 it
->descent
= it
->max_descent
;
25595 take_vertical_position_into_account (it
);
25597 /* If we have to actually produce glyphs, do it. */
25602 /* Translate a space with a `space-width' property
25603 into a stretch glyph. */
25604 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25605 / FONT_HEIGHT (font
));
25606 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25607 it
->ascent
+ it
->descent
, ascent
);
25612 /* If characters with lbearing or rbearing are displayed
25613 in this line, record that fact in a flag of the
25614 glyph row. This is used to optimize X output code. */
25615 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25616 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25618 if (! stretched_p
&& it
->pixel_width
== 0)
25619 /* We assure that all visible glyphs have at least 1-pixel
25621 it
->pixel_width
= 1;
25623 else if (it
->char_to_display
== '\n')
25625 /* A newline has no width, but we need the height of the
25626 line. But if previous part of the line sets a height,
25627 don't increase that height. */
25629 Lisp_Object height
;
25630 Lisp_Object total_height
= Qnil
;
25632 it
->override_ascent
= -1;
25633 it
->pixel_width
= 0;
25636 height
= get_it_property (it
, Qline_height
);
25637 /* Split (line-height total-height) list. */
25639 && CONSP (XCDR (height
))
25640 && NILP (XCDR (XCDR (height
))))
25642 total_height
= XCAR (XCDR (height
));
25643 height
= XCAR (height
);
25645 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25647 if (it
->override_ascent
>= 0)
25649 it
->ascent
= it
->override_ascent
;
25650 it
->descent
= it
->override_descent
;
25651 boff
= it
->override_boff
;
25655 it
->ascent
= FONT_BASE (font
) + boff
;
25656 it
->descent
= FONT_DESCENT (font
) - boff
;
25659 if (EQ (height
, Qt
))
25661 if (it
->descent
> it
->max_descent
)
25663 it
->ascent
+= it
->descent
- it
->max_descent
;
25664 it
->descent
= it
->max_descent
;
25666 if (it
->ascent
> it
->max_ascent
)
25668 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25669 it
->ascent
= it
->max_ascent
;
25671 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25672 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25673 it
->constrain_row_ascent_descent_p
= 1;
25674 extra_line_spacing
= 0;
25678 Lisp_Object spacing
;
25680 it
->phys_ascent
= it
->ascent
;
25681 it
->phys_descent
= it
->descent
;
25683 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25684 && face
->box
!= FACE_NO_BOX
25685 && face
->box_line_width
> 0)
25687 it
->ascent
+= face
->box_line_width
;
25688 it
->descent
+= face
->box_line_width
;
25691 && XINT (height
) > it
->ascent
+ it
->descent
)
25692 it
->ascent
= XINT (height
) - it
->descent
;
25694 if (!NILP (total_height
))
25695 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25698 spacing
= get_it_property (it
, Qline_spacing
);
25699 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25701 if (INTEGERP (spacing
))
25703 extra_line_spacing
= XINT (spacing
);
25704 if (!NILP (total_height
))
25705 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25709 else /* i.e. (it->char_to_display == '\t') */
25711 if (font
->space_width
> 0)
25713 int tab_width
= it
->tab_width
* font
->space_width
;
25714 int x
= it
->current_x
+ it
->continuation_lines_width
;
25715 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25717 /* If the distance from the current position to the next tab
25718 stop is less than a space character width, use the
25719 tab stop after that. */
25720 if (next_tab_x
- x
< font
->space_width
)
25721 next_tab_x
+= tab_width
;
25723 it
->pixel_width
= next_tab_x
- x
;
25725 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25726 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25730 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25731 it
->ascent
+ it
->descent
, it
->ascent
);
25736 it
->pixel_width
= 0;
25741 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25743 /* A static composition.
25745 Note: A composition is represented as one glyph in the
25746 glyph matrix. There are no padding glyphs.
25748 Important note: pixel_width, ascent, and descent are the
25749 values of what is drawn by draw_glyphs (i.e. the values of
25750 the overall glyphs composed). */
25751 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25752 int boff
; /* baseline offset */
25753 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25754 int glyph_len
= cmp
->glyph_len
;
25755 struct font
*font
= face
->font
;
25759 /* If we have not yet calculated pixel size data of glyphs of
25760 the composition for the current face font, calculate them
25761 now. Theoretically, we have to check all fonts for the
25762 glyphs, but that requires much time and memory space. So,
25763 here we check only the font of the first glyph. This may
25764 lead to incorrect display, but it's very rare, and C-l
25765 (recenter-top-bottom) can correct the display anyway. */
25766 if (! cmp
->font
|| cmp
->font
!= font
)
25768 /* Ascent and descent of the font of the first character
25769 of this composition (adjusted by baseline offset).
25770 Ascent and descent of overall glyphs should not be less
25771 than these, respectively. */
25772 int font_ascent
, font_descent
, font_height
;
25773 /* Bounding box of the overall glyphs. */
25774 int leftmost
, rightmost
, lowest
, highest
;
25775 int lbearing
, rbearing
;
25776 int i
, width
, ascent
, descent
;
25777 int left_padded
= 0, right_padded
= 0;
25778 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25780 struct font_metrics
*pcm
;
25781 int font_not_found_p
;
25784 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25785 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25787 if (glyph_len
< cmp
->glyph_len
)
25789 for (i
= 0; i
< glyph_len
; i
++)
25791 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25793 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25798 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25799 : IT_CHARPOS (*it
));
25800 /* If no suitable font is found, use the default font. */
25801 font_not_found_p
= font
== NULL
;
25802 if (font_not_found_p
)
25804 face
= face
->ascii_face
;
25807 boff
= font
->baseline_offset
;
25808 if (font
->vertical_centering
)
25809 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25810 font_ascent
= FONT_BASE (font
) + boff
;
25811 font_descent
= FONT_DESCENT (font
) - boff
;
25812 font_height
= FONT_HEIGHT (font
);
25817 if (! font_not_found_p
)
25819 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25821 pcm
= get_per_char_metric (font
, &char2b
);
25824 /* Initialize the bounding box. */
25827 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25828 ascent
= pcm
->ascent
;
25829 descent
= pcm
->descent
;
25830 lbearing
= pcm
->lbearing
;
25831 rbearing
= pcm
->rbearing
;
25835 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25836 ascent
= FONT_BASE (font
);
25837 descent
= FONT_DESCENT (font
);
25844 lowest
= - descent
+ boff
;
25845 highest
= ascent
+ boff
;
25847 if (! font_not_found_p
25848 && font
->default_ascent
25849 && CHAR_TABLE_P (Vuse_default_ascent
)
25850 && !NILP (Faref (Vuse_default_ascent
,
25851 make_number (it
->char_to_display
))))
25852 highest
= font
->default_ascent
+ boff
;
25854 /* Draw the first glyph at the normal position. It may be
25855 shifted to right later if some other glyphs are drawn
25857 cmp
->offsets
[i
* 2] = 0;
25858 cmp
->offsets
[i
* 2 + 1] = boff
;
25859 cmp
->lbearing
= lbearing
;
25860 cmp
->rbearing
= rbearing
;
25862 /* Set cmp->offsets for the remaining glyphs. */
25863 for (i
++; i
< glyph_len
; i
++)
25865 int left
, right
, btm
, top
;
25866 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25868 struct face
*this_face
;
25872 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25873 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25874 font
= this_face
->font
;
25880 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25882 pcm
= get_per_char_metric (font
, &char2b
);
25885 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25888 width
= pcm
->width
;
25889 ascent
= pcm
->ascent
;
25890 descent
= pcm
->descent
;
25891 lbearing
= pcm
->lbearing
;
25892 rbearing
= pcm
->rbearing
;
25893 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25895 /* Relative composition with or without
25896 alternate chars. */
25897 left
= (leftmost
+ rightmost
- width
) / 2;
25898 btm
= - descent
+ boff
;
25899 if (font
->relative_compose
25900 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25901 || NILP (Faref (Vignore_relative_composition
,
25902 make_number (ch
)))))
25905 if (- descent
>= font
->relative_compose
)
25906 /* One extra pixel between two glyphs. */
25908 else if (ascent
<= 0)
25909 /* One extra pixel between two glyphs. */
25910 btm
= lowest
- 1 - ascent
- descent
;
25915 /* A composition rule is specified by an integer
25916 value that encodes global and new reference
25917 points (GREF and NREF). GREF and NREF are
25918 specified by numbers as below:
25920 0---1---2 -- ascent
25924 9--10--11 -- center
25926 ---3---4---5--- baseline
25928 6---7---8 -- descent
25930 int rule
= COMPOSITION_RULE (cmp
, i
);
25931 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25933 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25934 grefx
= gref
% 3, nrefx
= nref
% 3;
25935 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25937 xoff
= font_height
* (xoff
- 128) / 256;
25939 yoff
= font_height
* (yoff
- 128) / 256;
25942 + grefx
* (rightmost
- leftmost
) / 2
25943 - nrefx
* width
/ 2
25946 btm
= ((grefy
== 0 ? highest
25948 : grefy
== 2 ? lowest
25949 : (highest
+ lowest
) / 2)
25950 - (nrefy
== 0 ? ascent
+ descent
25951 : nrefy
== 1 ? descent
- boff
25953 : (ascent
+ descent
) / 2)
25957 cmp
->offsets
[i
* 2] = left
;
25958 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25960 /* Update the bounding box of the overall glyphs. */
25963 right
= left
+ width
;
25964 if (left
< leftmost
)
25966 if (right
> rightmost
)
25969 top
= btm
+ descent
+ ascent
;
25975 if (cmp
->lbearing
> left
+ lbearing
)
25976 cmp
->lbearing
= left
+ lbearing
;
25977 if (cmp
->rbearing
< left
+ rbearing
)
25978 cmp
->rbearing
= left
+ rbearing
;
25982 /* If there are glyphs whose x-offsets are negative,
25983 shift all glyphs to the right and make all x-offsets
25987 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25988 cmp
->offsets
[i
* 2] -= leftmost
;
25989 rightmost
-= leftmost
;
25990 cmp
->lbearing
-= leftmost
;
25991 cmp
->rbearing
-= leftmost
;
25994 if (left_padded
&& cmp
->lbearing
< 0)
25996 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25997 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25998 rightmost
-= cmp
->lbearing
;
25999 cmp
->rbearing
-= cmp
->lbearing
;
26002 if (right_padded
&& rightmost
< cmp
->rbearing
)
26004 rightmost
= cmp
->rbearing
;
26007 cmp
->pixel_width
= rightmost
;
26008 cmp
->ascent
= highest
;
26009 cmp
->descent
= - lowest
;
26010 if (cmp
->ascent
< font_ascent
)
26011 cmp
->ascent
= font_ascent
;
26012 if (cmp
->descent
< font_descent
)
26013 cmp
->descent
= font_descent
;
26017 && (cmp
->lbearing
< 0
26018 || cmp
->rbearing
> cmp
->pixel_width
))
26019 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26021 it
->pixel_width
= cmp
->pixel_width
;
26022 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
26023 it
->descent
= it
->phys_descent
= cmp
->descent
;
26024 if (face
->box
!= FACE_NO_BOX
)
26026 int thick
= face
->box_line_width
;
26030 it
->ascent
+= thick
;
26031 it
->descent
+= thick
;
26036 if (it
->start_of_box_run_p
)
26037 it
->pixel_width
+= thick
;
26038 if (it
->end_of_box_run_p
)
26039 it
->pixel_width
+= thick
;
26042 /* If face has an overline, add the height of the overline
26043 (1 pixel) and a 1 pixel margin to the character height. */
26044 if (face
->overline_p
)
26045 it
->ascent
+= overline_margin
;
26047 take_vertical_position_into_account (it
);
26048 if (it
->ascent
< 0)
26050 if (it
->descent
< 0)
26053 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
26054 append_composite_glyph (it
);
26056 else if (it
->what
== IT_COMPOSITION
)
26058 /* A dynamic (automatic) composition. */
26059 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26060 Lisp_Object gstring
;
26061 struct font_metrics metrics
;
26065 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
26067 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
26070 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
26071 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26072 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
26073 it
->descent
= it
->phys_descent
= metrics
.descent
;
26074 if (face
->box
!= FACE_NO_BOX
)
26076 int thick
= face
->box_line_width
;
26080 it
->ascent
+= thick
;
26081 it
->descent
+= thick
;
26086 if (it
->start_of_box_run_p
)
26087 it
->pixel_width
+= thick
;
26088 if (it
->end_of_box_run_p
)
26089 it
->pixel_width
+= thick
;
26091 /* If face has an overline, add the height of the overline
26092 (1 pixel) and a 1 pixel margin to the character height. */
26093 if (face
->overline_p
)
26094 it
->ascent
+= overline_margin
;
26095 take_vertical_position_into_account (it
);
26096 if (it
->ascent
< 0)
26098 if (it
->descent
< 0)
26102 append_composite_glyph (it
);
26104 else if (it
->what
== IT_GLYPHLESS
)
26105 produce_glyphless_glyph (it
, 0, Qnil
);
26106 else if (it
->what
== IT_IMAGE
)
26107 produce_image_glyph (it
);
26108 else if (it
->what
== IT_STRETCH
)
26109 produce_stretch_glyph (it
);
26112 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26113 because this isn't true for images with `:ascent 100'. */
26114 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26115 if (it
->area
== TEXT_AREA
)
26116 it
->current_x
+= it
->pixel_width
;
26118 if (extra_line_spacing
> 0)
26120 it
->descent
+= extra_line_spacing
;
26121 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26122 it
->max_extra_line_spacing
= extra_line_spacing
;
26125 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26126 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26127 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26128 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26132 Output LEN glyphs starting at START at the nominal cursor position.
26133 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26134 being updated, and UPDATED_AREA is the area of that row being updated. */
26137 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26138 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26140 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26142 eassert (updated_row
);
26143 /* When the window is hscrolled, cursor hpos can legitimately be out
26144 of bounds, but we draw the cursor at the corresponding window
26145 margin in that case. */
26146 if (!updated_row
->reversed_p
&& chpos
< 0)
26148 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26149 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26153 /* Write glyphs. */
26155 hpos
= start
- updated_row
->glyphs
[updated_area
];
26156 x
= draw_glyphs (w
, w
->output_cursor
.x
,
26157 updated_row
, updated_area
,
26159 DRAW_NORMAL_TEXT
, 0);
26161 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26162 if (updated_area
== TEXT_AREA
26163 && w
->phys_cursor_on_p
26164 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
26166 && chpos
< hpos
+ len
)
26167 w
->phys_cursor_on_p
= 0;
26171 /* Advance the output cursor. */
26172 w
->output_cursor
.hpos
+= len
;
26173 w
->output_cursor
.x
= x
;
26178 Insert LEN glyphs from START at the nominal cursor position. */
26181 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26182 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26185 int line_height
, shift_by_width
, shifted_region_width
;
26186 struct glyph_row
*row
;
26187 struct glyph
*glyph
;
26188 int frame_x
, frame_y
;
26191 eassert (updated_row
);
26193 f
= XFRAME (WINDOW_FRAME (w
));
26195 /* Get the height of the line we are in. */
26197 line_height
= row
->height
;
26199 /* Get the width of the glyphs to insert. */
26200 shift_by_width
= 0;
26201 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26202 shift_by_width
+= glyph
->pixel_width
;
26204 /* Get the width of the region to shift right. */
26205 shifted_region_width
= (window_box_width (w
, updated_area
)
26206 - w
->output_cursor
.x
26210 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
26211 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
26213 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26214 line_height
, shift_by_width
);
26216 /* Write the glyphs. */
26217 hpos
= start
- row
->glyphs
[updated_area
];
26218 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
26220 DRAW_NORMAL_TEXT
, 0);
26222 /* Advance the output cursor. */
26223 w
->output_cursor
.hpos
+= len
;
26224 w
->output_cursor
.x
+= shift_by_width
;
26230 Erase the current text line from the nominal cursor position
26231 (inclusive) to pixel column TO_X (exclusive). The idea is that
26232 everything from TO_X onward is already erased.
26234 TO_X is a pixel position relative to UPDATED_AREA of currently
26235 updated window W. TO_X == -1 means clear to the end of this area. */
26238 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26239 enum glyph_row_area updated_area
, int to_x
)
26242 int max_x
, min_y
, max_y
;
26243 int from_x
, from_y
, to_y
;
26245 eassert (updated_row
);
26246 f
= XFRAME (w
->frame
);
26248 if (updated_row
->full_width_p
)
26249 max_x
= (WINDOW_PIXEL_WIDTH (w
)
26250 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
26252 max_x
= window_box_width (w
, updated_area
);
26253 max_y
= window_text_bottom_y (w
);
26255 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26256 of window. For TO_X > 0, truncate to end of drawing area. */
26262 to_x
= min (to_x
, max_x
);
26264 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
26266 /* Notice if the cursor will be cleared by this operation. */
26267 if (!updated_row
->full_width_p
)
26268 notice_overwritten_cursor (w
, updated_area
,
26269 w
->output_cursor
.x
, -1,
26271 MATRIX_ROW_BOTTOM_Y (updated_row
));
26273 from_x
= w
->output_cursor
.x
;
26275 /* Translate to frame coordinates. */
26276 if (updated_row
->full_width_p
)
26278 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26279 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26283 int area_left
= window_box_left (w
, updated_area
);
26284 from_x
+= area_left
;
26288 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26289 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26290 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26292 /* Prevent inadvertently clearing to end of the X window. */
26293 if (to_x
> from_x
&& to_y
> from_y
)
26296 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26297 to_x
- from_x
, to_y
- from_y
);
26302 #endif /* HAVE_WINDOW_SYSTEM */
26306 /***********************************************************************
26308 ***********************************************************************/
26310 /* Value is the internal representation of the specified cursor type
26311 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26312 of the bar cursor. */
26314 static enum text_cursor_kinds
26315 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26317 enum text_cursor_kinds type
;
26322 if (EQ (arg
, Qbox
))
26323 return FILLED_BOX_CURSOR
;
26325 if (EQ (arg
, Qhollow
))
26326 return HOLLOW_BOX_CURSOR
;
26328 if (EQ (arg
, Qbar
))
26335 && EQ (XCAR (arg
), Qbar
)
26336 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26338 *width
= XINT (XCDR (arg
));
26342 if (EQ (arg
, Qhbar
))
26345 return HBAR_CURSOR
;
26349 && EQ (XCAR (arg
), Qhbar
)
26350 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26352 *width
= XINT (XCDR (arg
));
26353 return HBAR_CURSOR
;
26356 /* Treat anything unknown as "hollow box cursor".
26357 It was bad to signal an error; people have trouble fixing
26358 .Xdefaults with Emacs, when it has something bad in it. */
26359 type
= HOLLOW_BOX_CURSOR
;
26364 /* Set the default cursor types for specified frame. */
26366 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26371 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26372 FRAME_CURSOR_WIDTH (f
) = width
;
26374 /* By default, set up the blink-off state depending on the on-state. */
26376 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26379 FRAME_BLINK_OFF_CURSOR (f
)
26380 = get_specified_cursor_type (XCDR (tem
), &width
);
26381 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26384 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26386 /* Make sure the cursor gets redrawn. */
26387 f
->cursor_type_changed
= 1;
26391 #ifdef HAVE_WINDOW_SYSTEM
26393 /* Return the cursor we want to be displayed in window W. Return
26394 width of bar/hbar cursor through WIDTH arg. Return with
26395 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26396 (i.e. if the `system caret' should track this cursor).
26398 In a mini-buffer window, we want the cursor only to appear if we
26399 are reading input from this window. For the selected window, we
26400 want the cursor type given by the frame parameter or buffer local
26401 setting of cursor-type. If explicitly marked off, draw no cursor.
26402 In all other cases, we want a hollow box cursor. */
26404 static enum text_cursor_kinds
26405 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26406 int *active_cursor
)
26408 struct frame
*f
= XFRAME (w
->frame
);
26409 struct buffer
*b
= XBUFFER (w
->contents
);
26410 int cursor_type
= DEFAULT_CURSOR
;
26411 Lisp_Object alt_cursor
;
26412 int non_selected
= 0;
26414 *active_cursor
= 1;
26417 if (cursor_in_echo_area
26418 && FRAME_HAS_MINIBUF_P (f
)
26419 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26421 if (w
== XWINDOW (echo_area_window
))
26423 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26425 *width
= FRAME_CURSOR_WIDTH (f
);
26426 return FRAME_DESIRED_CURSOR (f
);
26429 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26432 *active_cursor
= 0;
26436 /* Detect a nonselected window or nonselected frame. */
26437 else if (w
!= XWINDOW (f
->selected_window
)
26438 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26440 *active_cursor
= 0;
26442 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26448 /* Never display a cursor in a window in which cursor-type is nil. */
26449 if (NILP (BVAR (b
, cursor_type
)))
26452 /* Get the normal cursor type for this window. */
26453 if (EQ (BVAR (b
, cursor_type
), Qt
))
26455 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26456 *width
= FRAME_CURSOR_WIDTH (f
);
26459 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26461 /* Use cursor-in-non-selected-windows instead
26462 for non-selected window or frame. */
26465 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26466 if (!EQ (Qt
, alt_cursor
))
26467 return get_specified_cursor_type (alt_cursor
, width
);
26468 /* t means modify the normal cursor type. */
26469 if (cursor_type
== FILLED_BOX_CURSOR
)
26470 cursor_type
= HOLLOW_BOX_CURSOR
;
26471 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26473 return cursor_type
;
26476 /* Use normal cursor if not blinked off. */
26477 if (!w
->cursor_off_p
)
26479 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26481 if (cursor_type
== FILLED_BOX_CURSOR
)
26483 /* Using a block cursor on large images can be very annoying.
26484 So use a hollow cursor for "large" images.
26485 If image is not transparent (no mask), also use hollow cursor. */
26486 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26487 if (img
!= NULL
&& IMAGEP (img
->spec
))
26489 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26490 where N = size of default frame font size.
26491 This should cover most of the "tiny" icons people may use. */
26493 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26494 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26495 cursor_type
= HOLLOW_BOX_CURSOR
;
26498 else if (cursor_type
!= NO_CURSOR
)
26500 /* Display current only supports BOX and HOLLOW cursors for images.
26501 So for now, unconditionally use a HOLLOW cursor when cursor is
26502 not a solid box cursor. */
26503 cursor_type
= HOLLOW_BOX_CURSOR
;
26506 return cursor_type
;
26509 /* Cursor is blinked off, so determine how to "toggle" it. */
26511 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26512 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26513 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26515 /* Then see if frame has specified a specific blink off cursor type. */
26516 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26518 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26519 return FRAME_BLINK_OFF_CURSOR (f
);
26523 /* Some people liked having a permanently visible blinking cursor,
26524 while others had very strong opinions against it. So it was
26525 decided to remove it. KFS 2003-09-03 */
26527 /* Finally perform built-in cursor blinking:
26528 filled box <-> hollow box
26529 wide [h]bar <-> narrow [h]bar
26530 narrow [h]bar <-> no cursor
26531 other type <-> no cursor */
26533 if (cursor_type
== FILLED_BOX_CURSOR
)
26534 return HOLLOW_BOX_CURSOR
;
26536 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26539 return cursor_type
;
26547 /* Notice when the text cursor of window W has been completely
26548 overwritten by a drawing operation that outputs glyphs in AREA
26549 starting at X0 and ending at X1 in the line starting at Y0 and
26550 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26551 the rest of the line after X0 has been written. Y coordinates
26552 are window-relative. */
26555 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26556 int x0
, int x1
, int y0
, int y1
)
26558 int cx0
, cx1
, cy0
, cy1
;
26559 struct glyph_row
*row
;
26561 if (!w
->phys_cursor_on_p
)
26563 if (area
!= TEXT_AREA
)
26566 if (w
->phys_cursor
.vpos
< 0
26567 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26568 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26569 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26572 if (row
->cursor_in_fringe_p
)
26574 row
->cursor_in_fringe_p
= 0;
26575 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26576 w
->phys_cursor_on_p
= 0;
26580 cx0
= w
->phys_cursor
.x
;
26581 cx1
= cx0
+ w
->phys_cursor_width
;
26582 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26585 /* The cursor image will be completely removed from the
26586 screen if the output area intersects the cursor area in
26587 y-direction. When we draw in [y0 y1[, and some part of
26588 the cursor is at y < y0, that part must have been drawn
26589 before. When scrolling, the cursor is erased before
26590 actually scrolling, so we don't come here. When not
26591 scrolling, the rows above the old cursor row must have
26592 changed, and in this case these rows must have written
26593 over the cursor image.
26595 Likewise if part of the cursor is below y1, with the
26596 exception of the cursor being in the first blank row at
26597 the buffer and window end because update_text_area
26598 doesn't draw that row. (Except when it does, but
26599 that's handled in update_text_area.) */
26601 cy0
= w
->phys_cursor
.y
;
26602 cy1
= cy0
+ w
->phys_cursor_height
;
26603 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26606 w
->phys_cursor_on_p
= 0;
26609 #endif /* HAVE_WINDOW_SYSTEM */
26612 /************************************************************************
26614 ************************************************************************/
26616 #ifdef HAVE_WINDOW_SYSTEM
26619 Fix the display of area AREA of overlapping row ROW in window W
26620 with respect to the overlapping part OVERLAPS. */
26623 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26624 enum glyph_row_area area
, int overlaps
)
26631 for (i
= 0; i
< row
->used
[area
];)
26633 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26635 int start
= i
, start_x
= x
;
26639 x
+= row
->glyphs
[area
][i
].pixel_width
;
26642 while (i
< row
->used
[area
]
26643 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26645 draw_glyphs (w
, start_x
, row
, area
,
26647 DRAW_NORMAL_TEXT
, overlaps
);
26651 x
+= row
->glyphs
[area
][i
].pixel_width
;
26661 Draw the cursor glyph of window W in glyph row ROW. See the
26662 comment of draw_glyphs for the meaning of HL. */
26665 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26666 enum draw_glyphs_face hl
)
26668 /* If cursor hpos is out of bounds, don't draw garbage. This can
26669 happen in mini-buffer windows when switching between echo area
26670 glyphs and mini-buffer. */
26671 if ((row
->reversed_p
26672 ? (w
->phys_cursor
.hpos
>= 0)
26673 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26675 int on_p
= w
->phys_cursor_on_p
;
26677 int hpos
= w
->phys_cursor
.hpos
;
26679 /* When the window is hscrolled, cursor hpos can legitimately be
26680 out of bounds, but we draw the cursor at the corresponding
26681 window margin in that case. */
26682 if (!row
->reversed_p
&& hpos
< 0)
26684 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26685 hpos
= row
->used
[TEXT_AREA
] - 1;
26687 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26689 w
->phys_cursor_on_p
= on_p
;
26691 if (hl
== DRAW_CURSOR
)
26692 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26693 /* When we erase the cursor, and ROW is overlapped by other
26694 rows, make sure that these overlapping parts of other rows
26696 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26698 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26700 if (row
> w
->current_matrix
->rows
26701 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26702 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26703 OVERLAPS_ERASED_CURSOR
);
26705 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26706 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26707 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26708 OVERLAPS_ERASED_CURSOR
);
26714 /* Erase the image of a cursor of window W from the screen. */
26720 erase_phys_cursor (struct window
*w
)
26722 struct frame
*f
= XFRAME (w
->frame
);
26723 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26724 int hpos
= w
->phys_cursor
.hpos
;
26725 int vpos
= w
->phys_cursor
.vpos
;
26726 int mouse_face_here_p
= 0;
26727 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26728 struct glyph_row
*cursor_row
;
26729 struct glyph
*cursor_glyph
;
26730 enum draw_glyphs_face hl
;
26732 /* No cursor displayed or row invalidated => nothing to do on the
26734 if (w
->phys_cursor_type
== NO_CURSOR
)
26735 goto mark_cursor_off
;
26737 /* VPOS >= active_glyphs->nrows means that window has been resized.
26738 Don't bother to erase the cursor. */
26739 if (vpos
>= active_glyphs
->nrows
)
26740 goto mark_cursor_off
;
26742 /* If row containing cursor is marked invalid, there is nothing we
26744 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26745 if (!cursor_row
->enabled_p
)
26746 goto mark_cursor_off
;
26748 /* If line spacing is > 0, old cursor may only be partially visible in
26749 window after split-window. So adjust visible height. */
26750 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26751 window_text_bottom_y (w
) - cursor_row
->y
);
26753 /* If row is completely invisible, don't attempt to delete a cursor which
26754 isn't there. This can happen if cursor is at top of a window, and
26755 we switch to a buffer with a header line in that window. */
26756 if (cursor_row
->visible_height
<= 0)
26757 goto mark_cursor_off
;
26759 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26760 if (cursor_row
->cursor_in_fringe_p
)
26762 cursor_row
->cursor_in_fringe_p
= 0;
26763 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26764 goto mark_cursor_off
;
26767 /* This can happen when the new row is shorter than the old one.
26768 In this case, either draw_glyphs or clear_end_of_line
26769 should have cleared the cursor. Note that we wouldn't be
26770 able to erase the cursor in this case because we don't have a
26771 cursor glyph at hand. */
26772 if ((cursor_row
->reversed_p
26773 ? (w
->phys_cursor
.hpos
< 0)
26774 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26775 goto mark_cursor_off
;
26777 /* When the window is hscrolled, cursor hpos can legitimately be out
26778 of bounds, but we draw the cursor at the corresponding window
26779 margin in that case. */
26780 if (!cursor_row
->reversed_p
&& hpos
< 0)
26782 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26783 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26785 /* If the cursor is in the mouse face area, redisplay that when
26786 we clear the cursor. */
26787 if (! NILP (hlinfo
->mouse_face_window
)
26788 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26789 /* Don't redraw the cursor's spot in mouse face if it is at the
26790 end of a line (on a newline). The cursor appears there, but
26791 mouse highlighting does not. */
26792 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26793 mouse_face_here_p
= 1;
26795 /* Maybe clear the display under the cursor. */
26796 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26799 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26802 cursor_glyph
= get_phys_cursor_glyph (w
);
26803 if (cursor_glyph
== NULL
)
26804 goto mark_cursor_off
;
26806 width
= cursor_glyph
->pixel_width
;
26807 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26808 x
= w
->phys_cursor
.x
;
26810 width
-= left_x
- x
;
26811 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26812 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26813 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26816 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26819 /* Erase the cursor by redrawing the character underneath it. */
26820 if (mouse_face_here_p
)
26821 hl
= DRAW_MOUSE_FACE
;
26823 hl
= DRAW_NORMAL_TEXT
;
26824 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26827 w
->phys_cursor_on_p
= 0;
26828 w
->phys_cursor_type
= NO_CURSOR
;
26833 Display or clear cursor of window W. If ON is zero, clear the
26834 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26835 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26838 display_and_set_cursor (struct window
*w
, bool on
,
26839 int hpos
, int vpos
, int x
, int y
)
26841 struct frame
*f
= XFRAME (w
->frame
);
26842 int new_cursor_type
;
26843 int new_cursor_width
;
26845 struct glyph_row
*glyph_row
;
26846 struct glyph
*glyph
;
26848 /* This is pointless on invisible frames, and dangerous on garbaged
26849 windows and frames; in the latter case, the frame or window may
26850 be in the midst of changing its size, and x and y may be off the
26852 if (! FRAME_VISIBLE_P (f
)
26853 || FRAME_GARBAGED_P (f
)
26854 || vpos
>= w
->current_matrix
->nrows
26855 || hpos
>= w
->current_matrix
->matrix_w
)
26858 /* If cursor is off and we want it off, return quickly. */
26859 if (!on
&& !w
->phys_cursor_on_p
)
26862 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26863 /* If cursor row is not enabled, we don't really know where to
26864 display the cursor. */
26865 if (!glyph_row
->enabled_p
)
26867 w
->phys_cursor_on_p
= 0;
26872 if (!glyph_row
->exact_window_width_line_p
26873 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26874 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26876 eassert (input_blocked_p ());
26878 /* Set new_cursor_type to the cursor we want to be displayed. */
26879 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26880 &new_cursor_width
, &active_cursor
);
26882 /* If cursor is currently being shown and we don't want it to be or
26883 it is in the wrong place, or the cursor type is not what we want,
26885 if (w
->phys_cursor_on_p
26887 || w
->phys_cursor
.x
!= x
26888 || w
->phys_cursor
.y
!= y
26889 || new_cursor_type
!= w
->phys_cursor_type
26890 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26891 && new_cursor_width
!= w
->phys_cursor_width
)))
26892 erase_phys_cursor (w
);
26894 /* Don't check phys_cursor_on_p here because that flag is only set
26895 to zero in some cases where we know that the cursor has been
26896 completely erased, to avoid the extra work of erasing the cursor
26897 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26898 still not be visible, or it has only been partly erased. */
26901 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26902 w
->phys_cursor_height
= glyph_row
->height
;
26904 /* Set phys_cursor_.* before x_draw_.* is called because some
26905 of them may need the information. */
26906 w
->phys_cursor
.x
= x
;
26907 w
->phys_cursor
.y
= glyph_row
->y
;
26908 w
->phys_cursor
.hpos
= hpos
;
26909 w
->phys_cursor
.vpos
= vpos
;
26912 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26913 new_cursor_type
, new_cursor_width
,
26914 on
, active_cursor
);
26918 /* Switch the display of W's cursor on or off, according to the value
26922 update_window_cursor (struct window
*w
, bool on
)
26924 /* Don't update cursor in windows whose frame is in the process
26925 of being deleted. */
26926 if (w
->current_matrix
)
26928 int hpos
= w
->phys_cursor
.hpos
;
26929 int vpos
= w
->phys_cursor
.vpos
;
26930 struct glyph_row
*row
;
26932 if (vpos
>= w
->current_matrix
->nrows
26933 || hpos
>= w
->current_matrix
->matrix_w
)
26936 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26938 /* When the window is hscrolled, cursor hpos can legitimately be
26939 out of bounds, but we draw the cursor at the corresponding
26940 window margin in that case. */
26941 if (!row
->reversed_p
&& hpos
< 0)
26943 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26944 hpos
= row
->used
[TEXT_AREA
] - 1;
26947 display_and_set_cursor (w
, on
, hpos
, vpos
,
26948 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26954 /* Call update_window_cursor with parameter ON_P on all leaf windows
26955 in the window tree rooted at W. */
26958 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26962 if (WINDOWP (w
->contents
))
26963 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26965 update_window_cursor (w
, on_p
);
26967 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26973 Display the cursor on window W, or clear it, according to ON_P.
26974 Don't change the cursor's position. */
26977 x_update_cursor (struct frame
*f
, bool on_p
)
26979 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26984 Clear the cursor of window W to background color, and mark the
26985 cursor as not shown. This is used when the text where the cursor
26986 is about to be rewritten. */
26989 x_clear_cursor (struct window
*w
)
26991 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26992 update_window_cursor (w
, 0);
26995 #endif /* HAVE_WINDOW_SYSTEM */
26997 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
27000 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
27001 int start_hpos
, int end_hpos
,
27002 enum draw_glyphs_face draw
)
27004 #ifdef HAVE_WINDOW_SYSTEM
27005 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
27007 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
27011 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
27012 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
27016 /* Display the active region described by mouse_face_* according to DRAW. */
27019 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
27021 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
27022 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27024 if (/* If window is in the process of being destroyed, don't bother
27026 w
->current_matrix
!= NULL
27027 /* Don't update mouse highlight if hidden */
27028 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
27029 /* Recognize when we are called to operate on rows that don't exist
27030 anymore. This can happen when a window is split. */
27031 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
27033 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
27034 struct glyph_row
*row
, *first
, *last
;
27036 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
27037 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
27039 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
27041 int start_hpos
, end_hpos
, start_x
;
27043 /* For all but the first row, the highlight starts at column 0. */
27046 /* R2L rows have BEG and END in reversed order, but the
27047 screen drawing geometry is always left to right. So
27048 we need to mirror the beginning and end of the
27049 highlighted area in R2L rows. */
27050 if (!row
->reversed_p
)
27052 start_hpos
= hlinfo
->mouse_face_beg_col
;
27053 start_x
= hlinfo
->mouse_face_beg_x
;
27055 else if (row
== last
)
27057 start_hpos
= hlinfo
->mouse_face_end_col
;
27058 start_x
= hlinfo
->mouse_face_end_x
;
27066 else if (row
->reversed_p
&& row
== last
)
27068 start_hpos
= hlinfo
->mouse_face_end_col
;
27069 start_x
= hlinfo
->mouse_face_end_x
;
27079 if (!row
->reversed_p
)
27080 end_hpos
= hlinfo
->mouse_face_end_col
;
27081 else if (row
== first
)
27082 end_hpos
= hlinfo
->mouse_face_beg_col
;
27085 end_hpos
= row
->used
[TEXT_AREA
];
27086 if (draw
== DRAW_NORMAL_TEXT
)
27087 row
->fill_line_p
= 1; /* Clear to end of line */
27090 else if (row
->reversed_p
&& row
== first
)
27091 end_hpos
= hlinfo
->mouse_face_beg_col
;
27094 end_hpos
= row
->used
[TEXT_AREA
];
27095 if (draw
== DRAW_NORMAL_TEXT
)
27096 row
->fill_line_p
= 1; /* Clear to end of line */
27099 if (end_hpos
> start_hpos
)
27101 draw_row_with_mouse_face (w
, start_x
, row
,
27102 start_hpos
, end_hpos
, draw
);
27105 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27109 #ifdef HAVE_WINDOW_SYSTEM
27110 /* When we've written over the cursor, arrange for it to
27111 be displayed again. */
27112 if (FRAME_WINDOW_P (f
)
27113 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27115 int hpos
= w
->phys_cursor
.hpos
;
27117 /* When the window is hscrolled, cursor hpos can legitimately be
27118 out of bounds, but we draw the cursor at the corresponding
27119 window margin in that case. */
27120 if (!row
->reversed_p
&& hpos
< 0)
27122 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27123 hpos
= row
->used
[TEXT_AREA
] - 1;
27126 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27127 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27130 #endif /* HAVE_WINDOW_SYSTEM */
27133 #ifdef HAVE_WINDOW_SYSTEM
27134 /* Change the mouse cursor. */
27135 if (FRAME_WINDOW_P (f
))
27137 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
27138 if (draw
== DRAW_NORMAL_TEXT
27139 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27140 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27143 if (draw
== DRAW_MOUSE_FACE
)
27144 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27146 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27148 #endif /* HAVE_WINDOW_SYSTEM */
27152 Clear out the mouse-highlighted active region.
27153 Redraw it un-highlighted first. Value is non-zero if mouse
27154 face was actually drawn unhighlighted. */
27157 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27161 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27163 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27167 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27168 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27169 hlinfo
->mouse_face_window
= Qnil
;
27170 hlinfo
->mouse_face_overlay
= Qnil
;
27174 /* Return true if the coordinates HPOS and VPOS on windows W are
27175 within the mouse face on that window. */
27177 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27179 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27181 /* Quickly resolve the easy cases. */
27182 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27183 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27185 if (vpos
< hlinfo
->mouse_face_beg_row
27186 || vpos
> hlinfo
->mouse_face_end_row
)
27188 if (vpos
> hlinfo
->mouse_face_beg_row
27189 && vpos
< hlinfo
->mouse_face_end_row
)
27192 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27194 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27196 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27199 else if ((vpos
== hlinfo
->mouse_face_beg_row
27200 && hpos
>= hlinfo
->mouse_face_beg_col
)
27201 || (vpos
== hlinfo
->mouse_face_end_row
27202 && hpos
< hlinfo
->mouse_face_end_col
))
27207 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27209 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27212 else if ((vpos
== hlinfo
->mouse_face_beg_row
27213 && hpos
<= hlinfo
->mouse_face_beg_col
)
27214 || (vpos
== hlinfo
->mouse_face_end_row
27215 && hpos
> hlinfo
->mouse_face_end_col
))
27223 True if physical cursor of window W is within mouse face. */
27226 cursor_in_mouse_face_p (struct window
*w
)
27228 int hpos
= w
->phys_cursor
.hpos
;
27229 int vpos
= w
->phys_cursor
.vpos
;
27230 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27232 /* When the window is hscrolled, cursor hpos can legitimately be out
27233 of bounds, but we draw the cursor at the corresponding window
27234 margin in that case. */
27235 if (!row
->reversed_p
&& hpos
< 0)
27237 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27238 hpos
= row
->used
[TEXT_AREA
] - 1;
27240 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27245 /* Find the glyph rows START_ROW and END_ROW of window W that display
27246 characters between buffer positions START_CHARPOS and END_CHARPOS
27247 (excluding END_CHARPOS). DISP_STRING is a display string that
27248 covers these buffer positions. This is similar to
27249 row_containing_pos, but is more accurate when bidi reordering makes
27250 buffer positions change non-linearly with glyph rows. */
27252 rows_from_pos_range (struct window
*w
,
27253 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27254 Lisp_Object disp_string
,
27255 struct glyph_row
**start
, struct glyph_row
**end
)
27257 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27258 int last_y
= window_text_bottom_y (w
);
27259 struct glyph_row
*row
;
27264 while (!first
->enabled_p
27265 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27268 /* Find the START row. */
27270 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27273 /* A row can potentially be the START row if the range of the
27274 characters it displays intersects the range
27275 [START_CHARPOS..END_CHARPOS). */
27276 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27277 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27278 /* See the commentary in row_containing_pos, for the
27279 explanation of the complicated way to check whether
27280 some position is beyond the end of the characters
27281 displayed by a row. */
27282 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27283 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27284 && !row
->ends_at_zv_p
27285 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27286 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27287 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27288 && !row
->ends_at_zv_p
27289 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27291 /* Found a candidate row. Now make sure at least one of the
27292 glyphs it displays has a charpos from the range
27293 [START_CHARPOS..END_CHARPOS).
27295 This is not obvious because bidi reordering could make
27296 buffer positions of a row be 1,2,3,102,101,100, and if we
27297 want to highlight characters in [50..60), we don't want
27298 this row, even though [50..60) does intersect [1..103),
27299 the range of character positions given by the row's start
27300 and end positions. */
27301 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27302 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27306 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27307 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27308 /* A glyph that comes from DISP_STRING is by
27309 definition to be highlighted. */
27310 || EQ (g
->object
, disp_string
))
27319 /* Find the END row. */
27321 /* If the last row is partially visible, start looking for END
27322 from that row, instead of starting from FIRST. */
27323 && !(row
->enabled_p
27324 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27326 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27328 struct glyph_row
*next
= row
+ 1;
27329 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27331 if (!next
->enabled_p
27332 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27333 /* The first row >= START whose range of displayed characters
27334 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27335 is the row END + 1. */
27336 || (start_charpos
< next_start
27337 && end_charpos
< next_start
)
27338 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27339 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27340 && !next
->ends_at_zv_p
27341 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27342 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27343 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27344 && !next
->ends_at_zv_p
27345 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27352 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27353 but none of the characters it displays are in the range, it is
27355 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27356 struct glyph
*s
= g
;
27357 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27361 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27362 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27363 /* If the buffer position of the first glyph in
27364 the row is equal to END_CHARPOS, it means
27365 the last character to be highlighted is the
27366 newline of ROW, and we must consider NEXT as
27368 || (((!next
->reversed_p
&& g
== s
)
27369 || (next
->reversed_p
&& g
== e
- 1))
27370 && (g
->charpos
== end_charpos
27371 /* Special case for when NEXT is an
27372 empty line at ZV. */
27373 || (g
->charpos
== -1
27374 && !row
->ends_at_zv_p
27375 && next_start
== end_charpos
)))))
27376 /* A glyph that comes from DISP_STRING is by
27377 definition to be highlighted. */
27378 || EQ (g
->object
, disp_string
))
27387 /* The first row that ends at ZV must be the last to be
27389 else if (next
->ends_at_zv_p
)
27398 /* This function sets the mouse_face_* elements of HLINFO, assuming
27399 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27400 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27401 for the overlay or run of text properties specifying the mouse
27402 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27403 before-string and after-string that must also be highlighted.
27404 DISP_STRING, if non-nil, is a display string that may cover some
27405 or all of the highlighted text. */
27408 mouse_face_from_buffer_pos (Lisp_Object window
,
27409 Mouse_HLInfo
*hlinfo
,
27410 ptrdiff_t mouse_charpos
,
27411 ptrdiff_t start_charpos
,
27412 ptrdiff_t end_charpos
,
27413 Lisp_Object before_string
,
27414 Lisp_Object after_string
,
27415 Lisp_Object disp_string
)
27417 struct window
*w
= XWINDOW (window
);
27418 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27419 struct glyph_row
*r1
, *r2
;
27420 struct glyph
*glyph
, *end
;
27421 ptrdiff_t ignore
, pos
;
27424 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27425 eassert (NILP (before_string
) || STRINGP (before_string
));
27426 eassert (NILP (after_string
) || STRINGP (after_string
));
27428 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27429 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27431 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27432 /* If the before-string or display-string contains newlines,
27433 rows_from_pos_range skips to its last row. Move back. */
27434 if (!NILP (before_string
) || !NILP (disp_string
))
27436 struct glyph_row
*prev
;
27437 while ((prev
= r1
- 1, prev
>= first
)
27438 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27439 && prev
->used
[TEXT_AREA
] > 0)
27441 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27442 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27443 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27445 || !(EQ (glyph
->object
, before_string
)
27446 || EQ (glyph
->object
, disp_string
)))
27453 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27454 hlinfo
->mouse_face_past_end
= 1;
27456 else if (!NILP (after_string
))
27458 /* If the after-string has newlines, advance to its last row. */
27459 struct glyph_row
*next
;
27460 struct glyph_row
*last
27461 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27463 for (next
= r2
+ 1;
27465 && next
->used
[TEXT_AREA
] > 0
27466 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27470 /* The rest of the display engine assumes that mouse_face_beg_row is
27471 either above mouse_face_end_row or identical to it. But with
27472 bidi-reordered continued lines, the row for START_CHARPOS could
27473 be below the row for END_CHARPOS. If so, swap the rows and store
27474 them in correct order. */
27477 struct glyph_row
*tem
= r2
;
27483 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27484 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27486 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27487 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27488 could be anywhere in the row and in any order. The strategy
27489 below is to find the leftmost and the rightmost glyph that
27490 belongs to either of these 3 strings, or whose position is
27491 between START_CHARPOS and END_CHARPOS, and highlight all the
27492 glyphs between those two. This may cover more than just the text
27493 between START_CHARPOS and END_CHARPOS if the range of characters
27494 strides the bidi level boundary, e.g. if the beginning is in R2L
27495 text while the end is in L2R text or vice versa. */
27496 if (!r1
->reversed_p
)
27498 /* This row is in a left to right paragraph. Scan it left to
27500 glyph
= r1
->glyphs
[TEXT_AREA
];
27501 end
= glyph
+ r1
->used
[TEXT_AREA
];
27504 /* Skip truncation glyphs at the start of the glyph row. */
27505 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27507 && INTEGERP (glyph
->object
)
27508 && glyph
->charpos
< 0;
27510 x
+= glyph
->pixel_width
;
27512 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27513 or DISP_STRING, and the first glyph from buffer whose
27514 position is between START_CHARPOS and END_CHARPOS. */
27516 && !INTEGERP (glyph
->object
)
27517 && !EQ (glyph
->object
, disp_string
)
27518 && !(BUFFERP (glyph
->object
)
27519 && (glyph
->charpos
>= start_charpos
27520 && glyph
->charpos
< end_charpos
));
27523 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27524 are present at buffer positions between START_CHARPOS and
27525 END_CHARPOS, or if they come from an overlay. */
27526 if (EQ (glyph
->object
, before_string
))
27528 pos
= string_buffer_position (before_string
,
27530 /* If pos == 0, it means before_string came from an
27531 overlay, not from a buffer position. */
27532 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27535 else if (EQ (glyph
->object
, after_string
))
27537 pos
= string_buffer_position (after_string
, end_charpos
);
27538 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27541 x
+= glyph
->pixel_width
;
27543 hlinfo
->mouse_face_beg_x
= x
;
27544 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27548 /* This row is in a right to left paragraph. Scan it right to
27552 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27553 glyph
= end
+ r1
->used
[TEXT_AREA
];
27555 /* Skip truncation glyphs at the start of the glyph row. */
27556 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27558 && INTEGERP (glyph
->object
)
27559 && glyph
->charpos
< 0;
27563 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27564 or DISP_STRING, and the first glyph from buffer whose
27565 position is between START_CHARPOS and END_CHARPOS. */
27567 && !INTEGERP (glyph
->object
)
27568 && !EQ (glyph
->object
, disp_string
)
27569 && !(BUFFERP (glyph
->object
)
27570 && (glyph
->charpos
>= start_charpos
27571 && glyph
->charpos
< end_charpos
));
27574 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27575 are present at buffer positions between START_CHARPOS and
27576 END_CHARPOS, or if they come from an overlay. */
27577 if (EQ (glyph
->object
, before_string
))
27579 pos
= string_buffer_position (before_string
, start_charpos
);
27580 /* If pos == 0, it means before_string came from an
27581 overlay, not from a buffer position. */
27582 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27585 else if (EQ (glyph
->object
, after_string
))
27587 pos
= string_buffer_position (after_string
, end_charpos
);
27588 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27593 glyph
++; /* first glyph to the right of the highlighted area */
27594 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27595 x
+= g
->pixel_width
;
27596 hlinfo
->mouse_face_beg_x
= x
;
27597 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27600 /* If the highlight ends in a different row, compute GLYPH and END
27601 for the end row. Otherwise, reuse the values computed above for
27602 the row where the highlight begins. */
27605 if (!r2
->reversed_p
)
27607 glyph
= r2
->glyphs
[TEXT_AREA
];
27608 end
= glyph
+ r2
->used
[TEXT_AREA
];
27613 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27614 glyph
= end
+ r2
->used
[TEXT_AREA
];
27618 if (!r2
->reversed_p
)
27620 /* Skip truncation and continuation glyphs near the end of the
27621 row, and also blanks and stretch glyphs inserted by
27622 extend_face_to_end_of_line. */
27624 && INTEGERP ((end
- 1)->object
))
27626 /* Scan the rest of the glyph row from the end, looking for the
27627 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27628 DISP_STRING, or whose position is between START_CHARPOS
27632 && !INTEGERP (end
->object
)
27633 && !EQ (end
->object
, disp_string
)
27634 && !(BUFFERP (end
->object
)
27635 && (end
->charpos
>= start_charpos
27636 && end
->charpos
< end_charpos
));
27639 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27640 are present at buffer positions between START_CHARPOS and
27641 END_CHARPOS, or if they come from an overlay. */
27642 if (EQ (end
->object
, before_string
))
27644 pos
= string_buffer_position (before_string
, start_charpos
);
27645 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27648 else if (EQ (end
->object
, after_string
))
27650 pos
= string_buffer_position (after_string
, end_charpos
);
27651 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27655 /* Find the X coordinate of the last glyph to be highlighted. */
27656 for (; glyph
<= end
; ++glyph
)
27657 x
+= glyph
->pixel_width
;
27659 hlinfo
->mouse_face_end_x
= x
;
27660 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27664 /* Skip truncation and continuation glyphs near the end of the
27665 row, and also blanks and stretch glyphs inserted by
27666 extend_face_to_end_of_line. */
27670 && INTEGERP (end
->object
))
27672 x
+= end
->pixel_width
;
27675 /* Scan the rest of the glyph row from the end, looking for the
27676 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27677 DISP_STRING, or whose position is between START_CHARPOS
27681 && !INTEGERP (end
->object
)
27682 && !EQ (end
->object
, disp_string
)
27683 && !(BUFFERP (end
->object
)
27684 && (end
->charpos
>= start_charpos
27685 && end
->charpos
< end_charpos
));
27688 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27689 are present at buffer positions between START_CHARPOS and
27690 END_CHARPOS, or if they come from an overlay. */
27691 if (EQ (end
->object
, before_string
))
27693 pos
= string_buffer_position (before_string
, start_charpos
);
27694 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27697 else if (EQ (end
->object
, after_string
))
27699 pos
= string_buffer_position (after_string
, end_charpos
);
27700 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27703 x
+= end
->pixel_width
;
27705 /* If we exited the above loop because we arrived at the last
27706 glyph of the row, and its buffer position is still not in
27707 range, it means the last character in range is the preceding
27708 newline. Bump the end column and x values to get past the
27711 && BUFFERP (end
->object
)
27712 && (end
->charpos
< start_charpos
27713 || end
->charpos
>= end_charpos
))
27715 x
+= end
->pixel_width
;
27718 hlinfo
->mouse_face_end_x
= x
;
27719 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27722 hlinfo
->mouse_face_window
= window
;
27723 hlinfo
->mouse_face_face_id
27724 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27726 !hlinfo
->mouse_face_hidden
, -1);
27727 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27730 /* The following function is not used anymore (replaced with
27731 mouse_face_from_string_pos), but I leave it here for the time
27732 being, in case someone would. */
27734 #if 0 /* not used */
27736 /* Find the position of the glyph for position POS in OBJECT in
27737 window W's current matrix, and return in *X, *Y the pixel
27738 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27740 RIGHT_P non-zero means return the position of the right edge of the
27741 glyph, RIGHT_P zero means return the left edge position.
27743 If no glyph for POS exists in the matrix, return the position of
27744 the glyph with the next smaller position that is in the matrix, if
27745 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27746 exists in the matrix, return the position of the glyph with the
27747 next larger position in OBJECT.
27749 Value is non-zero if a glyph was found. */
27752 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27753 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27755 int yb
= window_text_bottom_y (w
);
27756 struct glyph_row
*r
;
27757 struct glyph
*best_glyph
= NULL
;
27758 struct glyph_row
*best_row
= NULL
;
27761 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27762 r
->enabled_p
&& r
->y
< yb
;
27765 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27766 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27769 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27770 if (EQ (g
->object
, object
))
27772 if (g
->charpos
== pos
)
27779 else if (best_glyph
== NULL
27780 || ((eabs (g
->charpos
- pos
)
27781 < eabs (best_glyph
->charpos
- pos
))
27784 : g
->charpos
> pos
)))
27798 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27802 *x
+= best_glyph
->pixel_width
;
27807 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27810 return best_glyph
!= NULL
;
27812 #endif /* not used */
27814 /* Find the positions of the first and the last glyphs in window W's
27815 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27816 (assumed to be a string), and return in HLINFO's mouse_face_*
27817 members the pixel and column/row coordinates of those glyphs. */
27820 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27821 Lisp_Object object
,
27822 ptrdiff_t startpos
, ptrdiff_t endpos
)
27824 int yb
= window_text_bottom_y (w
);
27825 struct glyph_row
*r
;
27826 struct glyph
*g
, *e
;
27830 /* Find the glyph row with at least one position in the range
27831 [STARTPOS..ENDPOS), and the first glyph in that row whose
27832 position belongs to that range. */
27833 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27834 r
->enabled_p
&& r
->y
< yb
;
27837 if (!r
->reversed_p
)
27839 g
= r
->glyphs
[TEXT_AREA
];
27840 e
= g
+ r
->used
[TEXT_AREA
];
27841 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27842 if (EQ (g
->object
, object
)
27843 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27845 hlinfo
->mouse_face_beg_row
27846 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27847 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27848 hlinfo
->mouse_face_beg_x
= gx
;
27857 e
= r
->glyphs
[TEXT_AREA
];
27858 g
= e
+ r
->used
[TEXT_AREA
];
27859 for ( ; g
> e
; --g
)
27860 if (EQ ((g
-1)->object
, object
)
27861 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27863 hlinfo
->mouse_face_beg_row
27864 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27865 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27866 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27867 gx
+= g1
->pixel_width
;
27868 hlinfo
->mouse_face_beg_x
= gx
;
27880 /* Starting with the next row, look for the first row which does NOT
27881 include any glyphs whose positions are in the range. */
27882 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27884 g
= r
->glyphs
[TEXT_AREA
];
27885 e
= g
+ r
->used
[TEXT_AREA
];
27887 for ( ; g
< e
; ++g
)
27888 if (EQ (g
->object
, object
)
27889 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27898 /* The highlighted region ends on the previous row. */
27901 /* Set the end row. */
27902 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27904 /* Compute and set the end column and the end column's horizontal
27905 pixel coordinate. */
27906 if (!r
->reversed_p
)
27908 g
= r
->glyphs
[TEXT_AREA
];
27909 e
= g
+ r
->used
[TEXT_AREA
];
27910 for ( ; e
> g
; --e
)
27911 if (EQ ((e
-1)->object
, object
)
27912 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27914 hlinfo
->mouse_face_end_col
= e
- g
;
27916 for (gx
= r
->x
; g
< e
; ++g
)
27917 gx
+= g
->pixel_width
;
27918 hlinfo
->mouse_face_end_x
= gx
;
27922 e
= r
->glyphs
[TEXT_AREA
];
27923 g
= e
+ r
->used
[TEXT_AREA
];
27924 for (gx
= r
->x
; e
< g
; ++e
)
27926 if (EQ (e
->object
, object
)
27927 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27929 gx
+= e
->pixel_width
;
27931 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27932 hlinfo
->mouse_face_end_x
= gx
;
27936 #ifdef HAVE_WINDOW_SYSTEM
27938 /* See if position X, Y is within a hot-spot of an image. */
27941 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27943 if (!CONSP (hot_spot
))
27946 if (EQ (XCAR (hot_spot
), Qrect
))
27948 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27949 Lisp_Object rect
= XCDR (hot_spot
);
27953 if (!CONSP (XCAR (rect
)))
27955 if (!CONSP (XCDR (rect
)))
27957 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27959 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27961 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27963 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27967 else if (EQ (XCAR (hot_spot
), Qcircle
))
27969 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27970 Lisp_Object circ
= XCDR (hot_spot
);
27971 Lisp_Object lr
, lx0
, ly0
;
27973 && CONSP (XCAR (circ
))
27974 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27975 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27976 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27978 double r
= XFLOATINT (lr
);
27979 double dx
= XINT (lx0
) - x
;
27980 double dy
= XINT (ly0
) - y
;
27981 return (dx
* dx
+ dy
* dy
<= r
* r
);
27984 else if (EQ (XCAR (hot_spot
), Qpoly
))
27986 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27987 if (VECTORP (XCDR (hot_spot
)))
27989 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27990 Lisp_Object
*poly
= v
->contents
;
27991 ptrdiff_t n
= v
->header
.size
;
27994 Lisp_Object lx
, ly
;
27997 /* Need an even number of coordinates, and at least 3 edges. */
27998 if (n
< 6 || n
& 1)
28001 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
28002 If count is odd, we are inside polygon. Pixels on edges
28003 may or may not be included depending on actual geometry of the
28005 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
28006 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
28008 x0
= XINT (lx
), y0
= XINT (ly
);
28009 for (i
= 0; i
< n
; i
+= 2)
28011 int x1
= x0
, y1
= y0
;
28012 if ((lx
= poly
[i
], !INTEGERP (lx
))
28013 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
28015 x0
= XINT (lx
), y0
= XINT (ly
);
28017 /* Does this segment cross the X line? */
28025 if (y
> y0
&& y
> y1
)
28027 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
28037 find_hot_spot (Lisp_Object map
, int x
, int y
)
28039 while (CONSP (map
))
28041 if (CONSP (XCAR (map
))
28042 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
28050 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
28052 doc
: /* Lookup in image map MAP coordinates X and Y.
28053 An image map is an alist where each element has the format (AREA ID PLIST).
28054 An AREA is specified as either a rectangle, a circle, or a polygon:
28055 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
28056 pixel coordinates of the upper left and bottom right corners.
28057 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
28058 and the radius of the circle; r may be a float or integer.
28059 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
28060 vector describes one corner in the polygon.
28061 Returns the alist element for the first matching AREA in MAP. */)
28062 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
28070 return find_hot_spot (map
,
28071 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
28072 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
28076 /* Display frame CURSOR, optionally using shape defined by POINTER. */
28078 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
28080 /* Do not change cursor shape while dragging mouse. */
28081 if (!NILP (do_mouse_tracking
))
28084 if (!NILP (pointer
))
28086 if (EQ (pointer
, Qarrow
))
28087 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28088 else if (EQ (pointer
, Qhand
))
28089 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
28090 else if (EQ (pointer
, Qtext
))
28091 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28092 else if (EQ (pointer
, intern ("hdrag")))
28093 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28094 else if (EQ (pointer
, intern ("nhdrag")))
28095 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28096 #ifdef HAVE_X_WINDOWS
28097 else if (EQ (pointer
, intern ("vdrag")))
28098 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28100 else if (EQ (pointer
, intern ("hourglass")))
28101 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28102 else if (EQ (pointer
, Qmodeline
))
28103 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28105 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28108 if (cursor
!= No_Cursor
)
28109 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28112 #endif /* HAVE_WINDOW_SYSTEM */
28114 /* Take proper action when mouse has moved to the mode or header line
28115 or marginal area AREA of window W, x-position X and y-position Y.
28116 X is relative to the start of the text display area of W, so the
28117 width of bitmap areas and scroll bars must be subtracted to get a
28118 position relative to the start of the mode line. */
28121 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28122 enum window_part area
)
28124 struct window
*w
= XWINDOW (window
);
28125 struct frame
*f
= XFRAME (w
->frame
);
28126 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28127 #ifdef HAVE_WINDOW_SYSTEM
28128 Display_Info
*dpyinfo
;
28130 Cursor cursor
= No_Cursor
;
28131 Lisp_Object pointer
= Qnil
;
28132 int dx
, dy
, width
, height
;
28134 Lisp_Object string
, object
= Qnil
;
28135 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28137 Lisp_Object mouse_face
;
28138 int original_x_pixel
= x
;
28139 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28140 struct glyph_row
*row
IF_LINT (= 0);
28142 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28147 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28148 returns them in row/column units! */
28149 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28150 &object
, &dx
, &dy
, &width
, &height
);
28152 row
= (area
== ON_MODE_LINE
28153 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28154 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28156 /* Find the glyph under the mouse pointer. */
28157 if (row
->mode_line_p
&& row
->enabled_p
)
28159 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28160 end
= glyph
+ row
->used
[TEXT_AREA
];
28162 for (x0
= original_x_pixel
;
28163 glyph
< end
&& x0
>= glyph
->pixel_width
;
28165 x0
-= glyph
->pixel_width
;
28173 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28174 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28175 returns them in row/column units! */
28176 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28177 &object
, &dx
, &dy
, &width
, &height
);
28182 #ifdef HAVE_WINDOW_SYSTEM
28183 if (IMAGEP (object
))
28185 Lisp_Object image_map
, hotspot
;
28186 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28188 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28190 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28194 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28195 If so, we could look for mouse-enter, mouse-leave
28196 properties in PLIST (and do something...). */
28197 hotspot
= XCDR (hotspot
);
28198 if (CONSP (hotspot
)
28199 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28201 pointer
= Fplist_get (plist
, Qpointer
);
28202 if (NILP (pointer
))
28204 help
= Fplist_get (plist
, Qhelp_echo
);
28207 help_echo_string
= help
;
28208 XSETWINDOW (help_echo_window
, w
);
28209 help_echo_object
= w
->contents
;
28210 help_echo_pos
= charpos
;
28214 if (NILP (pointer
))
28215 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28217 #endif /* HAVE_WINDOW_SYSTEM */
28219 if (STRINGP (string
))
28220 pos
= make_number (charpos
);
28222 /* Set the help text and mouse pointer. If the mouse is on a part
28223 of the mode line without any text (e.g. past the right edge of
28224 the mode line text), use the default help text and pointer. */
28225 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28227 /* Arrange to display the help by setting the global variables
28228 help_echo_string, help_echo_object, and help_echo_pos. */
28231 if (STRINGP (string
))
28232 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28236 help_echo_string
= help
;
28237 XSETWINDOW (help_echo_window
, w
);
28238 help_echo_object
= string
;
28239 help_echo_pos
= charpos
;
28241 else if (area
== ON_MODE_LINE
)
28243 Lisp_Object default_help
28244 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28247 if (STRINGP (default_help
))
28249 help_echo_string
= default_help
;
28250 XSETWINDOW (help_echo_window
, w
);
28251 help_echo_object
= Qnil
;
28252 help_echo_pos
= -1;
28257 #ifdef HAVE_WINDOW_SYSTEM
28258 /* Change the mouse pointer according to what is under it. */
28259 if (FRAME_WINDOW_P (f
))
28261 dpyinfo
= FRAME_DISPLAY_INFO (f
);
28262 if (STRINGP (string
))
28264 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28266 if (NILP (pointer
))
28267 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28269 /* Change the mouse pointer according to what is under X/Y. */
28271 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28274 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28275 if (!KEYMAPP (map
))
28276 map
= Fget_text_property (pos
, Qkeymap
, string
);
28277 if (!KEYMAPP (map
))
28278 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28282 /* Default mode-line pointer. */
28283 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28288 /* Change the mouse face according to what is under X/Y. */
28289 if (STRINGP (string
))
28291 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28292 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28293 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28298 struct glyph
* tmp_glyph
;
28302 int total_pixel_width
;
28303 ptrdiff_t begpos
, endpos
, ignore
;
28307 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28308 Qmouse_face
, string
, Qnil
);
28314 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28316 endpos
= SCHARS (string
);
28320 /* Calculate the glyph position GPOS of GLYPH in the
28321 displayed string, relative to the beginning of the
28322 highlighted part of the string.
28324 Note: GPOS is different from CHARPOS. CHARPOS is the
28325 position of GLYPH in the internal string object. A mode
28326 line string format has structures which are converted to
28327 a flattened string by the Emacs Lisp interpreter. The
28328 internal string is an element of those structures. The
28329 displayed string is the flattened string. */
28330 tmp_glyph
= row_start_glyph
;
28331 while (tmp_glyph
< glyph
28332 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28333 && begpos
<= tmp_glyph
->charpos
28334 && tmp_glyph
->charpos
< endpos
)))
28336 gpos
= glyph
- tmp_glyph
;
28338 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28339 the highlighted part of the displayed string to which
28340 GLYPH belongs. Note: GSEQ_LENGTH is different from
28341 SCHARS (STRING), because the latter returns the length of
28342 the internal string. */
28343 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28345 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28346 && begpos
<= tmp_glyph
->charpos
28347 && tmp_glyph
->charpos
< endpos
));
28350 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28352 /* Calculate the total pixel width of all the glyphs between
28353 the beginning of the highlighted area and GLYPH. */
28354 total_pixel_width
= 0;
28355 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28356 total_pixel_width
+= tmp_glyph
->pixel_width
;
28358 /* Pre calculation of re-rendering position. Note: X is in
28359 column units here, after the call to mode_line_string or
28360 marginal_area_string. */
28362 vpos
= (area
== ON_MODE_LINE
28363 ? (w
->current_matrix
)->nrows
- 1
28366 /* If GLYPH's position is included in the region that is
28367 already drawn in mouse face, we have nothing to do. */
28368 if ( EQ (window
, hlinfo
->mouse_face_window
)
28369 && (!row
->reversed_p
28370 ? (hlinfo
->mouse_face_beg_col
<= hpos
28371 && hpos
< hlinfo
->mouse_face_end_col
)
28372 /* In R2L rows we swap BEG and END, see below. */
28373 : (hlinfo
->mouse_face_end_col
<= hpos
28374 && hpos
< hlinfo
->mouse_face_beg_col
))
28375 && hlinfo
->mouse_face_beg_row
== vpos
)
28378 if (clear_mouse_face (hlinfo
))
28379 cursor
= No_Cursor
;
28381 if (!row
->reversed_p
)
28383 hlinfo
->mouse_face_beg_col
= hpos
;
28384 hlinfo
->mouse_face_beg_x
= original_x_pixel
28385 - (total_pixel_width
+ dx
);
28386 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28387 hlinfo
->mouse_face_end_x
= 0;
28391 /* In R2L rows, show_mouse_face expects BEG and END
28392 coordinates to be swapped. */
28393 hlinfo
->mouse_face_end_col
= hpos
;
28394 hlinfo
->mouse_face_end_x
= original_x_pixel
28395 - (total_pixel_width
+ dx
);
28396 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28397 hlinfo
->mouse_face_beg_x
= 0;
28400 hlinfo
->mouse_face_beg_row
= vpos
;
28401 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28402 hlinfo
->mouse_face_past_end
= 0;
28403 hlinfo
->mouse_face_window
= window
;
28405 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28410 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28412 if (NILP (pointer
))
28415 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28416 clear_mouse_face (hlinfo
);
28418 #ifdef HAVE_WINDOW_SYSTEM
28419 if (FRAME_WINDOW_P (f
))
28420 define_frame_cursor1 (f
, cursor
, pointer
);
28426 Take proper action when the mouse has moved to position X, Y on
28427 frame F with regards to highlighting portions of display that have
28428 mouse-face properties. Also de-highlight portions of display where
28429 the mouse was before, set the mouse pointer shape as appropriate
28430 for the mouse coordinates, and activate help echo (tooltips).
28431 X and Y can be negative or out of range. */
28434 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28436 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28437 enum window_part part
= ON_NOTHING
;
28438 Lisp_Object window
;
28440 Cursor cursor
= No_Cursor
;
28441 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28444 /* When a menu is active, don't highlight because this looks odd. */
28445 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28446 if (popup_activated ())
28450 if (!f
->glyphs_initialized_p
28451 || f
->pointer_invisible
)
28454 hlinfo
->mouse_face_mouse_x
= x
;
28455 hlinfo
->mouse_face_mouse_y
= y
;
28456 hlinfo
->mouse_face_mouse_frame
= f
;
28458 if (hlinfo
->mouse_face_defer
)
28461 /* Which window is that in? */
28462 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28464 /* If displaying active text in another window, clear that. */
28465 if (! EQ (window
, hlinfo
->mouse_face_window
)
28466 /* Also clear if we move out of text area in same window. */
28467 || (!NILP (hlinfo
->mouse_face_window
)
28470 && part
!= ON_MODE_LINE
28471 && part
!= ON_HEADER_LINE
))
28472 clear_mouse_face (hlinfo
);
28474 /* Not on a window -> return. */
28475 if (!WINDOWP (window
))
28478 /* Reset help_echo_string. It will get recomputed below. */
28479 help_echo_string
= Qnil
;
28481 /* Convert to window-relative pixel coordinates. */
28482 w
= XWINDOW (window
);
28483 frame_to_window_pixel_xy (w
, &x
, &y
);
28485 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28486 /* Handle tool-bar window differently since it doesn't display a
28488 if (EQ (window
, f
->tool_bar_window
))
28490 note_tool_bar_highlight (f
, x
, y
);
28495 /* Mouse is on the mode, header line or margin? */
28496 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28497 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28499 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28503 #ifdef HAVE_WINDOW_SYSTEM
28504 if (part
== ON_VERTICAL_BORDER
)
28506 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28507 help_echo_string
= build_string ("drag-mouse-1: resize");
28509 else if (part
== ON_RIGHT_DIVIDER
)
28511 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28512 help_echo_string
= build_string ("drag-mouse-1: resize");
28514 else if (part
== ON_BOTTOM_DIVIDER
)
28516 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28517 help_echo_string
= build_string ("drag-mouse-1: resize");
28519 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28520 || part
== ON_SCROLL_BAR
)
28521 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28523 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28526 /* Are we in a window whose display is up to date?
28527 And verify the buffer's text has not changed. */
28528 b
= XBUFFER (w
->contents
);
28529 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28531 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28533 struct glyph
*glyph
;
28534 Lisp_Object object
;
28535 Lisp_Object mouse_face
= Qnil
, position
;
28536 Lisp_Object
*overlay_vec
= NULL
;
28537 ptrdiff_t i
, noverlays
;
28538 struct buffer
*obuf
;
28539 ptrdiff_t obegv
, ozv
;
28542 /* Find the glyph under X/Y. */
28543 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28545 #ifdef HAVE_WINDOW_SYSTEM
28546 /* Look for :pointer property on image. */
28547 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28549 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28550 if (img
!= NULL
&& IMAGEP (img
->spec
))
28552 Lisp_Object image_map
, hotspot
;
28553 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28555 && (hotspot
= find_hot_spot (image_map
,
28556 glyph
->slice
.img
.x
+ dx
,
28557 glyph
->slice
.img
.y
+ dy
),
28559 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28563 /* Could check XCAR (hotspot) to see if we enter/leave
28565 If so, we could look for mouse-enter, mouse-leave
28566 properties in PLIST (and do something...). */
28567 hotspot
= XCDR (hotspot
);
28568 if (CONSP (hotspot
)
28569 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28571 pointer
= Fplist_get (plist
, Qpointer
);
28572 if (NILP (pointer
))
28574 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28575 if (!NILP (help_echo_string
))
28577 help_echo_window
= window
;
28578 help_echo_object
= glyph
->object
;
28579 help_echo_pos
= glyph
->charpos
;
28583 if (NILP (pointer
))
28584 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28587 #endif /* HAVE_WINDOW_SYSTEM */
28589 /* Clear mouse face if X/Y not over text. */
28591 || area
!= TEXT_AREA
28592 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28593 /* Glyph's OBJECT is an integer for glyphs inserted by the
28594 display engine for its internal purposes, like truncation
28595 and continuation glyphs and blanks beyond the end of
28596 line's text on text terminals. If we are over such a
28597 glyph, we are not over any text. */
28598 || INTEGERP (glyph
->object
)
28599 /* R2L rows have a stretch glyph at their front, which
28600 stands for no text, whereas L2R rows have no glyphs at
28601 all beyond the end of text. Treat such stretch glyphs
28602 like we do with NULL glyphs in L2R rows. */
28603 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28604 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28605 && glyph
->type
== STRETCH_GLYPH
28606 && glyph
->avoid_cursor_p
))
28608 if (clear_mouse_face (hlinfo
))
28609 cursor
= No_Cursor
;
28610 #ifdef HAVE_WINDOW_SYSTEM
28611 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28613 if (area
!= TEXT_AREA
)
28614 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28616 pointer
= Vvoid_text_area_pointer
;
28622 pos
= glyph
->charpos
;
28623 object
= glyph
->object
;
28624 if (!STRINGP (object
) && !BUFFERP (object
))
28627 /* If we get an out-of-range value, return now; avoid an error. */
28628 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28631 /* Make the window's buffer temporarily current for
28632 overlays_at and compute_char_face. */
28633 obuf
= current_buffer
;
28634 current_buffer
= b
;
28640 /* Is this char mouse-active or does it have help-echo? */
28641 position
= make_number (pos
);
28643 if (BUFFERP (object
))
28645 /* Put all the overlays we want in a vector in overlay_vec. */
28646 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28647 /* Sort overlays into increasing priority order. */
28648 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28653 if (NILP (Vmouse_highlight
))
28655 clear_mouse_face (hlinfo
);
28656 goto check_help_echo
;
28659 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28662 cursor
= No_Cursor
;
28664 /* Check mouse-face highlighting. */
28666 /* If there exists an overlay with mouse-face overlapping
28667 the one we are currently highlighting, we have to
28668 check if we enter the overlapping overlay, and then
28669 highlight only that. */
28670 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28671 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28673 /* Find the highest priority overlay with a mouse-face. */
28674 Lisp_Object overlay
= Qnil
;
28675 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28677 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28678 if (!NILP (mouse_face
))
28679 overlay
= overlay_vec
[i
];
28682 /* If we're highlighting the same overlay as before, there's
28683 no need to do that again. */
28684 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28685 goto check_help_echo
;
28686 hlinfo
->mouse_face_overlay
= overlay
;
28688 /* Clear the display of the old active region, if any. */
28689 if (clear_mouse_face (hlinfo
))
28690 cursor
= No_Cursor
;
28692 /* If no overlay applies, get a text property. */
28693 if (NILP (overlay
))
28694 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28696 /* Next, compute the bounds of the mouse highlighting and
28698 if (!NILP (mouse_face
) && STRINGP (object
))
28700 /* The mouse-highlighting comes from a display string
28701 with a mouse-face. */
28705 s
= Fprevious_single_property_change
28706 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28707 e
= Fnext_single_property_change
28708 (position
, Qmouse_face
, object
, Qnil
);
28710 s
= make_number (0);
28712 e
= make_number (SCHARS (object
));
28713 mouse_face_from_string_pos (w
, hlinfo
, object
,
28714 XINT (s
), XINT (e
));
28715 hlinfo
->mouse_face_past_end
= 0;
28716 hlinfo
->mouse_face_window
= window
;
28717 hlinfo
->mouse_face_face_id
28718 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28719 glyph
->face_id
, 1);
28720 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28721 cursor
= No_Cursor
;
28725 /* The mouse-highlighting, if any, comes from an overlay
28726 or text property in the buffer. */
28727 Lisp_Object buffer
IF_LINT (= Qnil
);
28728 Lisp_Object disp_string
IF_LINT (= Qnil
);
28730 if (STRINGP (object
))
28732 /* If we are on a display string with no mouse-face,
28733 check if the text under it has one. */
28734 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28735 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28736 pos
= string_buffer_position (object
, start
);
28739 mouse_face
= get_char_property_and_overlay
28740 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28741 buffer
= w
->contents
;
28742 disp_string
= object
;
28748 disp_string
= Qnil
;
28751 if (!NILP (mouse_face
))
28753 Lisp_Object before
, after
;
28754 Lisp_Object before_string
, after_string
;
28755 /* To correctly find the limits of mouse highlight
28756 in a bidi-reordered buffer, we must not use the
28757 optimization of limiting the search in
28758 previous-single-property-change and
28759 next-single-property-change, because
28760 rows_from_pos_range needs the real start and end
28761 positions to DTRT in this case. That's because
28762 the first row visible in a window does not
28763 necessarily display the character whose position
28764 is the smallest. */
28766 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28767 ? Fmarker_position (w
->start
)
28770 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28771 ? make_number (BUF_Z (XBUFFER (buffer
))
28772 - w
->window_end_pos
)
28775 if (NILP (overlay
))
28777 /* Handle the text property case. */
28778 before
= Fprevious_single_property_change
28779 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28780 after
= Fnext_single_property_change
28781 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28782 before_string
= after_string
= Qnil
;
28786 /* Handle the overlay case. */
28787 before
= Foverlay_start (overlay
);
28788 after
= Foverlay_end (overlay
);
28789 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28790 after_string
= Foverlay_get (overlay
, Qafter_string
);
28792 if (!STRINGP (before_string
)) before_string
= Qnil
;
28793 if (!STRINGP (after_string
)) after_string
= Qnil
;
28796 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28799 : XFASTINT (before
),
28801 ? BUF_Z (XBUFFER (buffer
))
28802 : XFASTINT (after
),
28803 before_string
, after_string
,
28805 cursor
= No_Cursor
;
28812 /* Look for a `help-echo' property. */
28813 if (NILP (help_echo_string
)) {
28814 Lisp_Object help
, overlay
;
28816 /* Check overlays first. */
28817 help
= overlay
= Qnil
;
28818 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28820 overlay
= overlay_vec
[i
];
28821 help
= Foverlay_get (overlay
, Qhelp_echo
);
28826 help_echo_string
= help
;
28827 help_echo_window
= window
;
28828 help_echo_object
= overlay
;
28829 help_echo_pos
= pos
;
28833 Lisp_Object obj
= glyph
->object
;
28834 ptrdiff_t charpos
= glyph
->charpos
;
28836 /* Try text properties. */
28839 && charpos
< SCHARS (obj
))
28841 help
= Fget_text_property (make_number (charpos
),
28845 /* If the string itself doesn't specify a help-echo,
28846 see if the buffer text ``under'' it does. */
28847 struct glyph_row
*r
28848 = MATRIX_ROW (w
->current_matrix
, vpos
);
28849 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28850 ptrdiff_t p
= string_buffer_position (obj
, start
);
28853 help
= Fget_char_property (make_number (p
),
28854 Qhelp_echo
, w
->contents
);
28863 else if (BUFFERP (obj
)
28866 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28871 help_echo_string
= help
;
28872 help_echo_window
= window
;
28873 help_echo_object
= obj
;
28874 help_echo_pos
= charpos
;
28879 #ifdef HAVE_WINDOW_SYSTEM
28880 /* Look for a `pointer' property. */
28881 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28883 /* Check overlays first. */
28884 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28885 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28887 if (NILP (pointer
))
28889 Lisp_Object obj
= glyph
->object
;
28890 ptrdiff_t charpos
= glyph
->charpos
;
28892 /* Try text properties. */
28895 && charpos
< SCHARS (obj
))
28897 pointer
= Fget_text_property (make_number (charpos
),
28899 if (NILP (pointer
))
28901 /* If the string itself doesn't specify a pointer,
28902 see if the buffer text ``under'' it does. */
28903 struct glyph_row
*r
28904 = MATRIX_ROW (w
->current_matrix
, vpos
);
28905 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28906 ptrdiff_t p
= string_buffer_position (obj
, start
);
28908 pointer
= Fget_char_property (make_number (p
),
28909 Qpointer
, w
->contents
);
28912 else if (BUFFERP (obj
)
28915 pointer
= Fget_text_property (make_number (charpos
),
28919 #endif /* HAVE_WINDOW_SYSTEM */
28923 current_buffer
= obuf
;
28928 #ifdef HAVE_WINDOW_SYSTEM
28929 if (FRAME_WINDOW_P (f
))
28930 define_frame_cursor1 (f
, cursor
, pointer
);
28932 /* This is here to prevent a compiler error, about "label at end of
28933 compound statement". */
28940 Clear any mouse-face on window W. This function is part of the
28941 redisplay interface, and is called from try_window_id and similar
28942 functions to ensure the mouse-highlight is off. */
28945 x_clear_window_mouse_face (struct window
*w
)
28947 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28948 Lisp_Object window
;
28951 XSETWINDOW (window
, w
);
28952 if (EQ (window
, hlinfo
->mouse_face_window
))
28953 clear_mouse_face (hlinfo
);
28959 Just discard the mouse face information for frame F, if any.
28960 This is used when the size of F is changed. */
28963 cancel_mouse_face (struct frame
*f
)
28965 Lisp_Object window
;
28966 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28968 window
= hlinfo
->mouse_face_window
;
28969 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28970 reset_mouse_highlight (hlinfo
);
28975 /***********************************************************************
28977 ***********************************************************************/
28979 #ifdef HAVE_WINDOW_SYSTEM
28981 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28982 which intersects rectangle R. R is in window-relative coordinates. */
28985 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28986 enum glyph_row_area area
)
28988 struct glyph
*first
= row
->glyphs
[area
];
28989 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28990 struct glyph
*last
;
28991 int first_x
, start_x
, x
;
28993 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28994 /* If row extends face to end of line write the whole line. */
28995 draw_glyphs (w
, 0, row
, area
,
28996 0, row
->used
[area
],
28997 DRAW_NORMAL_TEXT
, 0);
29000 /* Set START_X to the window-relative start position for drawing glyphs of
29001 AREA. The first glyph of the text area can be partially visible.
29002 The first glyphs of other areas cannot. */
29003 start_x
= window_box_left_offset (w
, area
);
29005 if (area
== TEXT_AREA
)
29008 /* Find the first glyph that must be redrawn. */
29010 && x
+ first
->pixel_width
< r
->x
)
29012 x
+= first
->pixel_width
;
29016 /* Find the last one. */
29020 && x
< r
->x
+ r
->width
)
29022 x
+= last
->pixel_width
;
29028 draw_glyphs (w
, first_x
- start_x
, row
, area
,
29029 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
29030 DRAW_NORMAL_TEXT
, 0);
29035 /* Redraw the parts of the glyph row ROW on window W intersecting
29036 rectangle R. R is in window-relative coordinates. Value is
29037 non-zero if mouse-face was overwritten. */
29040 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
29042 eassert (row
->enabled_p
);
29044 if (row
->mode_line_p
|| w
->pseudo_window_p
)
29045 draw_glyphs (w
, 0, row
, TEXT_AREA
,
29046 0, row
->used
[TEXT_AREA
],
29047 DRAW_NORMAL_TEXT
, 0);
29050 if (row
->used
[LEFT_MARGIN_AREA
])
29051 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
29052 if (row
->used
[TEXT_AREA
])
29053 expose_area (w
, row
, r
, TEXT_AREA
);
29054 if (row
->used
[RIGHT_MARGIN_AREA
])
29055 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
29056 draw_row_fringe_bitmaps (w
, row
);
29059 return row
->mouse_face_p
;
29063 /* Redraw those parts of glyphs rows during expose event handling that
29064 overlap other rows. Redrawing of an exposed line writes over parts
29065 of lines overlapping that exposed line; this function fixes that.
29067 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
29068 row in W's current matrix that is exposed and overlaps other rows.
29069 LAST_OVERLAPPING_ROW is the last such row. */
29072 expose_overlaps (struct window
*w
,
29073 struct glyph_row
*first_overlapping_row
,
29074 struct glyph_row
*last_overlapping_row
,
29077 struct glyph_row
*row
;
29079 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
29080 if (row
->overlapping_p
)
29082 eassert (row
->enabled_p
&& !row
->mode_line_p
);
29085 if (row
->used
[LEFT_MARGIN_AREA
])
29086 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
29088 if (row
->used
[TEXT_AREA
])
29089 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
29091 if (row
->used
[RIGHT_MARGIN_AREA
])
29092 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
29098 /* Return non-zero if W's cursor intersects rectangle R. */
29101 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
29103 XRectangle cr
, result
;
29104 struct glyph
*cursor_glyph
;
29105 struct glyph_row
*row
;
29107 if (w
->phys_cursor
.vpos
>= 0
29108 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
29109 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
29111 && row
->cursor_in_fringe_p
)
29113 /* Cursor is in the fringe. */
29114 cr
.x
= window_box_right_offset (w
,
29115 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
29116 ? RIGHT_MARGIN_AREA
29119 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
29120 cr
.height
= row
->height
;
29121 return x_intersect_rectangles (&cr
, r
, &result
);
29124 cursor_glyph
= get_phys_cursor_glyph (w
);
29127 /* r is relative to W's box, but w->phys_cursor.x is relative
29128 to left edge of W's TEXT area. Adjust it. */
29129 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29130 cr
.y
= w
->phys_cursor
.y
;
29131 cr
.width
= cursor_glyph
->pixel_width
;
29132 cr
.height
= w
->phys_cursor_height
;
29133 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29134 I assume the effect is the same -- and this is portable. */
29135 return x_intersect_rectangles (&cr
, r
, &result
);
29137 /* If we don't understand the format, pretend we're not in the hot-spot. */
29143 Draw a vertical window border to the right of window W if W doesn't
29144 have vertical scroll bars. */
29147 x_draw_vertical_border (struct window
*w
)
29149 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29151 /* We could do better, if we knew what type of scroll-bar the adjacent
29152 windows (on either side) have... But we don't :-(
29153 However, I think this works ok. ++KFS 2003-04-25 */
29155 /* Redraw borders between horizontally adjacent windows. Don't
29156 do it for frames with vertical scroll bars because either the
29157 right scroll bar of a window, or the left scroll bar of its
29158 neighbor will suffice as a border. */
29159 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
29162 /* Note: It is necessary to redraw both the left and the right
29163 borders, for when only this single window W is being
29165 if (!WINDOW_RIGHTMOST_P (w
)
29166 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29168 int x0
, x1
, y0
, y1
;
29170 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29173 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29176 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29179 if (!WINDOW_LEFTMOST_P (w
)
29180 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29182 int x0
, x1
, y0
, y1
;
29184 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29187 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29190 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29195 /* Draw window dividers for window W. */
29198 x_draw_right_divider (struct window
*w
)
29200 struct frame
*f
= WINDOW_XFRAME (w
);
29202 if (w
->mini
|| w
->pseudo_window_p
)
29204 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29206 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
29207 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29208 int y0
= WINDOW_TOP_EDGE_Y (w
);
29209 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29211 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29216 x_draw_bottom_divider (struct window
*w
)
29218 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29220 if (w
->mini
|| w
->pseudo_window_p
)
29222 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29224 int x0
= WINDOW_LEFT_EDGE_X (w
);
29225 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29226 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29227 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29229 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29233 /* Redraw the part of window W intersection rectangle FR. Pixel
29234 coordinates in FR are frame-relative. Call this function with
29235 input blocked. Value is non-zero if the exposure overwrites
29239 expose_window (struct window
*w
, XRectangle
*fr
)
29241 struct frame
*f
= XFRAME (w
->frame
);
29243 int mouse_face_overwritten_p
= 0;
29245 /* If window is not yet fully initialized, do nothing. This can
29246 happen when toolkit scroll bars are used and a window is split.
29247 Reconfiguring the scroll bar will generate an expose for a newly
29249 if (w
->current_matrix
== NULL
)
29252 /* When we're currently updating the window, display and current
29253 matrix usually don't agree. Arrange for a thorough display
29255 if (w
->must_be_updated_p
)
29257 SET_FRAME_GARBAGED (f
);
29261 /* Frame-relative pixel rectangle of W. */
29262 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29263 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29264 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
29265 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
29267 if (x_intersect_rectangles (fr
, &wr
, &r
))
29269 int yb
= window_text_bottom_y (w
);
29270 struct glyph_row
*row
;
29271 int cursor_cleared_p
, phys_cursor_on_p
;
29272 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29274 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29275 r
.x
, r
.y
, r
.width
, r
.height
));
29277 /* Convert to window coordinates. */
29278 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29279 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29281 /* Turn off the cursor. */
29282 if (!w
->pseudo_window_p
29283 && phys_cursor_in_rect_p (w
, &r
))
29285 x_clear_cursor (w
);
29286 cursor_cleared_p
= 1;
29289 cursor_cleared_p
= 0;
29291 /* If the row containing the cursor extends face to end of line,
29292 then expose_area might overwrite the cursor outside the
29293 rectangle and thus notice_overwritten_cursor might clear
29294 w->phys_cursor_on_p. We remember the original value and
29295 check later if it is changed. */
29296 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29298 /* Update lines intersecting rectangle R. */
29299 first_overlapping_row
= last_overlapping_row
= NULL
;
29300 for (row
= w
->current_matrix
->rows
;
29305 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29307 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29308 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29309 || (r
.y
>= y0
&& r
.y
< y1
)
29310 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29312 /* A header line may be overlapping, but there is no need
29313 to fix overlapping areas for them. KFS 2005-02-12 */
29314 if (row
->overlapping_p
&& !row
->mode_line_p
)
29316 if (first_overlapping_row
== NULL
)
29317 first_overlapping_row
= row
;
29318 last_overlapping_row
= row
;
29322 if (expose_line (w
, row
, &r
))
29323 mouse_face_overwritten_p
= 1;
29326 else if (row
->overlapping_p
)
29328 /* We must redraw a row overlapping the exposed area. */
29330 ? y0
+ row
->phys_height
> r
.y
29331 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29333 if (first_overlapping_row
== NULL
)
29334 first_overlapping_row
= row
;
29335 last_overlapping_row
= row
;
29343 /* Display the mode line if there is one. */
29344 if (WINDOW_WANTS_MODELINE_P (w
)
29345 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29347 && row
->y
< r
.y
+ r
.height
)
29349 if (expose_line (w
, row
, &r
))
29350 mouse_face_overwritten_p
= 1;
29353 if (!w
->pseudo_window_p
)
29355 /* Fix the display of overlapping rows. */
29356 if (first_overlapping_row
)
29357 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29360 /* Draw border between windows. */
29361 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29362 x_draw_right_divider (w
);
29364 x_draw_vertical_border (w
);
29366 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29367 x_draw_bottom_divider (w
);
29369 /* Turn the cursor on again. */
29370 if (cursor_cleared_p
29371 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29372 update_window_cursor (w
, 1);
29376 return mouse_face_overwritten_p
;
29381 /* Redraw (parts) of all windows in the window tree rooted at W that
29382 intersect R. R contains frame pixel coordinates. Value is
29383 non-zero if the exposure overwrites mouse-face. */
29386 expose_window_tree (struct window
*w
, XRectangle
*r
)
29388 struct frame
*f
= XFRAME (w
->frame
);
29389 int mouse_face_overwritten_p
= 0;
29391 while (w
&& !FRAME_GARBAGED_P (f
))
29393 if (WINDOWP (w
->contents
))
29394 mouse_face_overwritten_p
29395 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29397 mouse_face_overwritten_p
|= expose_window (w
, r
);
29399 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29402 return mouse_face_overwritten_p
;
29407 Redisplay an exposed area of frame F. X and Y are the upper-left
29408 corner of the exposed rectangle. W and H are width and height of
29409 the exposed area. All are pixel values. W or H zero means redraw
29410 the entire frame. */
29413 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29416 int mouse_face_overwritten_p
= 0;
29418 TRACE ((stderr
, "expose_frame "));
29420 /* No need to redraw if frame will be redrawn soon. */
29421 if (FRAME_GARBAGED_P (f
))
29423 TRACE ((stderr
, " garbaged\n"));
29427 /* If basic faces haven't been realized yet, there is no point in
29428 trying to redraw anything. This can happen when we get an expose
29429 event while Emacs is starting, e.g. by moving another window. */
29430 if (FRAME_FACE_CACHE (f
) == NULL
29431 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29433 TRACE ((stderr
, " no faces\n"));
29437 if (w
== 0 || h
== 0)
29440 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29441 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29451 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29452 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29454 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29455 if (WINDOWP (f
->tool_bar_window
))
29456 mouse_face_overwritten_p
29457 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29460 #ifdef HAVE_X_WINDOWS
29462 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29463 if (WINDOWP (f
->menu_bar_window
))
29464 mouse_face_overwritten_p
29465 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29466 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29470 /* Some window managers support a focus-follows-mouse style with
29471 delayed raising of frames. Imagine a partially obscured frame,
29472 and moving the mouse into partially obscured mouse-face on that
29473 frame. The visible part of the mouse-face will be highlighted,
29474 then the WM raises the obscured frame. With at least one WM, KDE
29475 2.1, Emacs is not getting any event for the raising of the frame
29476 (even tried with SubstructureRedirectMask), only Expose events.
29477 These expose events will draw text normally, i.e. not
29478 highlighted. Which means we must redo the highlight here.
29479 Subsume it under ``we love X''. --gerd 2001-08-15 */
29480 /* Included in Windows version because Windows most likely does not
29481 do the right thing if any third party tool offers
29482 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29483 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29485 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29486 if (f
== hlinfo
->mouse_face_mouse_frame
)
29488 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29489 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29490 clear_mouse_face (hlinfo
);
29491 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29498 Determine the intersection of two rectangles R1 and R2. Return
29499 the intersection in *RESULT. Value is non-zero if RESULT is not
29503 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29505 XRectangle
*left
, *right
;
29506 XRectangle
*upper
, *lower
;
29507 int intersection_p
= 0;
29509 /* Rearrange so that R1 is the left-most rectangle. */
29511 left
= r1
, right
= r2
;
29513 left
= r2
, right
= r1
;
29515 /* X0 of the intersection is right.x0, if this is inside R1,
29516 otherwise there is no intersection. */
29517 if (right
->x
<= left
->x
+ left
->width
)
29519 result
->x
= right
->x
;
29521 /* The right end of the intersection is the minimum of
29522 the right ends of left and right. */
29523 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29526 /* Same game for Y. */
29528 upper
= r1
, lower
= r2
;
29530 upper
= r2
, lower
= r1
;
29532 /* The upper end of the intersection is lower.y0, if this is inside
29533 of upper. Otherwise, there is no intersection. */
29534 if (lower
->y
<= upper
->y
+ upper
->height
)
29536 result
->y
= lower
->y
;
29538 /* The lower end of the intersection is the minimum of the lower
29539 ends of upper and lower. */
29540 result
->height
= (min (lower
->y
+ lower
->height
,
29541 upper
->y
+ upper
->height
)
29543 intersection_p
= 1;
29547 return intersection_p
;
29550 #endif /* HAVE_WINDOW_SYSTEM */
29553 /***********************************************************************
29555 ***********************************************************************/
29558 syms_of_xdisp (void)
29560 Vwith_echo_area_save_vector
= Qnil
;
29561 staticpro (&Vwith_echo_area_save_vector
);
29563 Vmessage_stack
= Qnil
;
29564 staticpro (&Vmessage_stack
);
29566 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29567 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29569 message_dolog_marker1
= Fmake_marker ();
29570 staticpro (&message_dolog_marker1
);
29571 message_dolog_marker2
= Fmake_marker ();
29572 staticpro (&message_dolog_marker2
);
29573 message_dolog_marker3
= Fmake_marker ();
29574 staticpro (&message_dolog_marker3
);
29577 defsubr (&Sdump_frame_glyph_matrix
);
29578 defsubr (&Sdump_glyph_matrix
);
29579 defsubr (&Sdump_glyph_row
);
29580 defsubr (&Sdump_tool_bar_row
);
29581 defsubr (&Strace_redisplay
);
29582 defsubr (&Strace_to_stderr
);
29584 #ifdef HAVE_WINDOW_SYSTEM
29585 defsubr (&Stool_bar_height
);
29586 defsubr (&Slookup_image_map
);
29588 defsubr (&Sline_pixel_height
);
29589 defsubr (&Sformat_mode_line
);
29590 defsubr (&Sinvisible_p
);
29591 defsubr (&Scurrent_bidi_paragraph_direction
);
29592 defsubr (&Swindow_text_pixel_size
);
29593 defsubr (&Smove_point_visually
);
29595 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29596 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29597 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29598 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29599 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29600 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29601 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29602 DEFSYM (Qeval
, "eval");
29603 DEFSYM (QCdata
, ":data");
29604 DEFSYM (Qdisplay
, "display");
29605 DEFSYM (Qspace_width
, "space-width");
29606 DEFSYM (Qraise
, "raise");
29607 DEFSYM (Qslice
, "slice");
29608 DEFSYM (Qspace
, "space");
29609 DEFSYM (Qmargin
, "margin");
29610 DEFSYM (Qpointer
, "pointer");
29611 DEFSYM (Qleft_margin
, "left-margin");
29612 DEFSYM (Qright_margin
, "right-margin");
29613 DEFSYM (Qcenter
, "center");
29614 DEFSYM (Qline_height
, "line-height");
29615 DEFSYM (QCalign_to
, ":align-to");
29616 DEFSYM (QCrelative_width
, ":relative-width");
29617 DEFSYM (QCrelative_height
, ":relative-height");
29618 DEFSYM (QCeval
, ":eval");
29619 DEFSYM (QCpropertize
, ":propertize");
29620 DEFSYM (QCfile
, ":file");
29621 DEFSYM (Qfontified
, "fontified");
29622 DEFSYM (Qfontification_functions
, "fontification-functions");
29623 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29624 DEFSYM (Qescape_glyph
, "escape-glyph");
29625 DEFSYM (Qnobreak_space
, "nobreak-space");
29626 DEFSYM (Qimage
, "image");
29627 DEFSYM (Qtext
, "text");
29628 DEFSYM (Qboth
, "both");
29629 DEFSYM (Qboth_horiz
, "both-horiz");
29630 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29631 DEFSYM (QCmap
, ":map");
29632 DEFSYM (QCpointer
, ":pointer");
29633 DEFSYM (Qrect
, "rect");
29634 DEFSYM (Qcircle
, "circle");
29635 DEFSYM (Qpoly
, "poly");
29636 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29637 DEFSYM (Qgrow_only
, "grow-only");
29638 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29639 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29640 DEFSYM (Qposition
, "position");
29641 DEFSYM (Qbuffer_position
, "buffer-position");
29642 DEFSYM (Qobject
, "object");
29643 DEFSYM (Qbar
, "bar");
29644 DEFSYM (Qhbar
, "hbar");
29645 DEFSYM (Qbox
, "box");
29646 DEFSYM (Qhollow
, "hollow");
29647 DEFSYM (Qhand
, "hand");
29648 DEFSYM (Qarrow
, "arrow");
29649 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29651 list_of_error
= list1 (list2 (intern_c_string ("error"),
29652 intern_c_string ("void-variable")));
29653 staticpro (&list_of_error
);
29655 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29656 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29657 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29658 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29660 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29661 staticpro (&echo_buffer
[0]);
29662 staticpro (&echo_buffer
[1]);
29664 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29665 staticpro (&echo_area_buffer
[0]);
29666 staticpro (&echo_area_buffer
[1]);
29668 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29669 staticpro (&Vmessages_buffer_name
);
29671 mode_line_proptrans_alist
= Qnil
;
29672 staticpro (&mode_line_proptrans_alist
);
29673 mode_line_string_list
= Qnil
;
29674 staticpro (&mode_line_string_list
);
29675 mode_line_string_face
= Qnil
;
29676 staticpro (&mode_line_string_face
);
29677 mode_line_string_face_prop
= Qnil
;
29678 staticpro (&mode_line_string_face_prop
);
29679 Vmode_line_unwind_vector
= Qnil
;
29680 staticpro (&Vmode_line_unwind_vector
);
29682 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29684 help_echo_string
= Qnil
;
29685 staticpro (&help_echo_string
);
29686 help_echo_object
= Qnil
;
29687 staticpro (&help_echo_object
);
29688 help_echo_window
= Qnil
;
29689 staticpro (&help_echo_window
);
29690 previous_help_echo_string
= Qnil
;
29691 staticpro (&previous_help_echo_string
);
29692 help_echo_pos
= -1;
29694 DEFSYM (Qright_to_left
, "right-to-left");
29695 DEFSYM (Qleft_to_right
, "left-to-right");
29697 #ifdef HAVE_WINDOW_SYSTEM
29698 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29699 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29700 For example, if a block cursor is over a tab, it will be drawn as
29701 wide as that tab on the display. */);
29702 x_stretch_cursor_p
= 0;
29705 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29706 doc
: /* Non-nil means highlight trailing whitespace.
29707 The face used for trailing whitespace is `trailing-whitespace'. */);
29708 Vshow_trailing_whitespace
= Qnil
;
29710 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29711 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29712 If the value is t, Emacs highlights non-ASCII chars which have the
29713 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29714 or `escape-glyph' face respectively.
29716 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29717 U+2011 (non-breaking hyphen) are affected.
29719 Any other non-nil value means to display these characters as a escape
29720 glyph followed by an ordinary space or hyphen.
29722 A value of nil means no special handling of these characters. */);
29723 Vnobreak_char_display
= Qt
;
29725 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29726 doc
: /* The pointer shape to show in void text areas.
29727 A value of nil means to show the text pointer. Other options are `arrow',
29728 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29729 Vvoid_text_area_pointer
= Qarrow
;
29731 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29732 doc
: /* Non-nil means don't actually do any redisplay.
29733 This is used for internal purposes. */);
29734 Vinhibit_redisplay
= Qnil
;
29736 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29737 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29738 Vglobal_mode_string
= Qnil
;
29740 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29741 doc
: /* Marker for where to display an arrow on top of the buffer text.
29742 This must be the beginning of a line in order to work.
29743 See also `overlay-arrow-string'. */);
29744 Voverlay_arrow_position
= Qnil
;
29746 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29747 doc
: /* String to display as an arrow in non-window frames.
29748 See also `overlay-arrow-position'. */);
29749 Voverlay_arrow_string
= build_pure_c_string ("=>");
29751 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29752 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29753 The symbols on this list are examined during redisplay to determine
29754 where to display overlay arrows. */);
29755 Voverlay_arrow_variable_list
29756 = list1 (intern_c_string ("overlay-arrow-position"));
29758 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29759 doc
: /* The number of lines to try scrolling a window by when point moves out.
29760 If that fails to bring point back on frame, point is centered instead.
29761 If this is zero, point is always centered after it moves off frame.
29762 If you want scrolling to always be a line at a time, you should set
29763 `scroll-conservatively' to a large value rather than set this to 1. */);
29765 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29766 doc
: /* Scroll up to this many lines, to bring point back on screen.
29767 If point moves off-screen, redisplay will scroll by up to
29768 `scroll-conservatively' lines in order to bring point just barely
29769 onto the screen again. If that cannot be done, then redisplay
29770 recenters point as usual.
29772 If the value is greater than 100, redisplay will never recenter point,
29773 but will always scroll just enough text to bring point into view, even
29774 if you move far away.
29776 A value of zero means always recenter point if it moves off screen. */);
29777 scroll_conservatively
= 0;
29779 DEFVAR_INT ("scroll-margin", scroll_margin
,
29780 doc
: /* Number of lines of margin at the top and bottom of a window.
29781 Recenter the window whenever point gets within this many lines
29782 of the top or bottom of the window. */);
29785 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29786 doc
: /* Pixels per inch value for non-window system displays.
29787 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29788 Vdisplay_pixels_per_inch
= make_float (72.0);
29791 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29794 DEFVAR_LISP ("truncate-partial-width-windows",
29795 Vtruncate_partial_width_windows
,
29796 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29797 For an integer value, truncate lines in each window narrower than the
29798 full frame width, provided the window width is less than that integer;
29799 otherwise, respect the value of `truncate-lines'.
29801 For any other non-nil value, truncate lines in all windows that do
29802 not span the full frame width.
29804 A value of nil means to respect the value of `truncate-lines'.
29806 If `word-wrap' is enabled, you might want to reduce this. */);
29807 Vtruncate_partial_width_windows
= make_number (50);
29809 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29810 doc
: /* Maximum buffer size for which line number should be displayed.
29811 If the buffer is bigger than this, the line number does not appear
29812 in the mode line. A value of nil means no limit. */);
29813 Vline_number_display_limit
= Qnil
;
29815 DEFVAR_INT ("line-number-display-limit-width",
29816 line_number_display_limit_width
,
29817 doc
: /* Maximum line width (in characters) for line number display.
29818 If the average length of the lines near point is bigger than this, then the
29819 line number may be omitted from the mode line. */);
29820 line_number_display_limit_width
= 200;
29822 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29823 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29824 highlight_nonselected_windows
= 0;
29826 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29827 doc
: /* Non-nil if more than one frame is visible on this display.
29828 Minibuffer-only frames don't count, but iconified frames do.
29829 This variable is not guaranteed to be accurate except while processing
29830 `frame-title-format' and `icon-title-format'. */);
29832 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29833 doc
: /* Template for displaying the title bar of visible frames.
29834 \(Assuming the window manager supports this feature.)
29836 This variable has the same structure as `mode-line-format', except that
29837 the %c and %l constructs are ignored. It is used only on frames for
29838 which no explicit name has been set \(see `modify-frame-parameters'). */);
29840 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29841 doc
: /* Template for displaying the title bar of an iconified frame.
29842 \(Assuming the window manager supports this feature.)
29843 This variable has the same structure as `mode-line-format' (which see),
29844 and is used only on frames for which no explicit name has been set
29845 \(see `modify-frame-parameters'). */);
29847 = Vframe_title_format
29848 = listn (CONSTYPE_PURE
, 3,
29849 intern_c_string ("multiple-frames"),
29850 build_pure_c_string ("%b"),
29851 listn (CONSTYPE_PURE
, 4,
29852 empty_unibyte_string
,
29853 intern_c_string ("invocation-name"),
29854 build_pure_c_string ("@"),
29855 intern_c_string ("system-name")));
29857 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29858 doc
: /* Maximum number of lines to keep in the message log buffer.
29859 If nil, disable message logging. If t, log messages but don't truncate
29860 the buffer when it becomes large. */);
29861 Vmessage_log_max
= make_number (1000);
29863 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29864 doc
: /* Functions called before redisplay, if window sizes have changed.
29865 The value should be a list of functions that take one argument.
29866 Just before redisplay, for each frame, if any of its windows have changed
29867 size since the last redisplay, or have been split or deleted,
29868 all the functions in the list are called, with the frame as argument. */);
29869 Vwindow_size_change_functions
= Qnil
;
29871 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29872 doc
: /* List of functions to call before redisplaying a window with scrolling.
29873 Each function is called with two arguments, the window and its new
29874 display-start position. Note that these functions are also called by
29875 `set-window-buffer'. Also note that the value of `window-end' is not
29876 valid when these functions are called.
29878 Warning: Do not use this feature to alter the way the window
29879 is scrolled. It is not designed for that, and such use probably won't
29881 Vwindow_scroll_functions
= Qnil
;
29883 DEFVAR_LISP ("window-text-change-functions",
29884 Vwindow_text_change_functions
,
29885 doc
: /* Functions to call in redisplay when text in the window might change. */);
29886 Vwindow_text_change_functions
= Qnil
;
29888 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29889 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29890 Each function is called with two arguments, the window and the end trigger value.
29891 See `set-window-redisplay-end-trigger'. */);
29892 Vredisplay_end_trigger_functions
= Qnil
;
29894 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29895 doc
: /* Non-nil means autoselect window with mouse pointer.
29896 If nil, do not autoselect windows.
29897 A positive number means delay autoselection by that many seconds: a
29898 window is autoselected only after the mouse has remained in that
29899 window for the duration of the delay.
29900 A negative number has a similar effect, but causes windows to be
29901 autoselected only after the mouse has stopped moving. \(Because of
29902 the way Emacs compares mouse events, you will occasionally wait twice
29903 that time before the window gets selected.\)
29904 Any other value means to autoselect window instantaneously when the
29905 mouse pointer enters it.
29907 Autoselection selects the minibuffer only if it is active, and never
29908 unselects the minibuffer if it is active.
29910 When customizing this variable make sure that the actual value of
29911 `focus-follows-mouse' matches the behavior of your window manager. */);
29912 Vmouse_autoselect_window
= Qnil
;
29914 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29915 doc
: /* Non-nil means automatically resize tool-bars.
29916 This dynamically changes the tool-bar's height to the minimum height
29917 that is needed to make all tool-bar items visible.
29918 If value is `grow-only', the tool-bar's height is only increased
29919 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29920 Vauto_resize_tool_bars
= Qt
;
29922 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29923 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29924 auto_raise_tool_bar_buttons_p
= 1;
29926 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29927 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29928 make_cursor_line_fully_visible_p
= 1;
29930 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29931 doc
: /* Border below tool-bar in pixels.
29932 If an integer, use it as the height of the border.
29933 If it is one of `internal-border-width' or `border-width', use the
29934 value of the corresponding frame parameter.
29935 Otherwise, no border is added below the tool-bar. */);
29936 Vtool_bar_border
= Qinternal_border_width
;
29938 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29939 doc
: /* Margin around tool-bar buttons in pixels.
29940 If an integer, use that for both horizontal and vertical margins.
29941 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29942 HORZ specifying the horizontal margin, and VERT specifying the
29943 vertical margin. */);
29944 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29946 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29947 doc
: /* Relief thickness of tool-bar buttons. */);
29948 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29950 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29951 doc
: /* Tool bar style to use.
29953 image - show images only
29954 text - show text only
29955 both - show both, text below image
29956 both-horiz - show text to the right of the image
29957 text-image-horiz - show text to the left of the image
29958 any other - use system default or image if no system default.
29960 This variable only affects the GTK+ toolkit version of Emacs. */);
29961 Vtool_bar_style
= Qnil
;
29963 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29964 doc
: /* Maximum number of characters a label can have to be shown.
29965 The tool bar style must also show labels for this to have any effect, see
29966 `tool-bar-style'. */);
29967 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29969 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29970 doc
: /* List of functions to call to fontify regions of text.
29971 Each function is called with one argument POS. Functions must
29972 fontify a region starting at POS in the current buffer, and give
29973 fontified regions the property `fontified'. */);
29974 Vfontification_functions
= Qnil
;
29975 Fmake_variable_buffer_local (Qfontification_functions
);
29977 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29978 unibyte_display_via_language_environment
,
29979 doc
: /* Non-nil means display unibyte text according to language environment.
29980 Specifically, this means that raw bytes in the range 160-255 decimal
29981 are displayed by converting them to the equivalent multibyte characters
29982 according to the current language environment. As a result, they are
29983 displayed according to the current fontset.
29985 Note that this variable affects only how these bytes are displayed,
29986 but does not change the fact they are interpreted as raw bytes. */);
29987 unibyte_display_via_language_environment
= 0;
29989 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29990 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29991 If a float, it specifies a fraction of the mini-window frame's height.
29992 If an integer, it specifies a number of lines. */);
29993 Vmax_mini_window_height
= make_float (0.25);
29995 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29996 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29997 A value of nil means don't automatically resize mini-windows.
29998 A value of t means resize them to fit the text displayed in them.
29999 A value of `grow-only', the default, means let mini-windows grow only;
30000 they return to their normal size when the minibuffer is closed, or the
30001 echo area becomes empty. */);
30002 Vresize_mini_windows
= Qgrow_only
;
30004 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
30005 doc
: /* Alist specifying how to blink the cursor off.
30006 Each element has the form (ON-STATE . OFF-STATE). Whenever the
30007 `cursor-type' frame-parameter or variable equals ON-STATE,
30008 comparing using `equal', Emacs uses OFF-STATE to specify
30009 how to blink it off. ON-STATE and OFF-STATE are values for
30010 the `cursor-type' frame parameter.
30012 If a frame's ON-STATE has no entry in this list,
30013 the frame's other specifications determine how to blink the cursor off. */);
30014 Vblink_cursor_alist
= Qnil
;
30016 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
30017 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
30018 If non-nil, windows are automatically scrolled horizontally to make
30019 point visible. */);
30020 automatic_hscrolling_p
= 1;
30021 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
30023 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
30024 doc
: /* How many columns away from the window edge point is allowed to get
30025 before automatic hscrolling will horizontally scroll the window. */);
30026 hscroll_margin
= 5;
30028 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
30029 doc
: /* How many columns to scroll the window when point gets too close to the edge.
30030 When point is less than `hscroll-margin' columns from the window
30031 edge, automatic hscrolling will scroll the window by the amount of columns
30032 determined by this variable. If its value is a positive integer, scroll that
30033 many columns. If it's a positive floating-point number, it specifies the
30034 fraction of the window's width to scroll. If it's nil or zero, point will be
30035 centered horizontally after the scroll. Any other value, including negative
30036 numbers, are treated as if the value were zero.
30038 Automatic hscrolling always moves point outside the scroll margin, so if
30039 point was more than scroll step columns inside the margin, the window will
30040 scroll more than the value given by the scroll step.
30042 Note that the lower bound for automatic hscrolling specified by `scroll-left'
30043 and `scroll-right' overrides this variable's effect. */);
30044 Vhscroll_step
= make_number (0);
30046 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
30047 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
30048 Bind this around calls to `message' to let it take effect. */);
30049 message_truncate_lines
= 0;
30051 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
30052 doc
: /* Normal hook run to update the menu bar definitions.
30053 Redisplay runs this hook before it redisplays the menu bar.
30054 This is used to update submenus such as Buffers,
30055 whose contents depend on various data. */);
30056 Vmenu_bar_update_hook
= Qnil
;
30058 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
30059 doc
: /* Frame for which we are updating a menu.
30060 The enable predicate for a menu binding should check this variable. */);
30061 Vmenu_updating_frame
= Qnil
;
30063 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
30064 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
30065 inhibit_menubar_update
= 0;
30067 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
30068 doc
: /* Prefix prepended to all continuation lines at display time.
30069 The value may be a string, an image, or a stretch-glyph; it is
30070 interpreted in the same way as the value of a `display' text property.
30072 This variable is overridden by any `wrap-prefix' text or overlay
30075 To add a prefix to non-continuation lines, use `line-prefix'. */);
30076 Vwrap_prefix
= Qnil
;
30077 DEFSYM (Qwrap_prefix
, "wrap-prefix");
30078 Fmake_variable_buffer_local (Qwrap_prefix
);
30080 DEFVAR_LISP ("line-prefix", Vline_prefix
,
30081 doc
: /* Prefix prepended to all non-continuation lines at display time.
30082 The value may be a string, an image, or a stretch-glyph; it is
30083 interpreted in the same way as the value of a `display' text property.
30085 This variable is overridden by any `line-prefix' text or overlay
30088 To add a prefix to continuation lines, use `wrap-prefix'. */);
30089 Vline_prefix
= Qnil
;
30090 DEFSYM (Qline_prefix
, "line-prefix");
30091 Fmake_variable_buffer_local (Qline_prefix
);
30093 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
30094 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
30095 inhibit_eval_during_redisplay
= 0;
30097 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
30098 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
30099 inhibit_free_realized_faces
= 0;
30102 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
30103 doc
: /* Inhibit try_window_id display optimization. */);
30104 inhibit_try_window_id
= 0;
30106 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
30107 doc
: /* Inhibit try_window_reusing display optimization. */);
30108 inhibit_try_window_reusing
= 0;
30110 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
30111 doc
: /* Inhibit try_cursor_movement display optimization. */);
30112 inhibit_try_cursor_movement
= 0;
30113 #endif /* GLYPH_DEBUG */
30115 DEFVAR_INT ("overline-margin", overline_margin
,
30116 doc
: /* Space between overline and text, in pixels.
30117 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
30118 margin to the character height. */);
30119 overline_margin
= 2;
30121 DEFVAR_INT ("underline-minimum-offset",
30122 underline_minimum_offset
,
30123 doc
: /* Minimum distance between baseline and underline.
30124 This can improve legibility of underlined text at small font sizes,
30125 particularly when using variable `x-use-underline-position-properties'
30126 with fonts that specify an UNDERLINE_POSITION relatively close to the
30127 baseline. The default value is 1. */);
30128 underline_minimum_offset
= 1;
30130 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
30131 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
30132 This feature only works when on a window system that can change
30133 cursor shapes. */);
30134 display_hourglass_p
= 1;
30136 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
30137 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
30138 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
30140 #ifdef HAVE_WINDOW_SYSTEM
30141 hourglass_atimer
= NULL
;
30142 hourglass_shown_p
= 0;
30143 #endif /* HAVE_WINDOW_SYSTEM */
30145 DEFSYM (Qglyphless_char
, "glyphless-char");
30146 DEFSYM (Qhex_code
, "hex-code");
30147 DEFSYM (Qempty_box
, "empty-box");
30148 DEFSYM (Qthin_space
, "thin-space");
30149 DEFSYM (Qzero_width
, "zero-width");
30151 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
30152 doc
: /* Function run just before redisplay.
30153 It is called with one argument, which is the set of windows that are to
30154 be redisplayed. This set can be nil (meaning, only the selected window),
30155 or t (meaning all windows). */);
30156 Vpre_redisplay_function
= intern ("ignore");
30158 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
30159 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
30161 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
30162 doc
: /* Char-table defining glyphless characters.
30163 Each element, if non-nil, should be one of the following:
30164 an ASCII acronym string: display this string in a box
30165 `hex-code': display the hexadecimal code of a character in a box
30166 `empty-box': display as an empty box
30167 `thin-space': display as 1-pixel width space
30168 `zero-width': don't display
30169 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
30170 display method for graphical terminals and text terminals respectively.
30171 GRAPHICAL and TEXT should each have one of the values listed above.
30173 The char-table has one extra slot to control the display of a character for
30174 which no font is found. This slot only takes effect on graphical terminals.
30175 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30176 `thin-space'. The default is `empty-box'.
30178 If a character has a non-nil entry in an active display table, the
30179 display table takes effect; in this case, Emacs does not consult
30180 `glyphless-char-display' at all. */);
30181 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30182 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30185 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30186 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30187 Vdebug_on_message
= Qnil
;
30189 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
30191 Vredisplay__all_windows_cause
30192 = Fmake_vector (make_number (100), make_number (0));
30194 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
30196 Vredisplay__mode_lines_cause
30197 = Fmake_vector (make_number (100), make_number (0));
30201 /* Initialize this module when Emacs starts. */
30206 CHARPOS (this_line_start_pos
) = 0;
30208 if (!noninteractive
)
30210 struct window
*m
= XWINDOW (minibuf_window
);
30211 Lisp_Object frame
= m
->frame
;
30212 struct frame
*f
= XFRAME (frame
);
30213 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30214 struct window
*r
= XWINDOW (root
);
30217 echo_area_window
= minibuf_window
;
30219 r
->top_line
= FRAME_TOP_MARGIN (f
);
30220 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
30221 r
->total_cols
= FRAME_COLS (f
);
30222 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30223 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30224 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
30226 m
->top_line
= FRAME_LINES (f
) - 1;
30227 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
30228 m
->total_cols
= FRAME_COLS (f
);
30229 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30230 m
->total_lines
= 1;
30231 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
30233 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30234 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30235 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30237 /* The default ellipsis glyphs `...'. */
30238 for (i
= 0; i
< 3; ++i
)
30239 default_invis_vector
[i
] = make_number ('.');
30243 /* Allocate the buffer for frame titles.
30244 Also used for `format-mode-line'. */
30246 mode_line_noprop_buf
= xmalloc (size
);
30247 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30248 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30249 mode_line_target
= MODE_LINE_DISPLAY
;
30252 help_echo_showing_p
= 0;
30255 #ifdef HAVE_WINDOW_SYSTEM
30257 /* Platform-independent portion of hourglass implementation. */
30259 /* Cancel a currently active hourglass timer, and start a new one. */
30261 start_hourglass (void)
30263 struct timespec delay
;
30265 cancel_hourglass ();
30267 if (INTEGERP (Vhourglass_delay
)
30268 && XINT (Vhourglass_delay
) > 0)
30269 delay
= make_timespec (min (XINT (Vhourglass_delay
),
30270 TYPE_MAXIMUM (time_t)),
30272 else if (FLOATP (Vhourglass_delay
)
30273 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30274 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
30276 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
30280 extern void w32_note_current_window (void);
30281 w32_note_current_window ();
30283 #endif /* HAVE_NTGUI */
30285 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30286 show_hourglass
, NULL
);
30290 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30293 cancel_hourglass (void)
30295 if (hourglass_atimer
)
30297 cancel_atimer (hourglass_atimer
);
30298 hourglass_atimer
= NULL
;
30301 if (hourglass_shown_p
)
30305 #endif /* HAVE_WINDOW_SYSTEM */